blob: ce5436996826b85fae1a5fac926ec5e130ef448a [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);
3268static char_u *term_bg_default(void);
3269static void did_set_option(int opt_idx, int opt_flags, int new_value);
3270static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003271#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003272static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273#endif
3274#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static char_u *option_expand(int opt_idx, char_u *val);
3278static void didset_options(void);
3279static void didset_options2(void);
3280static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003281#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003282static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003283#else
3284# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3285#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003286static void set_string_option_global(int opt_idx, char_u **varp);
3287static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3288static 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);
3289static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003290#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003291static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003292#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003293#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003294static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003296#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003297static char_u *did_set_spell_option(int is_spellfile);
3298static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003299#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003300#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003301static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003302#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003303static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3304static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3305static void check_redraw(long_u flags);
3306static int findoption(char_u *);
3307static int find_key_option(char_u *);
3308static void showoptions(int all, int opt_flags);
3309static int optval_default(struct vimoption *, char_u *varp);
3310static void showoneopt(struct vimoption *, int opt_flags);
3311static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3312static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3313static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3314static int istermoption(struct vimoption *);
3315static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3316static char_u *get_varp(struct vimoption *);
3317static void option_value2string(struct vimoption *, int opt_flags);
3318static void check_winopt(winopt_T *wop);
3319static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003321static void langmap_init(void);
3322static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003324static void paste_option_changed(void);
3325static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003327static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003329static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3330static int check_opt_strings(char_u *val, char **values, int);
3331static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003332#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003333static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003334#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335
3336/*
3337 * Initialize the options, first part.
3338 *
3339 * Called only once from main(), just after creating the first buffer.
3340 */
3341 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003342set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343{
3344 char_u *p;
3345 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003346 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347
3348#ifdef FEAT_LANGMAP
3349 langmap_init();
3350#endif
3351
3352 /* Be Vi compatible by default */
3353 p_cp = TRUE;
3354
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003355 /* Use POSIX compatibility when $VIM_POSIX is set. */
3356 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003357 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003358 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003359 set_string_default("shm", (char_u *)"A");
3360 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003361
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362 /*
3363 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003364 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003366 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003367#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003368 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003370 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371# endif
3372#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003373 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374 set_string_default("sh", p);
3375
3376#ifdef FEAT_WILDIGN
3377 /*
3378 * Set the default for 'backupskip' to include environment variables for
3379 * temp files.
3380 */
3381 {
3382# ifdef UNIX
3383 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3384# else
3385 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3386# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003387 int len;
3388 garray_T ga;
3389 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390
3391 ga_init2(&ga, 1, 100);
3392 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3393 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003394 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395# ifdef UNIX
3396 if (*names[n] == NUL)
3397 p = (char_u *)"/tmp";
3398 else
3399# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003400 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401 if (p != NULL && *p != NUL)
3402 {
3403 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003404 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405 if (ga_grow(&ga, len) == OK)
3406 {
3407 if (ga.ga_len > 0)
3408 STRCAT(ga.ga_data, ",");
3409 STRCAT(ga.ga_data, p);
3410 add_pathsep(ga.ga_data);
3411 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412 ga.ga_len += len;
3413 }
3414 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003415 if (mustfree)
3416 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417 }
3418 if (ga.ga_data != NULL)
3419 {
3420 set_string_default("bsk", ga.ga_data);
3421 vim_free(ga.ga_data);
3422 }
3423 }
3424#endif
3425
3426 /*
3427 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3428 */
3429 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003430 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003432#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3433 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3434#endif
3435 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003437 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003438 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439#else
3440# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003441 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003442 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003444 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445# endif
3446#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003448 opt_idx = findoption((char_u *)"maxmem");
3449 if (opt_idx >= 0)
3450 {
3451#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003452 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3453 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003454#endif
3455 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3456 }
3457 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458 }
3459
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460#ifdef FEAT_SEARCHPATH
3461 {
3462 char_u *cdpath;
3463 char_u *buf;
3464 int i;
3465 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003466 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467
3468 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003469 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470 if (cdpath != NULL)
3471 {
3472 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3473 if (buf != NULL)
3474 {
3475 buf[0] = ','; /* start with ",", current dir first */
3476 j = 1;
3477 for (i = 0; cdpath[i] != NUL; ++i)
3478 {
3479 if (vim_ispathlistsep(cdpath[i]))
3480 buf[j++] = ',';
3481 else
3482 {
3483 if (cdpath[i] == ' ' || cdpath[i] == ',')
3484 buf[j++] = '\\';
3485 buf[j++] = cdpath[i];
3486 }
3487 }
3488 buf[j] = NUL;
3489 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003490 if (opt_idx >= 0)
3491 {
3492 options[opt_idx].def_val[VI_DEFAULT] = buf;
3493 options[opt_idx].flags |= P_DEF_ALLOCED;
3494 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003495 else
3496 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003497 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003498 if (mustfree)
3499 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500 }
3501 }
3502#endif
3503
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003504#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505 /* Set print encoding on platforms that don't default to latin1 */
3506 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003507# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003508 (char_u *)"cp1252"
3509# else
3510# ifdef VMS
3511 (char_u *)"dec-mcs"
3512# else
3513# ifdef EBCDIC
3514 (char_u *)"ebcdic-uk"
3515# else
3516# ifdef MAC
3517 (char_u *)"mac-roman"
3518# else /* HPUX */
3519 (char_u *)"hp-roman8"
3520# endif
3521# endif
3522# endif
3523# endif
3524 );
3525#endif
3526
3527#ifdef FEAT_POSTSCRIPT
3528 /* 'printexpr' must be allocated to be able to evaluate it. */
3529 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003530# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003531 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003532# else
3533# ifdef VMS
3534 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3535
3536# else
3537 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3538# endif
3539# endif
3540 );
3541#endif
3542
3543 /*
3544 * Set all the options (except the terminal options) to their default
3545 * value. Also set the global value for local options.
3546 */
3547 set_options_default(0);
3548
3549#ifdef FEAT_GUI
3550 if (found_reverse_arg)
3551 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3552#endif
3553
3554 curbuf->b_p_initialized = TRUE;
3555 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003556 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557 check_buf_options(curbuf);
3558 check_win_options(curwin);
3559 check_options();
3560
3561 /* Must be before option_expand(), because that one needs vim_isIDc() */
3562 didset_options();
3563
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003564#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003565 /* Use the current chartab for the generic chartab. This is not in
3566 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003567 init_spell_chartab();
3568#endif
3569
Bram Moolenaar071d4272004-06-13 20:20:40 +00003570 /*
3571 * Expand environment variables and things like "~" for the defaults.
3572 * If option_expand() returns non-NULL the variable is expanded. This can
3573 * only happen for non-indirect options.
3574 * Also set the default to the expanded value, so ":set" does not list
3575 * them.
3576 * Don't set the P_ALLOCED flag, because we don't want to free the
3577 * default.
3578 */
3579 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3580 {
3581 if ((options[opt_idx].flags & P_GETTEXT)
3582 && options[opt_idx].var != NULL)
3583 p = (char_u *)_(*(char **)options[opt_idx].var);
3584 else
3585 p = option_expand(opt_idx, NULL);
3586 if (p != NULL && (p = vim_strsave(p)) != NULL)
3587 {
3588 *(char_u **)options[opt_idx].var = p;
3589 /* VIMEXP
3590 * Defaults for all expanded options are currently the same for Vi
3591 * and Vim. When this changes, add some code here! Also need to
3592 * split P_DEF_ALLOCED in two.
3593 */
3594 if (options[opt_idx].flags & P_DEF_ALLOCED)
3595 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3596 options[opt_idx].def_val[VI_DEFAULT] = p;
3597 options[opt_idx].flags |= P_DEF_ALLOCED;
3598 }
3599 }
3600
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 save_file_ff(curbuf); /* Buffer is unchanged */
3602
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603#if defined(FEAT_ARABIC)
3604 /* Detect use of mlterm.
3605 * Mlterm is a terminal emulator akin to xterm that has some special
3606 * abilities (bidi namely).
3607 * NOTE: mlterm's author is being asked to 'set' a variable
3608 * instead of an environment variable due to inheritance.
3609 */
3610 if (mch_getenv((char_u *)"MLTERM") != NULL)
3611 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3612#endif
3613
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003614 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615
3616#ifdef FEAT_MBYTE
3617# if defined(WIN3264) && defined(FEAT_GETTEXT)
3618 /*
3619 * If $LANG isn't set, try to get a good value for it. This makes the
3620 * right language be used automatically. Don't do this for English.
3621 */
3622 if (mch_getenv((char_u *)"LANG") == NULL)
3623 {
3624 char buf[20];
3625
3626 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3627 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3628 * only the first two. */
3629 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3630 (LPTSTR)buf, 20);
3631 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3632 {
3633 /* There are a few exceptions (probably more) */
3634 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3635 STRCPY(buf, "zh_TW");
3636 else if (STRNICMP(buf, "chs", 3) == 0
3637 || STRNICMP(buf, "zhc", 3) == 0)
3638 STRCPY(buf, "zh_CN");
3639 else if (STRNICMP(buf, "jp", 2) == 0)
3640 STRCPY(buf, "ja");
3641 else
3642 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003643 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644 }
3645 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003646# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003647# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003648 /* Moved to os_mac_conv.c to avoid dependency problems. */
3649 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003650# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651# endif
3652
3653 /* enc_locale() will try to find the encoding of the current locale. */
3654 p = enc_locale();
3655 if (p != NULL)
3656 {
3657 char_u *save_enc;
3658
3659 /* Try setting 'encoding' and check if the value is valid.
3660 * If not, go back to the default "latin1". */
3661 save_enc = p_enc;
3662 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003663 if (STRCMP(p_enc, "gb18030") == 0)
3664 {
3665 /* We don't support "gb18030", but "cp936" is a good substitute
3666 * for practical purposes, thus use that. It's not an alias to
3667 * still support conversion between gb18030 and utf-8. */
3668 p_enc = vim_strsave((char_u *)"cp936");
3669 vim_free(p);
3670 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671 if (mb_init() == NULL)
3672 {
3673 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003674 if (opt_idx >= 0)
3675 {
3676 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3677 options[opt_idx].flags |= P_DEF_ALLOCED;
3678 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003679
Bram Moolenaard0573012017-10-28 21:11:06 +02003680#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003681 if (STRCMP(p_enc, "latin1") == 0
3682# ifdef FEAT_MBYTE
3683 || enc_utf8
3684# endif
3685 )
3686 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003687 /* Adjust the default for 'isprint' and 'iskeyword' to match
3688 * latin1. Also set the defaults for when 'nocompatible' is
3689 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003690 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003691 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003692 set_string_option_direct((char_u *)"isk", -1,
3693 ISK_LATIN1, OPT_FREE, SID_NONE);
3694 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003695 if (opt_idx >= 0)
3696 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003697 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003698 if (opt_idx >= 0)
3699 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003700 (void)init_chartab();
3701 }
3702#endif
3703
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704# if defined(WIN3264) && !defined(FEAT_GUI)
3705 /* Win32 console: When GetACP() returns a different value from
3706 * GetConsoleCP() set 'termencoding'. */
3707 if (GetACP() != GetConsoleCP())
3708 {
3709 char buf[50];
3710
3711 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3712 p_tenc = vim_strsave((char_u *)buf);
3713 if (p_tenc != NULL)
3714 {
3715 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003716 if (opt_idx >= 0)
3717 {
3718 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3719 options[opt_idx].flags |= P_DEF_ALLOCED;
3720 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003721 convert_setup(&input_conv, p_tenc, p_enc);
3722 convert_setup(&output_conv, p_enc, p_tenc);
3723 }
3724 else
3725 p_tenc = empty_option;
3726 }
3727# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003728# if defined(WIN3264) && defined(FEAT_MBYTE)
3729 /* $HOME may have characters in active code page. */
3730 init_homedir();
3731# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732 }
3733 else
3734 {
3735 vim_free(p_enc);
3736 p_enc = save_enc;
3737 }
3738 }
3739#endif
3740
3741#ifdef FEAT_MULTI_LANG
3742 /* Set the default for 'helplang'. */
3743 set_helplang_default(get_mess_lang());
3744#endif
3745}
3746
3747/*
3748 * Set an option to its default value.
3749 * This does not take care of side effects!
3750 */
3751 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003752set_option_default(
3753 int opt_idx,
3754 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3755 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756{
3757 char_u *varp; /* pointer to variable for current option */
3758 int dvi; /* index in def_val[] */
3759 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003760 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3762
3763 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3764 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003765 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 {
3767 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3768 if (flags & P_STRING)
3769 {
3770 /* Use set_string_option_direct() for local options to handle
3771 * freeing and allocating the value. */
3772 if (options[opt_idx].indir != PV_NONE)
3773 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003774 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775 else
3776 {
3777 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3778 free_string_option(*(char_u **)(varp));
3779 *(char_u **)varp = options[opt_idx].def_val[dvi];
3780 options[opt_idx].flags &= ~P_ALLOCED;
3781 }
3782 }
3783 else if (flags & P_NUM)
3784 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003785 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003786 win_comp_scroll(curwin);
3787 else
3788 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003789 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790 /* May also set global value for local option. */
3791 if (both)
3792 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3793 *(long *)varp;
3794 }
3795 }
3796 else /* P_BOOL */
3797 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003798 /* the cast to long is required for Manx C, long_i is needed for
3799 * MSVC */
3800 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003801#ifdef UNIX
3802 /* 'modeline' defaults to off for root */
3803 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3804 *(int *)varp = FALSE;
3805#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806 /* May also set global value for local option. */
3807 if (both)
3808 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3809 *(int *)varp;
3810 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003811
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003812 /* The default value is not insecure. */
3813 flagsp = insecure_flag(opt_idx, opt_flags);
3814 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 }
3816
3817#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003818 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819#endif
3820}
3821
3822/*
3823 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003824 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 */
3826 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003827set_options_default(
3828 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829{
3830 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003832 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833
3834 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003835 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003836#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003837 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003838 || (TRUE
3839# if defined(FEAT_MBYTE)
3840 && options[i].var != (char_u *)&p_enc
3841# endif
3842# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003843 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003844 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003845# endif
3846 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003847#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003848 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003849 set_option_default(i, opt_flags, p_cp);
3850
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003852 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003854#ifdef FEAT_CINDENT
3855 parse_cino(curbuf);
3856#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857}
3858
3859/*
3860 * Set the Vi-default value of a string option.
3861 * Used for 'sh', 'backupskip' and 'term'.
3862 */
3863 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003864set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865{
3866 char_u *p;
3867 int opt_idx;
3868
3869 p = vim_strsave(val);
3870 if (p != NULL) /* we don't want a NULL */
3871 {
3872 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003873 if (opt_idx >= 0)
3874 {
3875 if (options[opt_idx].flags & P_DEF_ALLOCED)
3876 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3877 options[opt_idx].def_val[VI_DEFAULT] = p;
3878 options[opt_idx].flags |= P_DEF_ALLOCED;
3879 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880 }
3881}
3882
3883/*
3884 * Set the Vi-default value of a number option.
3885 * Used for 'lines' and 'columns'.
3886 */
3887 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003888set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003890 int opt_idx;
3891
3892 opt_idx = findoption((char_u *)name);
3893 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003894 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895}
3896
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003897#if defined(EXITFREE) || defined(PROTO)
3898/*
3899 * Free all options.
3900 */
3901 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003902free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003903{
3904 int i;
3905
3906 for (i = 0; !istermoption(&options[i]); i++)
3907 {
3908 if (options[i].indir == PV_NONE)
3909 {
3910 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003911 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003912 free_string_option(*(char_u **)options[i].var);
3913 if (options[i].flags & P_DEF_ALLOCED)
3914 free_string_option(options[i].def_val[VI_DEFAULT]);
3915 }
3916 else if (options[i].var != VAR_WIN
3917 && (options[i].flags & P_STRING))
3918 /* buffer-local option: free global value */
3919 free_string_option(*(char_u **)options[i].var);
3920 }
3921}
3922#endif
3923
3924
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925/*
3926 * Initialize the options, part two: After getting Rows and Columns and
3927 * setting 'term'.
3928 */
3929 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003930set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003932 int idx;
3933
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003935 * 'scroll' defaults to half the window height. The stored default is zero,
3936 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003938 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003939 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003940 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 comp_col();
3942
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003943 /*
3944 * 'window' is only for backwards compatibility with Vi.
3945 * Default is Rows - 1.
3946 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003947 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003948 p_window = Rows - 1;
3949 set_number_default("window", Rows - 1);
3950
Bram Moolenaarf740b292006-02-16 22:11:02 +00003951 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003952#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003953 /*
3954 * If 'background' wasn't set by the user, try guessing the value,
3955 * depending on the terminal name. Only need to check for terminals
3956 * with a dark background, that can handle color.
3957 */
3958 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003959 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3960 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003962 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003963 /* don't mark it as set, when starting the GUI it may be
3964 * changed again */
3965 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 }
3967#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003968
3969#ifdef CURSOR_SHAPE
3970 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3971#endif
3972#ifdef FEAT_MOUSESHAPE
3973 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3974#endif
3975#ifdef FEAT_PRINTER
3976 (void)parse_printoptions(); /* parse 'printoptions' default value */
3977#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978}
3979
3980/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003981 * Return "dark" or "light" depending on the kind of terminal.
3982 * This is just guessing! Recognized are:
3983 * "linux" Linux console
3984 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003985 * "cygwin.*" Cygwin shell
3986 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003987 * We also check the COLORFGBG environment variable, which is set by
3988 * rxvt and derivatives. This variable contains either two or three
3989 * values separated by semicolons; we want the last value in either
3990 * case. If this value is 0-6 or 8, our background is dark.
3991 */
3992 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003993term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003994{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003995#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003996 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003997 return (char_u *)"dark";
3998#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003999 char_u *p;
4000
Bram Moolenaarf740b292006-02-16 22:11:02 +00004001 if (STRCMP(T_NAME, "linux") == 0
4002 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004003 || STRNCMP(T_NAME, "cygwin", 6) == 0
4004 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004005 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4006 && (p = vim_strrchr(p, ';')) != NULL
4007 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4008 && p[2] == NUL))
4009 return (char_u *)"dark";
4010 return (char_u *)"light";
4011#endif
4012}
4013
4014/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015 * Initialize the options, part three: After reading the .vimrc
4016 */
4017 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004018set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004020#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021/*
4022 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4023 * This is done after other initializations, where 'shell' might have been
4024 * set, but only if they have not been set before.
4025 */
4026 char_u *p;
4027 int idx_srr;
4028 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004029# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030 int idx_sp;
4031 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004032# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033
4034 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004035 if (idx_srr < 0)
4036 do_srr = FALSE;
4037 else
4038 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004039# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004041 if (idx_sp < 0)
4042 do_sp = FALSE;
4043 else
4044 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004045# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004046 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047 if (p != NULL)
4048 {
4049 /*
4050 * Default for p_sp is "| tee", for p_srr is ">".
4051 * For known shells it is changed here to include stderr.
4052 */
4053 if ( fnamecmp(p, "csh") == 0
4054 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004055# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 || fnamecmp(p, "csh.exe") == 0
4057 || fnamecmp(p, "tcsh.exe") == 0
4058# endif
4059 )
4060 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 if (do_sp)
4063 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004064# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004066# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004068# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4070 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004071# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 if (do_srr)
4073 {
4074 p_srr = (char_u *)">&";
4075 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4076 }
4077 }
4078 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 if ( fnamecmp(p, "sh") == 0
4081 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004082 || fnamecmp(p, "mksh") == 0
4083 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004085 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004087 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004088# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 || fnamecmp(p, "cmd") == 0
4090 || fnamecmp(p, "sh.exe") == 0
4091 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004092 || fnamecmp(p, "mksh.exe") == 0
4093 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004095 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 || fnamecmp(p, "bash.exe") == 0
4097 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004099 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004101# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 if (do_sp)
4103 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004104# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004106# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4110 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004111# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 if (do_srr)
4113 {
4114 p_srr = (char_u *)">%s 2>&1";
4115 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4116 }
4117 }
4118 vim_free(p);
4119 }
4120#endif
4121
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004122#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004124 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4125 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 * This is done after other initializations, where 'shell' might have been
4127 * set, but only if they have not been set before. Default for p_shcf is
4128 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004129 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004131 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 {
4133 int idx3;
4134
4135 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004136 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 {
4138 p_shcf = (char_u *)"-c";
4139 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4140 }
4141
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 /* Somehow Win32 requires the quotes around the redirection too */
4143 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004144 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 {
4146 p_sxq = (char_u *)"\"";
4147 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004150 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4151 {
4152 int idx3;
4153
4154 /*
4155 * cmd.exe on Windows will strip the first and last double quote given
4156 * on the command line, e.g. most of the time things like:
4157 * cmd /c "my path/to/echo" "my args to echo"
4158 * become:
4159 * my path/to/echo" "my args to echo
4160 * when executed.
4161 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004162 * To avoid this, set shellxquote to surround the command in
4163 * parenthesis. This appears to make most commands work, without
4164 * breaking commands that worked previously, such as
4165 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004166 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004167 idx3 = findoption((char_u *)"sxq");
4168 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4169 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004170 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004171 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4172 }
4173
Bram Moolenaara64ba222012-02-12 23:23:31 +01004174 idx3 = findoption((char_u *)"shcf");
4175 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4176 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004177 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004178 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4179 }
4180 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004181#endif
4182
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004183 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004184 {
4185 int idx_ffs = findoption((char_u *)"ffs");
4186
4187 /* Apply the first entry of 'fileformats' to the initial buffer. */
4188 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4189 set_fileformat(default_fileformat(), OPT_LOCAL);
4190 }
4191
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192#ifdef FEAT_TITLE
4193 set_title_defaults();
4194#endif
4195}
4196
4197#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4198/*
4199 * When 'helplang' is still at its default value, set it to "lang".
4200 * Only the first two characters of "lang" are used.
4201 */
4202 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004203set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004204{
4205 int idx;
4206
4207 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4208 return;
4209 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004210 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004211 {
4212 if (options[idx].flags & P_ALLOCED)
4213 free_string_option(p_hlg);
4214 p_hlg = vim_strsave(lang);
4215 if (p_hlg == NULL)
4216 p_hlg = empty_option;
4217 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004218 {
4219 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4220 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4221 {
4222 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4223 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4224 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004226 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 options[idx].flags |= P_ALLOCED;
4228 }
4229}
4230#endif
4231
4232#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004233static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234
4235 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004236gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004237{
4238 if (gui_get_lightness(gui.back_pixel) < 127)
4239 return (char_u *)"dark";
4240 return (char_u *)"light";
4241}
4242
4243/*
4244 * Option initializations that can only be done after opening the GUI window.
4245 */
4246 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004247init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248{
4249 /* Set the 'background' option according to the lightness of the
4250 * background color, unless the user has set it already. */
4251 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4252 {
4253 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4254 highlight_changed();
4255 }
4256}
4257#endif
4258
4259#ifdef FEAT_TITLE
4260/*
4261 * 'title' and 'icon' only default to true if they have not been set or reset
4262 * in .vimrc and we can read the old value.
4263 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4264 * they can be reset. This reduces startup time when using X on a remote
4265 * machine.
4266 */
4267 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004268set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004269{
4270 int idx1;
4271 long val;
4272
4273 /*
4274 * If GUI is (going to be) used, we can always set the window title and
4275 * icon name. Saves a bit of time, because the X11 display server does
4276 * not need to be contacted.
4277 */
4278 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004279 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004280 {
4281#ifdef FEAT_GUI
4282 if (gui.starting || gui.in_use)
4283 val = TRUE;
4284 else
4285#endif
4286 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004287 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004288 p_title = val;
4289 }
4290 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004291 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004292 {
4293#ifdef FEAT_GUI
4294 if (gui.starting || gui.in_use)
4295 val = TRUE;
4296 else
4297#endif
4298 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004299 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004300 p_icon = val;
4301 }
4302}
4303#endif
4304
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004305#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4306 static void
4307trigger_optionsset_string(
4308 int opt_idx,
4309 int opt_flags,
4310 char_u *oldval,
4311 char_u *newval)
4312{
4313 if (oldval != NULL && newval != NULL)
4314 {
4315 char_u buf_type[7];
4316
4317 sprintf((char *)buf_type, "%s",
4318 (opt_flags & OPT_LOCAL) ? "local" : "global");
4319 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4320 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4321 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4322 apply_autocmds(EVENT_OPTIONSET,
4323 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4324 reset_v_option_vars();
4325 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004326}
4327#endif
4328
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329/*
4330 * Parse 'arg' for option settings.
4331 *
4332 * 'arg' may be IObuff, but only when no errors can be present and option
4333 * does not need to be expanded with option_expand().
4334 * "opt_flags":
4335 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004336 * OPT_GLOBAL for ":setglobal"
4337 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004338 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004339 * OPT_WINONLY to only set window-local options
4340 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004341 *
4342 * returns FAIL if an error is detected, OK otherwise
4343 */
4344 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004345do_set(
4346 char_u *arg, /* option string (may be written to!) */
4347 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004348{
4349 int opt_idx;
4350 char_u *errmsg;
4351 char_u errbuf[80];
4352 char_u *startarg;
4353 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4354 int nextchar; /* next non-white char after option name */
4355 int afterchar; /* character just after option name */
4356 int len;
4357 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004358 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359 int key;
4360 long_u flags; /* flags for current option */
4361 char_u *varp = NULL; /* pointer to variable for current option */
4362 int did_show = FALSE; /* already showed one value */
4363 int adding; /* "opt+=arg" */
4364 int prepending; /* "opt^=arg" */
4365 int removing; /* "opt-=arg" */
4366 int cp_val = 0;
4367 char_u key_name[2];
4368
4369 if (*arg == NUL)
4370 {
4371 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004372 did_show = TRUE;
4373 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374 }
4375
4376 while (*arg != NUL) /* loop to process all options */
4377 {
4378 errmsg = NULL;
4379 startarg = arg; /* remember for error message */
4380
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004381 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4382 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383 {
4384 /*
4385 * ":set all" show all options.
4386 * ":set all&" set all options to their default value.
4387 */
4388 arg += 3;
4389 if (*arg == '&')
4390 {
4391 ++arg;
4392 /* Only for :set command set global value of local options. */
4393 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004394 didset_options();
4395 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004396 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004397 }
4398 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004399 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004400 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004401 did_show = TRUE;
4402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004404 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004405 {
4406 showoptions(2, opt_flags);
4407 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004408 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004409 arg += 7;
4410 }
4411 else
4412 {
4413 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004414 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004415 {
4416 prefix = 0;
4417 arg += 2;
4418 }
4419 else if (STRNCMP(arg, "inv", 3) == 0)
4420 {
4421 prefix = 2;
4422 arg += 3;
4423 }
4424
4425 /* find end of name */
4426 key = 0;
4427 if (*arg == '<')
4428 {
4429 nextchar = 0;
4430 opt_idx = -1;
4431 /* look out for <t_>;> */
4432 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4433 len = 5;
4434 else
4435 {
4436 len = 1;
4437 while (arg[len] != NUL && arg[len] != '>')
4438 ++len;
4439 }
4440 if (arg[len] != '>')
4441 {
4442 errmsg = e_invarg;
4443 goto skip;
4444 }
4445 arg[len] = NUL; /* put NUL after name */
4446 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4447 opt_idx = findoption(arg + 1);
4448 arg[len++] = '>'; /* restore '>' */
4449 if (opt_idx == -1)
4450 key = find_key_option(arg + 1);
4451 }
4452 else
4453 {
4454 len = 0;
4455 /*
4456 * The two characters after "t_" may not be alphanumeric.
4457 */
4458 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4459 len = 4;
4460 else
4461 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4462 ++len;
4463 nextchar = arg[len];
4464 arg[len] = NUL; /* put NUL after name */
4465 opt_idx = findoption(arg);
4466 arg[len] = nextchar; /* restore nextchar */
4467 if (opt_idx == -1)
4468 key = find_key_option(arg);
4469 }
4470
4471 /* remember character after option name */
4472 afterchar = arg[len];
4473
4474 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004475 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004476 ++len;
4477
4478 adding = FALSE;
4479 prepending = FALSE;
4480 removing = FALSE;
4481 if (arg[len] != NUL && arg[len + 1] == '=')
4482 {
4483 if (arg[len] == '+')
4484 {
4485 adding = TRUE; /* "+=" */
4486 ++len;
4487 }
4488 else if (arg[len] == '^')
4489 {
4490 prepending = TRUE; /* "^=" */
4491 ++len;
4492 }
4493 else if (arg[len] == '-')
4494 {
4495 removing = TRUE; /* "-=" */
4496 ++len;
4497 }
4498 }
4499 nextchar = arg[len];
4500
4501 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4502 {
4503 errmsg = (char_u *)N_("E518: Unknown option");
4504 goto skip;
4505 }
4506
4507 if (opt_idx >= 0)
4508 {
4509 if (options[opt_idx].var == NULL) /* hidden option: skip */
4510 {
4511 /* Only give an error message when requesting the value of
4512 * a hidden option, ignore setting it. */
4513 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4514 && (!(options[opt_idx].flags & P_BOOL)
4515 || nextchar == '?'))
4516 errmsg = (char_u *)N_("E519: Option not supported");
4517 goto skip;
4518 }
4519
4520 flags = options[opt_idx].flags;
4521 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4522 }
4523 else
4524 {
4525 flags = P_STRING;
4526 if (key < 0)
4527 {
4528 key_name[0] = KEY2TERMCAP0(key);
4529 key_name[1] = KEY2TERMCAP1(key);
4530 }
4531 else
4532 {
4533 key_name[0] = KS_KEY;
4534 key_name[1] = (key & 0xff);
4535 }
4536 }
4537
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004538 /* Skip all options that are not window-local (used when showing
4539 * an already loaded buffer in a window). */
4540 if ((opt_flags & OPT_WINONLY)
4541 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4542 goto skip;
4543
Bram Moolenaara3227e22006-03-08 21:32:40 +00004544 /* Skip all options that are window-local (used for :vimgrep). */
4545 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4546 && options[opt_idx].var == VAR_WIN)
4547 goto skip;
4548
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004549 /* Disallow changing some options from modelines. */
4550 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004551 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004552 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004553 {
4554 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4555 goto skip;
4556 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004557#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004558 /* In diff mode some options are overruled. This avoids that
4559 * 'foldmethod' becomes "marker" instead of "diff" and that
4560 * "wrap" gets set. */
4561 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004562 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004563 && (
4564#ifdef FEAT_FOLDING
4565 options[opt_idx].indir == PV_FDM ||
4566#endif
4567 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004568 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004569#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 }
4571
4572#ifdef HAVE_SANDBOX
4573 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004574 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004575 {
4576 errmsg = (char_u *)_(e_sandbox);
4577 goto skip;
4578 }
4579#endif
4580
4581 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4582 {
4583 arg += len;
4584 cp_val = p_cp;
4585 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4586 {
4587 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4588 {
4589 cp_val = FALSE;
4590 arg += 3;
4591 }
4592 else /* "opt&vi": set to Vi default */
4593 {
4594 cp_val = TRUE;
4595 arg += 2;
4596 }
4597 }
4598 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004599 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004600 {
4601 errmsg = e_trailing;
4602 goto skip;
4603 }
4604 }
4605
4606 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004607 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4608 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004609 */
4610 if (nextchar == '?'
4611 || (prefix == 1
4612 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4613 && !(flags & P_BOOL)))
4614 {
4615 /*
4616 * print value
4617 */
4618 if (did_show)
4619 msg_putchar('\n'); /* cursor below last one */
4620 else
4621 {
4622 gotocmdline(TRUE); /* cursor at status line */
4623 did_show = TRUE; /* remember that we did a line */
4624 }
4625 if (opt_idx >= 0)
4626 {
4627 showoneopt(&options[opt_idx], opt_flags);
4628#ifdef FEAT_EVAL
4629 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004630 {
4631 /* Mention where the option was last set. */
4632 if (varp == options[opt_idx].var)
4633 last_set_msg(options[opt_idx].scriptID);
4634 else if ((int)options[opt_idx].indir & PV_WIN)
4635 last_set_msg(curwin->w_p_scriptID[
4636 (int)options[opt_idx].indir & PV_MASK]);
4637 else if ((int)options[opt_idx].indir & PV_BUF)
4638 last_set_msg(curbuf->b_p_scriptID[
4639 (int)options[opt_idx].indir & PV_MASK]);
4640 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004641#endif
4642 }
4643 else
4644 {
4645 char_u *p;
4646
4647 p = find_termcode(key_name);
4648 if (p == NULL)
4649 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004650 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651 goto skip;
4652 }
4653 else
4654 (void)show_one_termcode(key_name, p, TRUE);
4655 }
4656 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004657 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004658 errmsg = e_trailing;
4659 }
4660 else
4661 {
4662 if (flags & P_BOOL) /* boolean */
4663 {
4664 if (nextchar == '=' || nextchar == ':')
4665 {
4666 errmsg = e_invarg;
4667 goto skip;
4668 }
4669
4670 /*
4671 * ":set opt!": invert
4672 * ":set opt&": reset to default value
4673 * ":set opt<": reset to global value
4674 */
4675 if (nextchar == '!')
4676 value = *(int *)(varp) ^ 1;
4677 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004678 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004679 ((flags & P_VI_DEF) || cp_val)
4680 ? VI_DEFAULT : VIM_DEFAULT];
4681 else if (nextchar == '<')
4682 {
4683 /* For 'autoread' -1 means to use global value. */
4684 if ((int *)varp == &curbuf->b_p_ar
4685 && opt_flags == OPT_LOCAL)
4686 value = -1;
4687 else
4688 value = *(int *)get_varp_scope(&(options[opt_idx]),
4689 OPT_GLOBAL);
4690 }
4691 else
4692 {
4693 /*
4694 * ":set invopt": invert
4695 * ":set opt" or ":set noopt": set or reset
4696 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004697 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004698 {
4699 errmsg = e_trailing;
4700 goto skip;
4701 }
4702 if (prefix == 2) /* inv */
4703 value = *(int *)(varp) ^ 1;
4704 else
4705 value = prefix;
4706 }
4707
4708 errmsg = set_bool_option(opt_idx, varp, (int)value,
4709 opt_flags);
4710 }
4711 else /* numeric or string */
4712 {
4713 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4714 || prefix != 1)
4715 {
4716 errmsg = e_invarg;
4717 goto skip;
4718 }
4719
4720 if (flags & P_NUM) /* numeric */
4721 {
4722 /*
4723 * Different ways to set a number option:
4724 * & set to default value
4725 * < set to global value
4726 * <xx> accept special key codes for 'wildchar'
4727 * c accept any non-digit for 'wildchar'
4728 * [-]0-9 set number
4729 * other error
4730 */
4731 ++arg;
4732 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004733 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004734 ((flags & P_VI_DEF) || cp_val)
4735 ? VI_DEFAULT : VIM_DEFAULT];
4736 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004737 {
4738 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4739 * use the global value. */
4740 if ((long *)varp == &curbuf->b_p_ul
4741 && opt_flags == OPT_LOCAL)
4742 value = NO_LOCAL_UNDOLEVEL;
4743 else
4744 value = *(long *)get_varp_scope(
4745 &(options[opt_idx]), OPT_GLOBAL);
4746 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004747 else if (((long *)varp == &p_wc
4748 || (long *)varp == &p_wcm)
4749 && (*arg == '<'
4750 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004751 || (*arg != NUL
4752 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004753 && !VIM_ISDIGIT(*arg))))
4754 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004755 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004756 if (value == 0 && (long *)varp != &p_wcm)
4757 {
4758 errmsg = e_invarg;
4759 goto skip;
4760 }
4761 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004762 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4763 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004764 /* Allow negative (for 'undolevels'), octal and
4765 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004766 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4767 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004768 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769 {
4770 errmsg = e_invarg;
4771 goto skip;
4772 }
4773 }
4774 else
4775 {
4776 errmsg = (char_u *)N_("E521: Number required after =");
4777 goto skip;
4778 }
4779
4780 if (adding)
4781 value = *(long *)varp + value;
4782 if (prepending)
4783 value = *(long *)varp * value;
4784 if (removing)
4785 value = *(long *)varp - value;
4786 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004787 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004788 }
4789 else if (opt_idx >= 0) /* string */
4790 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004791 char_u *save_arg = NULL;
4792 char_u *s = NULL;
4793 char_u *oldval = NULL; /* previous value if *varp */
4794 char_u *newval;
4795 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004796#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004797 char_u *saved_origval = NULL;
4798 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004799#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004800 unsigned newlen;
4801 int comma;
4802 int bs;
4803 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804 was allocated */
4805
4806 /* When using ":set opt=val" for a global option
4807 * with a local value the local value will be
4808 * reset, use the global value here. */
4809 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004810 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004811 varp = options[opt_idx].var;
4812
4813 /* The old value is kept until we are sure that the
4814 * new value is valid. */
4815 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004816
4817 /* When setting the local value of a global
4818 * option, the old value may be the global value. */
4819 if (((int)options[opt_idx].indir & PV_BOTH)
4820 && (opt_flags & OPT_LOCAL))
4821 origval = *(char_u **)get_varp(
4822 &options[opt_idx]);
4823 else
4824 origval = oldval;
4825
Bram Moolenaar071d4272004-06-13 20:20:40 +00004826 if (nextchar == '&') /* set to default val */
4827 {
4828 newval = options[opt_idx].def_val[
4829 ((flags & P_VI_DEF) || cp_val)
4830 ? VI_DEFAULT : VIM_DEFAULT];
4831 if ((char_u **)varp == &p_bg)
4832 {
4833 /* guess the value of 'background' */
4834#ifdef FEAT_GUI
4835 if (gui.in_use)
4836 newval = gui_bg_default();
4837 else
4838#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004839 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004840 }
4841
4842 /* expand environment variables and ~ (since the
4843 * default value was already expanded, only
4844 * required when an environment variable was set
4845 * later */
4846 if (newval == NULL)
4847 newval = empty_option;
4848 else
4849 {
4850 s = option_expand(opt_idx, newval);
4851 if (s == NULL)
4852 s = newval;
4853 newval = vim_strsave(s);
4854 }
4855 new_value_alloced = TRUE;
4856 }
4857 else if (nextchar == '<') /* set to global val */
4858 {
4859 newval = vim_strsave(*(char_u **)get_varp_scope(
4860 &(options[opt_idx]), OPT_GLOBAL));
4861 new_value_alloced = TRUE;
4862 }
4863 else
4864 {
4865 ++arg; /* jump to after the '=' or ':' */
4866
4867 /*
4868 * Set 'keywordprg' to ":help" if an empty
4869 * value was passed to :set by the user.
4870 * Misuse errbuf[] for the resulting string.
4871 */
4872 if (varp == (char_u *)&p_kp
4873 && (*arg == NUL || *arg == ' '))
4874 {
4875 STRCPY(errbuf, ":help");
4876 save_arg = arg;
4877 arg = errbuf;
4878 }
4879 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004880 * Convert 'backspace' number to string, for
4881 * adding, prepending and removing string.
4882 */
4883 else if (varp == (char_u *)&p_bs
4884 && VIM_ISDIGIT(**(char_u **)varp))
4885 {
4886 i = getdigits((char_u **)varp);
4887 switch (i)
4888 {
4889 case 0:
4890 *(char_u **)varp = empty_option;
4891 break;
4892 case 1:
4893 *(char_u **)varp = vim_strsave(
4894 (char_u *)"indent,eol");
4895 break;
4896 case 2:
4897 *(char_u **)varp = vim_strsave(
4898 (char_u *)"indent,eol,start");
4899 break;
4900 }
4901 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004902 if (origval == oldval)
4903 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004904 oldval = *(char_u **)varp;
4905 }
4906 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004907 * Convert 'whichwrap' number to string, for
4908 * backwards compatibility with Vim 3.0.
4909 * Misuse errbuf[] for the resulting string.
4910 */
4911 else if (varp == (char_u *)&p_ww
4912 && VIM_ISDIGIT(*arg))
4913 {
4914 *errbuf = NUL;
4915 i = getdigits(&arg);
4916 if (i & 1)
4917 STRCAT(errbuf, "b,");
4918 if (i & 2)
4919 STRCAT(errbuf, "s,");
4920 if (i & 4)
4921 STRCAT(errbuf, "h,l,");
4922 if (i & 8)
4923 STRCAT(errbuf, "<,>,");
4924 if (i & 16)
4925 STRCAT(errbuf, "[,],");
4926 if (*errbuf != NUL) /* remove trailing , */
4927 errbuf[STRLEN(errbuf) - 1] = NUL;
4928 save_arg = arg;
4929 arg = errbuf;
4930 }
4931 /*
4932 * Remove '>' before 'dir' and 'bdir', for
4933 * backwards compatibility with version 3.0
4934 */
4935 else if ( *arg == '>'
4936 && (varp == (char_u *)&p_dir
4937 || varp == (char_u *)&p_bdir))
4938 {
4939 ++arg;
4940 }
4941
Bram Moolenaar071d4272004-06-13 20:20:40 +00004942 /*
4943 * Copy the new string into allocated memory.
4944 * Can't use set_string_option_direct(), because
4945 * we need to remove the backslashes.
4946 */
4947 /* get a bit too much */
4948 newlen = (unsigned)STRLEN(arg) + 1;
4949 if (adding || prepending || removing)
4950 newlen += (unsigned)STRLEN(origval) + 1;
4951 newval = alloc(newlen);
4952 if (newval == NULL) /* out of mem, don't change */
4953 break;
4954 s = newval;
4955
4956 /*
4957 * Copy the string, skip over escaped chars.
4958 * For MS-DOS and WIN32 backslashes before normal
4959 * file name characters are not removed, and keep
4960 * backslash at start, for "\\machine\path", but
4961 * do remove it for "\\\\machine\\path".
4962 * The reverse is found in ExpandOldSetting().
4963 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004964 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004965 {
4966 if (*arg == '\\' && arg[1] != NUL
4967#ifdef BACKSLASH_IN_FILENAME
4968 && !((flags & P_EXPAND)
4969 && vim_isfilec(arg[1])
4970 && (arg[1] != '\\'
4971 || (s == newval
4972 && arg[2] != '\\')))
4973#endif
4974 )
4975 ++arg; /* remove backslash */
4976#ifdef FEAT_MBYTE
4977 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004978 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004979 {
4980 /* copy multibyte char */
4981 mch_memmove(s, arg, (size_t)i);
4982 arg += i;
4983 s += i;
4984 }
4985 else
4986#endif
4987 *s++ = *arg++;
4988 }
4989 *s = NUL;
4990
4991 /*
4992 * Expand environment variables and ~.
4993 * Don't do it when adding without inserting a
4994 * comma.
4995 */
4996 if (!(adding || prepending || removing)
4997 || (flags & P_COMMA))
4998 {
4999 s = option_expand(opt_idx, newval);
5000 if (s != NULL)
5001 {
5002 vim_free(newval);
5003 newlen = (unsigned)STRLEN(s) + 1;
5004 if (adding || prepending || removing)
5005 newlen += (unsigned)STRLEN(origval) + 1;
5006 newval = alloc(newlen);
5007 if (newval == NULL)
5008 break;
5009 STRCPY(newval, s);
5010 }
5011 }
5012
5013 /* locate newval[] in origval[] when removing it
5014 * and when adding to avoid duplicates */
5015 i = 0; /* init for GCC */
5016 if (removing || (flags & P_NODUP))
5017 {
5018 i = (int)STRLEN(newval);
5019 bs = 0;
5020 for (s = origval; *s; ++s)
5021 {
5022 if ((!(flags & P_COMMA)
5023 || s == origval
5024 || (s[-1] == ',' && !(bs & 1)))
5025 && STRNCMP(s, newval, i) == 0
5026 && (!(flags & P_COMMA)
5027 || s[i] == ','
5028 || s[i] == NUL))
5029 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005030 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005031 * even number of backslashes or a single
5032 * backslash preceded by a comma before it
5033 * is recognized as a separator */
5034 if ((s > origval + 1
5035 && s[-1] == '\\'
5036 && s[-2] != ',')
5037 || (s == origval + 1
5038 && s[-1] == '\\'))
5039
Bram Moolenaar071d4272004-06-13 20:20:40 +00005040 ++bs;
5041 else
5042 bs = 0;
5043 }
5044
5045 /* do not add if already there */
5046 if ((adding || prepending) && *s)
5047 {
5048 prepending = FALSE;
5049 adding = FALSE;
5050 STRCPY(newval, origval);
5051 }
5052 }
5053
5054 /* concatenate the two strings; add a ',' if
5055 * needed */
5056 if (adding || prepending)
5057 {
5058 comma = ((flags & P_COMMA) && *origval != NUL
5059 && *newval != NUL);
5060 if (adding)
5061 {
5062 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005063 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005064 if (comma && i > 1
5065 && (flags & P_ONECOMMA) == P_ONECOMMA
5066 && origval[i - 1] == ','
5067 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005068 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005069 mch_memmove(newval + i + comma, newval,
5070 STRLEN(newval) + 1);
5071 mch_memmove(newval, origval, (size_t)i);
5072 }
5073 else
5074 {
5075 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005076 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005077 }
5078 if (comma)
5079 newval[i] = ',';
5080 }
5081
5082 /* Remove newval[] from origval[]. (Note: "i" has
5083 * been set above and is used here). */
5084 if (removing)
5085 {
5086 STRCPY(newval, origval);
5087 if (*s)
5088 {
5089 /* may need to remove a comma */
5090 if (flags & P_COMMA)
5091 {
5092 if (s == origval)
5093 {
5094 /* include comma after string */
5095 if (s[i] == ',')
5096 ++i;
5097 }
5098 else
5099 {
5100 /* include comma before string */
5101 --s;
5102 ++i;
5103 }
5104 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005105 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106 }
5107 }
5108
5109 if (flags & P_FLAGLIST)
5110 {
5111 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005112 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005113 {
5114 /* if options have P_FLAGLIST and
5115 * P_ONECOMMA such as 'whichwrap' */
5116 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005117 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005118 if (*s != ',' && *(s + 1) == ','
5119 && vim_strchr(s + 2, *s) != NULL)
5120 {
5121 /* Remove the duplicated value and
5122 * the next comma. */
5123 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005124 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005126 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005127 else
5128 {
5129 if ((!(flags & P_COMMA) || *s != ',')
5130 && vim_strchr(s + 1, *s) != NULL)
5131 {
5132 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005133 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005134 }
5135 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005136 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005137 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005138 }
5139
5140 if (save_arg != NULL) /* number for 'whichwrap' */
5141 arg = save_arg;
5142 new_value_alloced = TRUE;
5143 }
5144
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005145 /*
5146 * Set the new value.
5147 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005148 *(char_u **)(varp) = newval;
5149
Bram Moolenaar53744302015-07-17 17:38:22 +02005150#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005151 if (!starting
5152# ifdef FEAT_CRYPT
5153 && options[opt_idx].indir != PV_KEY
5154# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005155 && origval != NULL && newval != NULL)
5156 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005157 /* origval may be freed by
5158 * did_set_string_option(), make a copy. */
5159 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005160 /* newval (and varp) may become invalid if the
5161 * buffer is closed by autocommands. */
5162 saved_newval = vim_strsave(newval);
5163 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005164#endif
5165
Bram Moolenaar071d4272004-06-13 20:20:40 +00005166 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005167 * ":set" on local options. Note: when setting 'syntax'
5168 * or 'filetype' autocommands may be triggered that can
5169 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005170 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5171 new_value_alloced, oldval, errbuf, opt_flags);
5172
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005173#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5174 if (errmsg == NULL)
5175 trigger_optionsset_string(opt_idx, opt_flags,
5176 saved_origval, saved_newval);
5177 vim_free(saved_origval);
5178 vim_free(saved_newval);
5179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005180 /* If error detected, print the error message. */
5181 if (errmsg != NULL)
5182 goto skip;
5183 }
5184 else /* key code option */
5185 {
5186 char_u *p;
5187
5188 if (nextchar == '&')
5189 {
5190 if (add_termcap_entry(key_name, TRUE) == FAIL)
5191 errmsg = (char_u *)N_("E522: Not found in termcap");
5192 }
5193 else
5194 {
5195 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005196 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005197 if (*p == '\\' && p[1] != NUL)
5198 ++p;
5199 nextchar = *p;
5200 *p = NUL;
5201 add_termcode(key_name, arg, FALSE);
5202 *p = nextchar;
5203 }
5204 if (full_screen)
5205 ttest(FALSE);
5206 redraw_all_later(CLEAR);
5207 }
5208 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005209
Bram Moolenaar071d4272004-06-13 20:20:40 +00005210 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005211 did_set_option(opt_idx, opt_flags,
5212 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005213 }
5214
5215skip:
5216 /*
5217 * Advance to next argument.
5218 * - skip until a blank found, taking care of backslashes
5219 * - skip blanks
5220 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5221 */
5222 for (i = 0; i < 2 ; ++i)
5223 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005224 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005225 if (*arg++ == '\\' && *arg != NUL)
5226 ++arg;
5227 arg = skipwhite(arg);
5228 if (*arg != '=')
5229 break;
5230 }
5231 }
5232
5233 if (errmsg != NULL)
5234 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005235 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005236 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005237 if (i + (arg - startarg) < IOSIZE)
5238 {
5239 /* append the argument with the error */
5240 STRCAT(IObuff, ": ");
5241 mch_memmove(IObuff + i, startarg, (arg - startarg));
5242 IObuff[i + (arg - startarg)] = NUL;
5243 }
5244 /* make sure all characters are printable */
5245 trans_characters(IObuff, IOSIZE);
5246
5247 ++no_wait_return; /* wait_return done later */
5248 emsg(IObuff); /* show error highlighted */
5249 --no_wait_return;
5250
5251 return FAIL;
5252 }
5253
5254 arg = skipwhite(arg);
5255 }
5256
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005257theend:
5258 if (silent_mode && did_show)
5259 {
5260 /* After displaying option values in silent mode. */
5261 silent_mode = FALSE;
5262 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5263 msg_putchar('\n');
5264 cursor_on(); /* msg_start() switches it off */
5265 out_flush();
5266 silent_mode = TRUE;
5267 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5268 }
5269
Bram Moolenaar071d4272004-06-13 20:20:40 +00005270 return OK;
5271}
5272
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005273/*
5274 * Call this when an option has been given a new value through a user command.
5275 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5276 */
5277 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005278did_set_option(
5279 int opt_idx,
5280 int opt_flags, /* possibly with OPT_MODELINE */
5281 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005282{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005283 long_u *p;
5284
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005285 options[opt_idx].flags |= P_WAS_SET;
5286
5287 /* When an option is set in the sandbox, from a modeline or in secure mode
5288 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005289 * flag. */
5290 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005291 if (secure
5292#ifdef HAVE_SANDBOX
5293 || sandbox != 0
5294#endif
5295 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005296 *p = *p | P_INSECURE;
5297 else if (new_value)
5298 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005299}
5300
Bram Moolenaar071d4272004-06-13 20:20:40 +00005301 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005302illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005303{
5304 if (errbuf == NULL)
5305 return (char_u *)"";
5306 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005307 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308 return errbuf;
5309}
5310
5311/*
5312 * Convert a key name or string into a key value.
5313 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005314 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005315 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005316 int
5317string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005318{
5319 if (*arg == '<')
5320 return find_key_option(arg + 1);
5321 if (*arg == '^')
5322 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005323 if (multi_byte)
5324 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325 return *arg;
5326}
5327
5328#ifdef FEAT_CMDWIN
5329/*
5330 * Check value of 'cedit' and set cedit_key.
5331 * Returns NULL if value is OK, error message otherwise.
5332 */
5333 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005334check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335{
5336 int n;
5337
5338 if (*p_cedit == NUL)
5339 cedit_key = -1;
5340 else
5341 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005342 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343 if (vim_isprintc(n))
5344 return e_invarg;
5345 cedit_key = n;
5346 }
5347 return NULL;
5348}
5349#endif
5350
5351#ifdef FEAT_TITLE
5352/*
5353 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5354 * maketitle() to create and display it.
5355 * When switching the title or icon off, call mch_restore_title() to get
5356 * the old value back.
5357 */
5358 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005359did_set_title(
5360 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005361{
5362 if (starting != NO_SCREEN
5363#ifdef FEAT_GUI
5364 && !gui.starting
5365#endif
5366 )
5367 {
5368 maketitle();
5369 if (icon)
5370 {
5371 if (!p_icon)
5372 mch_restore_title(2);
5373 }
5374 else
5375 {
5376 if (!p_title)
5377 mch_restore_title(1);
5378 }
5379 }
5380}
5381#endif
5382
5383/*
5384 * set_options_bin - called when 'bin' changes value.
5385 */
5386 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005387set_options_bin(
5388 int oldval,
5389 int newval,
5390 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005391{
5392 /*
5393 * The option values that are changed when 'bin' changes are
5394 * copied when 'bin is set and restored when 'bin' is reset.
5395 */
5396 if (newval)
5397 {
5398 if (!oldval) /* switched on */
5399 {
5400 if (!(opt_flags & OPT_GLOBAL))
5401 {
5402 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5403 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5404 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5405 curbuf->b_p_et_nobin = curbuf->b_p_et;
5406 }
5407 if (!(opt_flags & OPT_LOCAL))
5408 {
5409 p_tw_nobin = p_tw;
5410 p_wm_nobin = p_wm;
5411 p_ml_nobin = p_ml;
5412 p_et_nobin = p_et;
5413 }
5414 }
5415
5416 if (!(opt_flags & OPT_GLOBAL))
5417 {
5418 curbuf->b_p_tw = 0; /* no automatic line wrap */
5419 curbuf->b_p_wm = 0; /* no automatic line wrap */
5420 curbuf->b_p_ml = 0; /* no modelines */
5421 curbuf->b_p_et = 0; /* no expandtab */
5422 }
5423 if (!(opt_flags & OPT_LOCAL))
5424 {
5425 p_tw = 0;
5426 p_wm = 0;
5427 p_ml = FALSE;
5428 p_et = FALSE;
5429 p_bin = TRUE; /* needed when called for the "-b" argument */
5430 }
5431 }
5432 else if (oldval) /* switched off */
5433 {
5434 if (!(opt_flags & OPT_GLOBAL))
5435 {
5436 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5437 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5438 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5439 curbuf->b_p_et = curbuf->b_p_et_nobin;
5440 }
5441 if (!(opt_flags & OPT_LOCAL))
5442 {
5443 p_tw = p_tw_nobin;
5444 p_wm = p_wm_nobin;
5445 p_ml = p_ml_nobin;
5446 p_et = p_et_nobin;
5447 }
5448 }
5449}
5450
5451#ifdef FEAT_VIMINFO
5452/*
5453 * Find the parameter represented by the given character (eg ', :, ", or /),
5454 * and return its associated value in the 'viminfo' string.
5455 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005456 * If the parameter is not specified in the string or there is no following
5457 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005458 */
5459 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005460get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005461{
5462 char_u *p;
5463
5464 p = find_viminfo_parameter(type);
5465 if (p != NULL && VIM_ISDIGIT(*p))
5466 return atoi((char *)p);
5467 return -1;
5468}
5469
5470/*
5471 * Find the parameter represented by the given character (eg ''', ':', '"', or
5472 * '/') in the 'viminfo' option and return a pointer to the string after it.
5473 * Return NULL if the parameter is not specified in the string.
5474 */
5475 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005476find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005477{
5478 char_u *p;
5479
5480 for (p = p_viminfo; *p; ++p)
5481 {
5482 if (*p == type)
5483 return p + 1;
5484 if (*p == 'n') /* 'n' is always the last one */
5485 break;
5486 p = vim_strchr(p, ','); /* skip until next ',' */
5487 if (p == NULL) /* hit the end without finding parameter */
5488 break;
5489 }
5490 return NULL;
5491}
5492#endif
5493
5494/*
5495 * Expand environment variables for some string options.
5496 * These string options cannot be indirect!
5497 * If "val" is NULL expand the current value of the option.
5498 * Return pointer to NameBuff, or NULL when not expanded.
5499 */
5500 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005501option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502{
5503 /* if option doesn't need expansion nothing to do */
5504 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5505 return NULL;
5506
5507 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5508 * expand_env() would truncate the string. */
5509 if (val != NULL && STRLEN(val) > MAXPATHL)
5510 return NULL;
5511
5512 if (val == NULL)
5513 val = *(char_u **)options[opt_idx].var;
5514
5515 /*
5516 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5517 * Escape spaces when expanding 'tags', they are used to separate file
5518 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005519 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520 */
5521 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005522 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005523#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005524 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5525#endif
5526 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005527 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5528 return NULL;
5529
5530 return NameBuff;
5531}
5532
5533/*
5534 * After setting various option values: recompute variables that depend on
5535 * option values.
5536 */
5537 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005538didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539{
5540 /* initialize the table for 'iskeyword' et.al. */
5541 (void)init_chartab();
5542
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005543#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005545#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005547 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005548#ifdef FEAT_SESSION
5549 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5550 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5551#endif
5552#ifdef FEAT_FOLDING
5553 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5554#endif
5555 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005556 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557#ifdef FEAT_VIRTUALEDIT
5558 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5559#endif
5560#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5561 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5562#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005563#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005564 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005565 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005566 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005567 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005568#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005569#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5570 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5571#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005572#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5574#endif
5575#ifdef FEAT_CMDWIN
5576 /* set cedit_key */
5577 (void)check_cedit();
5578#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005579#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005580 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005581#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005582#ifdef FEAT_LINEBREAK
5583 /* initialize the table for 'breakat'. */
5584 fill_breakat_flags();
5585#endif
5586
5587}
5588
5589/*
5590 * More side effects of setting options.
5591 */
5592 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005593didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005594{
5595 /* Initialize the highlight_attr[] table. */
5596 (void)highlight_changed();
5597
5598 /* Parse default for 'wildmode' */
5599 check_opt_wim();
5600
5601 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005602 /* Parse default for 'fillchars'. */
5603 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005604
5605#ifdef FEAT_CLIPBOARD
5606 /* Parse default for 'clipboard' */
5607 (void)check_clipboard_option();
5608#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005609}
5610
5611/*
5612 * Check for string options that are NULL (normally only termcap options).
5613 */
5614 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005615check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005616{
5617 int opt_idx;
5618
5619 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5620 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5621 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5622}
5623
5624/*
5625 * Check string options in a buffer for NULL value.
5626 */
5627 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005628check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005629{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630 check_string_option(&buf->b_p_bh);
5631 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005632#ifdef FEAT_MBYTE
5633 check_string_option(&buf->b_p_fenc);
5634#endif
5635 check_string_option(&buf->b_p_ff);
5636#ifdef FEAT_FIND_ID
5637 check_string_option(&buf->b_p_def);
5638 check_string_option(&buf->b_p_inc);
5639# ifdef FEAT_EVAL
5640 check_string_option(&buf->b_p_inex);
5641# endif
5642#endif
5643#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5644 check_string_option(&buf->b_p_inde);
5645 check_string_option(&buf->b_p_indk);
5646#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005647#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5648 check_string_option(&buf->b_p_bexpr);
5649#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005650#if defined(FEAT_CRYPT)
5651 check_string_option(&buf->b_p_cm);
5652#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005653 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005654#if defined(FEAT_EVAL)
5655 check_string_option(&buf->b_p_fex);
5656#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657#ifdef FEAT_CRYPT
5658 check_string_option(&buf->b_p_key);
5659#endif
5660 check_string_option(&buf->b_p_kp);
5661 check_string_option(&buf->b_p_mps);
5662 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005663 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664 check_string_option(&buf->b_p_isk);
5665#ifdef FEAT_COMMENTS
5666 check_string_option(&buf->b_p_com);
5667#endif
5668#ifdef FEAT_FOLDING
5669 check_string_option(&buf->b_p_cms);
5670#endif
5671 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005672#ifdef FEAT_TEXTOBJ
5673 check_string_option(&buf->b_p_qe);
5674#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675#ifdef FEAT_SYN_HL
5676 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005677 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005678#endif
5679#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005680 check_string_option(&buf->b_s.b_p_spc);
5681 check_string_option(&buf->b_s.b_p_spf);
5682 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683#endif
5684#ifdef FEAT_SEARCHPATH
5685 check_string_option(&buf->b_p_sua);
5686#endif
5687#ifdef FEAT_CINDENT
5688 check_string_option(&buf->b_p_cink);
5689 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005690 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691#endif
5692#ifdef FEAT_AUTOCMD
5693 check_string_option(&buf->b_p_ft);
5694#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5696 check_string_option(&buf->b_p_cinw);
5697#endif
5698#ifdef FEAT_INS_EXPAND
5699 check_string_option(&buf->b_p_cpt);
5700#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005701#ifdef FEAT_COMPL_FUNC
5702 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005703 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705#ifdef FEAT_KEYMAP
5706 check_string_option(&buf->b_p_keymap);
5707#endif
5708#ifdef FEAT_QUICKFIX
5709 check_string_option(&buf->b_p_gp);
5710 check_string_option(&buf->b_p_mp);
5711 check_string_option(&buf->b_p_efm);
5712#endif
5713 check_string_option(&buf->b_p_ep);
5714 check_string_option(&buf->b_p_path);
5715 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005716 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717#ifdef FEAT_INS_EXPAND
5718 check_string_option(&buf->b_p_dict);
5719 check_string_option(&buf->b_p_tsr);
5720#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005721#ifdef FEAT_LISP
5722 check_string_option(&buf->b_p_lw);
5723#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005724 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005725#ifdef FEAT_MBYTE
5726 check_string_option(&buf->b_p_menc);
5727#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728}
5729
5730/*
5731 * Free the string allocated for an option.
5732 * Checks for the string being empty_option. This may happen if we're out of
5733 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5734 * check_options().
5735 * Does NOT check for P_ALLOCED flag!
5736 */
5737 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005738free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739{
5740 if (p != empty_option)
5741 vim_free(p);
5742}
5743
5744 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005745clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746{
5747 if (*pp != empty_option)
5748 vim_free(*pp);
5749 *pp = empty_option;
5750}
5751
5752 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005753check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754{
5755 if (*pp == NULL)
5756 *pp = empty_option;
5757}
5758
5759/*
5760 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5761 */
5762 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005763set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764{
5765 int opt_idx;
5766
5767 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5768 if (options[opt_idx].var == (char_u *)p)
5769 {
5770 options[opt_idx].flags |= P_ALLOCED;
5771 return;
5772 }
5773 return; /* cannot happen: didn't find it! */
5774}
5775
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005776#if defined(FEAT_EVAL) || defined(PROTO)
5777/*
5778 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5779 * Return FALSE when it wasn't.
5780 * Return -1 for an unknown option.
5781 */
5782 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005783was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005784{
5785 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005786 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005787
5788 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005789 {
5790 flagp = insecure_flag(idx, opt_flags);
5791 return (*flagp & P_INSECURE) != 0;
5792 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005793 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005794 return -1;
5795}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005796
5797/*
5798 * Get a pointer to the flags used for the P_INSECURE flag of option
5799 * "opt_idx". For some local options a local flags field is used.
5800 */
5801 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005802insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005803{
5804 if (opt_flags & OPT_LOCAL)
5805 switch ((int)options[opt_idx].indir)
5806 {
5807#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005808 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005809#endif
5810#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005811# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005812 case PV_FDE: return &curwin->w_p_fde_flags;
5813 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005814# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005815# ifdef FEAT_BEVAL
5816 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5817# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005818# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005819 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005820# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005821 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005822# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005823 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005824# endif
5825#endif
5826 }
5827
5828 /* Nothing special, return global flags field. */
5829 return &options[opt_idx].flags;
5830}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005831#endif
5832
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005833#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005834static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005835
5836/*
5837 * Redraw the window title and/or tab page text later.
5838 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005839static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005840{
5841 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005842 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005843}
5844#endif
5845
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846/*
5847 * Set a string option to a new value (without checking the effect).
5848 * The string is copied into allocated memory.
5849 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005850 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005851 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852 */
5853 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005854set_string_option_direct(
5855 char_u *name,
5856 int opt_idx,
5857 char_u *val,
5858 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5859 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860{
5861 char_u *s;
5862 char_u **varp;
5863 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005864 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865
Bram Moolenaar89d40322006-08-29 15:30:07 +00005866 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005868 idx = findoption(name);
5869 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005870 {
5871 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005872 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875 }
5876
Bram Moolenaar89d40322006-08-29 15:30:07 +00005877 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878 return;
5879
5880 s = vim_strsave(val);
5881 if (s != NULL)
5882 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005883 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005884 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005885 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886 free_string_option(*varp);
5887 *varp = s;
5888
5889 /* For buffer/window local option may also set the global value. */
5890 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005891 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892
Bram Moolenaar89d40322006-08-29 15:30:07 +00005893 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894
5895 /* When setting both values of a global option with a local value,
5896 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005897 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 {
5899 free_string_option(*varp);
5900 *varp = empty_option;
5901 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005902# ifdef FEAT_EVAL
5903 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005904 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005905 set_sid == 0 ? current_SID : set_sid);
5906# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907 }
5908}
5909
5910/*
5911 * Set global value for string option when it's a local option.
5912 */
5913 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005914set_string_option_global(
5915 int opt_idx, /* option index */
5916 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917{
5918 char_u **p, *s;
5919
5920 /* the global value is always allocated */
5921 if (options[opt_idx].var == VAR_WIN)
5922 p = (char_u **)GLOBAL_WO(varp);
5923 else
5924 p = (char_u **)options[opt_idx].var;
5925 if (options[opt_idx].indir != PV_NONE
5926 && p != varp
5927 && (s = vim_strsave(*varp)) != NULL)
5928 {
5929 free_string_option(*p);
5930 *p = s;
5931 }
5932}
5933
5934/*
5935 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005936 *
5937 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005939 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005940set_string_option(
5941 int opt_idx,
5942 char_u *value,
5943 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944{
5945 char_u *s;
5946 char_u **varp;
5947 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005948#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5949 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005950 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005951#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005952 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005953
5954 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005955 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956
5957 s = vim_strsave(value);
5958 if (s != NULL)
5959 {
5960 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5961 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005962 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 ? OPT_GLOBAL : OPT_LOCAL)
5964 : opt_flags);
5965 oldval = *varp;
5966 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005967
5968#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005969 if (!starting
5970# ifdef FEAT_CRYPT
5971 && options[opt_idx].indir != PV_KEY
5972# endif
5973 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005974 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005975 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005976 saved_newval = vim_strsave(s);
5977 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005978#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005979 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5980 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005981 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005982
Bram Moolenaar53744302015-07-17 17:38:22 +02005983#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005984 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005985 if (r == NULL)
5986 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005987 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005988 vim_free(saved_oldval);
5989 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005990#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005992 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993}
5994
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005995#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005996/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005997 * Return TRUE if "val" is a valid 'filetype' name.
5998 * Also used for 'syntax' and 'keymap'.
5999 */
6000 static int
6001valid_filetype(char_u *val)
6002{
6003 char_u *s;
6004
6005 for (s = val; *s != NUL; ++s)
6006 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6007 return FALSE;
6008 return TRUE;
6009}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006010#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006011
6012/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006013 * Handle string options that need some action to perform when changed.
6014 * Returns NULL for success, or an error message for an error.
6015 */
6016 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006017did_set_string_option(
6018 int opt_idx, /* index in options[] table */
6019 char_u **varp, /* pointer to the option variable */
6020 int new_value_alloced, /* new value was allocated */
6021 char_u *oldval, /* previous value of the option */
6022 char_u *errbuf, /* buffer for errors, or NULL */
6023 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006024{
6025 char_u *errmsg = NULL;
6026 char_u *s, *p;
6027 int did_chartab = FALSE;
6028 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006029 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006030#ifdef FEAT_GUI
6031 /* set when changing an option that only requires a redraw in the GUI */
6032 int redraw_gui_only = FALSE;
6033#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006034#ifdef FEAT_AUTOCMD
6035 int ft_changed = FALSE;
6036#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037
6038 /* Get the global option to compare with, otherwise we would have to check
6039 * two values for all local options. */
6040 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6041
6042 /* Disallow changing some options from secure mode */
6043 if ((secure
6044#ifdef HAVE_SANDBOX
6045 || sandbox != 0
6046#endif
6047 ) && (options[opt_idx].flags & P_SECURE))
6048 {
6049 errmsg = e_secure;
6050 }
6051
Bram Moolenaar7554da42016-11-25 22:04:13 +01006052 /* Check for a "normal" directory or file name in some options. Disallow a
6053 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006054 * are often illegal in a file name. Be more permissive if "secure" is off.
6055 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006056 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006057 && vim_strpbrk(*varp, (char_u *)(secure
6058 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006059 || ((options[opt_idx].flags & P_NDNAME)
6060 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006061 {
6062 errmsg = e_invarg;
6063 }
6064
Bram Moolenaar071d4272004-06-13 20:20:40 +00006065 /* 'term' */
6066 else if (varp == &T_NAME)
6067 {
6068 if (T_NAME[0] == NUL)
6069 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6070#ifdef FEAT_GUI
6071 if (gui.in_use)
6072 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6073 else if (term_is_gui(T_NAME))
6074 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6075#endif
6076 else if (set_termname(T_NAME) == FAIL)
6077 errmsg = (char_u *)N_("E522: Not found in termcap");
6078 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006079 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006080 /* Screen colors may have changed. */
6081 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006082
6083 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6084 * P_ALLOCED flag on 'term'. */
6085 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006086 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006088 }
6089
6090 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006091 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006092 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006093 char_u *bkc = p_bkc;
6094 unsigned int *flags = &bkc_flags;
6095
6096 if (opt_flags & OPT_LOCAL)
6097 {
6098 bkc = curbuf->b_p_bkc;
6099 flags = &curbuf->b_bkc_flags;
6100 }
6101
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006102 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6103 /* make the local value empty: use the global value */
6104 *flags = 0;
6105 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006106 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006107 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6108 errmsg = e_invarg;
6109 if ((((int)*flags & BKC_AUTO) != 0)
6110 + (((int)*flags & BKC_YES) != 0)
6111 + (((int)*flags & BKC_NO) != 0) != 1)
6112 {
6113 /* Must have exactly one of "auto", "yes" and "no". */
6114 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6115 errmsg = e_invarg;
6116 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 }
6118 }
6119
6120 /* 'backupext' and 'patchmode' */
6121 else if (varp == &p_bex || varp == &p_pm)
6122 {
6123 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6124 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6125 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6126 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006127#ifdef FEAT_LINEBREAK
6128 /* 'breakindentopt' */
6129 else if (varp == &curwin->w_p_briopt)
6130 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006131 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006132 errmsg = e_invarg;
6133 }
6134#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006135
6136 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006137 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006139 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006140 */
6141 else if ( varp == &p_isi
6142 || varp == &(curbuf->b_p_isk)
6143 || varp == &p_isp
6144 || varp == &p_isf)
6145 {
6146 if (init_chartab() == FAIL)
6147 {
6148 did_chartab = TRUE; /* need to restore it below */
6149 errmsg = e_invarg; /* error in value */
6150 }
6151 }
6152
6153 /* 'helpfile' */
6154 else if (varp == &p_hf)
6155 {
6156 /* May compute new values for $VIM and $VIMRUNTIME */
6157 if (didset_vim)
6158 {
6159 vim_setenv((char_u *)"VIM", (char_u *)"");
6160 didset_vim = FALSE;
6161 }
6162 if (didset_vimruntime)
6163 {
6164 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6165 didset_vimruntime = FALSE;
6166 }
6167 }
6168
Bram Moolenaar1a384422010-07-14 19:53:30 +02006169#ifdef FEAT_SYN_HL
6170 /* 'colorcolumn' */
6171 else if (varp == &curwin->w_p_cc)
6172 errmsg = check_colorcolumn(curwin);
6173#endif
6174
Bram Moolenaar071d4272004-06-13 20:20:40 +00006175#ifdef FEAT_MULTI_LANG
6176 /* 'helplang' */
6177 else if (varp == &p_hlg)
6178 {
6179 /* Check for "", "ab", "ab,cd", etc. */
6180 for (s = p_hlg; *s != NUL; s += 3)
6181 {
6182 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6183 {
6184 errmsg = e_invarg;
6185 break;
6186 }
6187 if (s[2] == NUL)
6188 break;
6189 }
6190 }
6191#endif
6192
6193 /* 'highlight' */
6194 else if (varp == &p_hl)
6195 {
6196 if (highlight_changed() == FAIL)
6197 errmsg = e_invarg; /* invalid flags */
6198 }
6199
6200 /* 'nrformats' */
6201 else if (gvarp == &p_nf)
6202 {
6203 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6204 errmsg = e_invarg;
6205 }
6206
6207#ifdef FEAT_SESSION
6208 /* 'sessionoptions' */
6209 else if (varp == &p_ssop)
6210 {
6211 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6212 errmsg = e_invarg;
6213 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6214 {
6215 /* Don't allow both "sesdir" and "curdir". */
6216 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6217 errmsg = e_invarg;
6218 }
6219 }
6220 /* 'viewoptions' */
6221 else if (varp == &p_vop)
6222 {
6223 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6224 errmsg = e_invarg;
6225 }
6226#endif
6227
6228 /* 'scrollopt' */
6229#ifdef FEAT_SCROLLBIND
6230 else if (varp == &p_sbo)
6231 {
6232 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6233 errmsg = e_invarg;
6234 }
6235#endif
6236
6237 /* 'ambiwidth' */
6238#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006239 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240 {
6241 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6242 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006243 else if (set_chars_option(&p_lcs) != NULL)
6244 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006245 else if (set_chars_option(&p_fcs) != NULL)
6246 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006247 }
6248#endif
6249
6250 /* 'background' */
6251 else if (varp == &p_bg)
6252 {
6253 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6254 {
6255#ifdef FEAT_EVAL
6256 int dark = (*p_bg == 'd');
6257#endif
6258
6259 init_highlight(FALSE, FALSE);
6260
6261#ifdef FEAT_EVAL
6262 if (dark != (*p_bg == 'd')
6263 && get_var_value((char_u *)"g:colors_name") != NULL)
6264 {
6265 /* The color scheme must have set 'background' back to another
6266 * value, that's not what we want here. Disable the color
6267 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006268 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006269 free_string_option(p_bg);
6270 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6271 check_string_option(&p_bg);
6272 init_highlight(FALSE, FALSE);
6273 }
6274#endif
6275 }
6276 else
6277 errmsg = e_invarg;
6278 }
6279
6280 /* 'wildmode' */
6281 else if (varp == &p_wim)
6282 {
6283 if (check_opt_wim() == FAIL)
6284 errmsg = e_invarg;
6285 }
6286
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006287#ifdef FEAT_CMDL_COMPL
6288 /* 'wildoptions' */
6289 else if (varp == &p_wop)
6290 {
6291 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6292 errmsg = e_invarg;
6293 }
6294#endif
6295
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296#ifdef FEAT_WAK
6297 /* 'winaltkeys' */
6298 else if (varp == &p_wak)
6299 {
6300 if (*p_wak == NUL
6301 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6302 errmsg = e_invarg;
6303# ifdef FEAT_MENU
6304# ifdef FEAT_GUI_MOTIF
6305 else if (gui.in_use)
6306 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6307# else
6308# ifdef FEAT_GUI_GTK
6309 else if (gui.in_use)
6310 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6311# endif
6312# endif
6313# endif
6314 }
6315#endif
6316
6317#ifdef FEAT_AUTOCMD
6318 /* 'eventignore' */
6319 else if (varp == &p_ei)
6320 {
6321 if (check_ei() == FAIL)
6322 errmsg = e_invarg;
6323 }
6324#endif
6325
6326#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006327 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6328 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6329 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006330 {
6331 if (gvarp == &p_fenc)
6332 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006333 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334 errmsg = e_modifiable;
6335 else if (vim_strchr(*varp, ',') != NULL)
6336 /* No comma allowed in 'fileencoding'; catches confusing it
6337 * with 'fileencodings'. */
6338 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006340 {
6341# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006343 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006345 /* Add 'fileencoding' to the swap file. */
6346 ml_setflags(curbuf);
6347 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348 }
6349 if (errmsg == NULL)
6350 {
6351 /* canonize the value, so that STRCMP() can be used on it */
6352 p = enc_canonize(*varp);
6353 if (p != NULL)
6354 {
6355 vim_free(*varp);
6356 *varp = p;
6357 }
6358 if (varp == &p_enc)
6359 {
6360 errmsg = mb_init();
6361# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006362 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363# endif
6364 }
6365 }
6366
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006367# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006368 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6369 {
6370 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6371 if (STRCMP(p_tenc, "utf-8") != 0)
6372 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6373 }
6374# endif
6375
6376 if (errmsg == NULL)
6377 {
6378# ifdef FEAT_KEYMAP
6379 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6380 * (with another encoding). */
6381 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6382 (void)keymap_init();
6383# endif
6384
6385 /* When 'termencoding' is not empty and 'encoding' changes or when
6386 * 'termencoding' changes, need to setup for keyboard input and
6387 * display output conversion. */
6388 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6389 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006390 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6391 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6392 {
6393 EMSG3(_("E950: Cannot convert between %s and %s"),
6394 p_tenc, p_enc);
6395 errmsg = e_invarg;
6396 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006397 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006398
6399# if defined(WIN3264) && defined(FEAT_MBYTE)
6400 /* $HOME may have characters in active code page. */
6401 if (varp == &p_enc)
6402 init_homedir();
6403# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006404 }
6405 }
6406#endif
6407
6408#if defined(FEAT_POSTSCRIPT)
6409 else if (varp == &p_penc)
6410 {
6411 /* Canonize printencoding if VIM standard one */
6412 p = enc_canonize(p_penc);
6413 if (p != NULL)
6414 {
6415 vim_free(p_penc);
6416 p_penc = p;
6417 }
6418 else
6419 {
6420 /* Ensure lower case and '-' for '_' */
6421 for (s = p_penc; *s != NUL; s++)
6422 {
6423 if (*s == '_')
6424 *s = '-';
6425 else
6426 *s = TOLOWER_ASC(*s);
6427 }
6428 }
6429 }
6430#endif
6431
Bram Moolenaar9372a112005-12-06 19:59:18 +00006432#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006433 else if (varp == &p_imak)
6434 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006435 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006436 errmsg = e_invarg;
6437 }
6438#endif
6439
6440#ifdef FEAT_KEYMAP
6441 else if (varp == &curbuf->b_p_keymap)
6442 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006443 if (!valid_filetype(*varp))
6444 errmsg = e_invarg;
6445 else
6446 /* load or unload key mapping tables */
6447 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006448
Bram Moolenaarfab06232009-03-04 03:13:35 +00006449 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006450 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006451 if (*curbuf->b_p_keymap != NUL)
6452 {
6453 /* Installed a new keymap, switch on using it. */
6454 curbuf->b_p_iminsert = B_IMODE_LMAP;
6455 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6456 curbuf->b_p_imsearch = B_IMODE_LMAP;
6457 }
6458 else
6459 {
6460 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6461 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6462 curbuf->b_p_iminsert = B_IMODE_NONE;
6463 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6464 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6465 }
6466 if ((opt_flags & OPT_LOCAL) == 0)
6467 {
6468 set_iminsert_global();
6469 set_imsearch_global();
6470 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006471 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006472 }
6473 }
6474#endif
6475
6476 /* 'fileformat' */
6477 else if (gvarp == &p_ff)
6478 {
6479 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6480 errmsg = e_modifiable;
6481 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6482 errmsg = e_invarg;
6483 else
6484 {
6485 /* may also change 'textmode' */
6486 if (get_fileformat(curbuf) == EOL_DOS)
6487 curbuf->b_p_tx = TRUE;
6488 else
6489 curbuf->b_p_tx = FALSE;
6490#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006491 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006493 /* update flag in swap file */
6494 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006495 /* Redraw needed when switching to/from "mac": a CR in the text
6496 * will be displayed differently. */
6497 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6498 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006499 }
6500 }
6501
6502 /* 'fileformats' */
6503 else if (varp == &p_ffs)
6504 {
6505 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6506 errmsg = e_invarg;
6507 else
6508 {
6509 /* also change 'textauto' */
6510 if (*p_ffs == NUL)
6511 p_ta = FALSE;
6512 else
6513 p_ta = TRUE;
6514 }
6515 }
6516
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006517#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 /* 'cryptkey' */
6519 else if (gvarp == &p_key)
6520 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006521# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 /* Make sure the ":set" command doesn't show the new value in the
6523 * history. */
6524 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006525# endif
6526 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6527 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006528 ml_set_crypt_key(curbuf, oldval,
6529 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006530 }
6531
6532 else if (gvarp == &p_cm)
6533 {
6534 if (opt_flags & OPT_LOCAL)
6535 p = curbuf->b_p_cm;
6536 else
6537 p = p_cm;
6538 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6539 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006540 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006541 errmsg = e_invarg;
6542 else
6543 {
6544 /* When setting the global value to empty, make it "zip". */
6545 if (*p_cm == NUL)
6546 {
6547 if (new_value_alloced)
6548 free_string_option(p_cm);
6549 p_cm = vim_strsave((char_u *)"zip");
6550 new_value_alloced = TRUE;
6551 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006552 /* When using ":set cm=name" the local value is going to be empty.
6553 * Do that here, otherwise the crypt functions will still use the
6554 * local value. */
6555 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6556 {
6557 free_string_option(curbuf->b_p_cm);
6558 curbuf->b_p_cm = empty_option;
6559 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006560
6561 /* Need to update the swapfile when the effective method changed.
6562 * Set "s" to the effective old value, "p" to the effective new
6563 * method and compare. */
6564 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6565 s = p_cm; /* was previously using the global value */
6566 else
6567 s = oldval;
6568 if (*curbuf->b_p_cm == NUL)
6569 p = p_cm; /* is now using the global value */
6570 else
6571 p = curbuf->b_p_cm;
6572 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006573 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006574
6575 /* If the global value changes need to update the swapfile for all
6576 * buffers using that value. */
6577 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6578 {
6579 buf_T *buf;
6580
Bram Moolenaar29323592016-07-24 22:04:11 +02006581 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006582 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006583 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006584 }
6585 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006586 }
6587#endif
6588
6589 /* 'matchpairs' */
6590 else if (gvarp == &p_mps)
6591 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006592#ifdef FEAT_MBYTE
6593 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006594 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006595 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006596 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006597 int x2 = -1;
6598 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006599
6600 if (*p != NUL)
6601 p += mb_ptr2len(p);
6602 if (*p != NUL)
6603 x2 = *p++;
6604 if (*p != NUL)
6605 {
6606 x3 = mb_ptr2char(p);
6607 p += mb_ptr2len(p);
6608 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006609 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006610 {
6611 errmsg = e_invarg;
6612 break;
6613 }
6614 if (*p == NUL)
6615 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006616 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006617 }
6618 else
6619#endif
6620 {
6621 /* Check for "x:y,x:y" */
6622 for (p = *varp; *p != NUL; p += 4)
6623 {
6624 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6625 {
6626 errmsg = e_invarg;
6627 break;
6628 }
6629 if (p[3] == NUL)
6630 break;
6631 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006632 }
6633 }
6634
6635#ifdef FEAT_COMMENTS
6636 /* 'comments' */
6637 else if (gvarp == &p_com)
6638 {
6639 for (s = *varp; *s; )
6640 {
6641 while (*s && *s != ':')
6642 {
6643 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6644 && !VIM_ISDIGIT(*s) && *s != '-')
6645 {
6646 errmsg = illegal_char(errbuf, *s);
6647 break;
6648 }
6649 ++s;
6650 }
6651 if (*s++ == NUL)
6652 errmsg = (char_u *)N_("E524: Missing colon");
6653 else if (*s == ',' || *s == NUL)
6654 errmsg = (char_u *)N_("E525: Zero length string");
6655 if (errmsg != NULL)
6656 break;
6657 while (*s && *s != ',')
6658 {
6659 if (*s == '\\' && s[1] != NUL)
6660 ++s;
6661 ++s;
6662 }
6663 s = skip_to_option_part(s);
6664 }
6665 }
6666#endif
6667
6668 /* 'listchars' */
6669 else if (varp == &p_lcs)
6670 {
6671 errmsg = set_chars_option(varp);
6672 }
6673
Bram Moolenaar071d4272004-06-13 20:20:40 +00006674 /* 'fillchars' */
6675 else if (varp == &p_fcs)
6676 {
6677 errmsg = set_chars_option(varp);
6678 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006679
6680#ifdef FEAT_CMDWIN
6681 /* 'cedit' */
6682 else if (varp == &p_cedit)
6683 {
6684 errmsg = check_cedit();
6685 }
6686#endif
6687
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006688 /* 'verbosefile' */
6689 else if (varp == &p_vfile)
6690 {
6691 verbose_stop();
6692 if (*p_vfile != NUL && verbose_open() == FAIL)
6693 errmsg = e_invarg;
6694 }
6695
Bram Moolenaar071d4272004-06-13 20:20:40 +00006696#ifdef FEAT_VIMINFO
6697 /* 'viminfo' */
6698 else if (varp == &p_viminfo)
6699 {
6700 for (s = p_viminfo; *s;)
6701 {
6702 /* Check it's a valid character */
6703 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6704 {
6705 errmsg = illegal_char(errbuf, *s);
6706 break;
6707 }
6708 if (*s == 'n') /* name is always last one */
6709 {
6710 break;
6711 }
6712 else if (*s == 'r') /* skip until next ',' */
6713 {
6714 while (*++s && *s != ',')
6715 ;
6716 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006717 else if (*s == '%')
6718 {
6719 /* optional number */
6720 while (vim_isdigit(*++s))
6721 ;
6722 }
6723 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006724 ++s; /* no extra chars */
6725 else /* must have a number */
6726 {
6727 while (vim_isdigit(*++s))
6728 ;
6729
6730 if (!VIM_ISDIGIT(*(s - 1)))
6731 {
6732 if (errbuf != NULL)
6733 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006734 sprintf((char *)errbuf,
6735 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006736 transchar_byte(*(s - 1)));
6737 errmsg = errbuf;
6738 }
6739 else
6740 errmsg = (char_u *)"";
6741 break;
6742 }
6743 }
6744 if (*s == ',')
6745 ++s;
6746 else if (*s)
6747 {
6748 if (errbuf != NULL)
6749 errmsg = (char_u *)N_("E527: Missing comma");
6750 else
6751 errmsg = (char_u *)"";
6752 break;
6753 }
6754 }
6755 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6756 errmsg = (char_u *)N_("E528: Must specify a ' value");
6757 }
6758#endif /* FEAT_VIMINFO */
6759
6760 /* terminal options */
6761 else if (istermoption(&options[opt_idx]) && full_screen)
6762 {
6763 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6764 if (varp == &T_CCO)
6765 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006766 int colors = atoi((char *)T_CCO);
6767
6768 /* Only reinitialize colors if t_Co value has really changed to
6769 * avoid expensive reload of colorscheme if t_Co is set to the
6770 * same value multiple times. */
6771 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006773 t_colors = colors;
6774 if (t_colors <= 1)
6775 {
6776 if (new_value_alloced)
6777 vim_free(T_CCO);
6778 T_CCO = empty_option;
6779 }
6780 /* We now have a different color setup, initialize it again. */
6781 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006782 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 }
6784 ttest(FALSE);
6785 if (varp == &T_ME)
6786 {
6787 out_str(T_ME);
6788 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006789#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 /* Since t_me has been set, this probably means that the user
6791 * wants to use this as default colors. Need to reset default
6792 * background/foreground colors. */
6793 mch_set_normal_colors();
6794#endif
6795 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006796 if (varp == &T_BE && termcap_active)
6797 {
6798 if (*T_BE == NUL)
6799 /* When clearing t_BE we assume the user no longer wants
6800 * bracketed paste, thus disable it by writing t_BD. */
6801 out_str(T_BD);
6802 else
6803 out_str(T_BE);
6804 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006805 }
6806
6807#ifdef FEAT_LINEBREAK
6808 /* 'showbreak' */
6809 else if (varp == &p_sbr)
6810 {
6811 for (s = p_sbr; *s; )
6812 {
6813 if (ptr2cells(s) != 1)
6814 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006815 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816 }
6817 }
6818#endif
6819
6820#ifdef FEAT_GUI
6821 /* 'guifont' */
6822 else if (varp == &p_guifont)
6823 {
6824 if (gui.in_use)
6825 {
6826 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006827# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 /*
6829 * Put up a font dialog and let the user select a new value.
6830 * If this is cancelled go back to the old value but don't
6831 * give an error message.
6832 */
6833 if (STRCMP(p, "*") == 0)
6834 {
6835 p = gui_mch_font_dialog(oldval);
6836
6837 if (new_value_alloced)
6838 free_string_option(p_guifont);
6839
6840 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6841 new_value_alloced = TRUE;
6842 }
6843# endif
6844 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6845 {
6846# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6847 if (STRCMP(p_guifont, "*") == 0)
6848 {
6849 /* Dialog was cancelled: Keep the old value without giving
6850 * an error message. */
6851 if (new_value_alloced)
6852 free_string_option(p_guifont);
6853 p_guifont = vim_strsave(oldval);
6854 new_value_alloced = TRUE;
6855 }
6856 else
6857# endif
6858 errmsg = (char_u *)N_("E596: Invalid font(s)");
6859 }
6860 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006861 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006862 }
6863# ifdef FEAT_XFONTSET
6864 else if (varp == &p_guifontset)
6865 {
6866 if (STRCMP(p_guifontset, "*") == 0)
6867 errmsg = (char_u *)N_("E597: can't select fontset");
6868 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6869 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006870 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871 }
6872# endif
6873# ifdef FEAT_MBYTE
6874 else if (varp == &p_guifontwide)
6875 {
6876 if (STRCMP(p_guifontwide, "*") == 0)
6877 errmsg = (char_u *)N_("E533: can't select wide font");
6878 else if (gui_get_wide_font() == FAIL)
6879 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006880 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881 }
6882# endif
6883#endif
6884
6885#ifdef CURSOR_SHAPE
6886 /* 'guicursor' */
6887 else if (varp == &p_guicursor)
6888 errmsg = parse_shape_opt(SHAPE_CURSOR);
6889#endif
6890
6891#ifdef FEAT_MOUSESHAPE
6892 /* 'mouseshape' */
6893 else if (varp == &p_mouseshape)
6894 {
6895 errmsg = parse_shape_opt(SHAPE_MOUSE);
6896 update_mouseshape(-1);
6897 }
6898#endif
6899
6900#ifdef FEAT_PRINTER
6901 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006902 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006903# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006904 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006905 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006906# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006907#endif
6908
6909#ifdef FEAT_LANGMAP
6910 /* 'langmap' */
6911 else if (varp == &p_langmap)
6912 langmap_set();
6913#endif
6914
6915#ifdef FEAT_LINEBREAK
6916 /* 'breakat' */
6917 else if (varp == &p_breakat)
6918 fill_breakat_flags();
6919#endif
6920
6921#ifdef FEAT_TITLE
6922 /* 'titlestring' and 'iconstring' */
6923 else if (varp == &p_titlestring || varp == &p_iconstring)
6924 {
6925# ifdef FEAT_STL_OPT
6926 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6927
6928 /* NULL => statusline syntax */
6929 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6930 stl_syntax |= flagval;
6931 else
6932 stl_syntax &= ~flagval;
6933# endif
6934 did_set_title(varp == &p_iconstring);
6935
6936 }
6937#endif
6938
6939#ifdef FEAT_GUI
6940 /* 'guioptions' */
6941 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006942 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006944 redraw_gui_only = TRUE;
6945 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946#endif
6947
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006948#if defined(FEAT_GUI_TABLINE)
6949 /* 'guitablabel' */
6950 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006951 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006952 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006953 redraw_gui_only = TRUE;
6954 }
6955 /* 'guitabtooltip' */
6956 else if (varp == &p_gtt)
6957 {
6958 redraw_gui_only = TRUE;
6959 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006960#endif
6961
Bram Moolenaar071d4272004-06-13 20:20:40 +00006962#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6963 /* 'ttymouse' */
6964 else if (varp == &p_ttym)
6965 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006966 /* Switch the mouse off before changing the escape sequences used for
6967 * that. */
6968 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006969 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6970 errmsg = e_invarg;
6971 else
6972 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006973 if (termcap_active)
6974 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006975 }
6976#endif
6977
Bram Moolenaar071d4272004-06-13 20:20:40 +00006978 /* 'selection' */
6979 else if (varp == &p_sel)
6980 {
6981 if (*p_sel == NUL
6982 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6983 errmsg = e_invarg;
6984 }
6985
6986 /* 'selectmode' */
6987 else if (varp == &p_slm)
6988 {
6989 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6990 errmsg = e_invarg;
6991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992
6993#ifdef FEAT_BROWSE
6994 /* 'browsedir' */
6995 else if (varp == &p_bsdir)
6996 {
6997 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6998 && !mch_isdir(p_bsdir))
6999 errmsg = e_invarg;
7000 }
7001#endif
7002
Bram Moolenaar071d4272004-06-13 20:20:40 +00007003 /* 'keymodel' */
7004 else if (varp == &p_km)
7005 {
7006 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7007 errmsg = e_invarg;
7008 else
7009 {
7010 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7011 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7012 }
7013 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014
7015 /* 'mousemodel' */
7016 else if (varp == &p_mousem)
7017 {
7018 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7019 errmsg = e_invarg;
7020#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7021 else if (*p_mousem != *oldval)
7022 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7023 * to create or delete the popup menus. */
7024 gui_motif_update_mousemodel(root_menu);
7025#endif
7026 }
7027
7028 /* 'switchbuf' */
7029 else if (varp == &p_swb)
7030 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007031 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007032 errmsg = e_invarg;
7033 }
7034
7035 /* 'debug' */
7036 else if (varp == &p_debug)
7037 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007038 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007039 errmsg = e_invarg;
7040 }
7041
7042 /* 'display' */
7043 else if (varp == &p_dy)
7044 {
7045 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7046 errmsg = e_invarg;
7047 else
7048 (void)init_chartab();
7049
7050 }
7051
Bram Moolenaar071d4272004-06-13 20:20:40 +00007052 /* 'eadirection' */
7053 else if (varp == &p_ead)
7054 {
7055 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7056 errmsg = e_invarg;
7057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007058
7059#ifdef FEAT_CLIPBOARD
7060 /* 'clipboard' */
7061 else if (varp == &p_cb)
7062 errmsg = check_clipboard_option();
7063#endif
7064
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007065#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007066 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7067 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007068 else if (varp == &(curwin->w_s->b_p_spl)
7069 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007070 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007071 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007072 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007073 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007074 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007075 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007076 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007077 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007078 /* 'spellsuggest' */
7079 else if (varp == &p_sps)
7080 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007081 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007082 errmsg = e_invarg;
7083 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007084 /* 'mkspellmem' */
7085 else if (varp == &p_msm)
7086 {
7087 if (spell_check_msm() != OK)
7088 errmsg = e_invarg;
7089 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007090#endif
7091
Bram Moolenaar071d4272004-06-13 20:20:40 +00007092 /* When 'bufhidden' is set, check for valid value. */
7093 else if (gvarp == &p_bh)
7094 {
7095 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7096 errmsg = e_invarg;
7097 }
7098
7099 /* When 'buftype' is set, check for valid value. */
7100 else if (gvarp == &p_bt)
7101 {
7102 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7103 errmsg = e_invarg;
7104 else
7105 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 if (curwin->w_status_height)
7107 {
7108 curwin->w_redr_status = TRUE;
7109 redraw_later(VALID);
7110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007112#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007113 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007114#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007115 }
7116 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007117
7118#ifdef FEAT_STL_OPT
7119 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007120 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121 {
7122 int wid;
7123
7124 if (varp == &p_ruf) /* reset ru_wid first */
7125 ru_wid = 0;
7126 s = *varp;
7127 if (varp == &p_ruf && *s == '%')
7128 {
7129 /* set ru_wid if 'ruf' starts with "%99(" */
7130 if (*++s == '-') /* ignore a '-' */
7131 s++;
7132 wid = getdigits(&s);
7133 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7134 ru_wid = wid;
7135 else
7136 errmsg = check_stl_option(p_ruf);
7137 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007138 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007139 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007140 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007141 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007142 comp_col();
7143 }
7144#endif
7145
7146#ifdef FEAT_INS_EXPAND
7147 /* check if it is a valid value for 'complete' -- Acevedo */
7148 else if (gvarp == &p_cpt)
7149 {
7150 for (s = *varp; *s;)
7151 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007152 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007153 s++;
7154 if (!*s)
7155 break;
7156 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7157 {
7158 errmsg = illegal_char(errbuf, *s);
7159 break;
7160 }
7161 if (*++s != NUL && *s != ',' && *s != ' ')
7162 {
7163 if (s[-1] == 'k' || s[-1] == 's')
7164 {
7165 /* skip optional filename after 'k' and 's' */
7166 while (*s && *s != ',' && *s != ' ')
7167 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007168 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007169 ++s;
7170 ++s;
7171 }
7172 }
7173 else
7174 {
7175 if (errbuf != NULL)
7176 {
7177 sprintf((char *)errbuf,
7178 _("E535: Illegal character after <%c>"),
7179 *--s);
7180 errmsg = errbuf;
7181 }
7182 else
7183 errmsg = (char_u *)"";
7184 break;
7185 }
7186 }
7187 }
7188 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007189
7190 /* 'completeopt' */
7191 else if (varp == &p_cot)
7192 {
7193 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7194 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007195 else
7196 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007197 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198#endif /* FEAT_INS_EXPAND */
7199
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007200#ifdef FEAT_SIGNS
7201 /* 'signcolumn' */
7202 else if (varp == &curwin->w_p_scl)
7203 {
7204 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7205 errmsg = e_invarg;
7206 }
7207#endif
7208
Bram Moolenaar071d4272004-06-13 20:20:40 +00007209
7210#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007211 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007212 else if (varp == &p_toolbar)
7213 {
7214 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7215 &toolbar_flags, TRUE) != OK)
7216 errmsg = e_invarg;
7217 else
7218 {
7219 out_flush();
7220 gui_mch_show_toolbar((toolbar_flags &
7221 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7222 }
7223 }
7224#endif
7225
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007226#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227 /* 'toolbariconsize': GTK+ 2 only */
7228 else if (varp == &p_tbis)
7229 {
7230 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7231 errmsg = e_invarg;
7232 else
7233 {
7234 out_flush();
7235 gui_mch_show_toolbar((toolbar_flags &
7236 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7237 }
7238 }
7239#endif
7240
7241 /* 'pastetoggle': translate key codes like in a mapping */
7242 else if (varp == &p_pt)
7243 {
7244 if (*p_pt)
7245 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007246 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247 if (p != NULL)
7248 {
7249 if (new_value_alloced)
7250 free_string_option(p_pt);
7251 p_pt = p;
7252 new_value_alloced = TRUE;
7253 }
7254 }
7255 }
7256
7257 /* 'backspace' */
7258 else if (varp == &p_bs)
7259 {
7260 if (VIM_ISDIGIT(*p_bs))
7261 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007262 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007263 errmsg = e_invarg;
7264 }
7265 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7266 errmsg = e_invarg;
7267 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007268 else if (varp == &p_bo)
7269 {
7270 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7271 errmsg = e_invarg;
7272 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007273
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007274 /* 'tagcase' */
7275 else if (gvarp == &p_tc)
7276 {
7277 unsigned int *flags;
7278
7279 if (opt_flags & OPT_LOCAL)
7280 {
7281 p = curbuf->b_p_tc;
7282 flags = &curbuf->b_tc_flags;
7283 }
7284 else
7285 {
7286 p = p_tc;
7287 flags = &tc_flags;
7288 }
7289
7290 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7291 /* make the local value empty: use the global value */
7292 *flags = 0;
7293 else if (*p == NUL
7294 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7295 errmsg = e_invarg;
7296 }
7297
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007298#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007299 /* 'casemap' */
7300 else if (varp == &p_cmp)
7301 {
7302 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7303 errmsg = e_invarg;
7304 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007306
7307#ifdef FEAT_DIFF
7308 /* 'diffopt' */
7309 else if (varp == &p_dip)
7310 {
7311 if (diffopt_changed() == FAIL)
7312 errmsg = e_invarg;
7313 }
7314#endif
7315
7316#ifdef FEAT_FOLDING
7317 /* 'foldmethod' */
7318 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7319 {
7320 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7321 || *curwin->w_p_fdm == NUL)
7322 errmsg = e_invarg;
7323 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007324 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007325 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007326 if (foldmethodIsDiff(curwin))
7327 newFoldLevel();
7328 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007329 }
7330# ifdef FEAT_EVAL
7331 /* 'foldexpr' */
7332 else if (varp == &curwin->w_p_fde)
7333 {
7334 if (foldmethodIsExpr(curwin))
7335 foldUpdateAll(curwin);
7336 }
7337# endif
7338 /* 'foldmarker' */
7339 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7340 {
7341 p = vim_strchr(*varp, ',');
7342 if (p == NULL)
7343 errmsg = (char_u *)N_("E536: comma required");
7344 else if (p == *varp || p[1] == NUL)
7345 errmsg = e_invarg;
7346 else if (foldmethodIsMarker(curwin))
7347 foldUpdateAll(curwin);
7348 }
7349 /* 'commentstring' */
7350 else if (gvarp == &p_cms)
7351 {
7352 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7353 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7354 }
7355 /* 'foldopen' */
7356 else if (varp == &p_fdo)
7357 {
7358 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7359 errmsg = e_invarg;
7360 }
7361 /* 'foldclose' */
7362 else if (varp == &p_fcl)
7363 {
7364 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7365 errmsg = e_invarg;
7366 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007367 /* 'foldignore' */
7368 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7369 {
7370 if (foldmethodIsIndent(curwin))
7371 foldUpdateAll(curwin);
7372 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007373#endif
7374
7375#ifdef FEAT_VIRTUALEDIT
7376 /* 'virtualedit' */
7377 else if (varp == &p_ve)
7378 {
7379 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7380 errmsg = e_invarg;
7381 else if (STRCMP(p_ve, oldval) != 0)
7382 {
7383 /* Recompute cursor position in case the new 've' setting
7384 * changes something. */
7385 validate_virtcol();
7386 coladvance(curwin->w_virtcol);
7387 }
7388 }
7389#endif
7390
7391#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7392 else if (varp == &p_csqf)
7393 {
7394 if (p_csqf != NULL)
7395 {
7396 p = p_csqf;
7397 while (*p != NUL)
7398 {
7399 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7400 || p[1] == NUL
7401 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7402 || (p[2] != NUL && p[2] != ','))
7403 {
7404 errmsg = e_invarg;
7405 break;
7406 }
7407 else if (p[2] == NUL)
7408 break;
7409 else
7410 p += 3;
7411 }
7412 }
7413 }
7414#endif
7415
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007416#ifdef FEAT_CINDENT
7417 /* 'cinoptions' */
7418 else if (gvarp == &p_cino)
7419 {
7420 /* TODO: recognize errors */
7421 parse_cino(curbuf);
7422 }
7423#endif
7424
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007425#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007426 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007427 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007428 {
7429 if (!gui_mch_set_rendering_options(p_rop))
7430 errmsg = e_invarg;
7431 }
7432#endif
7433
Bram Moolenaard0b51382016-11-04 15:23:45 +01007434#ifdef FEAT_AUTOCMD
7435 else if (gvarp == &p_ft)
7436 {
7437 if (!valid_filetype(*varp))
7438 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007439 else
7440 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007441 }
7442#endif
7443
7444#ifdef FEAT_SYN_HL
7445 else if (gvarp == &p_syn)
7446 {
7447 if (!valid_filetype(*varp))
7448 errmsg = e_invarg;
7449 }
7450#endif
7451
Bram Moolenaar825680f2017-07-22 17:04:02 +02007452#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007453 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007454 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007455 {
7456 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7457 errmsg = e_invarg;
7458 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007459 /* 'termsize' */
7460 else if (varp == &curwin->w_p_tms)
7461 {
7462 if (*curwin->w_p_tms != NUL)
7463 {
7464 p = skipdigits(curwin->w_p_tms);
7465 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7466 errmsg = e_invarg;
7467 }
7468 }
7469#endif
7470
Bram Moolenaar071d4272004-06-13 20:20:40 +00007471 /* Options that are a list of flags. */
7472 else
7473 {
7474 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007475 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007476 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007477 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007478 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007479 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007480 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007481 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007483#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007484 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007485 p = (char_u *)COCU_ALL;
7486#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007487 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488 {
7489#ifdef FEAT_MOUSE
7490 p = (char_u *)MOUSE_ALL;
7491#else
7492 if (*p_mouse != NUL)
7493 errmsg = (char_u *)N_("E538: No mouse support");
7494#endif
7495 }
7496#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007497 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 p = (char_u *)GO_ALL;
7499#endif
7500 if (p != NULL)
7501 {
7502 for (s = *varp; *s; ++s)
7503 if (vim_strchr(p, *s) == NULL)
7504 {
7505 errmsg = illegal_char(errbuf, *s);
7506 break;
7507 }
7508 }
7509 }
7510
7511 /*
7512 * If error detected, restore the previous value.
7513 */
7514 if (errmsg != NULL)
7515 {
7516 if (new_value_alloced)
7517 free_string_option(*varp);
7518 *varp = oldval;
7519 /*
7520 * When resetting some values, need to act on it.
7521 */
7522 if (did_chartab)
7523 (void)init_chartab();
7524 if (varp == &p_hl)
7525 (void)highlight_changed();
7526 }
7527 else
7528 {
7529#ifdef FEAT_EVAL
7530 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007531 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007532#endif
7533 /*
7534 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007535 * Use "free_oldval", because recursiveness may change the flags under
7536 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007537 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007538 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007539 free_string_option(oldval);
7540 if (new_value_alloced)
7541 options[opt_idx].flags |= P_ALLOCED;
7542 else
7543 options[opt_idx].flags &= ~P_ALLOCED;
7544
7545 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007546 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547 {
7548 /* global option with local value set to use global value; free
7549 * the local value and make it empty */
7550 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7551 free_string_option(*(char_u **)p);
7552 *(char_u **)p = empty_option;
7553 }
7554
7555 /* May set global value for local option. */
7556 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7557 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007558
7559#ifdef FEAT_AUTOCMD
7560 /*
7561 * Trigger the autocommand only after setting the flags.
7562 */
7563# ifdef FEAT_SYN_HL
7564 /* When 'syntax' is set, load the syntax of that name */
7565 if (varp == &(curbuf->b_p_syn))
7566 {
7567 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7568 curbuf->b_fname, TRUE, curbuf);
7569 }
7570# endif
7571 else if (varp == &(curbuf->b_p_ft))
7572 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007573 /* 'filetype' is set, trigger the FileType autocommand.
7574 * Skip this when called from a modeline and the filetype was
7575 * already set to this value. */
7576 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7577 {
7578 did_filetype = TRUE;
7579 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007580 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007581 /* Just in case the old "curbuf" is now invalid. */
7582 if (varp != &(curbuf->b_p_ft))
7583 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007584 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007585 }
7586#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007587#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007588 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007589 {
7590 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007591 char_u *q = curwin->w_s->b_p_spl;
7592
7593 /* Skip the first name if it is "cjk". */
7594 if (STRNCMP(q, "cjk,", 4) == 0)
7595 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007596
7597 /*
7598 * Source the spell/LANG.vim in 'runtimepath'.
7599 * They could set 'spellcapcheck' depending on the language.
7600 * Use the first name in 'spelllang' up to '_region' or
7601 * '.encoding'.
7602 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007603 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007604 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7605 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007606 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007607 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007608 }
7609#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007610 }
7611
7612#ifdef FEAT_MOUSE
7613 if (varp == &p_mouse)
7614 {
7615# ifdef FEAT_MOUSE_TTY
7616 if (*p_mouse == NUL)
7617 mch_setmouse(FALSE); /* switch mouse off */
7618 else
7619# endif
7620 setmouse(); /* in case 'mouse' changed */
7621 }
7622#endif
7623
Bram Moolenaar913077c2012-03-28 19:59:04 +02007624 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007625 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007626 curwin->w_set_curswant = TRUE;
7627
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007628#ifdef FEAT_GUI
7629 /* check redraw when it's not a GUI option or the GUI is active. */
7630 if (!redraw_gui_only || gui.in_use)
7631#endif
7632 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007633
7634 return errmsg;
7635}
7636
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007637#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007638/*
7639 * Simple int comparison function for use with qsort()
7640 */
7641 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007642int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007643{
7644 return *(const int *)a - *(const int *)b;
7645}
7646
7647/*
7648 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7649 * Returns error message, NULL if it's OK.
7650 */
7651 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007652check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007653{
7654 char_u *s;
7655 int col;
7656 int count = 0;
7657 int color_cols[256];
7658 int i;
7659 int j = 0;
7660
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007661 if (wp->w_buffer == NULL)
7662 return NULL; /* buffer was closed */
7663
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007664 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007665 {
7666 if (*s == '-' || *s == '+')
7667 {
7668 /* -N and +N: add to 'textwidth' */
7669 col = (*s == '-') ? -1 : 1;
7670 ++s;
7671 if (!VIM_ISDIGIT(*s))
7672 return e_invarg;
7673 col = col * getdigits(&s);
7674 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007675 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007676 col += wp->w_buffer->b_p_tw;
7677 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007678 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007679 }
7680 else if (VIM_ISDIGIT(*s))
7681 col = getdigits(&s);
7682 else
7683 return e_invarg;
7684 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007685skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007686 if (*s == NUL)
7687 break;
7688 if (*s != ',')
7689 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007690 if (*++s == NUL)
7691 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007692 }
7693
7694 vim_free(wp->w_p_cc_cols);
7695 if (count == 0)
7696 wp->w_p_cc_cols = NULL;
7697 else
7698 {
7699 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7700 if (wp->w_p_cc_cols != NULL)
7701 {
7702 /* sort the columns for faster usage on screen redraw inside
7703 * win_line() */
7704 qsort(color_cols, count, sizeof(int), int_cmp);
7705
7706 for (i = 0; i < count; ++i)
7707 /* skip duplicates */
7708 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7709 wp->w_p_cc_cols[j++] = color_cols[i];
7710 wp->w_p_cc_cols[j] = -1; /* end marker */
7711 }
7712 }
7713
7714 return NULL; /* no error */
7715}
7716#endif
7717
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718/*
7719 * Handle setting 'listchars' or 'fillchars'.
7720 * Returns error message, NULL if it's OK.
7721 */
7722 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007723set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724{
7725 int round, i, len, entries;
7726 char_u *p, *s;
7727 int c1, c2 = 0;
7728 struct charstab
7729 {
7730 int *cp;
7731 char *name;
7732 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007733 static struct charstab filltab[] =
7734 {
7735 {&fill_stl, "stl"},
7736 {&fill_stlnc, "stlnc"},
7737 {&fill_vert, "vert"},
7738 {&fill_fold, "fold"},
7739 {&fill_diff, "diff"},
7740 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741 static struct charstab lcstab[] =
7742 {
7743 {&lcs_eol, "eol"},
7744 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007745 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007746 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007747 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 {&lcs_tab2, "tab"},
7749 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007750#ifdef FEAT_CONCEAL
7751 {&lcs_conceal, "conceal"},
7752#else
7753 {NULL, "conceal"},
7754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 };
7756 struct charstab *tab;
7757
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759 {
7760 tab = lcstab;
7761 entries = sizeof(lcstab) / sizeof(struct charstab);
7762 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 else
7764 {
7765 tab = filltab;
7766 entries = sizeof(filltab) / sizeof(struct charstab);
7767 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007768
7769 /* first round: check for valid value, second round: assign values */
7770 for (round = 0; round <= 1; ++round)
7771 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007772 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007773 {
7774 /* After checking that the value is valid: set defaults: space for
7775 * 'fillchars', NUL for 'listchars' */
7776 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007777 if (tab[i].cp != NULL)
7778 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 if (varp == &p_lcs)
7780 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781 else
7782 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007783 }
7784 p = *varp;
7785 while (*p)
7786 {
7787 for (i = 0; i < entries; ++i)
7788 {
7789 len = (int)STRLEN(tab[i].name);
7790 if (STRNCMP(p, tab[i].name, len) == 0
7791 && p[len] == ':'
7792 && p[len + 1] != NUL)
7793 {
7794 s = p + len + 1;
7795#ifdef FEAT_MBYTE
7796 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007797 if (mb_char2cells(c1) > 1)
7798 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799#else
7800 c1 = *s++;
7801#endif
7802 if (tab[i].cp == &lcs_tab2)
7803 {
7804 if (*s == NUL)
7805 continue;
7806#ifdef FEAT_MBYTE
7807 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007808 if (mb_char2cells(c2) > 1)
7809 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810#else
7811 c2 = *s++;
7812#endif
7813 }
7814 if (*s == ',' || *s == NUL)
7815 {
7816 if (round)
7817 {
7818 if (tab[i].cp == &lcs_tab2)
7819 {
7820 lcs_tab1 = c1;
7821 lcs_tab2 = c2;
7822 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007823 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007824 *(tab[i].cp) = c1;
7825
7826 }
7827 p = s;
7828 break;
7829 }
7830 }
7831 }
7832
7833 if (i == entries)
7834 return e_invarg;
7835 if (*p == ',')
7836 ++p;
7837 }
7838 }
7839
7840 return NULL; /* no error */
7841}
7842
7843#ifdef FEAT_STL_OPT
7844/*
7845 * Check validity of options with the 'statusline' format.
7846 * Return error message or NULL.
7847 */
7848 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007849check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850{
7851 int itemcnt = 0;
7852 int groupdepth = 0;
7853 static char_u errbuf[80];
7854
7855 while (*s && itemcnt < STL_MAX_ITEM)
7856 {
7857 /* Check for valid keys after % sequences */
7858 while (*s && *s != '%')
7859 s++;
7860 if (!*s)
7861 break;
7862 s++;
7863 if (*s != '%' && *s != ')')
7864 ++itemcnt;
7865 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7866 {
7867 s++;
7868 continue;
7869 }
7870 if (*s == ')')
7871 {
7872 s++;
7873 if (--groupdepth < 0)
7874 break;
7875 continue;
7876 }
7877 if (*s == '-')
7878 s++;
7879 while (VIM_ISDIGIT(*s))
7880 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007881 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007882 continue;
7883 if (*s == '.')
7884 {
7885 s++;
7886 while (*s && VIM_ISDIGIT(*s))
7887 s++;
7888 }
7889 if (*s == '(')
7890 {
7891 groupdepth++;
7892 continue;
7893 }
7894 if (vim_strchr(STL_ALL, *s) == NULL)
7895 {
7896 return illegal_char(errbuf, *s);
7897 }
7898 if (*s == '{')
7899 {
7900 s++;
7901 while (*s != '}' && *s)
7902 s++;
7903 if (*s != '}')
7904 return (char_u *)N_("E540: Unclosed expression sequence");
7905 }
7906 }
7907 if (itemcnt >= STL_MAX_ITEM)
7908 return (char_u *)N_("E541: too many items");
7909 if (groupdepth != 0)
7910 return (char_u *)N_("E542: unbalanced groups");
7911 return NULL;
7912}
7913#endif
7914
7915#ifdef FEAT_CLIPBOARD
7916/*
7917 * Extract the items in the 'clipboard' option and set global values.
7918 */
7919 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007920check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007922 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007923 int new_autoselect_star = FALSE;
7924 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007926 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 regprog_T *new_exclude_prog = NULL;
7928 char_u *errmsg = NULL;
7929 char_u *p;
7930
7931 for (p = p_cb; *p != NUL; )
7932 {
7933 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7934 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007935 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 p += 7;
7937 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007938 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007939 && (p[11] == ',' || p[11] == NUL))
7940 {
7941 new_unnamed |= CLIP_UNNAMED_PLUS;
7942 p += 11;
7943 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007945 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007947 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007948 p += 10;
7949 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007950 else if (STRNCMP(p, "autoselectplus", 14) == 0
7951 && (p[14] == ',' || p[14] == NUL))
7952 {
7953 new_autoselect_plus = TRUE;
7954 p += 14;
7955 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007957 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 {
7959 new_autoselectml = TRUE;
7960 p += 12;
7961 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007962 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7963 {
7964 new_html = TRUE;
7965 p += 4;
7966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7968 {
7969 p += 8;
7970 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7971 if (new_exclude_prog == NULL)
7972 errmsg = e_invarg;
7973 break;
7974 }
7975 else
7976 {
7977 errmsg = e_invarg;
7978 break;
7979 }
7980 if (*p == ',')
7981 ++p;
7982 }
7983 if (errmsg == NULL)
7984 {
7985 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007986 clip_autoselect_star = new_autoselect_star;
7987 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007989 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007990 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007991 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007992#ifdef FEAT_GUI_GTK
7993 if (gui.in_use)
7994 {
7995 gui_gtk_set_selection_targets();
7996 gui_gtk_set_dnd_targets();
7997 }
7998#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 }
8000 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008001 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002
8003 return errmsg;
8004}
8005#endif
8006
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008007#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008008 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008009did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008010{
8011 char_u *errmsg = NULL;
8012 win_T *wp;
8013 int l;
8014
8015 if (is_spellfile)
8016 {
8017 l = (int)STRLEN(curwin->w_s->b_p_spf);
8018 if (l > 0 && (l < 4
8019 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8020 errmsg = e_invarg;
8021 }
8022
8023 if (errmsg == NULL)
8024 {
8025 FOR_ALL_WINDOWS(wp)
8026 if (wp->w_buffer == curbuf && wp->w_p_spell)
8027 {
8028 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008029 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008030 }
8031 }
8032 return errmsg;
8033}
8034
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008035/*
8036 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8037 * Return error message when failed, NULL when OK.
8038 */
8039 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008040compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008041{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008042 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008043 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008044
Bram Moolenaar860cae12010-06-05 23:22:07 +02008045 if (*synblock->b_p_spc == NUL)
8046 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008047 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008048 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008049 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008050 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008051 if (re != NULL)
8052 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008053 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008054 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008055 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008056 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008057 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008058 return e_invarg;
8059 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008060 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008061 }
8062
Bram Moolenaar473de612013-06-08 18:19:48 +02008063 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008064 return NULL;
8065}
8066#endif
8067
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008068#if defined(FEAT_EVAL) || defined(PROTO)
8069/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008070 * Set the scriptID for an option, taking care of setting the buffer- or
8071 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008072 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008073 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008074set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008075{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008076 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8077 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008078
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008079 /* Remember where the option was set. For local options need to do that
8080 * in the buffer or window structure. */
8081 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008082 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008083 if (both || (opt_flags & OPT_LOCAL))
8084 {
8085 if (indir & PV_BUF)
8086 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8087 else if (indir & PV_WIN)
8088 curwin->w_p_scriptID[indir & PV_MASK] = id;
8089 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008090}
8091#endif
8092
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093/*
8094 * Set the value of a boolean option, and take care of side effects.
8095 * Returns NULL for success, or an error message for an error.
8096 */
8097 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008098set_bool_option(
8099 int opt_idx, /* index in options[] table */
8100 char_u *varp, /* pointer to the option variable */
8101 int value, /* new value */
8102 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008103{
8104 int old_value = *(int *)varp;
8105
Bram Moolenaar071d4272004-06-13 20:20:40 +00008106 /* Disallow changing some options from secure mode */
8107 if ((secure
8108#ifdef HAVE_SANDBOX
8109 || sandbox != 0
8110#endif
8111 ) && (options[opt_idx].flags & P_SECURE))
8112 return e_secure;
8113
8114 *(int *)varp = value; /* set the new value */
8115#ifdef FEAT_EVAL
8116 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008117 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118#endif
8119
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008120#ifdef FEAT_GUI
8121 need_mouse_correct = TRUE;
8122#endif
8123
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 /* May set global value for local option. */
8125 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8126 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8127
8128 /*
8129 * Handle side effects of changing a bool option.
8130 */
8131
8132 /* 'compatible' */
8133 if ((int *)varp == &p_cp)
8134 {
8135 compatible_set();
8136 }
8137
Bram Moolenaar920694c2016-08-21 17:45:02 +02008138#ifdef FEAT_LANGMAP
8139 if ((int *)varp == &p_lrm)
8140 /* 'langremap' -> !'langnoremap' */
8141 p_lnr = !p_lrm;
8142 else if ((int *)varp == &p_lnr)
8143 /* 'langnoremap' -> !'langremap' */
8144 p_lrm = !p_lnr;
8145#endif
8146
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008147#ifdef FEAT_PERSISTENT_UNDO
8148 /* 'undofile' */
8149 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8150 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008151 /* Only take action when the option was set. When reset we do not
8152 * delete the undo file, the option may be set again without making
8153 * any changes in between. */
8154 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008155 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008156 char_u hash[UNDO_HASH_SIZE];
8157 buf_T *save_curbuf = curbuf;
8158
Bram Moolenaar29323592016-07-24 22:04:11 +02008159 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008160 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008161 /* When 'undofile' is set globally: for every buffer, otherwise
8162 * only for the current buffer: Try to read in the undofile,
8163 * if one exists, the buffer wasn't changed and the buffer was
8164 * loaded */
8165 if ((curbuf == save_curbuf
8166 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8167 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8168 {
8169 u_compute_hash(hash);
8170 u_read_undo(NULL, hash, curbuf->b_fname);
8171 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008172 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008173 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008174 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008175 }
8176#endif
8177
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178 else if ((int *)varp == &curbuf->b_p_ro)
8179 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008180 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8182 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008183
8184 /* when 'readonly' is set may give W10 again */
8185 if (curbuf->b_p_ro)
8186 curbuf->b_did_warn = FALSE;
8187
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008189 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190#endif
8191 }
8192
Bram Moolenaar9c449722010-07-20 18:44:27 +02008193#ifdef FEAT_GUI
8194 else if ((int *)varp == &p_mh)
8195 {
8196 if (!p_mh)
8197 gui_mch_mousehide(FALSE);
8198 }
8199#endif
8200
Bram Moolenaara539df02010-08-01 14:35:05 +02008201 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008203 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008204# ifdef FEAT_TERMINAL
8205 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008206 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008207 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008208 {
8209 curbuf->b_p_ma = FALSE;
8210 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8211 }
8212# endif
8213# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008214 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008215# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008216 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008217#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 /* when 'endofline' is changed, redraw the window title */
8219 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008220 {
8221 redraw_titles();
8222 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008223 /* when 'fixeol' is changed, redraw the window title */
8224 else if ((int *)varp == &curbuf->b_p_fixeol)
8225 {
8226 redraw_titles();
8227 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008228# ifdef FEAT_MBYTE
8229 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008230 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008231 {
8232 redraw_titles();
8233 }
8234# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008235#endif
8236
8237 /* when 'bin' is set also set some other options */
8238 else if ((int *)varp == &curbuf->b_p_bin)
8239 {
8240 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8241#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008242 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008243#endif
8244 }
8245
8246#ifdef FEAT_AUTOCMD
8247 /* when 'buflisted' changes, trigger autocommands */
8248 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8249 {
8250 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8251 NULL, NULL, TRUE, curbuf);
8252 }
8253#endif
8254
8255 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8256 else if ((int *)varp == &curbuf->b_p_swf)
8257 {
8258 if (curbuf->b_p_swf && p_uc)
8259 ml_open_file(curbuf); /* create the swap file */
8260 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008261 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8262 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263 mf_close_file(curbuf, TRUE); /* remove the swap file */
8264 }
8265
8266 /* when 'terse' is set change 'shortmess' */
8267 else if ((int *)varp == &p_terse)
8268 {
8269 char_u *p;
8270
8271 p = vim_strchr(p_shm, SHM_SEARCH);
8272
8273 /* insert 's' in p_shm */
8274 if (p_terse && p == NULL)
8275 {
8276 STRCPY(IObuff, p_shm);
8277 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008278 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008279 }
8280 /* remove 's' from p_shm */
8281 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008282 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008283 }
8284
8285 /* when 'paste' is set or reset also change other options */
8286 else if ((int *)varp == &p_paste)
8287 {
8288 paste_option_changed();
8289 }
8290
8291 /* when 'insertmode' is set from an autocommand need to do work here */
8292 else if ((int *)varp == &p_im)
8293 {
8294 if (p_im)
8295 {
8296 if ((State & INSERT) == 0)
8297 need_start_insertmode = TRUE;
8298 stop_insert_mode = FALSE;
8299 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008300 /* only reset if it was set previously */
8301 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008302 {
8303 need_start_insertmode = FALSE;
8304 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008305 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 clear_cmdline = TRUE; /* remove "(insert)" */
8307 restart_edit = 0;
8308 }
8309 }
8310
8311 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8312 else if ((int *)varp == &p_ic && p_hls)
8313 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008314 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008315 }
8316
8317#ifdef FEAT_SEARCH_EXTRA
8318 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8319 else if ((int *)varp == &p_hls)
8320 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008321 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008322 }
8323#endif
8324
8325#ifdef FEAT_SCROLLBIND
8326 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8327 * at the end of normal_cmd() */
8328 else if ((int *)varp == &curwin->w_p_scb)
8329 {
8330 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008331 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008332 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008333 curwin->w_scbind_pos = curwin->w_topline;
8334 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008335 }
8336#endif
8337
Bram Moolenaar4033c552017-09-16 20:54:51 +02008338#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339 /* There can be only one window with 'previewwindow' set. */
8340 else if ((int *)varp == &curwin->w_p_pvw)
8341 {
8342 if (curwin->w_p_pvw)
8343 {
8344 win_T *win;
8345
Bram Moolenaar29323592016-07-24 22:04:11 +02008346 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008347 if (win->w_p_pvw && win != curwin)
8348 {
8349 curwin->w_p_pvw = FALSE;
8350 return (char_u *)N_("E590: A preview window already exists");
8351 }
8352 }
8353 }
8354#endif
8355
8356 /* when 'textmode' is set or reset also change 'fileformat' */
8357 else if ((int *)varp == &curbuf->b_p_tx)
8358 {
8359 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8360 }
8361
8362 /* when 'textauto' is set or reset also change 'fileformats' */
8363 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 set_string_option_direct((char_u *)"ffs", -1,
8365 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008366 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008367
8368 /*
8369 * When 'lisp' option changes include/exclude '-' in
8370 * keyword characters.
8371 */
8372#ifdef FEAT_LISP
8373 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8374 {
8375 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8376 }
8377#endif
8378
8379#ifdef FEAT_TITLE
8380 /* when 'title' changed, may need to change the title; same for 'icon' */
8381 else if ((int *)varp == &p_title)
8382 {
8383 did_set_title(FALSE);
8384 }
8385
8386 else if ((int *)varp == &p_icon)
8387 {
8388 did_set_title(TRUE);
8389 }
8390#endif
8391
8392 else if ((int *)varp == &curbuf->b_changed)
8393 {
8394 if (!value)
8395 save_file_ff(curbuf); /* Buffer is unchanged */
8396#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008397 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008398#endif
8399#ifdef FEAT_AUTOCMD
8400 modified_was_set = value;
8401#endif
8402 }
8403
8404#ifdef BACKSLASH_IN_FILENAME
8405 else if ((int *)varp == &p_ssl)
8406 {
8407 if (p_ssl)
8408 {
8409 psepc = '/';
8410 psepcN = '\\';
8411 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412 }
8413 else
8414 {
8415 psepc = '\\';
8416 psepcN = '/';
8417 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418 }
8419
8420 /* need to adjust the file name arguments and buffer names. */
8421 buflist_slash_adjust();
8422 alist_slash_adjust();
8423# ifdef FEAT_EVAL
8424 scriptnames_slash_adjust();
8425# endif
8426 }
8427#endif
8428
8429 /* If 'wrap' is set, set w_leftcol to zero. */
8430 else if ((int *)varp == &curwin->w_p_wrap)
8431 {
8432 if (curwin->w_p_wrap)
8433 curwin->w_leftcol = 0;
8434 }
8435
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436 else if ((int *)varp == &p_ea)
8437 {
8438 if (p_ea && !old_value)
8439 win_equal(curwin, FALSE, 0);
8440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441
8442 else if ((int *)varp == &p_wiv)
8443 {
8444 /*
8445 * When 'weirdinvert' changed, set/reset 't_xs'.
8446 * Then set 'weirdinvert' according to value of 't_xs'.
8447 */
8448 if (p_wiv && !old_value)
8449 T_XS = (char_u *)"y";
8450 else if (!p_wiv && old_value)
8451 T_XS = empty_option;
8452 p_wiv = (*T_XS != NUL);
8453 }
8454
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008455#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008456 else if ((int *)varp == &p_beval)
8457 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008458 if (!balloonEvalForTerm)
8459 {
8460 if (p_beval && !old_value)
8461 gui_mch_enable_beval_area(balloonEval);
8462 else if (!p_beval && old_value)
8463 gui_mch_disable_beval_area(balloonEval);
8464 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008465 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008466#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008467#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008468 else if ((int *)varp == &p_bevalterm)
8469 {
8470 mch_bevalterm_changed();
8471 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008472#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008474#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008475 else if ((int *)varp == &p_acd)
8476 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008477 /* Change directories when the 'acd' option is set now. */
8478 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008479 }
8480#endif
8481
8482#ifdef FEAT_DIFF
8483 /* 'diff' */
8484 else if ((int *)varp == &curwin->w_p_diff)
8485 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008486 /* May add or remove the buffer from the list of diff buffers. */
8487 diff_buf_adjust(curwin);
8488# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489 if (foldmethodIsDiff(curwin))
8490 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008491# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492 }
8493#endif
8494
Bram Moolenaar819edbe2017-11-25 17:14:33 +01008495#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008496 /* 'imdisable' */
8497 else if ((int *)varp == &p_imdisable)
8498 {
8499 /* Only de-activate it here, it will be enabled when changing mode. */
8500 if (p_imdisable)
8501 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008502 else if (State & INSERT)
8503 /* When the option is set from an autocommand, it may need to take
8504 * effect right away. */
8505 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506 }
8507#endif
8508
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008509#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008510 /* 'spell' */
8511 else if ((int *)varp == &curwin->w_p_spell)
8512 {
8513 if (curwin->w_p_spell)
8514 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008515 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008516 if (errmsg != NULL)
8517 EMSG(_(errmsg));
8518 }
8519 }
8520#endif
8521
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522#ifdef FEAT_FKMAP
8523 else if ((int *)varp == &p_altkeymap)
8524 {
8525 if (old_value != p_altkeymap)
8526 {
8527 if (!p_altkeymap)
8528 {
8529 p_hkmap = p_fkmap;
8530 p_fkmap = 0;
8531 }
8532 else
8533 {
8534 p_fkmap = p_hkmap;
8535 p_hkmap = 0;
8536 }
8537 (void)init_chartab();
8538 }
8539 }
8540
8541 /*
8542 * In case some second language keymapping options have changed, check
8543 * and correct the setting in a consistent way.
8544 */
8545
8546 /*
8547 * If hkmap or fkmap are set, reset Arabic keymapping.
8548 */
8549 if ((p_hkmap || p_fkmap) && p_altkeymap)
8550 {
8551 p_altkeymap = p_fkmap;
8552# ifdef FEAT_ARABIC
8553 curwin->w_p_arab = FALSE;
8554# endif
8555 (void)init_chartab();
8556 }
8557
8558 /*
8559 * If hkmap set, reset Farsi keymapping.
8560 */
8561 if (p_hkmap && p_altkeymap)
8562 {
8563 p_altkeymap = 0;
8564 p_fkmap = 0;
8565# ifdef FEAT_ARABIC
8566 curwin->w_p_arab = FALSE;
8567# endif
8568 (void)init_chartab();
8569 }
8570
8571 /*
8572 * If fkmap set, reset Hebrew keymapping.
8573 */
8574 if (p_fkmap && !p_altkeymap)
8575 {
8576 p_altkeymap = 1;
8577 p_hkmap = 0;
8578# ifdef FEAT_ARABIC
8579 curwin->w_p_arab = FALSE;
8580# endif
8581 (void)init_chartab();
8582 }
8583#endif
8584
8585#ifdef FEAT_ARABIC
8586 if ((int *)varp == &curwin->w_p_arab)
8587 {
8588 if (curwin->w_p_arab)
8589 {
8590 /*
8591 * 'arabic' is set, handle various sub-settings.
8592 */
8593 if (!p_tbidi)
8594 {
8595 /* set rightleft mode */
8596 if (!curwin->w_p_rl)
8597 {
8598 curwin->w_p_rl = TRUE;
8599 changed_window_setting();
8600 }
8601
8602 /* Enable Arabic shaping (major part of what Arabic requires) */
8603 if (!p_arshape)
8604 {
8605 p_arshape = TRUE;
8606 redraw_later_clear();
8607 }
8608 }
8609
8610 /* Arabic requires a utf-8 encoding, inform the user if its not
8611 * set. */
8612 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008613 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008614 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8615
Bram Moolenaar8820b482017-03-16 17:23:31 +01008616 msg_source(HL_ATTR(HLF_W));
8617 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008618#ifdef FEAT_EVAL
8619 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8620#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008621 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622
8623# ifdef FEAT_MBYTE
8624 /* set 'delcombine' */
8625 p_deco = TRUE;
8626# endif
8627
8628# ifdef FEAT_KEYMAP
8629 /* Force-set the necessary keymap for arabic */
8630 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8631 OPT_LOCAL);
8632# endif
8633# ifdef FEAT_FKMAP
8634 p_altkeymap = 0;
8635 p_hkmap = 0;
8636 p_fkmap = 0;
8637 (void)init_chartab();
8638# endif
8639 }
8640 else
8641 {
8642 /*
8643 * 'arabic' is reset, handle various sub-settings.
8644 */
8645 if (!p_tbidi)
8646 {
8647 /* reset rightleft mode */
8648 if (curwin->w_p_rl)
8649 {
8650 curwin->w_p_rl = FALSE;
8651 changed_window_setting();
8652 }
8653
8654 /* 'arabicshape' isn't reset, it is a global option and
8655 * another window may still need it "on". */
8656 }
8657
8658 /* 'delcombine' isn't reset, it is a global option and another
8659 * window may still want it "on". */
8660
8661# ifdef FEAT_KEYMAP
8662 /* Revert to the default keymap */
8663 curbuf->b_p_iminsert = B_IMODE_NONE;
8664 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8665# endif
8666 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008667 }
8668
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008669#endif
8670
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008671#ifdef FEAT_TERMGUICOLORS
8672 /* 'termguicolors' */
8673 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008674 {
8675# ifdef FEAT_GUI
8676 if (!gui.in_use && !gui.starting)
8677# endif
8678 highlight_gui_started();
8679 }
8680#endif
8681
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 /*
8683 * End of handling side effects for bool options.
8684 */
8685
Bram Moolenaar53744302015-07-17 17:38:22 +02008686 /* after handling side effects, call autocommand */
8687
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688 options[opt_idx].flags |= P_WAS_SET;
8689
Bram Moolenaar53744302015-07-17 17:38:22 +02008690#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8691 if (!starting)
8692 {
8693 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008694 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8695 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8696 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008697 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8698 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8699 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8700 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8701 reset_v_option_vars();
8702 }
8703#endif
8704
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008706 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008707 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008708 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709 check_redraw(options[opt_idx].flags);
8710
8711 return NULL;
8712}
8713
8714/*
8715 * Set the value of a number option, and take care of side effects.
8716 * Returns NULL for success, or an error message for an error.
8717 */
8718 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008719set_num_option(
8720 int opt_idx, /* index in options[] table */
8721 char_u *varp, /* pointer to the option variable */
8722 long value, /* new value */
8723 char_u *errbuf, /* buffer for error messages */
8724 size_t errbuflen, /* length of "errbuf" */
8725 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726 OPT_MODELINE */
8727{
8728 char_u *errmsg = NULL;
8729 long old_value = *(long *)varp;
8730 long old_Rows = Rows; /* remember old Rows */
8731 long old_Columns = Columns; /* remember old Columns */
8732 long *pp = (long *)varp;
8733
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008734 /* Disallow changing some options from secure mode. */
8735 if ((secure
8736#ifdef HAVE_SANDBOX
8737 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008738#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008739 ) && (options[opt_idx].flags & P_SECURE))
8740 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008741
8742 *pp = value;
8743#ifdef FEAT_EVAL
8744 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008745 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008747#ifdef FEAT_GUI
8748 need_mouse_correct = TRUE;
8749#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750
Bram Moolenaar14f24742012-08-08 18:01:05 +02008751 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752 {
8753 errmsg = e_positive;
8754 curbuf->b_p_sw = curbuf->b_p_ts;
8755 }
8756
8757 /*
8758 * Number options that need some action when changed
8759 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008760 if (pp == &p_wh || pp == &p_hh)
8761 {
8762 if (p_wh < 1)
8763 {
8764 errmsg = e_positive;
8765 p_wh = 1;
8766 }
8767 if (p_wmh > p_wh)
8768 {
8769 errmsg = e_winheight;
8770 p_wh = p_wmh;
8771 }
8772 if (p_hh < 0)
8773 {
8774 errmsg = e_positive;
8775 p_hh = 0;
8776 }
8777
8778 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008779 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 {
8781 if (pp == &p_wh && curwin->w_height < p_wh)
8782 win_setheight((int)p_wh);
8783 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8784 win_setheight((int)p_hh);
8785 }
8786 }
8787
8788 /* 'winminheight' */
8789 else if (pp == &p_wmh)
8790 {
8791 if (p_wmh < 0)
8792 {
8793 errmsg = e_positive;
8794 p_wmh = 0;
8795 }
8796 if (p_wmh > p_wh)
8797 {
8798 errmsg = e_winheight;
8799 p_wmh = p_wh;
8800 }
8801 win_setminheight();
8802 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008803 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 {
8805 if (p_wiw < 1)
8806 {
8807 errmsg = e_positive;
8808 p_wiw = 1;
8809 }
8810 if (p_wmw > p_wiw)
8811 {
8812 errmsg = e_winwidth;
8813 p_wiw = p_wmw;
8814 }
8815
8816 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008817 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008818 win_setwidth((int)p_wiw);
8819 }
8820
8821 /* 'winminwidth' */
8822 else if (pp == &p_wmw)
8823 {
8824 if (p_wmw < 0)
8825 {
8826 errmsg = e_positive;
8827 p_wmw = 0;
8828 }
8829 if (p_wmw > p_wiw)
8830 {
8831 errmsg = e_winwidth;
8832 p_wmw = p_wiw;
8833 }
8834 win_setminheight();
8835 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008836
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 /* (re)set last window status line */
8838 else if (pp == &p_ls)
8839 {
8840 last_status(FALSE);
8841 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008842
8843 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008844 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008845 {
8846 shell_new_rows(); /* recompute window positions and heights */
8847 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848
8849#ifdef FEAT_GUI
8850 else if (pp == &p_linespace)
8851 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008852 /* Recompute gui.char_height and resize the Vim window to keep the
8853 * same number of lines. */
8854 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008855 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856 }
8857#endif
8858
8859#ifdef FEAT_FOLDING
8860 /* 'foldlevel' */
8861 else if (pp == &curwin->w_p_fdl)
8862 {
8863 if (curwin->w_p_fdl < 0)
8864 curwin->w_p_fdl = 0;
8865 newFoldLevel();
8866 }
8867
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008868 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869 else if (pp == &curwin->w_p_fml)
8870 {
8871 foldUpdateAll(curwin);
8872 }
8873
8874 /* 'foldnestmax' */
8875 else if (pp == &curwin->w_p_fdn)
8876 {
8877 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8878 foldUpdateAll(curwin);
8879 }
8880
8881 /* 'foldcolumn' */
8882 else if (pp == &curwin->w_p_fdc)
8883 {
8884 if (curwin->w_p_fdc < 0)
8885 {
8886 errmsg = e_positive;
8887 curwin->w_p_fdc = 0;
8888 }
8889 else if (curwin->w_p_fdc > 12)
8890 {
8891 errmsg = e_invarg;
8892 curwin->w_p_fdc = 12;
8893 }
8894 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008895#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008896
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008897#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 /* 'shiftwidth' or 'tabstop' */
8899 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8900 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008901# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902 if (foldmethodIsIndent(curwin))
8903 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008904# endif
8905# ifdef FEAT_CINDENT
8906 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8907 * parse 'cinoptions'. */
8908 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8909 parse_cino(curbuf);
8910# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008912#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008914#ifdef FEAT_MBYTE
8915 /* 'maxcombine' */
8916 else if (pp == &p_mco)
8917 {
8918 if (p_mco > MAX_MCO)
8919 p_mco = MAX_MCO;
8920 else if (p_mco < 0)
8921 p_mco = 0;
8922 screenclear(); /* will re-allocate the screen */
8923 }
8924#endif
8925
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 else if (pp == &curbuf->b_p_iminsert)
8927 {
8928 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8929 {
8930 errmsg = e_invarg;
8931 curbuf->b_p_iminsert = B_IMODE_NONE;
8932 }
8933 p_iminsert = curbuf->b_p_iminsert;
8934 if (termcap_active) /* don't do this in the alternate screen */
8935 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008936#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937 /* Show/unshow value of 'keymap' in status lines. */
8938 status_redraw_curbuf();
8939#endif
8940 }
8941
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008942#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8943 /* 'imstyle' */
8944 else if (pp == &p_imst)
8945 {
8946 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8947 errmsg = e_invarg;
8948 }
8949#endif
8950
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008951 else if (pp == &p_window)
8952 {
8953 if (p_window < 1)
8954 p_window = 1;
8955 else if (p_window >= Rows)
8956 p_window = Rows - 1;
8957 }
8958
Bram Moolenaar071d4272004-06-13 20:20:40 +00008959 else if (pp == &curbuf->b_p_imsearch)
8960 {
8961 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8962 {
8963 errmsg = e_invarg;
8964 curbuf->b_p_imsearch = B_IMODE_NONE;
8965 }
8966 p_imsearch = curbuf->b_p_imsearch;
8967 }
8968
8969#ifdef FEAT_TITLE
8970 /* if 'titlelen' has changed, redraw the title */
8971 else if (pp == &p_titlelen)
8972 {
8973 if (p_titlelen < 0)
8974 {
8975 errmsg = e_positive;
8976 p_titlelen = 85;
8977 }
8978 if (starting != NO_SCREEN && old_value != p_titlelen)
8979 need_maketitle = TRUE;
8980 }
8981#endif
8982
8983 /* if p_ch changed value, change the command line height */
8984 else if (pp == &p_ch)
8985 {
8986 if (p_ch < 1)
8987 {
8988 errmsg = e_positive;
8989 p_ch = 1;
8990 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008991 if (p_ch > Rows - min_rows() + 1)
8992 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993
8994 /* Only compute the new window layout when startup has been
8995 * completed. Otherwise the frame sizes may be wrong. */
8996 if (p_ch != old_value && full_screen
8997#ifdef FEAT_GUI
8998 && !gui.starting
8999#endif
9000 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009001 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009002 }
9003
9004 /* when 'updatecount' changes from zero to non-zero, open swap files */
9005 else if (pp == &p_uc)
9006 {
9007 if (p_uc < 0)
9008 {
9009 errmsg = e_positive;
9010 p_uc = 100;
9011 }
9012 if (p_uc && !old_value)
9013 ml_open_files();
9014 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009015#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009016 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009017 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009018 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009019 {
9020 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009021 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009022 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009023 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009024 {
9025 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009026 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009027 }
9028 }
9029#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009030#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009031 else if (pp == &p_mzq)
9032 mzvim_reset_timer();
9033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009034
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009035#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9036 /* 'pyxversion' */
9037 else if (pp == &p_pyx)
9038 {
9039 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9040 errmsg = e_invarg;
9041 }
9042#endif
9043
Bram Moolenaar071d4272004-06-13 20:20:40 +00009044 /* sync undo before 'undolevels' changes */
9045 else if (pp == &p_ul)
9046 {
9047 /* use the old value, otherwise u_sync() may not work properly */
9048 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009049 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050 p_ul = value;
9051 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009052 else if (pp == &curbuf->b_p_ul)
9053 {
9054 /* use the old value, otherwise u_sync() may not work properly */
9055 curbuf->b_p_ul = old_value;
9056 u_sync(TRUE);
9057 curbuf->b_p_ul = value;
9058 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009060#ifdef FEAT_LINEBREAK
9061 /* 'numberwidth' must be positive */
9062 else if (pp == &curwin->w_p_nuw)
9063 {
9064 if (curwin->w_p_nuw < 1)
9065 {
9066 errmsg = e_positive;
9067 curwin->w_p_nuw = 1;
9068 }
9069 if (curwin->w_p_nuw > 10)
9070 {
9071 errmsg = e_invarg;
9072 curwin->w_p_nuw = 10;
9073 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009074 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009075 }
9076#endif
9077
Bram Moolenaar1a384422010-07-14 19:53:30 +02009078 else if (pp == &curbuf->b_p_tw)
9079 {
9080 if (curbuf->b_p_tw < 0)
9081 {
9082 errmsg = e_positive;
9083 curbuf->b_p_tw = 0;
9084 }
9085#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009086 {
9087 win_T *wp;
9088 tabpage_T *tp;
9089
9090 FOR_ALL_TAB_WINDOWS(tp, wp)
9091 check_colorcolumn(wp);
9092 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009093#endif
9094 }
9095
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 /*
9097 * Check the bounds for numeric options here
9098 */
9099 if (Rows < min_rows() && full_screen)
9100 {
9101 if (errbuf != NULL)
9102 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009103 vim_snprintf((char *)errbuf, errbuflen,
9104 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009105 errmsg = errbuf;
9106 }
9107 Rows = min_rows();
9108 }
9109 if (Columns < MIN_COLUMNS && full_screen)
9110 {
9111 if (errbuf != NULL)
9112 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009113 vim_snprintf((char *)errbuf, errbuflen,
9114 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115 errmsg = errbuf;
9116 }
9117 Columns = MIN_COLUMNS;
9118 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009119 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009120
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121 /*
9122 * If the screen (shell) height has been changed, assume it is the
9123 * physical screenheight.
9124 */
9125 if (old_Rows != Rows || old_Columns != Columns)
9126 {
9127 /* Changing the screen size is not allowed while updating the screen. */
9128 if (updating_screen)
9129 *pp = old_value;
9130 else if (full_screen
9131#ifdef FEAT_GUI
9132 && !gui.starting
9133#endif
9134 )
9135 set_shellsize((int)Columns, (int)Rows, TRUE);
9136 else
9137 {
9138 /* Postpone the resizing; check the size and cmdline position for
9139 * messages. */
9140 check_shellsize();
9141 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9142 cmdline_row = Rows - p_ch;
9143 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009144 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009145 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009146 }
9147
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 if (curbuf->b_p_ts <= 0)
9149 {
9150 errmsg = e_positive;
9151 curbuf->b_p_ts = 8;
9152 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009153 if (p_tm < 0)
9154 {
9155 errmsg = e_positive;
9156 p_tm = 0;
9157 }
9158 if ((curwin->w_p_scr <= 0
9159 || (curwin->w_p_scr > curwin->w_height
9160 && curwin->w_height > 0))
9161 && full_screen)
9162 {
9163 if (pp == &(curwin->w_p_scr))
9164 {
9165 if (curwin->w_p_scr != 0)
9166 errmsg = e_scroll;
9167 win_comp_scroll(curwin);
9168 }
9169 /* If 'scroll' became invalid because of a side effect silently adjust
9170 * it. */
9171 else if (curwin->w_p_scr <= 0)
9172 curwin->w_p_scr = 1;
9173 else /* curwin->w_p_scr > curwin->w_height */
9174 curwin->w_p_scr = curwin->w_height;
9175 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009176 if (p_hi < 0)
9177 {
9178 errmsg = e_positive;
9179 p_hi = 0;
9180 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009181 else if (p_hi > 10000)
9182 {
9183 errmsg = e_invarg;
9184 p_hi = 10000;
9185 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009186 if (p_re < 0 || p_re > 2)
9187 {
9188 errmsg = e_invarg;
9189 p_re = 0;
9190 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009191 if (p_report < 0)
9192 {
9193 errmsg = e_positive;
9194 p_report = 1;
9195 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009196 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009197 {
9198 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9199 p_sj = Rows / 2;
9200 else
9201 {
9202 errmsg = e_scroll;
9203 p_sj = 1;
9204 }
9205 }
9206 if (p_so < 0 && full_screen)
9207 {
9208 errmsg = e_scroll;
9209 p_so = 0;
9210 }
9211 if (p_siso < 0 && full_screen)
9212 {
9213 errmsg = e_positive;
9214 p_siso = 0;
9215 }
9216#ifdef FEAT_CMDWIN
9217 if (p_cwh < 1)
9218 {
9219 errmsg = e_positive;
9220 p_cwh = 1;
9221 }
9222#endif
9223 if (p_ut < 0)
9224 {
9225 errmsg = e_positive;
9226 p_ut = 2000;
9227 }
9228 if (p_ss < 0)
9229 {
9230 errmsg = e_positive;
9231 p_ss = 0;
9232 }
9233
9234 /* May set global value for local option. */
9235 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9236 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9237
9238 options[opt_idx].flags |= P_WAS_SET;
9239
Bram Moolenaar53744302015-07-17 17:38:22 +02009240#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9241 if (!starting && errmsg == NULL)
9242 {
9243 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009244 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9245 vim_snprintf((char *)buf_new, 10, "%ld", value);
9246 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009247 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9248 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9249 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9250 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9251 reset_v_option_vars();
9252 }
9253#endif
9254
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009256 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009257 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009258 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009259 check_redraw(options[opt_idx].flags);
9260
9261 return errmsg;
9262}
9263
9264/*
9265 * Called after an option changed: check if something needs to be redrawn.
9266 */
9267 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009268check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009269{
9270 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009271 int doclear = (flags & P_RCLR) == P_RCLR;
9272 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009273
Bram Moolenaar071d4272004-06-13 20:20:40 +00009274 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9275 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009276
9277 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9278 changed_window_setting();
9279 if (flags & P_RBUF)
9280 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009281 if (flags & P_RWINONLY)
9282 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009283 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009284 redraw_all_later(CLEAR);
9285 else if (all)
9286 redraw_all_later(NOT_VALID);
9287}
9288
9289/*
9290 * Find index for option 'arg'.
9291 * Return -1 if not found.
9292 */
9293 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009294findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295{
9296 int opt_idx;
9297 char *s, *p;
9298 static short quick_tab[27] = {0, 0}; /* quick access table */
9299 int is_term_opt;
9300
9301 /*
9302 * For first call: Initialize the quick-access table.
9303 * It contains the index for the first option that starts with a certain
9304 * letter. There are 26 letters, plus the first "t_" option.
9305 */
9306 if (quick_tab[1] == 0)
9307 {
9308 p = options[0].fullname;
9309 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9310 {
9311 if (s[0] != p[0])
9312 {
9313 if (s[0] == 't' && s[1] == '_')
9314 quick_tab[26] = opt_idx;
9315 else
9316 quick_tab[CharOrdLow(s[0])] = opt_idx;
9317 }
9318 p = s;
9319 }
9320 }
9321
9322 /*
9323 * Check for name starting with an illegal character.
9324 */
9325#ifdef EBCDIC
9326 if (!islower(arg[0]))
9327#else
9328 if (arg[0] < 'a' || arg[0] > 'z')
9329#endif
9330 return -1;
9331
9332 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9333 if (is_term_opt)
9334 opt_idx = quick_tab[26];
9335 else
9336 opt_idx = quick_tab[CharOrdLow(arg[0])];
9337 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9338 {
9339 if (STRCMP(arg, s) == 0) /* match full name */
9340 break;
9341 }
9342 if (s == NULL && !is_term_opt)
9343 {
9344 opt_idx = quick_tab[CharOrdLow(arg[0])];
9345 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9346 {
9347 s = options[opt_idx].shortname;
9348 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9349 break;
9350 s = NULL;
9351 }
9352 }
9353 if (s == NULL)
9354 opt_idx = -1;
9355 return opt_idx;
9356}
9357
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009358#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359/*
9360 * Get the value for an option.
9361 *
9362 * Returns:
9363 * Number or Toggle option: 1, *numval gets value.
9364 * String option: 0, *stringval gets allocated string.
9365 * Hidden Number or Toggle option: -1.
9366 * hidden String option: -2.
9367 * unknown option: -3.
9368 */
9369 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009370get_option_value(
9371 char_u *name,
9372 long *numval,
9373 char_u **stringval, /* NULL when only checking existence */
9374 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009375{
9376 int opt_idx;
9377 char_u *varp;
9378
9379 opt_idx = findoption(name);
9380 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009381 {
9382 int key;
9383
9384 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9385 && (key = find_key_option(name)) != 0)
9386 {
9387 char_u key_name[2];
9388 char_u *p;
9389
9390 if (key < 0)
9391 {
9392 key_name[0] = KEY2TERMCAP0(key);
9393 key_name[1] = KEY2TERMCAP1(key);
9394 }
9395 else
9396 {
9397 key_name[0] = KS_KEY;
9398 key_name[1] = (key & 0xff);
9399 }
9400 p = find_termcode(key_name);
9401 if (p != NULL)
9402 {
9403 if (stringval != NULL)
9404 *stringval = vim_strsave(p);
9405 return 0;
9406 }
9407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009408 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009409 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009410
9411 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9412
9413 if (options[opt_idx].flags & P_STRING)
9414 {
9415 if (varp == NULL) /* hidden option */
9416 return -2;
9417 if (stringval != NULL)
9418 {
9419#ifdef FEAT_CRYPT
9420 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009421 if ((char_u **)varp == &curbuf->b_p_key
9422 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423 *stringval = vim_strsave((char_u *)"*****");
9424 else
9425#endif
9426 *stringval = vim_strsave(*(char_u **)(varp));
9427 }
9428 return 0;
9429 }
9430
9431 if (varp == NULL) /* hidden option */
9432 return -1;
9433 if (options[opt_idx].flags & P_NUM)
9434 *numval = *(long *)varp;
9435 else
9436 {
9437 /* Special case: 'modified' is b_changed, but we also want to consider
9438 * it set when 'ff' or 'fenc' changed. */
9439 if ((int *)varp == &curbuf->b_changed)
9440 *numval = curbufIsChanged();
9441 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009442 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443 }
9444 return 1;
9445}
9446#endif
9447
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009448#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009449/*
9450 * Returns the option attributes and its value. Unlike the above function it
9451 * will return either global value or local value of the option depending on
9452 * what was requested, but it will never return global value if it was
9453 * requested to return local one and vice versa. Neither it will return
9454 * buffer-local value if it was requested to return window-local one.
9455 *
9456 * Pretends that option is absent if it is not present in the requested scope
9457 * (i.e. has no global, window-local or buffer-local value depending on
9458 * opt_type). Uses
9459 *
9460 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009461 * 0 hidden or unknown option, also option that does not have requested
9462 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009463 * see SOPT_* in vim.h for other flags
9464 *
9465 * Possible opt_type values: see SREQ_* in vim.h
9466 */
9467 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009468get_option_value_strict(
9469 char_u *name,
9470 long *numval,
9471 char_u **stringval, /* NULL when only obtaining attributes */
9472 int opt_type,
9473 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009474{
9475 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009476 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009477 struct vimoption *p;
9478 int r = 0;
9479
9480 opt_idx = findoption(name);
9481 if (opt_idx < 0)
9482 return 0;
9483
9484 p = &(options[opt_idx]);
9485
9486 /* Hidden option */
9487 if (p->var == NULL)
9488 return 0;
9489
9490 if (p->flags & P_BOOL)
9491 r |= SOPT_BOOL;
9492 else if (p->flags & P_NUM)
9493 r |= SOPT_NUM;
9494 else if (p->flags & P_STRING)
9495 r |= SOPT_STRING;
9496
9497 if (p->indir == PV_NONE)
9498 {
9499 if (opt_type == SREQ_GLOBAL)
9500 r |= SOPT_GLOBAL;
9501 else
9502 return 0; /* Did not request global-only option */
9503 }
9504 else
9505 {
9506 if (p->indir & PV_BOTH)
9507 r |= SOPT_GLOBAL;
9508 else if (opt_type == SREQ_GLOBAL)
9509 return 0; /* Requested global option */
9510
9511 if (p->indir & PV_WIN)
9512 {
9513 if (opt_type == SREQ_BUF)
9514 return 0; /* Did not request window-local option */
9515 else
9516 r |= SOPT_WIN;
9517 }
9518 else if (p->indir & PV_BUF)
9519 {
9520 if (opt_type == SREQ_WIN)
9521 return 0; /* Did not request buffer-local option */
9522 else
9523 r |= SOPT_BUF;
9524 }
9525 }
9526
9527 if (stringval == NULL)
9528 return r;
9529
9530 if (opt_type == SREQ_GLOBAL)
9531 varp = p->var;
9532 else
9533 {
9534 if (opt_type == SREQ_BUF)
9535 {
9536 /* Special case: 'modified' is b_changed, but we also want to
9537 * consider it set when 'ff' or 'fenc' changed. */
9538 if (p->indir == PV_MOD)
9539 {
9540 *numval = bufIsChanged((buf_T *) from);
9541 varp = NULL;
9542 }
9543#ifdef FEAT_CRYPT
9544 else if (p->indir == PV_KEY)
9545 {
9546 /* never return the value of the crypt key */
9547 *stringval = NULL;
9548 varp = NULL;
9549 }
9550#endif
9551 else
9552 {
9553 aco_save_T aco;
9554 aucmd_prepbuf(&aco, (buf_T *) from);
9555 varp = get_varp(p);
9556 aucmd_restbuf(&aco);
9557 }
9558 }
9559 else if (opt_type == SREQ_WIN)
9560 {
9561 win_T *save_curwin;
9562 save_curwin = curwin;
9563 curwin = (win_T *) from;
9564 curbuf = curwin->w_buffer;
9565 varp = get_varp(p);
9566 curwin = save_curwin;
9567 curbuf = curwin->w_buffer;
9568 }
9569 if (varp == p->var)
9570 return (r | SOPT_UNSET);
9571 }
9572
9573 if (varp != NULL)
9574 {
9575 if (p->flags & P_STRING)
9576 *stringval = vim_strsave(*(char_u **)(varp));
9577 else if (p->flags & P_NUM)
9578 *numval = *(long *) varp;
9579 else
9580 *numval = *(int *)varp;
9581 }
9582
9583 return r;
9584}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009585
9586/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009587 * Iterate over options. First argument is a pointer to a pointer to a
9588 * structure inside options[] array, second is option type like in the above
9589 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009590 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009591 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009592 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009593 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009594 * first argument to NULL.
9595 *
9596 * Returns full option name for current option on each call.
9597 */
9598 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009599option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009600{
9601 struct vimoption *ret = NULL;
9602 do
9603 {
9604 if (*option == NULL)
9605 *option = (void *) options;
9606 else if (((struct vimoption *) (*option))->fullname == NULL)
9607 {
9608 *option = NULL;
9609 return NULL;
9610 }
9611 else
9612 *option = (void *) (((struct vimoption *) (*option)) + 1);
9613
9614 ret = ((struct vimoption *) (*option));
9615
9616 /* Hidden option */
9617 if (ret->var == NULL)
9618 {
9619 ret = NULL;
9620 continue;
9621 }
9622
9623 switch (opt_type)
9624 {
9625 case SREQ_GLOBAL:
9626 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9627 ret = NULL;
9628 break;
9629 case SREQ_BUF:
9630 if (!(ret->indir & PV_BUF))
9631 ret = NULL;
9632 break;
9633 case SREQ_WIN:
9634 if (!(ret->indir & PV_WIN))
9635 ret = NULL;
9636 break;
9637 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009638 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009639 return NULL;
9640 }
9641 }
9642 while (ret == NULL);
9643
9644 return (char_u *)ret->fullname;
9645}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009646#endif
9647
Bram Moolenaar071d4272004-06-13 20:20:40 +00009648/*
9649 * Set the value of option "name".
9650 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009651 *
9652 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009653 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009654 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009655set_option_value(
9656 char_u *name,
9657 long number,
9658 char_u *string,
9659 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660{
9661 int opt_idx;
9662 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009663 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009664
9665 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009666 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009667 {
9668 int key;
9669
9670 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9671 && (key = find_key_option(name)) != 0)
9672 {
9673 char_u key_name[2];
9674
9675 if (key < 0)
9676 {
9677 key_name[0] = KEY2TERMCAP0(key);
9678 key_name[1] = KEY2TERMCAP1(key);
9679 }
9680 else
9681 {
9682 key_name[0] = KS_KEY;
9683 key_name[1] = (key & 0xff);
9684 }
9685 add_termcode(key_name, string, FALSE);
9686 if (full_screen)
9687 ttest(FALSE);
9688 redraw_all_later(CLEAR);
9689 return NULL;
9690 }
9691
Bram Moolenaar071d4272004-06-13 20:20:40 +00009692 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009693 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694 else
9695 {
9696 flags = options[opt_idx].flags;
9697#ifdef HAVE_SANDBOX
9698 /* Disallow changing some options in the sandbox */
9699 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009700 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009701 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009702 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009704#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009705 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009706 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009707 else
9708 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009709 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009710 if (varp != NULL) /* hidden option is not changed */
9711 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009712 if (number == 0 && string != NULL)
9713 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009714 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009715
9716 /* Either we are given a string or we are setting option
9717 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009718 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009719 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009720 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009721 {
9722 /* There's another character after zeros or the string
9723 * is empty. In both cases, we are trying to set a
9724 * num option using a string. */
9725 EMSG3(_("E521: Number required: &%s = '%s'"),
9726 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009727 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009728
9729 }
9730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009732 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009733 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009735 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009736 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737 }
9738 }
9739 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009740 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741}
9742
9743/*
9744 * Get the terminal code for a terminal option.
9745 * Returns NULL when not found.
9746 */
9747 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009748get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749{
9750 int opt_idx;
9751 char_u *varp;
9752
9753 if (tname[0] != 't' || tname[1] != '_' ||
9754 tname[2] == NUL || tname[3] == NUL)
9755 return NULL;
9756 if ((opt_idx = findoption(tname)) >= 0)
9757 {
9758 varp = get_varp(&(options[opt_idx]));
9759 if (varp != NULL)
9760 varp = *(char_u **)(varp);
9761 return varp;
9762 }
9763 return find_termcode(tname + 2);
9764}
9765
9766 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009767get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768{
9769 int i;
9770
9771 i = findoption((char_u *)"hl");
9772 if (i >= 0)
9773 return options[i].def_val[VI_DEFAULT];
9774 return (char_u *)NULL;
9775}
9776
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009777#if defined(FEAT_MBYTE) || defined(PROTO)
9778 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009779get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009780{
9781 int i;
9782
9783 i = findoption((char_u *)"enc");
9784 if (i >= 0)
9785 return options[i].def_val[VI_DEFAULT];
9786 return (char_u *)NULL;
9787}
9788#endif
9789
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790/*
9791 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9792 */
9793 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009794find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795{
9796 int key;
9797 int modifiers;
9798
9799 /*
9800 * Don't use get_special_key_code() for t_xx, we don't want it to call
9801 * add_termcap_entry().
9802 */
9803 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9804 key = TERMCAP2KEY(arg[2], arg[3]);
9805 else
9806 {
9807 --arg; /* put arg at the '<' */
9808 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009809 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810 if (modifiers) /* can't handle modifiers here */
9811 key = 0;
9812 }
9813 return key;
9814}
9815
9816/*
9817 * if 'all' == 0: show changed options
9818 * if 'all' == 1: show all normal options
9819 * if 'all' == 2: show all terminal options
9820 */
9821 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009822showoptions(
9823 int all,
9824 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009825{
9826 struct vimoption *p;
9827 int col;
9828 int isterm;
9829 char_u *varp;
9830 struct vimoption **items;
9831 int item_count;
9832 int run;
9833 int row, rows;
9834 int cols;
9835 int i;
9836 int len;
9837
9838#define INC 20
9839#define GAP 3
9840
9841 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9842 PARAM_COUNT));
9843 if (items == NULL)
9844 return;
9845
9846 /* Highlight title */
9847 if (all == 2)
9848 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9849 else if (opt_flags & OPT_GLOBAL)
9850 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9851 else if (opt_flags & OPT_LOCAL)
9852 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9853 else
9854 MSG_PUTS_TITLE(_("\n--- Options ---"));
9855
9856 /*
9857 * do the loop two times:
9858 * 1. display the short items
9859 * 2. display the long items (only strings and numbers)
9860 */
9861 for (run = 1; run <= 2 && !got_int; ++run)
9862 {
9863 /*
9864 * collect the items in items[]
9865 */
9866 item_count = 0;
9867 for (p = &options[0]; p->fullname != NULL; p++)
9868 {
9869 varp = NULL;
9870 isterm = istermoption(p);
9871 if (opt_flags != 0)
9872 {
9873 if (p->indir != PV_NONE && !isterm)
9874 varp = get_varp_scope(p, opt_flags);
9875 }
9876 else
9877 varp = get_varp(p);
9878 if (varp != NULL
9879 && ((all == 2 && isterm)
9880 || (all == 1 && !isterm)
9881 || (all == 0 && !optval_default(p, varp))))
9882 {
9883 if (p->flags & P_BOOL)
9884 len = 1; /* a toggle option fits always */
9885 else
9886 {
9887 option_value2string(p, opt_flags);
9888 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9889 }
9890 if ((len <= INC - GAP && run == 1) ||
9891 (len > INC - GAP && run == 2))
9892 items[item_count++] = p;
9893 }
9894 }
9895
9896 /*
9897 * display the items
9898 */
9899 if (run == 1)
9900 {
9901 cols = (Columns + GAP - 3) / INC;
9902 if (cols == 0)
9903 cols = 1;
9904 rows = (item_count + cols - 1) / cols;
9905 }
9906 else /* run == 2 */
9907 rows = item_count;
9908 for (row = 0; row < rows && !got_int; ++row)
9909 {
9910 msg_putchar('\n'); /* go to next line */
9911 if (got_int) /* 'q' typed in more */
9912 break;
9913 col = 0;
9914 for (i = row; i < item_count; i += rows)
9915 {
9916 msg_col = col; /* make columns */
9917 showoneopt(items[i], opt_flags);
9918 col += INC;
9919 }
9920 out_flush();
9921 ui_breakcheck();
9922 }
9923 }
9924 vim_free(items);
9925}
9926
9927/*
9928 * Return TRUE if option "p" has its default value.
9929 */
9930 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009931optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932{
9933 int dvi;
9934
9935 if (varp == NULL)
9936 return TRUE; /* hidden option is always at default */
9937 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9938 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009939 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009941 /* the cast to long is required for Manx C, long_i is
9942 * needed for MSVC */
9943 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009944 /* P_STRING */
9945 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9946}
9947
9948/*
9949 * showoneopt: show the value of one option
9950 * must not be called with a hidden option!
9951 */
9952 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009953showoneopt(
9954 struct vimoption *p,
9955 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009956{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009957 char_u *varp;
9958 int save_silent = silent_mode;
9959
9960 silent_mode = FALSE;
9961 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962
9963 varp = get_varp_scope(p, opt_flags);
9964
9965 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9966 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9967 ? !curbufIsChanged() : !*(int *)varp))
9968 MSG_PUTS("no");
9969 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9970 MSG_PUTS("--");
9971 else
9972 MSG_PUTS(" ");
9973 MSG_PUTS(p->fullname);
9974 if (!(p->flags & P_BOOL))
9975 {
9976 msg_putchar('=');
9977 /* put value string in NameBuff */
9978 option_value2string(p, opt_flags);
9979 msg_outtrans(NameBuff);
9980 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009981
9982 silent_mode = save_silent;
9983 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984}
9985
9986/*
9987 * Write modified options as ":set" commands to a file.
9988 *
9989 * There are three values for "opt_flags":
9990 * OPT_GLOBAL: Write global option values and fresh values of
9991 * buffer-local options (used for start of a session
9992 * file).
9993 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9994 * curwin (used for a vimrc file).
9995 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9996 * and local values for window-local options of
9997 * curwin. Local values are also written when at the
9998 * default value, because a modeline or autocommand
9999 * may have set them when doing ":edit file" and the
10000 * user has set them back at the default or fresh
10001 * value.
10002 * When "local_only" is TRUE, don't write fresh
10003 * values, only local values (for ":mkview").
10004 * (fresh value = value used for a new buffer or window for a local option).
10005 *
10006 * Return FAIL on error, OK otherwise.
10007 */
10008 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010009makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010010{
10011 struct vimoption *p;
10012 char_u *varp; /* currently used value */
10013 char_u *varp_fresh; /* local value */
10014 char_u *varp_local = NULL; /* fresh value */
10015 char *cmd;
10016 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010017 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010018
10019 /*
10020 * The options that don't have a default (terminal name, columns, lines)
10021 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010022 * Do the loop over "options[]" twice: once for options with the
10023 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010024 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010025 for (pri = 1; pri >= 0; --pri)
10026 {
10027 for (p = &options[0]; !istermoption(p); p++)
10028 if (!(p->flags & P_NO_MKRC)
10029 && !istermoption(p)
10030 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031 {
10032 /* skip global option when only doing locals */
10033 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10034 continue;
10035
10036 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10037 * file, they are always buffer-specific. */
10038 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10039 continue;
10040
10041 /* Global values are only written when not at the default value. */
10042 varp = get_varp_scope(p, opt_flags);
10043 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10044 continue;
10045
10046 round = 2;
10047 if (p->indir != PV_NONE)
10048 {
10049 if (p->var == VAR_WIN)
10050 {
10051 /* skip window-local option when only doing globals */
10052 if (!(opt_flags & OPT_LOCAL))
10053 continue;
10054 /* When fresh value of window-local option is not at the
10055 * default, need to write it too. */
10056 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10057 {
10058 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10059 if (!optval_default(p, varp_fresh))
10060 {
10061 round = 1;
10062 varp_local = varp;
10063 varp = varp_fresh;
10064 }
10065 }
10066 }
10067 }
10068
10069 /* Round 1: fresh value for window-local options.
10070 * Round 2: other values */
10071 for ( ; round <= 2; varp = varp_local, ++round)
10072 {
10073 if (round == 1 || (opt_flags & OPT_GLOBAL))
10074 cmd = "set";
10075 else
10076 cmd = "setlocal";
10077
10078 if (p->flags & P_BOOL)
10079 {
10080 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10081 return FAIL;
10082 }
10083 else if (p->flags & P_NUM)
10084 {
10085 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10086 return FAIL;
10087 }
10088 else /* P_STRING */
10089 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010090#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10091 int do_endif = FALSE;
10092
Bram Moolenaar071d4272004-06-13 20:20:40 +000010093 /* Don't set 'syntax' and 'filetype' again if the value is
10094 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010095 if (
10096# if defined(FEAT_SYN_HL)
10097 p->indir == PV_SYN
10098# if defined(FEAT_AUTOCMD)
10099 ||
10100# endif
10101# endif
10102# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010103 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010104# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010105 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010106 {
10107 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10108 *(char_u **)(varp)) < 0
10109 || put_eol(fd) < 0)
10110 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010111 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010112 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010113#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010114 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10115 (p->flags & P_EXPAND) != 0) == FAIL)
10116 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010117#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10118 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119 {
10120 if (put_line(fd, "endif") == FAIL)
10121 return FAIL;
10122 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010123#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124 }
10125 }
10126 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010127 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128 return OK;
10129}
10130
10131#if defined(FEAT_FOLDING) || defined(PROTO)
10132/*
10133 * Generate set commands for the local fold options only. Used when
10134 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10135 */
10136 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010137makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010138{
10139 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10140# ifdef FEAT_EVAL
10141 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10142 == FAIL
10143# endif
10144 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10145 == FAIL
10146 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10147 == FAIL
10148 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10149 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10150 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10151 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10152 )
10153 return FAIL;
10154
10155 return OK;
10156}
10157#endif
10158
10159 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010160put_setstring(
10161 FILE *fd,
10162 char *cmd,
10163 char *name,
10164 char_u **valuep,
10165 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166{
10167 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010168 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169
10170 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10171 return FAIL;
10172 if (*valuep != NULL)
10173 {
10174 /* Output 'pastetoggle' as key names. For other
10175 * options some characters have to be escaped with
10176 * CTRL-V or backslash */
10177 if (valuep == &p_pt)
10178 {
10179 s = *valuep;
10180 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010181 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182 return FAIL;
10183 }
10184 else if (expand)
10185 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010186 buf = alloc(MAXPATHL);
10187 if (buf == NULL)
10188 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10190 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010191 {
10192 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010194 }
10195 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 }
10197 else if (put_escstr(fd, *valuep, 2) == FAIL)
10198 return FAIL;
10199 }
10200 if (put_eol(fd) < 0)
10201 return FAIL;
10202 return OK;
10203}
10204
10205 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010206put_setnum(
10207 FILE *fd,
10208 char *cmd,
10209 char *name,
10210 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211{
10212 long wc;
10213
10214 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10215 return FAIL;
10216 if (wc_use_keyname((char_u *)valuep, &wc))
10217 {
10218 /* print 'wildchar' and 'wildcharm' as a key name */
10219 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10220 return FAIL;
10221 }
10222 else if (fprintf(fd, "%ld", *valuep) < 0)
10223 return FAIL;
10224 if (put_eol(fd) < 0)
10225 return FAIL;
10226 return OK;
10227}
10228
10229 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010230put_setbool(
10231 FILE *fd,
10232 char *cmd,
10233 char *name,
10234 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010235{
Bram Moolenaar893de922007-10-02 18:40:57 +000010236 if (value < 0) /* global/local option using global value */
10237 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010238 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10239 || put_eol(fd) < 0)
10240 return FAIL;
10241 return OK;
10242}
10243
10244/*
10245 * Clear all the terminal options.
10246 * If the option has been allocated, free the memory.
10247 * Terminal options are never hidden or indirect.
10248 */
10249 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010250clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252 /*
10253 * Reset a few things before clearing the old options. This may cause
10254 * outputting a few things that the terminal doesn't understand, but the
10255 * screen will be cleared later, so this is OK.
10256 */
10257#ifdef FEAT_MOUSE_TTY
10258 mch_setmouse(FALSE); /* switch mouse off */
10259#endif
10260#ifdef FEAT_TITLE
10261 mch_restore_title(3); /* restore window titles */
10262#endif
10263#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10264 /* When starting the GUI close the display opened for the clipboard.
10265 * After restoring the title, because that will need the display. */
10266 if (gui.starting)
10267 clear_xterm_clip();
10268#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010269 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010271 free_termoptions();
10272}
10273
10274 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010275free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010276{
10277 struct vimoption *p;
10278
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279 for (p = &options[0]; p->fullname != NULL; p++)
10280 if (istermoption(p))
10281 {
10282 if (p->flags & P_ALLOCED)
10283 free_string_option(*(char_u **)(p->var));
10284 if (p->flags & P_DEF_ALLOCED)
10285 free_string_option(p->def_val[VI_DEFAULT]);
10286 *(char_u **)(p->var) = empty_option;
10287 p->def_val[VI_DEFAULT] = empty_option;
10288 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10289 }
10290 clear_termcodes();
10291}
10292
10293/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010294 * Free the string for one term option, if it was allocated.
10295 * Set the string to empty_option and clear allocated flag.
10296 * "var" points to the option value.
10297 */
10298 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010299free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010300{
10301 struct vimoption *p;
10302
10303 for (p = &options[0]; p->fullname != NULL; p++)
10304 if (p->var == var)
10305 {
10306 if (p->flags & P_ALLOCED)
10307 free_string_option(*(char_u **)(p->var));
10308 *(char_u **)(p->var) = empty_option;
10309 p->flags &= ~P_ALLOCED;
10310 break;
10311 }
10312}
10313
10314/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 * Set the terminal option defaults to the current value.
10316 * Used after setting the terminal name.
10317 */
10318 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010319set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320{
10321 struct vimoption *p;
10322
10323 for (p = &options[0]; p->fullname != NULL; p++)
10324 {
10325 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10326 {
10327 if (p->flags & P_DEF_ALLOCED)
10328 {
10329 free_string_option(p->def_val[VI_DEFAULT]);
10330 p->flags &= ~P_DEF_ALLOCED;
10331 }
10332 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10333 if (p->flags & P_ALLOCED)
10334 {
10335 p->flags |= P_DEF_ALLOCED;
10336 p->flags &= ~P_ALLOCED; /* don't free the value now */
10337 }
10338 }
10339 }
10340}
10341
10342/*
10343 * return TRUE if 'p' starts with 't_'
10344 */
10345 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010346istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347{
10348 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10349}
10350
10351/*
10352 * Compute columns for ruler and shown command. 'sc_col' is also used to
10353 * decide what the maximum length of a message on the status line can be.
10354 * If there is a status line for the last window, 'sc_col' is independent
10355 * of 'ru_col'.
10356 */
10357
10358#define COL_RULER 17 /* columns needed by standard ruler */
10359
10360 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010361comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010362{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010363#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010364 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365
10366 sc_col = 0;
10367 ru_col = 0;
10368 if (p_ru)
10369 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010370# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010372# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010374# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375 /* no last status line, adjust sc_col */
10376 if (!last_has_status)
10377 sc_col = ru_col;
10378 }
10379 if (p_sc)
10380 {
10381 sc_col += SHOWCMD_COLS;
10382 if (!p_ru || last_has_status) /* no need for separating space */
10383 ++sc_col;
10384 }
10385 sc_col = Columns - sc_col;
10386 ru_col = Columns - ru_col;
10387 if (sc_col <= 0) /* screen too narrow, will become a mess */
10388 sc_col = 1;
10389 if (ru_col <= 0)
10390 ru_col = 1;
10391#else
10392 sc_col = Columns;
10393 ru_col = Columns;
10394#endif
10395}
10396
10397/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010398 * Unset local option value, similar to ":set opt<".
10399 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010400 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010401unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010402{
10403 struct vimoption *p;
10404 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010405 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010406
10407 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010408 if (opt_idx < 0)
10409 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010410 p = &(options[opt_idx]);
10411
10412 switch ((int)p->indir)
10413 {
10414 /* global option with local value: use local value if it's been set */
10415 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010416 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010417 break;
10418 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010419 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010420 break;
10421 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010422 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010423 break;
10424 case PV_AR:
10425 buf->b_p_ar = -1;
10426 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010427 case PV_BKC:
10428 clear_string_option(&buf->b_p_bkc);
10429 buf->b_bkc_flags = 0;
10430 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010432 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010433 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010434 case PV_TC:
10435 clear_string_option(&buf->b_p_tc);
10436 buf->b_tc_flags = 0;
10437 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010438#ifdef FEAT_FIND_ID
10439 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010440 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010441 break;
10442 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010443 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010444 break;
10445#endif
10446#ifdef FEAT_INS_EXPAND
10447 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010448 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010449 break;
10450 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010451 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 break;
10453#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010454 case PV_FP:
10455 clear_string_option(&buf->b_p_fp);
10456 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010457#ifdef FEAT_QUICKFIX
10458 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010459 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010460 break;
10461 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010462 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010463 break;
10464 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010465 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010466 break;
10467#endif
10468#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10469 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010470 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010471 break;
10472#endif
10473#if defined(FEAT_CRYPT)
10474 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010475 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010476 break;
10477#endif
10478#ifdef FEAT_STL_OPT
10479 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010480 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010481 break;
10482#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010483 case PV_UL:
10484 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10485 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010486#ifdef FEAT_LISP
10487 case PV_LW:
10488 clear_string_option(&buf->b_p_lw);
10489 break;
10490#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010491#ifdef FEAT_MBYTE
10492 case PV_MENC:
10493 clear_string_option(&buf->b_p_menc);
10494 break;
10495#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010496 }
10497}
10498
10499/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500 * Get pointer to option variable, depending on local or global scope.
10501 */
10502 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010503get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504{
10505 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10506 {
10507 if (p->var == VAR_WIN)
10508 return (char_u *)GLOBAL_WO(get_varp(p));
10509 return p->var;
10510 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010511 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512 {
10513 switch ((int)p->indir)
10514 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010515 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010517 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10518 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10519 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010521 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10522 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10523 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010524 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010525 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010526 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010528 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10529 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530#endif
10531#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010532 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10533 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010535#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10536 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10537#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010538#if defined(FEAT_CRYPT)
10539 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10540#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010541#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010542 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010543#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010544 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010545#ifdef FEAT_LISP
10546 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10547#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010548 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010549#ifdef FEAT_MBYTE
10550 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10551#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552 }
10553 return NULL; /* "cannot happen" */
10554 }
10555 return get_varp(p);
10556}
10557
10558/*
10559 * Get pointer to option variable.
10560 */
10561 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010562get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563{
10564 /* hidden option, always return NULL */
10565 if (p->var == NULL)
10566 return NULL;
10567
10568 switch ((int)p->indir)
10569 {
10570 case PV_NONE: return p->var;
10571
10572 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010573 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010575 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010577 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010579 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010581 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010583 case PV_TC: return *curbuf->b_p_tc != NUL
10584 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010585 case PV_BKC: return *curbuf->b_p_bkc != NUL
10586 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010588 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010590 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10592#endif
10593#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010594 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010596 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10598#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010599 case PV_FP: return *curbuf->b_p_fp != NUL
10600 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010602 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010604 case PV_GP: return *curbuf->b_p_gp != NUL
10605 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10606 case PV_MP: return *curbuf->b_p_mp != NUL
10607 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010609#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10610 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10611 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10612#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010613#if defined(FEAT_CRYPT)
10614 case PV_CM: return *curbuf->b_p_cm != NUL
10615 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10616#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010617#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010618 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010619 ? (char_u *)&(curwin->w_p_stl) : p->var;
10620#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010621 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10622 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010623#ifdef FEAT_LISP
10624 case PV_LW: return *curbuf->b_p_lw != NUL
10625 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10626#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010627#ifdef FEAT_MBYTE
10628 case PV_MENC: return *curbuf->b_p_menc != NUL
10629 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631
10632#ifdef FEAT_ARABIC
10633 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10634#endif
10635 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010636#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010637 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10638#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010639#ifdef FEAT_SYN_HL
10640 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10641 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010642 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010643#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644#ifdef FEAT_DIFF
10645 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10646#endif
10647#ifdef FEAT_FOLDING
10648 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10649 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10650 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10651 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10652 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10653 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10654 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10655# ifdef FEAT_EVAL
10656 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10657 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10658# endif
10659 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10660#endif
10661 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010662 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010663#ifdef FEAT_LINEBREAK
10664 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10665#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010666 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010667 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010668#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010669 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10670#endif
10671#ifdef FEAT_RIGHTLEFT
10672 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10673 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10674#endif
10675 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10676 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10677#ifdef FEAT_LINEBREAK
10678 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010679 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10680 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010681#endif
10682#ifdef FEAT_SCROLLBIND
10683 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10684#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010685#ifdef FEAT_CURSORBIND
10686 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10687#endif
10688#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010689 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10690 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10691#endif
10692#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010693 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010694 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010695#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010696
10697 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10698 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10699#ifdef FEAT_MBYTE
10700 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010702 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10703 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10705 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10706#ifdef FEAT_CINDENT
10707 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10708 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10709 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10710#endif
10711#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10712 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10713#endif
10714#ifdef FEAT_COMMENTS
10715 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10716#endif
10717#ifdef FEAT_FOLDING
10718 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10719#endif
10720#ifdef FEAT_INS_EXPAND
10721 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10722#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010723#ifdef FEAT_COMPL_FUNC
10724 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010725 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010728 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10730#ifdef FEAT_MBYTE
10731 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10732#endif
10733 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10734#ifdef FEAT_AUTOCMD
10735 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10736#endif
10737 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010738 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10740 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10741 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10742 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10743#ifdef FEAT_FIND_ID
10744# ifdef FEAT_EVAL
10745 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10746# endif
10747#endif
10748#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10749 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10750 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10751#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010752#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010753 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755#ifdef FEAT_CRYPT
10756 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10757#endif
10758#ifdef FEAT_LISP
10759 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10760#endif
10761 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10762 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10763 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10764 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10765 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010767#ifdef FEAT_TEXTOBJ
10768 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10771#ifdef FEAT_SMARTINDENT
10772 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10773#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10776#ifdef FEAT_SEARCHPATH
10777 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10778#endif
10779 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10780#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010781 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010782 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10783#endif
10784#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010785 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10786 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10787 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788#endif
10789 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10790 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10791 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10792 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010793#ifdef FEAT_PERSISTENT_UNDO
10794 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10797#ifdef FEAT_KEYMAP
10798 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10799#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010800#ifdef FEAT_SIGNS
10801 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10802#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010803 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010804 }
10805 /* always return a valid pointer to avoid a crash! */
10806 return (char_u *)&(curbuf->b_p_wm);
10807}
10808
10809/*
10810 * Get the value of 'equalprg', either the buffer-local one or the global one.
10811 */
10812 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010813get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010814{
10815 if (*curbuf->b_p_ep == NUL)
10816 return p_ep;
10817 return curbuf->b_p_ep;
10818}
10819
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820/*
10821 * Copy options from one window to another.
10822 * Used when splitting a window.
10823 */
10824 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010825win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010826{
10827 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10828 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10829# ifdef FEAT_RIGHTLEFT
10830# ifdef FEAT_FKMAP
10831 /* Is this right? */
10832 wp_to->w_farsi = wp_from->w_farsi;
10833# endif
10834# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010835#if defined(FEAT_LINEBREAK)
10836 briopt_check(wp_to);
10837#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839
10840/*
10841 * Copy the options from one winopt_T to another.
10842 * Doesn't free the old option values in "to", use clear_winopt() for that.
10843 * The 'scroll' option is not copied, because it depends on the window height.
10844 * The 'previewwindow' option is reset, there can be only one preview window.
10845 */
10846 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010847copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848{
10849#ifdef FEAT_ARABIC
10850 to->wo_arab = from->wo_arab;
10851#endif
10852 to->wo_list = from->wo_list;
10853 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010854 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010855#ifdef FEAT_LINEBREAK
10856 to->wo_nuw = from->wo_nuw;
10857#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858#ifdef FEAT_RIGHTLEFT
10859 to->wo_rl = from->wo_rl;
10860 to->wo_rlc = vim_strsave(from->wo_rlc);
10861#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010862#ifdef FEAT_STL_OPT
10863 to->wo_stl = vim_strsave(from->wo_stl);
10864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010866#ifdef FEAT_DIFF
10867 to->wo_wrap_save = from->wo_wrap_save;
10868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869#ifdef FEAT_LINEBREAK
10870 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010871 to->wo_bri = from->wo_bri;
10872 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010873#endif
10874#ifdef FEAT_SCROLLBIND
10875 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010876 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010877#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010878#ifdef FEAT_CURSORBIND
10879 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010880 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010881#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010882#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010883 to->wo_spell = from->wo_spell;
10884#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010885#ifdef FEAT_SYN_HL
10886 to->wo_cuc = from->wo_cuc;
10887 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010888 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010889#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890#ifdef FEAT_DIFF
10891 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010892 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010893#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010894#ifdef FEAT_CONCEAL
10895 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010896 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010897#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010898#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010899 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010900 to->wo_tms = vim_strsave(from->wo_tms);
10901#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902#ifdef FEAT_FOLDING
10903 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010904 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010905 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010906 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907 to->wo_fdi = vim_strsave(from->wo_fdi);
10908 to->wo_fml = from->wo_fml;
10909 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010910 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010911 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010912 to->wo_fdm_save = from->wo_diff_saved
10913 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914 to->wo_fdn = from->wo_fdn;
10915# ifdef FEAT_EVAL
10916 to->wo_fde = vim_strsave(from->wo_fde);
10917 to->wo_fdt = vim_strsave(from->wo_fdt);
10918# endif
10919 to->wo_fmr = vim_strsave(from->wo_fmr);
10920#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010921#ifdef FEAT_SIGNS
10922 to->wo_scl = vim_strsave(from->wo_scl);
10923#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924 check_winopt(to); /* don't want NULL pointers */
10925}
10926
10927/*
10928 * Check string options in a window for a NULL value.
10929 */
10930 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010931check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932{
10933 check_winopt(&win->w_onebuf_opt);
10934 check_winopt(&win->w_allbuf_opt);
10935}
10936
10937/*
10938 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10939 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010940 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010941check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010942{
10943#ifdef FEAT_FOLDING
10944 check_string_option(&wop->wo_fdi);
10945 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010946 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947# ifdef FEAT_EVAL
10948 check_string_option(&wop->wo_fde);
10949 check_string_option(&wop->wo_fdt);
10950# endif
10951 check_string_option(&wop->wo_fmr);
10952#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010953#ifdef FEAT_SIGNS
10954 check_string_option(&wop->wo_scl);
10955#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010956#ifdef FEAT_RIGHTLEFT
10957 check_string_option(&wop->wo_rlc);
10958#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010959#ifdef FEAT_STL_OPT
10960 check_string_option(&wop->wo_stl);
10961#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010962#ifdef FEAT_SYN_HL
10963 check_string_option(&wop->wo_cc);
10964#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010965#ifdef FEAT_CONCEAL
10966 check_string_option(&wop->wo_cocu);
10967#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010968#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010969 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010970 check_string_option(&wop->wo_tms);
10971#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010972#ifdef FEAT_LINEBREAK
10973 check_string_option(&wop->wo_briopt);
10974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975}
10976
10977/*
10978 * Free the allocated memory inside a winopt_T.
10979 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010980 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010981clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982{
10983#ifdef FEAT_FOLDING
10984 clear_string_option(&wop->wo_fdi);
10985 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010986 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010987# ifdef FEAT_EVAL
10988 clear_string_option(&wop->wo_fde);
10989 clear_string_option(&wop->wo_fdt);
10990# endif
10991 clear_string_option(&wop->wo_fmr);
10992#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010993#ifdef FEAT_SIGNS
10994 clear_string_option(&wop->wo_scl);
10995#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010996#ifdef FEAT_LINEBREAK
10997 clear_string_option(&wop->wo_briopt);
10998#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010999#ifdef FEAT_RIGHTLEFT
11000 clear_string_option(&wop->wo_rlc);
11001#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011002#ifdef FEAT_STL_OPT
11003 clear_string_option(&wop->wo_stl);
11004#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011005#ifdef FEAT_SYN_HL
11006 clear_string_option(&wop->wo_cc);
11007#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011008#ifdef FEAT_CONCEAL
11009 clear_string_option(&wop->wo_cocu);
11010#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011011#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011012 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011013 clear_string_option(&wop->wo_tms);
11014#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011015}
11016
11017/*
11018 * Copy global option values to local options for one buffer.
11019 * Used when creating a new buffer and sometimes when entering a buffer.
11020 * flags:
11021 * BCO_ENTER We will enter the buf buffer.
11022 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11023 * appropriate.
11024 * BCO_NOHELP Don't copy the values to a help buffer.
11025 */
11026 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011027buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011028{
11029 int should_copy = TRUE;
11030 char_u *save_p_isk = NULL; /* init for GCC */
11031 int dont_do_help;
11032 int did_isk = FALSE;
11033
11034 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035 * Skip this when the option defaults have not been set yet. Happens when
11036 * main() allocates the first buffer.
11037 */
11038 if (p_cpo != NULL)
11039 {
11040 /*
11041 * Always copy when entering and 'cpo' contains 'S'.
11042 * Don't copy when already initialized.
11043 * Don't copy when 'cpo' contains 's' and not entering.
11044 * 'S' BCO_ENTER initialized 's' should_copy
11045 * yes yes X X TRUE
11046 * yes no yes X FALSE
11047 * no X yes X FALSE
11048 * X no no yes FALSE
11049 * X no no no TRUE
11050 * no yes no X TRUE
11051 */
11052 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11053 && (buf->b_p_initialized
11054 || (!(flags & BCO_ENTER)
11055 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11056 should_copy = FALSE;
11057
11058 if (should_copy || (flags & BCO_ALWAYS))
11059 {
11060 /* Don't copy the options specific to a help buffer when
11061 * BCO_NOHELP is given or the options were initialized already
11062 * (jumping back to a help file with CTRL-T or CTRL-O) */
11063 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11064 || buf->b_p_initialized;
11065 if (dont_do_help) /* don't free b_p_isk */
11066 {
11067 save_p_isk = buf->b_p_isk;
11068 buf->b_p_isk = NULL;
11069 }
11070 /*
11071 * Always free the allocated strings.
11072 * If not already initialized, set 'readonly' and copy 'fileformat'.
11073 */
11074 if (!buf->b_p_initialized)
11075 {
11076 free_buf_options(buf, TRUE);
11077 buf->b_p_ro = FALSE; /* don't copy readonly */
11078 buf->b_p_tx = p_tx;
11079#ifdef FEAT_MBYTE
11080 buf->b_p_fenc = vim_strsave(p_fenc);
11081#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011082 switch (*p_ffs)
11083 {
11084 case 'm':
11085 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11086 case 'd':
11087 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11088 case 'u':
11089 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11090 default:
11091 buf->b_p_ff = vim_strsave(p_ff);
11092 }
11093 if (buf->b_p_ff != NULL)
11094 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095 buf->b_p_bh = empty_option;
11096 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097 }
11098 else
11099 free_buf_options(buf, FALSE);
11100
11101 buf->b_p_ai = p_ai;
11102 buf->b_p_ai_nopaste = p_ai_nopaste;
11103 buf->b_p_sw = p_sw;
11104 buf->b_p_tw = p_tw;
11105 buf->b_p_tw_nopaste = p_tw_nopaste;
11106 buf->b_p_tw_nobin = p_tw_nobin;
11107 buf->b_p_wm = p_wm;
11108 buf->b_p_wm_nopaste = p_wm_nopaste;
11109 buf->b_p_wm_nobin = p_wm_nobin;
11110 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011111#ifdef FEAT_MBYTE
11112 buf->b_p_bomb = p_bomb;
11113#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011114 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115 buf->b_p_et = p_et;
11116 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011117 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118 buf->b_p_ml = p_ml;
11119 buf->b_p_ml_nobin = p_ml_nobin;
11120 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011121 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122#ifdef FEAT_INS_EXPAND
11123 buf->b_p_cpt = vim_strsave(p_cpt);
11124#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011125#ifdef FEAT_COMPL_FUNC
11126 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011127 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011128#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129 buf->b_p_sts = p_sts;
11130 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011131 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132#ifdef FEAT_COMMENTS
11133 buf->b_p_com = vim_strsave(p_com);
11134#endif
11135#ifdef FEAT_FOLDING
11136 buf->b_p_cms = vim_strsave(p_cms);
11137#endif
11138 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011139 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011140 buf->b_p_nf = vim_strsave(p_nf);
11141 buf->b_p_mps = vim_strsave(p_mps);
11142#ifdef FEAT_SMARTINDENT
11143 buf->b_p_si = p_si;
11144#endif
11145 buf->b_p_ci = p_ci;
11146#ifdef FEAT_CINDENT
11147 buf->b_p_cin = p_cin;
11148 buf->b_p_cink = vim_strsave(p_cink);
11149 buf->b_p_cino = vim_strsave(p_cino);
11150#endif
11151#ifdef FEAT_AUTOCMD
11152 /* Don't copy 'filetype', it must be detected */
11153 buf->b_p_ft = empty_option;
11154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155 buf->b_p_pi = p_pi;
11156#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11157 buf->b_p_cinw = vim_strsave(p_cinw);
11158#endif
11159#ifdef FEAT_LISP
11160 buf->b_p_lisp = p_lisp;
11161#endif
11162#ifdef FEAT_SYN_HL
11163 /* Don't copy 'syntax', it must be set */
11164 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011165 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011166 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011167#endif
11168#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011169 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011170 (void)compile_cap_prog(&buf->b_s);
11171 buf->b_s.b_p_spf = vim_strsave(p_spf);
11172 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173#endif
11174#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11175 buf->b_p_inde = vim_strsave(p_inde);
11176 buf->b_p_indk = vim_strsave(p_indk);
11177#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011178 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011179#if defined(FEAT_EVAL)
11180 buf->b_p_fex = vim_strsave(p_fex);
11181#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011182#ifdef FEAT_CRYPT
11183 buf->b_p_key = vim_strsave(p_key);
11184#endif
11185#ifdef FEAT_SEARCHPATH
11186 buf->b_p_sua = vim_strsave(p_sua);
11187#endif
11188#ifdef FEAT_KEYMAP
11189 buf->b_p_keymap = vim_strsave(p_keymap);
11190 buf->b_kmap_state |= KEYMAP_INIT;
11191#endif
11192 /* This isn't really an option, but copying the langmap and IME
11193 * state from the current buffer is better than resetting it. */
11194 buf->b_p_iminsert = p_iminsert;
11195 buf->b_p_imsearch = p_imsearch;
11196
11197 /* options that are normally global but also have a local value
11198 * are not copied, start using the global value */
11199 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011200 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011201 buf->b_p_bkc = empty_option;
11202 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011203#ifdef FEAT_QUICKFIX
11204 buf->b_p_gp = empty_option;
11205 buf->b_p_mp = empty_option;
11206 buf->b_p_efm = empty_option;
11207#endif
11208 buf->b_p_ep = empty_option;
11209 buf->b_p_kp = empty_option;
11210 buf->b_p_path = empty_option;
11211 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011212 buf->b_p_tc = empty_option;
11213 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011214#ifdef FEAT_FIND_ID
11215 buf->b_p_def = empty_option;
11216 buf->b_p_inc = empty_option;
11217# ifdef FEAT_EVAL
11218 buf->b_p_inex = vim_strsave(p_inex);
11219# endif
11220#endif
11221#ifdef FEAT_INS_EXPAND
11222 buf->b_p_dict = empty_option;
11223 buf->b_p_tsr = empty_option;
11224#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011225#ifdef FEAT_TEXTOBJ
11226 buf->b_p_qe = vim_strsave(p_qe);
11227#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011228#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11229 buf->b_p_bexpr = empty_option;
11230#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011231#if defined(FEAT_CRYPT)
11232 buf->b_p_cm = empty_option;
11233#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011234#ifdef FEAT_PERSISTENT_UNDO
11235 buf->b_p_udf = p_udf;
11236#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011237#ifdef FEAT_LISP
11238 buf->b_p_lw = empty_option;
11239#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011240#ifdef FEAT_MBYTE
11241 buf->b_p_menc = empty_option;
11242#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011243
11244 /*
11245 * Don't copy the options set by ex_help(), use the saved values,
11246 * when going from a help buffer to a non-help buffer.
11247 * Don't touch these at all when BCO_NOHELP is used and going from
11248 * or to a help buffer.
11249 */
11250 if (dont_do_help)
11251 buf->b_p_isk = save_p_isk;
11252 else
11253 {
11254 buf->b_p_isk = vim_strsave(p_isk);
11255 did_isk = TRUE;
11256 buf->b_p_ts = p_ts;
11257 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011258 if (buf->b_p_bt[0] == 'h')
11259 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011260 buf->b_p_ma = p_ma;
11261 }
11262 }
11263
11264 /*
11265 * When the options should be copied (ignoring BCO_ALWAYS), set the
11266 * flag that indicates that the options have been initialized.
11267 */
11268 if (should_copy)
11269 buf->b_p_initialized = TRUE;
11270 }
11271
11272 check_buf_options(buf); /* make sure we don't have NULLs */
11273 if (did_isk)
11274 (void)buf_init_chartab(buf, FALSE);
11275}
11276
11277/*
11278 * Reset the 'modifiable' option and its default value.
11279 */
11280 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011281reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011282{
11283 int opt_idx;
11284
11285 curbuf->b_p_ma = FALSE;
11286 p_ma = FALSE;
11287 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011288 if (opt_idx >= 0)
11289 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011290}
11291
11292/*
11293 * Set the global value for 'iminsert' to the local value.
11294 */
11295 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011296set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011297{
11298 p_iminsert = curbuf->b_p_iminsert;
11299}
11300
11301/*
11302 * Set the global value for 'imsearch' to the local value.
11303 */
11304 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011305set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011306{
11307 p_imsearch = curbuf->b_p_imsearch;
11308}
11309
11310#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11311static int expand_option_idx = -1;
11312static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11313static int expand_option_flags = 0;
11314
11315 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011316set_context_in_set_cmd(
11317 expand_T *xp,
11318 char_u *arg,
11319 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011320{
11321 int nextchar;
11322 long_u flags = 0; /* init for GCC */
11323 int opt_idx = 0; /* init for GCC */
11324 char_u *p;
11325 char_u *s;
11326 int is_term_option = FALSE;
11327 int key;
11328
11329 expand_option_flags = opt_flags;
11330
11331 xp->xp_context = EXPAND_SETTINGS;
11332 if (*arg == NUL)
11333 {
11334 xp->xp_pattern = arg;
11335 return;
11336 }
11337 p = arg + STRLEN(arg) - 1;
11338 if (*p == ' ' && *(p - 1) != '\\')
11339 {
11340 xp->xp_pattern = p + 1;
11341 return;
11342 }
11343 while (p > arg)
11344 {
11345 s = p;
11346 /* count number of backslashes before ' ' or ',' */
11347 if (*p == ' ' || *p == ',')
11348 {
11349 while (s > arg && *(s - 1) == '\\')
11350 --s;
11351 }
11352 /* break at a space with an even number of backslashes */
11353 if (*p == ' ' && ((p - s) & 1) == 0)
11354 {
11355 ++p;
11356 break;
11357 }
11358 --p;
11359 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011360 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011361 {
11362 xp->xp_context = EXPAND_BOOL_SETTINGS;
11363 p += 2;
11364 }
11365 if (STRNCMP(p, "inv", 3) == 0)
11366 {
11367 xp->xp_context = EXPAND_BOOL_SETTINGS;
11368 p += 3;
11369 }
11370 xp->xp_pattern = arg = p;
11371 if (*arg == '<')
11372 {
11373 while (*p != '>')
11374 if (*p++ == NUL) /* expand terminal option name */
11375 return;
11376 key = get_special_key_code(arg + 1);
11377 if (key == 0) /* unknown name */
11378 {
11379 xp->xp_context = EXPAND_NOTHING;
11380 return;
11381 }
11382 nextchar = *++p;
11383 is_term_option = TRUE;
11384 expand_option_name[2] = KEY2TERMCAP0(key);
11385 expand_option_name[3] = KEY2TERMCAP1(key);
11386 }
11387 else
11388 {
11389 if (p[0] == 't' && p[1] == '_')
11390 {
11391 p += 2;
11392 if (*p != NUL)
11393 ++p;
11394 if (*p == NUL)
11395 return; /* expand option name */
11396 nextchar = *++p;
11397 is_term_option = TRUE;
11398 expand_option_name[2] = p[-2];
11399 expand_option_name[3] = p[-1];
11400 }
11401 else
11402 {
11403 /* Allow * wildcard */
11404 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11405 p++;
11406 if (*p == NUL)
11407 return;
11408 nextchar = *p;
11409 *p = NUL;
11410 opt_idx = findoption(arg);
11411 *p = nextchar;
11412 if (opt_idx == -1 || options[opt_idx].var == NULL)
11413 {
11414 xp->xp_context = EXPAND_NOTHING;
11415 return;
11416 }
11417 flags = options[opt_idx].flags;
11418 if (flags & P_BOOL)
11419 {
11420 xp->xp_context = EXPAND_NOTHING;
11421 return;
11422 }
11423 }
11424 }
11425 /* handle "-=" and "+=" */
11426 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11427 {
11428 ++p;
11429 nextchar = '=';
11430 }
11431 if ((nextchar != '=' && nextchar != ':')
11432 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11433 {
11434 xp->xp_context = EXPAND_UNSUCCESSFUL;
11435 return;
11436 }
11437 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11438 {
11439 xp->xp_context = EXPAND_OLD_SETTING;
11440 if (is_term_option)
11441 expand_option_idx = -1;
11442 else
11443 expand_option_idx = opt_idx;
11444 xp->xp_pattern = p + 1;
11445 return;
11446 }
11447 xp->xp_context = EXPAND_NOTHING;
11448 if (is_term_option || (flags & P_NUM))
11449 return;
11450
11451 xp->xp_pattern = p + 1;
11452
11453 if (flags & P_EXPAND)
11454 {
11455 p = options[opt_idx].var;
11456 if (p == (char_u *)&p_bdir
11457 || p == (char_u *)&p_dir
11458 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011459 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011460 || p == (char_u *)&p_rtp
11461#ifdef FEAT_SEARCHPATH
11462 || p == (char_u *)&p_cdpath
11463#endif
11464#ifdef FEAT_SESSION
11465 || p == (char_u *)&p_vdir
11466#endif
11467 )
11468 {
11469 xp->xp_context = EXPAND_DIRECTORIES;
11470 if (p == (char_u *)&p_path
11471#ifdef FEAT_SEARCHPATH
11472 || p == (char_u *)&p_cdpath
11473#endif
11474 )
11475 xp->xp_backslash = XP_BS_THREE;
11476 else
11477 xp->xp_backslash = XP_BS_ONE;
11478 }
11479 else
11480 {
11481 xp->xp_context = EXPAND_FILES;
11482 /* for 'tags' need three backslashes for a space */
11483 if (p == (char_u *)&p_tags)
11484 xp->xp_backslash = XP_BS_THREE;
11485 else
11486 xp->xp_backslash = XP_BS_ONE;
11487 }
11488 }
11489
11490 /* For an option that is a list of file names, find the start of the
11491 * last file name. */
11492 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11493 {
11494 /* count number of backslashes before ' ' or ',' */
11495 if (*p == ' ' || *p == ',')
11496 {
11497 s = p;
11498 while (s > xp->xp_pattern && *(s - 1) == '\\')
11499 --s;
11500 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11501 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11502 {
11503 xp->xp_pattern = p + 1;
11504 break;
11505 }
11506 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011507
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011508#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011509 /* for 'spellsuggest' start at "file:" */
11510 if (options[opt_idx].var == (char_u *)&p_sps
11511 && STRNCMP(p, "file:", 5) == 0)
11512 {
11513 xp->xp_pattern = p + 5;
11514 break;
11515 }
11516#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011517 }
11518
11519 return;
11520}
11521
11522 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011523ExpandSettings(
11524 expand_T *xp,
11525 regmatch_T *regmatch,
11526 int *num_file,
11527 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528{
11529 int num_normal = 0; /* Nr of matching non-term-code settings */
11530 int num_term = 0; /* Nr of matching terminal code settings */
11531 int opt_idx;
11532 int match;
11533 int count = 0;
11534 char_u *str;
11535 int loop;
11536 int is_term_opt;
11537 char_u name_buf[MAX_KEY_NAME_LEN];
11538 static char *(names[]) = {"all", "termcap"};
11539 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11540
11541 /* do this loop twice:
11542 * loop == 0: count the number of matching options
11543 * loop == 1: copy the matching options into allocated memory
11544 */
11545 for (loop = 0; loop <= 1; ++loop)
11546 {
11547 regmatch->rm_ic = ic;
11548 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11549 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011550 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11551 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011552 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11553 {
11554 if (loop == 0)
11555 num_normal++;
11556 else
11557 (*file)[count++] = vim_strsave((char_u *)names[match]);
11558 }
11559 }
11560 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11561 opt_idx++)
11562 {
11563 if (options[opt_idx].var == NULL)
11564 continue;
11565 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11566 && !(options[opt_idx].flags & P_BOOL))
11567 continue;
11568 is_term_opt = istermoption(&options[opt_idx]);
11569 if (is_term_opt && num_normal > 0)
11570 continue;
11571 match = FALSE;
11572 if (vim_regexec(regmatch, str, (colnr_T)0)
11573 || (options[opt_idx].shortname != NULL
11574 && vim_regexec(regmatch,
11575 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11576 match = TRUE;
11577 else if (is_term_opt)
11578 {
11579 name_buf[0] = '<';
11580 name_buf[1] = 't';
11581 name_buf[2] = '_';
11582 name_buf[3] = str[2];
11583 name_buf[4] = str[3];
11584 name_buf[5] = '>';
11585 name_buf[6] = NUL;
11586 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11587 {
11588 match = TRUE;
11589 str = name_buf;
11590 }
11591 }
11592 if (match)
11593 {
11594 if (loop == 0)
11595 {
11596 if (is_term_opt)
11597 num_term++;
11598 else
11599 num_normal++;
11600 }
11601 else
11602 (*file)[count++] = vim_strsave(str);
11603 }
11604 }
11605 /*
11606 * Check terminal key codes, these are not in the option table
11607 */
11608 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11609 {
11610 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11611 {
11612 if (!isprint(str[0]) || !isprint(str[1]))
11613 continue;
11614
11615 name_buf[0] = 't';
11616 name_buf[1] = '_';
11617 name_buf[2] = str[0];
11618 name_buf[3] = str[1];
11619 name_buf[4] = NUL;
11620
11621 match = FALSE;
11622 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11623 match = TRUE;
11624 else
11625 {
11626 name_buf[0] = '<';
11627 name_buf[1] = 't';
11628 name_buf[2] = '_';
11629 name_buf[3] = str[0];
11630 name_buf[4] = str[1];
11631 name_buf[5] = '>';
11632 name_buf[6] = NUL;
11633
11634 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11635 match = TRUE;
11636 }
11637 if (match)
11638 {
11639 if (loop == 0)
11640 num_term++;
11641 else
11642 (*file)[count++] = vim_strsave(name_buf);
11643 }
11644 }
11645
11646 /*
11647 * Check special key names.
11648 */
11649 regmatch->rm_ic = TRUE; /* ignore case here */
11650 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11651 {
11652 name_buf[0] = '<';
11653 STRCPY(name_buf + 1, str);
11654 STRCAT(name_buf, ">");
11655
11656 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11657 {
11658 if (loop == 0)
11659 num_term++;
11660 else
11661 (*file)[count++] = vim_strsave(name_buf);
11662 }
11663 }
11664 }
11665 if (loop == 0)
11666 {
11667 if (num_normal > 0)
11668 *num_file = num_normal;
11669 else if (num_term > 0)
11670 *num_file = num_term;
11671 else
11672 return OK;
11673 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11674 if (*file == NULL)
11675 {
11676 *file = (char_u **)"";
11677 return FAIL;
11678 }
11679 }
11680 }
11681 return OK;
11682}
11683
11684 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011685ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011686{
11687 char_u *var = NULL; /* init for GCC */
11688 char_u *buf;
11689
11690 *num_file = 0;
11691 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11692 if (*file == NULL)
11693 return FAIL;
11694
11695 /*
11696 * For a terminal key code expand_option_idx is < 0.
11697 */
11698 if (expand_option_idx < 0)
11699 {
11700 var = find_termcode(expand_option_name + 2);
11701 if (var == NULL)
11702 expand_option_idx = findoption(expand_option_name);
11703 }
11704
11705 if (expand_option_idx >= 0)
11706 {
11707 /* put string of option value in NameBuff */
11708 option_value2string(&options[expand_option_idx], expand_option_flags);
11709 var = NameBuff;
11710 }
11711 else if (var == NULL)
11712 var = (char_u *)"";
11713
11714 /* A backslash is required before some characters. This is the reverse of
11715 * what happens in do_set(). */
11716 buf = vim_strsave_escaped(var, escape_chars);
11717
11718 if (buf == NULL)
11719 {
11720 vim_free(*file);
11721 *file = NULL;
11722 return FAIL;
11723 }
11724
11725#ifdef BACKSLASH_IN_FILENAME
11726 /* For MS-Windows et al. we don't double backslashes at the start and
11727 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011728 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011729 if (var[0] == '\\' && var[1] == '\\'
11730 && expand_option_idx >= 0
11731 && (options[expand_option_idx].flags & P_EXPAND)
11732 && vim_isfilec(var[2])
11733 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011734 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735#endif
11736
11737 *file[0] = buf;
11738 *num_file = 1;
11739 return OK;
11740}
11741#endif
11742
11743/*
11744 * Get the value for the numeric or string option *opp in a nice format into
11745 * NameBuff[]. Must not be called with a hidden option!
11746 */
11747 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011748option_value2string(
11749 struct vimoption *opp,
11750 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011751{
11752 char_u *varp;
11753
11754 varp = get_varp_scope(opp, opt_flags);
11755
11756 if (opp->flags & P_NUM)
11757 {
11758 long wc = 0;
11759
11760 if (wc_use_keyname(varp, &wc))
11761 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11762 else if (wc != 0)
11763 STRCPY(NameBuff, transchar((int)wc));
11764 else
11765 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11766 }
11767 else /* P_STRING */
11768 {
11769 varp = *(char_u **)(varp);
11770 if (varp == NULL) /* just in case */
11771 NameBuff[0] = NUL;
11772#ifdef FEAT_CRYPT
11773 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011774 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011775 STRCPY(NameBuff, "*****");
11776#endif
11777 else if (opp->flags & P_EXPAND)
11778 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11779 /* Translate 'pastetoggle' into special key names */
11780 else if ((char_u **)opp->var == &p_pt)
11781 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11782 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011783 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784 }
11785}
11786
11787/*
11788 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11789 * printed as a keyname.
11790 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11791 */
11792 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011793wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794{
11795 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11796 {
11797 *wcp = *(long *)varp;
11798 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11799 return TRUE;
11800 }
11801 return FALSE;
11802}
11803
Bram Moolenaar01615492015-02-03 13:00:38 +010011804#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011806 * Any character has an equivalent 'langmap' character. This is used for
11807 * keyboards that have a special language mode that sends characters above
11808 * 128 (although other characters can be translated too). The "to" field is a
11809 * Vim command character. This avoids having to switch the keyboard back to
11810 * ASCII mode when leaving Insert mode.
11811 *
11812 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11813 * commands.
11814 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11815 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11816 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011817 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011818# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011819/*
11820 * With multi-byte support use growarray for 'langmap' chars >= 256
11821 */
11822typedef struct
11823{
11824 int from;
11825 int to;
11826} langmap_entry_T;
11827
11828static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011829static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011830
11831/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011832 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11833 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011834 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011835 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011836langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011837{
11838 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011839 int a = 0;
11840 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011841
11842 /* Do a binary search for an existing entry. */
11843 while (a != b)
11844 {
11845 int i = (a + b) / 2;
11846 int d = entries[i].from - from;
11847
11848 if (d == 0)
11849 {
11850 entries[i].to = to;
11851 return;
11852 }
11853 if (d < 0)
11854 a = i + 1;
11855 else
11856 b = i;
11857 }
11858
11859 if (ga_grow(&langmap_mapga, 1) != OK)
11860 return; /* out of memory */
11861
11862 /* insert new entry at position "a" */
11863 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11864 mch_memmove(entries + 1, entries,
11865 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11866 ++langmap_mapga.ga_len;
11867 entries[0].from = from;
11868 entries[0].to = to;
11869}
11870
11871/*
11872 * Apply 'langmap' to multi-byte character "c" and return the result.
11873 */
11874 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011875langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011876{
11877 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11878 int a = 0;
11879 int b = langmap_mapga.ga_len;
11880
11881 while (a != b)
11882 {
11883 int i = (a + b) / 2;
11884 int d = entries[i].from - c;
11885
11886 if (d == 0)
11887 return entries[i].to; /* found matching entry */
11888 if (d < 0)
11889 a = i + 1;
11890 else
11891 b = i;
11892 }
11893 return c; /* no entry found, return "c" unmodified */
11894}
11895# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011896
11897 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011898langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011899{
11900 int i;
11901
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011902 for (i = 0; i < 256; i++)
11903 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11904# ifdef FEAT_MBYTE
11905 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11906# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011907}
11908
11909/*
11910 * Called when langmap option is set; the language map can be
11911 * changed at any time!
11912 */
11913 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011914langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915{
11916 char_u *p;
11917 char_u *p2;
11918 int from, to;
11919
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011920#ifdef FEAT_MBYTE
11921 ga_clear(&langmap_mapga); /* clear the previous map first */
11922#endif
11923 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011924
11925 for (p = p_langmap; p[0] != NUL; )
11926 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011927 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011928 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011929 {
11930 if (p2[0] == '\\' && p2[1] != NUL)
11931 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932 }
11933 if (p2[0] == ';')
11934 ++p2; /* abcd;ABCD form, p2 points to A */
11935 else
11936 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11937 while (p[0])
11938 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011939 if (p[0] == ',')
11940 {
11941 ++p;
11942 break;
11943 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011944 if (p[0] == '\\' && p[1] != NUL)
11945 ++p;
11946#ifdef FEAT_MBYTE
11947 from = (*mb_ptr2char)(p);
11948#else
11949 from = p[0];
11950#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011951 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011952 if (p2 == NULL)
11953 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011954 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011955 if (p[0] != ',')
11956 {
11957 if (p[0] == '\\')
11958 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011959#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011960 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011961#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011962 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011964 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965 }
11966 else
11967 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011968 if (p2[0] != ',')
11969 {
11970 if (p2[0] == '\\')
11971 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011972#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011973 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011974#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011975 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011976#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011977 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978 }
11979 if (to == NUL)
11980 {
11981 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11982 transchar(from));
11983 return;
11984 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011985
11986#ifdef FEAT_MBYTE
11987 if (from >= 256)
11988 langmap_set_entry(from, to);
11989 else
11990#endif
11991 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011992
11993 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011994 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011995 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011997 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011998 if (*p == ';')
11999 {
12000 p = p2;
12001 if (p[0] != NUL)
12002 {
12003 if (p[0] != ',')
12004 {
12005 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12006 return;
12007 }
12008 ++p;
12009 }
12010 break;
12011 }
12012 }
12013 }
12014 }
12015}
12016#endif
12017
12018/*
12019 * Return TRUE if format option 'x' is in effect.
12020 * Take care of no formatting when 'paste' is set.
12021 */
12022 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012023has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012024{
12025 if (p_paste)
12026 return FALSE;
12027 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12028}
12029
12030/*
12031 * Return TRUE if "x" is present in 'shortmess' option, or
12032 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12033 */
12034 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012035shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012037 return p_shm != NULL &&
12038 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012039 || (vim_strchr(p_shm, 'a') != NULL
12040 && vim_strchr((char_u *)SHM_A, x) != NULL));
12041}
12042
12043/*
12044 * paste_option_changed() - Called after p_paste was set or reset.
12045 */
12046 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012047paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012048{
12049 static int old_p_paste = FALSE;
12050 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012051 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012052#ifdef FEAT_CMDL_INFO
12053 static int save_ru = 0;
12054#endif
12055#ifdef FEAT_RIGHTLEFT
12056 static int save_ri = 0;
12057 static int save_hkmap = 0;
12058#endif
12059 buf_T *buf;
12060
12061 if (p_paste)
12062 {
12063 /*
12064 * Paste switched from off to on.
12065 * Save the current values, so they can be restored later.
12066 */
12067 if (!old_p_paste)
12068 {
12069 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012070 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012071 {
12072 buf->b_p_tw_nopaste = buf->b_p_tw;
12073 buf->b_p_wm_nopaste = buf->b_p_wm;
12074 buf->b_p_sts_nopaste = buf->b_p_sts;
12075 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012076 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012077 }
12078
12079 /* save global options */
12080 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012081 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012082#ifdef FEAT_CMDL_INFO
12083 save_ru = p_ru;
12084#endif
12085#ifdef FEAT_RIGHTLEFT
12086 save_ri = p_ri;
12087 save_hkmap = p_hkmap;
12088#endif
12089 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012090 p_ai_nopaste = p_ai;
12091 p_et_nopaste = p_et;
12092 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012093 p_tw_nopaste = p_tw;
12094 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 }
12096
12097 /*
12098 * Always set the option values, also when 'paste' is set when it is
12099 * already on.
12100 */
12101 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012102 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 {
12104 buf->b_p_tw = 0; /* textwidth is 0 */
12105 buf->b_p_wm = 0; /* wrapmargin is 0 */
12106 buf->b_p_sts = 0; /* softtabstop is 0 */
12107 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012108 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109 }
12110
12111 /* set global options */
12112 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012113 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012114#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012115 if (p_ru)
12116 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012117 p_ru = 0; /* no ruler */
12118#endif
12119#ifdef FEAT_RIGHTLEFT
12120 p_ri = 0; /* no reverse insert */
12121 p_hkmap = 0; /* no Hebrew keyboard */
12122#endif
12123 /* set global values for local buffer options */
12124 p_tw = 0;
12125 p_wm = 0;
12126 p_sts = 0;
12127 p_ai = 0;
12128 }
12129
12130 /*
12131 * Paste switched from on to off: Restore saved values.
12132 */
12133 else if (old_p_paste)
12134 {
12135 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012136 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012137 {
12138 buf->b_p_tw = buf->b_p_tw_nopaste;
12139 buf->b_p_wm = buf->b_p_wm_nopaste;
12140 buf->b_p_sts = buf->b_p_sts_nopaste;
12141 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012142 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012143 }
12144
12145 /* restore global options */
12146 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012147 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012148#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 if (p_ru != save_ru)
12150 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012151 p_ru = save_ru;
12152#endif
12153#ifdef FEAT_RIGHTLEFT
12154 p_ri = save_ri;
12155 p_hkmap = save_hkmap;
12156#endif
12157 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012158 p_ai = p_ai_nopaste;
12159 p_et = p_et_nopaste;
12160 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161 p_tw = p_tw_nopaste;
12162 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012163 }
12164
12165 old_p_paste = p_paste;
12166}
12167
12168/*
12169 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12170 *
12171 * Reset 'compatible' and set the values for options that didn't get set yet
12172 * to the Vim defaults.
12173 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012174 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175 */
12176 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012177vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012178{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012179 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012180 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012181 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012182
12183 if (!option_was_set((char_u *)"cp"))
12184 {
12185 p_cp = FALSE;
12186 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12187 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12188 set_option_default(opt_idx, OPT_FREE, FALSE);
12189 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012190 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012191 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012192
12193 if (fname != NULL)
12194 {
12195 p = vim_getenv(envname, &dofree);
12196 if (p == NULL)
12197 {
12198 /* Set $MYVIMRC to the first vimrc file found. */
12199 p = FullName_save(fname, FALSE);
12200 if (p != NULL)
12201 {
12202 vim_setenv(envname, p);
12203 vim_free(p);
12204 }
12205 }
12206 else if (dofree)
12207 vim_free(p);
12208 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209}
12210
12211/*
12212 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12213 */
12214 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012215change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012216{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012217 int opt_idx;
12218
Bram Moolenaar071d4272004-06-13 20:20:40 +000012219 if (p_cp != on)
12220 {
12221 p_cp = on;
12222 compatible_set();
12223 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012224 opt_idx = findoption((char_u *)"cp");
12225 if (opt_idx >= 0)
12226 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012227}
12228
12229/*
12230 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012231 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012232 */
12233 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012234option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012235{
12236 int idx;
12237
12238 idx = findoption(name);
12239 if (idx < 0) /* unknown option */
12240 return FALSE;
12241 if (options[idx].flags & P_WAS_SET)
12242 return TRUE;
12243 return FALSE;
12244}
12245
12246/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012247 * Reset the flag indicating option "name" was set.
12248 */
12249 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012250reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012251{
12252 int idx = findoption(name);
12253
12254 if (idx >= 0)
12255 options[idx].flags &= ~P_WAS_SET;
12256}
12257
12258/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259 * compatible_set() - Called when 'compatible' has been set or unset.
12260 *
12261 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12262 * flag) to a Vi compatible value.
12263 * When 'compatible' is unset: Set all options that have a different default
12264 * for Vim (without the P_VI_DEF flag) to that default.
12265 */
12266 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012267compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012268{
12269 int opt_idx;
12270
12271 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12272 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12273 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12274 set_option_default(opt_idx, OPT_FREE, p_cp);
12275 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012276 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012277}
12278
12279#ifdef FEAT_LINEBREAK
12280
12281# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12282 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012283 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012284# endif
12285
12286/*
12287 * fill_breakat_flags() -- called when 'breakat' changes value.
12288 */
12289 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012290fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012291{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012292 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012293 int i;
12294
12295 for (i = 0; i < 256; i++)
12296 breakat_flags[i] = FALSE;
12297
12298 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012299 for (p = p_breakat; *p; p++)
12300 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012301}
12302
12303# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012304 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012305# endif
12306
12307#endif
12308
12309/*
12310 * Check an option that can be a range of string values.
12311 *
12312 * Return OK for correct value, FAIL otherwise.
12313 * Empty is always OK.
12314 */
12315 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012316check_opt_strings(
12317 char_u *val,
12318 char **values,
12319 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012320{
12321 return opt_strings_flags(val, values, NULL, list);
12322}
12323
12324/*
12325 * Handle an option that can be a range of string values.
12326 * Set a flag in "*flagp" for each string present.
12327 *
12328 * Return OK for correct value, FAIL otherwise.
12329 * Empty is always OK.
12330 */
12331 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012332opt_strings_flags(
12333 char_u *val, /* new value */
12334 char **values, /* array of valid string values */
12335 unsigned *flagp,
12336 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012337{
12338 int i;
12339 int len;
12340 unsigned new_flags = 0;
12341
12342 while (*val)
12343 {
12344 for (i = 0; ; ++i)
12345 {
12346 if (values[i] == NULL) /* val not found in values[] */
12347 return FAIL;
12348
12349 len = (int)STRLEN(values[i]);
12350 if (STRNCMP(values[i], val, len) == 0
12351 && ((list && val[len] == ',') || val[len] == NUL))
12352 {
12353 val += len + (val[len] == ',');
12354 new_flags |= (1 << i);
12355 break; /* check next item in val list */
12356 }
12357 }
12358 }
12359 if (flagp != NULL)
12360 *flagp = new_flags;
12361
12362 return OK;
12363}
12364
12365/*
12366 * Read the 'wildmode' option, fill wim_flags[].
12367 */
12368 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012369check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012370{
12371 char_u new_wim_flags[4];
12372 char_u *p;
12373 int i;
12374 int idx = 0;
12375
12376 for (i = 0; i < 4; ++i)
12377 new_wim_flags[i] = 0;
12378
12379 for (p = p_wim; *p; ++p)
12380 {
12381 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12382 ;
12383 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12384 return FAIL;
12385 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12386 new_wim_flags[idx] |= WIM_LONGEST;
12387 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12388 new_wim_flags[idx] |= WIM_FULL;
12389 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12390 new_wim_flags[idx] |= WIM_LIST;
12391 else
12392 return FAIL;
12393 p += i;
12394 if (*p == NUL)
12395 break;
12396 if (*p == ',')
12397 {
12398 if (idx == 3)
12399 return FAIL;
12400 ++idx;
12401 }
12402 }
12403
12404 /* fill remaining entries with last flag */
12405 while (idx < 3)
12406 {
12407 new_wim_flags[idx + 1] = new_wim_flags[idx];
12408 ++idx;
12409 }
12410
12411 /* only when there are no errors, wim_flags[] is changed */
12412 for (i = 0; i < 4; ++i)
12413 wim_flags[i] = new_wim_flags[i];
12414 return OK;
12415}
12416
12417/*
12418 * Check if backspacing over something is allowed.
12419 */
12420 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012421can_bs(
12422 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012423{
12424 switch (*p_bs)
12425 {
12426 case '2': return TRUE;
12427 case '1': return (what != BS_START);
12428 case '0': return FALSE;
12429 }
12430 return vim_strchr(p_bs, what) != NULL;
12431}
12432
12433/*
12434 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12435 * the file must be considered changed when the value is different.
12436 */
12437 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012438save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012439{
12440 buf->b_start_ffc = *buf->b_p_ff;
12441 buf->b_start_eol = buf->b_p_eol;
12442#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012443 buf->b_start_bomb = buf->b_p_bomb;
12444
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445 /* Only use free/alloc when necessary, they take time. */
12446 if (buf->b_start_fenc == NULL
12447 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12448 {
12449 vim_free(buf->b_start_fenc);
12450 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12451 }
12452#endif
12453}
12454
12455/*
12456 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12457 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012458 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12459 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012460 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012461 * When "ignore_empty" is true don't consider a new, empty buffer to be
12462 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012463 */
12464 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012465file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012466{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012467 /* In a buffer that was never loaded the options are not valid. */
12468 if (buf->b_flags & BF_NEVERLOADED)
12469 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012470 if (ignore_empty
12471 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472 && buf->b_ml.ml_line_count == 1
12473 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12474 return FALSE;
12475 if (buf->b_start_ffc != *buf->b_p_ff)
12476 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012477 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012478 return TRUE;
12479#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012480 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12481 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012482 if (buf->b_start_fenc == NULL)
12483 return (*buf->b_p_fenc != NUL);
12484 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12485#else
12486 return FALSE;
12487#endif
12488}
12489
12490/*
12491 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12492 */
12493 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012494check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012495{
12496 return check_opt_strings(p, p_ff_values, FALSE);
12497}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012498
12499/*
12500 * Return the effective shiftwidth value for current buffer, using the
12501 * 'tabstop' value when 'shiftwidth' is zero.
12502 */
12503 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012504get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012505{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012506 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012507}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012508
12509/*
12510 * Return the effective softtabstop value for the current buffer, using the
12511 * 'tabstop' value when 'softtabstop' is negative.
12512 */
12513 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012514get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012515{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012516 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012517}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012518
12519/*
12520 * Check matchpairs option for "*initc".
12521 * If there is a match set "*initc" to the matching character and "*findc" to
12522 * the opposite character. Set "*backwards" to the direction.
12523 * When "switchit" is TRUE swap the direction.
12524 */
12525 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012526find_mps_values(
12527 int *initc,
12528 int *findc,
12529 int *backwards,
12530 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012531{
12532 char_u *ptr;
12533
12534 ptr = curbuf->b_p_mps;
12535 while (*ptr != NUL)
12536 {
12537#ifdef FEAT_MBYTE
12538 if (has_mbyte)
12539 {
12540 char_u *prev;
12541
12542 if (mb_ptr2char(ptr) == *initc)
12543 {
12544 if (switchit)
12545 {
12546 *findc = *initc;
12547 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12548 *backwards = TRUE;
12549 }
12550 else
12551 {
12552 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12553 *backwards = FALSE;
12554 }
12555 return;
12556 }
12557 prev = ptr;
12558 ptr += mb_ptr2len(ptr) + 1;
12559 if (mb_ptr2char(ptr) == *initc)
12560 {
12561 if (switchit)
12562 {
12563 *findc = *initc;
12564 *initc = mb_ptr2char(prev);
12565 *backwards = FALSE;
12566 }
12567 else
12568 {
12569 *findc = mb_ptr2char(prev);
12570 *backwards = TRUE;
12571 }
12572 return;
12573 }
12574 ptr += mb_ptr2len(ptr);
12575 }
12576 else
12577#endif
12578 {
12579 if (*ptr == *initc)
12580 {
12581 if (switchit)
12582 {
12583 *backwards = TRUE;
12584 *findc = *initc;
12585 *initc = ptr[2];
12586 }
12587 else
12588 {
12589 *backwards = FALSE;
12590 *findc = ptr[2];
12591 }
12592 return;
12593 }
12594 ptr += 2;
12595 if (*ptr == *initc)
12596 {
12597 if (switchit)
12598 {
12599 *backwards = FALSE;
12600 *findc = *initc;
12601 *initc = ptr[-2];
12602 }
12603 else
12604 {
12605 *backwards = TRUE;
12606 *findc = ptr[-2];
12607 }
12608 return;
12609 }
12610 ++ptr;
12611 }
12612 if (*ptr == ',')
12613 ++ptr;
12614 }
12615}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012616
12617#if defined(FEAT_LINEBREAK) || defined(PROTO)
12618/*
12619 * This is called when 'breakindentopt' is changed and when a window is
12620 * initialized.
12621 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012622 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012623briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012624{
12625 char_u *p;
12626 int bri_shift = 0;
12627 long bri_min = 20;
12628 int bri_sbr = FALSE;
12629
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012630 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012631 while (*p != NUL)
12632 {
12633 if (STRNCMP(p, "shift:", 6) == 0
12634 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12635 {
12636 p += 6;
12637 bri_shift = getdigits(&p);
12638 }
12639 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12640 {
12641 p += 4;
12642 bri_min = getdigits(&p);
12643 }
12644 else if (STRNCMP(p, "sbr", 3) == 0)
12645 {
12646 p += 3;
12647 bri_sbr = TRUE;
12648 }
12649 if (*p != ',' && *p != NUL)
12650 return FAIL;
12651 if (*p == ',')
12652 ++p;
12653 }
12654
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012655 wp->w_p_brishift = bri_shift;
12656 wp->w_p_brimin = bri_min;
12657 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012658
12659 return OK;
12660}
12661#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012662
12663/*
12664 * Get the local or global value of 'backupcopy'.
12665 */
12666 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012667get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012668{
12669 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12670}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012671
12672#if defined(FEAT_SIGNS) || defined(PROTO)
12673/*
12674 * Return TRUE when window "wp" has a column to draw signs in.
12675 */
12676 int
12677signcolumn_on(win_T *wp)
12678{
12679 if (*wp->w_p_scl == 'n')
12680 return FALSE;
12681 if (*wp->w_p_scl == 'y')
12682 return TRUE;
12683 return (wp->w_buffer->b_signlist != NULL
12684# ifdef FEAT_NETBEANS_INTG
12685 || wp->w_buffer->b_has_sign_column
12686# endif
12687 );
12688}
12689#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012690
12691#if defined(FEAT_EVAL) || defined(PROTO)
12692/*
12693 * Get window or buffer local options.
12694 */
12695 dict_T *
12696get_winbuf_options(int bufopt)
12697{
12698 dict_T *d;
12699 int opt_idx;
12700
12701 d = dict_alloc();
12702 if (d == NULL)
12703 return NULL;
12704
12705 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12706 {
12707 struct vimoption *opt = &options[opt_idx];
12708
12709 if ((bufopt && (opt->indir & PV_BUF))
12710 || (!bufopt && (opt->indir & PV_WIN)))
12711 {
12712 char_u *varp = get_varp(opt);
12713
12714 if (varp != NULL)
12715 {
12716 if (opt->flags & P_STRING)
12717 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012718 else if (opt->flags & P_NUM)
12719 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012720 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012721 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012722 }
12723 }
12724 }
12725
12726 return d;
12727}
12728#endif