blob: 4898e694c5e80456f35f402643afd4515f375445 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200225#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#ifdef FEAT_CURSORBIND
252# define PV_CRBIND OPT_WIN(WV_CRBIND)
253#endif
254#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200255# define PV_COCU OPT_WIN(WV_COCU)
256# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200257#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200258#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200259# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260# define PV_TMS OPT_WIN(WV_TMS)
261#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200262#ifdef FEAT_SIGNS
263# define PV_SCL OPT_WIN(WV_SCL)
264#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000265
266/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267typedef enum
268{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000269 PV_NONE = 0,
270 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271} idopt_T;
272
273/*
274 * Options local to a window have a value local to a buffer and global to all
275 * buffers. Indicate this by setting "var" to VAR_WIN.
276 */
277#define VAR_WIN ((char_u *)-1)
278
279/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000280 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281 * Only to be used in option.c!
282 */
283static int p_ai;
284static int p_bin;
285#ifdef FEAT_MBYTE
286static int p_bomb;
287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288static char_u *p_bh;
289static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static int p_bl;
291static int p_ci;
292#ifdef FEAT_CINDENT
293static int p_cin;
294static char_u *p_cink;
295static char_u *p_cino;
296#endif
297#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
298static char_u *p_cinw;
299#endif
300#ifdef FEAT_COMMENTS
301static char_u *p_com;
302#endif
303#ifdef FEAT_FOLDING
304static char_u *p_cms;
305#endif
306#ifdef FEAT_INS_EXPAND
307static char_u *p_cpt;
308#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#ifdef FEAT_COMPL_FUNC
310static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000311static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
316#ifdef FEAT_MBYTE
317static char_u *p_fenc;
318#endif
319static char_u *p_ff;
320static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000321static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322#ifdef FEAT_AUTOCMD
323static char_u *p_ft;
324#endif
325static long p_iminsert;
326static long p_imsearch;
327#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
328static char_u *p_inex;
329#endif
330#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
331static char_u *p_inde;
332static char_u *p_indk;
333#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000334#if defined(FEAT_EVAL)
335static char_u *p_fex;
336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_inf;
338static char_u *p_isk;
339#ifdef FEAT_CRYPT
340static char_u *p_key;
341#endif
342#ifdef FEAT_LISP
343static int p_lisp;
344#endif
345static int p_ml;
346static int p_ma;
347static int p_mod;
348static char_u *p_mps;
349static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000351#ifdef FEAT_TEXTOBJ
352static char_u *p_qe;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_ro;
355#ifdef FEAT_SMARTINDENT
356static int p_si;
357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static long p_sts;
360#if defined(FEAT_SEARCHPATH)
361static char_u *p_sua;
362#endif
363static long p_sw;
364static int p_swf;
365#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000366static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000368#endif
369#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000370static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000371static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000372static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373#endif
374static long p_ts;
375static long p_tw;
376static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200377#ifdef FEAT_PERSISTENT_UNDO
378static int p_udf;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380static long p_wm;
381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
384
385/* Saved values for when 'bin' is set. */
386static int p_et_nobin;
387static int p_ml_nobin;
388static long p_tw_nobin;
389static long p_wm_nobin;
390
391/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200392static int p_ai_nopaste;
393static int p_et_nopaste;
394static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395static long p_tw_nopaste;
396static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398struct vimoption
399{
400 char *fullname; /* full option name */
401 char *shortname; /* permissible abbreviation */
402 long_u flags; /* see below */
403 char_u *var; /* global option: pointer to variable;
404 * window-local option: VAR_WIN;
405 * buffer-local option: global value */
406 idopt_T indir; /* global option: PV_NONE;
407 * local option: indirect option index */
408 char_u *def_val[2]; /* default values for variable (vi and vim) */
409#ifdef FEAT_EVAL
410 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411# define SCRIPTID_INIT , 0
412#else
413# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#endif
415};
416
417#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
418#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
419
420/*
421 * Flags
422 */
423#define P_BOOL 0x01 /* the option is boolean */
424#define P_NUM 0x02 /* the option is numeric */
425#define P_STRING 0x04 /* the option is a string */
426#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000427 must use free_string_option() when
428 assigning new value. Not set if default is
429 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
431 never be used for local or hidden options! */
432#define P_NODEFAULT 0x40 /* don't set to default value */
433#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
434 use vim_free() when assigning new value */
435#define P_WAS_SET 0x100 /* option has been set/reset */
436#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
437#define P_VI_DEF 0x400 /* Use Vi default for Vim */
438#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
439
440 /* when option changed, what to display: */
441#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100442#define P_RWIN 0x2000 /* redraw current window and recompute text */
443#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444#define P_RALL 0x6000 /* redraw all windows */
445#define P_RCLR 0x7000 /* clear and redraw all */
446
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200447#define P_COMMA 0x8000 /* comma separated list */
448#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
449 * commas */
450#define P_NODUP 0x20000L /* don't allow duplicate strings */
451#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
454#define P_GETTEXT 0x100000L /* expand default value with _() */
455#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
456#define P_NFNAME 0x400000L /* only normal file name chars allowed */
457#define P_INSECURE 0x800000L /* option was set from a modeline */
458#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_NO_ML 0x2000000L /* not allowed in modeline */
461#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200462 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100464#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000466#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000468/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100470#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000471# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000472#else
473# define ISP_LATIN1 (char_u *)"@,161-255"
474#endif
475
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200476# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000477
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100478/* Default python version for pyx* commands */
479#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
480# define DEFAULT_PYTHON_VER 0
481#elif defined(FEAT_PYTHON3)
482# define DEFAULT_PYTHON_VER 3
483#elif defined(FEAT_PYTHON)
484# define DEFAULT_PYTHON_VER 2
485#else
486# define DEFAULT_PYTHON_VER 0
487#endif
488
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489/*
490 * options[] is initialized here.
491 * The order of the options MUST be alphabetic for ":set all" and findoption().
492 * All option names MUST start with a lowercase letter (for findoption()).
493 * Exception: "t_" options are at the end.
494 * The options with a NULL variable are 'hidden': a set command for them is
495 * ignored and they are not printed.
496 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100497static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200499 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500#ifdef FEAT_RIGHTLEFT
501 (char_u *)&p_aleph, PV_NONE,
502#else
503 (char_u *)NULL, PV_NONE,
504#endif
505 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100506#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507 (char_u *)128L,
508#else
509 (char_u *)224L,
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200513#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (char_u *)&p_antialias, PV_NONE,
515 {(char_u *)FALSE, (char_u *)FALSE}
516#else
517 (char_u *)NULL, PV_NONE,
518 {(char_u *)FALSE, (char_u *)FALSE}
519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000520 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200521 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522#ifdef FEAT_ARABIC
523 (char_u *)VAR_WIN, PV_ARAB,
524#else
525 (char_u *)NULL, PV_NONE,
526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000527 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
529#ifdef FEAT_ARABIC
530 (char_u *)&p_arshape, PV_NONE,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000534 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
536#ifdef FEAT_RIGHTLEFT
537 (char_u *)&p_ari, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
543#ifdef FEAT_FKMAP
544 (char_u *)&p_altkeymap, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
550#if defined(FEAT_MBYTE)
551 (char_u *)&p_ambw, PV_NONE,
552 {(char_u *)"single", (char_u *)0L}
553#else
554 (char_u *)NULL, PV_NONE,
555 {(char_u *)0L, (char_u *)0L}
556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100559#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100561 {(char_u *)FALSE, (char_u *)0L}
562#else
563 (char_u *)NULL, PV_NONE,
564 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autoindent", "ai", P_BOOL|P_VI_DEF,
568 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autoprint", "ap", P_BOOL|P_VI_DEF,
571 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000574 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"autowrite", "aw", P_BOOL|P_VI_DEF,
577 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"autowriteall","awa", P_BOOL|P_VI_DEF,
580 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
583 (char_u *)&p_bg, PV_NONE,
584 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100585#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)"dark",
587#else
588 (char_u *)"light",
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
595 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200598 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599#ifdef UNIX
600 {(char_u *)"yes", (char_u *)"auto"}
601#else
602 {(char_u *)"auto", (char_u *)"auto"}
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200605 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
606 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000609 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610 (char_u *)&p_bex, PV_NONE,
611 {
612#ifdef VMS
613 (char_u *)"_",
614#else
615 (char_u *)"~",
616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200618 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_WILDIGN
620 (char_u *)&p_bsk, PV_NONE,
621 {(char_u *)"", (char_u *)0L}
622#else
623 (char_u *)NULL, PV_NONE,
624 {(char_u *)0L, (char_u *)0L}
625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 {(char_u *)600L, (char_u *)0L}
631#else
632 (char_u *)NULL, PV_NONE,
633 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635 SCRIPTID_INIT},
636 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100637#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100638 (char_u *)&p_beval, PV_NONE,
639 {(char_u *)FALSE, (char_u *)0L}
640#else
641 (char_u *)NULL, PV_NONE,
642 {(char_u *)0L, (char_u *)0L}
643#endif
644 SCRIPTID_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100645 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100646#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100647 (char_u *)&p_bevalterm, PV_NONE,
648 {(char_u *)FALSE, (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
653 SCRIPTID_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100654 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
655#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
656 (char_u *)&p_bexpr, PV_BEXPR,
657 {(char_u *)"", (char_u *)0L}
658#else
659 (char_u *)NULL, PV_NONE,
660 {(char_u *)0L, (char_u *)0L}
661#endif
662 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"beautify", "bf", P_BOOL|P_VI_DEF,
664 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200666 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
667 (char_u *)&p_bo, PV_NONE,
668 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
670 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000671 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000674 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
676#ifdef FEAT_MBYTE
677 (char_u *)&p_bomb, PV_BOMB,
678#else
679 (char_u *)NULL, PV_NONE,
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
683#ifdef FEAT_LINEBREAK
684 (char_u *)&p_breakat, PV_NONE,
685 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200691 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
692#ifdef FEAT_LINEBREAK
693 (char_u *)VAR_WIN, PV_BRI,
694 {(char_u *)FALSE, (char_u *)0L}
695#else
696 (char_u *)NULL, PV_NONE,
697 {(char_u *)0L, (char_u *)0L}
698#endif
699 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200700 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
701 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200702#ifdef FEAT_LINEBREAK
703 (char_u *)VAR_WIN, PV_BRIOPT,
704 {(char_u *)"", (char_u *)NULL}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)"", (char_u *)NULL}
708#endif
709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
711#ifdef FEAT_BROWSE
712 (char_u *)&p_bsdir, PV_NONE,
713 {(char_u *)"last", (char_u *)0L}
714#else
715 (char_u *)NULL, PV_NONE,
716 {(char_u *)0L, (char_u *)0L}
717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 (char_u *)&p_bh, PV_BH,
721 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
724 (char_u *)&p_bl, PV_BL,
725 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 (char_u *)&p_bt, PV_BT,
729 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200731 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000732#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733 (char_u *)&p_cmp, PV_NONE,
734 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
741#ifdef FEAT_SEARCHPATH
742 (char_u *)&p_cdpath, PV_NONE,
743 {(char_u *)",,", (char_u *)0L}
744#else
745 (char_u *)NULL, PV_NONE,
746 {(char_u *)0L, (char_u *)0L}
747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 {"cedit", NULL, P_STRING,
750#ifdef FEAT_CMDWIN
751 (char_u *)&p_cedit, PV_NONE,
752 {(char_u *)"", (char_u *)CTRL_F_STR}
753#else
754 (char_u *)NULL, PV_NONE,
755 {(char_u *)0L, (char_u *)0L}
756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000757 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
759#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
760 (char_u *)&p_ccv, PV_NONE,
761 {(char_u *)"", (char_u *)0L}
762#else
763 (char_u *)NULL, PV_NONE,
764 {(char_u *)0L, (char_u *)0L}
765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
768#ifdef FEAT_CINDENT
769 (char_u *)&p_cin, PV_CIN,
770#else
771 (char_u *)NULL, PV_NONE,
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775#ifdef FEAT_CINDENT
776 (char_u *)&p_cink, PV_CINK,
777 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
778#else
779 (char_u *)NULL, PV_NONE,
780 {(char_u *)0L, (char_u *)0L}
781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000782 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200783 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#ifdef FEAT_CINDENT
785 (char_u *)&p_cino, PV_CINO,
786#else
787 (char_u *)NULL, PV_NONE,
788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200790 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
792 (char_u *)&p_cinw, PV_CINW,
793 {(char_u *)"if,else,while,do,for,switch",
794 (char_u *)0L}
795#else
796 (char_u *)NULL, PV_NONE,
797 {(char_u *)0L, (char_u *)0L}
798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000799 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200800 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801#ifdef FEAT_CLIPBOARD
802 (char_u *)&p_cb, PV_NONE,
803# ifdef FEAT_XCLIPBOARD
804 {(char_u *)"autoselect,exclude:cons\\|linux",
805 (char_u *)0L}
806# else
807 {(char_u *)"", (char_u *)0L}
808# endif
809#else
810 (char_u *)NULL, PV_NONE,
811 {(char_u *)"", (char_u *)0L}
812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000813 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
815 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000816 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000817 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
818#ifdef FEAT_CMDWIN
819 (char_u *)&p_cwh, PV_NONE,
820#else
821 (char_u *)NULL, PV_NONE,
822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000823 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200824 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200825#ifdef FEAT_SYN_HL
826 (char_u *)VAR_WIN, PV_CC,
827#else
828 (char_u *)NULL, PV_NONE,
829#endif
830 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
832 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000833 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200834 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
835 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836#ifdef FEAT_COMMENTS
837 (char_u *)&p_com, PV_COM,
838 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
839 (char_u *)0L}
840#else
841 (char_u *)NULL, PV_NONE,
842 {(char_u *)0L, (char_u *)0L}
843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000844 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200845 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846#ifdef FEAT_FOLDING
847 (char_u *)&p_cms, PV_CMS,
848 {(char_u *)"/*%s*/", (char_u *)0L}
849#else
850 (char_u *)NULL, PV_NONE,
851 {(char_u *)0L, (char_u *)0L}
852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000853 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000854 /* P_PRI_MKRC isn't needed here, optval_default()
855 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000856 {"compatible", "cp", P_BOOL|P_RALL,
857 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200859 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000860#ifdef FEAT_INS_EXPAND
861 (char_u *)&p_cpt, PV_CPT,
862 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
863#else
864 (char_u *)NULL, PV_NONE,
865 {(char_u *)0L, (char_u *)0L}
866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000867 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200868 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200869#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 (char_u *)VAR_WIN, PV_COCU,
871 {(char_u *)"", (char_u *)NULL}
872#else
873 (char_u *)NULL, PV_NONE,
874 {(char_u *)NULL, (char_u *)0L}
875#endif
876 SCRIPTID_INIT},
877 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
878#ifdef FEAT_CONCEAL
879 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200880#else
881 (char_u *)NULL, PV_NONE,
882#endif
883 {(char_u *)0L, (char_u *)0L}
884 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000885 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
886#ifdef FEAT_COMPL_FUNC
887 (char_u *)&p_cfu, PV_CFU,
888 {(char_u *)"", (char_u *)0L}
889#else
890 (char_u *)NULL, PV_NONE,
891 {(char_u *)0L, (char_u *)0L}
892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000893 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200894 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000895#ifdef FEAT_INS_EXPAND
896 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000897 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000898#else
899 (char_u *)NULL, PV_NONE,
900 {(char_u *)0L, (char_u *)0L}
901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 {"confirm", "cf", P_BOOL|P_VI_DEF,
904#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
905 (char_u *)&p_confirm, PV_NONE,
906#else
907 (char_u *)NULL, PV_NONE,
908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000910 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
914 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000915 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
917 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000918 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
919 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200920 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200921#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200922 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200923 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200924#else
925 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200926 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200927#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
930#ifdef FEAT_CSCOPE
931 (char_u *)&p_cspc, PV_NONE,
932#else
933 (char_u *)NULL, PV_NONE,
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000936 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
937#ifdef FEAT_CSCOPE
938 (char_u *)&p_csprg, PV_NONE,
939 {(char_u *)"cscope", (char_u *)0L}
940#else
941 (char_u *)NULL, PV_NONE,
942 {(char_u *)0L, (char_u *)0L}
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200945 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
947 (char_u *)&p_csqf, PV_NONE,
948 {(char_u *)"", (char_u *)0L}
949#else
950 (char_u *)NULL, PV_NONE,
951 {(char_u *)0L, (char_u *)0L}
952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000953 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200954 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
955#ifdef FEAT_CSCOPE
956 (char_u *)&p_csre, PV_NONE,
957#else
958 (char_u *)NULL, PV_NONE,
959#endif
960 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
962#ifdef FEAT_CSCOPE
963 (char_u *)&p_cst, PV_NONE,
964#else
965 (char_u *)NULL, PV_NONE,
966#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000967 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000968 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
969#ifdef FEAT_CSCOPE
970 (char_u *)&p_csto, PV_NONE,
971#else
972 (char_u *)NULL, PV_NONE,
973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000974 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
976#ifdef FEAT_CSCOPE
977 (char_u *)&p_csverbose, PV_NONE,
978#else
979 (char_u *)NULL, PV_NONE,
980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000981 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200982 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
983#ifdef FEAT_CURSORBIND
984 (char_u *)VAR_WIN, PV_CRBIND,
985#else
986 (char_u *)NULL, PV_NONE,
987#endif
988 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000989 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
990#ifdef FEAT_SYN_HL
991 (char_u *)VAR_WIN, PV_CUC,
992#else
993 (char_u *)NULL, PV_NONE,
994#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000995 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100996 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000997#ifdef FEAT_SYN_HL
998 (char_u *)VAR_WIN, PV_CUL,
999#else
1000 (char_u *)NULL, PV_NONE,
1001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"debug", NULL, P_STRING|P_VI_DEF,
1004 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001006 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001008 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001009 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#else
1011 (char_u *)NULL, PV_NONE,
1012 {(char_u *)NULL, (char_u *)0L}
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1016#ifdef FEAT_MBYTE
1017 (char_u *)&p_deco, PV_NONE,
1018#else
1019 (char_u *)NULL, PV_NONE,
1020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001022 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001024 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#else
1026 (char_u *)NULL, PV_NONE,
1027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001028 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1030#ifdef FEAT_DIFF
1031 (char_u *)VAR_WIN, PV_DIFF,
1032#else
1033 (char_u *)NULL, PV_NONE,
1034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001036 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1038 (char_u *)&p_dex, PV_NONE,
1039 {(char_u *)"", (char_u *)0L}
1040#else
1041 (char_u *)NULL, PV_NONE,
1042 {(char_u *)0L, (char_u *)0L}
1043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001044 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001045 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1046 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047#ifdef FEAT_DIFF
1048 (char_u *)&p_dip, PV_NONE,
1049 {(char_u *)"filler", (char_u *)NULL}
1050#else
1051 (char_u *)NULL, PV_NONE,
1052 {(char_u *)"", (char_u *)NULL}
1053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1056#ifdef FEAT_DIGRAPHS
1057 (char_u *)&p_dg, PV_NONE,
1058#else
1059 (char_u *)NULL, PV_NONE,
1060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001061 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001062 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1063 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001065 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001066 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 (char_u *)&p_ead, PV_NONE,
1071 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1074 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001076 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1077#if defined(FEAT_MBYTE)
1078 (char_u *)&p_emoji, PV_NONE,
1079 {(char_u *)TRUE, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)0L, (char_u *)0L}
1083#endif
1084 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001085 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086#ifdef FEAT_MBYTE
1087 (char_u *)&p_enc, PV_NONE,
1088 {(char_u *)ENC_DFLT, (char_u *)0L}
1089#else
1090 (char_u *)NULL, PV_NONE,
1091 {(char_u *)0L, (char_u *)0L}
1092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1095 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1098 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001101 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1104 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1107#ifdef FEAT_QUICKFIX
1108 (char_u *)&p_ef, PV_NONE,
1109 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1110#else
1111 (char_u *)NULL, PV_NONE,
1112 {(char_u *)NULL, (char_u *)0L}
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001117 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119#else
1120 (char_u *)NULL, PV_NONE,
1121 {(char_u *)NULL, (char_u *)0L}
1122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 {"esckeys", "ek", P_BOOL|P_VIM,
1125 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001126 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001127 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128#ifdef FEAT_AUTOCMD
1129 (char_u *)&p_ei, PV_NONE,
1130#else
1131 (char_u *)NULL, PV_NONE,
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1135 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1138 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1141 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142#ifdef FEAT_MBYTE
1143 (char_u *)&p_fenc, PV_FENC,
1144 {(char_u *)"", (char_u *)0L}
1145#else
1146 (char_u *)NULL, PV_NONE,
1147 {(char_u *)0L, (char_u *)0L}
1148#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001150 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151#ifdef FEAT_MBYTE
1152 (char_u *)&p_fencs, PV_NONE,
1153 {(char_u *)"ucs-bom", (char_u *)0L}
1154#else
1155 (char_u *)NULL, PV_NONE,
1156 {(char_u *)0L, (char_u *)0L}
1157#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001158 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001159 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1160 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1166 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001167 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1168 (char_u *)&p_fic, PV_NONE,
1169 {
1170#ifdef CASE_INSENSITIVE_FILENAME
1171 (char_u *)TRUE,
1172#else
1173 (char_u *)FALSE,
1174#endif
1175 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001176 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177#ifdef FEAT_AUTOCMD
1178 (char_u *)&p_ft, PV_FT,
1179 {(char_u *)"", (char_u *)0L}
1180#else
1181 (char_u *)NULL, PV_NONE,
1182 {(char_u *)0L, (char_u *)0L}
1183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001185 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 (char_u *)&p_fcs, PV_NONE,
1187 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001189 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1190 (char_u *)&p_fixeol, PV_FIXEOL,
1191 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1193#ifdef FEAT_FKMAP
1194 (char_u *)&p_fkmap, PV_NONE,
1195#else
1196 (char_u *)NULL, PV_NONE,
1197#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"flash", "fl", P_BOOL|P_VI_DEF,
1200 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001202 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001203#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001205 {(char_u *)"", (char_u *)0L}
1206#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001209#endif
1210 SCRIPTID_INIT},
1211 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1212#ifdef FEAT_FOLDING
1213 (char_u *)VAR_WIN, PV_FDC,
1214 {(char_u *)FALSE, (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)NULL, (char_u *)0L}
1218#endif
1219 SCRIPTID_INIT},
1220 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1221#ifdef FEAT_FOLDING
1222 (char_u *)VAR_WIN, PV_FEN,
1223 {(char_u *)TRUE, (char_u *)0L}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
1227#endif
1228 SCRIPTID_INIT},
1229 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1230#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1231 (char_u *)VAR_WIN, PV_FDE,
1232 {(char_u *)"0", (char_u *)NULL}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001239#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001241 {(char_u *)"#", (char_u *)NULL}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001248#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001250 {(char_u *)0L, (char_u *)0L}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
1255 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001256 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001259 {(char_u *)-1L, (char_u *)0L}
1260#else
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)NULL, (char_u *)0L}
1263#endif
1264 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001266 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001267#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001270#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001274 SCRIPTID_INIT},
1275 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1276#ifdef FEAT_FOLDING
1277 (char_u *)VAR_WIN, PV_FDM,
1278 {(char_u *)"manual", (char_u *)NULL}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)NULL, (char_u *)0L}
1282#endif
1283 SCRIPTID_INIT},
1284 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1285#ifdef FEAT_FOLDING
1286 (char_u *)VAR_WIN, PV_FML,
1287 {(char_u *)1L, (char_u *)0L}
1288#else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
1291#endif
1292 SCRIPTID_INIT},
1293 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1294#ifdef FEAT_FOLDING
1295 (char_u *)VAR_WIN, PV_FDN,
1296 {(char_u *)20L, (char_u *)0L}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)NULL, (char_u *)0L}
1300#endif
1301 SCRIPTID_INIT},
1302 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1303#ifdef FEAT_FOLDING
1304 (char_u *)&p_fdo, PV_NONE,
1305 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1306 (char_u *)0L}
1307#else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310#endif
1311 SCRIPTID_INIT},
1312 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1313#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1314 (char_u *)VAR_WIN, PV_FDT,
1315 {(char_u *)"foldtext()", (char_u *)NULL}
1316#else
1317 (char_u *)NULL, PV_NONE,
1318 {(char_u *)NULL, (char_u *)0L}
1319#endif
1320 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001321 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001322#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001323 (char_u *)&p_fex, PV_FEX,
1324 {(char_u *)"", (char_u *)0L}
1325#else
1326 (char_u *)NULL, PV_NONE,
1327 {(char_u *)0L, (char_u *)0L}
1328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001329 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1331 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1333 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001334 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1335 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1337 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001339 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001341 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1342#ifdef HAVE_FSYNC
1343 (char_u *)&p_fs, PV_NONE,
1344 {(char_u *)TRUE, (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)FALSE, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1351 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"graphic", "gr", P_BOOL|P_VI_DEF,
1354 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001356 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357#ifdef FEAT_QUICKFIX
1358 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360#else
1361 (char_u *)NULL, PV_NONE,
1362 {(char_u *)NULL, (char_u *)0L}
1363#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1366#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001367 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {
1369# ifdef WIN3264
1370 /* may be changed to "grep -n" in os_win32.c */
1371 (char_u *)"findstr /n",
1372# else
1373# ifdef UNIX
1374 /* Add an extra file name so that grep will always
1375 * insert a file name in the match line. */
1376 (char_u *)"grep -n $* /dev/null",
1377# else
1378# ifdef VMS
1379 (char_u *)"SEARCH/NUMBERS ",
1380# else
1381 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382# endif
1383# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386#else
1387 (char_u *)NULL, PV_NONE,
1388 {(char_u *)NULL, (char_u *)0L}
1389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001390 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001391 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392#ifdef CURSOR_SHAPE
1393 (char_u *)&p_guicursor, PV_NONE,
1394 {
1395# ifdef FEAT_GUI
1396 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001397# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1399# endif
1400 (char_u *)0L}
1401#else
1402 (char_u *)NULL, PV_NONE,
1403 {(char_u *)NULL, (char_u *)0L}
1404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001406 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407#ifdef FEAT_GUI
1408 (char_u *)&p_guifont, PV_NONE,
1409 {(char_u *)"", (char_u *)0L}
1410#else
1411 (char_u *)NULL, PV_NONE,
1412 {(char_u *)NULL, (char_u *)0L}
1413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1417 (char_u *)&p_guifontset, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001424 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1426 (char_u *)&p_guifontwide, PV_NONE,
1427 {(char_u *)"", (char_u *)0L}
1428#else
1429 (char_u *)NULL, PV_NONE,
1430 {(char_u *)NULL, (char_u *)0L}
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001434#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 (char_u *)&p_ghr, PV_NONE,
1436#else
1437 (char_u *)NULL, PV_NONE,
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001441#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001443# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001444 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001446 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447# endif
1448#else
1449 (char_u *)NULL, PV_NONE,
1450 {(char_u *)NULL, (char_u *)0L}
1451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"guipty", NULL, P_BOOL|P_VI_DEF,
1454#if defined(FEAT_GUI)
1455 (char_u *)&p_guipty, PV_NONE,
1456#else
1457 (char_u *)NULL, PV_NONE,
1458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001460 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001461#if defined(FEAT_GUI_TABLINE)
1462 (char_u *)&p_gtl, PV_NONE,
1463 {(char_u *)"", (char_u *)0L}
1464#else
1465 (char_u *)NULL, PV_NONE,
1466 {(char_u *)NULL, (char_u *)0L}
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001469 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001470#if defined(FEAT_GUI_TABLINE)
1471 (char_u *)&p_gtt, PV_NONE,
1472 {(char_u *)"", (char_u *)0L}
1473#else
1474 (char_u *)NULL, PV_NONE,
1475 {(char_u *)NULL, (char_u *)0L}
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1479 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1482 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001483 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1484 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001488 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489#ifdef FEAT_MULTI_LANG
1490 (char_u *)&p_hlg, PV_NONE,
1491 {(char_u *)"", (char_u *)0L}
1492#else
1493 (char_u *)NULL, PV_NONE,
1494 {(char_u *)0L, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"hidden", "hid", P_BOOL|P_VI_DEF,
1498 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001500 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1503 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 {"history", "hi", P_NUM|P_VIM,
1505 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001506 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1508#ifdef FEAT_RIGHTLEFT
1509 (char_u *)&p_hkmap, PV_NONE,
1510#else
1511 (char_u *)NULL, PV_NONE,
1512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001513 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1515#ifdef FEAT_RIGHTLEFT
1516 (char_u *)&p_hkmapp, PV_NONE,
1517#else
1518 (char_u *)NULL, PV_NONE,
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1522 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 {"icon", NULL, P_BOOL|P_VI_DEF,
1525#ifdef FEAT_TITLE
1526 (char_u *)&p_icon, PV_NONE,
1527#else
1528 (char_u *)NULL, PV_NONE,
1529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"iconstring", NULL, P_STRING|P_VI_DEF,
1532#ifdef FEAT_TITLE
1533 (char_u *)&p_iconstring, PV_NONE,
1534#else
1535 (char_u *)NULL, PV_NONE,
1536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001537 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1539 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001541 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001542#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001543 (char_u *)&p_imaf, PV_NONE,
1544 {(char_u *)"", (char_u *)NULL}
1545# else
1546 (char_u *)NULL, PV_NONE,
1547 {(char_u *)NULL, (char_u *)0L}
1548# endif
1549 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001551#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 (char_u *)&p_imak, PV_NONE,
1553#else
1554 (char_u *)NULL, PV_NONE,
1555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001558#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559 (char_u *)&p_imcmdline, PV_NONE,
1560#else
1561 (char_u *)NULL, PV_NONE,
1562#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001565#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 (char_u *)&p_imdisable, PV_NONE,
1567#else
1568 (char_u *)NULL, PV_NONE,
1569#endif
1570#ifdef __sgi
1571 {(char_u *)TRUE, (char_u *)0L}
1572#else
1573 {(char_u *)FALSE, (char_u *)0L}
1574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001575 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576 {"iminsert", "imi", P_NUM|P_VI_DEF,
1577 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001578 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"imsearch", "ims", P_NUM|P_VI_DEF,
1581 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001582 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001583 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001584 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar819edbe2017-11-25 17:14:33 +01001585#if defined(FEAT_EVAL) && defined(FEAT_MBYTE)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001586 (char_u *)&p_imsf, PV_NONE,
1587 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001588#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001591#endif
1592 SCRIPTID_INIT},
1593 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1594#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1595 (char_u *)&p_imst, PV_NONE,
1596 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)0L, (char_u *)0L}
1600#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001601 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1603#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001604 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1606#else
1607 (char_u *)NULL, PV_NONE,
1608 {(char_u *)0L, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1612#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1613 (char_u *)&p_inex, PV_INEX,
1614 {(char_u *)"", (char_u *)0L}
1615#else
1616 (char_u *)NULL, PV_NONE,
1617 {(char_u *)0L, (char_u *)0L}
1618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1621 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1624#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1625 (char_u *)&p_inde, PV_INDE,
1626 {(char_u *)"", (char_u *)0L}
1627#else
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)0L, (char_u *)0L}
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001632 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1634 (char_u *)&p_indk, PV_INDK,
1635 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1636#else
1637 (char_u *)NULL, PV_NONE,
1638 {(char_u *)0L, (char_u *)0L}
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"infercase", "inf", P_BOOL|P_VI_DEF,
1642 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1645 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1648 (char_u *)&p_isf, PV_NONE,
1649 {
1650#ifdef BACKSLASH_IN_FILENAME
1651 /* Excluded are: & and ^ are special in cmd.exe
1652 * ( and ) are used in text separating fnames */
1653 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1654#else
1655# ifdef AMIGA
1656 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1657# else
1658# ifdef VMS
1659 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1660# else /* UNIX et al. */
1661# ifdef EBCDIC
1662 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1663# else
1664 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1665# endif
1666# endif
1667# endif
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1671 (char_u *)&p_isi, PV_NONE,
1672 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001673#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 (char_u *)"@,48-57,_,128-167,224-235",
1675#else
1676# ifdef EBCDIC
1677 /* TODO: EBCDIC Check this! @ == isalpha()*/
1678 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1679 "112-120,128,140-142,156,158,172,"
1680 "174,186,191,203-207,219-225,235-239,"
1681 "251-254",
1682# else
1683 (char_u *)"@,48-57,_,192-255",
1684# endif
1685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001686 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1688 (char_u *)&p_isk, PV_ISK,
1689 {
1690#ifdef EBCDIC
1691 (char_u *)"@,240-249,_",
1692 /* TODO: EBCDIC Check this! @ == isalpha()*/
1693 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1694 "112-120,128,140-142,156,158,172,"
1695 "174,186,191,203-207,219-225,235-239,"
1696 "251-254",
1697#else
1698 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001699# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 (char_u *)"@,48-57,_,128-167,224-235"
1701# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001702 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703# endif
1704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1707 (char_u *)&p_isp, PV_NONE,
1708 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001709#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 (char_u *)"@,~-255",
1711#else
1712# ifdef EBCDIC
1713 /* all chars above 63 are printable */
1714 (char_u *)"63-255",
1715# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001716 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717# endif
1718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1721 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1724#ifdef FEAT_CRYPT
1725 (char_u *)&p_key, PV_KEY,
1726 {(char_u *)"", (char_u *)0L}
1727#else
1728 (char_u *)NULL, PV_NONE,
1729 {(char_u *)0L, (char_u *)0L}
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001732 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733#ifdef FEAT_KEYMAP
1734 (char_u *)&p_keymap, PV_KMAP,
1735 {(char_u *)"", (char_u *)0L}
1736#else
1737 (char_u *)NULL, PV_NONE,
1738 {(char_u *)"", (char_u *)0L}
1739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001740 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001741 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001745 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001747#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 (char_u *)":help",
1749#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001750# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001752# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001753# ifdef USEMAN_S
1754 (char_u *)"man -s",
1755# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001757# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758# endif
1759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001761 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762#ifdef FEAT_LANGMAP
1763 (char_u *)&p_langmap, PV_NONE,
1764 {(char_u *)"", /* unmatched } */
1765#else
1766 (char_u *)NULL, PV_NONE,
1767 {(char_u *)NULL,
1768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001770 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1772 (char_u *)&p_lm, PV_NONE,
1773#else
1774 (char_u *)NULL, PV_NONE,
1775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001777 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1778#ifdef FEAT_LANGMAP
1779 (char_u *)&p_lnr, PV_NONE,
1780#else
1781 (char_u *)NULL, PV_NONE,
1782#endif
1783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001784 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1785#ifdef FEAT_LANGMAP
1786 (char_u *)&p_lrm, PV_NONE,
1787#else
1788 (char_u *)NULL, PV_NONE,
1789#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001790 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1795 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1798#ifdef FEAT_LINEBREAK
1799 (char_u *)VAR_WIN, PV_LBR,
1800#else
1801 (char_u *)NULL, PV_NONE,
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1805 (char_u *)&Rows, PV_NONE,
1806 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001807#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 (char_u *)25L,
1809#else
1810 (char_u *)24L,
1811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1814#ifdef FEAT_GUI
1815 (char_u *)&p_linespace, PV_NONE,
1816#else
1817 (char_u *)NULL, PV_NONE,
1818#endif
1819#ifdef FEAT_GUI_W32
1820 {(char_u *)1L, (char_u *)0L}
1821#else
1822 {(char_u *)0L, (char_u *)0L}
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"lisp", NULL, P_BOOL|P_VI_DEF,
1826#ifdef FEAT_LISP
1827 (char_u *)&p_lisp, PV_LISP,
1828#else
1829 (char_u *)NULL, PV_NONE,
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001832 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001834 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1836#else
1837 (char_u *)NULL, PV_NONE,
1838 {(char_u *)"", (char_u *)0L}
1839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1842 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001844 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001846 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001847 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1848 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001850 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001851#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001852 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001853 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)"", (char_u *)0L}
1857#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001858 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001859 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001860#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001861 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001862 {(char_u *)TRUE, (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001866#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"magic", NULL, P_BOOL|P_VI_DEF,
1869 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001871 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872#ifdef FEAT_QUICKFIX
1873 (char_u *)&p_mef, PV_NONE,
1874 {(char_u *)"", (char_u *)0L}
1875#else
1876 (char_u *)NULL, PV_NONE,
1877 {(char_u *)NULL, (char_u *)0L}
1878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001880 {"makeencoding","menc", P_STRING|P_VI_DEF,
1881#ifdef FEAT_MBYTE
1882 (char_u *)&p_menc, PV_MENC,
1883 {(char_u *)"", (char_u *)0L}
1884#else
1885 (char_u *)NULL, PV_NONE,
1886 {(char_u *)0L, (char_u *)0L}
1887#endif
1888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1890#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001891 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892# ifdef VMS
1893 {(char_u *)"MMS", (char_u *)0L}
1894# else
1895 {(char_u *)"make", (char_u *)0L}
1896# endif
1897#else
1898 (char_u *)NULL, PV_NONE,
1899 {(char_u *)NULL, (char_u *)0L}
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001902 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001904 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1905 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"matchtime", "mat", P_NUM|P_VI_DEF,
1907 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001909 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001910#ifdef FEAT_MBYTE
1911 (char_u *)&p_mco, PV_NONE,
1912#else
1913 (char_u *)NULL, PV_NONE,
1914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1917#ifdef FEAT_EVAL
1918 (char_u *)&p_mfd, PV_NONE,
1919#else
1920 (char_u *)NULL, PV_NONE,
1921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1924 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {"maxmem", "mm", P_NUM|P_VI_DEF,
1927 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1929 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001930 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1931 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001932 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1934 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1936 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"menuitems", "mis", P_NUM|P_VI_DEF,
1938#ifdef FEAT_MENU
1939 (char_u *)&p_mis, PV_NONE,
1940#else
1941 (char_u *)NULL, PV_NONE,
1942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"mesg", NULL, P_BOOL|P_VI_DEF,
1945 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001947 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001948#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001949 (char_u *)&p_msm, PV_NONE,
1950 {(char_u *)"460000,2000,500", (char_u *)0L}
1951#else
1952 (char_u *)NULL, PV_NONE,
1953 {(char_u *)0L, (char_u *)0L}
1954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"modeline", "ml", P_BOOL|P_VIM,
1957 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"modelines", "mls", P_NUM|P_VI_DEF,
1960 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1963 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1966 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"more", NULL, P_BOOL|P_VIM,
1969 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1972 (char_u *)&p_mouse, PV_NONE,
1973 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001974#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 (char_u *)"a",
1976#else
1977 (char_u *)"",
1978#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001979 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1981#ifdef FEAT_GUI
1982 (char_u *)&p_mousef, PV_NONE,
1983#else
1984 (char_u *)NULL, PV_NONE,
1985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1988#ifdef FEAT_GUI
1989 (char_u *)&p_mh, PV_NONE,
1990#else
1991 (char_u *)NULL, PV_NONE,
1992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1995 (char_u *)&p_mousem, PV_NONE,
1996 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001997#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 (char_u *)"popup",
1999#else
Bram Moolenaard0573012017-10-28 21:11:06 +02002000# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 (char_u *)"popup_setpos",
2002# else
2003 (char_u *)"extend",
2004# endif
2005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002007 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008#ifdef FEAT_MOUSESHAPE
2009 (char_u *)&p_mouseshape, PV_NONE,
2010 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2011#else
2012 (char_u *)NULL, PV_NONE,
2013 {(char_u *)NULL, (char_u *)0L}
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2017 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002019 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2020#if defined(DYNAMIC_MZSCHEME)
2021 (char_u *)&p_mzschemedll, PV_NONE,
2022 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2023#else
2024 (char_u *)NULL, PV_NONE,
2025 {(char_u *)"", (char_u *)0L}
2026#endif
2027 SCRIPTID_INIT},
2028 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2029#if defined(DYNAMIC_MZSCHEME)
2030 (char_u *)&p_mzschemegcdll, PV_NONE,
2031 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2032#else
2033 (char_u *)NULL, PV_NONE,
2034 {(char_u *)"", (char_u *)0L}
2035#endif
2036 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002037 {"mzquantum", "mzq", P_NUM,
2038#ifdef FEAT_MZSCHEME
2039 (char_u *)&p_mzq, PV_NONE,
2040#else
2041 (char_u *)NULL, PV_NONE,
2042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002043 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044 {"novice", NULL, P_BOOL|P_VI_DEF,
2045 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002047 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002048 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002049 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2052 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002054 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2055#ifdef FEAT_LINEBREAK
2056 (char_u *)VAR_WIN, PV_NUW,
2057#else
2058 (char_u *)NULL, PV_NONE,
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002061 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002062#ifdef FEAT_COMPL_FUNC
2063 (char_u *)&p_ofu, PV_OFU,
2064 {(char_u *)"", (char_u *)0L}
2065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)0L, (char_u *)0L}
2068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"open", NULL, P_BOOL|P_VI_DEF,
2071 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002073 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002074#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002075 (char_u *)&p_odev, PV_NONE,
2076#else
2077 (char_u *)NULL, PV_NONE,
2078#endif
2079 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002081 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2082 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 {"optimize", "opt", P_BOOL|P_VI_DEF,
2085 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002089 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002090 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2091 |P_SECURE,
2092 (char_u *)&p_pp, PV_NONE,
2093 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2094 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"paragraphs", "para", P_STRING|P_VI_DEF,
2096 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002097 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002099 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2103 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2106#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2107 (char_u *)&p_pex, PV_NONE,
2108 {(char_u *)"", (char_u *)0L}
2109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)0L, (char_u *)0L}
2112#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002114 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002118 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002120#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 (char_u *)".,,",
2122#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002126 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002127#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002128 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002129 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002130#else
2131 (char_u *)NULL, PV_NONE,
2132 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002134 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2136 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002138 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002139#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 (char_u *)&p_pvh, PV_NONE,
2141#else
2142 (char_u *)NULL, PV_NONE,
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002146#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 (char_u *)VAR_WIN, PV_PVW,
2148#else
2149 (char_u *)NULL, PV_NONE,
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002152 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153#ifdef FEAT_PRINTER
2154 (char_u *)&p_pdev, PV_NONE,
2155 {(char_u *)"", (char_u *)0L}
2156#else
2157 (char_u *)NULL, PV_NONE,
2158 {(char_u *)NULL, (char_u *)0L}
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"printencoding", "penc", P_STRING|P_VI_DEF,
2162#ifdef FEAT_POSTSCRIPT
2163 (char_u *)&p_penc, PV_NONE,
2164 {(char_u *)"", (char_u *)0L}
2165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)NULL, (char_u *)0L}
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002170 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171#ifdef FEAT_POSTSCRIPT
2172 (char_u *)&p_pexpr, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"printfont", "pfn", P_STRING|P_VI_DEF,
2180#ifdef FEAT_PRINTER
2181 (char_u *)&p_pfn, PV_NONE,
2182 {
2183# ifdef MSWIN
2184 (char_u *)"Courier_New:h10",
2185# else
2186 (char_u *)"courier",
2187# endif
2188 (char_u *)0L}
2189#else
2190 (char_u *)NULL, PV_NONE,
2191 {(char_u *)NULL, (char_u *)0L}
2192#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2195#ifdef FEAT_PRINTER
2196 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002197 /* untranslated to avoid problems when 'encoding'
2198 * is changed */
2199 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002205 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2206#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2207 (char_u *)&p_pmcs, PV_NONE,
2208 {(char_u *)"", (char_u *)0L}
2209#else
2210 (char_u *)NULL, PV_NONE,
2211 {(char_u *)NULL, (char_u *)0L}
2212#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002213 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002214 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2215#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2216 (char_u *)&p_pmfn, PV_NONE,
2217 {(char_u *)"", (char_u *)0L}
2218#else
2219 (char_u *)NULL, PV_NONE,
2220 {(char_u *)NULL, (char_u *)0L}
2221#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002223 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224#ifdef FEAT_PRINTER
2225 (char_u *)&p_popt, PV_NONE,
2226 {(char_u *)"", (char_u *)0L}
2227#else
2228 (char_u *)NULL, PV_NONE,
2229 {(char_u *)NULL, (char_u *)0L}
2230#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002231 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002233 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002234 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002235 {"pumheight", "ph", P_NUM|P_VI_DEF,
2236#ifdef FEAT_INS_EXPAND
2237 (char_u *)&p_ph, PV_NONE,
2238#else
2239 (char_u *)NULL, PV_NONE,
2240#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002242 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002243#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002244 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002245 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002246#else
2247 (char_u *)NULL, PV_NONE,
2248 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002249#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002250 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002251 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2252#if defined(FEAT_PYTHON3)
2253 (char_u *)&p_py3home, PV_NONE,
2254 {(char_u *)"", (char_u *)0L}
2255#else
2256 (char_u *)NULL, PV_NONE,
2257 {(char_u *)NULL, (char_u *)0L}
2258#endif
2259 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002260 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002261#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002262 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002263 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002264#else
2265 (char_u *)NULL, PV_NONE,
2266 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002267#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002268 SCRIPTID_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002269 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2270#if defined(FEAT_PYTHON)
2271 (char_u *)&p_pyhome, PV_NONE,
2272 {(char_u *)"", (char_u *)0L}
2273#else
2274 (char_u *)NULL, PV_NONE,
2275 {(char_u *)NULL, (char_u *)0L}
2276#endif
2277 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002278 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2279#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2280 (char_u *)&p_pyx, PV_NONE,
2281#else
2282 (char_u *)NULL, PV_NONE,
2283#endif
2284 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2285 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002286 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2287#ifdef FEAT_TEXTOBJ
2288 (char_u *)&p_qe, PV_QE,
2289 {(char_u *)"\\", (char_u *)0L}
2290#else
2291 (char_u *)NULL, PV_NONE,
2292 {(char_u *)NULL, (char_u *)0L}
2293#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002294 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2296 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 {"redraw", NULL, P_BOOL|P_VI_DEF,
2299 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002300 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002301 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2302#ifdef FEAT_RELTIME
2303 (char_u *)&p_rdt, PV_NONE,
2304#else
2305 (char_u *)NULL, PV_NONE,
2306#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002307 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002308 {"regexpengine", "re", P_NUM|P_VI_DEF,
2309 (char_u *)&p_re, PV_NONE,
2310 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002311 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2312 (char_u *)VAR_WIN, PV_RNU,
2313 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"remap", NULL, P_BOOL|P_VI_DEF,
2315 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002317 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002318#ifdef FEAT_RENDER_OPTIONS
2319 (char_u *)&p_rop, PV_NONE,
2320 {(char_u *)"", (char_u *)0L}
2321#else
2322 (char_u *)NULL, PV_NONE,
2323 {(char_u *)NULL, (char_u *)0L}
2324#endif
2325 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"report", NULL, P_NUM|P_VI_DEF,
2327 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2330#ifdef WIN3264
2331 (char_u *)&p_rs, PV_NONE,
2332#else
2333 (char_u *)NULL, PV_NONE,
2334#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2337#ifdef FEAT_RIGHTLEFT
2338 (char_u *)&p_ri, PV_NONE,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2344#ifdef FEAT_RIGHTLEFT
2345 (char_u *)VAR_WIN, PV_RL,
2346#else
2347 (char_u *)NULL, PV_NONE,
2348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2351#ifdef FEAT_RIGHTLEFT
2352 (char_u *)VAR_WIN, PV_RLC,
2353 {(char_u *)"search", (char_u *)NULL}
2354#else
2355 (char_u *)NULL, PV_NONE,
2356 {(char_u *)NULL, (char_u *)0L}
2357#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002359 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002360#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002361 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002362 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002363#else
2364 (char_u *)NULL, PV_NONE,
2365 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002366#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002367 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2369#ifdef FEAT_CMDL_INFO
2370 (char_u *)&p_ru, PV_NONE,
2371#else
2372 (char_u *)NULL, PV_NONE,
2373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2376#ifdef FEAT_STL_OPT
2377 (char_u *)&p_ruf, PV_NONE,
2378#else
2379 (char_u *)NULL, PV_NONE,
2380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002382 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2383 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2386 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2388 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002389 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2391#ifdef FEAT_SCROLLBIND
2392 (char_u *)VAR_WIN, PV_SCBIND,
2393#else
2394 (char_u *)NULL, PV_NONE,
2395#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2398 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2401 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002403 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404#ifdef FEAT_SCROLLBIND
2405 (char_u *)&p_sbo, PV_NONE,
2406 {(char_u *)"ver,jump", (char_u *)0L}
2407#else
2408 (char_u *)NULL, PV_NONE,
2409 {(char_u *)0L, (char_u *)0L}
2410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"sections", "sect", P_STRING|P_VI_DEF,
2413 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002414 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2415 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2417 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002421 {(char_u *)"inclusive", (char_u *)0L}
2422 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002423 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002426 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427#ifdef FEAT_SESSION
2428 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002429 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 (char_u *)0L}
2431#else
2432 (char_u *)NULL, PV_NONE,
2433 {(char_u *)0L, (char_u *)0L}
2434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2437 (char_u *)&p_sh, PV_NONE,
2438 {
2439#ifdef VMS
2440 (char_u *)"-",
2441#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002442# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002444# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446# endif
2447#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2450 (char_u *)&p_shcf, PV_NONE,
2451 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002452#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 (char_u *)"/c",
2454#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002457 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2459#ifdef FEAT_QUICKFIX
2460 (char_u *)&p_sp, PV_NONE,
2461 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002462#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464#else
2465 (char_u *)">",
2466#endif
2467 (char_u *)0L}
2468#else
2469 (char_u *)NULL, PV_NONE,
2470 {(char_u *)0L, (char_u *)0L}
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2474 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2477 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2480#ifdef BACKSLASH_IN_FILENAME
2481 (char_u *)&p_ssl, PV_NONE,
2482#else
2483 (char_u *)NULL, PV_NONE,
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002486 {"shelltemp", "stmp", P_BOOL,
2487 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002488 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 {"shelltype", "st", P_NUM|P_VI_DEF,
2490#ifdef AMIGA
2491 (char_u *)&p_st, PV_NONE,
2492#else
2493 (char_u *)NULL, PV_NONE,
2494#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002495 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2497 (char_u *)&p_sxq, PV_NONE,
2498 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002499#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 (char_u *)"\"",
2501#else
2502 (char_u *)"",
2503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002505 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2506 (char_u *)&p_sxe, PV_NONE,
2507 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002508#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002509 (char_u *)"\"&|<>()@^",
2510#else
2511 (char_u *)"",
2512#endif
2513 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2515 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002516 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2518 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2521 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)"", (char_u *)"filnxtToO"}
2523 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2528#ifdef FEAT_LINEBREAK
2529 (char_u *)&p_sbr, PV_NONE,
2530#else
2531 (char_u *)NULL, PV_NONE,
2532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"showcmd", "sc", P_BOOL|P_VIM,
2535#ifdef FEAT_CMDL_INFO
2536 (char_u *)&p_sc, PV_NONE,
2537#else
2538 (char_u *)NULL, PV_NONE,
2539#endif
2540 {(char_u *)FALSE,
2541#ifdef UNIX
2542 (char_u *)FALSE
2543#else
2544 (char_u *)TRUE
2545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2548 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002549 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2551 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 {"showmode", "smd", P_BOOL|P_VIM,
2554 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002556 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002557 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2560 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2563 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002565 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2566#ifdef FEAT_SIGNS
2567 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002568 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002569#else
2570 (char_u *)NULL, PV_NONE,
2571 {(char_u *)NULL, (char_u *)0L}
2572#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002573 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2575 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2578 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2581#ifdef FEAT_SMARTINDENT
2582 (char_u *)&p_si, PV_SI,
2583#else
2584 (char_u *)NULL, PV_NONE,
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2588 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2591 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002592 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2594 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002595 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002596 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002597#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002598 (char_u *)VAR_WIN, PV_SPELL,
2599#else
2600 (char_u *)NULL, PV_NONE,
2601#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002602 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002603 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002604#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002605 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002606 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002607#else
2608 (char_u *)NULL, PV_NONE,
2609 {(char_u *)0L, (char_u *)0L}
2610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002612 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2613 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002614#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002615 (char_u *)&p_spf, PV_SPF,
2616 {(char_u *)"", (char_u *)0L}
2617#else
2618 (char_u *)NULL, PV_NONE,
2619 {(char_u *)0L, (char_u *)0L}
2620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002622 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2623 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002624#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002625 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002626 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002627#else
2628 (char_u *)NULL, PV_NONE,
2629 {(char_u *)0L, (char_u *)0L}
2630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002632 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002633#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002634 (char_u *)&p_sps, PV_NONE,
2635 {(char_u *)"best", (char_u *)0L}
2636#else
2637 (char_u *)NULL, PV_NONE,
2638 {(char_u *)0L, (char_u *)0L}
2639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2648 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2651#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002652 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653#else
2654 (char_u *)NULL, PV_NONE,
2655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002657 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 (char_u *)&p_su, PV_NONE,
2659 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002661 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002662#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 (char_u *)&p_sua, PV_SUA,
2664 {(char_u *)"", (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2671 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {"swapsync", "sws", P_STRING|P_VI_DEF,
2674 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002676 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002679 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2680#ifdef FEAT_SYN_HL
2681 (char_u *)&p_smc, PV_SMC,
2682 {(char_u *)3000L, (char_u *)0L}
2683#else
2684 (char_u *)NULL, PV_NONE,
2685 {(char_u *)0L, (char_u *)0L}
2686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002688 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689#ifdef FEAT_SYN_HL
2690 (char_u *)&p_syn, PV_SYN,
2691 {(char_u *)"", (char_u *)0L}
2692#else
2693 (char_u *)NULL, PV_NONE,
2694 {(char_u *)0L, (char_u *)0L}
2695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002697 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2698#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002699 (char_u *)&p_tal, PV_NONE,
2700#else
2701 (char_u *)NULL, PV_NONE,
2702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002704 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002705 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2708 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002709 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2711 (char_u *)&p_tbs, PV_NONE,
2712#ifdef VMS /* binary searching doesn't appear to work on VMS */
2713 {(char_u *)0L, (char_u *)0L}
2714#else
2715 {(char_u *)TRUE, (char_u *)0L}
2716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002718 {"tagcase", "tc", P_STRING|P_VIM,
2719 (char_u *)&p_tc, PV_TC,
2720 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"taglength", "tl", P_NUM|P_VI_DEF,
2722 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"tagrelative", "tr", P_BOOL|P_VIM,
2725 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002727 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002728 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {
2730#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2731 (char_u *)"./tags,./TAGS,tags,TAGS",
2732#else
2733 (char_u *)"./tags,tags",
2734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2737 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002739 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002740#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002741 (char_u *)&p_tcldll, PV_NONE,
2742 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002743#else
2744 (char_u *)NULL, PV_NONE,
2745 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002746#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2749 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002750 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2752#ifdef FEAT_ARABIC
2753 (char_u *)&p_tbidi, PV_NONE,
2754#else
2755 (char_u *)NULL, PV_NONE,
2756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002757 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2759#ifdef FEAT_MBYTE
2760 (char_u *)&p_tenc, PV_NONE,
2761 {(char_u *)"", (char_u *)0L}
2762#else
2763 (char_u *)NULL, PV_NONE,
2764 {(char_u *)0L, (char_u *)0L}
2765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002767 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2768#ifdef FEAT_TERMGUICOLORS
2769 (char_u *)&p_tgc, PV_NONE,
2770 {(char_u *)FALSE, (char_u *)FALSE}
2771#else
2772 (char_u*)NULL, PV_NONE,
2773 {(char_u *)FALSE, (char_u *)FALSE}
2774#endif
2775 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002776 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2777#ifdef FEAT_TERMINAL
2778 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002779 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002780#else
2781 (char_u *)NULL, PV_NONE,
2782 {(char_u *)NULL, (char_u *)0L}
2783#endif
2784 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002785 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2786#ifdef FEAT_TERMINAL
2787 (char_u *)VAR_WIN, PV_TMS,
2788 {(char_u *)"", (char_u *)NULL}
2789#else
2790 (char_u *)NULL, PV_NONE,
2791 {(char_u *)NULL, (char_u *)0L}
2792#endif
2793 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 {"terse", NULL, P_BOOL|P_VI_DEF,
2795 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 {"textauto", "ta", P_BOOL|P_VIM,
2798 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2800 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2802 (char_u *)&p_tx, PV_TX,
2803 {
2804#ifdef USE_CRNL
2805 (char_u *)TRUE,
2806#else
2807 (char_u *)FALSE,
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002810 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002813 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002815 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816#else
2817 (char_u *)NULL, PV_NONE,
2818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2821 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"timeout", "to", P_BOOL|P_VI_DEF,
2824 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2827 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"title", NULL, P_BOOL|P_VI_DEF,
2830#ifdef FEAT_TITLE
2831 (char_u *)&p_title, PV_NONE,
2832#else
2833 (char_u *)NULL, PV_NONE,
2834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002835 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"titlelen", NULL, P_NUM|P_VI_DEF,
2837#ifdef FEAT_TITLE
2838 (char_u *)&p_titlelen, PV_NONE,
2839#else
2840 (char_u *)NULL, PV_NONE,
2841#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002843 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844#ifdef FEAT_TITLE
2845 (char_u *)&p_titleold, PV_NONE,
2846 {(char_u *)N_("Thanks for flying Vim"),
2847 (char_u *)0L}
2848#else
2849 (char_u *)NULL, PV_NONE,
2850 {(char_u *)0L, (char_u *)0L}
2851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"titlestring", NULL, P_STRING|P_VI_DEF,
2854#ifdef FEAT_TITLE
2855 (char_u *)&p_titlestring, PV_NONE,
2856#else
2857 (char_u *)NULL, PV_NONE,
2858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002860 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002861#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002863 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002864#else
2865 (char_u *)NULL, PV_NONE,
2866 {(char_u *)0L, (char_u *)0L}
2867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002868 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002870#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002872 {(char_u *)"small", (char_u *)0L}
2873#else
2874 (char_u *)NULL, PV_NONE,
2875 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002877 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2879 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002880 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2882 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2885 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2888 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002889 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2891#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2892 (char_u *)&p_ttym, PV_NONE,
2893#else
2894 (char_u *)NULL, PV_NONE,
2895#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002896 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2898 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002899 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2901 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002902 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002903 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2904 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002905#ifdef FEAT_PERSISTENT_UNDO
2906 (char_u *)&p_udir, PV_NONE,
2907 {(char_u *)".", (char_u *)0L}
2908#else
2909 (char_u *)NULL, PV_NONE,
2910 {(char_u *)0L, (char_u *)0L}
2911#endif
2912 SCRIPTID_INIT},
2913 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2914#ifdef FEAT_PERSISTENT_UNDO
2915 (char_u *)&p_udf, PV_UDF,
2916#else
2917 (char_u *)NULL, PV_NONE,
2918#endif
2919 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002921 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002923#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 (char_u *)1000L,
2925#else
2926 (char_u *)100L,
2927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002928 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002929 {"undoreload", "ur", P_NUM|P_VI_DEF,
2930 (char_u *)&p_ur, PV_NONE,
2931 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 {"updatecount", "uc", P_NUM|P_VI_DEF,
2933 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935 {"updatetime", "ut", P_NUM|P_VI_DEF,
2936 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002937 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938 {"verbose", "vbs", P_NUM|P_VI_DEF,
2939 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002940 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002941 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2942 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002943 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2945#ifdef FEAT_SESSION
2946 (char_u *)&p_vdir, PV_NONE,
2947 {(char_u *)DFLT_VDIR, (char_u *)0L}
2948#else
2949 (char_u *)NULL, PV_NONE,
2950 {(char_u *)0L, (char_u *)0L}
2951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002952 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002953 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954#ifdef FEAT_SESSION
2955 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002956 {(char_u *)"folds,options,cursor,curdir",
2957 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958#else
2959 (char_u *)NULL, PV_NONE,
2960 {(char_u *)0L, (char_u *)0L}
2961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002962 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002963 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964#ifdef FEAT_VIMINFO
2965 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002966#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002967 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968#else
2969# ifdef AMIGA
2970 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002971 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002973 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974# endif
2975#endif
2976#else
2977 (char_u *)NULL, PV_NONE,
2978 {(char_u *)0L, (char_u *)0L}
2979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002980 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002981 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2982#ifdef FEAT_VIMINFO
2983 (char_u *)&p_viminfofile, PV_NONE,
2984 {(char_u *)"", (char_u *)0L}
2985#else
2986 (char_u *)NULL, PV_NONE,
2987 {(char_u *)0L, (char_u *)0L}
2988#endif
2989 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002990 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2991 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992#ifdef FEAT_VIRTUALEDIT
2993 (char_u *)&p_ve, PV_NONE,
2994 {(char_u *)"", (char_u *)""}
2995#else
2996 (char_u *)NULL, PV_NONE,
2997 {(char_u *)0L, (char_u *)0L}
2998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3001 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003002 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 {"w300", NULL, P_NUM|P_VI_DEF,
3004 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003005 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 {"w1200", NULL, P_NUM|P_VI_DEF,
3007 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003008 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 {"w9600", NULL, P_NUM|P_VI_DEF,
3010 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 {"warn", NULL, P_BOOL|P_VI_DEF,
3013 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003014 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3016 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003017 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003018 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 {"wildchar", "wc", P_NUM|P_VIM,
3022 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003023 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3024 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003025 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003027 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003028 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029#ifdef FEAT_WILDIGN
3030 (char_u *)&p_wig, PV_NONE,
3031#else
3032 (char_u *)NULL, PV_NONE,
3033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003034 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003035 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3036 (char_u *)&p_wic, PV_NONE,
3037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3039#ifdef FEAT_WILDMENU
3040 (char_u *)&p_wmnu, PV_NONE,
3041#else
3042 (char_u *)NULL, PV_NONE,
3043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003044 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003045 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003047 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003048 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3049#ifdef FEAT_CMDL_COMPL
3050 (char_u *)&p_wop, PV_NONE,
3051 {(char_u *)"", (char_u *)0L}
3052#else
3053 (char_u *)NULL, PV_NONE,
3054 {(char_u *)NULL, (char_u *)0L}
3055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3058#ifdef FEAT_WAK
3059 (char_u *)&p_wak, PV_NONE,
3060 {(char_u *)"menu", (char_u *)0L}
3061#else
3062 (char_u *)NULL, PV_NONE,
3063 {(char_u *)NULL, (char_u *)0L}
3064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003065 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003067 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003068 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003071 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003074 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003075 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003076 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003077 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003080 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003083 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003084 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003085#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003086 (char_u *)&p_winptydll, PV_NONE, {
3087# ifdef _WIN64
3088 (char_u *)"winpty64.dll",
3089# else
3090 (char_u *)"winpty32.dll",
3091# endif
3092 (char_u *)0L}
3093#else
3094 (char_u *)NULL, PV_NONE,
3095 {(char_u *)0L, (char_u *)0L}
3096#endif
3097 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003100 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3102 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003103 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3105 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003106 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3108 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003109 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 {"write", NULL, P_BOOL|P_VI_DEF,
3111 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003112 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 {"writeany", "wa", P_BOOL|P_VI_DEF,
3114 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003115 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3117 (char_u *)&p_wb, PV_NONE,
3118 {
3119#ifdef FEAT_WRITEBACKUP
3120 (char_u *)TRUE,
3121#else
3122 (char_u *)FALSE,
3123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003124 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 {"writedelay", "wd", P_NUM|P_VI_DEF,
3126 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003127 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128
3129/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003130#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003132 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133
3134 p_term("t_AB", T_CAB)
3135 p_term("t_AF", T_CAF)
3136 p_term("t_AL", T_CAL)
3137 p_term("t_al", T_AL)
3138 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003139 p_term("t_BE", T_BE)
3140 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_cd", T_CD)
3142 p_term("t_ce", T_CE)
3143 p_term("t_cl", T_CL)
3144 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003145 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 p_term("t_Co", T_CCO)
3147 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003148 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_da", T_DA)
3152 p_term("t_db", T_DB)
3153 p_term("t_DL", T_CDL)
3154 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003155 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003156 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003158 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 p_term("t_IE", T_CIE)
3160 p_term("t_IS", T_CIS)
3161 p_term("t_ke", T_KE)
3162 p_term("t_ks", T_KS)
3163 p_term("t_le", T_LE)
3164 p_term("t_mb", T_MB)
3165 p_term("t_md", T_MD)
3166 p_term("t_me", T_ME)
3167 p_term("t_mr", T_MR)
3168 p_term("t_ms", T_MS)
3169 p_term("t_nd", T_ND)
3170 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003171 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003172 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003173 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003175 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 p_term("t_RV", T_CRV)
3177 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003178 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003180 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003181 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003182 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003184 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003186 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187 p_term("t_te", T_TE)
3188 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003189 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003190 p_term("t_ts", T_TS)
3191 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192 p_term("t_ue", T_UE)
3193 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003194 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195 p_term("t_vb", T_VB)
3196 p_term("t_ve", T_VE)
3197 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003198 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 p_term("t_vs", T_VS)
3200 p_term("t_WP", T_CWP)
3201 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003202 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203 p_term("t_xs", T_XS)
3204 p_term("t_ZH", T_CZH)
3205 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003206 p_term("t_8f", T_8F)
3207 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208
3209/* terminal key codes are not in here */
3210
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003211 /* end marker */
3212 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213};
3214
3215#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3216
3217#ifdef FEAT_MBYTE
3218static char *(p_ambw_values[]) = {"single", "double", NULL};
3219#endif
3220static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003221static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003223#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003224static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003225#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003226#ifdef FEAT_CMDL_COMPL
3227static char *(p_wop_values[]) = {"tagfile", NULL};
3228#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229#ifdef FEAT_WAK
3230static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3231#endif
3232static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3234static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236#ifdef FEAT_BROWSE
3237static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3238#endif
3239#ifdef FEAT_SCROLLBIND
3240static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3241#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003242static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003244#ifdef FEAT_AUTOCMD
3245static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3246#else
3247static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003249static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3251#ifdef FEAT_FOLDING
3252static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003253# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003255# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256 NULL};
3257static char *(p_fcl_values[]) = {"all", NULL};
3258#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003259#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003260static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003261#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003262#ifdef FEAT_SIGNS
3263static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static void set_option_default(int, int opt_flags, int compatible);
3267static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003268static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003269static char_u *term_bg_default(void);
3270static void did_set_option(int opt_idx, int opt_flags, int new_value);
3271static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274#endif
3275#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003278static char_u *option_expand(int opt_idx, char_u *val);
3279static void didset_options(void);
3280static void didset_options2(void);
3281static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003282#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003284#else
3285# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3286#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static void set_string_option_global(int opt_idx, char_u **varp);
3288static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3289static 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);
3290static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003291#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003292static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003295static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003297#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003298static char_u *did_set_spell_option(int is_spellfile);
3299static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003300#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003301#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003303#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003304static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3305static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3306static void check_redraw(long_u flags);
3307static int findoption(char_u *);
3308static int find_key_option(char_u *);
3309static void showoptions(int all, int opt_flags);
3310static int optval_default(struct vimoption *, char_u *varp);
3311static void showoneopt(struct vimoption *, int opt_flags);
3312static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3313static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3314static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3315static int istermoption(struct vimoption *);
3316static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3317static char_u *get_varp(struct vimoption *);
3318static void option_value2string(struct vimoption *, int opt_flags);
3319static void check_winopt(winopt_T *wop);
3320static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003322static void langmap_init(void);
3323static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003325static void paste_option_changed(void);
3326static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003327#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003328static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003330static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3331static int check_opt_strings(char_u *val, char **values, int);
3332static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003333#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003334static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003335#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336
3337/*
3338 * Initialize the options, first part.
3339 *
3340 * Called only once from main(), just after creating the first buffer.
3341 */
3342 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003343set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344{
3345 char_u *p;
3346 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003347 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348
3349#ifdef FEAT_LANGMAP
3350 langmap_init();
3351#endif
3352
3353 /* Be Vi compatible by default */
3354 p_cp = TRUE;
3355
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003356 /* Use POSIX compatibility when $VIM_POSIX is set. */
3357 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003358 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003359 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003360 set_string_default("shm", (char_u *)"A");
3361 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003362
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363 /*
3364 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003365 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003367 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003368#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003369 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003370# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003371 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372# endif
3373#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003374 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003375 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376
3377#ifdef FEAT_WILDIGN
3378 /*
3379 * Set the default for 'backupskip' to include environment variables for
3380 * temp files.
3381 */
3382 {
3383# ifdef UNIX
3384 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3385# else
3386 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3387# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003388 int len;
3389 garray_T ga;
3390 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391
3392 ga_init2(&ga, 1, 100);
3393 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3394 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003395 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396# ifdef UNIX
3397 if (*names[n] == NUL)
3398 p = (char_u *)"/tmp";
3399 else
3400# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003401 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402 if (p != NULL && *p != NUL)
3403 {
3404 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003405 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406 if (ga_grow(&ga, len) == OK)
3407 {
3408 if (ga.ga_len > 0)
3409 STRCAT(ga.ga_data, ",");
3410 STRCAT(ga.ga_data, p);
3411 add_pathsep(ga.ga_data);
3412 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 ga.ga_len += len;
3414 }
3415 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003416 if (mustfree)
3417 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 }
3419 if (ga.ga_data != NULL)
3420 {
3421 set_string_default("bsk", ga.ga_data);
3422 vim_free(ga.ga_data);
3423 }
3424 }
3425#endif
3426
3427 /*
3428 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3429 */
3430 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003431 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003433#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3434 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3435#endif
3436 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003438 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003439 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440#else
3441# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003442 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003443 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003445 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003446# endif
3447#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003449 opt_idx = findoption((char_u *)"maxmem");
3450 if (opt_idx >= 0)
3451 {
3452#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003453 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3454 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003455#endif
3456 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3457 }
3458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459 }
3460
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461#ifdef FEAT_SEARCHPATH
3462 {
3463 char_u *cdpath;
3464 char_u *buf;
3465 int i;
3466 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003467 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468
3469 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003470 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471 if (cdpath != NULL)
3472 {
3473 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3474 if (buf != NULL)
3475 {
3476 buf[0] = ','; /* start with ",", current dir first */
3477 j = 1;
3478 for (i = 0; cdpath[i] != NUL; ++i)
3479 {
3480 if (vim_ispathlistsep(cdpath[i]))
3481 buf[j++] = ',';
3482 else
3483 {
3484 if (cdpath[i] == ' ' || cdpath[i] == ',')
3485 buf[j++] = '\\';
3486 buf[j++] = cdpath[i];
3487 }
3488 }
3489 buf[j] = NUL;
3490 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003491 if (opt_idx >= 0)
3492 {
3493 options[opt_idx].def_val[VI_DEFAULT] = buf;
3494 options[opt_idx].flags |= P_DEF_ALLOCED;
3495 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003496 else
3497 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003499 if (mustfree)
3500 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003501 }
3502 }
3503#endif
3504
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003505#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506 /* Set print encoding on platforms that don't default to latin1 */
3507 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003508# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509 (char_u *)"cp1252"
3510# else
3511# ifdef VMS
3512 (char_u *)"dec-mcs"
3513# else
3514# ifdef EBCDIC
3515 (char_u *)"ebcdic-uk"
3516# else
3517# ifdef MAC
3518 (char_u *)"mac-roman"
3519# else /* HPUX */
3520 (char_u *)"hp-roman8"
3521# endif
3522# endif
3523# endif
3524# endif
3525 );
3526#endif
3527
3528#ifdef FEAT_POSTSCRIPT
3529 /* 'printexpr' must be allocated to be able to evaluate it. */
3530 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003531# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003532 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533# else
3534# ifdef VMS
3535 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3536
3537# else
3538 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3539# endif
3540# endif
3541 );
3542#endif
3543
3544 /*
3545 * Set all the options (except the terminal options) to their default
3546 * value. Also set the global value for local options.
3547 */
3548 set_options_default(0);
3549
3550#ifdef FEAT_GUI
3551 if (found_reverse_arg)
3552 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3553#endif
3554
3555 curbuf->b_p_initialized = TRUE;
3556 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003557 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558 check_buf_options(curbuf);
3559 check_win_options(curwin);
3560 check_options();
3561
3562 /* Must be before option_expand(), because that one needs vim_isIDc() */
3563 didset_options();
3564
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003565#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003566 /* Use the current chartab for the generic chartab. This is not in
3567 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003568 init_spell_chartab();
3569#endif
3570
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571 /*
3572 * Expand environment variables and things like "~" for the defaults.
3573 * If option_expand() returns non-NULL the variable is expanded. This can
3574 * only happen for non-indirect options.
3575 * Also set the default to the expanded value, so ":set" does not list
3576 * them.
3577 * Don't set the P_ALLOCED flag, because we don't want to free the
3578 * default.
3579 */
3580 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3581 {
3582 if ((options[opt_idx].flags & P_GETTEXT)
3583 && options[opt_idx].var != NULL)
3584 p = (char_u *)_(*(char **)options[opt_idx].var);
3585 else
3586 p = option_expand(opt_idx, NULL);
3587 if (p != NULL && (p = vim_strsave(p)) != NULL)
3588 {
3589 *(char_u **)options[opt_idx].var = p;
3590 /* VIMEXP
3591 * Defaults for all expanded options are currently the same for Vi
3592 * and Vim. When this changes, add some code here! Also need to
3593 * split P_DEF_ALLOCED in two.
3594 */
3595 if (options[opt_idx].flags & P_DEF_ALLOCED)
3596 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3597 options[opt_idx].def_val[VI_DEFAULT] = p;
3598 options[opt_idx].flags |= P_DEF_ALLOCED;
3599 }
3600 }
3601
Bram Moolenaar071d4272004-06-13 20:20:40 +00003602 save_file_ff(curbuf); /* Buffer is unchanged */
3603
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604#if defined(FEAT_ARABIC)
3605 /* Detect use of mlterm.
3606 * Mlterm is a terminal emulator akin to xterm that has some special
3607 * abilities (bidi namely).
3608 * NOTE: mlterm's author is being asked to 'set' a variable
3609 * instead of an environment variable due to inheritance.
3610 */
3611 if (mch_getenv((char_u *)"MLTERM") != NULL)
3612 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3613#endif
3614
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003615 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003616
3617#ifdef FEAT_MBYTE
3618# if defined(WIN3264) && defined(FEAT_GETTEXT)
3619 /*
3620 * If $LANG isn't set, try to get a good value for it. This makes the
3621 * right language be used automatically. Don't do this for English.
3622 */
3623 if (mch_getenv((char_u *)"LANG") == NULL)
3624 {
3625 char buf[20];
3626
3627 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3628 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3629 * only the first two. */
3630 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3631 (LPTSTR)buf, 20);
3632 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3633 {
3634 /* There are a few exceptions (probably more) */
3635 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3636 STRCPY(buf, "zh_TW");
3637 else if (STRNICMP(buf, "chs", 3) == 0
3638 || STRNICMP(buf, "zhc", 3) == 0)
3639 STRCPY(buf, "zh_CN");
3640 else if (STRNICMP(buf, "jp", 2) == 0)
3641 STRCPY(buf, "ja");
3642 else
3643 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003644 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003645 }
3646 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003647# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003648# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003649 /* Moved to os_mac_conv.c to avoid dependency problems. */
3650 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003651# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652# endif
3653
3654 /* enc_locale() will try to find the encoding of the current locale. */
3655 p = enc_locale();
3656 if (p != NULL)
3657 {
3658 char_u *save_enc;
3659
3660 /* Try setting 'encoding' and check if the value is valid.
3661 * If not, go back to the default "latin1". */
3662 save_enc = p_enc;
3663 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003664 if (STRCMP(p_enc, "gb18030") == 0)
3665 {
3666 /* We don't support "gb18030", but "cp936" is a good substitute
3667 * for practical purposes, thus use that. It's not an alias to
3668 * still support conversion between gb18030 and utf-8. */
3669 p_enc = vim_strsave((char_u *)"cp936");
3670 vim_free(p);
3671 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003672 if (mb_init() == NULL)
3673 {
3674 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003675 if (opt_idx >= 0)
3676 {
3677 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3678 options[opt_idx].flags |= P_DEF_ALLOCED;
3679 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680
Bram Moolenaard0573012017-10-28 21:11:06 +02003681#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003682 if (STRCMP(p_enc, "latin1") == 0
3683# ifdef FEAT_MBYTE
3684 || enc_utf8
3685# endif
3686 )
3687 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003688 /* Adjust the default for 'isprint' and 'iskeyword' to match
3689 * latin1. Also set the defaults for when 'nocompatible' is
3690 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003691 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003692 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003693 set_string_option_direct((char_u *)"isk", -1,
3694 ISK_LATIN1, OPT_FREE, SID_NONE);
3695 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003696 if (opt_idx >= 0)
3697 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003698 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003701 (void)init_chartab();
3702 }
3703#endif
3704
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705# if defined(WIN3264) && !defined(FEAT_GUI)
3706 /* Win32 console: When GetACP() returns a different value from
3707 * GetConsoleCP() set 'termencoding'. */
3708 if (GetACP() != GetConsoleCP())
3709 {
3710 char buf[50];
3711
3712 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3713 p_tenc = vim_strsave((char_u *)buf);
3714 if (p_tenc != NULL)
3715 {
3716 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003717 if (opt_idx >= 0)
3718 {
3719 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3720 options[opt_idx].flags |= P_DEF_ALLOCED;
3721 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 convert_setup(&input_conv, p_tenc, p_enc);
3723 convert_setup(&output_conv, p_enc, p_tenc);
3724 }
3725 else
3726 p_tenc = empty_option;
3727 }
3728# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003729# if defined(WIN3264) && defined(FEAT_MBYTE)
3730 /* $HOME may have characters in active code page. */
3731 init_homedir();
3732# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 }
3734 else
3735 {
3736 vim_free(p_enc);
3737 p_enc = save_enc;
3738 }
3739 }
3740#endif
3741
3742#ifdef FEAT_MULTI_LANG
3743 /* Set the default for 'helplang'. */
3744 set_helplang_default(get_mess_lang());
3745#endif
3746}
3747
3748/*
3749 * Set an option to its default value.
3750 * This does not take care of side effects!
3751 */
3752 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003753set_option_default(
3754 int opt_idx,
3755 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3756 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757{
3758 char_u *varp; /* pointer to variable for current option */
3759 int dvi; /* index in def_val[] */
3760 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003761 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3763
3764 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3765 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003766 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003767 {
3768 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3769 if (flags & P_STRING)
3770 {
3771 /* Use set_string_option_direct() for local options to handle
3772 * freeing and allocating the value. */
3773 if (options[opt_idx].indir != PV_NONE)
3774 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003775 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 else
3777 {
3778 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3779 free_string_option(*(char_u **)(varp));
3780 *(char_u **)varp = options[opt_idx].def_val[dvi];
3781 options[opt_idx].flags &= ~P_ALLOCED;
3782 }
3783 }
3784 else if (flags & P_NUM)
3785 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003786 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 win_comp_scroll(curwin);
3788 else
3789 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003790 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791 /* May also set global value for local option. */
3792 if (both)
3793 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3794 *(long *)varp;
3795 }
3796 }
3797 else /* P_BOOL */
3798 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003799 /* the cast to long is required for Manx C, long_i is needed for
3800 * MSVC */
3801 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003802#ifdef UNIX
3803 /* 'modeline' defaults to off for root */
3804 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3805 *(int *)varp = FALSE;
3806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 /* May also set global value for local option. */
3808 if (both)
3809 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3810 *(int *)varp;
3811 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003812
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003813 /* The default value is not insecure. */
3814 flagsp = insecure_flag(opt_idx, opt_flags);
3815 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816 }
3817
3818#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003819 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820#endif
3821}
3822
3823/*
3824 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003825 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 */
3827 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003828set_options_default(
3829 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830{
3831 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003832 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003833 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834
3835 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003836 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003837#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003838 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003839 || (TRUE
3840# if defined(FEAT_MBYTE)
3841 && options[i].var != (char_u *)&p_enc
3842# endif
3843# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003844 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003845 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003846# endif
3847 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003848#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003849 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850 set_option_default(i, opt_flags, p_cp);
3851
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003853 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003855#ifdef FEAT_CINDENT
3856 parse_cino(curbuf);
3857#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858}
3859
3860/*
3861 * Set the Vi-default value of a string option.
3862 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003863 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003865 static void
3866set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867{
3868 char_u *p;
3869 int opt_idx;
3870
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003871 if (escape && vim_strchr(val, ' ') != NULL)
3872 p = vim_strsave_escaped(val, (char_u *)" ");
3873 else
3874 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 if (p != NULL) /* we don't want a NULL */
3876 {
3877 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003878 if (opt_idx >= 0)
3879 {
3880 if (options[opt_idx].flags & P_DEF_ALLOCED)
3881 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3882 options[opt_idx].def_val[VI_DEFAULT] = p;
3883 options[opt_idx].flags |= P_DEF_ALLOCED;
3884 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885 }
3886}
3887
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003888 void
3889set_string_default(char *name, char_u *val)
3890{
3891 set_string_default_esc(name, val, FALSE);
3892}
3893
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894/*
3895 * Set the Vi-default value of a number option.
3896 * Used for 'lines' and 'columns'.
3897 */
3898 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003899set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003901 int opt_idx;
3902
3903 opt_idx = findoption((char_u *)name);
3904 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003905 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906}
3907
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003908#if defined(EXITFREE) || defined(PROTO)
3909/*
3910 * Free all options.
3911 */
3912 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003913free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003914{
3915 int i;
3916
3917 for (i = 0; !istermoption(&options[i]); i++)
3918 {
3919 if (options[i].indir == PV_NONE)
3920 {
3921 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003922 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003923 free_string_option(*(char_u **)options[i].var);
3924 if (options[i].flags & P_DEF_ALLOCED)
3925 free_string_option(options[i].def_val[VI_DEFAULT]);
3926 }
3927 else if (options[i].var != VAR_WIN
3928 && (options[i].flags & P_STRING))
3929 /* buffer-local option: free global value */
3930 free_string_option(*(char_u **)options[i].var);
3931 }
3932}
3933#endif
3934
3935
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936/*
3937 * Initialize the options, part two: After getting Rows and Columns and
3938 * setting 'term'.
3939 */
3940 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003941set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003943 int idx;
3944
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003946 * 'scroll' defaults to half the window height. The stored default is zero,
3947 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003949 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003950 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003951 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 comp_col();
3953
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003954 /*
3955 * 'window' is only for backwards compatibility with Vi.
3956 * Default is Rows - 1.
3957 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003958 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003959 p_window = Rows - 1;
3960 set_number_default("window", Rows - 1);
3961
Bram Moolenaarf740b292006-02-16 22:11:02 +00003962 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003963#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003964 /*
3965 * If 'background' wasn't set by the user, try guessing the value,
3966 * depending on the terminal name. Only need to check for terminals
3967 * with a dark background, that can handle color.
3968 */
3969 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003970 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3971 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003973 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003974 /* don't mark it as set, when starting the GUI it may be
3975 * changed again */
3976 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 }
3978#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003979
3980#ifdef CURSOR_SHAPE
3981 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3982#endif
3983#ifdef FEAT_MOUSESHAPE
3984 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3985#endif
3986#ifdef FEAT_PRINTER
3987 (void)parse_printoptions(); /* parse 'printoptions' default value */
3988#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989}
3990
3991/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003992 * Return "dark" or "light" depending on the kind of terminal.
3993 * This is just guessing! Recognized are:
3994 * "linux" Linux console
3995 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003996 * "cygwin.*" Cygwin shell
3997 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003998 * We also check the COLORFGBG environment variable, which is set by
3999 * rxvt and derivatives. This variable contains either two or three
4000 * values separated by semicolons; we want the last value in either
4001 * case. If this value is 0-6 or 8, our background is dark.
4002 */
4003 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004004term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004005{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004006#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004007 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004008 return (char_u *)"dark";
4009#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004010 char_u *p;
4011
Bram Moolenaarf740b292006-02-16 22:11:02 +00004012 if (STRCMP(T_NAME, "linux") == 0
4013 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004014 || STRNCMP(T_NAME, "cygwin", 6) == 0
4015 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004016 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4017 && (p = vim_strrchr(p, ';')) != NULL
4018 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4019 && p[2] == NUL))
4020 return (char_u *)"dark";
4021 return (char_u *)"light";
4022#endif
4023}
4024
4025/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026 * Initialize the options, part three: After reading the .vimrc
4027 */
4028 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004029set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004031#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032/*
4033 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4034 * This is done after other initializations, where 'shell' might have been
4035 * set, but only if they have not been set before.
4036 */
4037 char_u *p;
4038 int idx_srr;
4039 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004040# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041 int idx_sp;
4042 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004043# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044
4045 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004046 if (idx_srr < 0)
4047 do_srr = FALSE;
4048 else
4049 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004050# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004052 if (idx_sp < 0)
4053 do_sp = FALSE;
4054 else
4055 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004057 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 if (p != NULL)
4059 {
4060 /*
4061 * Default for p_sp is "| tee", for p_srr is ">".
4062 * For known shells it is changed here to include stderr.
4063 */
4064 if ( fnamecmp(p, "csh") == 0
4065 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004066# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 || fnamecmp(p, "csh.exe") == 0
4068 || fnamecmp(p, "tcsh.exe") == 0
4069# endif
4070 )
4071 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004072# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073 if (do_sp)
4074 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004075# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004077# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4081 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004082# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 if (do_srr)
4084 {
4085 p_srr = (char_u *)">&";
4086 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4087 }
4088 }
4089 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004090 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 if ( fnamecmp(p, "sh") == 0
4092 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004093 || fnamecmp(p, "mksh") == 0
4094 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004096 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004098 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004099# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 || fnamecmp(p, "cmd") == 0
4101 || fnamecmp(p, "sh.exe") == 0
4102 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004103 || fnamecmp(p, "mksh.exe") == 0
4104 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004106 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 || fnamecmp(p, "bash.exe") == 0
4108 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004110 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004112# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 if (do_sp)
4114 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004115# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004117# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4121 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004122# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 if (do_srr)
4124 {
4125 p_srr = (char_u *)">%s 2>&1";
4126 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4127 }
4128 }
4129 vim_free(p);
4130 }
4131#endif
4132
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004133#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004135 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4136 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 * This is done after other initializations, where 'shell' might have been
4138 * set, but only if they have not been set before. Default for p_shcf is
4139 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004140 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004142 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 {
4144 int idx3;
4145
4146 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004147 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 {
4149 p_shcf = (char_u *)"-c";
4150 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4151 }
4152
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 /* Somehow Win32 requires the quotes around the redirection too */
4154 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004155 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156 {
4157 p_sxq = (char_u *)"\"";
4158 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4159 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004161 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4162 {
4163 int idx3;
4164
4165 /*
4166 * cmd.exe on Windows will strip the first and last double quote given
4167 * on the command line, e.g. most of the time things like:
4168 * cmd /c "my path/to/echo" "my args to echo"
4169 * become:
4170 * my path/to/echo" "my args to echo
4171 * when executed.
4172 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004173 * To avoid this, set shellxquote to surround the command in
4174 * parenthesis. This appears to make most commands work, without
4175 * breaking commands that worked previously, such as
4176 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004177 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004178 idx3 = findoption((char_u *)"sxq");
4179 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4180 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004181 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004182 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4183 }
4184
Bram Moolenaara64ba222012-02-12 23:23:31 +01004185 idx3 = findoption((char_u *)"shcf");
4186 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4187 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004188 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004189 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4190 }
4191 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192#endif
4193
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004194 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004195 {
4196 int idx_ffs = findoption((char_u *)"ffs");
4197
4198 /* Apply the first entry of 'fileformats' to the initial buffer. */
4199 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4200 set_fileformat(default_fileformat(), OPT_LOCAL);
4201 }
4202
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203#ifdef FEAT_TITLE
4204 set_title_defaults();
4205#endif
4206}
4207
4208#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4209/*
4210 * When 'helplang' is still at its default value, set it to "lang".
4211 * Only the first two characters of "lang" are used.
4212 */
4213 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004214set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215{
4216 int idx;
4217
4218 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4219 return;
4220 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004221 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 {
4223 if (options[idx].flags & P_ALLOCED)
4224 free_string_option(p_hlg);
4225 p_hlg = vim_strsave(lang);
4226 if (p_hlg == NULL)
4227 p_hlg = empty_option;
4228 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004229 {
4230 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4231 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4232 {
4233 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4234 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004237 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238 options[idx].flags |= P_ALLOCED;
4239 }
4240}
4241#endif
4242
4243#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004244static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004245
4246 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004247gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248{
4249 if (gui_get_lightness(gui.back_pixel) < 127)
4250 return (char_u *)"dark";
4251 return (char_u *)"light";
4252}
4253
4254/*
4255 * Option initializations that can only be done after opening the GUI window.
4256 */
4257 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004258init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259{
4260 /* Set the 'background' option according to the lightness of the
4261 * background color, unless the user has set it already. */
4262 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4263 {
4264 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4265 highlight_changed();
4266 }
4267}
4268#endif
4269
4270#ifdef FEAT_TITLE
4271/*
4272 * 'title' and 'icon' only default to true if they have not been set or reset
4273 * in .vimrc and we can read the old value.
4274 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4275 * they can be reset. This reduces startup time when using X on a remote
4276 * machine.
4277 */
4278 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004279set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004280{
4281 int idx1;
4282 long val;
4283
4284 /*
4285 * If GUI is (going to be) used, we can always set the window title and
4286 * icon name. Saves a bit of time, because the X11 display server does
4287 * not need to be contacted.
4288 */
4289 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004290 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004291 {
4292#ifdef FEAT_GUI
4293 if (gui.starting || gui.in_use)
4294 val = TRUE;
4295 else
4296#endif
4297 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004298 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004299 p_title = val;
4300 }
4301 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004302 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303 {
4304#ifdef FEAT_GUI
4305 if (gui.starting || gui.in_use)
4306 val = TRUE;
4307 else
4308#endif
4309 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004310 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311 p_icon = val;
4312 }
4313}
4314#endif
4315
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004316#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4317 static void
4318trigger_optionsset_string(
4319 int opt_idx,
4320 int opt_flags,
4321 char_u *oldval,
4322 char_u *newval)
4323{
4324 if (oldval != NULL && newval != NULL)
4325 {
4326 char_u buf_type[7];
4327
4328 sprintf((char *)buf_type, "%s",
4329 (opt_flags & OPT_LOCAL) ? "local" : "global");
4330 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4331 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4332 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4333 apply_autocmds(EVENT_OPTIONSET,
4334 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4335 reset_v_option_vars();
4336 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004337}
4338#endif
4339
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340/*
4341 * Parse 'arg' for option settings.
4342 *
4343 * 'arg' may be IObuff, but only when no errors can be present and option
4344 * does not need to be expanded with option_expand().
4345 * "opt_flags":
4346 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004347 * OPT_GLOBAL for ":setglobal"
4348 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004350 * OPT_WINONLY to only set window-local options
4351 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004352 *
4353 * returns FAIL if an error is detected, OK otherwise
4354 */
4355 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004356do_set(
4357 char_u *arg, /* option string (may be written to!) */
4358 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359{
4360 int opt_idx;
4361 char_u *errmsg;
4362 char_u errbuf[80];
4363 char_u *startarg;
4364 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4365 int nextchar; /* next non-white char after option name */
4366 int afterchar; /* character just after option name */
4367 int len;
4368 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004369 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004370 int key;
4371 long_u flags; /* flags for current option */
4372 char_u *varp = NULL; /* pointer to variable for current option */
4373 int did_show = FALSE; /* already showed one value */
4374 int adding; /* "opt+=arg" */
4375 int prepending; /* "opt^=arg" */
4376 int removing; /* "opt-=arg" */
4377 int cp_val = 0;
4378 char_u key_name[2];
4379
4380 if (*arg == NUL)
4381 {
4382 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004383 did_show = TRUE;
4384 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 }
4386
4387 while (*arg != NUL) /* loop to process all options */
4388 {
4389 errmsg = NULL;
4390 startarg = arg; /* remember for error message */
4391
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004392 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4393 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394 {
4395 /*
4396 * ":set all" show all options.
4397 * ":set all&" set all options to their default value.
4398 */
4399 arg += 3;
4400 if (*arg == '&')
4401 {
4402 ++arg;
4403 /* Only for :set command set global value of local options. */
4404 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004405 didset_options();
4406 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004407 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 }
4409 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004410 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004412 did_show = TRUE;
4413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004415 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004416 {
4417 showoptions(2, opt_flags);
4418 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004419 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 arg += 7;
4421 }
4422 else
4423 {
4424 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004425 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004426 {
4427 prefix = 0;
4428 arg += 2;
4429 }
4430 else if (STRNCMP(arg, "inv", 3) == 0)
4431 {
4432 prefix = 2;
4433 arg += 3;
4434 }
4435
4436 /* find end of name */
4437 key = 0;
4438 if (*arg == '<')
4439 {
4440 nextchar = 0;
4441 opt_idx = -1;
4442 /* look out for <t_>;> */
4443 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4444 len = 5;
4445 else
4446 {
4447 len = 1;
4448 while (arg[len] != NUL && arg[len] != '>')
4449 ++len;
4450 }
4451 if (arg[len] != '>')
4452 {
4453 errmsg = e_invarg;
4454 goto skip;
4455 }
4456 arg[len] = NUL; /* put NUL after name */
4457 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4458 opt_idx = findoption(arg + 1);
4459 arg[len++] = '>'; /* restore '>' */
4460 if (opt_idx == -1)
4461 key = find_key_option(arg + 1);
4462 }
4463 else
4464 {
4465 len = 0;
4466 /*
4467 * The two characters after "t_" may not be alphanumeric.
4468 */
4469 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4470 len = 4;
4471 else
4472 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4473 ++len;
4474 nextchar = arg[len];
4475 arg[len] = NUL; /* put NUL after name */
4476 opt_idx = findoption(arg);
4477 arg[len] = nextchar; /* restore nextchar */
4478 if (opt_idx == -1)
4479 key = find_key_option(arg);
4480 }
4481
4482 /* remember character after option name */
4483 afterchar = arg[len];
4484
4485 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004486 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004487 ++len;
4488
4489 adding = FALSE;
4490 prepending = FALSE;
4491 removing = FALSE;
4492 if (arg[len] != NUL && arg[len + 1] == '=')
4493 {
4494 if (arg[len] == '+')
4495 {
4496 adding = TRUE; /* "+=" */
4497 ++len;
4498 }
4499 else if (arg[len] == '^')
4500 {
4501 prepending = TRUE; /* "^=" */
4502 ++len;
4503 }
4504 else if (arg[len] == '-')
4505 {
4506 removing = TRUE; /* "-=" */
4507 ++len;
4508 }
4509 }
4510 nextchar = arg[len];
4511
4512 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4513 {
4514 errmsg = (char_u *)N_("E518: Unknown option");
4515 goto skip;
4516 }
4517
4518 if (opt_idx >= 0)
4519 {
4520 if (options[opt_idx].var == NULL) /* hidden option: skip */
4521 {
4522 /* Only give an error message when requesting the value of
4523 * a hidden option, ignore setting it. */
4524 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4525 && (!(options[opt_idx].flags & P_BOOL)
4526 || nextchar == '?'))
4527 errmsg = (char_u *)N_("E519: Option not supported");
4528 goto skip;
4529 }
4530
4531 flags = options[opt_idx].flags;
4532 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4533 }
4534 else
4535 {
4536 flags = P_STRING;
4537 if (key < 0)
4538 {
4539 key_name[0] = KEY2TERMCAP0(key);
4540 key_name[1] = KEY2TERMCAP1(key);
4541 }
4542 else
4543 {
4544 key_name[0] = KS_KEY;
4545 key_name[1] = (key & 0xff);
4546 }
4547 }
4548
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004549 /* Skip all options that are not window-local (used when showing
4550 * an already loaded buffer in a window). */
4551 if ((opt_flags & OPT_WINONLY)
4552 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4553 goto skip;
4554
Bram Moolenaara3227e22006-03-08 21:32:40 +00004555 /* Skip all options that are window-local (used for :vimgrep). */
4556 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4557 && options[opt_idx].var == VAR_WIN)
4558 goto skip;
4559
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004560 /* Disallow changing some options from modelines. */
4561 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004563 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004564 {
4565 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4566 goto skip;
4567 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004568#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004569 /* In diff mode some options are overruled. This avoids that
4570 * 'foldmethod' becomes "marker" instead of "diff" and that
4571 * "wrap" gets set. */
4572 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004573 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004574 && (
4575#ifdef FEAT_FOLDING
4576 options[opt_idx].indir == PV_FDM ||
4577#endif
4578 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004579 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 }
4582
4583#ifdef HAVE_SANDBOX
4584 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004585 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004586 {
4587 errmsg = (char_u *)_(e_sandbox);
4588 goto skip;
4589 }
4590#endif
4591
4592 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4593 {
4594 arg += len;
4595 cp_val = p_cp;
4596 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4597 {
4598 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4599 {
4600 cp_val = FALSE;
4601 arg += 3;
4602 }
4603 else /* "opt&vi": set to Vi default */
4604 {
4605 cp_val = TRUE;
4606 arg += 2;
4607 }
4608 }
4609 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004610 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611 {
4612 errmsg = e_trailing;
4613 goto skip;
4614 }
4615 }
4616
4617 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004618 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4619 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004620 */
4621 if (nextchar == '?'
4622 || (prefix == 1
4623 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4624 && !(flags & P_BOOL)))
4625 {
4626 /*
4627 * print value
4628 */
4629 if (did_show)
4630 msg_putchar('\n'); /* cursor below last one */
4631 else
4632 {
4633 gotocmdline(TRUE); /* cursor at status line */
4634 did_show = TRUE; /* remember that we did a line */
4635 }
4636 if (opt_idx >= 0)
4637 {
4638 showoneopt(&options[opt_idx], opt_flags);
4639#ifdef FEAT_EVAL
4640 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004641 {
4642 /* Mention where the option was last set. */
4643 if (varp == options[opt_idx].var)
4644 last_set_msg(options[opt_idx].scriptID);
4645 else if ((int)options[opt_idx].indir & PV_WIN)
4646 last_set_msg(curwin->w_p_scriptID[
4647 (int)options[opt_idx].indir & PV_MASK]);
4648 else if ((int)options[opt_idx].indir & PV_BUF)
4649 last_set_msg(curbuf->b_p_scriptID[
4650 (int)options[opt_idx].indir & PV_MASK]);
4651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652#endif
4653 }
4654 else
4655 {
4656 char_u *p;
4657
4658 p = find_termcode(key_name);
4659 if (p == NULL)
4660 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004661 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004662 goto skip;
4663 }
4664 else
4665 (void)show_one_termcode(key_name, p, TRUE);
4666 }
4667 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004668 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004669 errmsg = e_trailing;
4670 }
4671 else
4672 {
4673 if (flags & P_BOOL) /* boolean */
4674 {
4675 if (nextchar == '=' || nextchar == ':')
4676 {
4677 errmsg = e_invarg;
4678 goto skip;
4679 }
4680
4681 /*
4682 * ":set opt!": invert
4683 * ":set opt&": reset to default value
4684 * ":set opt<": reset to global value
4685 */
4686 if (nextchar == '!')
4687 value = *(int *)(varp) ^ 1;
4688 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004689 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004690 ((flags & P_VI_DEF) || cp_val)
4691 ? VI_DEFAULT : VIM_DEFAULT];
4692 else if (nextchar == '<')
4693 {
4694 /* For 'autoread' -1 means to use global value. */
4695 if ((int *)varp == &curbuf->b_p_ar
4696 && opt_flags == OPT_LOCAL)
4697 value = -1;
4698 else
4699 value = *(int *)get_varp_scope(&(options[opt_idx]),
4700 OPT_GLOBAL);
4701 }
4702 else
4703 {
4704 /*
4705 * ":set invopt": invert
4706 * ":set opt" or ":set noopt": set or reset
4707 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004708 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004709 {
4710 errmsg = e_trailing;
4711 goto skip;
4712 }
4713 if (prefix == 2) /* inv */
4714 value = *(int *)(varp) ^ 1;
4715 else
4716 value = prefix;
4717 }
4718
4719 errmsg = set_bool_option(opt_idx, varp, (int)value,
4720 opt_flags);
4721 }
4722 else /* numeric or string */
4723 {
4724 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4725 || prefix != 1)
4726 {
4727 errmsg = e_invarg;
4728 goto skip;
4729 }
4730
4731 if (flags & P_NUM) /* numeric */
4732 {
4733 /*
4734 * Different ways to set a number option:
4735 * & set to default value
4736 * < set to global value
4737 * <xx> accept special key codes for 'wildchar'
4738 * c accept any non-digit for 'wildchar'
4739 * [-]0-9 set number
4740 * other error
4741 */
4742 ++arg;
4743 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004744 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004745 ((flags & P_VI_DEF) || cp_val)
4746 ? VI_DEFAULT : VIM_DEFAULT];
4747 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004748 {
4749 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4750 * use the global value. */
4751 if ((long *)varp == &curbuf->b_p_ul
4752 && opt_flags == OPT_LOCAL)
4753 value = NO_LOCAL_UNDOLEVEL;
4754 else
4755 value = *(long *)get_varp_scope(
4756 &(options[opt_idx]), OPT_GLOBAL);
4757 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004758 else if (((long *)varp == &p_wc
4759 || (long *)varp == &p_wcm)
4760 && (*arg == '<'
4761 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004762 || (*arg != NUL
4763 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004764 && !VIM_ISDIGIT(*arg))))
4765 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004766 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 if (value == 0 && (long *)varp != &p_wcm)
4768 {
4769 errmsg = e_invarg;
4770 goto skip;
4771 }
4772 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004773 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4774 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004775 /* Allow negative (for 'undolevels'), octal and
4776 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004777 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4778 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004779 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004780 {
4781 errmsg = e_invarg;
4782 goto skip;
4783 }
4784 }
4785 else
4786 {
4787 errmsg = (char_u *)N_("E521: Number required after =");
4788 goto skip;
4789 }
4790
4791 if (adding)
4792 value = *(long *)varp + value;
4793 if (prepending)
4794 value = *(long *)varp * value;
4795 if (removing)
4796 value = *(long *)varp - value;
4797 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004798 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799 }
4800 else if (opt_idx >= 0) /* string */
4801 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004802 char_u *save_arg = NULL;
4803 char_u *s = NULL;
4804 char_u *oldval = NULL; /* previous value if *varp */
4805 char_u *newval;
4806 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004807#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004808 char_u *saved_origval = NULL;
4809 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004810#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004811 unsigned newlen;
4812 int comma;
4813 int bs;
4814 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004815 was allocated */
4816
4817 /* When using ":set opt=val" for a global option
4818 * with a local value the local value will be
4819 * reset, use the global value here. */
4820 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004821 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 varp = options[opt_idx].var;
4823
4824 /* The old value is kept until we are sure that the
4825 * new value is valid. */
4826 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004827
4828 /* When setting the local value of a global
4829 * option, the old value may be the global value. */
4830 if (((int)options[opt_idx].indir & PV_BOTH)
4831 && (opt_flags & OPT_LOCAL))
4832 origval = *(char_u **)get_varp(
4833 &options[opt_idx]);
4834 else
4835 origval = oldval;
4836
Bram Moolenaar071d4272004-06-13 20:20:40 +00004837 if (nextchar == '&') /* set to default val */
4838 {
4839 newval = options[opt_idx].def_val[
4840 ((flags & P_VI_DEF) || cp_val)
4841 ? VI_DEFAULT : VIM_DEFAULT];
4842 if ((char_u **)varp == &p_bg)
4843 {
4844 /* guess the value of 'background' */
4845#ifdef FEAT_GUI
4846 if (gui.in_use)
4847 newval = gui_bg_default();
4848 else
4849#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004850 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004851 }
4852
4853 /* expand environment variables and ~ (since the
4854 * default value was already expanded, only
4855 * required when an environment variable was set
4856 * later */
4857 if (newval == NULL)
4858 newval = empty_option;
4859 else
4860 {
4861 s = option_expand(opt_idx, newval);
4862 if (s == NULL)
4863 s = newval;
4864 newval = vim_strsave(s);
4865 }
4866 new_value_alloced = TRUE;
4867 }
4868 else if (nextchar == '<') /* set to global val */
4869 {
4870 newval = vim_strsave(*(char_u **)get_varp_scope(
4871 &(options[opt_idx]), OPT_GLOBAL));
4872 new_value_alloced = TRUE;
4873 }
4874 else
4875 {
4876 ++arg; /* jump to after the '=' or ':' */
4877
4878 /*
4879 * Set 'keywordprg' to ":help" if an empty
4880 * value was passed to :set by the user.
4881 * Misuse errbuf[] for the resulting string.
4882 */
4883 if (varp == (char_u *)&p_kp
4884 && (*arg == NUL || *arg == ' '))
4885 {
4886 STRCPY(errbuf, ":help");
4887 save_arg = arg;
4888 arg = errbuf;
4889 }
4890 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004891 * Convert 'backspace' number to string, for
4892 * adding, prepending and removing string.
4893 */
4894 else if (varp == (char_u *)&p_bs
4895 && VIM_ISDIGIT(**(char_u **)varp))
4896 {
4897 i = getdigits((char_u **)varp);
4898 switch (i)
4899 {
4900 case 0:
4901 *(char_u **)varp = empty_option;
4902 break;
4903 case 1:
4904 *(char_u **)varp = vim_strsave(
4905 (char_u *)"indent,eol");
4906 break;
4907 case 2:
4908 *(char_u **)varp = vim_strsave(
4909 (char_u *)"indent,eol,start");
4910 break;
4911 }
4912 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004913 if (origval == oldval)
4914 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004915 oldval = *(char_u **)varp;
4916 }
4917 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004918 * Convert 'whichwrap' number to string, for
4919 * backwards compatibility with Vim 3.0.
4920 * Misuse errbuf[] for the resulting string.
4921 */
4922 else if (varp == (char_u *)&p_ww
4923 && VIM_ISDIGIT(*arg))
4924 {
4925 *errbuf = NUL;
4926 i = getdigits(&arg);
4927 if (i & 1)
4928 STRCAT(errbuf, "b,");
4929 if (i & 2)
4930 STRCAT(errbuf, "s,");
4931 if (i & 4)
4932 STRCAT(errbuf, "h,l,");
4933 if (i & 8)
4934 STRCAT(errbuf, "<,>,");
4935 if (i & 16)
4936 STRCAT(errbuf, "[,],");
4937 if (*errbuf != NUL) /* remove trailing , */
4938 errbuf[STRLEN(errbuf) - 1] = NUL;
4939 save_arg = arg;
4940 arg = errbuf;
4941 }
4942 /*
4943 * Remove '>' before 'dir' and 'bdir', for
4944 * backwards compatibility with version 3.0
4945 */
4946 else if ( *arg == '>'
4947 && (varp == (char_u *)&p_dir
4948 || varp == (char_u *)&p_bdir))
4949 {
4950 ++arg;
4951 }
4952
Bram Moolenaar071d4272004-06-13 20:20:40 +00004953 /*
4954 * Copy the new string into allocated memory.
4955 * Can't use set_string_option_direct(), because
4956 * we need to remove the backslashes.
4957 */
4958 /* get a bit too much */
4959 newlen = (unsigned)STRLEN(arg) + 1;
4960 if (adding || prepending || removing)
4961 newlen += (unsigned)STRLEN(origval) + 1;
4962 newval = alloc(newlen);
4963 if (newval == NULL) /* out of mem, don't change */
4964 break;
4965 s = newval;
4966
4967 /*
4968 * Copy the string, skip over escaped chars.
4969 * For MS-DOS and WIN32 backslashes before normal
4970 * file name characters are not removed, and keep
4971 * backslash at start, for "\\machine\path", but
4972 * do remove it for "\\\\machine\\path".
4973 * The reverse is found in ExpandOldSetting().
4974 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004975 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004976 {
4977 if (*arg == '\\' && arg[1] != NUL
4978#ifdef BACKSLASH_IN_FILENAME
4979 && !((flags & P_EXPAND)
4980 && vim_isfilec(arg[1])
4981 && (arg[1] != '\\'
4982 || (s == newval
4983 && arg[2] != '\\')))
4984#endif
4985 )
4986 ++arg; /* remove backslash */
4987#ifdef FEAT_MBYTE
4988 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004989 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004990 {
4991 /* copy multibyte char */
4992 mch_memmove(s, arg, (size_t)i);
4993 arg += i;
4994 s += i;
4995 }
4996 else
4997#endif
4998 *s++ = *arg++;
4999 }
5000 *s = NUL;
5001
5002 /*
5003 * Expand environment variables and ~.
5004 * Don't do it when adding without inserting a
5005 * comma.
5006 */
5007 if (!(adding || prepending || removing)
5008 || (flags & P_COMMA))
5009 {
5010 s = option_expand(opt_idx, newval);
5011 if (s != NULL)
5012 {
5013 vim_free(newval);
5014 newlen = (unsigned)STRLEN(s) + 1;
5015 if (adding || prepending || removing)
5016 newlen += (unsigned)STRLEN(origval) + 1;
5017 newval = alloc(newlen);
5018 if (newval == NULL)
5019 break;
5020 STRCPY(newval, s);
5021 }
5022 }
5023
5024 /* locate newval[] in origval[] when removing it
5025 * and when adding to avoid duplicates */
5026 i = 0; /* init for GCC */
5027 if (removing || (flags & P_NODUP))
5028 {
5029 i = (int)STRLEN(newval);
5030 bs = 0;
5031 for (s = origval; *s; ++s)
5032 {
5033 if ((!(flags & P_COMMA)
5034 || s == origval
5035 || (s[-1] == ',' && !(bs & 1)))
5036 && STRNCMP(s, newval, i) == 0
5037 && (!(flags & P_COMMA)
5038 || s[i] == ','
5039 || s[i] == NUL))
5040 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005041 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005042 * even number of backslashes or a single
5043 * backslash preceded by a comma before it
5044 * is recognized as a separator */
5045 if ((s > origval + 1
5046 && s[-1] == '\\'
5047 && s[-2] != ',')
5048 || (s == origval + 1
5049 && s[-1] == '\\'))
5050
Bram Moolenaar071d4272004-06-13 20:20:40 +00005051 ++bs;
5052 else
5053 bs = 0;
5054 }
5055
5056 /* do not add if already there */
5057 if ((adding || prepending) && *s)
5058 {
5059 prepending = FALSE;
5060 adding = FALSE;
5061 STRCPY(newval, origval);
5062 }
5063 }
5064
5065 /* concatenate the two strings; add a ',' if
5066 * needed */
5067 if (adding || prepending)
5068 {
5069 comma = ((flags & P_COMMA) && *origval != NUL
5070 && *newval != NUL);
5071 if (adding)
5072 {
5073 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005074 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005075 if (comma && i > 1
5076 && (flags & P_ONECOMMA) == P_ONECOMMA
5077 && origval[i - 1] == ','
5078 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005079 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005080 mch_memmove(newval + i + comma, newval,
5081 STRLEN(newval) + 1);
5082 mch_memmove(newval, origval, (size_t)i);
5083 }
5084 else
5085 {
5086 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005087 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005088 }
5089 if (comma)
5090 newval[i] = ',';
5091 }
5092
5093 /* Remove newval[] from origval[]. (Note: "i" has
5094 * been set above and is used here). */
5095 if (removing)
5096 {
5097 STRCPY(newval, origval);
5098 if (*s)
5099 {
5100 /* may need to remove a comma */
5101 if (flags & P_COMMA)
5102 {
5103 if (s == origval)
5104 {
5105 /* include comma after string */
5106 if (s[i] == ',')
5107 ++i;
5108 }
5109 else
5110 {
5111 /* include comma before string */
5112 --s;
5113 ++i;
5114 }
5115 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005116 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005117 }
5118 }
5119
5120 if (flags & P_FLAGLIST)
5121 {
5122 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005123 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005124 {
5125 /* if options have P_FLAGLIST and
5126 * P_ONECOMMA such as 'whichwrap' */
5127 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005128 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005129 if (*s != ',' && *(s + 1) == ','
5130 && vim_strchr(s + 2, *s) != NULL)
5131 {
5132 /* Remove the duplicated value and
5133 * the next comma. */
5134 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005135 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005137 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005138 else
5139 {
5140 if ((!(flags & P_COMMA) || *s != ',')
5141 && vim_strchr(s + 1, *s) != NULL)
5142 {
5143 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005144 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005145 }
5146 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005147 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005149 }
5150
5151 if (save_arg != NULL) /* number for 'whichwrap' */
5152 arg = save_arg;
5153 new_value_alloced = TRUE;
5154 }
5155
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005156 /*
5157 * Set the new value.
5158 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005159 *(char_u **)(varp) = newval;
5160
Bram Moolenaar53744302015-07-17 17:38:22 +02005161#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005162 if (!starting
5163# ifdef FEAT_CRYPT
5164 && options[opt_idx].indir != PV_KEY
5165# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005166 && origval != NULL && newval != NULL)
5167 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005168 /* origval may be freed by
5169 * did_set_string_option(), make a copy. */
5170 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005171 /* newval (and varp) may become invalid if the
5172 * buffer is closed by autocommands. */
5173 saved_newval = vim_strsave(newval);
5174 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005175#endif
5176
Bram Moolenaar071d4272004-06-13 20:20:40 +00005177 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005178 * ":set" on local options. Note: when setting 'syntax'
5179 * or 'filetype' autocommands may be triggered that can
5180 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005181 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5182 new_value_alloced, oldval, errbuf, opt_flags);
5183
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005184#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5185 if (errmsg == NULL)
5186 trigger_optionsset_string(opt_idx, opt_flags,
5187 saved_origval, saved_newval);
5188 vim_free(saved_origval);
5189 vim_free(saved_newval);
5190#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005191 /* If error detected, print the error message. */
5192 if (errmsg != NULL)
5193 goto skip;
5194 }
5195 else /* key code option */
5196 {
5197 char_u *p;
5198
5199 if (nextchar == '&')
5200 {
5201 if (add_termcap_entry(key_name, TRUE) == FAIL)
5202 errmsg = (char_u *)N_("E522: Not found in termcap");
5203 }
5204 else
5205 {
5206 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005207 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005208 if (*p == '\\' && p[1] != NUL)
5209 ++p;
5210 nextchar = *p;
5211 *p = NUL;
5212 add_termcode(key_name, arg, FALSE);
5213 *p = nextchar;
5214 }
5215 if (full_screen)
5216 ttest(FALSE);
5217 redraw_all_later(CLEAR);
5218 }
5219 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005220
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005222 did_set_option(opt_idx, opt_flags,
5223 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005224 }
5225
5226skip:
5227 /*
5228 * Advance to next argument.
5229 * - skip until a blank found, taking care of backslashes
5230 * - skip blanks
5231 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5232 */
5233 for (i = 0; i < 2 ; ++i)
5234 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005235 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005236 if (*arg++ == '\\' && *arg != NUL)
5237 ++arg;
5238 arg = skipwhite(arg);
5239 if (*arg != '=')
5240 break;
5241 }
5242 }
5243
5244 if (errmsg != NULL)
5245 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005246 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005247 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005248 if (i + (arg - startarg) < IOSIZE)
5249 {
5250 /* append the argument with the error */
5251 STRCAT(IObuff, ": ");
5252 mch_memmove(IObuff + i, startarg, (arg - startarg));
5253 IObuff[i + (arg - startarg)] = NUL;
5254 }
5255 /* make sure all characters are printable */
5256 trans_characters(IObuff, IOSIZE);
5257
5258 ++no_wait_return; /* wait_return done later */
5259 emsg(IObuff); /* show error highlighted */
5260 --no_wait_return;
5261
5262 return FAIL;
5263 }
5264
5265 arg = skipwhite(arg);
5266 }
5267
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005268theend:
5269 if (silent_mode && did_show)
5270 {
5271 /* After displaying option values in silent mode. */
5272 silent_mode = FALSE;
5273 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5274 msg_putchar('\n');
5275 cursor_on(); /* msg_start() switches it off */
5276 out_flush();
5277 silent_mode = TRUE;
5278 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5279 }
5280
Bram Moolenaar071d4272004-06-13 20:20:40 +00005281 return OK;
5282}
5283
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005284/*
5285 * Call this when an option has been given a new value through a user command.
5286 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5287 */
5288 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005289did_set_option(
5290 int opt_idx,
5291 int opt_flags, /* possibly with OPT_MODELINE */
5292 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005293{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005294 long_u *p;
5295
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005296 options[opt_idx].flags |= P_WAS_SET;
5297
5298 /* When an option is set in the sandbox, from a modeline or in secure mode
5299 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005300 * flag. */
5301 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005302 if (secure
5303#ifdef HAVE_SANDBOX
5304 || sandbox != 0
5305#endif
5306 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005307 *p = *p | P_INSECURE;
5308 else if (new_value)
5309 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005310}
5311
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005313illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005314{
5315 if (errbuf == NULL)
5316 return (char_u *)"";
5317 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005318 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005319 return errbuf;
5320}
5321
5322/*
5323 * Convert a key name or string into a key value.
5324 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005325 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005327 int
5328string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005329{
5330 if (*arg == '<')
5331 return find_key_option(arg + 1);
5332 if (*arg == '^')
5333 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005334 if (multi_byte)
5335 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336 return *arg;
5337}
5338
5339#ifdef FEAT_CMDWIN
5340/*
5341 * Check value of 'cedit' and set cedit_key.
5342 * Returns NULL if value is OK, error message otherwise.
5343 */
5344 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005345check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346{
5347 int n;
5348
5349 if (*p_cedit == NUL)
5350 cedit_key = -1;
5351 else
5352 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005353 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354 if (vim_isprintc(n))
5355 return e_invarg;
5356 cedit_key = n;
5357 }
5358 return NULL;
5359}
5360#endif
5361
5362#ifdef FEAT_TITLE
5363/*
5364 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5365 * maketitle() to create and display it.
5366 * When switching the title or icon off, call mch_restore_title() to get
5367 * the old value back.
5368 */
5369 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005370did_set_title(
5371 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372{
5373 if (starting != NO_SCREEN
5374#ifdef FEAT_GUI
5375 && !gui.starting
5376#endif
5377 )
5378 {
5379 maketitle();
5380 if (icon)
5381 {
5382 if (!p_icon)
5383 mch_restore_title(2);
5384 }
5385 else
5386 {
5387 if (!p_title)
5388 mch_restore_title(1);
5389 }
5390 }
5391}
5392#endif
5393
5394/*
5395 * set_options_bin - called when 'bin' changes value.
5396 */
5397 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005398set_options_bin(
5399 int oldval,
5400 int newval,
5401 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005402{
5403 /*
5404 * The option values that are changed when 'bin' changes are
5405 * copied when 'bin is set and restored when 'bin' is reset.
5406 */
5407 if (newval)
5408 {
5409 if (!oldval) /* switched on */
5410 {
5411 if (!(opt_flags & OPT_GLOBAL))
5412 {
5413 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5414 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5415 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5416 curbuf->b_p_et_nobin = curbuf->b_p_et;
5417 }
5418 if (!(opt_flags & OPT_LOCAL))
5419 {
5420 p_tw_nobin = p_tw;
5421 p_wm_nobin = p_wm;
5422 p_ml_nobin = p_ml;
5423 p_et_nobin = p_et;
5424 }
5425 }
5426
5427 if (!(opt_flags & OPT_GLOBAL))
5428 {
5429 curbuf->b_p_tw = 0; /* no automatic line wrap */
5430 curbuf->b_p_wm = 0; /* no automatic line wrap */
5431 curbuf->b_p_ml = 0; /* no modelines */
5432 curbuf->b_p_et = 0; /* no expandtab */
5433 }
5434 if (!(opt_flags & OPT_LOCAL))
5435 {
5436 p_tw = 0;
5437 p_wm = 0;
5438 p_ml = FALSE;
5439 p_et = FALSE;
5440 p_bin = TRUE; /* needed when called for the "-b" argument */
5441 }
5442 }
5443 else if (oldval) /* switched off */
5444 {
5445 if (!(opt_flags & OPT_GLOBAL))
5446 {
5447 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5448 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5449 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5450 curbuf->b_p_et = curbuf->b_p_et_nobin;
5451 }
5452 if (!(opt_flags & OPT_LOCAL))
5453 {
5454 p_tw = p_tw_nobin;
5455 p_wm = p_wm_nobin;
5456 p_ml = p_ml_nobin;
5457 p_et = p_et_nobin;
5458 }
5459 }
5460}
5461
5462#ifdef FEAT_VIMINFO
5463/*
5464 * Find the parameter represented by the given character (eg ', :, ", or /),
5465 * and return its associated value in the 'viminfo' string.
5466 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005467 * If the parameter is not specified in the string or there is no following
5468 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469 */
5470 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005471get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005472{
5473 char_u *p;
5474
5475 p = find_viminfo_parameter(type);
5476 if (p != NULL && VIM_ISDIGIT(*p))
5477 return atoi((char *)p);
5478 return -1;
5479}
5480
5481/*
5482 * Find the parameter represented by the given character (eg ''', ':', '"', or
5483 * '/') in the 'viminfo' option and return a pointer to the string after it.
5484 * Return NULL if the parameter is not specified in the string.
5485 */
5486 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005487find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005488{
5489 char_u *p;
5490
5491 for (p = p_viminfo; *p; ++p)
5492 {
5493 if (*p == type)
5494 return p + 1;
5495 if (*p == 'n') /* 'n' is always the last one */
5496 break;
5497 p = vim_strchr(p, ','); /* skip until next ',' */
5498 if (p == NULL) /* hit the end without finding parameter */
5499 break;
5500 }
5501 return NULL;
5502}
5503#endif
5504
5505/*
5506 * Expand environment variables for some string options.
5507 * These string options cannot be indirect!
5508 * If "val" is NULL expand the current value of the option.
5509 * Return pointer to NameBuff, or NULL when not expanded.
5510 */
5511 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005512option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513{
5514 /* if option doesn't need expansion nothing to do */
5515 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5516 return NULL;
5517
5518 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5519 * expand_env() would truncate the string. */
5520 if (val != NULL && STRLEN(val) > MAXPATHL)
5521 return NULL;
5522
5523 if (val == NULL)
5524 val = *(char_u **)options[opt_idx].var;
5525
5526 /*
5527 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5528 * Escape spaces when expanding 'tags', they are used to separate file
5529 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005530 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005531 */
5532 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005533 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005534#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005535 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5536#endif
5537 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005538 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5539 return NULL;
5540
5541 return NameBuff;
5542}
5543
5544/*
5545 * After setting various option values: recompute variables that depend on
5546 * option values.
5547 */
5548 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005549didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550{
5551 /* initialize the table for 'iskeyword' et.al. */
5552 (void)init_chartab();
5553
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005554#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005556#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005558 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559#ifdef FEAT_SESSION
5560 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5561 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5562#endif
5563#ifdef FEAT_FOLDING
5564 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5565#endif
5566 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005567 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568#ifdef FEAT_VIRTUALEDIT
5569 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5570#endif
5571#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5572 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5573#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005574#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005575 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005576 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005577 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005578 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005579#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005580#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5581 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5582#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005583#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5585#endif
5586#ifdef FEAT_CMDWIN
5587 /* set cedit_key */
5588 (void)check_cedit();
5589#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005590#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005591 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005592#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005593#ifdef FEAT_LINEBREAK
5594 /* initialize the table for 'breakat'. */
5595 fill_breakat_flags();
5596#endif
5597
5598}
5599
5600/*
5601 * More side effects of setting options.
5602 */
5603 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005604didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005605{
5606 /* Initialize the highlight_attr[] table. */
5607 (void)highlight_changed();
5608
5609 /* Parse default for 'wildmode' */
5610 check_opt_wim();
5611
5612 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005613 /* Parse default for 'fillchars'. */
5614 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005615
5616#ifdef FEAT_CLIPBOARD
5617 /* Parse default for 'clipboard' */
5618 (void)check_clipboard_option();
5619#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005620}
5621
5622/*
5623 * Check for string options that are NULL (normally only termcap options).
5624 */
5625 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005626check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005627{
5628 int opt_idx;
5629
5630 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5631 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5632 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5633}
5634
5635/*
5636 * Check string options in a buffer for NULL value.
5637 */
5638 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005639check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005641 check_string_option(&buf->b_p_bh);
5642 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643#ifdef FEAT_MBYTE
5644 check_string_option(&buf->b_p_fenc);
5645#endif
5646 check_string_option(&buf->b_p_ff);
5647#ifdef FEAT_FIND_ID
5648 check_string_option(&buf->b_p_def);
5649 check_string_option(&buf->b_p_inc);
5650# ifdef FEAT_EVAL
5651 check_string_option(&buf->b_p_inex);
5652# endif
5653#endif
5654#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5655 check_string_option(&buf->b_p_inde);
5656 check_string_option(&buf->b_p_indk);
5657#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005658#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5659 check_string_option(&buf->b_p_bexpr);
5660#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005661#if defined(FEAT_CRYPT)
5662 check_string_option(&buf->b_p_cm);
5663#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005664 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005665#if defined(FEAT_EVAL)
5666 check_string_option(&buf->b_p_fex);
5667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668#ifdef FEAT_CRYPT
5669 check_string_option(&buf->b_p_key);
5670#endif
5671 check_string_option(&buf->b_p_kp);
5672 check_string_option(&buf->b_p_mps);
5673 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005674 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675 check_string_option(&buf->b_p_isk);
5676#ifdef FEAT_COMMENTS
5677 check_string_option(&buf->b_p_com);
5678#endif
5679#ifdef FEAT_FOLDING
5680 check_string_option(&buf->b_p_cms);
5681#endif
5682 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005683#ifdef FEAT_TEXTOBJ
5684 check_string_option(&buf->b_p_qe);
5685#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005686#ifdef FEAT_SYN_HL
5687 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005688 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005689#endif
5690#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005691 check_string_option(&buf->b_s.b_p_spc);
5692 check_string_option(&buf->b_s.b_p_spf);
5693 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694#endif
5695#ifdef FEAT_SEARCHPATH
5696 check_string_option(&buf->b_p_sua);
5697#endif
5698#ifdef FEAT_CINDENT
5699 check_string_option(&buf->b_p_cink);
5700 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005701 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702#endif
5703#ifdef FEAT_AUTOCMD
5704 check_string_option(&buf->b_p_ft);
5705#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5707 check_string_option(&buf->b_p_cinw);
5708#endif
5709#ifdef FEAT_INS_EXPAND
5710 check_string_option(&buf->b_p_cpt);
5711#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005712#ifdef FEAT_COMPL_FUNC
5713 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005714 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716#ifdef FEAT_KEYMAP
5717 check_string_option(&buf->b_p_keymap);
5718#endif
5719#ifdef FEAT_QUICKFIX
5720 check_string_option(&buf->b_p_gp);
5721 check_string_option(&buf->b_p_mp);
5722 check_string_option(&buf->b_p_efm);
5723#endif
5724 check_string_option(&buf->b_p_ep);
5725 check_string_option(&buf->b_p_path);
5726 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005727 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728#ifdef FEAT_INS_EXPAND
5729 check_string_option(&buf->b_p_dict);
5730 check_string_option(&buf->b_p_tsr);
5731#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005732#ifdef FEAT_LISP
5733 check_string_option(&buf->b_p_lw);
5734#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005735 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005736#ifdef FEAT_MBYTE
5737 check_string_option(&buf->b_p_menc);
5738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739}
5740
5741/*
5742 * Free the string allocated for an option.
5743 * Checks for the string being empty_option. This may happen if we're out of
5744 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5745 * check_options().
5746 * Does NOT check for P_ALLOCED flag!
5747 */
5748 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005749free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005750{
5751 if (p != empty_option)
5752 vim_free(p);
5753}
5754
5755 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005756clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757{
5758 if (*pp != empty_option)
5759 vim_free(*pp);
5760 *pp = empty_option;
5761}
5762
5763 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005764check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765{
5766 if (*pp == NULL)
5767 *pp = empty_option;
5768}
5769
5770/*
5771 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5772 */
5773 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005774set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005775{
5776 int opt_idx;
5777
5778 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5779 if (options[opt_idx].var == (char_u *)p)
5780 {
5781 options[opt_idx].flags |= P_ALLOCED;
5782 return;
5783 }
5784 return; /* cannot happen: didn't find it! */
5785}
5786
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005787#if defined(FEAT_EVAL) || defined(PROTO)
5788/*
5789 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5790 * Return FALSE when it wasn't.
5791 * Return -1 for an unknown option.
5792 */
5793 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005794was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005795{
5796 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005797 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005798
5799 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005800 {
5801 flagp = insecure_flag(idx, opt_flags);
5802 return (*flagp & P_INSECURE) != 0;
5803 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005804 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005805 return -1;
5806}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005807
5808/*
5809 * Get a pointer to the flags used for the P_INSECURE flag of option
5810 * "opt_idx". For some local options a local flags field is used.
5811 */
5812 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005813insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005814{
5815 if (opt_flags & OPT_LOCAL)
5816 switch ((int)options[opt_idx].indir)
5817 {
5818#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005819 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005820#endif
5821#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005822# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005823 case PV_FDE: return &curwin->w_p_fde_flags;
5824 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005825# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005826# ifdef FEAT_BEVAL
5827 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5828# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005829# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005830 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005831# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005832 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005833# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005834 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005835# endif
5836#endif
5837 }
5838
5839 /* Nothing special, return global flags field. */
5840 return &options[opt_idx].flags;
5841}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005842#endif
5843
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005844#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005845static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005846
5847/*
5848 * Redraw the window title and/or tab page text later.
5849 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005850static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005851{
5852 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005853 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005854}
5855#endif
5856
Bram Moolenaar071d4272004-06-13 20:20:40 +00005857/*
5858 * Set a string option to a new value (without checking the effect).
5859 * The string is copied into allocated memory.
5860 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005861 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005862 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005863 */
5864 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005865set_string_option_direct(
5866 char_u *name,
5867 int opt_idx,
5868 char_u *val,
5869 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5870 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871{
5872 char_u *s;
5873 char_u **varp;
5874 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005875 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876
Bram Moolenaar89d40322006-08-29 15:30:07 +00005877 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005879 idx = findoption(name);
5880 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005881 {
5882 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005883 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005884 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005885 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886 }
5887
Bram Moolenaar89d40322006-08-29 15:30:07 +00005888 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889 return;
5890
5891 s = vim_strsave(val);
5892 if (s != NULL)
5893 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005894 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005895 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005896 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897 free_string_option(*varp);
5898 *varp = s;
5899
5900 /* For buffer/window local option may also set the global value. */
5901 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005902 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005903
Bram Moolenaar89d40322006-08-29 15:30:07 +00005904 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905
5906 /* When setting both values of a global option with a local value,
5907 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005908 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005909 {
5910 free_string_option(*varp);
5911 *varp = empty_option;
5912 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005913# ifdef FEAT_EVAL
5914 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005915 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005916 set_sid == 0 ? current_SID : set_sid);
5917# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 }
5919}
5920
5921/*
5922 * Set global value for string option when it's a local option.
5923 */
5924 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005925set_string_option_global(
5926 int opt_idx, /* option index */
5927 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005928{
5929 char_u **p, *s;
5930
5931 /* the global value is always allocated */
5932 if (options[opt_idx].var == VAR_WIN)
5933 p = (char_u **)GLOBAL_WO(varp);
5934 else
5935 p = (char_u **)options[opt_idx].var;
5936 if (options[opt_idx].indir != PV_NONE
5937 && p != varp
5938 && (s = vim_strsave(*varp)) != NULL)
5939 {
5940 free_string_option(*p);
5941 *p = s;
5942 }
5943}
5944
5945/*
5946 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005947 *
5948 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005949 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005950 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005951set_string_option(
5952 int opt_idx,
5953 char_u *value,
5954 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955{
5956 char_u *s;
5957 char_u **varp;
5958 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005959#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5960 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005961 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005962#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005963 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964
5965 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005966 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005967
5968 s = vim_strsave(value);
5969 if (s != NULL)
5970 {
5971 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5972 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005973 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974 ? OPT_GLOBAL : OPT_LOCAL)
5975 : opt_flags);
5976 oldval = *varp;
5977 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005978
5979#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005980 if (!starting
5981# ifdef FEAT_CRYPT
5982 && options[opt_idx].indir != PV_KEY
5983# endif
5984 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005985 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005986 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005987 saved_newval = vim_strsave(s);
5988 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005989#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005990 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5991 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005992 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005993
Bram Moolenaar53744302015-07-17 17:38:22 +02005994#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005995 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005996 if (r == NULL)
5997 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005998 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005999 vim_free(saved_oldval);
6000 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006001#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006002 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006003 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006004}
6005
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006006#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006007/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006008 * Return TRUE if "val" is a valid 'filetype' name.
6009 * Also used for 'syntax' and 'keymap'.
6010 */
6011 static int
6012valid_filetype(char_u *val)
6013{
6014 char_u *s;
6015
6016 for (s = val; *s != NUL; ++s)
6017 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6018 return FALSE;
6019 return TRUE;
6020}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006021#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006022
6023/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006024 * Handle string options that need some action to perform when changed.
6025 * Returns NULL for success, or an error message for an error.
6026 */
6027 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006028did_set_string_option(
6029 int opt_idx, /* index in options[] table */
6030 char_u **varp, /* pointer to the option variable */
6031 int new_value_alloced, /* new value was allocated */
6032 char_u *oldval, /* previous value of the option */
6033 char_u *errbuf, /* buffer for errors, or NULL */
6034 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006035{
6036 char_u *errmsg = NULL;
6037 char_u *s, *p;
6038 int did_chartab = FALSE;
6039 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006040 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006041#ifdef FEAT_GUI
6042 /* set when changing an option that only requires a redraw in the GUI */
6043 int redraw_gui_only = FALSE;
6044#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006045#ifdef FEAT_AUTOCMD
6046 int ft_changed = FALSE;
6047#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006048
6049 /* Get the global option to compare with, otherwise we would have to check
6050 * two values for all local options. */
6051 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6052
6053 /* Disallow changing some options from secure mode */
6054 if ((secure
6055#ifdef HAVE_SANDBOX
6056 || sandbox != 0
6057#endif
6058 ) && (options[opt_idx].flags & P_SECURE))
6059 {
6060 errmsg = e_secure;
6061 }
6062
Bram Moolenaar7554da42016-11-25 22:04:13 +01006063 /* Check for a "normal" directory or file name in some options. Disallow a
6064 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006065 * are often illegal in a file name. Be more permissive if "secure" is off.
6066 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006067 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006068 && vim_strpbrk(*varp, (char_u *)(secure
6069 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006070 || ((options[opt_idx].flags & P_NDNAME)
6071 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006072 {
6073 errmsg = e_invarg;
6074 }
6075
Bram Moolenaar071d4272004-06-13 20:20:40 +00006076 /* 'term' */
6077 else if (varp == &T_NAME)
6078 {
6079 if (T_NAME[0] == NUL)
6080 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6081#ifdef FEAT_GUI
6082 if (gui.in_use)
6083 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6084 else if (term_is_gui(T_NAME))
6085 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6086#endif
6087 else if (set_termname(T_NAME) == FAIL)
6088 errmsg = (char_u *)N_("E522: Not found in termcap");
6089 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006090 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006091 /* Screen colors may have changed. */
6092 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006093
6094 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6095 * P_ALLOCED flag on 'term'. */
6096 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006097 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 }
6100
6101 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006102 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006103 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006104 char_u *bkc = p_bkc;
6105 unsigned int *flags = &bkc_flags;
6106
6107 if (opt_flags & OPT_LOCAL)
6108 {
6109 bkc = curbuf->b_p_bkc;
6110 flags = &curbuf->b_bkc_flags;
6111 }
6112
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006113 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6114 /* make the local value empty: use the global value */
6115 *flags = 0;
6116 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006118 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6119 errmsg = e_invarg;
6120 if ((((int)*flags & BKC_AUTO) != 0)
6121 + (((int)*flags & BKC_YES) != 0)
6122 + (((int)*flags & BKC_NO) != 0) != 1)
6123 {
6124 /* Must have exactly one of "auto", "yes" and "no". */
6125 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6126 errmsg = e_invarg;
6127 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128 }
6129 }
6130
6131 /* 'backupext' and 'patchmode' */
6132 else if (varp == &p_bex || varp == &p_pm)
6133 {
6134 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6135 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6136 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6137 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006138#ifdef FEAT_LINEBREAK
6139 /* 'breakindentopt' */
6140 else if (varp == &curwin->w_p_briopt)
6141 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006142 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006143 errmsg = e_invarg;
6144 }
6145#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006146
6147 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006148 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006149 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006150 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151 */
6152 else if ( varp == &p_isi
6153 || varp == &(curbuf->b_p_isk)
6154 || varp == &p_isp
6155 || varp == &p_isf)
6156 {
6157 if (init_chartab() == FAIL)
6158 {
6159 did_chartab = TRUE; /* need to restore it below */
6160 errmsg = e_invarg; /* error in value */
6161 }
6162 }
6163
6164 /* 'helpfile' */
6165 else if (varp == &p_hf)
6166 {
6167 /* May compute new values for $VIM and $VIMRUNTIME */
6168 if (didset_vim)
6169 {
6170 vim_setenv((char_u *)"VIM", (char_u *)"");
6171 didset_vim = FALSE;
6172 }
6173 if (didset_vimruntime)
6174 {
6175 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6176 didset_vimruntime = FALSE;
6177 }
6178 }
6179
Bram Moolenaar1a384422010-07-14 19:53:30 +02006180#ifdef FEAT_SYN_HL
6181 /* 'colorcolumn' */
6182 else if (varp == &curwin->w_p_cc)
6183 errmsg = check_colorcolumn(curwin);
6184#endif
6185
Bram Moolenaar071d4272004-06-13 20:20:40 +00006186#ifdef FEAT_MULTI_LANG
6187 /* 'helplang' */
6188 else if (varp == &p_hlg)
6189 {
6190 /* Check for "", "ab", "ab,cd", etc. */
6191 for (s = p_hlg; *s != NUL; s += 3)
6192 {
6193 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6194 {
6195 errmsg = e_invarg;
6196 break;
6197 }
6198 if (s[2] == NUL)
6199 break;
6200 }
6201 }
6202#endif
6203
6204 /* 'highlight' */
6205 else if (varp == &p_hl)
6206 {
6207 if (highlight_changed() == FAIL)
6208 errmsg = e_invarg; /* invalid flags */
6209 }
6210
6211 /* 'nrformats' */
6212 else if (gvarp == &p_nf)
6213 {
6214 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6215 errmsg = e_invarg;
6216 }
6217
6218#ifdef FEAT_SESSION
6219 /* 'sessionoptions' */
6220 else if (varp == &p_ssop)
6221 {
6222 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6223 errmsg = e_invarg;
6224 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6225 {
6226 /* Don't allow both "sesdir" and "curdir". */
6227 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6228 errmsg = e_invarg;
6229 }
6230 }
6231 /* 'viewoptions' */
6232 else if (varp == &p_vop)
6233 {
6234 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6235 errmsg = e_invarg;
6236 }
6237#endif
6238
6239 /* 'scrollopt' */
6240#ifdef FEAT_SCROLLBIND
6241 else if (varp == &p_sbo)
6242 {
6243 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6244 errmsg = e_invarg;
6245 }
6246#endif
6247
6248 /* 'ambiwidth' */
6249#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006250 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251 {
6252 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6253 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006254 else if (set_chars_option(&p_lcs) != NULL)
6255 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006256 else if (set_chars_option(&p_fcs) != NULL)
6257 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006258 }
6259#endif
6260
6261 /* 'background' */
6262 else if (varp == &p_bg)
6263 {
6264 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6265 {
6266#ifdef FEAT_EVAL
6267 int dark = (*p_bg == 'd');
6268#endif
6269
6270 init_highlight(FALSE, FALSE);
6271
6272#ifdef FEAT_EVAL
6273 if (dark != (*p_bg == 'd')
6274 && get_var_value((char_u *)"g:colors_name") != NULL)
6275 {
6276 /* The color scheme must have set 'background' back to another
6277 * value, that's not what we want here. Disable the color
6278 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006279 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006280 free_string_option(p_bg);
6281 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6282 check_string_option(&p_bg);
6283 init_highlight(FALSE, FALSE);
6284 }
6285#endif
6286 }
6287 else
6288 errmsg = e_invarg;
6289 }
6290
6291 /* 'wildmode' */
6292 else if (varp == &p_wim)
6293 {
6294 if (check_opt_wim() == FAIL)
6295 errmsg = e_invarg;
6296 }
6297
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006298#ifdef FEAT_CMDL_COMPL
6299 /* 'wildoptions' */
6300 else if (varp == &p_wop)
6301 {
6302 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6303 errmsg = e_invarg;
6304 }
6305#endif
6306
Bram Moolenaar071d4272004-06-13 20:20:40 +00006307#ifdef FEAT_WAK
6308 /* 'winaltkeys' */
6309 else if (varp == &p_wak)
6310 {
6311 if (*p_wak == NUL
6312 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6313 errmsg = e_invarg;
6314# ifdef FEAT_MENU
6315# ifdef FEAT_GUI_MOTIF
6316 else if (gui.in_use)
6317 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6318# else
6319# ifdef FEAT_GUI_GTK
6320 else if (gui.in_use)
6321 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6322# endif
6323# endif
6324# endif
6325 }
6326#endif
6327
6328#ifdef FEAT_AUTOCMD
6329 /* 'eventignore' */
6330 else if (varp == &p_ei)
6331 {
6332 if (check_ei() == FAIL)
6333 errmsg = e_invarg;
6334 }
6335#endif
6336
6337#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006338 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6339 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6340 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006341 {
6342 if (gvarp == &p_fenc)
6343 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006344 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006345 errmsg = e_modifiable;
6346 else if (vim_strchr(*varp, ',') != NULL)
6347 /* No comma allowed in 'fileencoding'; catches confusing it
6348 * with 'fileencodings'. */
6349 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006351 {
6352# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006353 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006354 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006355# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006356 /* Add 'fileencoding' to the swap file. */
6357 ml_setflags(curbuf);
6358 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006359 }
6360 if (errmsg == NULL)
6361 {
6362 /* canonize the value, so that STRCMP() can be used on it */
6363 p = enc_canonize(*varp);
6364 if (p != NULL)
6365 {
6366 vim_free(*varp);
6367 *varp = p;
6368 }
6369 if (varp == &p_enc)
6370 {
6371 errmsg = mb_init();
6372# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006373 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374# endif
6375 }
6376 }
6377
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006378# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6380 {
6381 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6382 if (STRCMP(p_tenc, "utf-8") != 0)
6383 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6384 }
6385# endif
6386
6387 if (errmsg == NULL)
6388 {
6389# ifdef FEAT_KEYMAP
6390 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6391 * (with another encoding). */
6392 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6393 (void)keymap_init();
6394# endif
6395
6396 /* When 'termencoding' is not empty and 'encoding' changes or when
6397 * 'termencoding' changes, need to setup for keyboard input and
6398 * display output conversion. */
6399 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6400 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006401 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6402 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6403 {
6404 EMSG3(_("E950: Cannot convert between %s and %s"),
6405 p_tenc, p_enc);
6406 errmsg = e_invarg;
6407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006409
6410# if defined(WIN3264) && defined(FEAT_MBYTE)
6411 /* $HOME may have characters in active code page. */
6412 if (varp == &p_enc)
6413 init_homedir();
6414# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006415 }
6416 }
6417#endif
6418
6419#if defined(FEAT_POSTSCRIPT)
6420 else if (varp == &p_penc)
6421 {
6422 /* Canonize printencoding if VIM standard one */
6423 p = enc_canonize(p_penc);
6424 if (p != NULL)
6425 {
6426 vim_free(p_penc);
6427 p_penc = p;
6428 }
6429 else
6430 {
6431 /* Ensure lower case and '-' for '_' */
6432 for (s = p_penc; *s != NUL; s++)
6433 {
6434 if (*s == '_')
6435 *s = '-';
6436 else
6437 *s = TOLOWER_ASC(*s);
6438 }
6439 }
6440 }
6441#endif
6442
Bram Moolenaar9372a112005-12-06 19:59:18 +00006443#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006444 else if (varp == &p_imak)
6445 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006446 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006447 errmsg = e_invarg;
6448 }
6449#endif
6450
6451#ifdef FEAT_KEYMAP
6452 else if (varp == &curbuf->b_p_keymap)
6453 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006454 if (!valid_filetype(*varp))
6455 errmsg = e_invarg;
6456 else
6457 /* load or unload key mapping tables */
6458 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006459
Bram Moolenaarfab06232009-03-04 03:13:35 +00006460 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006461 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006462 if (*curbuf->b_p_keymap != NUL)
6463 {
6464 /* Installed a new keymap, switch on using it. */
6465 curbuf->b_p_iminsert = B_IMODE_LMAP;
6466 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6467 curbuf->b_p_imsearch = B_IMODE_LMAP;
6468 }
6469 else
6470 {
6471 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6472 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6473 curbuf->b_p_iminsert = B_IMODE_NONE;
6474 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6475 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6476 }
6477 if ((opt_flags & OPT_LOCAL) == 0)
6478 {
6479 set_iminsert_global();
6480 set_imsearch_global();
6481 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006482 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 }
6484 }
6485#endif
6486
6487 /* 'fileformat' */
6488 else if (gvarp == &p_ff)
6489 {
6490 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6491 errmsg = e_modifiable;
6492 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6493 errmsg = e_invarg;
6494 else
6495 {
6496 /* may also change 'textmode' */
6497 if (get_fileformat(curbuf) == EOL_DOS)
6498 curbuf->b_p_tx = TRUE;
6499 else
6500 curbuf->b_p_tx = FALSE;
6501#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006502 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006503#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006504 /* update flag in swap file */
6505 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006506 /* Redraw needed when switching to/from "mac": a CR in the text
6507 * will be displayed differently. */
6508 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6509 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006510 }
6511 }
6512
6513 /* 'fileformats' */
6514 else if (varp == &p_ffs)
6515 {
6516 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6517 errmsg = e_invarg;
6518 else
6519 {
6520 /* also change 'textauto' */
6521 if (*p_ffs == NUL)
6522 p_ta = FALSE;
6523 else
6524 p_ta = TRUE;
6525 }
6526 }
6527
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006528#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529 /* 'cryptkey' */
6530 else if (gvarp == &p_key)
6531 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006532# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006533 /* Make sure the ":set" command doesn't show the new value in the
6534 * history. */
6535 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006536# endif
6537 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6538 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006539 ml_set_crypt_key(curbuf, oldval,
6540 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006541 }
6542
6543 else if (gvarp == &p_cm)
6544 {
6545 if (opt_flags & OPT_LOCAL)
6546 p = curbuf->b_p_cm;
6547 else
6548 p = p_cm;
6549 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6550 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006551 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006552 errmsg = e_invarg;
6553 else
6554 {
6555 /* When setting the global value to empty, make it "zip". */
6556 if (*p_cm == NUL)
6557 {
6558 if (new_value_alloced)
6559 free_string_option(p_cm);
6560 p_cm = vim_strsave((char_u *)"zip");
6561 new_value_alloced = TRUE;
6562 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006563 /* When using ":set cm=name" the local value is going to be empty.
6564 * Do that here, otherwise the crypt functions will still use the
6565 * local value. */
6566 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6567 {
6568 free_string_option(curbuf->b_p_cm);
6569 curbuf->b_p_cm = empty_option;
6570 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006571
6572 /* Need to update the swapfile when the effective method changed.
6573 * Set "s" to the effective old value, "p" to the effective new
6574 * method and compare. */
6575 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6576 s = p_cm; /* was previously using the global value */
6577 else
6578 s = oldval;
6579 if (*curbuf->b_p_cm == NUL)
6580 p = p_cm; /* is now using the global value */
6581 else
6582 p = curbuf->b_p_cm;
6583 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006584 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006585
6586 /* If the global value changes need to update the swapfile for all
6587 * buffers using that value. */
6588 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6589 {
6590 buf_T *buf;
6591
Bram Moolenaar29323592016-07-24 22:04:11 +02006592 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006593 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006594 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006595 }
6596 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006597 }
6598#endif
6599
6600 /* 'matchpairs' */
6601 else if (gvarp == &p_mps)
6602 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006603#ifdef FEAT_MBYTE
6604 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006605 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006606 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006607 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006608 int x2 = -1;
6609 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006610
6611 if (*p != NUL)
6612 p += mb_ptr2len(p);
6613 if (*p != NUL)
6614 x2 = *p++;
6615 if (*p != NUL)
6616 {
6617 x3 = mb_ptr2char(p);
6618 p += mb_ptr2len(p);
6619 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006620 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006621 {
6622 errmsg = e_invarg;
6623 break;
6624 }
6625 if (*p == NUL)
6626 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006627 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006628 }
6629 else
6630#endif
6631 {
6632 /* Check for "x:y,x:y" */
6633 for (p = *varp; *p != NUL; p += 4)
6634 {
6635 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6636 {
6637 errmsg = e_invarg;
6638 break;
6639 }
6640 if (p[3] == NUL)
6641 break;
6642 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006643 }
6644 }
6645
6646#ifdef FEAT_COMMENTS
6647 /* 'comments' */
6648 else if (gvarp == &p_com)
6649 {
6650 for (s = *varp; *s; )
6651 {
6652 while (*s && *s != ':')
6653 {
6654 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6655 && !VIM_ISDIGIT(*s) && *s != '-')
6656 {
6657 errmsg = illegal_char(errbuf, *s);
6658 break;
6659 }
6660 ++s;
6661 }
6662 if (*s++ == NUL)
6663 errmsg = (char_u *)N_("E524: Missing colon");
6664 else if (*s == ',' || *s == NUL)
6665 errmsg = (char_u *)N_("E525: Zero length string");
6666 if (errmsg != NULL)
6667 break;
6668 while (*s && *s != ',')
6669 {
6670 if (*s == '\\' && s[1] != NUL)
6671 ++s;
6672 ++s;
6673 }
6674 s = skip_to_option_part(s);
6675 }
6676 }
6677#endif
6678
6679 /* 'listchars' */
6680 else if (varp == &p_lcs)
6681 {
6682 errmsg = set_chars_option(varp);
6683 }
6684
Bram Moolenaar071d4272004-06-13 20:20:40 +00006685 /* 'fillchars' */
6686 else if (varp == &p_fcs)
6687 {
6688 errmsg = set_chars_option(varp);
6689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006690
6691#ifdef FEAT_CMDWIN
6692 /* 'cedit' */
6693 else if (varp == &p_cedit)
6694 {
6695 errmsg = check_cedit();
6696 }
6697#endif
6698
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006699 /* 'verbosefile' */
6700 else if (varp == &p_vfile)
6701 {
6702 verbose_stop();
6703 if (*p_vfile != NUL && verbose_open() == FAIL)
6704 errmsg = e_invarg;
6705 }
6706
Bram Moolenaar071d4272004-06-13 20:20:40 +00006707#ifdef FEAT_VIMINFO
6708 /* 'viminfo' */
6709 else if (varp == &p_viminfo)
6710 {
6711 for (s = p_viminfo; *s;)
6712 {
6713 /* Check it's a valid character */
6714 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6715 {
6716 errmsg = illegal_char(errbuf, *s);
6717 break;
6718 }
6719 if (*s == 'n') /* name is always last one */
6720 {
6721 break;
6722 }
6723 else if (*s == 'r') /* skip until next ',' */
6724 {
6725 while (*++s && *s != ',')
6726 ;
6727 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006728 else if (*s == '%')
6729 {
6730 /* optional number */
6731 while (vim_isdigit(*++s))
6732 ;
6733 }
6734 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006735 ++s; /* no extra chars */
6736 else /* must have a number */
6737 {
6738 while (vim_isdigit(*++s))
6739 ;
6740
6741 if (!VIM_ISDIGIT(*(s - 1)))
6742 {
6743 if (errbuf != NULL)
6744 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006745 sprintf((char *)errbuf,
6746 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747 transchar_byte(*(s - 1)));
6748 errmsg = errbuf;
6749 }
6750 else
6751 errmsg = (char_u *)"";
6752 break;
6753 }
6754 }
6755 if (*s == ',')
6756 ++s;
6757 else if (*s)
6758 {
6759 if (errbuf != NULL)
6760 errmsg = (char_u *)N_("E527: Missing comma");
6761 else
6762 errmsg = (char_u *)"";
6763 break;
6764 }
6765 }
6766 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6767 errmsg = (char_u *)N_("E528: Must specify a ' value");
6768 }
6769#endif /* FEAT_VIMINFO */
6770
6771 /* terminal options */
6772 else if (istermoption(&options[opt_idx]) && full_screen)
6773 {
6774 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6775 if (varp == &T_CCO)
6776 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006777 int colors = atoi((char *)T_CCO);
6778
6779 /* Only reinitialize colors if t_Co value has really changed to
6780 * avoid expensive reload of colorscheme if t_Co is set to the
6781 * same value multiple times. */
6782 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006784 t_colors = colors;
6785 if (t_colors <= 1)
6786 {
6787 if (new_value_alloced)
6788 vim_free(T_CCO);
6789 T_CCO = empty_option;
6790 }
6791 /* We now have a different color setup, initialize it again. */
6792 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006794 }
6795 ttest(FALSE);
6796 if (varp == &T_ME)
6797 {
6798 out_str(T_ME);
6799 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006800#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801 /* Since t_me has been set, this probably means that the user
6802 * wants to use this as default colors. Need to reset default
6803 * background/foreground colors. */
6804 mch_set_normal_colors();
6805#endif
6806 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006807 if (varp == &T_BE && termcap_active)
6808 {
6809 if (*T_BE == NUL)
6810 /* When clearing t_BE we assume the user no longer wants
6811 * bracketed paste, thus disable it by writing t_BD. */
6812 out_str(T_BD);
6813 else
6814 out_str(T_BE);
6815 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816 }
6817
6818#ifdef FEAT_LINEBREAK
6819 /* 'showbreak' */
6820 else if (varp == &p_sbr)
6821 {
6822 for (s = p_sbr; *s; )
6823 {
6824 if (ptr2cells(s) != 1)
6825 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006826 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006827 }
6828 }
6829#endif
6830
6831#ifdef FEAT_GUI
6832 /* 'guifont' */
6833 else if (varp == &p_guifont)
6834 {
6835 if (gui.in_use)
6836 {
6837 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006838# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006839 /*
6840 * Put up a font dialog and let the user select a new value.
6841 * If this is cancelled go back to the old value but don't
6842 * give an error message.
6843 */
6844 if (STRCMP(p, "*") == 0)
6845 {
6846 p = gui_mch_font_dialog(oldval);
6847
6848 if (new_value_alloced)
6849 free_string_option(p_guifont);
6850
6851 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6852 new_value_alloced = TRUE;
6853 }
6854# endif
6855 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6856 {
6857# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6858 if (STRCMP(p_guifont, "*") == 0)
6859 {
6860 /* Dialog was cancelled: Keep the old value without giving
6861 * an error message. */
6862 if (new_value_alloced)
6863 free_string_option(p_guifont);
6864 p_guifont = vim_strsave(oldval);
6865 new_value_alloced = TRUE;
6866 }
6867 else
6868# endif
6869 errmsg = (char_u *)N_("E596: Invalid font(s)");
6870 }
6871 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006872 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873 }
6874# ifdef FEAT_XFONTSET
6875 else if (varp == &p_guifontset)
6876 {
6877 if (STRCMP(p_guifontset, "*") == 0)
6878 errmsg = (char_u *)N_("E597: can't select fontset");
6879 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6880 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006881 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006882 }
6883# endif
6884# ifdef FEAT_MBYTE
6885 else if (varp == &p_guifontwide)
6886 {
6887 if (STRCMP(p_guifontwide, "*") == 0)
6888 errmsg = (char_u *)N_("E533: can't select wide font");
6889 else if (gui_get_wide_font() == FAIL)
6890 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006891 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006892 }
6893# endif
6894#endif
6895
6896#ifdef CURSOR_SHAPE
6897 /* 'guicursor' */
6898 else if (varp == &p_guicursor)
6899 errmsg = parse_shape_opt(SHAPE_CURSOR);
6900#endif
6901
6902#ifdef FEAT_MOUSESHAPE
6903 /* 'mouseshape' */
6904 else if (varp == &p_mouseshape)
6905 {
6906 errmsg = parse_shape_opt(SHAPE_MOUSE);
6907 update_mouseshape(-1);
6908 }
6909#endif
6910
6911#ifdef FEAT_PRINTER
6912 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006913 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006914# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006915 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006916 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006917# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006918#endif
6919
6920#ifdef FEAT_LANGMAP
6921 /* 'langmap' */
6922 else if (varp == &p_langmap)
6923 langmap_set();
6924#endif
6925
6926#ifdef FEAT_LINEBREAK
6927 /* 'breakat' */
6928 else if (varp == &p_breakat)
6929 fill_breakat_flags();
6930#endif
6931
6932#ifdef FEAT_TITLE
6933 /* 'titlestring' and 'iconstring' */
6934 else if (varp == &p_titlestring || varp == &p_iconstring)
6935 {
6936# ifdef FEAT_STL_OPT
6937 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6938
6939 /* NULL => statusline syntax */
6940 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6941 stl_syntax |= flagval;
6942 else
6943 stl_syntax &= ~flagval;
6944# endif
6945 did_set_title(varp == &p_iconstring);
6946
6947 }
6948#endif
6949
6950#ifdef FEAT_GUI
6951 /* 'guioptions' */
6952 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006953 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006954 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006955 redraw_gui_only = TRUE;
6956 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957#endif
6958
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006959#if defined(FEAT_GUI_TABLINE)
6960 /* 'guitablabel' */
6961 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006962 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006963 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006964 redraw_gui_only = TRUE;
6965 }
6966 /* 'guitabtooltip' */
6967 else if (varp == &p_gtt)
6968 {
6969 redraw_gui_only = TRUE;
6970 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006971#endif
6972
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6974 /* 'ttymouse' */
6975 else if (varp == &p_ttym)
6976 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006977 /* Switch the mouse off before changing the escape sequences used for
6978 * that. */
6979 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6981 errmsg = e_invarg;
6982 else
6983 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006984 if (termcap_active)
6985 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006986 }
6987#endif
6988
Bram Moolenaar071d4272004-06-13 20:20:40 +00006989 /* 'selection' */
6990 else if (varp == &p_sel)
6991 {
6992 if (*p_sel == NUL
6993 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6994 errmsg = e_invarg;
6995 }
6996
6997 /* 'selectmode' */
6998 else if (varp == &p_slm)
6999 {
7000 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7001 errmsg = e_invarg;
7002 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007003
7004#ifdef FEAT_BROWSE
7005 /* 'browsedir' */
7006 else if (varp == &p_bsdir)
7007 {
7008 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7009 && !mch_isdir(p_bsdir))
7010 errmsg = e_invarg;
7011 }
7012#endif
7013
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014 /* 'keymodel' */
7015 else if (varp == &p_km)
7016 {
7017 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7018 errmsg = e_invarg;
7019 else
7020 {
7021 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7022 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7023 }
7024 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007025
7026 /* 'mousemodel' */
7027 else if (varp == &p_mousem)
7028 {
7029 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7030 errmsg = e_invarg;
7031#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7032 else if (*p_mousem != *oldval)
7033 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7034 * to create or delete the popup menus. */
7035 gui_motif_update_mousemodel(root_menu);
7036#endif
7037 }
7038
7039 /* 'switchbuf' */
7040 else if (varp == &p_swb)
7041 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007042 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043 errmsg = e_invarg;
7044 }
7045
7046 /* 'debug' */
7047 else if (varp == &p_debug)
7048 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007049 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 errmsg = e_invarg;
7051 }
7052
7053 /* 'display' */
7054 else if (varp == &p_dy)
7055 {
7056 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7057 errmsg = e_invarg;
7058 else
7059 (void)init_chartab();
7060
7061 }
7062
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063 /* 'eadirection' */
7064 else if (varp == &p_ead)
7065 {
7066 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7067 errmsg = e_invarg;
7068 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007069
7070#ifdef FEAT_CLIPBOARD
7071 /* 'clipboard' */
7072 else if (varp == &p_cb)
7073 errmsg = check_clipboard_option();
7074#endif
7075
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007076#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007077 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7078 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007079 else if (varp == &(curwin->w_s->b_p_spl)
7080 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007081 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007082 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007083 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007084 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007085 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007086 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007087 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007088 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007089 /* 'spellsuggest' */
7090 else if (varp == &p_sps)
7091 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007092 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007093 errmsg = e_invarg;
7094 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007095 /* 'mkspellmem' */
7096 else if (varp == &p_msm)
7097 {
7098 if (spell_check_msm() != OK)
7099 errmsg = e_invarg;
7100 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007101#endif
7102
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103 /* When 'bufhidden' is set, check for valid value. */
7104 else if (gvarp == &p_bh)
7105 {
7106 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7107 errmsg = e_invarg;
7108 }
7109
7110 /* When 'buftype' is set, check for valid value. */
7111 else if (gvarp == &p_bt)
7112 {
7113 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7114 errmsg = e_invarg;
7115 else
7116 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007117 if (curwin->w_status_height)
7118 {
7119 curwin->w_redr_status = TRUE;
7120 redraw_later(VALID);
7121 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007123#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007124 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007125#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007126 }
7127 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007128
7129#ifdef FEAT_STL_OPT
7130 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007131 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007132 {
7133 int wid;
7134
7135 if (varp == &p_ruf) /* reset ru_wid first */
7136 ru_wid = 0;
7137 s = *varp;
7138 if (varp == &p_ruf && *s == '%')
7139 {
7140 /* set ru_wid if 'ruf' starts with "%99(" */
7141 if (*++s == '-') /* ignore a '-' */
7142 s++;
7143 wid = getdigits(&s);
7144 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7145 ru_wid = wid;
7146 else
7147 errmsg = check_stl_option(p_ruf);
7148 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007149 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007150 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007151 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007152 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007153 comp_col();
7154 }
7155#endif
7156
7157#ifdef FEAT_INS_EXPAND
7158 /* check if it is a valid value for 'complete' -- Acevedo */
7159 else if (gvarp == &p_cpt)
7160 {
7161 for (s = *varp; *s;)
7162 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007163 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007164 s++;
7165 if (!*s)
7166 break;
7167 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7168 {
7169 errmsg = illegal_char(errbuf, *s);
7170 break;
7171 }
7172 if (*++s != NUL && *s != ',' && *s != ' ')
7173 {
7174 if (s[-1] == 'k' || s[-1] == 's')
7175 {
7176 /* skip optional filename after 'k' and 's' */
7177 while (*s && *s != ',' && *s != ' ')
7178 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007179 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180 ++s;
7181 ++s;
7182 }
7183 }
7184 else
7185 {
7186 if (errbuf != NULL)
7187 {
7188 sprintf((char *)errbuf,
7189 _("E535: Illegal character after <%c>"),
7190 *--s);
7191 errmsg = errbuf;
7192 }
7193 else
7194 errmsg = (char_u *)"";
7195 break;
7196 }
7197 }
7198 }
7199 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007200
7201 /* 'completeopt' */
7202 else if (varp == &p_cot)
7203 {
7204 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7205 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007206 else
7207 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007208 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007209#endif /* FEAT_INS_EXPAND */
7210
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007211#ifdef FEAT_SIGNS
7212 /* 'signcolumn' */
7213 else if (varp == &curwin->w_p_scl)
7214 {
7215 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7216 errmsg = e_invarg;
7217 }
7218#endif
7219
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220
7221#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007222 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007223 else if (varp == &p_toolbar)
7224 {
7225 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7226 &toolbar_flags, TRUE) != OK)
7227 errmsg = e_invarg;
7228 else
7229 {
7230 out_flush();
7231 gui_mch_show_toolbar((toolbar_flags &
7232 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7233 }
7234 }
7235#endif
7236
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007237#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007238 /* 'toolbariconsize': GTK+ 2 only */
7239 else if (varp == &p_tbis)
7240 {
7241 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7242 errmsg = e_invarg;
7243 else
7244 {
7245 out_flush();
7246 gui_mch_show_toolbar((toolbar_flags &
7247 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7248 }
7249 }
7250#endif
7251
7252 /* 'pastetoggle': translate key codes like in a mapping */
7253 else if (varp == &p_pt)
7254 {
7255 if (*p_pt)
7256 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007257 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007258 if (p != NULL)
7259 {
7260 if (new_value_alloced)
7261 free_string_option(p_pt);
7262 p_pt = p;
7263 new_value_alloced = TRUE;
7264 }
7265 }
7266 }
7267
7268 /* 'backspace' */
7269 else if (varp == &p_bs)
7270 {
7271 if (VIM_ISDIGIT(*p_bs))
7272 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007273 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007274 errmsg = e_invarg;
7275 }
7276 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7277 errmsg = e_invarg;
7278 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007279 else if (varp == &p_bo)
7280 {
7281 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7282 errmsg = e_invarg;
7283 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007284
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007285 /* 'tagcase' */
7286 else if (gvarp == &p_tc)
7287 {
7288 unsigned int *flags;
7289
7290 if (opt_flags & OPT_LOCAL)
7291 {
7292 p = curbuf->b_p_tc;
7293 flags = &curbuf->b_tc_flags;
7294 }
7295 else
7296 {
7297 p = p_tc;
7298 flags = &tc_flags;
7299 }
7300
7301 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7302 /* make the local value empty: use the global value */
7303 *flags = 0;
7304 else if (*p == NUL
7305 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7306 errmsg = e_invarg;
7307 }
7308
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007309#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310 /* 'casemap' */
7311 else if (varp == &p_cmp)
7312 {
7313 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7314 errmsg = e_invarg;
7315 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007316#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317
7318#ifdef FEAT_DIFF
7319 /* 'diffopt' */
7320 else if (varp == &p_dip)
7321 {
7322 if (diffopt_changed() == FAIL)
7323 errmsg = e_invarg;
7324 }
7325#endif
7326
7327#ifdef FEAT_FOLDING
7328 /* 'foldmethod' */
7329 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7330 {
7331 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7332 || *curwin->w_p_fdm == NUL)
7333 errmsg = e_invarg;
7334 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007335 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007337 if (foldmethodIsDiff(curwin))
7338 newFoldLevel();
7339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007340 }
7341# ifdef FEAT_EVAL
7342 /* 'foldexpr' */
7343 else if (varp == &curwin->w_p_fde)
7344 {
7345 if (foldmethodIsExpr(curwin))
7346 foldUpdateAll(curwin);
7347 }
7348# endif
7349 /* 'foldmarker' */
7350 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7351 {
7352 p = vim_strchr(*varp, ',');
7353 if (p == NULL)
7354 errmsg = (char_u *)N_("E536: comma required");
7355 else if (p == *varp || p[1] == NUL)
7356 errmsg = e_invarg;
7357 else if (foldmethodIsMarker(curwin))
7358 foldUpdateAll(curwin);
7359 }
7360 /* 'commentstring' */
7361 else if (gvarp == &p_cms)
7362 {
7363 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7364 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7365 }
7366 /* 'foldopen' */
7367 else if (varp == &p_fdo)
7368 {
7369 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7370 errmsg = e_invarg;
7371 }
7372 /* 'foldclose' */
7373 else if (varp == &p_fcl)
7374 {
7375 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7376 errmsg = e_invarg;
7377 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007378 /* 'foldignore' */
7379 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7380 {
7381 if (foldmethodIsIndent(curwin))
7382 foldUpdateAll(curwin);
7383 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007384#endif
7385
7386#ifdef FEAT_VIRTUALEDIT
7387 /* 'virtualedit' */
7388 else if (varp == &p_ve)
7389 {
7390 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7391 errmsg = e_invarg;
7392 else if (STRCMP(p_ve, oldval) != 0)
7393 {
7394 /* Recompute cursor position in case the new 've' setting
7395 * changes something. */
7396 validate_virtcol();
7397 coladvance(curwin->w_virtcol);
7398 }
7399 }
7400#endif
7401
7402#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7403 else if (varp == &p_csqf)
7404 {
7405 if (p_csqf != NULL)
7406 {
7407 p = p_csqf;
7408 while (*p != NUL)
7409 {
7410 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7411 || p[1] == NUL
7412 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7413 || (p[2] != NUL && p[2] != ','))
7414 {
7415 errmsg = e_invarg;
7416 break;
7417 }
7418 else if (p[2] == NUL)
7419 break;
7420 else
7421 p += 3;
7422 }
7423 }
7424 }
7425#endif
7426
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007427#ifdef FEAT_CINDENT
7428 /* 'cinoptions' */
7429 else if (gvarp == &p_cino)
7430 {
7431 /* TODO: recognize errors */
7432 parse_cino(curbuf);
7433 }
7434#endif
7435
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007436#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007437 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007438 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007439 {
7440 if (!gui_mch_set_rendering_options(p_rop))
7441 errmsg = e_invarg;
7442 }
7443#endif
7444
Bram Moolenaard0b51382016-11-04 15:23:45 +01007445#ifdef FEAT_AUTOCMD
7446 else if (gvarp == &p_ft)
7447 {
7448 if (!valid_filetype(*varp))
7449 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007450 else
7451 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007452 }
7453#endif
7454
7455#ifdef FEAT_SYN_HL
7456 else if (gvarp == &p_syn)
7457 {
7458 if (!valid_filetype(*varp))
7459 errmsg = e_invarg;
7460 }
7461#endif
7462
Bram Moolenaar825680f2017-07-22 17:04:02 +02007463#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007464 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007465 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007466 {
7467 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7468 errmsg = e_invarg;
7469 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007470 /* 'termsize' */
7471 else if (varp == &curwin->w_p_tms)
7472 {
7473 if (*curwin->w_p_tms != NUL)
7474 {
7475 p = skipdigits(curwin->w_p_tms);
7476 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7477 errmsg = e_invarg;
7478 }
7479 }
7480#endif
7481
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 /* Options that are a list of flags. */
7483 else
7484 {
7485 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007486 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007487 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007488 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007490 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007492 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007493 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007494#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007495 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007496 p = (char_u *)COCU_ALL;
7497#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007498 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499 {
7500#ifdef FEAT_MOUSE
7501 p = (char_u *)MOUSE_ALL;
7502#else
7503 if (*p_mouse != NUL)
7504 errmsg = (char_u *)N_("E538: No mouse support");
7505#endif
7506 }
7507#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007508 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007509 p = (char_u *)GO_ALL;
7510#endif
7511 if (p != NULL)
7512 {
7513 for (s = *varp; *s; ++s)
7514 if (vim_strchr(p, *s) == NULL)
7515 {
7516 errmsg = illegal_char(errbuf, *s);
7517 break;
7518 }
7519 }
7520 }
7521
7522 /*
7523 * If error detected, restore the previous value.
7524 */
7525 if (errmsg != NULL)
7526 {
7527 if (new_value_alloced)
7528 free_string_option(*varp);
7529 *varp = oldval;
7530 /*
7531 * When resetting some values, need to act on it.
7532 */
7533 if (did_chartab)
7534 (void)init_chartab();
7535 if (varp == &p_hl)
7536 (void)highlight_changed();
7537 }
7538 else
7539 {
7540#ifdef FEAT_EVAL
7541 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007542 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543#endif
7544 /*
7545 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007546 * Use "free_oldval", because recursiveness may change the flags under
7547 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007549 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007550 free_string_option(oldval);
7551 if (new_value_alloced)
7552 options[opt_idx].flags |= P_ALLOCED;
7553 else
7554 options[opt_idx].flags &= ~P_ALLOCED;
7555
7556 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007557 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007558 {
7559 /* global option with local value set to use global value; free
7560 * the local value and make it empty */
7561 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7562 free_string_option(*(char_u **)p);
7563 *(char_u **)p = empty_option;
7564 }
7565
7566 /* May set global value for local option. */
7567 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7568 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007569
7570#ifdef FEAT_AUTOCMD
7571 /*
7572 * Trigger the autocommand only after setting the flags.
7573 */
7574# ifdef FEAT_SYN_HL
7575 /* When 'syntax' is set, load the syntax of that name */
7576 if (varp == &(curbuf->b_p_syn))
7577 {
7578 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7579 curbuf->b_fname, TRUE, curbuf);
7580 }
7581# endif
7582 else if (varp == &(curbuf->b_p_ft))
7583 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007584 /* 'filetype' is set, trigger the FileType autocommand.
7585 * Skip this when called from a modeline and the filetype was
7586 * already set to this value. */
7587 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7588 {
7589 did_filetype = TRUE;
7590 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007591 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007592 /* Just in case the old "curbuf" is now invalid. */
7593 if (varp != &(curbuf->b_p_ft))
7594 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007595 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007596 }
7597#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007598#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007599 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007600 {
7601 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007602 char_u *q = curwin->w_s->b_p_spl;
7603
7604 /* Skip the first name if it is "cjk". */
7605 if (STRNCMP(q, "cjk,", 4) == 0)
7606 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007607
7608 /*
7609 * Source the spell/LANG.vim in 'runtimepath'.
7610 * They could set 'spellcapcheck' depending on the language.
7611 * Use the first name in 'spelllang' up to '_region' or
7612 * '.encoding'.
7613 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007614 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007615 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7616 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007617 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007618 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007619 }
7620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621 }
7622
7623#ifdef FEAT_MOUSE
7624 if (varp == &p_mouse)
7625 {
7626# ifdef FEAT_MOUSE_TTY
7627 if (*p_mouse == NUL)
7628 mch_setmouse(FALSE); /* switch mouse off */
7629 else
7630# endif
7631 setmouse(); /* in case 'mouse' changed */
7632 }
7633#endif
7634
Bram Moolenaar913077c2012-03-28 19:59:04 +02007635 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007636 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007637 curwin->w_set_curswant = TRUE;
7638
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007639#ifdef FEAT_GUI
7640 /* check redraw when it's not a GUI option or the GUI is active. */
7641 if (!redraw_gui_only || gui.in_use)
7642#endif
7643 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007644
7645 return errmsg;
7646}
7647
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007648#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007649/*
7650 * Simple int comparison function for use with qsort()
7651 */
7652 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007653int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007654{
7655 return *(const int *)a - *(const int *)b;
7656}
7657
7658/*
7659 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7660 * Returns error message, NULL if it's OK.
7661 */
7662 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007663check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007664{
7665 char_u *s;
7666 int col;
7667 int count = 0;
7668 int color_cols[256];
7669 int i;
7670 int j = 0;
7671
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007672 if (wp->w_buffer == NULL)
7673 return NULL; /* buffer was closed */
7674
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007675 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007676 {
7677 if (*s == '-' || *s == '+')
7678 {
7679 /* -N and +N: add to 'textwidth' */
7680 col = (*s == '-') ? -1 : 1;
7681 ++s;
7682 if (!VIM_ISDIGIT(*s))
7683 return e_invarg;
7684 col = col * getdigits(&s);
7685 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007686 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007687 col += wp->w_buffer->b_p_tw;
7688 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007689 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007690 }
7691 else if (VIM_ISDIGIT(*s))
7692 col = getdigits(&s);
7693 else
7694 return e_invarg;
7695 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007696skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007697 if (*s == NUL)
7698 break;
7699 if (*s != ',')
7700 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007701 if (*++s == NUL)
7702 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007703 }
7704
7705 vim_free(wp->w_p_cc_cols);
7706 if (count == 0)
7707 wp->w_p_cc_cols = NULL;
7708 else
7709 {
7710 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7711 if (wp->w_p_cc_cols != NULL)
7712 {
7713 /* sort the columns for faster usage on screen redraw inside
7714 * win_line() */
7715 qsort(color_cols, count, sizeof(int), int_cmp);
7716
7717 for (i = 0; i < count; ++i)
7718 /* skip duplicates */
7719 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7720 wp->w_p_cc_cols[j++] = color_cols[i];
7721 wp->w_p_cc_cols[j] = -1; /* end marker */
7722 }
7723 }
7724
7725 return NULL; /* no error */
7726}
7727#endif
7728
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729/*
7730 * Handle setting 'listchars' or 'fillchars'.
7731 * Returns error message, NULL if it's OK.
7732 */
7733 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007734set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735{
7736 int round, i, len, entries;
7737 char_u *p, *s;
7738 int c1, c2 = 0;
7739 struct charstab
7740 {
7741 int *cp;
7742 char *name;
7743 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007744 static struct charstab filltab[] =
7745 {
7746 {&fill_stl, "stl"},
7747 {&fill_stlnc, "stlnc"},
7748 {&fill_vert, "vert"},
7749 {&fill_fold, "fold"},
7750 {&fill_diff, "diff"},
7751 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007752 static struct charstab lcstab[] =
7753 {
7754 {&lcs_eol, "eol"},
7755 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007756 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007757 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007758 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759 {&lcs_tab2, "tab"},
7760 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007761#ifdef FEAT_CONCEAL
7762 {&lcs_conceal, "conceal"},
7763#else
7764 {NULL, "conceal"},
7765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766 };
7767 struct charstab *tab;
7768
Bram Moolenaar071d4272004-06-13 20:20:40 +00007769 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770 {
7771 tab = lcstab;
7772 entries = sizeof(lcstab) / sizeof(struct charstab);
7773 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774 else
7775 {
7776 tab = filltab;
7777 entries = sizeof(filltab) / sizeof(struct charstab);
7778 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779
7780 /* first round: check for valid value, second round: assign values */
7781 for (round = 0; round <= 1; ++round)
7782 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007783 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784 {
7785 /* After checking that the value is valid: set defaults: space for
7786 * 'fillchars', NUL for 'listchars' */
7787 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007788 if (tab[i].cp != NULL)
7789 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007790 if (varp == &p_lcs)
7791 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792 else
7793 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007794 }
7795 p = *varp;
7796 while (*p)
7797 {
7798 for (i = 0; i < entries; ++i)
7799 {
7800 len = (int)STRLEN(tab[i].name);
7801 if (STRNCMP(p, tab[i].name, len) == 0
7802 && p[len] == ':'
7803 && p[len + 1] != NUL)
7804 {
7805 s = p + len + 1;
7806#ifdef FEAT_MBYTE
7807 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007808 if (mb_char2cells(c1) > 1)
7809 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810#else
7811 c1 = *s++;
7812#endif
7813 if (tab[i].cp == &lcs_tab2)
7814 {
7815 if (*s == NUL)
7816 continue;
7817#ifdef FEAT_MBYTE
7818 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007819 if (mb_char2cells(c2) > 1)
7820 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007821#else
7822 c2 = *s++;
7823#endif
7824 }
7825 if (*s == ',' || *s == NUL)
7826 {
7827 if (round)
7828 {
7829 if (tab[i].cp == &lcs_tab2)
7830 {
7831 lcs_tab1 = c1;
7832 lcs_tab2 = c2;
7833 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007834 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007835 *(tab[i].cp) = c1;
7836
7837 }
7838 p = s;
7839 break;
7840 }
7841 }
7842 }
7843
7844 if (i == entries)
7845 return e_invarg;
7846 if (*p == ',')
7847 ++p;
7848 }
7849 }
7850
7851 return NULL; /* no error */
7852}
7853
7854#ifdef FEAT_STL_OPT
7855/*
7856 * Check validity of options with the 'statusline' format.
7857 * Return error message or NULL.
7858 */
7859 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007860check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861{
7862 int itemcnt = 0;
7863 int groupdepth = 0;
7864 static char_u errbuf[80];
7865
7866 while (*s && itemcnt < STL_MAX_ITEM)
7867 {
7868 /* Check for valid keys after % sequences */
7869 while (*s && *s != '%')
7870 s++;
7871 if (!*s)
7872 break;
7873 s++;
7874 if (*s != '%' && *s != ')')
7875 ++itemcnt;
7876 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7877 {
7878 s++;
7879 continue;
7880 }
7881 if (*s == ')')
7882 {
7883 s++;
7884 if (--groupdepth < 0)
7885 break;
7886 continue;
7887 }
7888 if (*s == '-')
7889 s++;
7890 while (VIM_ISDIGIT(*s))
7891 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007892 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007893 continue;
7894 if (*s == '.')
7895 {
7896 s++;
7897 while (*s && VIM_ISDIGIT(*s))
7898 s++;
7899 }
7900 if (*s == '(')
7901 {
7902 groupdepth++;
7903 continue;
7904 }
7905 if (vim_strchr(STL_ALL, *s) == NULL)
7906 {
7907 return illegal_char(errbuf, *s);
7908 }
7909 if (*s == '{')
7910 {
7911 s++;
7912 while (*s != '}' && *s)
7913 s++;
7914 if (*s != '}')
7915 return (char_u *)N_("E540: Unclosed expression sequence");
7916 }
7917 }
7918 if (itemcnt >= STL_MAX_ITEM)
7919 return (char_u *)N_("E541: too many items");
7920 if (groupdepth != 0)
7921 return (char_u *)N_("E542: unbalanced groups");
7922 return NULL;
7923}
7924#endif
7925
7926#ifdef FEAT_CLIPBOARD
7927/*
7928 * Extract the items in the 'clipboard' option and set global values.
7929 */
7930 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007931check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007932{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007933 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007934 int new_autoselect_star = FALSE;
7935 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007937 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 regprog_T *new_exclude_prog = NULL;
7939 char_u *errmsg = NULL;
7940 char_u *p;
7941
7942 for (p = p_cb; *p != NUL; )
7943 {
7944 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7945 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007946 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 p += 7;
7948 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007949 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007950 && (p[11] == ',' || p[11] == NUL))
7951 {
7952 new_unnamed |= CLIP_UNNAMED_PLUS;
7953 p += 11;
7954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007955 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007956 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007958 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959 p += 10;
7960 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007961 else if (STRNCMP(p, "autoselectplus", 14) == 0
7962 && (p[14] == ',' || p[14] == NUL))
7963 {
7964 new_autoselect_plus = TRUE;
7965 p += 14;
7966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007968 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969 {
7970 new_autoselectml = TRUE;
7971 p += 12;
7972 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007973 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7974 {
7975 new_html = TRUE;
7976 p += 4;
7977 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7979 {
7980 p += 8;
7981 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7982 if (new_exclude_prog == NULL)
7983 errmsg = e_invarg;
7984 break;
7985 }
7986 else
7987 {
7988 errmsg = e_invarg;
7989 break;
7990 }
7991 if (*p == ',')
7992 ++p;
7993 }
7994 if (errmsg == NULL)
7995 {
7996 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007997 clip_autoselect_star = new_autoselect_star;
7998 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008000 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008001 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008003#ifdef FEAT_GUI_GTK
8004 if (gui.in_use)
8005 {
8006 gui_gtk_set_selection_targets();
8007 gui_gtk_set_dnd_targets();
8008 }
8009#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 }
8011 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008012 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013
8014 return errmsg;
8015}
8016#endif
8017
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008018#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008019 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008020did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008021{
8022 char_u *errmsg = NULL;
8023 win_T *wp;
8024 int l;
8025
8026 if (is_spellfile)
8027 {
8028 l = (int)STRLEN(curwin->w_s->b_p_spf);
8029 if (l > 0 && (l < 4
8030 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8031 errmsg = e_invarg;
8032 }
8033
8034 if (errmsg == NULL)
8035 {
8036 FOR_ALL_WINDOWS(wp)
8037 if (wp->w_buffer == curbuf && wp->w_p_spell)
8038 {
8039 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008040 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008041 }
8042 }
8043 return errmsg;
8044}
8045
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008046/*
8047 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8048 * Return error message when failed, NULL when OK.
8049 */
8050 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008051compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008052{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008053 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008054 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008055
Bram Moolenaar860cae12010-06-05 23:22:07 +02008056 if (*synblock->b_p_spc == NUL)
8057 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008058 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008059 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008060 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008061 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008062 if (re != NULL)
8063 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008064 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008065 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008066 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008067 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008068 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008069 return e_invarg;
8070 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008071 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008072 }
8073
Bram Moolenaar473de612013-06-08 18:19:48 +02008074 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008075 return NULL;
8076}
8077#endif
8078
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008079#if defined(FEAT_EVAL) || defined(PROTO)
8080/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008081 * Set the scriptID for an option, taking care of setting the buffer- or
8082 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008083 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008084 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008085set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008086{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008087 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8088 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008089
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008090 /* Remember where the option was set. For local options need to do that
8091 * in the buffer or window structure. */
8092 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008093 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008094 if (both || (opt_flags & OPT_LOCAL))
8095 {
8096 if (indir & PV_BUF)
8097 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8098 else if (indir & PV_WIN)
8099 curwin->w_p_scriptID[indir & PV_MASK] = id;
8100 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008101}
8102#endif
8103
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104/*
8105 * Set the value of a boolean option, and take care of side effects.
8106 * Returns NULL for success, or an error message for an error.
8107 */
8108 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008109set_bool_option(
8110 int opt_idx, /* index in options[] table */
8111 char_u *varp, /* pointer to the option variable */
8112 int value, /* new value */
8113 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114{
8115 int old_value = *(int *)varp;
8116
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 /* Disallow changing some options from secure mode */
8118 if ((secure
8119#ifdef HAVE_SANDBOX
8120 || sandbox != 0
8121#endif
8122 ) && (options[opt_idx].flags & P_SECURE))
8123 return e_secure;
8124
8125 *(int *)varp = value; /* set the new value */
8126#ifdef FEAT_EVAL
8127 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008128 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008129#endif
8130
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008131#ifdef FEAT_GUI
8132 need_mouse_correct = TRUE;
8133#endif
8134
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 /* May set global value for local option. */
8136 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8137 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8138
8139 /*
8140 * Handle side effects of changing a bool option.
8141 */
8142
8143 /* 'compatible' */
8144 if ((int *)varp == &p_cp)
8145 {
8146 compatible_set();
8147 }
8148
Bram Moolenaar920694c2016-08-21 17:45:02 +02008149#ifdef FEAT_LANGMAP
8150 if ((int *)varp == &p_lrm)
8151 /* 'langremap' -> !'langnoremap' */
8152 p_lnr = !p_lrm;
8153 else if ((int *)varp == &p_lnr)
8154 /* 'langnoremap' -> !'langremap' */
8155 p_lrm = !p_lnr;
8156#endif
8157
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008158#ifdef FEAT_PERSISTENT_UNDO
8159 /* 'undofile' */
8160 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8161 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008162 /* Only take action when the option was set. When reset we do not
8163 * delete the undo file, the option may be set again without making
8164 * any changes in between. */
8165 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008166 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008167 char_u hash[UNDO_HASH_SIZE];
8168 buf_T *save_curbuf = curbuf;
8169
Bram Moolenaar29323592016-07-24 22:04:11 +02008170 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008171 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008172 /* When 'undofile' is set globally: for every buffer, otherwise
8173 * only for the current buffer: Try to read in the undofile,
8174 * if one exists, the buffer wasn't changed and the buffer was
8175 * loaded */
8176 if ((curbuf == save_curbuf
8177 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8178 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8179 {
8180 u_compute_hash(hash);
8181 u_read_undo(NULL, hash, curbuf->b_fname);
8182 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008183 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008184 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008185 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008186 }
8187#endif
8188
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189 else if ((int *)varp == &curbuf->b_p_ro)
8190 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008191 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8193 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008194
8195 /* when 'readonly' is set may give W10 again */
8196 if (curbuf->b_p_ro)
8197 curbuf->b_did_warn = FALSE;
8198
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008200 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008201#endif
8202 }
8203
Bram Moolenaar9c449722010-07-20 18:44:27 +02008204#ifdef FEAT_GUI
8205 else if ((int *)varp == &p_mh)
8206 {
8207 if (!p_mh)
8208 gui_mch_mousehide(FALSE);
8209 }
8210#endif
8211
Bram Moolenaara539df02010-08-01 14:35:05 +02008212 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008213 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008214 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008215# ifdef FEAT_TERMINAL
8216 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008217 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008218 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008219 {
8220 curbuf->b_p_ma = FALSE;
8221 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8222 }
8223# endif
8224# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008225 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008226# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008227 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008228#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008229 /* when 'endofline' is changed, redraw the window title */
8230 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008231 {
8232 redraw_titles();
8233 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008234 /* when 'fixeol' is changed, redraw the window title */
8235 else if ((int *)varp == &curbuf->b_p_fixeol)
8236 {
8237 redraw_titles();
8238 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008239# ifdef FEAT_MBYTE
8240 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008241 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008242 {
8243 redraw_titles();
8244 }
8245# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008246#endif
8247
8248 /* when 'bin' is set also set some other options */
8249 else if ((int *)varp == &curbuf->b_p_bin)
8250 {
8251 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8252#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008253 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008254#endif
8255 }
8256
8257#ifdef FEAT_AUTOCMD
8258 /* when 'buflisted' changes, trigger autocommands */
8259 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8260 {
8261 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8262 NULL, NULL, TRUE, curbuf);
8263 }
8264#endif
8265
8266 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8267 else if ((int *)varp == &curbuf->b_p_swf)
8268 {
8269 if (curbuf->b_p_swf && p_uc)
8270 ml_open_file(curbuf); /* create the swap file */
8271 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008272 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8273 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008274 mf_close_file(curbuf, TRUE); /* remove the swap file */
8275 }
8276
8277 /* when 'terse' is set change 'shortmess' */
8278 else if ((int *)varp == &p_terse)
8279 {
8280 char_u *p;
8281
8282 p = vim_strchr(p_shm, SHM_SEARCH);
8283
8284 /* insert 's' in p_shm */
8285 if (p_terse && p == NULL)
8286 {
8287 STRCPY(IObuff, p_shm);
8288 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008289 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 }
8291 /* remove 's' from p_shm */
8292 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008293 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008294 }
8295
8296 /* when 'paste' is set or reset also change other options */
8297 else if ((int *)varp == &p_paste)
8298 {
8299 paste_option_changed();
8300 }
8301
8302 /* when 'insertmode' is set from an autocommand need to do work here */
8303 else if ((int *)varp == &p_im)
8304 {
8305 if (p_im)
8306 {
8307 if ((State & INSERT) == 0)
8308 need_start_insertmode = TRUE;
8309 stop_insert_mode = FALSE;
8310 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008311 /* only reset if it was set previously */
8312 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008313 {
8314 need_start_insertmode = FALSE;
8315 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008316 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008317 clear_cmdline = TRUE; /* remove "(insert)" */
8318 restart_edit = 0;
8319 }
8320 }
8321
8322 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8323 else if ((int *)varp == &p_ic && p_hls)
8324 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008325 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 }
8327
8328#ifdef FEAT_SEARCH_EXTRA
8329 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8330 else if ((int *)varp == &p_hls)
8331 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008332 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008333 }
8334#endif
8335
8336#ifdef FEAT_SCROLLBIND
8337 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8338 * at the end of normal_cmd() */
8339 else if ((int *)varp == &curwin->w_p_scb)
8340 {
8341 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008342 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008344 curwin->w_scbind_pos = curwin->w_topline;
8345 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008346 }
8347#endif
8348
Bram Moolenaar4033c552017-09-16 20:54:51 +02008349#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350 /* There can be only one window with 'previewwindow' set. */
8351 else if ((int *)varp == &curwin->w_p_pvw)
8352 {
8353 if (curwin->w_p_pvw)
8354 {
8355 win_T *win;
8356
Bram Moolenaar29323592016-07-24 22:04:11 +02008357 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008358 if (win->w_p_pvw && win != curwin)
8359 {
8360 curwin->w_p_pvw = FALSE;
8361 return (char_u *)N_("E590: A preview window already exists");
8362 }
8363 }
8364 }
8365#endif
8366
8367 /* when 'textmode' is set or reset also change 'fileformat' */
8368 else if ((int *)varp == &curbuf->b_p_tx)
8369 {
8370 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8371 }
8372
8373 /* when 'textauto' is set or reset also change 'fileformats' */
8374 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375 set_string_option_direct((char_u *)"ffs", -1,
8376 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008377 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008378
8379 /*
8380 * When 'lisp' option changes include/exclude '-' in
8381 * keyword characters.
8382 */
8383#ifdef FEAT_LISP
8384 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8385 {
8386 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8387 }
8388#endif
8389
8390#ifdef FEAT_TITLE
8391 /* when 'title' changed, may need to change the title; same for 'icon' */
8392 else if ((int *)varp == &p_title)
8393 {
8394 did_set_title(FALSE);
8395 }
8396
8397 else if ((int *)varp == &p_icon)
8398 {
8399 did_set_title(TRUE);
8400 }
8401#endif
8402
8403 else if ((int *)varp == &curbuf->b_changed)
8404 {
8405 if (!value)
8406 save_file_ff(curbuf); /* Buffer is unchanged */
8407#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008408 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409#endif
8410#ifdef FEAT_AUTOCMD
8411 modified_was_set = value;
8412#endif
8413 }
8414
8415#ifdef BACKSLASH_IN_FILENAME
8416 else if ((int *)varp == &p_ssl)
8417 {
8418 if (p_ssl)
8419 {
8420 psepc = '/';
8421 psepcN = '\\';
8422 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 }
8424 else
8425 {
8426 psepc = '\\';
8427 psepcN = '/';
8428 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008429 }
8430
8431 /* need to adjust the file name arguments and buffer names. */
8432 buflist_slash_adjust();
8433 alist_slash_adjust();
8434# ifdef FEAT_EVAL
8435 scriptnames_slash_adjust();
8436# endif
8437 }
8438#endif
8439
8440 /* If 'wrap' is set, set w_leftcol to zero. */
8441 else if ((int *)varp == &curwin->w_p_wrap)
8442 {
8443 if (curwin->w_p_wrap)
8444 curwin->w_leftcol = 0;
8445 }
8446
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447 else if ((int *)varp == &p_ea)
8448 {
8449 if (p_ea && !old_value)
8450 win_equal(curwin, FALSE, 0);
8451 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008452
8453 else if ((int *)varp == &p_wiv)
8454 {
8455 /*
8456 * When 'weirdinvert' changed, set/reset 't_xs'.
8457 * Then set 'weirdinvert' according to value of 't_xs'.
8458 */
8459 if (p_wiv && !old_value)
8460 T_XS = (char_u *)"y";
8461 else if (!p_wiv && old_value)
8462 T_XS = empty_option;
8463 p_wiv = (*T_XS != NUL);
8464 }
8465
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008466#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008467 else if ((int *)varp == &p_beval)
8468 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008469 if (!balloonEvalForTerm)
8470 {
8471 if (p_beval && !old_value)
8472 gui_mch_enable_beval_area(balloonEval);
8473 else if (!p_beval && old_value)
8474 gui_mch_disable_beval_area(balloonEval);
8475 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008476 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008477#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008478#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008479 else if ((int *)varp == &p_bevalterm)
8480 {
8481 mch_bevalterm_changed();
8482 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008484
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008485#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486 else if ((int *)varp == &p_acd)
8487 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008488 /* Change directories when the 'acd' option is set now. */
8489 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008490 }
8491#endif
8492
8493#ifdef FEAT_DIFF
8494 /* 'diff' */
8495 else if ((int *)varp == &curwin->w_p_diff)
8496 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008497 /* May add or remove the buffer from the list of diff buffers. */
8498 diff_buf_adjust(curwin);
8499# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500 if (foldmethodIsDiff(curwin))
8501 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008502# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008503 }
8504#endif
8505
Bram Moolenaar819edbe2017-11-25 17:14:33 +01008506#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008507 /* 'imdisable' */
8508 else if ((int *)varp == &p_imdisable)
8509 {
8510 /* Only de-activate it here, it will be enabled when changing mode. */
8511 if (p_imdisable)
8512 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008513 else if (State & INSERT)
8514 /* When the option is set from an autocommand, it may need to take
8515 * effect right away. */
8516 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008517 }
8518#endif
8519
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008520#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008521 /* 'spell' */
8522 else if ((int *)varp == &curwin->w_p_spell)
8523 {
8524 if (curwin->w_p_spell)
8525 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008526 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008527 if (errmsg != NULL)
8528 EMSG(_(errmsg));
8529 }
8530 }
8531#endif
8532
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533#ifdef FEAT_FKMAP
8534 else if ((int *)varp == &p_altkeymap)
8535 {
8536 if (old_value != p_altkeymap)
8537 {
8538 if (!p_altkeymap)
8539 {
8540 p_hkmap = p_fkmap;
8541 p_fkmap = 0;
8542 }
8543 else
8544 {
8545 p_fkmap = p_hkmap;
8546 p_hkmap = 0;
8547 }
8548 (void)init_chartab();
8549 }
8550 }
8551
8552 /*
8553 * In case some second language keymapping options have changed, check
8554 * and correct the setting in a consistent way.
8555 */
8556
8557 /*
8558 * If hkmap or fkmap are set, reset Arabic keymapping.
8559 */
8560 if ((p_hkmap || p_fkmap) && p_altkeymap)
8561 {
8562 p_altkeymap = p_fkmap;
8563# ifdef FEAT_ARABIC
8564 curwin->w_p_arab = FALSE;
8565# endif
8566 (void)init_chartab();
8567 }
8568
8569 /*
8570 * If hkmap set, reset Farsi keymapping.
8571 */
8572 if (p_hkmap && p_altkeymap)
8573 {
8574 p_altkeymap = 0;
8575 p_fkmap = 0;
8576# ifdef FEAT_ARABIC
8577 curwin->w_p_arab = FALSE;
8578# endif
8579 (void)init_chartab();
8580 }
8581
8582 /*
8583 * If fkmap set, reset Hebrew keymapping.
8584 */
8585 if (p_fkmap && !p_altkeymap)
8586 {
8587 p_altkeymap = 1;
8588 p_hkmap = 0;
8589# ifdef FEAT_ARABIC
8590 curwin->w_p_arab = FALSE;
8591# endif
8592 (void)init_chartab();
8593 }
8594#endif
8595
8596#ifdef FEAT_ARABIC
8597 if ((int *)varp == &curwin->w_p_arab)
8598 {
8599 if (curwin->w_p_arab)
8600 {
8601 /*
8602 * 'arabic' is set, handle various sub-settings.
8603 */
8604 if (!p_tbidi)
8605 {
8606 /* set rightleft mode */
8607 if (!curwin->w_p_rl)
8608 {
8609 curwin->w_p_rl = TRUE;
8610 changed_window_setting();
8611 }
8612
8613 /* Enable Arabic shaping (major part of what Arabic requires) */
8614 if (!p_arshape)
8615 {
8616 p_arshape = TRUE;
8617 redraw_later_clear();
8618 }
8619 }
8620
8621 /* Arabic requires a utf-8 encoding, inform the user if its not
8622 * set. */
8623 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008624 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008625 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8626
Bram Moolenaar8820b482017-03-16 17:23:31 +01008627 msg_source(HL_ATTR(HLF_W));
8628 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008629#ifdef FEAT_EVAL
8630 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8631#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008632 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633
8634# ifdef FEAT_MBYTE
8635 /* set 'delcombine' */
8636 p_deco = TRUE;
8637# endif
8638
8639# ifdef FEAT_KEYMAP
8640 /* Force-set the necessary keymap for arabic */
8641 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8642 OPT_LOCAL);
8643# endif
8644# ifdef FEAT_FKMAP
8645 p_altkeymap = 0;
8646 p_hkmap = 0;
8647 p_fkmap = 0;
8648 (void)init_chartab();
8649# endif
8650 }
8651 else
8652 {
8653 /*
8654 * 'arabic' is reset, handle various sub-settings.
8655 */
8656 if (!p_tbidi)
8657 {
8658 /* reset rightleft mode */
8659 if (curwin->w_p_rl)
8660 {
8661 curwin->w_p_rl = FALSE;
8662 changed_window_setting();
8663 }
8664
8665 /* 'arabicshape' isn't reset, it is a global option and
8666 * another window may still need it "on". */
8667 }
8668
8669 /* 'delcombine' isn't reset, it is a global option and another
8670 * window may still want it "on". */
8671
8672# ifdef FEAT_KEYMAP
8673 /* Revert to the default keymap */
8674 curbuf->b_p_iminsert = B_IMODE_NONE;
8675 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8676# endif
8677 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008678 }
8679
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008680#endif
8681
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008682#ifdef FEAT_TERMGUICOLORS
8683 /* 'termguicolors' */
8684 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008685 {
8686# ifdef FEAT_GUI
8687 if (!gui.in_use && !gui.starting)
8688# endif
8689 highlight_gui_started();
8690 }
8691#endif
8692
Bram Moolenaar071d4272004-06-13 20:20:40 +00008693 /*
8694 * End of handling side effects for bool options.
8695 */
8696
Bram Moolenaar53744302015-07-17 17:38:22 +02008697 /* after handling side effects, call autocommand */
8698
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699 options[opt_idx].flags |= P_WAS_SET;
8700
Bram Moolenaar53744302015-07-17 17:38:22 +02008701#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8702 if (!starting)
8703 {
8704 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008705 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8706 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8707 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008708 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8709 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8710 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8711 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8712 reset_v_option_vars();
8713 }
8714#endif
8715
Bram Moolenaar071d4272004-06-13 20:20:40 +00008716 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008717 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008718 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008719 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 check_redraw(options[opt_idx].flags);
8721
8722 return NULL;
8723}
8724
8725/*
8726 * Set the value of a number option, and take care of side effects.
8727 * Returns NULL for success, or an error message for an error.
8728 */
8729 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008730set_num_option(
8731 int opt_idx, /* index in options[] table */
8732 char_u *varp, /* pointer to the option variable */
8733 long value, /* new value */
8734 char_u *errbuf, /* buffer for error messages */
8735 size_t errbuflen, /* length of "errbuf" */
8736 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008737 OPT_MODELINE */
8738{
8739 char_u *errmsg = NULL;
8740 long old_value = *(long *)varp;
8741 long old_Rows = Rows; /* remember old Rows */
8742 long old_Columns = Columns; /* remember old Columns */
8743 long *pp = (long *)varp;
8744
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008745 /* Disallow changing some options from secure mode. */
8746 if ((secure
8747#ifdef HAVE_SANDBOX
8748 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008749#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008750 ) && (options[opt_idx].flags & P_SECURE))
8751 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752
8753 *pp = value;
8754#ifdef FEAT_EVAL
8755 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008756 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008758#ifdef FEAT_GUI
8759 need_mouse_correct = TRUE;
8760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761
Bram Moolenaar14f24742012-08-08 18:01:05 +02008762 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763 {
8764 errmsg = e_positive;
8765 curbuf->b_p_sw = curbuf->b_p_ts;
8766 }
8767
8768 /*
8769 * Number options that need some action when changed
8770 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771 if (pp == &p_wh || pp == &p_hh)
8772 {
8773 if (p_wh < 1)
8774 {
8775 errmsg = e_positive;
8776 p_wh = 1;
8777 }
8778 if (p_wmh > p_wh)
8779 {
8780 errmsg = e_winheight;
8781 p_wh = p_wmh;
8782 }
8783 if (p_hh < 0)
8784 {
8785 errmsg = e_positive;
8786 p_hh = 0;
8787 }
8788
8789 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008790 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008791 {
8792 if (pp == &p_wh && curwin->w_height < p_wh)
8793 win_setheight((int)p_wh);
8794 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8795 win_setheight((int)p_hh);
8796 }
8797 }
8798
8799 /* 'winminheight' */
8800 else if (pp == &p_wmh)
8801 {
8802 if (p_wmh < 0)
8803 {
8804 errmsg = e_positive;
8805 p_wmh = 0;
8806 }
8807 if (p_wmh > p_wh)
8808 {
8809 errmsg = e_winheight;
8810 p_wmh = p_wh;
8811 }
8812 win_setminheight();
8813 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008814 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008815 {
8816 if (p_wiw < 1)
8817 {
8818 errmsg = e_positive;
8819 p_wiw = 1;
8820 }
8821 if (p_wmw > p_wiw)
8822 {
8823 errmsg = e_winwidth;
8824 p_wiw = p_wmw;
8825 }
8826
8827 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008828 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008829 win_setwidth((int)p_wiw);
8830 }
8831
8832 /* 'winminwidth' */
8833 else if (pp == &p_wmw)
8834 {
8835 if (p_wmw < 0)
8836 {
8837 errmsg = e_positive;
8838 p_wmw = 0;
8839 }
8840 if (p_wmw > p_wiw)
8841 {
8842 errmsg = e_winwidth;
8843 p_wmw = p_wiw;
8844 }
8845 win_setminheight();
8846 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008847
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848 /* (re)set last window status line */
8849 else if (pp == &p_ls)
8850 {
8851 last_status(FALSE);
8852 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008853
8854 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008855 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008856 {
8857 shell_new_rows(); /* recompute window positions and heights */
8858 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008859
8860#ifdef FEAT_GUI
8861 else if (pp == &p_linespace)
8862 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008863 /* Recompute gui.char_height and resize the Vim window to keep the
8864 * same number of lines. */
8865 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008866 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008867 }
8868#endif
8869
8870#ifdef FEAT_FOLDING
8871 /* 'foldlevel' */
8872 else if (pp == &curwin->w_p_fdl)
8873 {
8874 if (curwin->w_p_fdl < 0)
8875 curwin->w_p_fdl = 0;
8876 newFoldLevel();
8877 }
8878
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008879 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880 else if (pp == &curwin->w_p_fml)
8881 {
8882 foldUpdateAll(curwin);
8883 }
8884
8885 /* 'foldnestmax' */
8886 else if (pp == &curwin->w_p_fdn)
8887 {
8888 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8889 foldUpdateAll(curwin);
8890 }
8891
8892 /* 'foldcolumn' */
8893 else if (pp == &curwin->w_p_fdc)
8894 {
8895 if (curwin->w_p_fdc < 0)
8896 {
8897 errmsg = e_positive;
8898 curwin->w_p_fdc = 0;
8899 }
8900 else if (curwin->w_p_fdc > 12)
8901 {
8902 errmsg = e_invarg;
8903 curwin->w_p_fdc = 12;
8904 }
8905 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008906#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008908#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008909 /* 'shiftwidth' or 'tabstop' */
8910 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8911 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008912# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 if (foldmethodIsIndent(curwin))
8914 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008915# endif
8916# ifdef FEAT_CINDENT
8917 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8918 * parse 'cinoptions'. */
8919 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8920 parse_cino(curbuf);
8921# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008923#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008925#ifdef FEAT_MBYTE
8926 /* 'maxcombine' */
8927 else if (pp == &p_mco)
8928 {
8929 if (p_mco > MAX_MCO)
8930 p_mco = MAX_MCO;
8931 else if (p_mco < 0)
8932 p_mco = 0;
8933 screenclear(); /* will re-allocate the screen */
8934 }
8935#endif
8936
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937 else if (pp == &curbuf->b_p_iminsert)
8938 {
8939 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8940 {
8941 errmsg = e_invarg;
8942 curbuf->b_p_iminsert = B_IMODE_NONE;
8943 }
8944 p_iminsert = curbuf->b_p_iminsert;
8945 if (termcap_active) /* don't do this in the alternate screen */
8946 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008947#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008948 /* Show/unshow value of 'keymap' in status lines. */
8949 status_redraw_curbuf();
8950#endif
8951 }
8952
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008953#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8954 /* 'imstyle' */
8955 else if (pp == &p_imst)
8956 {
8957 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8958 errmsg = e_invarg;
8959 }
8960#endif
8961
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008962 else if (pp == &p_window)
8963 {
8964 if (p_window < 1)
8965 p_window = 1;
8966 else if (p_window >= Rows)
8967 p_window = Rows - 1;
8968 }
8969
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970 else if (pp == &curbuf->b_p_imsearch)
8971 {
8972 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8973 {
8974 errmsg = e_invarg;
8975 curbuf->b_p_imsearch = B_IMODE_NONE;
8976 }
8977 p_imsearch = curbuf->b_p_imsearch;
8978 }
8979
8980#ifdef FEAT_TITLE
8981 /* if 'titlelen' has changed, redraw the title */
8982 else if (pp == &p_titlelen)
8983 {
8984 if (p_titlelen < 0)
8985 {
8986 errmsg = e_positive;
8987 p_titlelen = 85;
8988 }
8989 if (starting != NO_SCREEN && old_value != p_titlelen)
8990 need_maketitle = TRUE;
8991 }
8992#endif
8993
8994 /* if p_ch changed value, change the command line height */
8995 else if (pp == &p_ch)
8996 {
8997 if (p_ch < 1)
8998 {
8999 errmsg = e_positive;
9000 p_ch = 1;
9001 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009002 if (p_ch > Rows - min_rows() + 1)
9003 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009004
9005 /* Only compute the new window layout when startup has been
9006 * completed. Otherwise the frame sizes may be wrong. */
9007 if (p_ch != old_value && full_screen
9008#ifdef FEAT_GUI
9009 && !gui.starting
9010#endif
9011 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009012 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013 }
9014
9015 /* when 'updatecount' changes from zero to non-zero, open swap files */
9016 else if (pp == &p_uc)
9017 {
9018 if (p_uc < 0)
9019 {
9020 errmsg = e_positive;
9021 p_uc = 100;
9022 }
9023 if (p_uc && !old_value)
9024 ml_open_files();
9025 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009026#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009027 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009028 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009029 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009030 {
9031 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009032 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009033 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009034 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009035 {
9036 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009037 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009038 }
9039 }
9040#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009041#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009042 else if (pp == &p_mzq)
9043 mzvim_reset_timer();
9044#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009045
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009046#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9047 /* 'pyxversion' */
9048 else if (pp == &p_pyx)
9049 {
9050 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9051 errmsg = e_invarg;
9052 }
9053#endif
9054
Bram Moolenaar071d4272004-06-13 20:20:40 +00009055 /* sync undo before 'undolevels' changes */
9056 else if (pp == &p_ul)
9057 {
9058 /* use the old value, otherwise u_sync() may not work properly */
9059 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009060 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061 p_ul = value;
9062 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009063 else if (pp == &curbuf->b_p_ul)
9064 {
9065 /* use the old value, otherwise u_sync() may not work properly */
9066 curbuf->b_p_ul = old_value;
9067 u_sync(TRUE);
9068 curbuf->b_p_ul = value;
9069 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009070
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009071#ifdef FEAT_LINEBREAK
9072 /* 'numberwidth' must be positive */
9073 else if (pp == &curwin->w_p_nuw)
9074 {
9075 if (curwin->w_p_nuw < 1)
9076 {
9077 errmsg = e_positive;
9078 curwin->w_p_nuw = 1;
9079 }
9080 if (curwin->w_p_nuw > 10)
9081 {
9082 errmsg = e_invarg;
9083 curwin->w_p_nuw = 10;
9084 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009085 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009086 }
9087#endif
9088
Bram Moolenaar1a384422010-07-14 19:53:30 +02009089 else if (pp == &curbuf->b_p_tw)
9090 {
9091 if (curbuf->b_p_tw < 0)
9092 {
9093 errmsg = e_positive;
9094 curbuf->b_p_tw = 0;
9095 }
9096#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009097 {
9098 win_T *wp;
9099 tabpage_T *tp;
9100
9101 FOR_ALL_TAB_WINDOWS(tp, wp)
9102 check_colorcolumn(wp);
9103 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009104#endif
9105 }
9106
Bram Moolenaar071d4272004-06-13 20:20:40 +00009107 /*
9108 * Check the bounds for numeric options here
9109 */
9110 if (Rows < min_rows() && full_screen)
9111 {
9112 if (errbuf != NULL)
9113 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009114 vim_snprintf((char *)errbuf, errbuflen,
9115 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 errmsg = errbuf;
9117 }
9118 Rows = min_rows();
9119 }
9120 if (Columns < MIN_COLUMNS && full_screen)
9121 {
9122 if (errbuf != NULL)
9123 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009124 vim_snprintf((char *)errbuf, errbuflen,
9125 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009126 errmsg = errbuf;
9127 }
9128 Columns = MIN_COLUMNS;
9129 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009130 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009131
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132 /*
9133 * If the screen (shell) height has been changed, assume it is the
9134 * physical screenheight.
9135 */
9136 if (old_Rows != Rows || old_Columns != Columns)
9137 {
9138 /* Changing the screen size is not allowed while updating the screen. */
9139 if (updating_screen)
9140 *pp = old_value;
9141 else if (full_screen
9142#ifdef FEAT_GUI
9143 && !gui.starting
9144#endif
9145 )
9146 set_shellsize((int)Columns, (int)Rows, TRUE);
9147 else
9148 {
9149 /* Postpone the resizing; check the size and cmdline position for
9150 * messages. */
9151 check_shellsize();
9152 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9153 cmdline_row = Rows - p_ch;
9154 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009155 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009156 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157 }
9158
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159 if (curbuf->b_p_ts <= 0)
9160 {
9161 errmsg = e_positive;
9162 curbuf->b_p_ts = 8;
9163 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009164 if (p_tm < 0)
9165 {
9166 errmsg = e_positive;
9167 p_tm = 0;
9168 }
9169 if ((curwin->w_p_scr <= 0
9170 || (curwin->w_p_scr > curwin->w_height
9171 && curwin->w_height > 0))
9172 && full_screen)
9173 {
9174 if (pp == &(curwin->w_p_scr))
9175 {
9176 if (curwin->w_p_scr != 0)
9177 errmsg = e_scroll;
9178 win_comp_scroll(curwin);
9179 }
9180 /* If 'scroll' became invalid because of a side effect silently adjust
9181 * it. */
9182 else if (curwin->w_p_scr <= 0)
9183 curwin->w_p_scr = 1;
9184 else /* curwin->w_p_scr > curwin->w_height */
9185 curwin->w_p_scr = curwin->w_height;
9186 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009187 if (p_hi < 0)
9188 {
9189 errmsg = e_positive;
9190 p_hi = 0;
9191 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009192 else if (p_hi > 10000)
9193 {
9194 errmsg = e_invarg;
9195 p_hi = 10000;
9196 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009197 if (p_re < 0 || p_re > 2)
9198 {
9199 errmsg = e_invarg;
9200 p_re = 0;
9201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009202 if (p_report < 0)
9203 {
9204 errmsg = e_positive;
9205 p_report = 1;
9206 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009207 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009208 {
9209 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9210 p_sj = Rows / 2;
9211 else
9212 {
9213 errmsg = e_scroll;
9214 p_sj = 1;
9215 }
9216 }
9217 if (p_so < 0 && full_screen)
9218 {
9219 errmsg = e_scroll;
9220 p_so = 0;
9221 }
9222 if (p_siso < 0 && full_screen)
9223 {
9224 errmsg = e_positive;
9225 p_siso = 0;
9226 }
9227#ifdef FEAT_CMDWIN
9228 if (p_cwh < 1)
9229 {
9230 errmsg = e_positive;
9231 p_cwh = 1;
9232 }
9233#endif
9234 if (p_ut < 0)
9235 {
9236 errmsg = e_positive;
9237 p_ut = 2000;
9238 }
9239 if (p_ss < 0)
9240 {
9241 errmsg = e_positive;
9242 p_ss = 0;
9243 }
9244
9245 /* May set global value for local option. */
9246 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9247 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9248
9249 options[opt_idx].flags |= P_WAS_SET;
9250
Bram Moolenaar53744302015-07-17 17:38:22 +02009251#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9252 if (!starting && errmsg == NULL)
9253 {
9254 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009255 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9256 vim_snprintf((char *)buf_new, 10, "%ld", value);
9257 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009258 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9259 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9260 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9261 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9262 reset_v_option_vars();
9263 }
9264#endif
9265
Bram Moolenaar071d4272004-06-13 20:20:40 +00009266 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009267 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009268 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009269 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009270 check_redraw(options[opt_idx].flags);
9271
9272 return errmsg;
9273}
9274
9275/*
9276 * Called after an option changed: check if something needs to be redrawn.
9277 */
9278 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009279check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280{
9281 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009282 int doclear = (flags & P_RCLR) == P_RCLR;
9283 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009284
Bram Moolenaar071d4272004-06-13 20:20:40 +00009285 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9286 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009287
9288 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9289 changed_window_setting();
9290 if (flags & P_RBUF)
9291 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009292 if (flags & P_RWINONLY)
9293 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009294 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295 redraw_all_later(CLEAR);
9296 else if (all)
9297 redraw_all_later(NOT_VALID);
9298}
9299
9300/*
9301 * Find index for option 'arg'.
9302 * Return -1 if not found.
9303 */
9304 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009305findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306{
9307 int opt_idx;
9308 char *s, *p;
9309 static short quick_tab[27] = {0, 0}; /* quick access table */
9310 int is_term_opt;
9311
9312 /*
9313 * For first call: Initialize the quick-access table.
9314 * It contains the index for the first option that starts with a certain
9315 * letter. There are 26 letters, plus the first "t_" option.
9316 */
9317 if (quick_tab[1] == 0)
9318 {
9319 p = options[0].fullname;
9320 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9321 {
9322 if (s[0] != p[0])
9323 {
9324 if (s[0] == 't' && s[1] == '_')
9325 quick_tab[26] = opt_idx;
9326 else
9327 quick_tab[CharOrdLow(s[0])] = opt_idx;
9328 }
9329 p = s;
9330 }
9331 }
9332
9333 /*
9334 * Check for name starting with an illegal character.
9335 */
9336#ifdef EBCDIC
9337 if (!islower(arg[0]))
9338#else
9339 if (arg[0] < 'a' || arg[0] > 'z')
9340#endif
9341 return -1;
9342
9343 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9344 if (is_term_opt)
9345 opt_idx = quick_tab[26];
9346 else
9347 opt_idx = quick_tab[CharOrdLow(arg[0])];
9348 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9349 {
9350 if (STRCMP(arg, s) == 0) /* match full name */
9351 break;
9352 }
9353 if (s == NULL && !is_term_opt)
9354 {
9355 opt_idx = quick_tab[CharOrdLow(arg[0])];
9356 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9357 {
9358 s = options[opt_idx].shortname;
9359 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9360 break;
9361 s = NULL;
9362 }
9363 }
9364 if (s == NULL)
9365 opt_idx = -1;
9366 return opt_idx;
9367}
9368
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009369#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370/*
9371 * Get the value for an option.
9372 *
9373 * Returns:
9374 * Number or Toggle option: 1, *numval gets value.
9375 * String option: 0, *stringval gets allocated string.
9376 * Hidden Number or Toggle option: -1.
9377 * hidden String option: -2.
9378 * unknown option: -3.
9379 */
9380 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009381get_option_value(
9382 char_u *name,
9383 long *numval,
9384 char_u **stringval, /* NULL when only checking existence */
9385 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009386{
9387 int opt_idx;
9388 char_u *varp;
9389
9390 opt_idx = findoption(name);
9391 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009392 {
9393 int key;
9394
9395 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9396 && (key = find_key_option(name)) != 0)
9397 {
9398 char_u key_name[2];
9399 char_u *p;
9400
9401 if (key < 0)
9402 {
9403 key_name[0] = KEY2TERMCAP0(key);
9404 key_name[1] = KEY2TERMCAP1(key);
9405 }
9406 else
9407 {
9408 key_name[0] = KS_KEY;
9409 key_name[1] = (key & 0xff);
9410 }
9411 p = find_termcode(key_name);
9412 if (p != NULL)
9413 {
9414 if (stringval != NULL)
9415 *stringval = vim_strsave(p);
9416 return 0;
9417 }
9418 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009419 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009420 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009421
9422 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9423
9424 if (options[opt_idx].flags & P_STRING)
9425 {
9426 if (varp == NULL) /* hidden option */
9427 return -2;
9428 if (stringval != NULL)
9429 {
9430#ifdef FEAT_CRYPT
9431 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009432 if ((char_u **)varp == &curbuf->b_p_key
9433 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009434 *stringval = vim_strsave((char_u *)"*****");
9435 else
9436#endif
9437 *stringval = vim_strsave(*(char_u **)(varp));
9438 }
9439 return 0;
9440 }
9441
9442 if (varp == NULL) /* hidden option */
9443 return -1;
9444 if (options[opt_idx].flags & P_NUM)
9445 *numval = *(long *)varp;
9446 else
9447 {
9448 /* Special case: 'modified' is b_changed, but we also want to consider
9449 * it set when 'ff' or 'fenc' changed. */
9450 if ((int *)varp == &curbuf->b_changed)
9451 *numval = curbufIsChanged();
9452 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009453 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009454 }
9455 return 1;
9456}
9457#endif
9458
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009459#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009460/*
9461 * Returns the option attributes and its value. Unlike the above function it
9462 * will return either global value or local value of the option depending on
9463 * what was requested, but it will never return global value if it was
9464 * requested to return local one and vice versa. Neither it will return
9465 * buffer-local value if it was requested to return window-local one.
9466 *
9467 * Pretends that option is absent if it is not present in the requested scope
9468 * (i.e. has no global, window-local or buffer-local value depending on
9469 * opt_type). Uses
9470 *
9471 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009472 * 0 hidden or unknown option, also option that does not have requested
9473 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009474 * see SOPT_* in vim.h for other flags
9475 *
9476 * Possible opt_type values: see SREQ_* in vim.h
9477 */
9478 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009479get_option_value_strict(
9480 char_u *name,
9481 long *numval,
9482 char_u **stringval, /* NULL when only obtaining attributes */
9483 int opt_type,
9484 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009485{
9486 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009487 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009488 struct vimoption *p;
9489 int r = 0;
9490
9491 opt_idx = findoption(name);
9492 if (opt_idx < 0)
9493 return 0;
9494
9495 p = &(options[opt_idx]);
9496
9497 /* Hidden option */
9498 if (p->var == NULL)
9499 return 0;
9500
9501 if (p->flags & P_BOOL)
9502 r |= SOPT_BOOL;
9503 else if (p->flags & P_NUM)
9504 r |= SOPT_NUM;
9505 else if (p->flags & P_STRING)
9506 r |= SOPT_STRING;
9507
9508 if (p->indir == PV_NONE)
9509 {
9510 if (opt_type == SREQ_GLOBAL)
9511 r |= SOPT_GLOBAL;
9512 else
9513 return 0; /* Did not request global-only option */
9514 }
9515 else
9516 {
9517 if (p->indir & PV_BOTH)
9518 r |= SOPT_GLOBAL;
9519 else if (opt_type == SREQ_GLOBAL)
9520 return 0; /* Requested global option */
9521
9522 if (p->indir & PV_WIN)
9523 {
9524 if (opt_type == SREQ_BUF)
9525 return 0; /* Did not request window-local option */
9526 else
9527 r |= SOPT_WIN;
9528 }
9529 else if (p->indir & PV_BUF)
9530 {
9531 if (opt_type == SREQ_WIN)
9532 return 0; /* Did not request buffer-local option */
9533 else
9534 r |= SOPT_BUF;
9535 }
9536 }
9537
9538 if (stringval == NULL)
9539 return r;
9540
9541 if (opt_type == SREQ_GLOBAL)
9542 varp = p->var;
9543 else
9544 {
9545 if (opt_type == SREQ_BUF)
9546 {
9547 /* Special case: 'modified' is b_changed, but we also want to
9548 * consider it set when 'ff' or 'fenc' changed. */
9549 if (p->indir == PV_MOD)
9550 {
9551 *numval = bufIsChanged((buf_T *) from);
9552 varp = NULL;
9553 }
9554#ifdef FEAT_CRYPT
9555 else if (p->indir == PV_KEY)
9556 {
9557 /* never return the value of the crypt key */
9558 *stringval = NULL;
9559 varp = NULL;
9560 }
9561#endif
9562 else
9563 {
9564 aco_save_T aco;
9565 aucmd_prepbuf(&aco, (buf_T *) from);
9566 varp = get_varp(p);
9567 aucmd_restbuf(&aco);
9568 }
9569 }
9570 else if (opt_type == SREQ_WIN)
9571 {
9572 win_T *save_curwin;
9573 save_curwin = curwin;
9574 curwin = (win_T *) from;
9575 curbuf = curwin->w_buffer;
9576 varp = get_varp(p);
9577 curwin = save_curwin;
9578 curbuf = curwin->w_buffer;
9579 }
9580 if (varp == p->var)
9581 return (r | SOPT_UNSET);
9582 }
9583
9584 if (varp != NULL)
9585 {
9586 if (p->flags & P_STRING)
9587 *stringval = vim_strsave(*(char_u **)(varp));
9588 else if (p->flags & P_NUM)
9589 *numval = *(long *) varp;
9590 else
9591 *numval = *(int *)varp;
9592 }
9593
9594 return r;
9595}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009596
9597/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009598 * Iterate over options. First argument is a pointer to a pointer to a
9599 * structure inside options[] array, second is option type like in the above
9600 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009601 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009602 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009603 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009604 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009605 * first argument to NULL.
9606 *
9607 * Returns full option name for current option on each call.
9608 */
9609 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009610option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009611{
9612 struct vimoption *ret = NULL;
9613 do
9614 {
9615 if (*option == NULL)
9616 *option = (void *) options;
9617 else if (((struct vimoption *) (*option))->fullname == NULL)
9618 {
9619 *option = NULL;
9620 return NULL;
9621 }
9622 else
9623 *option = (void *) (((struct vimoption *) (*option)) + 1);
9624
9625 ret = ((struct vimoption *) (*option));
9626
9627 /* Hidden option */
9628 if (ret->var == NULL)
9629 {
9630 ret = NULL;
9631 continue;
9632 }
9633
9634 switch (opt_type)
9635 {
9636 case SREQ_GLOBAL:
9637 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9638 ret = NULL;
9639 break;
9640 case SREQ_BUF:
9641 if (!(ret->indir & PV_BUF))
9642 ret = NULL;
9643 break;
9644 case SREQ_WIN:
9645 if (!(ret->indir & PV_WIN))
9646 ret = NULL;
9647 break;
9648 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009649 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009650 return NULL;
9651 }
9652 }
9653 while (ret == NULL);
9654
9655 return (char_u *)ret->fullname;
9656}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009657#endif
9658
Bram Moolenaar071d4272004-06-13 20:20:40 +00009659/*
9660 * Set the value of option "name".
9661 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009662 *
9663 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009664 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009665 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009666set_option_value(
9667 char_u *name,
9668 long number,
9669 char_u *string,
9670 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009671{
9672 int opt_idx;
9673 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009674 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009675
9676 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009677 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009678 {
9679 int key;
9680
9681 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9682 && (key = find_key_option(name)) != 0)
9683 {
9684 char_u key_name[2];
9685
9686 if (key < 0)
9687 {
9688 key_name[0] = KEY2TERMCAP0(key);
9689 key_name[1] = KEY2TERMCAP1(key);
9690 }
9691 else
9692 {
9693 key_name[0] = KS_KEY;
9694 key_name[1] = (key & 0xff);
9695 }
9696 add_termcode(key_name, string, FALSE);
9697 if (full_screen)
9698 ttest(FALSE);
9699 redraw_all_later(CLEAR);
9700 return NULL;
9701 }
9702
Bram Moolenaar071d4272004-06-13 20:20:40 +00009703 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009705 else
9706 {
9707 flags = options[opt_idx].flags;
9708#ifdef HAVE_SANDBOX
9709 /* Disallow changing some options in the sandbox */
9710 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009711 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009712 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009713 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009714 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009716 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009717 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009718 else
9719 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009720 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009721 if (varp != NULL) /* hidden option is not changed */
9722 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009723 if (number == 0 && string != NULL)
9724 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009725 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009726
9727 /* Either we are given a string or we are setting option
9728 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009729 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009730 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009731 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009732 {
9733 /* There's another character after zeros or the string
9734 * is empty. In both cases, we are trying to set a
9735 * num option using a string. */
9736 EMSG3(_("E521: Number required: &%s = '%s'"),
9737 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009738 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009739
9740 }
9741 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009743 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009744 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009745 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009746 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009747 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009748 }
9749 }
9750 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009751 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752}
9753
9754/*
9755 * Get the terminal code for a terminal option.
9756 * Returns NULL when not found.
9757 */
9758 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009759get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760{
9761 int opt_idx;
9762 char_u *varp;
9763
9764 if (tname[0] != 't' || tname[1] != '_' ||
9765 tname[2] == NUL || tname[3] == NUL)
9766 return NULL;
9767 if ((opt_idx = findoption(tname)) >= 0)
9768 {
9769 varp = get_varp(&(options[opt_idx]));
9770 if (varp != NULL)
9771 varp = *(char_u **)(varp);
9772 return varp;
9773 }
9774 return find_termcode(tname + 2);
9775}
9776
9777 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009778get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009779{
9780 int i;
9781
9782 i = findoption((char_u *)"hl");
9783 if (i >= 0)
9784 return options[i].def_val[VI_DEFAULT];
9785 return (char_u *)NULL;
9786}
9787
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009788#if defined(FEAT_MBYTE) || defined(PROTO)
9789 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009790get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009791{
9792 int i;
9793
9794 i = findoption((char_u *)"enc");
9795 if (i >= 0)
9796 return options[i].def_val[VI_DEFAULT];
9797 return (char_u *)NULL;
9798}
9799#endif
9800
Bram Moolenaar071d4272004-06-13 20:20:40 +00009801/*
9802 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9803 */
9804 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009805find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009806{
9807 int key;
9808 int modifiers;
9809
9810 /*
9811 * Don't use get_special_key_code() for t_xx, we don't want it to call
9812 * add_termcap_entry().
9813 */
9814 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9815 key = TERMCAP2KEY(arg[2], arg[3]);
9816 else
9817 {
9818 --arg; /* put arg at the '<' */
9819 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009820 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009821 if (modifiers) /* can't handle modifiers here */
9822 key = 0;
9823 }
9824 return key;
9825}
9826
9827/*
9828 * if 'all' == 0: show changed options
9829 * if 'all' == 1: show all normal options
9830 * if 'all' == 2: show all terminal options
9831 */
9832 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009833showoptions(
9834 int all,
9835 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009836{
9837 struct vimoption *p;
9838 int col;
9839 int isterm;
9840 char_u *varp;
9841 struct vimoption **items;
9842 int item_count;
9843 int run;
9844 int row, rows;
9845 int cols;
9846 int i;
9847 int len;
9848
9849#define INC 20
9850#define GAP 3
9851
9852 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9853 PARAM_COUNT));
9854 if (items == NULL)
9855 return;
9856
9857 /* Highlight title */
9858 if (all == 2)
9859 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9860 else if (opt_flags & OPT_GLOBAL)
9861 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9862 else if (opt_flags & OPT_LOCAL)
9863 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9864 else
9865 MSG_PUTS_TITLE(_("\n--- Options ---"));
9866
9867 /*
9868 * do the loop two times:
9869 * 1. display the short items
9870 * 2. display the long items (only strings and numbers)
9871 */
9872 for (run = 1; run <= 2 && !got_int; ++run)
9873 {
9874 /*
9875 * collect the items in items[]
9876 */
9877 item_count = 0;
9878 for (p = &options[0]; p->fullname != NULL; p++)
9879 {
9880 varp = NULL;
9881 isterm = istermoption(p);
9882 if (opt_flags != 0)
9883 {
9884 if (p->indir != PV_NONE && !isterm)
9885 varp = get_varp_scope(p, opt_flags);
9886 }
9887 else
9888 varp = get_varp(p);
9889 if (varp != NULL
9890 && ((all == 2 && isterm)
9891 || (all == 1 && !isterm)
9892 || (all == 0 && !optval_default(p, varp))))
9893 {
9894 if (p->flags & P_BOOL)
9895 len = 1; /* a toggle option fits always */
9896 else
9897 {
9898 option_value2string(p, opt_flags);
9899 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9900 }
9901 if ((len <= INC - GAP && run == 1) ||
9902 (len > INC - GAP && run == 2))
9903 items[item_count++] = p;
9904 }
9905 }
9906
9907 /*
9908 * display the items
9909 */
9910 if (run == 1)
9911 {
9912 cols = (Columns + GAP - 3) / INC;
9913 if (cols == 0)
9914 cols = 1;
9915 rows = (item_count + cols - 1) / cols;
9916 }
9917 else /* run == 2 */
9918 rows = item_count;
9919 for (row = 0; row < rows && !got_int; ++row)
9920 {
9921 msg_putchar('\n'); /* go to next line */
9922 if (got_int) /* 'q' typed in more */
9923 break;
9924 col = 0;
9925 for (i = row; i < item_count; i += rows)
9926 {
9927 msg_col = col; /* make columns */
9928 showoneopt(items[i], opt_flags);
9929 col += INC;
9930 }
9931 out_flush();
9932 ui_breakcheck();
9933 }
9934 }
9935 vim_free(items);
9936}
9937
9938/*
9939 * Return TRUE if option "p" has its default value.
9940 */
9941 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009942optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009943{
9944 int dvi;
9945
9946 if (varp == NULL)
9947 return TRUE; /* hidden option is always at default */
9948 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9949 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009950 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009951 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009952 /* the cast to long is required for Manx C, long_i is
9953 * needed for MSVC */
9954 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009955 /* P_STRING */
9956 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9957}
9958
9959/*
9960 * showoneopt: show the value of one option
9961 * must not be called with a hidden option!
9962 */
9963 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009964showoneopt(
9965 struct vimoption *p,
9966 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009967{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009968 char_u *varp;
9969 int save_silent = silent_mode;
9970
9971 silent_mode = FALSE;
9972 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973
9974 varp = get_varp_scope(p, opt_flags);
9975
9976 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9977 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9978 ? !curbufIsChanged() : !*(int *)varp))
9979 MSG_PUTS("no");
9980 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9981 MSG_PUTS("--");
9982 else
9983 MSG_PUTS(" ");
9984 MSG_PUTS(p->fullname);
9985 if (!(p->flags & P_BOOL))
9986 {
9987 msg_putchar('=');
9988 /* put value string in NameBuff */
9989 option_value2string(p, opt_flags);
9990 msg_outtrans(NameBuff);
9991 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009992
9993 silent_mode = save_silent;
9994 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009995}
9996
9997/*
9998 * Write modified options as ":set" commands to a file.
9999 *
10000 * There are three values for "opt_flags":
10001 * OPT_GLOBAL: Write global option values and fresh values of
10002 * buffer-local options (used for start of a session
10003 * file).
10004 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10005 * curwin (used for a vimrc file).
10006 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10007 * and local values for window-local options of
10008 * curwin. Local values are also written when at the
10009 * default value, because a modeline or autocommand
10010 * may have set them when doing ":edit file" and the
10011 * user has set them back at the default or fresh
10012 * value.
10013 * When "local_only" is TRUE, don't write fresh
10014 * values, only local values (for ":mkview").
10015 * (fresh value = value used for a new buffer or window for a local option).
10016 *
10017 * Return FAIL on error, OK otherwise.
10018 */
10019 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010020makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010021{
10022 struct vimoption *p;
10023 char_u *varp; /* currently used value */
10024 char_u *varp_fresh; /* local value */
10025 char_u *varp_local = NULL; /* fresh value */
10026 char *cmd;
10027 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010028 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010029
10030 /*
10031 * The options that don't have a default (terminal name, columns, lines)
10032 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010033 * Do the loop over "options[]" twice: once for options with the
10034 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010035 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010036 for (pri = 1; pri >= 0; --pri)
10037 {
10038 for (p = &options[0]; !istermoption(p); p++)
10039 if (!(p->flags & P_NO_MKRC)
10040 && !istermoption(p)
10041 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042 {
10043 /* skip global option when only doing locals */
10044 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10045 continue;
10046
10047 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10048 * file, they are always buffer-specific. */
10049 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10050 continue;
10051
10052 /* Global values are only written when not at the default value. */
10053 varp = get_varp_scope(p, opt_flags);
10054 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10055 continue;
10056
10057 round = 2;
10058 if (p->indir != PV_NONE)
10059 {
10060 if (p->var == VAR_WIN)
10061 {
10062 /* skip window-local option when only doing globals */
10063 if (!(opt_flags & OPT_LOCAL))
10064 continue;
10065 /* When fresh value of window-local option is not at the
10066 * default, need to write it too. */
10067 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10068 {
10069 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10070 if (!optval_default(p, varp_fresh))
10071 {
10072 round = 1;
10073 varp_local = varp;
10074 varp = varp_fresh;
10075 }
10076 }
10077 }
10078 }
10079
10080 /* Round 1: fresh value for window-local options.
10081 * Round 2: other values */
10082 for ( ; round <= 2; varp = varp_local, ++round)
10083 {
10084 if (round == 1 || (opt_flags & OPT_GLOBAL))
10085 cmd = "set";
10086 else
10087 cmd = "setlocal";
10088
10089 if (p->flags & P_BOOL)
10090 {
10091 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10092 return FAIL;
10093 }
10094 else if (p->flags & P_NUM)
10095 {
10096 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10097 return FAIL;
10098 }
10099 else /* P_STRING */
10100 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010101#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10102 int do_endif = FALSE;
10103
Bram Moolenaar071d4272004-06-13 20:20:40 +000010104 /* Don't set 'syntax' and 'filetype' again if the value is
10105 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010106 if (
10107# if defined(FEAT_SYN_HL)
10108 p->indir == PV_SYN
10109# if defined(FEAT_AUTOCMD)
10110 ||
10111# endif
10112# endif
10113# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010114 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010115# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010116 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010117 {
10118 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10119 *(char_u **)(varp)) < 0
10120 || put_eol(fd) < 0)
10121 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010122 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010123 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10126 (p->flags & P_EXPAND) != 0) == FAIL)
10127 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010128#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10129 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010130 {
10131 if (put_line(fd, "endif") == FAIL)
10132 return FAIL;
10133 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010134#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010135 }
10136 }
10137 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139 return OK;
10140}
10141
10142#if defined(FEAT_FOLDING) || defined(PROTO)
10143/*
10144 * Generate set commands for the local fold options only. Used when
10145 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10146 */
10147 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010148makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149{
10150 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10151# ifdef FEAT_EVAL
10152 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10153 == FAIL
10154# endif
10155 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10156 == FAIL
10157 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10158 == FAIL
10159 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10160 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10161 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10162 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10163 )
10164 return FAIL;
10165
10166 return OK;
10167}
10168#endif
10169
10170 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010171put_setstring(
10172 FILE *fd,
10173 char *cmd,
10174 char *name,
10175 char_u **valuep,
10176 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010177{
10178 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010179 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180
10181 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10182 return FAIL;
10183 if (*valuep != NULL)
10184 {
10185 /* Output 'pastetoggle' as key names. For other
10186 * options some characters have to be escaped with
10187 * CTRL-V or backslash */
10188 if (valuep == &p_pt)
10189 {
10190 s = *valuep;
10191 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010192 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 return FAIL;
10194 }
10195 else if (expand)
10196 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010197 buf = alloc(MAXPATHL);
10198 if (buf == NULL)
10199 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10201 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010202 {
10203 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010205 }
10206 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207 }
10208 else if (put_escstr(fd, *valuep, 2) == FAIL)
10209 return FAIL;
10210 }
10211 if (put_eol(fd) < 0)
10212 return FAIL;
10213 return OK;
10214}
10215
10216 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010217put_setnum(
10218 FILE *fd,
10219 char *cmd,
10220 char *name,
10221 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010222{
10223 long wc;
10224
10225 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10226 return FAIL;
10227 if (wc_use_keyname((char_u *)valuep, &wc))
10228 {
10229 /* print 'wildchar' and 'wildcharm' as a key name */
10230 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10231 return FAIL;
10232 }
10233 else if (fprintf(fd, "%ld", *valuep) < 0)
10234 return FAIL;
10235 if (put_eol(fd) < 0)
10236 return FAIL;
10237 return OK;
10238}
10239
10240 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010241put_setbool(
10242 FILE *fd,
10243 char *cmd,
10244 char *name,
10245 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246{
Bram Moolenaar893de922007-10-02 18:40:57 +000010247 if (value < 0) /* global/local option using global value */
10248 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010249 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10250 || put_eol(fd) < 0)
10251 return FAIL;
10252 return OK;
10253}
10254
10255/*
10256 * Clear all the terminal options.
10257 * If the option has been allocated, free the memory.
10258 * Terminal options are never hidden or indirect.
10259 */
10260 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010261clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010263 /*
10264 * Reset a few things before clearing the old options. This may cause
10265 * outputting a few things that the terminal doesn't understand, but the
10266 * screen will be cleared later, so this is OK.
10267 */
10268#ifdef FEAT_MOUSE_TTY
10269 mch_setmouse(FALSE); /* switch mouse off */
10270#endif
10271#ifdef FEAT_TITLE
10272 mch_restore_title(3); /* restore window titles */
10273#endif
10274#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10275 /* When starting the GUI close the display opened for the clipboard.
10276 * After restoring the title, because that will need the display. */
10277 if (gui.starting)
10278 clear_xterm_clip();
10279#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010280 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010282 free_termoptions();
10283}
10284
10285 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010286free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010287{
10288 struct vimoption *p;
10289
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290 for (p = &options[0]; p->fullname != NULL; p++)
10291 if (istermoption(p))
10292 {
10293 if (p->flags & P_ALLOCED)
10294 free_string_option(*(char_u **)(p->var));
10295 if (p->flags & P_DEF_ALLOCED)
10296 free_string_option(p->def_val[VI_DEFAULT]);
10297 *(char_u **)(p->var) = empty_option;
10298 p->def_val[VI_DEFAULT] = empty_option;
10299 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10300 }
10301 clear_termcodes();
10302}
10303
10304/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010305 * Free the string for one term option, if it was allocated.
10306 * Set the string to empty_option and clear allocated flag.
10307 * "var" points to the option value.
10308 */
10309 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010310free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010311{
10312 struct vimoption *p;
10313
10314 for (p = &options[0]; p->fullname != NULL; p++)
10315 if (p->var == var)
10316 {
10317 if (p->flags & P_ALLOCED)
10318 free_string_option(*(char_u **)(p->var));
10319 *(char_u **)(p->var) = empty_option;
10320 p->flags &= ~P_ALLOCED;
10321 break;
10322 }
10323}
10324
10325/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 * Set the terminal option defaults to the current value.
10327 * Used after setting the terminal name.
10328 */
10329 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010330set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331{
10332 struct vimoption *p;
10333
10334 for (p = &options[0]; p->fullname != NULL; p++)
10335 {
10336 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10337 {
10338 if (p->flags & P_DEF_ALLOCED)
10339 {
10340 free_string_option(p->def_val[VI_DEFAULT]);
10341 p->flags &= ~P_DEF_ALLOCED;
10342 }
10343 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10344 if (p->flags & P_ALLOCED)
10345 {
10346 p->flags |= P_DEF_ALLOCED;
10347 p->flags &= ~P_ALLOCED; /* don't free the value now */
10348 }
10349 }
10350 }
10351}
10352
10353/*
10354 * return TRUE if 'p' starts with 't_'
10355 */
10356 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010357istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358{
10359 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10360}
10361
10362/*
10363 * Compute columns for ruler and shown command. 'sc_col' is also used to
10364 * decide what the maximum length of a message on the status line can be.
10365 * If there is a status line for the last window, 'sc_col' is independent
10366 * of 'ru_col'.
10367 */
10368
10369#define COL_RULER 17 /* columns needed by standard ruler */
10370
10371 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010372comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010374#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010375 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010376
10377 sc_col = 0;
10378 ru_col = 0;
10379 if (p_ru)
10380 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010381# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010382 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010383# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010385# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010386 /* no last status line, adjust sc_col */
10387 if (!last_has_status)
10388 sc_col = ru_col;
10389 }
10390 if (p_sc)
10391 {
10392 sc_col += SHOWCMD_COLS;
10393 if (!p_ru || last_has_status) /* no need for separating space */
10394 ++sc_col;
10395 }
10396 sc_col = Columns - sc_col;
10397 ru_col = Columns - ru_col;
10398 if (sc_col <= 0) /* screen too narrow, will become a mess */
10399 sc_col = 1;
10400 if (ru_col <= 0)
10401 ru_col = 1;
10402#else
10403 sc_col = Columns;
10404 ru_col = Columns;
10405#endif
10406}
10407
10408/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010409 * Unset local option value, similar to ":set opt<".
10410 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010411 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010412unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413{
10414 struct vimoption *p;
10415 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010416 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010417
10418 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010419 if (opt_idx < 0)
10420 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010421 p = &(options[opt_idx]);
10422
10423 switch ((int)p->indir)
10424 {
10425 /* global option with local value: use local value if it's been set */
10426 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010427 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010428 break;
10429 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010430 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 break;
10432 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010433 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010434 break;
10435 case PV_AR:
10436 buf->b_p_ar = -1;
10437 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010438 case PV_BKC:
10439 clear_string_option(&buf->b_p_bkc);
10440 buf->b_bkc_flags = 0;
10441 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010442 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010443 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010444 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010445 case PV_TC:
10446 clear_string_option(&buf->b_p_tc);
10447 buf->b_tc_flags = 0;
10448 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010449#ifdef FEAT_FIND_ID
10450 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010451 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 break;
10453 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010454 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010455 break;
10456#endif
10457#ifdef FEAT_INS_EXPAND
10458 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010459 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010460 break;
10461 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010462 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010463 break;
10464#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010465 case PV_FP:
10466 clear_string_option(&buf->b_p_fp);
10467 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010468#ifdef FEAT_QUICKFIX
10469 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010470 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010471 break;
10472 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010473 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010474 break;
10475 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010476 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010477 break;
10478#endif
10479#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10480 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010481 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010482 break;
10483#endif
10484#if defined(FEAT_CRYPT)
10485 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010486 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010487 break;
10488#endif
10489#ifdef FEAT_STL_OPT
10490 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010491 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010492 break;
10493#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010494 case PV_UL:
10495 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10496 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010497#ifdef FEAT_LISP
10498 case PV_LW:
10499 clear_string_option(&buf->b_p_lw);
10500 break;
10501#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010502#ifdef FEAT_MBYTE
10503 case PV_MENC:
10504 clear_string_option(&buf->b_p_menc);
10505 break;
10506#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010507 }
10508}
10509
10510/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511 * Get pointer to option variable, depending on local or global scope.
10512 */
10513 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010514get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515{
10516 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10517 {
10518 if (p->var == VAR_WIN)
10519 return (char_u *)GLOBAL_WO(get_varp(p));
10520 return p->var;
10521 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010522 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523 {
10524 switch ((int)p->indir)
10525 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010526 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010528 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10529 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10530 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010531#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010532 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10533 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10534 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010535 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010536 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010537 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010539 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10540 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541#endif
10542#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010543 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10544 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010546#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10547 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10548#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010549#if defined(FEAT_CRYPT)
10550 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10551#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010552#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010553 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010554#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010555 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010556#ifdef FEAT_LISP
10557 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10558#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010559 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010560#ifdef FEAT_MBYTE
10561 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563 }
10564 return NULL; /* "cannot happen" */
10565 }
10566 return get_varp(p);
10567}
10568
10569/*
10570 * Get pointer to option variable.
10571 */
10572 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010573get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574{
10575 /* hidden option, always return NULL */
10576 if (p->var == NULL)
10577 return NULL;
10578
10579 switch ((int)p->indir)
10580 {
10581 case PV_NONE: return p->var;
10582
10583 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010584 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010586 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010588 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010590 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010592 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010594 case PV_TC: return *curbuf->b_p_tc != NUL
10595 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010596 case PV_BKC: return *curbuf->b_p_bkc != NUL
10597 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010598#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010599 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010601 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10603#endif
10604#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010605 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010607 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10609#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010610 case PV_FP: return *curbuf->b_p_fp != NUL
10611 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010613 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010614 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010615 case PV_GP: return *curbuf->b_p_gp != NUL
10616 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10617 case PV_MP: return *curbuf->b_p_mp != NUL
10618 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010620#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10621 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10622 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10623#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010624#if defined(FEAT_CRYPT)
10625 case PV_CM: return *curbuf->b_p_cm != NUL
10626 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10627#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010628#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010629 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010630 ? (char_u *)&(curwin->w_p_stl) : p->var;
10631#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010632 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10633 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010634#ifdef FEAT_LISP
10635 case PV_LW: return *curbuf->b_p_lw != NUL
10636 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10637#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010638#ifdef FEAT_MBYTE
10639 case PV_MENC: return *curbuf->b_p_menc != NUL
10640 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642
10643#ifdef FEAT_ARABIC
10644 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10645#endif
10646 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010647#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010648 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10649#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010650#ifdef FEAT_SYN_HL
10651 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10652 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010653 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010654#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655#ifdef FEAT_DIFF
10656 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10657#endif
10658#ifdef FEAT_FOLDING
10659 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10660 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10661 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10662 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10663 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10664 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10665 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10666# ifdef FEAT_EVAL
10667 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10668 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10669# endif
10670 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10671#endif
10672 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010673 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010674#ifdef FEAT_LINEBREAK
10675 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010677 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010678 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010679#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10681#endif
10682#ifdef FEAT_RIGHTLEFT
10683 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10684 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10685#endif
10686 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10687 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10688#ifdef FEAT_LINEBREAK
10689 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010690 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10691 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010692#endif
10693#ifdef FEAT_SCROLLBIND
10694 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10695#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010696#ifdef FEAT_CURSORBIND
10697 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10698#endif
10699#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010700 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10701 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10702#endif
10703#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010704 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010705 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707
10708 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10709 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10710#ifdef FEAT_MBYTE
10711 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10712#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10714 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010715 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10716 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10717#ifdef FEAT_CINDENT
10718 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10719 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10720 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10721#endif
10722#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10723 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10724#endif
10725#ifdef FEAT_COMMENTS
10726 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10727#endif
10728#ifdef FEAT_FOLDING
10729 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10730#endif
10731#ifdef FEAT_INS_EXPAND
10732 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10733#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010734#ifdef FEAT_COMPL_FUNC
10735 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010736 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010737#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010739 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010740 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10741#ifdef FEAT_MBYTE
10742 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10743#endif
10744 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10745#ifdef FEAT_AUTOCMD
10746 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10747#endif
10748 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010749 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10751 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10752 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10753 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10754#ifdef FEAT_FIND_ID
10755# ifdef FEAT_EVAL
10756 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10757# endif
10758#endif
10759#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10760 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10761 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10762#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010763#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010764 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766#ifdef FEAT_CRYPT
10767 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10768#endif
10769#ifdef FEAT_LISP
10770 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10771#endif
10772 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10773 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10774 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10775 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10776 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010778#ifdef FEAT_TEXTOBJ
10779 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10780#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10782#ifdef FEAT_SMARTINDENT
10783 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10787#ifdef FEAT_SEARCHPATH
10788 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10789#endif
10790 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10791#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010792 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010793 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10794#endif
10795#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010796 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10797 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10798 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799#endif
10800 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10801 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10802 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10803 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010804#ifdef FEAT_PERSISTENT_UNDO
10805 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10808#ifdef FEAT_KEYMAP
10809 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10810#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010811#ifdef FEAT_SIGNS
10812 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10813#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010814 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010815 }
10816 /* always return a valid pointer to avoid a crash! */
10817 return (char_u *)&(curbuf->b_p_wm);
10818}
10819
10820/*
10821 * Get the value of 'equalprg', either the buffer-local one or the global one.
10822 */
10823 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010824get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825{
10826 if (*curbuf->b_p_ep == NUL)
10827 return p_ep;
10828 return curbuf->b_p_ep;
10829}
10830
Bram Moolenaar071d4272004-06-13 20:20:40 +000010831/*
10832 * Copy options from one window to another.
10833 * Used when splitting a window.
10834 */
10835 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010836win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837{
10838 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10839 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10840# ifdef FEAT_RIGHTLEFT
10841# ifdef FEAT_FKMAP
10842 /* Is this right? */
10843 wp_to->w_farsi = wp_from->w_farsi;
10844# endif
10845# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010846#if defined(FEAT_LINEBREAK)
10847 briopt_check(wp_to);
10848#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850
10851/*
10852 * Copy the options from one winopt_T to another.
10853 * Doesn't free the old option values in "to", use clear_winopt() for that.
10854 * The 'scroll' option is not copied, because it depends on the window height.
10855 * The 'previewwindow' option is reset, there can be only one preview window.
10856 */
10857 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010858copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859{
10860#ifdef FEAT_ARABIC
10861 to->wo_arab = from->wo_arab;
10862#endif
10863 to->wo_list = from->wo_list;
10864 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010865 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010866#ifdef FEAT_LINEBREAK
10867 to->wo_nuw = from->wo_nuw;
10868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869#ifdef FEAT_RIGHTLEFT
10870 to->wo_rl = from->wo_rl;
10871 to->wo_rlc = vim_strsave(from->wo_rlc);
10872#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010873#ifdef FEAT_STL_OPT
10874 to->wo_stl = vim_strsave(from->wo_stl);
10875#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010877#ifdef FEAT_DIFF
10878 to->wo_wrap_save = from->wo_wrap_save;
10879#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880#ifdef FEAT_LINEBREAK
10881 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010882 to->wo_bri = from->wo_bri;
10883 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884#endif
10885#ifdef FEAT_SCROLLBIND
10886 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010887 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010888#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010889#ifdef FEAT_CURSORBIND
10890 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010891 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010892#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010893#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010894 to->wo_spell = from->wo_spell;
10895#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010896#ifdef FEAT_SYN_HL
10897 to->wo_cuc = from->wo_cuc;
10898 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010899 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010900#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901#ifdef FEAT_DIFF
10902 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010903 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010905#ifdef FEAT_CONCEAL
10906 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010907 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010908#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010909#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010910 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010911 to->wo_tms = vim_strsave(from->wo_tms);
10912#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913#ifdef FEAT_FOLDING
10914 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010915 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010917 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918 to->wo_fdi = vim_strsave(from->wo_fdi);
10919 to->wo_fml = from->wo_fml;
10920 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010921 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010923 to->wo_fdm_save = from->wo_diff_saved
10924 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010925 to->wo_fdn = from->wo_fdn;
10926# ifdef FEAT_EVAL
10927 to->wo_fde = vim_strsave(from->wo_fde);
10928 to->wo_fdt = vim_strsave(from->wo_fdt);
10929# endif
10930 to->wo_fmr = vim_strsave(from->wo_fmr);
10931#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010932#ifdef FEAT_SIGNS
10933 to->wo_scl = vim_strsave(from->wo_scl);
10934#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935 check_winopt(to); /* don't want NULL pointers */
10936}
10937
10938/*
10939 * Check string options in a window for a NULL value.
10940 */
10941 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010942check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943{
10944 check_winopt(&win->w_onebuf_opt);
10945 check_winopt(&win->w_allbuf_opt);
10946}
10947
10948/*
10949 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10950 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010951 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010952check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010953{
10954#ifdef FEAT_FOLDING
10955 check_string_option(&wop->wo_fdi);
10956 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010957 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010958# ifdef FEAT_EVAL
10959 check_string_option(&wop->wo_fde);
10960 check_string_option(&wop->wo_fdt);
10961# endif
10962 check_string_option(&wop->wo_fmr);
10963#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010964#ifdef FEAT_SIGNS
10965 check_string_option(&wop->wo_scl);
10966#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010967#ifdef FEAT_RIGHTLEFT
10968 check_string_option(&wop->wo_rlc);
10969#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010970#ifdef FEAT_STL_OPT
10971 check_string_option(&wop->wo_stl);
10972#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010973#ifdef FEAT_SYN_HL
10974 check_string_option(&wop->wo_cc);
10975#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010976#ifdef FEAT_CONCEAL
10977 check_string_option(&wop->wo_cocu);
10978#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010979#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010980 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010981 check_string_option(&wop->wo_tms);
10982#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010983#ifdef FEAT_LINEBREAK
10984 check_string_option(&wop->wo_briopt);
10985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010986}
10987
10988/*
10989 * Free the allocated memory inside a winopt_T.
10990 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010991 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010992clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010993{
10994#ifdef FEAT_FOLDING
10995 clear_string_option(&wop->wo_fdi);
10996 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010997 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010998# ifdef FEAT_EVAL
10999 clear_string_option(&wop->wo_fde);
11000 clear_string_option(&wop->wo_fdt);
11001# endif
11002 clear_string_option(&wop->wo_fmr);
11003#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011004#ifdef FEAT_SIGNS
11005 clear_string_option(&wop->wo_scl);
11006#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011007#ifdef FEAT_LINEBREAK
11008 clear_string_option(&wop->wo_briopt);
11009#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010#ifdef FEAT_RIGHTLEFT
11011 clear_string_option(&wop->wo_rlc);
11012#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011013#ifdef FEAT_STL_OPT
11014 clear_string_option(&wop->wo_stl);
11015#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011016#ifdef FEAT_SYN_HL
11017 clear_string_option(&wop->wo_cc);
11018#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011019#ifdef FEAT_CONCEAL
11020 clear_string_option(&wop->wo_cocu);
11021#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011022#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011023 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011024 clear_string_option(&wop->wo_tms);
11025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011026}
11027
11028/*
11029 * Copy global option values to local options for one buffer.
11030 * Used when creating a new buffer and sometimes when entering a buffer.
11031 * flags:
11032 * BCO_ENTER We will enter the buf buffer.
11033 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11034 * appropriate.
11035 * BCO_NOHELP Don't copy the values to a help buffer.
11036 */
11037 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011038buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011039{
11040 int should_copy = TRUE;
11041 char_u *save_p_isk = NULL; /* init for GCC */
11042 int dont_do_help;
11043 int did_isk = FALSE;
11044
11045 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011046 * Skip this when the option defaults have not been set yet. Happens when
11047 * main() allocates the first buffer.
11048 */
11049 if (p_cpo != NULL)
11050 {
11051 /*
11052 * Always copy when entering and 'cpo' contains 'S'.
11053 * Don't copy when already initialized.
11054 * Don't copy when 'cpo' contains 's' and not entering.
11055 * 'S' BCO_ENTER initialized 's' should_copy
11056 * yes yes X X TRUE
11057 * yes no yes X FALSE
11058 * no X yes X FALSE
11059 * X no no yes FALSE
11060 * X no no no TRUE
11061 * no yes no X TRUE
11062 */
11063 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11064 && (buf->b_p_initialized
11065 || (!(flags & BCO_ENTER)
11066 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11067 should_copy = FALSE;
11068
11069 if (should_copy || (flags & BCO_ALWAYS))
11070 {
11071 /* Don't copy the options specific to a help buffer when
11072 * BCO_NOHELP is given or the options were initialized already
11073 * (jumping back to a help file with CTRL-T or CTRL-O) */
11074 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11075 || buf->b_p_initialized;
11076 if (dont_do_help) /* don't free b_p_isk */
11077 {
11078 save_p_isk = buf->b_p_isk;
11079 buf->b_p_isk = NULL;
11080 }
11081 /*
11082 * Always free the allocated strings.
11083 * If not already initialized, set 'readonly' and copy 'fileformat'.
11084 */
11085 if (!buf->b_p_initialized)
11086 {
11087 free_buf_options(buf, TRUE);
11088 buf->b_p_ro = FALSE; /* don't copy readonly */
11089 buf->b_p_tx = p_tx;
11090#ifdef FEAT_MBYTE
11091 buf->b_p_fenc = vim_strsave(p_fenc);
11092#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011093 switch (*p_ffs)
11094 {
11095 case 'm':
11096 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11097 case 'd':
11098 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11099 case 'u':
11100 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11101 default:
11102 buf->b_p_ff = vim_strsave(p_ff);
11103 }
11104 if (buf->b_p_ff != NULL)
11105 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011106 buf->b_p_bh = empty_option;
11107 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108 }
11109 else
11110 free_buf_options(buf, FALSE);
11111
11112 buf->b_p_ai = p_ai;
11113 buf->b_p_ai_nopaste = p_ai_nopaste;
11114 buf->b_p_sw = p_sw;
11115 buf->b_p_tw = p_tw;
11116 buf->b_p_tw_nopaste = p_tw_nopaste;
11117 buf->b_p_tw_nobin = p_tw_nobin;
11118 buf->b_p_wm = p_wm;
11119 buf->b_p_wm_nopaste = p_wm_nopaste;
11120 buf->b_p_wm_nobin = p_wm_nobin;
11121 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011122#ifdef FEAT_MBYTE
11123 buf->b_p_bomb = p_bomb;
11124#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011125 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011126 buf->b_p_et = p_et;
11127 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011128 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129 buf->b_p_ml = p_ml;
11130 buf->b_p_ml_nobin = p_ml_nobin;
11131 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011132 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133#ifdef FEAT_INS_EXPAND
11134 buf->b_p_cpt = vim_strsave(p_cpt);
11135#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011136#ifdef FEAT_COMPL_FUNC
11137 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011138 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011139#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011140 buf->b_p_sts = p_sts;
11141 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011143#ifdef FEAT_COMMENTS
11144 buf->b_p_com = vim_strsave(p_com);
11145#endif
11146#ifdef FEAT_FOLDING
11147 buf->b_p_cms = vim_strsave(p_cms);
11148#endif
11149 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011150 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011151 buf->b_p_nf = vim_strsave(p_nf);
11152 buf->b_p_mps = vim_strsave(p_mps);
11153#ifdef FEAT_SMARTINDENT
11154 buf->b_p_si = p_si;
11155#endif
11156 buf->b_p_ci = p_ci;
11157#ifdef FEAT_CINDENT
11158 buf->b_p_cin = p_cin;
11159 buf->b_p_cink = vim_strsave(p_cink);
11160 buf->b_p_cino = vim_strsave(p_cino);
11161#endif
11162#ifdef FEAT_AUTOCMD
11163 /* Don't copy 'filetype', it must be detected */
11164 buf->b_p_ft = empty_option;
11165#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166 buf->b_p_pi = p_pi;
11167#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11168 buf->b_p_cinw = vim_strsave(p_cinw);
11169#endif
11170#ifdef FEAT_LISP
11171 buf->b_p_lisp = p_lisp;
11172#endif
11173#ifdef FEAT_SYN_HL
11174 /* Don't copy 'syntax', it must be set */
11175 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011176 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011177 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011178#endif
11179#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011180 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011181 (void)compile_cap_prog(&buf->b_s);
11182 buf->b_s.b_p_spf = vim_strsave(p_spf);
11183 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011184#endif
11185#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11186 buf->b_p_inde = vim_strsave(p_inde);
11187 buf->b_p_indk = vim_strsave(p_indk);
11188#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011189 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011190#if defined(FEAT_EVAL)
11191 buf->b_p_fex = vim_strsave(p_fex);
11192#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011193#ifdef FEAT_CRYPT
11194 buf->b_p_key = vim_strsave(p_key);
11195#endif
11196#ifdef FEAT_SEARCHPATH
11197 buf->b_p_sua = vim_strsave(p_sua);
11198#endif
11199#ifdef FEAT_KEYMAP
11200 buf->b_p_keymap = vim_strsave(p_keymap);
11201 buf->b_kmap_state |= KEYMAP_INIT;
11202#endif
11203 /* This isn't really an option, but copying the langmap and IME
11204 * state from the current buffer is better than resetting it. */
11205 buf->b_p_iminsert = p_iminsert;
11206 buf->b_p_imsearch = p_imsearch;
11207
11208 /* options that are normally global but also have a local value
11209 * are not copied, start using the global value */
11210 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011211 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011212 buf->b_p_bkc = empty_option;
11213 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011214#ifdef FEAT_QUICKFIX
11215 buf->b_p_gp = empty_option;
11216 buf->b_p_mp = empty_option;
11217 buf->b_p_efm = empty_option;
11218#endif
11219 buf->b_p_ep = empty_option;
11220 buf->b_p_kp = empty_option;
11221 buf->b_p_path = empty_option;
11222 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011223 buf->b_p_tc = empty_option;
11224 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225#ifdef FEAT_FIND_ID
11226 buf->b_p_def = empty_option;
11227 buf->b_p_inc = empty_option;
11228# ifdef FEAT_EVAL
11229 buf->b_p_inex = vim_strsave(p_inex);
11230# endif
11231#endif
11232#ifdef FEAT_INS_EXPAND
11233 buf->b_p_dict = empty_option;
11234 buf->b_p_tsr = empty_option;
11235#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011236#ifdef FEAT_TEXTOBJ
11237 buf->b_p_qe = vim_strsave(p_qe);
11238#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011239#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11240 buf->b_p_bexpr = empty_option;
11241#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011242#if defined(FEAT_CRYPT)
11243 buf->b_p_cm = empty_option;
11244#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011245#ifdef FEAT_PERSISTENT_UNDO
11246 buf->b_p_udf = p_udf;
11247#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011248#ifdef FEAT_LISP
11249 buf->b_p_lw = empty_option;
11250#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011251#ifdef FEAT_MBYTE
11252 buf->b_p_menc = empty_option;
11253#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011254
11255 /*
11256 * Don't copy the options set by ex_help(), use the saved values,
11257 * when going from a help buffer to a non-help buffer.
11258 * Don't touch these at all when BCO_NOHELP is used and going from
11259 * or to a help buffer.
11260 */
11261 if (dont_do_help)
11262 buf->b_p_isk = save_p_isk;
11263 else
11264 {
11265 buf->b_p_isk = vim_strsave(p_isk);
11266 did_isk = TRUE;
11267 buf->b_p_ts = p_ts;
11268 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011269 if (buf->b_p_bt[0] == 'h')
11270 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011271 buf->b_p_ma = p_ma;
11272 }
11273 }
11274
11275 /*
11276 * When the options should be copied (ignoring BCO_ALWAYS), set the
11277 * flag that indicates that the options have been initialized.
11278 */
11279 if (should_copy)
11280 buf->b_p_initialized = TRUE;
11281 }
11282
11283 check_buf_options(buf); /* make sure we don't have NULLs */
11284 if (did_isk)
11285 (void)buf_init_chartab(buf, FALSE);
11286}
11287
11288/*
11289 * Reset the 'modifiable' option and its default value.
11290 */
11291 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011292reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011293{
11294 int opt_idx;
11295
11296 curbuf->b_p_ma = FALSE;
11297 p_ma = FALSE;
11298 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011299 if (opt_idx >= 0)
11300 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011301}
11302
11303/*
11304 * Set the global value for 'iminsert' to the local value.
11305 */
11306 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011307set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308{
11309 p_iminsert = curbuf->b_p_iminsert;
11310}
11311
11312/*
11313 * Set the global value for 'imsearch' to the local value.
11314 */
11315 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011316set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011317{
11318 p_imsearch = curbuf->b_p_imsearch;
11319}
11320
11321#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11322static int expand_option_idx = -1;
11323static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11324static int expand_option_flags = 0;
11325
11326 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011327set_context_in_set_cmd(
11328 expand_T *xp,
11329 char_u *arg,
11330 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331{
11332 int nextchar;
11333 long_u flags = 0; /* init for GCC */
11334 int opt_idx = 0; /* init for GCC */
11335 char_u *p;
11336 char_u *s;
11337 int is_term_option = FALSE;
11338 int key;
11339
11340 expand_option_flags = opt_flags;
11341
11342 xp->xp_context = EXPAND_SETTINGS;
11343 if (*arg == NUL)
11344 {
11345 xp->xp_pattern = arg;
11346 return;
11347 }
11348 p = arg + STRLEN(arg) - 1;
11349 if (*p == ' ' && *(p - 1) != '\\')
11350 {
11351 xp->xp_pattern = p + 1;
11352 return;
11353 }
11354 while (p > arg)
11355 {
11356 s = p;
11357 /* count number of backslashes before ' ' or ',' */
11358 if (*p == ' ' || *p == ',')
11359 {
11360 while (s > arg && *(s - 1) == '\\')
11361 --s;
11362 }
11363 /* break at a space with an even number of backslashes */
11364 if (*p == ' ' && ((p - s) & 1) == 0)
11365 {
11366 ++p;
11367 break;
11368 }
11369 --p;
11370 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011371 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372 {
11373 xp->xp_context = EXPAND_BOOL_SETTINGS;
11374 p += 2;
11375 }
11376 if (STRNCMP(p, "inv", 3) == 0)
11377 {
11378 xp->xp_context = EXPAND_BOOL_SETTINGS;
11379 p += 3;
11380 }
11381 xp->xp_pattern = arg = p;
11382 if (*arg == '<')
11383 {
11384 while (*p != '>')
11385 if (*p++ == NUL) /* expand terminal option name */
11386 return;
11387 key = get_special_key_code(arg + 1);
11388 if (key == 0) /* unknown name */
11389 {
11390 xp->xp_context = EXPAND_NOTHING;
11391 return;
11392 }
11393 nextchar = *++p;
11394 is_term_option = TRUE;
11395 expand_option_name[2] = KEY2TERMCAP0(key);
11396 expand_option_name[3] = KEY2TERMCAP1(key);
11397 }
11398 else
11399 {
11400 if (p[0] == 't' && p[1] == '_')
11401 {
11402 p += 2;
11403 if (*p != NUL)
11404 ++p;
11405 if (*p == NUL)
11406 return; /* expand option name */
11407 nextchar = *++p;
11408 is_term_option = TRUE;
11409 expand_option_name[2] = p[-2];
11410 expand_option_name[3] = p[-1];
11411 }
11412 else
11413 {
11414 /* Allow * wildcard */
11415 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11416 p++;
11417 if (*p == NUL)
11418 return;
11419 nextchar = *p;
11420 *p = NUL;
11421 opt_idx = findoption(arg);
11422 *p = nextchar;
11423 if (opt_idx == -1 || options[opt_idx].var == NULL)
11424 {
11425 xp->xp_context = EXPAND_NOTHING;
11426 return;
11427 }
11428 flags = options[opt_idx].flags;
11429 if (flags & P_BOOL)
11430 {
11431 xp->xp_context = EXPAND_NOTHING;
11432 return;
11433 }
11434 }
11435 }
11436 /* handle "-=" and "+=" */
11437 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11438 {
11439 ++p;
11440 nextchar = '=';
11441 }
11442 if ((nextchar != '=' && nextchar != ':')
11443 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11444 {
11445 xp->xp_context = EXPAND_UNSUCCESSFUL;
11446 return;
11447 }
11448 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11449 {
11450 xp->xp_context = EXPAND_OLD_SETTING;
11451 if (is_term_option)
11452 expand_option_idx = -1;
11453 else
11454 expand_option_idx = opt_idx;
11455 xp->xp_pattern = p + 1;
11456 return;
11457 }
11458 xp->xp_context = EXPAND_NOTHING;
11459 if (is_term_option || (flags & P_NUM))
11460 return;
11461
11462 xp->xp_pattern = p + 1;
11463
11464 if (flags & P_EXPAND)
11465 {
11466 p = options[opt_idx].var;
11467 if (p == (char_u *)&p_bdir
11468 || p == (char_u *)&p_dir
11469 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011470 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011471 || p == (char_u *)&p_rtp
11472#ifdef FEAT_SEARCHPATH
11473 || p == (char_u *)&p_cdpath
11474#endif
11475#ifdef FEAT_SESSION
11476 || p == (char_u *)&p_vdir
11477#endif
11478 )
11479 {
11480 xp->xp_context = EXPAND_DIRECTORIES;
11481 if (p == (char_u *)&p_path
11482#ifdef FEAT_SEARCHPATH
11483 || p == (char_u *)&p_cdpath
11484#endif
11485 )
11486 xp->xp_backslash = XP_BS_THREE;
11487 else
11488 xp->xp_backslash = XP_BS_ONE;
11489 }
11490 else
11491 {
11492 xp->xp_context = EXPAND_FILES;
11493 /* for 'tags' need three backslashes for a space */
11494 if (p == (char_u *)&p_tags)
11495 xp->xp_backslash = XP_BS_THREE;
11496 else
11497 xp->xp_backslash = XP_BS_ONE;
11498 }
11499 }
11500
11501 /* For an option that is a list of file names, find the start of the
11502 * last file name. */
11503 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11504 {
11505 /* count number of backslashes before ' ' or ',' */
11506 if (*p == ' ' || *p == ',')
11507 {
11508 s = p;
11509 while (s > xp->xp_pattern && *(s - 1) == '\\')
11510 --s;
11511 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11512 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11513 {
11514 xp->xp_pattern = p + 1;
11515 break;
11516 }
11517 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011518
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011519#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011520 /* for 'spellsuggest' start at "file:" */
11521 if (options[opt_idx].var == (char_u *)&p_sps
11522 && STRNCMP(p, "file:", 5) == 0)
11523 {
11524 xp->xp_pattern = p + 5;
11525 break;
11526 }
11527#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528 }
11529
11530 return;
11531}
11532
11533 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011534ExpandSettings(
11535 expand_T *xp,
11536 regmatch_T *regmatch,
11537 int *num_file,
11538 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011539{
11540 int num_normal = 0; /* Nr of matching non-term-code settings */
11541 int num_term = 0; /* Nr of matching terminal code settings */
11542 int opt_idx;
11543 int match;
11544 int count = 0;
11545 char_u *str;
11546 int loop;
11547 int is_term_opt;
11548 char_u name_buf[MAX_KEY_NAME_LEN];
11549 static char *(names[]) = {"all", "termcap"};
11550 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11551
11552 /* do this loop twice:
11553 * loop == 0: count the number of matching options
11554 * loop == 1: copy the matching options into allocated memory
11555 */
11556 for (loop = 0; loop <= 1; ++loop)
11557 {
11558 regmatch->rm_ic = ic;
11559 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11560 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011561 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11562 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011563 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11564 {
11565 if (loop == 0)
11566 num_normal++;
11567 else
11568 (*file)[count++] = vim_strsave((char_u *)names[match]);
11569 }
11570 }
11571 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11572 opt_idx++)
11573 {
11574 if (options[opt_idx].var == NULL)
11575 continue;
11576 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11577 && !(options[opt_idx].flags & P_BOOL))
11578 continue;
11579 is_term_opt = istermoption(&options[opt_idx]);
11580 if (is_term_opt && num_normal > 0)
11581 continue;
11582 match = FALSE;
11583 if (vim_regexec(regmatch, str, (colnr_T)0)
11584 || (options[opt_idx].shortname != NULL
11585 && vim_regexec(regmatch,
11586 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11587 match = TRUE;
11588 else if (is_term_opt)
11589 {
11590 name_buf[0] = '<';
11591 name_buf[1] = 't';
11592 name_buf[2] = '_';
11593 name_buf[3] = str[2];
11594 name_buf[4] = str[3];
11595 name_buf[5] = '>';
11596 name_buf[6] = NUL;
11597 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11598 {
11599 match = TRUE;
11600 str = name_buf;
11601 }
11602 }
11603 if (match)
11604 {
11605 if (loop == 0)
11606 {
11607 if (is_term_opt)
11608 num_term++;
11609 else
11610 num_normal++;
11611 }
11612 else
11613 (*file)[count++] = vim_strsave(str);
11614 }
11615 }
11616 /*
11617 * Check terminal key codes, these are not in the option table
11618 */
11619 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11620 {
11621 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11622 {
11623 if (!isprint(str[0]) || !isprint(str[1]))
11624 continue;
11625
11626 name_buf[0] = 't';
11627 name_buf[1] = '_';
11628 name_buf[2] = str[0];
11629 name_buf[3] = str[1];
11630 name_buf[4] = NUL;
11631
11632 match = FALSE;
11633 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11634 match = TRUE;
11635 else
11636 {
11637 name_buf[0] = '<';
11638 name_buf[1] = 't';
11639 name_buf[2] = '_';
11640 name_buf[3] = str[0];
11641 name_buf[4] = str[1];
11642 name_buf[5] = '>';
11643 name_buf[6] = NUL;
11644
11645 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11646 match = TRUE;
11647 }
11648 if (match)
11649 {
11650 if (loop == 0)
11651 num_term++;
11652 else
11653 (*file)[count++] = vim_strsave(name_buf);
11654 }
11655 }
11656
11657 /*
11658 * Check special key names.
11659 */
11660 regmatch->rm_ic = TRUE; /* ignore case here */
11661 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11662 {
11663 name_buf[0] = '<';
11664 STRCPY(name_buf + 1, str);
11665 STRCAT(name_buf, ">");
11666
11667 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11668 {
11669 if (loop == 0)
11670 num_term++;
11671 else
11672 (*file)[count++] = vim_strsave(name_buf);
11673 }
11674 }
11675 }
11676 if (loop == 0)
11677 {
11678 if (num_normal > 0)
11679 *num_file = num_normal;
11680 else if (num_term > 0)
11681 *num_file = num_term;
11682 else
11683 return OK;
11684 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11685 if (*file == NULL)
11686 {
11687 *file = (char_u **)"";
11688 return FAIL;
11689 }
11690 }
11691 }
11692 return OK;
11693}
11694
11695 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011696ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011697{
11698 char_u *var = NULL; /* init for GCC */
11699 char_u *buf;
11700
11701 *num_file = 0;
11702 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11703 if (*file == NULL)
11704 return FAIL;
11705
11706 /*
11707 * For a terminal key code expand_option_idx is < 0.
11708 */
11709 if (expand_option_idx < 0)
11710 {
11711 var = find_termcode(expand_option_name + 2);
11712 if (var == NULL)
11713 expand_option_idx = findoption(expand_option_name);
11714 }
11715
11716 if (expand_option_idx >= 0)
11717 {
11718 /* put string of option value in NameBuff */
11719 option_value2string(&options[expand_option_idx], expand_option_flags);
11720 var = NameBuff;
11721 }
11722 else if (var == NULL)
11723 var = (char_u *)"";
11724
11725 /* A backslash is required before some characters. This is the reverse of
11726 * what happens in do_set(). */
11727 buf = vim_strsave_escaped(var, escape_chars);
11728
11729 if (buf == NULL)
11730 {
11731 vim_free(*file);
11732 *file = NULL;
11733 return FAIL;
11734 }
11735
11736#ifdef BACKSLASH_IN_FILENAME
11737 /* For MS-Windows et al. we don't double backslashes at the start and
11738 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011739 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011740 if (var[0] == '\\' && var[1] == '\\'
11741 && expand_option_idx >= 0
11742 && (options[expand_option_idx].flags & P_EXPAND)
11743 && vim_isfilec(var[2])
11744 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011745 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746#endif
11747
11748 *file[0] = buf;
11749 *num_file = 1;
11750 return OK;
11751}
11752#endif
11753
11754/*
11755 * Get the value for the numeric or string option *opp in a nice format into
11756 * NameBuff[]. Must not be called with a hidden option!
11757 */
11758 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011759option_value2string(
11760 struct vimoption *opp,
11761 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011762{
11763 char_u *varp;
11764
11765 varp = get_varp_scope(opp, opt_flags);
11766
11767 if (opp->flags & P_NUM)
11768 {
11769 long wc = 0;
11770
11771 if (wc_use_keyname(varp, &wc))
11772 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11773 else if (wc != 0)
11774 STRCPY(NameBuff, transchar((int)wc));
11775 else
11776 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11777 }
11778 else /* P_STRING */
11779 {
11780 varp = *(char_u **)(varp);
11781 if (varp == NULL) /* just in case */
11782 NameBuff[0] = NUL;
11783#ifdef FEAT_CRYPT
11784 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011785 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011786 STRCPY(NameBuff, "*****");
11787#endif
11788 else if (opp->flags & P_EXPAND)
11789 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11790 /* Translate 'pastetoggle' into special key names */
11791 else if ((char_u **)opp->var == &p_pt)
11792 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11793 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011794 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011795 }
11796}
11797
11798/*
11799 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11800 * printed as a keyname.
11801 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11802 */
11803 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011804wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805{
11806 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11807 {
11808 *wcp = *(long *)varp;
11809 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11810 return TRUE;
11811 }
11812 return FALSE;
11813}
11814
Bram Moolenaar01615492015-02-03 13:00:38 +010011815#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011817 * Any character has an equivalent 'langmap' character. This is used for
11818 * keyboards that have a special language mode that sends characters above
11819 * 128 (although other characters can be translated too). The "to" field is a
11820 * Vim command character. This avoids having to switch the keyboard back to
11821 * ASCII mode when leaving Insert mode.
11822 *
11823 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11824 * commands.
11825 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11826 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11827 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011828 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011829# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011830/*
11831 * With multi-byte support use growarray for 'langmap' chars >= 256
11832 */
11833typedef struct
11834{
11835 int from;
11836 int to;
11837} langmap_entry_T;
11838
11839static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011840static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011841
11842/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011843 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11844 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011846 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011847langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011848{
11849 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011850 int a = 0;
11851 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011852
11853 /* Do a binary search for an existing entry. */
11854 while (a != b)
11855 {
11856 int i = (a + b) / 2;
11857 int d = entries[i].from - from;
11858
11859 if (d == 0)
11860 {
11861 entries[i].to = to;
11862 return;
11863 }
11864 if (d < 0)
11865 a = i + 1;
11866 else
11867 b = i;
11868 }
11869
11870 if (ga_grow(&langmap_mapga, 1) != OK)
11871 return; /* out of memory */
11872
11873 /* insert new entry at position "a" */
11874 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11875 mch_memmove(entries + 1, entries,
11876 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11877 ++langmap_mapga.ga_len;
11878 entries[0].from = from;
11879 entries[0].to = to;
11880}
11881
11882/*
11883 * Apply 'langmap' to multi-byte character "c" and return the result.
11884 */
11885 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011886langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011887{
11888 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11889 int a = 0;
11890 int b = langmap_mapga.ga_len;
11891
11892 while (a != b)
11893 {
11894 int i = (a + b) / 2;
11895 int d = entries[i].from - c;
11896
11897 if (d == 0)
11898 return entries[i].to; /* found matching entry */
11899 if (d < 0)
11900 a = i + 1;
11901 else
11902 b = i;
11903 }
11904 return c; /* no entry found, return "c" unmodified */
11905}
11906# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011907
11908 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011909langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011910{
11911 int i;
11912
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011913 for (i = 0; i < 256; i++)
11914 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11915# ifdef FEAT_MBYTE
11916 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11917# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011918}
11919
11920/*
11921 * Called when langmap option is set; the language map can be
11922 * changed at any time!
11923 */
11924 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011925langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011926{
11927 char_u *p;
11928 char_u *p2;
11929 int from, to;
11930
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011931#ifdef FEAT_MBYTE
11932 ga_clear(&langmap_mapga); /* clear the previous map first */
11933#endif
11934 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011935
11936 for (p = p_langmap; p[0] != NUL; )
11937 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011938 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011939 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011940 {
11941 if (p2[0] == '\\' && p2[1] != NUL)
11942 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011943 }
11944 if (p2[0] == ';')
11945 ++p2; /* abcd;ABCD form, p2 points to A */
11946 else
11947 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11948 while (p[0])
11949 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011950 if (p[0] == ',')
11951 {
11952 ++p;
11953 break;
11954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 if (p[0] == '\\' && p[1] != NUL)
11956 ++p;
11957#ifdef FEAT_MBYTE
11958 from = (*mb_ptr2char)(p);
11959#else
11960 from = p[0];
11961#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011962 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963 if (p2 == NULL)
11964 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011965 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011966 if (p[0] != ',')
11967 {
11968 if (p[0] == '\\')
11969 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011970#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011971 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011972#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011973 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011974#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011975 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011976 }
11977 else
11978 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011979 if (p2[0] != ',')
11980 {
11981 if (p2[0] == '\\')
11982 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011984 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011986 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011987#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011989 }
11990 if (to == NUL)
11991 {
11992 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11993 transchar(from));
11994 return;
11995 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011996
11997#ifdef FEAT_MBYTE
11998 if (from >= 256)
11999 langmap_set_entry(from, to);
12000 else
12001#endif
12002 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012003
12004 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012005 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012006 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012007 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012008 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012009 if (*p == ';')
12010 {
12011 p = p2;
12012 if (p[0] != NUL)
12013 {
12014 if (p[0] != ',')
12015 {
12016 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12017 return;
12018 }
12019 ++p;
12020 }
12021 break;
12022 }
12023 }
12024 }
12025 }
12026}
12027#endif
12028
12029/*
12030 * Return TRUE if format option 'x' is in effect.
12031 * Take care of no formatting when 'paste' is set.
12032 */
12033 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012034has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012035{
12036 if (p_paste)
12037 return FALSE;
12038 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12039}
12040
12041/*
12042 * Return TRUE if "x" is present in 'shortmess' option, or
12043 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12044 */
12045 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012046shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012047{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012048 return p_shm != NULL &&
12049 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 || (vim_strchr(p_shm, 'a') != NULL
12051 && vim_strchr((char_u *)SHM_A, x) != NULL));
12052}
12053
12054/*
12055 * paste_option_changed() - Called after p_paste was set or reset.
12056 */
12057 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012058paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012059{
12060 static int old_p_paste = FALSE;
12061 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012062 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012063#ifdef FEAT_CMDL_INFO
12064 static int save_ru = 0;
12065#endif
12066#ifdef FEAT_RIGHTLEFT
12067 static int save_ri = 0;
12068 static int save_hkmap = 0;
12069#endif
12070 buf_T *buf;
12071
12072 if (p_paste)
12073 {
12074 /*
12075 * Paste switched from off to on.
12076 * Save the current values, so they can be restored later.
12077 */
12078 if (!old_p_paste)
12079 {
12080 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012081 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012082 {
12083 buf->b_p_tw_nopaste = buf->b_p_tw;
12084 buf->b_p_wm_nopaste = buf->b_p_wm;
12085 buf->b_p_sts_nopaste = buf->b_p_sts;
12086 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012087 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012088 }
12089
12090 /* save global options */
12091 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012092 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012093#ifdef FEAT_CMDL_INFO
12094 save_ru = p_ru;
12095#endif
12096#ifdef FEAT_RIGHTLEFT
12097 save_ri = p_ri;
12098 save_hkmap = p_hkmap;
12099#endif
12100 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012101 p_ai_nopaste = p_ai;
12102 p_et_nopaste = p_et;
12103 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012104 p_tw_nopaste = p_tw;
12105 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012106 }
12107
12108 /*
12109 * Always set the option values, also when 'paste' is set when it is
12110 * already on.
12111 */
12112 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012113 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012114 {
12115 buf->b_p_tw = 0; /* textwidth is 0 */
12116 buf->b_p_wm = 0; /* wrapmargin is 0 */
12117 buf->b_p_sts = 0; /* softtabstop is 0 */
12118 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012119 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120 }
12121
12122 /* set global options */
12123 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012124 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012125#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012126 if (p_ru)
12127 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128 p_ru = 0; /* no ruler */
12129#endif
12130#ifdef FEAT_RIGHTLEFT
12131 p_ri = 0; /* no reverse insert */
12132 p_hkmap = 0; /* no Hebrew keyboard */
12133#endif
12134 /* set global values for local buffer options */
12135 p_tw = 0;
12136 p_wm = 0;
12137 p_sts = 0;
12138 p_ai = 0;
12139 }
12140
12141 /*
12142 * Paste switched from on to off: Restore saved values.
12143 */
12144 else if (old_p_paste)
12145 {
12146 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012147 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012148 {
12149 buf->b_p_tw = buf->b_p_tw_nopaste;
12150 buf->b_p_wm = buf->b_p_wm_nopaste;
12151 buf->b_p_sts = buf->b_p_sts_nopaste;
12152 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012153 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012154 }
12155
12156 /* restore global options */
12157 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012158 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012159#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012160 if (p_ru != save_ru)
12161 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012162 p_ru = save_ru;
12163#endif
12164#ifdef FEAT_RIGHTLEFT
12165 p_ri = save_ri;
12166 p_hkmap = save_hkmap;
12167#endif
12168 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012169 p_ai = p_ai_nopaste;
12170 p_et = p_et_nopaste;
12171 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012172 p_tw = p_tw_nopaste;
12173 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012174 }
12175
12176 old_p_paste = p_paste;
12177}
12178
12179/*
12180 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12181 *
12182 * Reset 'compatible' and set the values for options that didn't get set yet
12183 * to the Vim defaults.
12184 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012185 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186 */
12187 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012188vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012189{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012190 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012191 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012192 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193
12194 if (!option_was_set((char_u *)"cp"))
12195 {
12196 p_cp = FALSE;
12197 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12198 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12199 set_option_default(opt_idx, OPT_FREE, FALSE);
12200 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012201 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012202 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012203
12204 if (fname != NULL)
12205 {
12206 p = vim_getenv(envname, &dofree);
12207 if (p == NULL)
12208 {
12209 /* Set $MYVIMRC to the first vimrc file found. */
12210 p = FullName_save(fname, FALSE);
12211 if (p != NULL)
12212 {
12213 vim_setenv(envname, p);
12214 vim_free(p);
12215 }
12216 }
12217 else if (dofree)
12218 vim_free(p);
12219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012220}
12221
12222/*
12223 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12224 */
12225 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012226change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012227{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012228 int opt_idx;
12229
Bram Moolenaar071d4272004-06-13 20:20:40 +000012230 if (p_cp != on)
12231 {
12232 p_cp = on;
12233 compatible_set();
12234 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012235 opt_idx = findoption((char_u *)"cp");
12236 if (opt_idx >= 0)
12237 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012238}
12239
12240/*
12241 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012242 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012243 */
12244 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012245option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246{
12247 int idx;
12248
12249 idx = findoption(name);
12250 if (idx < 0) /* unknown option */
12251 return FALSE;
12252 if (options[idx].flags & P_WAS_SET)
12253 return TRUE;
12254 return FALSE;
12255}
12256
12257/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012258 * Reset the flag indicating option "name" was set.
12259 */
12260 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012261reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012262{
12263 int idx = findoption(name);
12264
12265 if (idx >= 0)
12266 options[idx].flags &= ~P_WAS_SET;
12267}
12268
12269/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012270 * compatible_set() - Called when 'compatible' has been set or unset.
12271 *
12272 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12273 * flag) to a Vi compatible value.
12274 * When 'compatible' is unset: Set all options that have a different default
12275 * for Vim (without the P_VI_DEF flag) to that default.
12276 */
12277 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012278compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012279{
12280 int opt_idx;
12281
12282 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12283 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12284 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12285 set_option_default(opt_idx, OPT_FREE, p_cp);
12286 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012287 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288}
12289
12290#ifdef FEAT_LINEBREAK
12291
12292# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12293 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012294 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295# endif
12296
12297/*
12298 * fill_breakat_flags() -- called when 'breakat' changes value.
12299 */
12300 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012301fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012302{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012303 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012304 int i;
12305
12306 for (i = 0; i < 256; i++)
12307 breakat_flags[i] = FALSE;
12308
12309 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012310 for (p = p_breakat; *p; p++)
12311 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012312}
12313
12314# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012315 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012316# endif
12317
12318#endif
12319
12320/*
12321 * Check an option that can be a range of string values.
12322 *
12323 * Return OK for correct value, FAIL otherwise.
12324 * Empty is always OK.
12325 */
12326 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012327check_opt_strings(
12328 char_u *val,
12329 char **values,
12330 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012331{
12332 return opt_strings_flags(val, values, NULL, list);
12333}
12334
12335/*
12336 * Handle an option that can be a range of string values.
12337 * Set a flag in "*flagp" for each string present.
12338 *
12339 * Return OK for correct value, FAIL otherwise.
12340 * Empty is always OK.
12341 */
12342 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012343opt_strings_flags(
12344 char_u *val, /* new value */
12345 char **values, /* array of valid string values */
12346 unsigned *flagp,
12347 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012348{
12349 int i;
12350 int len;
12351 unsigned new_flags = 0;
12352
12353 while (*val)
12354 {
12355 for (i = 0; ; ++i)
12356 {
12357 if (values[i] == NULL) /* val not found in values[] */
12358 return FAIL;
12359
12360 len = (int)STRLEN(values[i]);
12361 if (STRNCMP(values[i], val, len) == 0
12362 && ((list && val[len] == ',') || val[len] == NUL))
12363 {
12364 val += len + (val[len] == ',');
12365 new_flags |= (1 << i);
12366 break; /* check next item in val list */
12367 }
12368 }
12369 }
12370 if (flagp != NULL)
12371 *flagp = new_flags;
12372
12373 return OK;
12374}
12375
12376/*
12377 * Read the 'wildmode' option, fill wim_flags[].
12378 */
12379 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012380check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012381{
12382 char_u new_wim_flags[4];
12383 char_u *p;
12384 int i;
12385 int idx = 0;
12386
12387 for (i = 0; i < 4; ++i)
12388 new_wim_flags[i] = 0;
12389
12390 for (p = p_wim; *p; ++p)
12391 {
12392 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12393 ;
12394 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12395 return FAIL;
12396 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12397 new_wim_flags[idx] |= WIM_LONGEST;
12398 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12399 new_wim_flags[idx] |= WIM_FULL;
12400 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12401 new_wim_flags[idx] |= WIM_LIST;
12402 else
12403 return FAIL;
12404 p += i;
12405 if (*p == NUL)
12406 break;
12407 if (*p == ',')
12408 {
12409 if (idx == 3)
12410 return FAIL;
12411 ++idx;
12412 }
12413 }
12414
12415 /* fill remaining entries with last flag */
12416 while (idx < 3)
12417 {
12418 new_wim_flags[idx + 1] = new_wim_flags[idx];
12419 ++idx;
12420 }
12421
12422 /* only when there are no errors, wim_flags[] is changed */
12423 for (i = 0; i < 4; ++i)
12424 wim_flags[i] = new_wim_flags[i];
12425 return OK;
12426}
12427
12428/*
12429 * Check if backspacing over something is allowed.
12430 */
12431 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012432can_bs(
12433 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012434{
12435 switch (*p_bs)
12436 {
12437 case '2': return TRUE;
12438 case '1': return (what != BS_START);
12439 case '0': return FALSE;
12440 }
12441 return vim_strchr(p_bs, what) != NULL;
12442}
12443
12444/*
12445 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12446 * the file must be considered changed when the value is different.
12447 */
12448 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012449save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012450{
12451 buf->b_start_ffc = *buf->b_p_ff;
12452 buf->b_start_eol = buf->b_p_eol;
12453#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012454 buf->b_start_bomb = buf->b_p_bomb;
12455
Bram Moolenaar071d4272004-06-13 20:20:40 +000012456 /* Only use free/alloc when necessary, they take time. */
12457 if (buf->b_start_fenc == NULL
12458 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12459 {
12460 vim_free(buf->b_start_fenc);
12461 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12462 }
12463#endif
12464}
12465
12466/*
12467 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12468 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012469 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12470 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012471 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012472 * When "ignore_empty" is true don't consider a new, empty buffer to be
12473 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012474 */
12475 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012476file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012477{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012478 /* In a buffer that was never loaded the options are not valid. */
12479 if (buf->b_flags & BF_NEVERLOADED)
12480 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012481 if (ignore_empty
12482 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012483 && buf->b_ml.ml_line_count == 1
12484 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12485 return FALSE;
12486 if (buf->b_start_ffc != *buf->b_p_ff)
12487 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012488 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012489 return TRUE;
12490#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012491 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12492 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012493 if (buf->b_start_fenc == NULL)
12494 return (*buf->b_p_fenc != NUL);
12495 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12496#else
12497 return FALSE;
12498#endif
12499}
12500
12501/*
12502 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12503 */
12504 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012505check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012506{
12507 return check_opt_strings(p, p_ff_values, FALSE);
12508}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012509
12510/*
12511 * Return the effective shiftwidth value for current buffer, using the
12512 * 'tabstop' value when 'shiftwidth' is zero.
12513 */
12514 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012515get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012516{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012517 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012518}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012519
12520/*
12521 * Return the effective softtabstop value for the current buffer, using the
12522 * 'tabstop' value when 'softtabstop' is negative.
12523 */
12524 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012525get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012526{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012527 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012528}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012529
12530/*
12531 * Check matchpairs option for "*initc".
12532 * If there is a match set "*initc" to the matching character and "*findc" to
12533 * the opposite character. Set "*backwards" to the direction.
12534 * When "switchit" is TRUE swap the direction.
12535 */
12536 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012537find_mps_values(
12538 int *initc,
12539 int *findc,
12540 int *backwards,
12541 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012542{
12543 char_u *ptr;
12544
12545 ptr = curbuf->b_p_mps;
12546 while (*ptr != NUL)
12547 {
12548#ifdef FEAT_MBYTE
12549 if (has_mbyte)
12550 {
12551 char_u *prev;
12552
12553 if (mb_ptr2char(ptr) == *initc)
12554 {
12555 if (switchit)
12556 {
12557 *findc = *initc;
12558 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12559 *backwards = TRUE;
12560 }
12561 else
12562 {
12563 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12564 *backwards = FALSE;
12565 }
12566 return;
12567 }
12568 prev = ptr;
12569 ptr += mb_ptr2len(ptr) + 1;
12570 if (mb_ptr2char(ptr) == *initc)
12571 {
12572 if (switchit)
12573 {
12574 *findc = *initc;
12575 *initc = mb_ptr2char(prev);
12576 *backwards = FALSE;
12577 }
12578 else
12579 {
12580 *findc = mb_ptr2char(prev);
12581 *backwards = TRUE;
12582 }
12583 return;
12584 }
12585 ptr += mb_ptr2len(ptr);
12586 }
12587 else
12588#endif
12589 {
12590 if (*ptr == *initc)
12591 {
12592 if (switchit)
12593 {
12594 *backwards = TRUE;
12595 *findc = *initc;
12596 *initc = ptr[2];
12597 }
12598 else
12599 {
12600 *backwards = FALSE;
12601 *findc = ptr[2];
12602 }
12603 return;
12604 }
12605 ptr += 2;
12606 if (*ptr == *initc)
12607 {
12608 if (switchit)
12609 {
12610 *backwards = FALSE;
12611 *findc = *initc;
12612 *initc = ptr[-2];
12613 }
12614 else
12615 {
12616 *backwards = TRUE;
12617 *findc = ptr[-2];
12618 }
12619 return;
12620 }
12621 ++ptr;
12622 }
12623 if (*ptr == ',')
12624 ++ptr;
12625 }
12626}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012627
12628#if defined(FEAT_LINEBREAK) || defined(PROTO)
12629/*
12630 * This is called when 'breakindentopt' is changed and when a window is
12631 * initialized.
12632 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012633 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012634briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012635{
12636 char_u *p;
12637 int bri_shift = 0;
12638 long bri_min = 20;
12639 int bri_sbr = FALSE;
12640
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012641 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012642 while (*p != NUL)
12643 {
12644 if (STRNCMP(p, "shift:", 6) == 0
12645 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12646 {
12647 p += 6;
12648 bri_shift = getdigits(&p);
12649 }
12650 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12651 {
12652 p += 4;
12653 bri_min = getdigits(&p);
12654 }
12655 else if (STRNCMP(p, "sbr", 3) == 0)
12656 {
12657 p += 3;
12658 bri_sbr = TRUE;
12659 }
12660 if (*p != ',' && *p != NUL)
12661 return FAIL;
12662 if (*p == ',')
12663 ++p;
12664 }
12665
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012666 wp->w_p_brishift = bri_shift;
12667 wp->w_p_brimin = bri_min;
12668 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012669
12670 return OK;
12671}
12672#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012673
12674/*
12675 * Get the local or global value of 'backupcopy'.
12676 */
12677 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012678get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012679{
12680 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12681}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012682
12683#if defined(FEAT_SIGNS) || defined(PROTO)
12684/*
12685 * Return TRUE when window "wp" has a column to draw signs in.
12686 */
12687 int
12688signcolumn_on(win_T *wp)
12689{
12690 if (*wp->w_p_scl == 'n')
12691 return FALSE;
12692 if (*wp->w_p_scl == 'y')
12693 return TRUE;
12694 return (wp->w_buffer->b_signlist != NULL
12695# ifdef FEAT_NETBEANS_INTG
12696 || wp->w_buffer->b_has_sign_column
12697# endif
12698 );
12699}
12700#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012701
12702#if defined(FEAT_EVAL) || defined(PROTO)
12703/*
12704 * Get window or buffer local options.
12705 */
12706 dict_T *
12707get_winbuf_options(int bufopt)
12708{
12709 dict_T *d;
12710 int opt_idx;
12711
12712 d = dict_alloc();
12713 if (d == NULL)
12714 return NULL;
12715
12716 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12717 {
12718 struct vimoption *opt = &options[opt_idx];
12719
12720 if ((bufopt && (opt->indir & PV_BUF))
12721 || (!bufopt && (opt->indir & PV_WIN)))
12722 {
12723 char_u *varp = get_varp(opt);
12724
12725 if (varp != NULL)
12726 {
12727 if (opt->flags & P_STRING)
12728 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012729 else if (opt->flags & P_NUM)
12730 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012731 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012732 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012733 }
12734 }
12735 }
12736
12737 return d;
12738}
12739#endif