blob: 320bbfd7caba965913e27bd73c7c7248d7c3e751 [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,
637#ifdef FEAT_BEVAL
638 (char_u *)&p_beval, PV_NONE,
639 {(char_u *)FALSE, (char_u *)0L}
640#else
641 (char_u *)NULL, PV_NONE,
642 {(char_u *)0L, (char_u *)0L}
643#endif
644 SCRIPTID_INIT},
645 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
646#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
647 (char_u *)&p_bexpr, PV_BEXPR,
648 {(char_u *)"", (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
653 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654 {"beautify", "bf", P_BOOL|P_VI_DEF,
655 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200657 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
658 (char_u *)&p_bo, PV_NONE,
659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
661 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000662 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
667#ifdef FEAT_MBYTE
668 (char_u *)&p_bomb, PV_BOMB,
669#else
670 (char_u *)NULL, PV_NONE,
671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
674#ifdef FEAT_LINEBREAK
675 (char_u *)&p_breakat, PV_NONE,
676 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200682 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
683#ifdef FEAT_LINEBREAK
684 (char_u *)VAR_WIN, PV_BRI,
685 {(char_u *)FALSE, (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
690 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200691 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
692 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693#ifdef FEAT_LINEBREAK
694 (char_u *)VAR_WIN, PV_BRIOPT,
695 {(char_u *)"", (char_u *)NULL}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)"", (char_u *)NULL}
699#endif
700 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
702#ifdef FEAT_BROWSE
703 (char_u *)&p_bsdir, PV_NONE,
704 {(char_u *)"last", (char_u *)0L}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 (char_u *)&p_bh, PV_BH,
712 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
715 (char_u *)&p_bl, PV_BL,
716 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 (char_u *)&p_bt, PV_BT,
720 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200722 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000723#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 (char_u *)&p_cmp, PV_NONE,
725 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
732#ifdef FEAT_SEARCHPATH
733 (char_u *)&p_cdpath, PV_NONE,
734 {(char_u *)",,", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cedit", NULL, P_STRING,
741#ifdef FEAT_CMDWIN
742 (char_u *)&p_cedit, PV_NONE,
743 {(char_u *)"", (char_u *)CTRL_F_STR}
744#else
745 (char_u *)NULL, PV_NONE,
746 {(char_u *)0L, (char_u *)0L}
747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
750#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
751 (char_u *)&p_ccv, PV_NONE,
752 {(char_u *)"", (char_u *)0L}
753#else
754 (char_u *)NULL, PV_NONE,
755 {(char_u *)0L, (char_u *)0L}
756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000757 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
759#ifdef FEAT_CINDENT
760 (char_u *)&p_cin, PV_CIN,
761#else
762 (char_u *)NULL, PV_NONE,
763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200765 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766#ifdef FEAT_CINDENT
767 (char_u *)&p_cink, PV_CINK,
768 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
769#else
770 (char_u *)NULL, PV_NONE,
771 {(char_u *)0L, (char_u *)0L}
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775#ifdef FEAT_CINDENT
776 (char_u *)&p_cino, PV_CINO,
777#else
778 (char_u *)NULL, PV_NONE,
779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000780 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200781 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
783 (char_u *)&p_cinw, PV_CINW,
784 {(char_u *)"if,else,while,do,for,switch",
785 (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#ifdef FEAT_CLIPBOARD
793 (char_u *)&p_cb, PV_NONE,
794# ifdef FEAT_XCLIPBOARD
795 {(char_u *)"autoselect,exclude:cons\\|linux",
796 (char_u *)0L}
797# else
798 {(char_u *)"", (char_u *)0L}
799# endif
800#else
801 (char_u *)NULL, PV_NONE,
802 {(char_u *)"", (char_u *)0L}
803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
806 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
809#ifdef FEAT_CMDWIN
810 (char_u *)&p_cwh, PV_NONE,
811#else
812 (char_u *)NULL, PV_NONE,
813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200815 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200816#ifdef FEAT_SYN_HL
817 (char_u *)VAR_WIN, PV_CC,
818#else
819 (char_u *)NULL, PV_NONE,
820#endif
821 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
823 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200825 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
826 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827#ifdef FEAT_COMMENTS
828 (char_u *)&p_com, PV_COM,
829 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
830 (char_u *)0L}
831#else
832 (char_u *)NULL, PV_NONE,
833 {(char_u *)0L, (char_u *)0L}
834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200836 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837#ifdef FEAT_FOLDING
838 (char_u *)&p_cms, PV_CMS,
839 {(char_u *)"/*%s*/", (char_u *)0L}
840#else
841 (char_u *)NULL, PV_NONE,
842 {(char_u *)0L, (char_u *)0L}
843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000844 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000845 /* P_PRI_MKRC isn't needed here, optval_default()
846 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 {"compatible", "cp", P_BOOL|P_RALL,
848 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000849 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200850 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000851#ifdef FEAT_INS_EXPAND
852 (char_u *)&p_cpt, PV_CPT,
853 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
854#else
855 (char_u *)NULL, PV_NONE,
856 {(char_u *)0L, (char_u *)0L}
857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200859 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200860#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200861 (char_u *)VAR_WIN, PV_COCU,
862 {(char_u *)"", (char_u *)NULL}
863#else
864 (char_u *)NULL, PV_NONE,
865 {(char_u *)NULL, (char_u *)0L}
866#endif
867 SCRIPTID_INIT},
868 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
869#ifdef FEAT_CONCEAL
870 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200871#else
872 (char_u *)NULL, PV_NONE,
873#endif
874 {(char_u *)0L, (char_u *)0L}
875 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000876 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
877#ifdef FEAT_COMPL_FUNC
878 (char_u *)&p_cfu, PV_CFU,
879 {(char_u *)"", (char_u *)0L}
880#else
881 (char_u *)NULL, PV_NONE,
882 {(char_u *)0L, (char_u *)0L}
883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000884 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200885 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000886#ifdef FEAT_INS_EXPAND
887 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000888 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000889#else
890 (char_u *)NULL, PV_NONE,
891 {(char_u *)0L, (char_u *)0L}
892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000893 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894 {"confirm", "cf", P_BOOL|P_VI_DEF,
895#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
896 (char_u *)&p_confirm, PV_NONE,
897#else
898 (char_u *)NULL, PV_NONE,
899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
905 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
908 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
910 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200911 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200912#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200913 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200914 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200915#else
916 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200917 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200918#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
921#ifdef FEAT_CSCOPE
922 (char_u *)&p_cspc, PV_NONE,
923#else
924 (char_u *)NULL, PV_NONE,
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
928#ifdef FEAT_CSCOPE
929 (char_u *)&p_csprg, PV_NONE,
930 {(char_u *)"cscope", (char_u *)0L}
931#else
932 (char_u *)NULL, PV_NONE,
933 {(char_u *)0L, (char_u *)0L}
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200936 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
938 (char_u *)&p_csqf, PV_NONE,
939 {(char_u *)"", (char_u *)0L}
940#else
941 (char_u *)NULL, PV_NONE,
942 {(char_u *)0L, (char_u *)0L}
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200945 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csre, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_cst, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000958 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
960#ifdef FEAT_CSCOPE
961 (char_u *)&p_csto, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
967#ifdef FEAT_CSCOPE
968 (char_u *)&p_csverbose, PV_NONE,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200973 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
974#ifdef FEAT_CURSORBIND
975 (char_u *)VAR_WIN, PV_CRBIND,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000980 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
981#ifdef FEAT_SYN_HL
982 (char_u *)VAR_WIN, PV_CUC,
983#else
984 (char_u *)NULL, PV_NONE,
985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100987 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000988#ifdef FEAT_SYN_HL
989 (char_u *)VAR_WIN, PV_CUL,
990#else
991 (char_u *)NULL, PV_NONE,
992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 {"debug", NULL, P_STRING|P_VI_DEF,
995 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000996 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200997 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000999 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001000 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#else
1002 (char_u *)NULL, PV_NONE,
1003 {(char_u *)NULL, (char_u *)0L}
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1007#ifdef FEAT_MBYTE
1008 (char_u *)&p_deco, PV_NONE,
1009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001013 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001015 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016#else
1017 (char_u *)NULL, PV_NONE,
1018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001019 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1021#ifdef FEAT_DIFF
1022 (char_u *)VAR_WIN, PV_DIFF,
1023#else
1024 (char_u *)NULL, PV_NONE,
1025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001026 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001027 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1029 (char_u *)&p_dex, PV_NONE,
1030 {(char_u *)"", (char_u *)0L}
1031#else
1032 (char_u *)NULL, PV_NONE,
1033 {(char_u *)0L, (char_u *)0L}
1034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001036 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1037 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038#ifdef FEAT_DIFF
1039 (char_u *)&p_dip, PV_NONE,
1040 {(char_u *)"filler", (char_u *)NULL}
1041#else
1042 (char_u *)NULL, PV_NONE,
1043 {(char_u *)"", (char_u *)NULL}
1044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1047#ifdef FEAT_DIGRAPHS
1048 (char_u *)&p_dg, PV_NONE,
1049#else
1050 (char_u *)NULL, PV_NONE,
1051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1054 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001057 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001059 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061 (char_u *)&p_ead, PV_NONE,
1062 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1065 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001067 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1068#if defined(FEAT_MBYTE)
1069 (char_u *)&p_emoji, PV_NONE,
1070 {(char_u *)TRUE, (char_u *)0L}
1071#else
1072 (char_u *)NULL, PV_NONE,
1073 {(char_u *)0L, (char_u *)0L}
1074#endif
1075 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001076 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077#ifdef FEAT_MBYTE
1078 (char_u *)&p_enc, PV_NONE,
1079 {(char_u *)ENC_DFLT, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)0L, (char_u *)0L}
1083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1086 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1089 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001092 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1095 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1098#ifdef FEAT_QUICKFIX
1099 (char_u *)&p_ef, PV_NONE,
1100 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1101#else
1102 (char_u *)NULL, PV_NONE,
1103 {(char_u *)NULL, (char_u *)0L}
1104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001106 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001108 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110#else
1111 (char_u *)NULL, PV_NONE,
1112 {(char_u *)NULL, (char_u *)0L}
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"esckeys", "ek", P_BOOL|P_VIM,
1116 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001118 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119#ifdef FEAT_AUTOCMD
1120 (char_u *)&p_ei, PV_NONE,
1121#else
1122 (char_u *)NULL, PV_NONE,
1123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1126 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1129 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001131 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1132 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133#ifdef FEAT_MBYTE
1134 (char_u *)&p_fenc, PV_FENC,
1135 {(char_u *)"", (char_u *)0L}
1136#else
1137 (char_u *)NULL, PV_NONE,
1138 {(char_u *)0L, (char_u *)0L}
1139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001141 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142#ifdef FEAT_MBYTE
1143 (char_u *)&p_fencs, PV_NONE,
1144 {(char_u *)"ucs-bom", (char_u *)0L}
1145#else
1146 (char_u *)NULL, PV_NONE,
1147 {(char_u *)0L, (char_u *)0L}
1148#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001150 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1151 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001154 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1157 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001158 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1159 (char_u *)&p_fic, PV_NONE,
1160 {
1161#ifdef CASE_INSENSITIVE_FILENAME
1162 (char_u *)TRUE,
1163#else
1164 (char_u *)FALSE,
1165#endif
1166 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001167 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168#ifdef FEAT_AUTOCMD
1169 (char_u *)&p_ft, PV_FT,
1170 {(char_u *)"", (char_u *)0L}
1171#else
1172 (char_u *)NULL, PV_NONE,
1173 {(char_u *)0L, (char_u *)0L}
1174#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001176 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)&p_fcs, PV_NONE,
1178 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001180 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1181 (char_u *)&p_fixeol, PV_FIXEOL,
1182 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1184#ifdef FEAT_FKMAP
1185 (char_u *)&p_fkmap, PV_NONE,
1186#else
1187 (char_u *)NULL, PV_NONE,
1188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001189 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 {"flash", "fl", P_BOOL|P_VI_DEF,
1191 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001193 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001194#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001196 {(char_u *)"", (char_u *)0L}
1197#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)NULL, PV_NONE,
1199 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#endif
1201 SCRIPTID_INIT},
1202 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1203#ifdef FEAT_FOLDING
1204 (char_u *)VAR_WIN, PV_FDC,
1205 {(char_u *)FALSE, (char_u *)0L}
1206#else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
1209#endif
1210 SCRIPTID_INIT},
1211 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1212#ifdef FEAT_FOLDING
1213 (char_u *)VAR_WIN, PV_FEN,
1214 {(char_u *)TRUE, (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)NULL, (char_u *)0L}
1218#endif
1219 SCRIPTID_INIT},
1220 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1221#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1222 (char_u *)VAR_WIN, PV_FDE,
1223 {(char_u *)"0", (char_u *)NULL}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
1227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001228 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001230#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001232 {(char_u *)"#", (char_u *)NULL}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
1237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001239#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001241 {(char_u *)0L, (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001247 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001248#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001250 {(char_u *)-1L, (char_u *)0L}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
1255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001257 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001258#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001261#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 (char_u *)NULL, PV_NONE,
1263 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001265 SCRIPTID_INIT},
1266 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1267#ifdef FEAT_FOLDING
1268 (char_u *)VAR_WIN, PV_FDM,
1269 {(char_u *)"manual", (char_u *)NULL}
1270#else
1271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)NULL, (char_u *)0L}
1273#endif
1274 SCRIPTID_INIT},
1275 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1276#ifdef FEAT_FOLDING
1277 (char_u *)VAR_WIN, PV_FML,
1278 {(char_u *)1L, (char_u *)0L}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)NULL, (char_u *)0L}
1282#endif
1283 SCRIPTID_INIT},
1284 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1285#ifdef FEAT_FOLDING
1286 (char_u *)VAR_WIN, PV_FDN,
1287 {(char_u *)20L, (char_u *)0L}
1288#else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
1291#endif
1292 SCRIPTID_INIT},
1293 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1294#ifdef FEAT_FOLDING
1295 (char_u *)&p_fdo, PV_NONE,
1296 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1297 (char_u *)0L}
1298#else
1299 (char_u *)NULL, PV_NONE,
1300 {(char_u *)NULL, (char_u *)0L}
1301#endif
1302 SCRIPTID_INIT},
1303 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1304#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1305 (char_u *)VAR_WIN, PV_FDT,
1306 {(char_u *)"foldtext()", (char_u *)NULL}
1307#else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310#endif
1311 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001312 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001313#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001314 (char_u *)&p_fex, PV_FEX,
1315 {(char_u *)"", (char_u *)0L}
1316#else
1317 (char_u *)NULL, PV_NONE,
1318 {(char_u *)0L, (char_u *)0L}
1319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001320 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1322 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001323 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1324 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001325 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1326 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001327 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1328 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001330 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001332 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1333#ifdef HAVE_FSYNC
1334 (char_u *)&p_fs, PV_NONE,
1335 {(char_u *)TRUE, (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)FALSE, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1342 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 {"graphic", "gr", P_BOOL|P_VI_DEF,
1345 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001347 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348#ifdef FEAT_QUICKFIX
1349 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351#else
1352 (char_u *)NULL, PV_NONE,
1353 {(char_u *)NULL, (char_u *)0L}
1354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1357#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001358 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 {
1360# ifdef WIN3264
1361 /* may be changed to "grep -n" in os_win32.c */
1362 (char_u *)"findstr /n",
1363# else
1364# ifdef UNIX
1365 /* Add an extra file name so that grep will always
1366 * insert a file name in the match line. */
1367 (char_u *)"grep -n $* /dev/null",
1368# else
1369# ifdef VMS
1370 (char_u *)"SEARCH/NUMBERS ",
1371# else
1372 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373# endif
1374# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377#else
1378 (char_u *)NULL, PV_NONE,
1379 {(char_u *)NULL, (char_u *)0L}
1380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001381 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001382 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383#ifdef CURSOR_SHAPE
1384 (char_u *)&p_guicursor, PV_NONE,
1385 {
1386# ifdef FEAT_GUI
1387 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001388# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1390# endif
1391 (char_u *)0L}
1392#else
1393 (char_u *)NULL, PV_NONE,
1394 {(char_u *)NULL, (char_u *)0L}
1395#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001396 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001397 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398#ifdef FEAT_GUI
1399 (char_u *)&p_guifont, PV_NONE,
1400 {(char_u *)"", (char_u *)0L}
1401#else
1402 (char_u *)NULL, PV_NONE,
1403 {(char_u *)NULL, (char_u *)0L}
1404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001406 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1408 (char_u *)&p_guifontset, PV_NONE,
1409 {(char_u *)"", (char_u *)0L}
1410#else
1411 (char_u *)NULL, PV_NONE,
1412 {(char_u *)NULL, (char_u *)0L}
1413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1417 (char_u *)&p_guifontwide, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001425#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 (char_u *)&p_ghr, PV_NONE,
1427#else
1428 (char_u *)NULL, PV_NONE,
1429#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001430 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001432#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001434# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001435 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001437 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438# endif
1439#else
1440 (char_u *)NULL, PV_NONE,
1441 {(char_u *)NULL, (char_u *)0L}
1442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001443 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 {"guipty", NULL, P_BOOL|P_VI_DEF,
1445#if defined(FEAT_GUI)
1446 (char_u *)&p_guipty, PV_NONE,
1447#else
1448 (char_u *)NULL, PV_NONE,
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001451 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001452#if defined(FEAT_GUI_TABLINE)
1453 (char_u *)&p_gtl, PV_NONE,
1454 {(char_u *)"", (char_u *)0L}
1455#else
1456 (char_u *)NULL, PV_NONE,
1457 {(char_u *)NULL, (char_u *)0L}
1458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001460 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001461#if defined(FEAT_GUI_TABLINE)
1462 (char_u *)&p_gtt, PV_NONE,
1463 {(char_u *)"", (char_u *)0L}
1464#else
1465 (char_u *)NULL, PV_NONE,
1466 {(char_u *)NULL, (char_u *)0L}
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1470 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1473 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001479 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480#ifdef FEAT_MULTI_LANG
1481 (char_u *)&p_hlg, PV_NONE,
1482 {(char_u *)"", (char_u *)0L}
1483#else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)0L, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"hidden", "hid", P_BOOL|P_VI_DEF,
1489 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001491 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001492 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001493 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1494 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"history", "hi", P_NUM|P_VIM,
1496 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001497 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1499#ifdef FEAT_RIGHTLEFT
1500 (char_u *)&p_hkmap, PV_NONE,
1501#else
1502 (char_u *)NULL, PV_NONE,
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1506#ifdef FEAT_RIGHTLEFT
1507 (char_u *)&p_hkmapp, PV_NONE,
1508#else
1509 (char_u *)NULL, PV_NONE,
1510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1513 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"icon", NULL, P_BOOL|P_VI_DEF,
1516#ifdef FEAT_TITLE
1517 (char_u *)&p_icon, PV_NONE,
1518#else
1519 (char_u *)NULL, PV_NONE,
1520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"iconstring", NULL, P_STRING|P_VI_DEF,
1523#ifdef FEAT_TITLE
1524 (char_u *)&p_iconstring, PV_NONE,
1525#else
1526 (char_u *)NULL, PV_NONE,
1527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001528 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1530 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001532 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1533# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1534 (char_u *)&p_imaf, PV_NONE,
1535 {(char_u *)"", (char_u *)NULL}
1536# else
1537 (char_u *)NULL, PV_NONE,
1538 {(char_u *)NULL, (char_u *)0L}
1539# endif
1540 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001542#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 (char_u *)&p_imak, PV_NONE,
1544#else
1545 (char_u *)NULL, PV_NONE,
1546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001547 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1549#ifdef USE_IM_CONTROL
1550 (char_u *)&p_imcmdline, PV_NONE,
1551#else
1552 (char_u *)NULL, PV_NONE,
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1556#ifdef USE_IM_CONTROL
1557 (char_u *)&p_imdisable, PV_NONE,
1558#else
1559 (char_u *)NULL, PV_NONE,
1560#endif
1561#ifdef __sgi
1562 {(char_u *)TRUE, (char_u *)0L}
1563#else
1564 {(char_u *)FALSE, (char_u *)0L}
1565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"iminsert", "imi", P_NUM|P_VI_DEF,
1568 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"imsearch", "ims", P_NUM|P_VI_DEF,
1572 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001573 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001574 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001575 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001576#if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001577 (char_u *)&p_imsf, PV_NONE,
1578 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001579#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001580 (char_u *)NULL, PV_NONE,
1581 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001582#endif
1583 SCRIPTID_INIT},
1584 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1585#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1586 (char_u *)&p_imst, PV_NONE,
1587 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1588#else
1589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)0L, (char_u *)0L}
1591#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001592 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1594#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001595 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)0L, (char_u *)0L}
1600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001601 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1603#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1604 (char_u *)&p_inex, PV_INEX,
1605 {(char_u *)"", (char_u *)0L}
1606#else
1607 (char_u *)NULL, PV_NONE,
1608 {(char_u *)0L, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1612 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001613 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1615#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1616 (char_u *)&p_inde, PV_INDE,
1617 {(char_u *)"", (char_u *)0L}
1618#else
1619 (char_u *)NULL, PV_NONE,
1620 {(char_u *)0L, (char_u *)0L}
1621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001623 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1625 (char_u *)&p_indk, PV_INDK,
1626 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1627#else
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)0L, (char_u *)0L}
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"infercase", "inf", P_BOOL|P_VI_DEF,
1633 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1636 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1639 (char_u *)&p_isf, PV_NONE,
1640 {
1641#ifdef BACKSLASH_IN_FILENAME
1642 /* Excluded are: & and ^ are special in cmd.exe
1643 * ( and ) are used in text separating fnames */
1644 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1645#else
1646# ifdef AMIGA
1647 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1648# else
1649# ifdef VMS
1650 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1651# else /* UNIX et al. */
1652# ifdef EBCDIC
1653 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1654# else
1655 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1656# endif
1657# endif
1658# endif
1659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001660 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1662 (char_u *)&p_isi, PV_NONE,
1663 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001664#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 (char_u *)"@,48-57,_,128-167,224-235",
1666#else
1667# ifdef EBCDIC
1668 /* TODO: EBCDIC Check this! @ == isalpha()*/
1669 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1670 "112-120,128,140-142,156,158,172,"
1671 "174,186,191,203-207,219-225,235-239,"
1672 "251-254",
1673# else
1674 (char_u *)"@,48-57,_,192-255",
1675# endif
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1679 (char_u *)&p_isk, PV_ISK,
1680 {
1681#ifdef EBCDIC
1682 (char_u *)"@,240-249,_",
1683 /* TODO: EBCDIC Check this! @ == isalpha()*/
1684 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1685 "112-120,128,140-142,156,158,172,"
1686 "174,186,191,203-207,219-225,235-239,"
1687 "251-254",
1688#else
1689 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001690# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 (char_u *)"@,48-57,_,128-167,224-235"
1692# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001693 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694# endif
1695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1698 (char_u *)&p_isp, PV_NONE,
1699 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001700#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 (char_u *)"@,~-255",
1702#else
1703# ifdef EBCDIC
1704 /* all chars above 63 are printable */
1705 (char_u *)"63-255",
1706# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001707 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708# endif
1709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1712 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001713 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1715#ifdef FEAT_CRYPT
1716 (char_u *)&p_key, PV_KEY,
1717 {(char_u *)"", (char_u *)0L}
1718#else
1719 (char_u *)NULL, PV_NONE,
1720 {(char_u *)0L, (char_u *)0L}
1721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001723 {"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 +00001724#ifdef FEAT_KEYMAP
1725 (char_u *)&p_keymap, PV_KMAP,
1726 {(char_u *)"", (char_u *)0L}
1727#else
1728 (char_u *)NULL, PV_NONE,
1729 {(char_u *)"", (char_u *)0L}
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001732 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001734 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001736 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001738#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 (char_u *)":help",
1740#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001741# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001743# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001744# ifdef USEMAN_S
1745 (char_u *)"man -s",
1746# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001748# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749# endif
1750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001751 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001752 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753#ifdef FEAT_LANGMAP
1754 (char_u *)&p_langmap, PV_NONE,
1755 {(char_u *)"", /* unmatched } */
1756#else
1757 (char_u *)NULL, PV_NONE,
1758 {(char_u *)NULL,
1759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001761 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1763 (char_u *)&p_lm, PV_NONE,
1764#else
1765 (char_u *)NULL, PV_NONE,
1766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001768 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1769#ifdef FEAT_LANGMAP
1770 (char_u *)&p_lnr, PV_NONE,
1771#else
1772 (char_u *)NULL, PV_NONE,
1773#endif
1774 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001775 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1776#ifdef FEAT_LANGMAP
1777 (char_u *)&p_lrm, PV_NONE,
1778#else
1779 (char_u *)NULL, PV_NONE,
1780#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001781 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1786 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001787 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1789#ifdef FEAT_LINEBREAK
1790 (char_u *)VAR_WIN, PV_LBR,
1791#else
1792 (char_u *)NULL, PV_NONE,
1793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1796 (char_u *)&Rows, PV_NONE,
1797 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001798#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 (char_u *)25L,
1800#else
1801 (char_u *)24L,
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1805#ifdef FEAT_GUI
1806 (char_u *)&p_linespace, PV_NONE,
1807#else
1808 (char_u *)NULL, PV_NONE,
1809#endif
1810#ifdef FEAT_GUI_W32
1811 {(char_u *)1L, (char_u *)0L}
1812#else
1813 {(char_u *)0L, (char_u *)0L}
1814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001815 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 {"lisp", NULL, P_BOOL|P_VI_DEF,
1817#ifdef FEAT_LISP
1818 (char_u *)&p_lisp, PV_LISP,
1819#else
1820 (char_u *)NULL, PV_NONE,
1821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001823 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001825 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1827#else
1828 (char_u *)NULL, PV_NONE,
1829 {(char_u *)"", (char_u *)0L}
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1833 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001835 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001838 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1839 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001841 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001842#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001843 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001844 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001845#else
1846 (char_u *)NULL, PV_NONE,
1847 {(char_u *)"", (char_u *)0L}
1848#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001849 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001850 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001851#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001852 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001853 {(char_u *)TRUE, (char_u *)0L}
1854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001857#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001858 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"magic", NULL, P_BOOL|P_VI_DEF,
1860 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001862 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863#ifdef FEAT_QUICKFIX
1864 (char_u *)&p_mef, PV_NONE,
1865 {(char_u *)"", (char_u *)0L}
1866#else
1867 (char_u *)NULL, PV_NONE,
1868 {(char_u *)NULL, (char_u *)0L}
1869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001871 {"makeencoding","menc", P_STRING|P_VI_DEF,
1872#ifdef FEAT_MBYTE
1873 (char_u *)&p_menc, PV_MENC,
1874 {(char_u *)"", (char_u *)0L}
1875#else
1876 (char_u *)NULL, PV_NONE,
1877 {(char_u *)0L, (char_u *)0L}
1878#endif
1879 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1881#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001882 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883# ifdef VMS
1884 {(char_u *)"MMS", (char_u *)0L}
1885# else
1886 {(char_u *)"make", (char_u *)0L}
1887# endif
1888#else
1889 (char_u *)NULL, PV_NONE,
1890 {(char_u *)NULL, (char_u *)0L}
1891#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001892 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001893 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1896 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"matchtime", "mat", P_NUM|P_VI_DEF,
1898 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001900 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001901#ifdef FEAT_MBYTE
1902 (char_u *)&p_mco, PV_NONE,
1903#else
1904 (char_u *)NULL, PV_NONE,
1905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001906 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1908#ifdef FEAT_EVAL
1909 (char_u *)&p_mfd, PV_NONE,
1910#else
1911 (char_u *)NULL, PV_NONE,
1912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001913 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1915 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001916 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"maxmem", "mm", P_NUM|P_VI_DEF,
1918 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1920 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001921 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1922 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001923 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1925 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1927 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"menuitems", "mis", P_NUM|P_VI_DEF,
1929#ifdef FEAT_MENU
1930 (char_u *)&p_mis, PV_NONE,
1931#else
1932 (char_u *)NULL, PV_NONE,
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"mesg", NULL, P_BOOL|P_VI_DEF,
1936 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001938 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001939#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001940 (char_u *)&p_msm, PV_NONE,
1941 {(char_u *)"460000,2000,500", (char_u *)0L}
1942#else
1943 (char_u *)NULL, PV_NONE,
1944 {(char_u *)0L, (char_u *)0L}
1945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"modeline", "ml", P_BOOL|P_VIM,
1948 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"modelines", "mls", P_NUM|P_VI_DEF,
1951 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1954 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1957 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"more", NULL, P_BOOL|P_VIM,
1960 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1963 (char_u *)&p_mouse, PV_NONE,
1964 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001965#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 (char_u *)"a",
1967#else
1968 (char_u *)"",
1969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1972#ifdef FEAT_GUI
1973 (char_u *)&p_mousef, PV_NONE,
1974#else
1975 (char_u *)NULL, PV_NONE,
1976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1979#ifdef FEAT_GUI
1980 (char_u *)&p_mh, PV_NONE,
1981#else
1982 (char_u *)NULL, PV_NONE,
1983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1986 (char_u *)&p_mousem, PV_NONE,
1987 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001988#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 (char_u *)"popup",
1990#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001991# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 (char_u *)"popup_setpos",
1993# else
1994 (char_u *)"extend",
1995# endif
1996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001998 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999#ifdef FEAT_MOUSESHAPE
2000 (char_u *)&p_mouseshape, PV_NONE,
2001 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2002#else
2003 (char_u *)NULL, PV_NONE,
2004 {(char_u *)NULL, (char_u *)0L}
2005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2008 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002009 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002010 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2011#if defined(DYNAMIC_MZSCHEME)
2012 (char_u *)&p_mzschemedll, PV_NONE,
2013 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2014#else
2015 (char_u *)NULL, PV_NONE,
2016 {(char_u *)"", (char_u *)0L}
2017#endif
2018 SCRIPTID_INIT},
2019 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2020#if defined(DYNAMIC_MZSCHEME)
2021 (char_u *)&p_mzschemegcdll, PV_NONE,
2022 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2023#else
2024 (char_u *)NULL, PV_NONE,
2025 {(char_u *)"", (char_u *)0L}
2026#endif
2027 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002028 {"mzquantum", "mzq", P_NUM,
2029#ifdef FEAT_MZSCHEME
2030 (char_u *)&p_mzq, PV_NONE,
2031#else
2032 (char_u *)NULL, PV_NONE,
2033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 {"novice", NULL, P_BOOL|P_VI_DEF,
2036 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002038 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002040 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2043 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002045 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2046#ifdef FEAT_LINEBREAK
2047 (char_u *)VAR_WIN, PV_NUW,
2048#else
2049 (char_u *)NULL, PV_NONE,
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002052 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002053#ifdef FEAT_COMPL_FUNC
2054 (char_u *)&p_ofu, PV_OFU,
2055 {(char_u *)"", (char_u *)0L}
2056#else
2057 (char_u *)NULL, PV_NONE,
2058 {(char_u *)0L, (char_u *)0L}
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"open", NULL, P_BOOL|P_VI_DEF,
2062 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002064 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002065#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002066 (char_u *)&p_odev, PV_NONE,
2067#else
2068 (char_u *)NULL, PV_NONE,
2069#endif
2070 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002071 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002072 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2073 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 {"optimize", "opt", P_BOOL|P_VI_DEF,
2076 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002080 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002081 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2082 |P_SECURE,
2083 (char_u *)&p_pp, PV_NONE,
2084 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"paragraphs", "para", P_STRING|P_VI_DEF,
2087 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002088 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002090 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002092 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002093 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2094 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2097#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2098 (char_u *)&p_pex, PV_NONE,
2099 {(char_u *)"", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)0L, (char_u *)0L}
2103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002105 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002109 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002111#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002112 (char_u *)".,,",
2113#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002117 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002118#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002119 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002120 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002121#else
2122 (char_u *)NULL, PV_NONE,
2123 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002124#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002125 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2127 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002129 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002130#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 (char_u *)&p_pvh, PV_NONE,
2132#else
2133 (char_u *)NULL, PV_NONE,
2134#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002135 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002137#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 (char_u *)VAR_WIN, PV_PVW,
2139#else
2140 (char_u *)NULL, PV_NONE,
2141#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002142 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002143 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144#ifdef FEAT_PRINTER
2145 (char_u *)&p_pdev, PV_NONE,
2146 {(char_u *)"", (char_u *)0L}
2147#else
2148 (char_u *)NULL, PV_NONE,
2149 {(char_u *)NULL, (char_u *)0L}
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 {"printencoding", "penc", P_STRING|P_VI_DEF,
2153#ifdef FEAT_POSTSCRIPT
2154 (char_u *)&p_penc, 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 Moolenaar031cb742016-11-24 21:46:19 +01002161 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162#ifdef FEAT_POSTSCRIPT
2163 (char_u *)&p_pexpr, 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 Moolenaar071d4272004-06-13 20:20:40 +00002170 {"printfont", "pfn", P_STRING|P_VI_DEF,
2171#ifdef FEAT_PRINTER
2172 (char_u *)&p_pfn, PV_NONE,
2173 {
2174# ifdef MSWIN
2175 (char_u *)"Courier_New:h10",
2176# else
2177 (char_u *)"courier",
2178# endif
2179 (char_u *)0L}
2180#else
2181 (char_u *)NULL, PV_NONE,
2182 {(char_u *)NULL, (char_u *)0L}
2183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002184 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2186#ifdef FEAT_PRINTER
2187 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002188 /* untranslated to avoid problems when 'encoding'
2189 * is changed */
2190 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191#else
2192 (char_u *)NULL, PV_NONE,
2193 {(char_u *)NULL, (char_u *)0L}
2194#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002195 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002196 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2197#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2198 (char_u *)&p_pmcs, PV_NONE,
2199 {(char_u *)"", (char_u *)0L}
2200#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 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2206#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2207 (char_u *)&p_pmfn, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002214 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215#ifdef FEAT_PRINTER
2216 (char_u *)&p_popt, 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 Moolenaar071d4272004-06-13 20:20:40 +00002223 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002224 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002226 {"pumheight", "ph", P_NUM|P_VI_DEF,
2227#ifdef FEAT_INS_EXPAND
2228 (char_u *)&p_ph, PV_NONE,
2229#else
2230 (char_u *)NULL, PV_NONE,
2231#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002232 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002233 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002234#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002235 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002236 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002237#else
2238 (char_u *)NULL, PV_NONE,
2239 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002240#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002241 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002242 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002243#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002244 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002245 {(char_u *)DYNAMIC_PYTHON_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 Moolenaarf42dd3c2017-01-28 16:06:38 +01002251 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2252#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2253 (char_u *)&p_pyx, PV_NONE,
2254#else
2255 (char_u *)NULL, PV_NONE,
2256#endif
2257 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2258 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002259 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2260#ifdef FEAT_TEXTOBJ
2261 (char_u *)&p_qe, PV_QE,
2262 {(char_u *)"\\", (char_u *)0L}
2263#else
2264 (char_u *)NULL, PV_NONE,
2265 {(char_u *)NULL, (char_u *)0L}
2266#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002267 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2269 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002270 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 {"redraw", NULL, P_BOOL|P_VI_DEF,
2272 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002274 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2275#ifdef FEAT_RELTIME
2276 (char_u *)&p_rdt, PV_NONE,
2277#else
2278 (char_u *)NULL, PV_NONE,
2279#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002280 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002281 {"regexpengine", "re", P_NUM|P_VI_DEF,
2282 (char_u *)&p_re, PV_NONE,
2283 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002284 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2285 (char_u *)VAR_WIN, PV_RNU,
2286 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"remap", NULL, P_BOOL|P_VI_DEF,
2288 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002290 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002291#ifdef FEAT_RENDER_OPTIONS
2292 (char_u *)&p_rop, PV_NONE,
2293 {(char_u *)"", (char_u *)0L}
2294#else
2295 (char_u *)NULL, PV_NONE,
2296 {(char_u *)NULL, (char_u *)0L}
2297#endif
2298 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"report", NULL, P_NUM|P_VI_DEF,
2300 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2303#ifdef WIN3264
2304 (char_u *)&p_rs, PV_NONE,
2305#else
2306 (char_u *)NULL, PV_NONE,
2307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2310#ifdef FEAT_RIGHTLEFT
2311 (char_u *)&p_ri, PV_NONE,
2312#else
2313 (char_u *)NULL, PV_NONE,
2314#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002315 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2317#ifdef FEAT_RIGHTLEFT
2318 (char_u *)VAR_WIN, PV_RL,
2319#else
2320 (char_u *)NULL, PV_NONE,
2321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2324#ifdef FEAT_RIGHTLEFT
2325 (char_u *)VAR_WIN, PV_RLC,
2326 {(char_u *)"search", (char_u *)NULL}
2327#else
2328 (char_u *)NULL, PV_NONE,
2329 {(char_u *)NULL, (char_u *)0L}
2330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002332 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002333#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002334 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002335 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002336#else
2337 (char_u *)NULL, PV_NONE,
2338 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002339#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2342#ifdef FEAT_CMDL_INFO
2343 (char_u *)&p_ru, PV_NONE,
2344#else
2345 (char_u *)NULL, PV_NONE,
2346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002347 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2349#ifdef FEAT_STL_OPT
2350 (char_u *)&p_ruf, PV_NONE,
2351#else
2352 (char_u *)NULL, PV_NONE,
2353#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002355 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2356 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2359 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2361 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2364#ifdef FEAT_SCROLLBIND
2365 (char_u *)VAR_WIN, PV_SCBIND,
2366#else
2367 (char_u *)NULL, PV_NONE,
2368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2371 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002372 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2374 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002376 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377#ifdef FEAT_SCROLLBIND
2378 (char_u *)&p_sbo, PV_NONE,
2379 {(char_u *)"ver,jump", (char_u *)0L}
2380#else
2381 (char_u *)NULL, PV_NONE,
2382 {(char_u *)0L, (char_u *)0L}
2383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"sections", "sect", P_STRING|P_VI_DEF,
2386 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2388 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2390 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 {(char_u *)"inclusive", (char_u *)0L}
2395 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002396 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002399 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400#ifdef FEAT_SESSION
2401 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002402 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 (char_u *)0L}
2404#else
2405 (char_u *)NULL, PV_NONE,
2406 {(char_u *)0L, (char_u *)0L}
2407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002408 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2410 (char_u *)&p_sh, PV_NONE,
2411 {
2412#ifdef VMS
2413 (char_u *)"-",
2414#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002415# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002417# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419# endif
2420#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002421 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2423 (char_u *)&p_shcf, PV_NONE,
2424 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002425#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 (char_u *)"/c",
2427#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2432#ifdef FEAT_QUICKFIX
2433 (char_u *)&p_sp, PV_NONE,
2434 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002435#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437#else
2438 (char_u *)">",
2439#endif
2440 (char_u *)0L}
2441#else
2442 (char_u *)NULL, PV_NONE,
2443 {(char_u *)0L, (char_u *)0L}
2444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2447 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2450 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2453#ifdef BACKSLASH_IN_FILENAME
2454 (char_u *)&p_ssl, PV_NONE,
2455#else
2456 (char_u *)NULL, PV_NONE,
2457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002459 {"shelltemp", "stmp", P_BOOL,
2460 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"shelltype", "st", P_NUM|P_VI_DEF,
2463#ifdef AMIGA
2464 (char_u *)&p_st, PV_NONE,
2465#else
2466 (char_u *)NULL, PV_NONE,
2467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2470 (char_u *)&p_sxq, PV_NONE,
2471 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002472#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 (char_u *)"\"",
2474#else
2475 (char_u *)"",
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002478 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2479 (char_u *)&p_sxe, PV_NONE,
2480 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002481#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002482 (char_u *)"\"&|<>()@^",
2483#else
2484 (char_u *)"",
2485#endif
2486 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2488 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2491 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2494 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002495 {(char_u *)"", (char_u *)"filnxtToO"}
2496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002499 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2501#ifdef FEAT_LINEBREAK
2502 (char_u *)&p_sbr, PV_NONE,
2503#else
2504 (char_u *)NULL, PV_NONE,
2505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002506 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"showcmd", "sc", P_BOOL|P_VIM,
2508#ifdef FEAT_CMDL_INFO
2509 (char_u *)&p_sc, PV_NONE,
2510#else
2511 (char_u *)NULL, PV_NONE,
2512#endif
2513 {(char_u *)FALSE,
2514#ifdef UNIX
2515 (char_u *)FALSE
2516#else
2517 (char_u *)TRUE
2518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2521 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2524 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"showmode", "smd", P_BOOL|P_VIM,
2527 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002529 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002530 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2533 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2536 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002538 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2539#ifdef FEAT_SIGNS
2540 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002541 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002542#else
2543 (char_u *)NULL, PV_NONE,
2544 {(char_u *)NULL, (char_u *)0L}
2545#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002546 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2548 (char_u *)NULL, 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 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2551 (char_u *)&p_scs, 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 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2554#ifdef FEAT_SMARTINDENT
2555 (char_u *)&p_si, PV_SI,
2556#else
2557 (char_u *)NULL, PV_NONE,
2558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2561 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2564 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2567 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002569 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002570#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002571 (char_u *)VAR_WIN, PV_SPELL,
2572#else
2573 (char_u *)NULL, PV_NONE,
2574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002576 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002577#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002578 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002579 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002580#else
2581 (char_u *)NULL, PV_NONE,
2582 {(char_u *)0L, (char_u *)0L}
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002585 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2586 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002587#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002588 (char_u *)&p_spf, PV_SPF,
2589 {(char_u *)"", (char_u *)0L}
2590#else
2591 (char_u *)NULL, PV_NONE,
2592 {(char_u *)0L, (char_u *)0L}
2593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002595 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2596 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002597#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002598 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002599 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002600#else
2601 (char_u *)NULL, PV_NONE,
2602 {(char_u *)0L, (char_u *)0L}
2603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002605 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002606#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002607 (char_u *)&p_sps, PV_NONE,
2608 {(char_u *)"best", (char_u *)0L}
2609#else
2610 (char_u *)NULL, PV_NONE,
2611 {(char_u *)0L, (char_u *)0L}
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2621 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2624#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002625 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626#else
2627 (char_u *)NULL, PV_NONE,
2628#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002630 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 (char_u *)&p_su, PV_NONE,
2632 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002634 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002635#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 (char_u *)&p_sua, PV_SUA,
2637 {(char_u *)"", (char_u *)0L}
2638#else
2639 (char_u *)NULL, PV_NONE,
2640 {(char_u *)0L, (char_u *)0L}
2641#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2644 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"swapsync", "sws", P_STRING|P_VI_DEF,
2647 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002649 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002652 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2653#ifdef FEAT_SYN_HL
2654 (char_u *)&p_smc, PV_SMC,
2655 {(char_u *)3000L, (char_u *)0L}
2656#else
2657 (char_u *)NULL, PV_NONE,
2658 {(char_u *)0L, (char_u *)0L}
2659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002661 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662#ifdef FEAT_SYN_HL
2663 (char_u *)&p_syn, PV_SYN,
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 Moolenaarfaa959a2006-02-20 21:37:40 +00002670 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2671#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002672 (char_u *)&p_tal, PV_NONE,
2673#else
2674 (char_u *)NULL, PV_NONE,
2675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002677 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002678 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002679 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002680 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2681 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2684 (char_u *)&p_tbs, PV_NONE,
2685#ifdef VMS /* binary searching doesn't appear to work on VMS */
2686 {(char_u *)0L, (char_u *)0L}
2687#else
2688 {(char_u *)TRUE, (char_u *)0L}
2689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002691 {"tagcase", "tc", P_STRING|P_VIM,
2692 (char_u *)&p_tc, PV_TC,
2693 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 {"taglength", "tl", P_NUM|P_VI_DEF,
2695 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"tagrelative", "tr", P_BOOL|P_VIM,
2698 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002700 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002701 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {
2703#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2704 (char_u *)"./tags,./TAGS,tags,TAGS",
2705#else
2706 (char_u *)"./tags,tags",
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2710 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002712 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002713#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002714 (char_u *)&p_tcldll, PV_NONE,
2715 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002716#else
2717 (char_u *)NULL, PV_NONE,
2718 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002719#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2722 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2725#ifdef FEAT_ARABIC
2726 (char_u *)&p_tbidi, PV_NONE,
2727#else
2728 (char_u *)NULL, PV_NONE,
2729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2732#ifdef FEAT_MBYTE
2733 (char_u *)&p_tenc, PV_NONE,
2734 {(char_u *)"", (char_u *)0L}
2735#else
2736 (char_u *)NULL, PV_NONE,
2737 {(char_u *)0L, (char_u *)0L}
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002740 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2741#ifdef FEAT_TERMGUICOLORS
2742 (char_u *)&p_tgc, PV_NONE,
2743 {(char_u *)FALSE, (char_u *)FALSE}
2744#else
2745 (char_u*)NULL, PV_NONE,
2746 {(char_u *)FALSE, (char_u *)FALSE}
2747#endif
2748 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002749 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2750#ifdef FEAT_TERMINAL
2751 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002752 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002753#else
2754 (char_u *)NULL, PV_NONE,
2755 {(char_u *)NULL, (char_u *)0L}
2756#endif
2757 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002758 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2759#ifdef FEAT_TERMINAL
2760 (char_u *)VAR_WIN, PV_TMS,
2761 {(char_u *)"", (char_u *)NULL}
2762#else
2763 (char_u *)NULL, PV_NONE,
2764 {(char_u *)NULL, (char_u *)0L}
2765#endif
2766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"terse", NULL, P_BOOL|P_VI_DEF,
2768 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002769 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 {"textauto", "ta", P_BOOL|P_VIM,
2771 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002772 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2773 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2775 (char_u *)&p_tx, PV_TX,
2776 {
2777#ifdef USE_CRNL
2778 (char_u *)TRUE,
2779#else
2780 (char_u *)FALSE,
2781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002783 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002786 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002788 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789#else
2790 (char_u *)NULL, PV_NONE,
2791#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002792 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2794 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {"timeout", "to", P_BOOL|P_VI_DEF,
2797 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2800 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002801 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"title", NULL, P_BOOL|P_VI_DEF,
2803#ifdef FEAT_TITLE
2804 (char_u *)&p_title, PV_NONE,
2805#else
2806 (char_u *)NULL, PV_NONE,
2807#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"titlelen", NULL, P_NUM|P_VI_DEF,
2810#ifdef FEAT_TITLE
2811 (char_u *)&p_titlelen, PV_NONE,
2812#else
2813 (char_u *)NULL, PV_NONE,
2814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002816 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817#ifdef FEAT_TITLE
2818 (char_u *)&p_titleold, PV_NONE,
2819 {(char_u *)N_("Thanks for flying Vim"),
2820 (char_u *)0L}
2821#else
2822 (char_u *)NULL, PV_NONE,
2823 {(char_u *)0L, (char_u *)0L}
2824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"titlestring", NULL, P_STRING|P_VI_DEF,
2827#ifdef FEAT_TITLE
2828 (char_u *)&p_titlestring, PV_NONE,
2829#else
2830 (char_u *)NULL, PV_NONE,
2831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002833 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002834#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002837#else
2838 (char_u *)NULL, PV_NONE,
2839 {(char_u *)0L, (char_u *)0L}
2840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002843#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002845 {(char_u *)"small", (char_u *)0L}
2846#else
2847 (char_u *)NULL, PV_NONE,
2848 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2852 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2855 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002856 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2858 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2861 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2864#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2865 (char_u *)&p_ttym, PV_NONE,
2866#else
2867 (char_u *)NULL, PV_NONE,
2868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2871 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2874 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002875 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002876 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2877 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002878#ifdef FEAT_PERSISTENT_UNDO
2879 (char_u *)&p_udir, PV_NONE,
2880 {(char_u *)".", (char_u *)0L}
2881#else
2882 (char_u *)NULL, PV_NONE,
2883 {(char_u *)0L, (char_u *)0L}
2884#endif
2885 SCRIPTID_INIT},
2886 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2887#ifdef FEAT_PERSISTENT_UNDO
2888 (char_u *)&p_udf, PV_UDF,
2889#else
2890 (char_u *)NULL, PV_NONE,
2891#endif
2892 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002894 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002896#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 (char_u *)1000L,
2898#else
2899 (char_u *)100L,
2900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002901 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002902 {"undoreload", "ur", P_NUM|P_VI_DEF,
2903 (char_u *)&p_ur, PV_NONE,
2904 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905 {"updatecount", "uc", P_NUM|P_VI_DEF,
2906 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002907 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {"updatetime", "ut", P_NUM|P_VI_DEF,
2909 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"verbose", "vbs", P_NUM|P_VI_DEF,
2912 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002913 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002914 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2915 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2918#ifdef FEAT_SESSION
2919 (char_u *)&p_vdir, PV_NONE,
2920 {(char_u *)DFLT_VDIR, (char_u *)0L}
2921#else
2922 (char_u *)NULL, PV_NONE,
2923 {(char_u *)0L, (char_u *)0L}
2924#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002926 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927#ifdef FEAT_SESSION
2928 (char_u *)&p_vop, PV_NONE,
2929 {(char_u *)"folds,options,cursor", (char_u *)0L}
2930#else
2931 (char_u *)NULL, PV_NONE,
2932 {(char_u *)0L, (char_u *)0L}
2933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002935 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936#ifdef FEAT_VIMINFO
2937 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002938#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002939 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940#else
2941# ifdef AMIGA
2942 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002943 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002945 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946# endif
2947#endif
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 Moolenaarc4da1132017-07-15 19:39:43 +02002953 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2954#ifdef FEAT_VIMINFO
2955 (char_u *)&p_viminfofile, PV_NONE,
2956 {(char_u *)"", (char_u *)0L}
2957#else
2958 (char_u *)NULL, PV_NONE,
2959 {(char_u *)0L, (char_u *)0L}
2960#endif
2961 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002962 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2963 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964#ifdef FEAT_VIRTUALEDIT
2965 (char_u *)&p_ve, PV_NONE,
2966 {(char_u *)"", (char_u *)""}
2967#else
2968 (char_u *)NULL, PV_NONE,
2969 {(char_u *)0L, (char_u *)0L}
2970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002971 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2973 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002974 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975 {"w300", NULL, P_NUM|P_VI_DEF,
2976 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002977 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978 {"w1200", NULL, P_NUM|P_VI_DEF,
2979 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002980 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 {"w9600", NULL, P_NUM|P_VI_DEF,
2982 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002983 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984 {"warn", NULL, P_BOOL|P_VI_DEF,
2985 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002986 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2988 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002990 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002992 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 {"wildchar", "wc", P_NUM|P_VIM,
2994 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002995 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2996 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002997 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003000 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001#ifdef FEAT_WILDIGN
3002 (char_u *)&p_wig, PV_NONE,
3003#else
3004 (char_u *)NULL, PV_NONE,
3005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003006 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003007 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3008 (char_u *)&p_wic, PV_NONE,
3009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3011#ifdef FEAT_WILDMENU
3012 (char_u *)&p_wmnu, PV_NONE,
3013#else
3014 (char_u *)NULL, PV_NONE,
3015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003016 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003017 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003019 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003020 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3021#ifdef FEAT_CMDL_COMPL
3022 (char_u *)&p_wop, PV_NONE,
3023 {(char_u *)"", (char_u *)0L}
3024#else
3025 (char_u *)NULL, PV_NONE,
3026 {(char_u *)NULL, (char_u *)0L}
3027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003028 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3030#ifdef FEAT_WAK
3031 (char_u *)&p_wak, PV_NONE,
3032 {(char_u *)"menu", (char_u *)0L}
3033#else
3034 (char_u *)NULL, PV_NONE,
3035 {(char_u *)NULL, (char_u *)0L}
3036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003037 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003039 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003040 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003043 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003047 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003048 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003049 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003052 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003055 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003056 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003057#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003058 (char_u *)&p_winptydll, PV_NONE, {
3059# ifdef _WIN64
3060 (char_u *)"winpty64.dll",
3061# else
3062 (char_u *)"winpty32.dll",
3063# endif
3064 (char_u *)0L}
3065#else
3066 (char_u *)NULL, PV_NONE,
3067 {(char_u *)0L, (char_u *)0L}
3068#endif
3069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003072 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3074 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003075 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3077 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003078 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3080 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003081 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 {"write", NULL, P_BOOL|P_VI_DEF,
3083 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003084 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 {"writeany", "wa", P_BOOL|P_VI_DEF,
3086 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003087 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3089 (char_u *)&p_wb, PV_NONE,
3090 {
3091#ifdef FEAT_WRITEBACKUP
3092 (char_u *)TRUE,
3093#else
3094 (char_u *)FALSE,
3095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003096 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 {"writedelay", "wd", P_NUM|P_VI_DEF,
3098 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003099 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100
3101/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003102#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003104 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105
3106 p_term("t_AB", T_CAB)
3107 p_term("t_AF", T_CAF)
3108 p_term("t_AL", T_CAL)
3109 p_term("t_al", T_AL)
3110 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003111 p_term("t_BE", T_BE)
3112 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 p_term("t_cd", T_CD)
3114 p_term("t_ce", T_CE)
3115 p_term("t_cl", T_CL)
3116 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003117 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 p_term("t_Co", T_CCO)
3119 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003120 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_da", T_DA)
3124 p_term("t_db", T_DB)
3125 p_term("t_DL", T_CDL)
3126 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003127 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003128 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003130 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 p_term("t_IE", T_CIE)
3132 p_term("t_IS", T_CIS)
3133 p_term("t_ke", T_KE)
3134 p_term("t_ks", T_KS)
3135 p_term("t_le", T_LE)
3136 p_term("t_mb", T_MB)
3137 p_term("t_md", T_MD)
3138 p_term("t_me", T_ME)
3139 p_term("t_mr", T_MR)
3140 p_term("t_ms", T_MS)
3141 p_term("t_nd", T_ND)
3142 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003143 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003144 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003145 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003147 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 p_term("t_RV", T_CRV)
3149 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003150 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003152 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003153 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003154 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003156 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003158 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 p_term("t_te", T_TE)
3160 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003161 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003162 p_term("t_ts", T_TS)
3163 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_ue", T_UE)
3165 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003166 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 p_term("t_vb", T_VB)
3168 p_term("t_ve", T_VE)
3169 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003170 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 p_term("t_vs", T_VS)
3172 p_term("t_WP", T_CWP)
3173 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003174 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 p_term("t_xs", T_XS)
3176 p_term("t_ZH", T_CZH)
3177 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003178 p_term("t_8f", T_8F)
3179 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180
3181/* terminal key codes are not in here */
3182
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003183 /* end marker */
3184 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185};
3186
3187#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3188
3189#ifdef FEAT_MBYTE
3190static char *(p_ambw_values[]) = {"single", "double", NULL};
3191#endif
3192static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003193static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003195#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003196static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003197#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003198#ifdef FEAT_CMDL_COMPL
3199static char *(p_wop_values[]) = {"tagfile", NULL};
3200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201#ifdef FEAT_WAK
3202static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3203#endif
3204static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3206static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208#ifdef FEAT_BROWSE
3209static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3210#endif
3211#ifdef FEAT_SCROLLBIND
3212static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3213#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003214static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003216#ifdef FEAT_AUTOCMD
3217static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3218#else
3219static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003221static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3223#ifdef FEAT_FOLDING
3224static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003225# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003227# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 NULL};
3229static char *(p_fcl_values[]) = {"all", NULL};
3230#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003231#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003232static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003233#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003234#ifdef FEAT_SIGNS
3235static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3236#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003238static void set_option_default(int, int opt_flags, int compatible);
3239static void set_options_default(int opt_flags);
3240static char_u *term_bg_default(void);
3241static void did_set_option(int opt_idx, int opt_flags, int new_value);
3242static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003244static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245#endif
3246#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003247static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003249static char_u *option_expand(int opt_idx, char_u *val);
3250static void didset_options(void);
3251static void didset_options2(void);
3252static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003253#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003254static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003255#else
3256# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3257#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003258static void set_string_option_global(int opt_idx, char_u **varp);
3259static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3260static 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);
3261static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003262#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003268#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003269static char_u *did_set_spell_option(int is_spellfile);
3270static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003271#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003272#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003274#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3276static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3277static void check_redraw(long_u flags);
3278static int findoption(char_u *);
3279static int find_key_option(char_u *);
3280static void showoptions(int all, int opt_flags);
3281static int optval_default(struct vimoption *, char_u *varp);
3282static void showoneopt(struct vimoption *, int opt_flags);
3283static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3284static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3285static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3286static int istermoption(struct vimoption *);
3287static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3288static char_u *get_varp(struct vimoption *);
3289static void option_value2string(struct vimoption *, int opt_flags);
3290static void check_winopt(winopt_T *wop);
3291static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static void langmap_init(void);
3294static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003296static void paste_option_changed(void);
3297static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003301static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3302static int check_opt_strings(char_u *val, char **values, int);
3303static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003304#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307
3308/*
3309 * Initialize the options, first part.
3310 *
3311 * Called only once from main(), just after creating the first buffer.
3312 */
3313 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003314set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315{
3316 char_u *p;
3317 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003318 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319
3320#ifdef FEAT_LANGMAP
3321 langmap_init();
3322#endif
3323
3324 /* Be Vi compatible by default */
3325 p_cp = TRUE;
3326
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003327 /* Use POSIX compatibility when $VIM_POSIX is set. */
3328 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003329 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003330 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003331 set_string_default("shm", (char_u *)"A");
3332 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003333
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334 /*
3335 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003336 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003338 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003339#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003340 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003342 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343# endif
3344#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003345 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003346 set_string_default("sh", p);
3347
3348#ifdef FEAT_WILDIGN
3349 /*
3350 * Set the default for 'backupskip' to include environment variables for
3351 * temp files.
3352 */
3353 {
3354# ifdef UNIX
3355 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3356# else
3357 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3358# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003359 int len;
3360 garray_T ga;
3361 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362
3363 ga_init2(&ga, 1, 100);
3364 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3365 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003366 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367# ifdef UNIX
3368 if (*names[n] == NUL)
3369 p = (char_u *)"/tmp";
3370 else
3371# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003372 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373 if (p != NULL && *p != NUL)
3374 {
3375 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003376 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377 if (ga_grow(&ga, len) == OK)
3378 {
3379 if (ga.ga_len > 0)
3380 STRCAT(ga.ga_data, ",");
3381 STRCAT(ga.ga_data, p);
3382 add_pathsep(ga.ga_data);
3383 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 ga.ga_len += len;
3385 }
3386 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003387 if (mustfree)
3388 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 }
3390 if (ga.ga_data != NULL)
3391 {
3392 set_string_default("bsk", ga.ga_data);
3393 vim_free(ga.ga_data);
3394 }
3395 }
3396#endif
3397
3398 /*
3399 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3400 */
3401 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003402 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003404#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3405 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3406#endif
3407 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003409 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003410 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411#else
3412# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003413 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003414 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003415# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003416 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417# endif
3418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420 opt_idx = findoption((char_u *)"maxmem");
3421 if (opt_idx >= 0)
3422 {
3423#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003424 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3425 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003426#endif
3427 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3428 }
3429 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430 }
3431
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432#ifdef FEAT_SEARCHPATH
3433 {
3434 char_u *cdpath;
3435 char_u *buf;
3436 int i;
3437 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003438 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439
3440 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003441 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442 if (cdpath != NULL)
3443 {
3444 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3445 if (buf != NULL)
3446 {
3447 buf[0] = ','; /* start with ",", current dir first */
3448 j = 1;
3449 for (i = 0; cdpath[i] != NUL; ++i)
3450 {
3451 if (vim_ispathlistsep(cdpath[i]))
3452 buf[j++] = ',';
3453 else
3454 {
3455 if (cdpath[i] == ' ' || cdpath[i] == ',')
3456 buf[j++] = '\\';
3457 buf[j++] = cdpath[i];
3458 }
3459 }
3460 buf[j] = NUL;
3461 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003462 if (opt_idx >= 0)
3463 {
3464 options[opt_idx].def_val[VI_DEFAULT] = buf;
3465 options[opt_idx].flags |= P_DEF_ALLOCED;
3466 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003467 else
3468 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003470 if (mustfree)
3471 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 }
3473 }
3474#endif
3475
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003476#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477 /* Set print encoding on platforms that don't default to latin1 */
3478 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003479# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 (char_u *)"cp1252"
3481# else
3482# ifdef VMS
3483 (char_u *)"dec-mcs"
3484# else
3485# ifdef EBCDIC
3486 (char_u *)"ebcdic-uk"
3487# else
3488# ifdef MAC
3489 (char_u *)"mac-roman"
3490# else /* HPUX */
3491 (char_u *)"hp-roman8"
3492# endif
3493# endif
3494# endif
3495# endif
3496 );
3497#endif
3498
3499#ifdef FEAT_POSTSCRIPT
3500 /* 'printexpr' must be allocated to be able to evaluate it. */
3501 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003502# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003503 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504# else
3505# ifdef VMS
3506 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3507
3508# else
3509 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3510# endif
3511# endif
3512 );
3513#endif
3514
3515 /*
3516 * Set all the options (except the terminal options) to their default
3517 * value. Also set the global value for local options.
3518 */
3519 set_options_default(0);
3520
3521#ifdef FEAT_GUI
3522 if (found_reverse_arg)
3523 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3524#endif
3525
3526 curbuf->b_p_initialized = TRUE;
3527 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003528 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 check_buf_options(curbuf);
3530 check_win_options(curwin);
3531 check_options();
3532
3533 /* Must be before option_expand(), because that one needs vim_isIDc() */
3534 didset_options();
3535
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003536#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003537 /* Use the current chartab for the generic chartab. This is not in
3538 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003539 init_spell_chartab();
3540#endif
3541
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542 /*
3543 * Expand environment variables and things like "~" for the defaults.
3544 * If option_expand() returns non-NULL the variable is expanded. This can
3545 * only happen for non-indirect options.
3546 * Also set the default to the expanded value, so ":set" does not list
3547 * them.
3548 * Don't set the P_ALLOCED flag, because we don't want to free the
3549 * default.
3550 */
3551 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3552 {
3553 if ((options[opt_idx].flags & P_GETTEXT)
3554 && options[opt_idx].var != NULL)
3555 p = (char_u *)_(*(char **)options[opt_idx].var);
3556 else
3557 p = option_expand(opt_idx, NULL);
3558 if (p != NULL && (p = vim_strsave(p)) != NULL)
3559 {
3560 *(char_u **)options[opt_idx].var = p;
3561 /* VIMEXP
3562 * Defaults for all expanded options are currently the same for Vi
3563 * and Vim. When this changes, add some code here! Also need to
3564 * split P_DEF_ALLOCED in two.
3565 */
3566 if (options[opt_idx].flags & P_DEF_ALLOCED)
3567 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3568 options[opt_idx].def_val[VI_DEFAULT] = p;
3569 options[opt_idx].flags |= P_DEF_ALLOCED;
3570 }
3571 }
3572
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 save_file_ff(curbuf); /* Buffer is unchanged */
3574
Bram Moolenaar071d4272004-06-13 20:20:40 +00003575#if defined(FEAT_ARABIC)
3576 /* Detect use of mlterm.
3577 * Mlterm is a terminal emulator akin to xterm that has some special
3578 * abilities (bidi namely).
3579 * NOTE: mlterm's author is being asked to 'set' a variable
3580 * instead of an environment variable due to inheritance.
3581 */
3582 if (mch_getenv((char_u *)"MLTERM") != NULL)
3583 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3584#endif
3585
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003586 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587
3588#ifdef FEAT_MBYTE
3589# if defined(WIN3264) && defined(FEAT_GETTEXT)
3590 /*
3591 * If $LANG isn't set, try to get a good value for it. This makes the
3592 * right language be used automatically. Don't do this for English.
3593 */
3594 if (mch_getenv((char_u *)"LANG") == NULL)
3595 {
3596 char buf[20];
3597
3598 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3599 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3600 * only the first two. */
3601 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3602 (LPTSTR)buf, 20);
3603 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3604 {
3605 /* There are a few exceptions (probably more) */
3606 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3607 STRCPY(buf, "zh_TW");
3608 else if (STRNICMP(buf, "chs", 3) == 0
3609 || STRNICMP(buf, "zhc", 3) == 0)
3610 STRCPY(buf, "zh_CN");
3611 else if (STRNICMP(buf, "jp", 2) == 0)
3612 STRCPY(buf, "ja");
3613 else
3614 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003615 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003616 }
3617 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003618# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003619# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003620 /* Moved to os_mac_conv.c to avoid dependency problems. */
3621 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003622# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623# endif
3624
3625 /* enc_locale() will try to find the encoding of the current locale. */
3626 p = enc_locale();
3627 if (p != NULL)
3628 {
3629 char_u *save_enc;
3630
3631 /* Try setting 'encoding' and check if the value is valid.
3632 * If not, go back to the default "latin1". */
3633 save_enc = p_enc;
3634 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003635 if (STRCMP(p_enc, "gb18030") == 0)
3636 {
3637 /* We don't support "gb18030", but "cp936" is a good substitute
3638 * for practical purposes, thus use that. It's not an alias to
3639 * still support conversion between gb18030 and utf-8. */
3640 p_enc = vim_strsave((char_u *)"cp936");
3641 vim_free(p);
3642 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643 if (mb_init() == NULL)
3644 {
3645 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003646 if (opt_idx >= 0)
3647 {
3648 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3649 options[opt_idx].flags |= P_DEF_ALLOCED;
3650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651
Bram Moolenaard0573012017-10-28 21:11:06 +02003652#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003653 if (STRCMP(p_enc, "latin1") == 0
3654# ifdef FEAT_MBYTE
3655 || enc_utf8
3656# endif
3657 )
3658 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003659 /* Adjust the default for 'isprint' and 'iskeyword' to match
3660 * latin1. Also set the defaults for when 'nocompatible' is
3661 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003662 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003663 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003664 set_string_option_direct((char_u *)"isk", -1,
3665 ISK_LATIN1, OPT_FREE, SID_NONE);
3666 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003667 if (opt_idx >= 0)
3668 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003669 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003670 if (opt_idx >= 0)
3671 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003672 (void)init_chartab();
3673 }
3674#endif
3675
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676# if defined(WIN3264) && !defined(FEAT_GUI)
3677 /* Win32 console: When GetACP() returns a different value from
3678 * GetConsoleCP() set 'termencoding'. */
3679 if (GetACP() != GetConsoleCP())
3680 {
3681 char buf[50];
3682
3683 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3684 p_tenc = vim_strsave((char_u *)buf);
3685 if (p_tenc != NULL)
3686 {
3687 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003688 if (opt_idx >= 0)
3689 {
3690 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3691 options[opt_idx].flags |= P_DEF_ALLOCED;
3692 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693 convert_setup(&input_conv, p_tenc, p_enc);
3694 convert_setup(&output_conv, p_enc, p_tenc);
3695 }
3696 else
3697 p_tenc = empty_option;
3698 }
3699# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003700# if defined(WIN3264) && defined(FEAT_MBYTE)
3701 /* $HOME may have characters in active code page. */
3702 init_homedir();
3703# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704 }
3705 else
3706 {
3707 vim_free(p_enc);
3708 p_enc = save_enc;
3709 }
3710 }
3711#endif
3712
3713#ifdef FEAT_MULTI_LANG
3714 /* Set the default for 'helplang'. */
3715 set_helplang_default(get_mess_lang());
3716#endif
3717}
3718
3719/*
3720 * Set an option to its default value.
3721 * This does not take care of side effects!
3722 */
3723 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003724set_option_default(
3725 int opt_idx,
3726 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3727 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728{
3729 char_u *varp; /* pointer to variable for current option */
3730 int dvi; /* index in def_val[] */
3731 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003732 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3734
3735 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3736 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003737 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738 {
3739 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3740 if (flags & P_STRING)
3741 {
3742 /* Use set_string_option_direct() for local options to handle
3743 * freeing and allocating the value. */
3744 if (options[opt_idx].indir != PV_NONE)
3745 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003746 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747 else
3748 {
3749 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3750 free_string_option(*(char_u **)(varp));
3751 *(char_u **)varp = options[opt_idx].def_val[dvi];
3752 options[opt_idx].flags &= ~P_ALLOCED;
3753 }
3754 }
3755 else if (flags & P_NUM)
3756 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003757 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758 win_comp_scroll(curwin);
3759 else
3760 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003761 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 /* May also set global value for local option. */
3763 if (both)
3764 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3765 *(long *)varp;
3766 }
3767 }
3768 else /* P_BOOL */
3769 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003770 /* the cast to long is required for Manx C, long_i is needed for
3771 * MSVC */
3772 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003773#ifdef UNIX
3774 /* 'modeline' defaults to off for root */
3775 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3776 *(int *)varp = FALSE;
3777#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003778 /* May also set global value for local option. */
3779 if (both)
3780 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3781 *(int *)varp;
3782 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003783
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003784 /* The default value is not insecure. */
3785 flagsp = insecure_flag(opt_idx, opt_flags);
3786 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 }
3788
3789#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003790 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791#endif
3792}
3793
3794/*
3795 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003796 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 */
3798 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003799set_options_default(
3800 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801{
3802 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003803 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003804 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805
3806 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003807 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003808#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003809 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003810 || (TRUE
3811# if defined(FEAT_MBYTE)
3812 && options[i].var != (char_u *)&p_enc
3813# endif
3814# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003815 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003816 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003817# endif
3818 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003819#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003820 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821 set_option_default(i, opt_flags, p_cp);
3822
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003824 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003826#ifdef FEAT_CINDENT
3827 parse_cino(curbuf);
3828#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829}
3830
3831/*
3832 * Set the Vi-default value of a string option.
3833 * Used for 'sh', 'backupskip' and 'term'.
3834 */
3835 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003836set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837{
3838 char_u *p;
3839 int opt_idx;
3840
3841 p = vim_strsave(val);
3842 if (p != NULL) /* we don't want a NULL */
3843 {
3844 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003845 if (opt_idx >= 0)
3846 {
3847 if (options[opt_idx].flags & P_DEF_ALLOCED)
3848 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3849 options[opt_idx].def_val[VI_DEFAULT] = p;
3850 options[opt_idx].flags |= P_DEF_ALLOCED;
3851 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 }
3853}
3854
3855/*
3856 * Set the Vi-default value of a number option.
3857 * Used for 'lines' and 'columns'.
3858 */
3859 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003860set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003862 int opt_idx;
3863
3864 opt_idx = findoption((char_u *)name);
3865 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003866 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867}
3868
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003869#if defined(EXITFREE) || defined(PROTO)
3870/*
3871 * Free all options.
3872 */
3873 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003874free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003875{
3876 int i;
3877
3878 for (i = 0; !istermoption(&options[i]); i++)
3879 {
3880 if (options[i].indir == PV_NONE)
3881 {
3882 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003883 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003884 free_string_option(*(char_u **)options[i].var);
3885 if (options[i].flags & P_DEF_ALLOCED)
3886 free_string_option(options[i].def_val[VI_DEFAULT]);
3887 }
3888 else if (options[i].var != VAR_WIN
3889 && (options[i].flags & P_STRING))
3890 /* buffer-local option: free global value */
3891 free_string_option(*(char_u **)options[i].var);
3892 }
3893}
3894#endif
3895
3896
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897/*
3898 * Initialize the options, part two: After getting Rows and Columns and
3899 * setting 'term'.
3900 */
3901 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003902set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003904 int idx;
3905
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906 /*
3907 * 'scroll' defaults to half the window height. Note that this default is
3908 * wrong when the window height changes.
3909 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003910 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003911 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003912 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003913 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 comp_col();
3915
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003916 /*
3917 * 'window' is only for backwards compatibility with Vi.
3918 * Default is Rows - 1.
3919 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003920 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003921 p_window = Rows - 1;
3922 set_number_default("window", Rows - 1);
3923
Bram Moolenaarf740b292006-02-16 22:11:02 +00003924 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003925#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003926 /*
3927 * If 'background' wasn't set by the user, try guessing the value,
3928 * depending on the terminal name. Only need to check for terminals
3929 * with a dark background, that can handle color.
3930 */
3931 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003932 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3933 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003935 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003936 /* don't mark it as set, when starting the GUI it may be
3937 * changed again */
3938 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 }
3940#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003941
3942#ifdef CURSOR_SHAPE
3943 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3944#endif
3945#ifdef FEAT_MOUSESHAPE
3946 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3947#endif
3948#ifdef FEAT_PRINTER
3949 (void)parse_printoptions(); /* parse 'printoptions' default value */
3950#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951}
3952
3953/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003954 * Return "dark" or "light" depending on the kind of terminal.
3955 * This is just guessing! Recognized are:
3956 * "linux" Linux console
3957 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003958 * "cygwin.*" Cygwin shell
3959 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003960 * We also check the COLORFGBG environment variable, which is set by
3961 * rxvt and derivatives. This variable contains either two or three
3962 * values separated by semicolons; we want the last value in either
3963 * case. If this value is 0-6 or 8, our background is dark.
3964 */
3965 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003966term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003967{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003968#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003969 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003970 return (char_u *)"dark";
3971#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003972 char_u *p;
3973
Bram Moolenaarf740b292006-02-16 22:11:02 +00003974 if (STRCMP(T_NAME, "linux") == 0
3975 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003976 || STRNCMP(T_NAME, "cygwin", 6) == 0
3977 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003978 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3979 && (p = vim_strrchr(p, ';')) != NULL
3980 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3981 && p[2] == NUL))
3982 return (char_u *)"dark";
3983 return (char_u *)"light";
3984#endif
3985}
3986
3987/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988 * Initialize the options, part three: After reading the .vimrc
3989 */
3990 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003991set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003992{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003993#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994/*
3995 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3996 * This is done after other initializations, where 'shell' might have been
3997 * set, but only if they have not been set before.
3998 */
3999 char_u *p;
4000 int idx_srr;
4001 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004002# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 int idx_sp;
4004 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004005# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004006
4007 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004008 if (idx_srr < 0)
4009 do_srr = FALSE;
4010 else
4011 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004012# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004013 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004014 if (idx_sp < 0)
4015 do_sp = FALSE;
4016 else
4017 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004018# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004019 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 if (p != NULL)
4021 {
4022 /*
4023 * Default for p_sp is "| tee", for p_srr is ">".
4024 * For known shells it is changed here to include stderr.
4025 */
4026 if ( fnamecmp(p, "csh") == 0
4027 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004028# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 || fnamecmp(p, "csh.exe") == 0
4030 || fnamecmp(p, "tcsh.exe") == 0
4031# endif
4032 )
4033 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004034# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035 if (do_sp)
4036 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004037# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004039# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004041# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4043 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004044# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045 if (do_srr)
4046 {
4047 p_srr = (char_u *)">&";
4048 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4049 }
4050 }
4051 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004052 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 if ( fnamecmp(p, "sh") == 0
4054 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004055 || fnamecmp(p, "mksh") == 0
4056 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004058 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004060 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 || fnamecmp(p, "cmd") == 0
4063 || fnamecmp(p, "sh.exe") == 0
4064 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004065 || fnamecmp(p, "mksh.exe") == 0
4066 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004068 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 || fnamecmp(p, "bash.exe") == 0
4070 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004072 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004074# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075 if (do_sp)
4076 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004077# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004081# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4083 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004084# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 if (do_srr)
4086 {
4087 p_srr = (char_u *)">%s 2>&1";
4088 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4089 }
4090 }
4091 vim_free(p);
4092 }
4093#endif
4094
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004095#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004097 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4098 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 * This is done after other initializations, where 'shell' might have been
4100 * set, but only if they have not been set before. Default for p_shcf is
4101 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004102 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004104 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 {
4106 int idx3;
4107
4108 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004109 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 {
4111 p_shcf = (char_u *)"-c";
4112 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4113 }
4114
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 /* Somehow Win32 requires the quotes around the redirection too */
4116 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004117 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 {
4119 p_sxq = (char_u *)"\"";
4120 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4121 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004123 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4124 {
4125 int idx3;
4126
4127 /*
4128 * cmd.exe on Windows will strip the first and last double quote given
4129 * on the command line, e.g. most of the time things like:
4130 * cmd /c "my path/to/echo" "my args to echo"
4131 * become:
4132 * my path/to/echo" "my args to echo
4133 * when executed.
4134 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004135 * To avoid this, set shellxquote to surround the command in
4136 * parenthesis. This appears to make most commands work, without
4137 * breaking commands that worked previously, such as
4138 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004139 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004140 idx3 = findoption((char_u *)"sxq");
4141 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4142 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004143 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004144 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4145 }
4146
Bram Moolenaara64ba222012-02-12 23:23:31 +01004147 idx3 = findoption((char_u *)"shcf");
4148 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4149 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004150 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004151 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4152 }
4153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154#endif
4155
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004156 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004157 {
4158 int idx_ffs = findoption((char_u *)"ffs");
4159
4160 /* Apply the first entry of 'fileformats' to the initial buffer. */
4161 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4162 set_fileformat(default_fileformat(), OPT_LOCAL);
4163 }
4164
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165#ifdef FEAT_TITLE
4166 set_title_defaults();
4167#endif
4168}
4169
4170#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4171/*
4172 * When 'helplang' is still at its default value, set it to "lang".
4173 * Only the first two characters of "lang" are used.
4174 */
4175 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004176set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177{
4178 int idx;
4179
4180 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4181 return;
4182 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004183 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184 {
4185 if (options[idx].flags & P_ALLOCED)
4186 free_string_option(p_hlg);
4187 p_hlg = vim_strsave(lang);
4188 if (p_hlg == NULL)
4189 p_hlg = empty_option;
4190 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004191 {
4192 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4193 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4194 {
4195 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4196 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4197 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004198 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004199 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004200 options[idx].flags |= P_ALLOCED;
4201 }
4202}
4203#endif
4204
4205#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004206static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207
4208 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004209gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210{
4211 if (gui_get_lightness(gui.back_pixel) < 127)
4212 return (char_u *)"dark";
4213 return (char_u *)"light";
4214}
4215
4216/*
4217 * Option initializations that can only be done after opening the GUI window.
4218 */
4219 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004220init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221{
4222 /* Set the 'background' option according to the lightness of the
4223 * background color, unless the user has set it already. */
4224 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4225 {
4226 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4227 highlight_changed();
4228 }
4229}
4230#endif
4231
4232#ifdef FEAT_TITLE
4233/*
4234 * 'title' and 'icon' only default to true if they have not been set or reset
4235 * in .vimrc and we can read the old value.
4236 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4237 * they can be reset. This reduces startup time when using X on a remote
4238 * machine.
4239 */
4240 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004241set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242{
4243 int idx1;
4244 long val;
4245
4246 /*
4247 * If GUI is (going to be) used, we can always set the window title and
4248 * icon name. Saves a bit of time, because the X11 display server does
4249 * not need to be contacted.
4250 */
4251 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004252 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004253 {
4254#ifdef FEAT_GUI
4255 if (gui.starting || gui.in_use)
4256 val = TRUE;
4257 else
4258#endif
4259 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004260 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004261 p_title = val;
4262 }
4263 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004264 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004265 {
4266#ifdef FEAT_GUI
4267 if (gui.starting || gui.in_use)
4268 val = TRUE;
4269 else
4270#endif
4271 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004272 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004273 p_icon = val;
4274 }
4275}
4276#endif
4277
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004278#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4279 static void
4280trigger_optionsset_string(
4281 int opt_idx,
4282 int opt_flags,
4283 char_u *oldval,
4284 char_u *newval)
4285{
4286 if (oldval != NULL && newval != NULL)
4287 {
4288 char_u buf_type[7];
4289
4290 sprintf((char *)buf_type, "%s",
4291 (opt_flags & OPT_LOCAL) ? "local" : "global");
4292 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4293 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4294 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4295 apply_autocmds(EVENT_OPTIONSET,
4296 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4297 reset_v_option_vars();
4298 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004299}
4300#endif
4301
Bram Moolenaar071d4272004-06-13 20:20:40 +00004302/*
4303 * Parse 'arg' for option settings.
4304 *
4305 * 'arg' may be IObuff, but only when no errors can be present and option
4306 * does not need to be expanded with option_expand().
4307 * "opt_flags":
4308 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004309 * OPT_GLOBAL for ":setglobal"
4310 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004312 * OPT_WINONLY to only set window-local options
4313 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314 *
4315 * returns FAIL if an error is detected, OK otherwise
4316 */
4317 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004318do_set(
4319 char_u *arg, /* option string (may be written to!) */
4320 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004321{
4322 int opt_idx;
4323 char_u *errmsg;
4324 char_u errbuf[80];
4325 char_u *startarg;
4326 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4327 int nextchar; /* next non-white char after option name */
4328 int afterchar; /* character just after option name */
4329 int len;
4330 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004331 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004332 int key;
4333 long_u flags; /* flags for current option */
4334 char_u *varp = NULL; /* pointer to variable for current option */
4335 int did_show = FALSE; /* already showed one value */
4336 int adding; /* "opt+=arg" */
4337 int prepending; /* "opt^=arg" */
4338 int removing; /* "opt-=arg" */
4339 int cp_val = 0;
4340 char_u key_name[2];
4341
4342 if (*arg == NUL)
4343 {
4344 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004345 did_show = TRUE;
4346 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004347 }
4348
4349 while (*arg != NUL) /* loop to process all options */
4350 {
4351 errmsg = NULL;
4352 startarg = arg; /* remember for error message */
4353
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004354 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4355 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004356 {
4357 /*
4358 * ":set all" show all options.
4359 * ":set all&" set all options to their default value.
4360 */
4361 arg += 3;
4362 if (*arg == '&')
4363 {
4364 ++arg;
4365 /* Only for :set command set global value of local options. */
4366 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004367 didset_options();
4368 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004369 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004370 }
4371 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004372 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004374 did_show = TRUE;
4375 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004376 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004377 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004378 {
4379 showoptions(2, opt_flags);
4380 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004381 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004382 arg += 7;
4383 }
4384 else
4385 {
4386 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004387 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004388 {
4389 prefix = 0;
4390 arg += 2;
4391 }
4392 else if (STRNCMP(arg, "inv", 3) == 0)
4393 {
4394 prefix = 2;
4395 arg += 3;
4396 }
4397
4398 /* find end of name */
4399 key = 0;
4400 if (*arg == '<')
4401 {
4402 nextchar = 0;
4403 opt_idx = -1;
4404 /* look out for <t_>;> */
4405 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4406 len = 5;
4407 else
4408 {
4409 len = 1;
4410 while (arg[len] != NUL && arg[len] != '>')
4411 ++len;
4412 }
4413 if (arg[len] != '>')
4414 {
4415 errmsg = e_invarg;
4416 goto skip;
4417 }
4418 arg[len] = NUL; /* put NUL after name */
4419 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4420 opt_idx = findoption(arg + 1);
4421 arg[len++] = '>'; /* restore '>' */
4422 if (opt_idx == -1)
4423 key = find_key_option(arg + 1);
4424 }
4425 else
4426 {
4427 len = 0;
4428 /*
4429 * The two characters after "t_" may not be alphanumeric.
4430 */
4431 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4432 len = 4;
4433 else
4434 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4435 ++len;
4436 nextchar = arg[len];
4437 arg[len] = NUL; /* put NUL after name */
4438 opt_idx = findoption(arg);
4439 arg[len] = nextchar; /* restore nextchar */
4440 if (opt_idx == -1)
4441 key = find_key_option(arg);
4442 }
4443
4444 /* remember character after option name */
4445 afterchar = arg[len];
4446
4447 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004448 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004449 ++len;
4450
4451 adding = FALSE;
4452 prepending = FALSE;
4453 removing = FALSE;
4454 if (arg[len] != NUL && arg[len + 1] == '=')
4455 {
4456 if (arg[len] == '+')
4457 {
4458 adding = TRUE; /* "+=" */
4459 ++len;
4460 }
4461 else if (arg[len] == '^')
4462 {
4463 prepending = TRUE; /* "^=" */
4464 ++len;
4465 }
4466 else if (arg[len] == '-')
4467 {
4468 removing = TRUE; /* "-=" */
4469 ++len;
4470 }
4471 }
4472 nextchar = arg[len];
4473
4474 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4475 {
4476 errmsg = (char_u *)N_("E518: Unknown option");
4477 goto skip;
4478 }
4479
4480 if (opt_idx >= 0)
4481 {
4482 if (options[opt_idx].var == NULL) /* hidden option: skip */
4483 {
4484 /* Only give an error message when requesting the value of
4485 * a hidden option, ignore setting it. */
4486 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4487 && (!(options[opt_idx].flags & P_BOOL)
4488 || nextchar == '?'))
4489 errmsg = (char_u *)N_("E519: Option not supported");
4490 goto skip;
4491 }
4492
4493 flags = options[opt_idx].flags;
4494 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4495 }
4496 else
4497 {
4498 flags = P_STRING;
4499 if (key < 0)
4500 {
4501 key_name[0] = KEY2TERMCAP0(key);
4502 key_name[1] = KEY2TERMCAP1(key);
4503 }
4504 else
4505 {
4506 key_name[0] = KS_KEY;
4507 key_name[1] = (key & 0xff);
4508 }
4509 }
4510
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004511 /* Skip all options that are not window-local (used when showing
4512 * an already loaded buffer in a window). */
4513 if ((opt_flags & OPT_WINONLY)
4514 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4515 goto skip;
4516
Bram Moolenaara3227e22006-03-08 21:32:40 +00004517 /* Skip all options that are window-local (used for :vimgrep). */
4518 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4519 && options[opt_idx].var == VAR_WIN)
4520 goto skip;
4521
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004522 /* Disallow changing some options from modelines. */
4523 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004524 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004525 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004526 {
4527 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4528 goto skip;
4529 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004530#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004531 /* In diff mode some options are overruled. This avoids that
4532 * 'foldmethod' becomes "marker" instead of "diff" and that
4533 * "wrap" gets set. */
4534 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004535 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004536 && (
4537#ifdef FEAT_FOLDING
4538 options[opt_idx].indir == PV_FDM ||
4539#endif
4540 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004541 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004543 }
4544
4545#ifdef HAVE_SANDBOX
4546 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004547 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004548 {
4549 errmsg = (char_u *)_(e_sandbox);
4550 goto skip;
4551 }
4552#endif
4553
4554 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4555 {
4556 arg += len;
4557 cp_val = p_cp;
4558 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4559 {
4560 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4561 {
4562 cp_val = FALSE;
4563 arg += 3;
4564 }
4565 else /* "opt&vi": set to Vi default */
4566 {
4567 cp_val = TRUE;
4568 arg += 2;
4569 }
4570 }
4571 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004572 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004573 {
4574 errmsg = e_trailing;
4575 goto skip;
4576 }
4577 }
4578
4579 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004580 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4581 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004582 */
4583 if (nextchar == '?'
4584 || (prefix == 1
4585 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4586 && !(flags & P_BOOL)))
4587 {
4588 /*
4589 * print value
4590 */
4591 if (did_show)
4592 msg_putchar('\n'); /* cursor below last one */
4593 else
4594 {
4595 gotocmdline(TRUE); /* cursor at status line */
4596 did_show = TRUE; /* remember that we did a line */
4597 }
4598 if (opt_idx >= 0)
4599 {
4600 showoneopt(&options[opt_idx], opt_flags);
4601#ifdef FEAT_EVAL
4602 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004603 {
4604 /* Mention where the option was last set. */
4605 if (varp == options[opt_idx].var)
4606 last_set_msg(options[opt_idx].scriptID);
4607 else if ((int)options[opt_idx].indir & PV_WIN)
4608 last_set_msg(curwin->w_p_scriptID[
4609 (int)options[opt_idx].indir & PV_MASK]);
4610 else if ((int)options[opt_idx].indir & PV_BUF)
4611 last_set_msg(curbuf->b_p_scriptID[
4612 (int)options[opt_idx].indir & PV_MASK]);
4613 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004614#endif
4615 }
4616 else
4617 {
4618 char_u *p;
4619
4620 p = find_termcode(key_name);
4621 if (p == NULL)
4622 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004623 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004624 goto skip;
4625 }
4626 else
4627 (void)show_one_termcode(key_name, p, TRUE);
4628 }
4629 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004630 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004631 errmsg = e_trailing;
4632 }
4633 else
4634 {
4635 if (flags & P_BOOL) /* boolean */
4636 {
4637 if (nextchar == '=' || nextchar == ':')
4638 {
4639 errmsg = e_invarg;
4640 goto skip;
4641 }
4642
4643 /*
4644 * ":set opt!": invert
4645 * ":set opt&": reset to default value
4646 * ":set opt<": reset to global value
4647 */
4648 if (nextchar == '!')
4649 value = *(int *)(varp) ^ 1;
4650 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004651 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652 ((flags & P_VI_DEF) || cp_val)
4653 ? VI_DEFAULT : VIM_DEFAULT];
4654 else if (nextchar == '<')
4655 {
4656 /* For 'autoread' -1 means to use global value. */
4657 if ((int *)varp == &curbuf->b_p_ar
4658 && opt_flags == OPT_LOCAL)
4659 value = -1;
4660 else
4661 value = *(int *)get_varp_scope(&(options[opt_idx]),
4662 OPT_GLOBAL);
4663 }
4664 else
4665 {
4666 /*
4667 * ":set invopt": invert
4668 * ":set opt" or ":set noopt": set or reset
4669 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004670 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004671 {
4672 errmsg = e_trailing;
4673 goto skip;
4674 }
4675 if (prefix == 2) /* inv */
4676 value = *(int *)(varp) ^ 1;
4677 else
4678 value = prefix;
4679 }
4680
4681 errmsg = set_bool_option(opt_idx, varp, (int)value,
4682 opt_flags);
4683 }
4684 else /* numeric or string */
4685 {
4686 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4687 || prefix != 1)
4688 {
4689 errmsg = e_invarg;
4690 goto skip;
4691 }
4692
4693 if (flags & P_NUM) /* numeric */
4694 {
4695 /*
4696 * Different ways to set a number option:
4697 * & set to default value
4698 * < set to global value
4699 * <xx> accept special key codes for 'wildchar'
4700 * c accept any non-digit for 'wildchar'
4701 * [-]0-9 set number
4702 * other error
4703 */
4704 ++arg;
4705 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004706 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004707 ((flags & P_VI_DEF) || cp_val)
4708 ? VI_DEFAULT : VIM_DEFAULT];
4709 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004710 {
4711 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4712 * use the global value. */
4713 if ((long *)varp == &curbuf->b_p_ul
4714 && opt_flags == OPT_LOCAL)
4715 value = NO_LOCAL_UNDOLEVEL;
4716 else
4717 value = *(long *)get_varp_scope(
4718 &(options[opt_idx]), OPT_GLOBAL);
4719 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004720 else if (((long *)varp == &p_wc
4721 || (long *)varp == &p_wcm)
4722 && (*arg == '<'
4723 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004724 || (*arg != NUL
4725 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004726 && !VIM_ISDIGIT(*arg))))
4727 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004728 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004729 if (value == 0 && (long *)varp != &p_wcm)
4730 {
4731 errmsg = e_invarg;
4732 goto skip;
4733 }
4734 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004735 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4736 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004737 /* Allow negative (for 'undolevels'), octal and
4738 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004739 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4740 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004741 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004742 {
4743 errmsg = e_invarg;
4744 goto skip;
4745 }
4746 }
4747 else
4748 {
4749 errmsg = (char_u *)N_("E521: Number required after =");
4750 goto skip;
4751 }
4752
4753 if (adding)
4754 value = *(long *)varp + value;
4755 if (prepending)
4756 value = *(long *)varp * value;
4757 if (removing)
4758 value = *(long *)varp - value;
4759 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004760 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004761 }
4762 else if (opt_idx >= 0) /* string */
4763 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004764 char_u *save_arg = NULL;
4765 char_u *s = NULL;
4766 char_u *oldval = NULL; /* previous value if *varp */
4767 char_u *newval;
4768 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004769#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004770 char_u *saved_origval = NULL;
4771 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004772#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004773 unsigned newlen;
4774 int comma;
4775 int bs;
4776 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004777 was allocated */
4778
4779 /* When using ":set opt=val" for a global option
4780 * with a local value the local value will be
4781 * reset, use the global value here. */
4782 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004783 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004784 varp = options[opt_idx].var;
4785
4786 /* The old value is kept until we are sure that the
4787 * new value is valid. */
4788 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004789
4790 /* When setting the local value of a global
4791 * option, the old value may be the global value. */
4792 if (((int)options[opt_idx].indir & PV_BOTH)
4793 && (opt_flags & OPT_LOCAL))
4794 origval = *(char_u **)get_varp(
4795 &options[opt_idx]);
4796 else
4797 origval = oldval;
4798
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799 if (nextchar == '&') /* set to default val */
4800 {
4801 newval = options[opt_idx].def_val[
4802 ((flags & P_VI_DEF) || cp_val)
4803 ? VI_DEFAULT : VIM_DEFAULT];
4804 if ((char_u **)varp == &p_bg)
4805 {
4806 /* guess the value of 'background' */
4807#ifdef FEAT_GUI
4808 if (gui.in_use)
4809 newval = gui_bg_default();
4810 else
4811#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004812 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004813 }
4814
4815 /* expand environment variables and ~ (since the
4816 * default value was already expanded, only
4817 * required when an environment variable was set
4818 * later */
4819 if (newval == NULL)
4820 newval = empty_option;
4821 else
4822 {
4823 s = option_expand(opt_idx, newval);
4824 if (s == NULL)
4825 s = newval;
4826 newval = vim_strsave(s);
4827 }
4828 new_value_alloced = TRUE;
4829 }
4830 else if (nextchar == '<') /* set to global val */
4831 {
4832 newval = vim_strsave(*(char_u **)get_varp_scope(
4833 &(options[opt_idx]), OPT_GLOBAL));
4834 new_value_alloced = TRUE;
4835 }
4836 else
4837 {
4838 ++arg; /* jump to after the '=' or ':' */
4839
4840 /*
4841 * Set 'keywordprg' to ":help" if an empty
4842 * value was passed to :set by the user.
4843 * Misuse errbuf[] for the resulting string.
4844 */
4845 if (varp == (char_u *)&p_kp
4846 && (*arg == NUL || *arg == ' '))
4847 {
4848 STRCPY(errbuf, ":help");
4849 save_arg = arg;
4850 arg = errbuf;
4851 }
4852 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004853 * Convert 'backspace' number to string, for
4854 * adding, prepending and removing string.
4855 */
4856 else if (varp == (char_u *)&p_bs
4857 && VIM_ISDIGIT(**(char_u **)varp))
4858 {
4859 i = getdigits((char_u **)varp);
4860 switch (i)
4861 {
4862 case 0:
4863 *(char_u **)varp = empty_option;
4864 break;
4865 case 1:
4866 *(char_u **)varp = vim_strsave(
4867 (char_u *)"indent,eol");
4868 break;
4869 case 2:
4870 *(char_u **)varp = vim_strsave(
4871 (char_u *)"indent,eol,start");
4872 break;
4873 }
4874 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004875 if (origval == oldval)
4876 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004877 oldval = *(char_u **)varp;
4878 }
4879 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004880 * Convert 'whichwrap' number to string, for
4881 * backwards compatibility with Vim 3.0.
4882 * Misuse errbuf[] for the resulting string.
4883 */
4884 else if (varp == (char_u *)&p_ww
4885 && VIM_ISDIGIT(*arg))
4886 {
4887 *errbuf = NUL;
4888 i = getdigits(&arg);
4889 if (i & 1)
4890 STRCAT(errbuf, "b,");
4891 if (i & 2)
4892 STRCAT(errbuf, "s,");
4893 if (i & 4)
4894 STRCAT(errbuf, "h,l,");
4895 if (i & 8)
4896 STRCAT(errbuf, "<,>,");
4897 if (i & 16)
4898 STRCAT(errbuf, "[,],");
4899 if (*errbuf != NUL) /* remove trailing , */
4900 errbuf[STRLEN(errbuf) - 1] = NUL;
4901 save_arg = arg;
4902 arg = errbuf;
4903 }
4904 /*
4905 * Remove '>' before 'dir' and 'bdir', for
4906 * backwards compatibility with version 3.0
4907 */
4908 else if ( *arg == '>'
4909 && (varp == (char_u *)&p_dir
4910 || varp == (char_u *)&p_bdir))
4911 {
4912 ++arg;
4913 }
4914
Bram Moolenaar071d4272004-06-13 20:20:40 +00004915 /*
4916 * Copy the new string into allocated memory.
4917 * Can't use set_string_option_direct(), because
4918 * we need to remove the backslashes.
4919 */
4920 /* get a bit too much */
4921 newlen = (unsigned)STRLEN(arg) + 1;
4922 if (adding || prepending || removing)
4923 newlen += (unsigned)STRLEN(origval) + 1;
4924 newval = alloc(newlen);
4925 if (newval == NULL) /* out of mem, don't change */
4926 break;
4927 s = newval;
4928
4929 /*
4930 * Copy the string, skip over escaped chars.
4931 * For MS-DOS and WIN32 backslashes before normal
4932 * file name characters are not removed, and keep
4933 * backslash at start, for "\\machine\path", but
4934 * do remove it for "\\\\machine\\path".
4935 * The reverse is found in ExpandOldSetting().
4936 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004937 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004938 {
4939 if (*arg == '\\' && arg[1] != NUL
4940#ifdef BACKSLASH_IN_FILENAME
4941 && !((flags & P_EXPAND)
4942 && vim_isfilec(arg[1])
4943 && (arg[1] != '\\'
4944 || (s == newval
4945 && arg[2] != '\\')))
4946#endif
4947 )
4948 ++arg; /* remove backslash */
4949#ifdef FEAT_MBYTE
4950 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004951 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004952 {
4953 /* copy multibyte char */
4954 mch_memmove(s, arg, (size_t)i);
4955 arg += i;
4956 s += i;
4957 }
4958 else
4959#endif
4960 *s++ = *arg++;
4961 }
4962 *s = NUL;
4963
4964 /*
4965 * Expand environment variables and ~.
4966 * Don't do it when adding without inserting a
4967 * comma.
4968 */
4969 if (!(adding || prepending || removing)
4970 || (flags & P_COMMA))
4971 {
4972 s = option_expand(opt_idx, newval);
4973 if (s != NULL)
4974 {
4975 vim_free(newval);
4976 newlen = (unsigned)STRLEN(s) + 1;
4977 if (adding || prepending || removing)
4978 newlen += (unsigned)STRLEN(origval) + 1;
4979 newval = alloc(newlen);
4980 if (newval == NULL)
4981 break;
4982 STRCPY(newval, s);
4983 }
4984 }
4985
4986 /* locate newval[] in origval[] when removing it
4987 * and when adding to avoid duplicates */
4988 i = 0; /* init for GCC */
4989 if (removing || (flags & P_NODUP))
4990 {
4991 i = (int)STRLEN(newval);
4992 bs = 0;
4993 for (s = origval; *s; ++s)
4994 {
4995 if ((!(flags & P_COMMA)
4996 || s == origval
4997 || (s[-1] == ',' && !(bs & 1)))
4998 && STRNCMP(s, newval, i) == 0
4999 && (!(flags & P_COMMA)
5000 || s[i] == ','
5001 || s[i] == NUL))
5002 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005003 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005004 * even number of backslashes or a single
5005 * backslash preceded by a comma before it
5006 * is recognized as a separator */
5007 if ((s > origval + 1
5008 && s[-1] == '\\'
5009 && s[-2] != ',')
5010 || (s == origval + 1
5011 && s[-1] == '\\'))
5012
Bram Moolenaar071d4272004-06-13 20:20:40 +00005013 ++bs;
5014 else
5015 bs = 0;
5016 }
5017
5018 /* do not add if already there */
5019 if ((adding || prepending) && *s)
5020 {
5021 prepending = FALSE;
5022 adding = FALSE;
5023 STRCPY(newval, origval);
5024 }
5025 }
5026
5027 /* concatenate the two strings; add a ',' if
5028 * needed */
5029 if (adding || prepending)
5030 {
5031 comma = ((flags & P_COMMA) && *origval != NUL
5032 && *newval != NUL);
5033 if (adding)
5034 {
5035 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005036 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005037 if (comma && i > 1
5038 && (flags & P_ONECOMMA) == P_ONECOMMA
5039 && origval[i - 1] == ','
5040 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005041 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005042 mch_memmove(newval + i + comma, newval,
5043 STRLEN(newval) + 1);
5044 mch_memmove(newval, origval, (size_t)i);
5045 }
5046 else
5047 {
5048 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005049 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005050 }
5051 if (comma)
5052 newval[i] = ',';
5053 }
5054
5055 /* Remove newval[] from origval[]. (Note: "i" has
5056 * been set above and is used here). */
5057 if (removing)
5058 {
5059 STRCPY(newval, origval);
5060 if (*s)
5061 {
5062 /* may need to remove a comma */
5063 if (flags & P_COMMA)
5064 {
5065 if (s == origval)
5066 {
5067 /* include comma after string */
5068 if (s[i] == ',')
5069 ++i;
5070 }
5071 else
5072 {
5073 /* include comma before string */
5074 --s;
5075 ++i;
5076 }
5077 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005078 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005079 }
5080 }
5081
5082 if (flags & P_FLAGLIST)
5083 {
5084 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005085 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005086 {
5087 /* if options have P_FLAGLIST and
5088 * P_ONECOMMA such as 'whichwrap' */
5089 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005090 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005091 if (*s != ',' && *(s + 1) == ','
5092 && vim_strchr(s + 2, *s) != NULL)
5093 {
5094 /* Remove the duplicated value and
5095 * the next comma. */
5096 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005097 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005099 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005100 else
5101 {
5102 if ((!(flags & P_COMMA) || *s != ',')
5103 && vim_strchr(s + 1, *s) != NULL)
5104 {
5105 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005106 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005107 }
5108 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005109 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 }
5112
5113 if (save_arg != NULL) /* number for 'whichwrap' */
5114 arg = save_arg;
5115 new_value_alloced = TRUE;
5116 }
5117
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005118 /*
5119 * Set the new value.
5120 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005121 *(char_u **)(varp) = newval;
5122
Bram Moolenaar53744302015-07-17 17:38:22 +02005123#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005124 if (!starting
5125# ifdef FEAT_CRYPT
5126 && options[opt_idx].indir != PV_KEY
5127# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005128 && origval != NULL && newval != NULL)
5129 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005130 /* origval may be freed by
5131 * did_set_string_option(), make a copy. */
5132 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005133 /* newval (and varp) may become invalid if the
5134 * buffer is closed by autocommands. */
5135 saved_newval = vim_strsave(newval);
5136 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005137#endif
5138
Bram Moolenaar071d4272004-06-13 20:20:40 +00005139 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005140 * ":set" on local options. Note: when setting 'syntax'
5141 * or 'filetype' autocommands may be triggered that can
5142 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005143 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5144 new_value_alloced, oldval, errbuf, opt_flags);
5145
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005146#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5147 if (errmsg == NULL)
5148 trigger_optionsset_string(opt_idx, opt_flags,
5149 saved_origval, saved_newval);
5150 vim_free(saved_origval);
5151 vim_free(saved_newval);
5152#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005153 /* If error detected, print the error message. */
5154 if (errmsg != NULL)
5155 goto skip;
5156 }
5157 else /* key code option */
5158 {
5159 char_u *p;
5160
5161 if (nextchar == '&')
5162 {
5163 if (add_termcap_entry(key_name, TRUE) == FAIL)
5164 errmsg = (char_u *)N_("E522: Not found in termcap");
5165 }
5166 else
5167 {
5168 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005169 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005170 if (*p == '\\' && p[1] != NUL)
5171 ++p;
5172 nextchar = *p;
5173 *p = NUL;
5174 add_termcode(key_name, arg, FALSE);
5175 *p = nextchar;
5176 }
5177 if (full_screen)
5178 ttest(FALSE);
5179 redraw_all_later(CLEAR);
5180 }
5181 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005182
Bram Moolenaar071d4272004-06-13 20:20:40 +00005183 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005184 did_set_option(opt_idx, opt_flags,
5185 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186 }
5187
5188skip:
5189 /*
5190 * Advance to next argument.
5191 * - skip until a blank found, taking care of backslashes
5192 * - skip blanks
5193 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5194 */
5195 for (i = 0; i < 2 ; ++i)
5196 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005197 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005198 if (*arg++ == '\\' && *arg != NUL)
5199 ++arg;
5200 arg = skipwhite(arg);
5201 if (*arg != '=')
5202 break;
5203 }
5204 }
5205
5206 if (errmsg != NULL)
5207 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005208 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005209 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005210 if (i + (arg - startarg) < IOSIZE)
5211 {
5212 /* append the argument with the error */
5213 STRCAT(IObuff, ": ");
5214 mch_memmove(IObuff + i, startarg, (arg - startarg));
5215 IObuff[i + (arg - startarg)] = NUL;
5216 }
5217 /* make sure all characters are printable */
5218 trans_characters(IObuff, IOSIZE);
5219
5220 ++no_wait_return; /* wait_return done later */
5221 emsg(IObuff); /* show error highlighted */
5222 --no_wait_return;
5223
5224 return FAIL;
5225 }
5226
5227 arg = skipwhite(arg);
5228 }
5229
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005230theend:
5231 if (silent_mode && did_show)
5232 {
5233 /* After displaying option values in silent mode. */
5234 silent_mode = FALSE;
5235 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5236 msg_putchar('\n');
5237 cursor_on(); /* msg_start() switches it off */
5238 out_flush();
5239 silent_mode = TRUE;
5240 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5241 }
5242
Bram Moolenaar071d4272004-06-13 20:20:40 +00005243 return OK;
5244}
5245
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005246/*
5247 * Call this when an option has been given a new value through a user command.
5248 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5249 */
5250 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005251did_set_option(
5252 int opt_idx,
5253 int opt_flags, /* possibly with OPT_MODELINE */
5254 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005255{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005256 long_u *p;
5257
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005258 options[opt_idx].flags |= P_WAS_SET;
5259
5260 /* When an option is set in the sandbox, from a modeline or in secure mode
5261 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005262 * flag. */
5263 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005264 if (secure
5265#ifdef HAVE_SANDBOX
5266 || sandbox != 0
5267#endif
5268 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005269 *p = *p | P_INSECURE;
5270 else if (new_value)
5271 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005272}
5273
Bram Moolenaar071d4272004-06-13 20:20:40 +00005274 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005275illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005276{
5277 if (errbuf == NULL)
5278 return (char_u *)"";
5279 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005280 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005281 return errbuf;
5282}
5283
5284/*
5285 * Convert a key name or string into a key value.
5286 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005287 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005288 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005289 int
5290string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005291{
5292 if (*arg == '<')
5293 return find_key_option(arg + 1);
5294 if (*arg == '^')
5295 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005296 if (multi_byte)
5297 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005298 return *arg;
5299}
5300
5301#ifdef FEAT_CMDWIN
5302/*
5303 * Check value of 'cedit' and set cedit_key.
5304 * Returns NULL if value is OK, error message otherwise.
5305 */
5306 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005307check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308{
5309 int n;
5310
5311 if (*p_cedit == NUL)
5312 cedit_key = -1;
5313 else
5314 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005315 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 if (vim_isprintc(n))
5317 return e_invarg;
5318 cedit_key = n;
5319 }
5320 return NULL;
5321}
5322#endif
5323
5324#ifdef FEAT_TITLE
5325/*
5326 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5327 * maketitle() to create and display it.
5328 * When switching the title or icon off, call mch_restore_title() to get
5329 * the old value back.
5330 */
5331 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005332did_set_title(
5333 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334{
5335 if (starting != NO_SCREEN
5336#ifdef FEAT_GUI
5337 && !gui.starting
5338#endif
5339 )
5340 {
5341 maketitle();
5342 if (icon)
5343 {
5344 if (!p_icon)
5345 mch_restore_title(2);
5346 }
5347 else
5348 {
5349 if (!p_title)
5350 mch_restore_title(1);
5351 }
5352 }
5353}
5354#endif
5355
5356/*
5357 * set_options_bin - called when 'bin' changes value.
5358 */
5359 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005360set_options_bin(
5361 int oldval,
5362 int newval,
5363 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005364{
5365 /*
5366 * The option values that are changed when 'bin' changes are
5367 * copied when 'bin is set and restored when 'bin' is reset.
5368 */
5369 if (newval)
5370 {
5371 if (!oldval) /* switched on */
5372 {
5373 if (!(opt_flags & OPT_GLOBAL))
5374 {
5375 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5376 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5377 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5378 curbuf->b_p_et_nobin = curbuf->b_p_et;
5379 }
5380 if (!(opt_flags & OPT_LOCAL))
5381 {
5382 p_tw_nobin = p_tw;
5383 p_wm_nobin = p_wm;
5384 p_ml_nobin = p_ml;
5385 p_et_nobin = p_et;
5386 }
5387 }
5388
5389 if (!(opt_flags & OPT_GLOBAL))
5390 {
5391 curbuf->b_p_tw = 0; /* no automatic line wrap */
5392 curbuf->b_p_wm = 0; /* no automatic line wrap */
5393 curbuf->b_p_ml = 0; /* no modelines */
5394 curbuf->b_p_et = 0; /* no expandtab */
5395 }
5396 if (!(opt_flags & OPT_LOCAL))
5397 {
5398 p_tw = 0;
5399 p_wm = 0;
5400 p_ml = FALSE;
5401 p_et = FALSE;
5402 p_bin = TRUE; /* needed when called for the "-b" argument */
5403 }
5404 }
5405 else if (oldval) /* switched off */
5406 {
5407 if (!(opt_flags & OPT_GLOBAL))
5408 {
5409 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5410 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5411 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5412 curbuf->b_p_et = curbuf->b_p_et_nobin;
5413 }
5414 if (!(opt_flags & OPT_LOCAL))
5415 {
5416 p_tw = p_tw_nobin;
5417 p_wm = p_wm_nobin;
5418 p_ml = p_ml_nobin;
5419 p_et = p_et_nobin;
5420 }
5421 }
5422}
5423
5424#ifdef FEAT_VIMINFO
5425/*
5426 * Find the parameter represented by the given character (eg ', :, ", or /),
5427 * and return its associated value in the 'viminfo' string.
5428 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005429 * If the parameter is not specified in the string or there is no following
5430 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005431 */
5432 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005433get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005434{
5435 char_u *p;
5436
5437 p = find_viminfo_parameter(type);
5438 if (p != NULL && VIM_ISDIGIT(*p))
5439 return atoi((char *)p);
5440 return -1;
5441}
5442
5443/*
5444 * Find the parameter represented by the given character (eg ''', ':', '"', or
5445 * '/') in the 'viminfo' option and return a pointer to the string after it.
5446 * Return NULL if the parameter is not specified in the string.
5447 */
5448 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005449find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005450{
5451 char_u *p;
5452
5453 for (p = p_viminfo; *p; ++p)
5454 {
5455 if (*p == type)
5456 return p + 1;
5457 if (*p == 'n') /* 'n' is always the last one */
5458 break;
5459 p = vim_strchr(p, ','); /* skip until next ',' */
5460 if (p == NULL) /* hit the end without finding parameter */
5461 break;
5462 }
5463 return NULL;
5464}
5465#endif
5466
5467/*
5468 * Expand environment variables for some string options.
5469 * These string options cannot be indirect!
5470 * If "val" is NULL expand the current value of the option.
5471 * Return pointer to NameBuff, or NULL when not expanded.
5472 */
5473 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005474option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005475{
5476 /* if option doesn't need expansion nothing to do */
5477 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5478 return NULL;
5479
5480 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5481 * expand_env() would truncate the string. */
5482 if (val != NULL && STRLEN(val) > MAXPATHL)
5483 return NULL;
5484
5485 if (val == NULL)
5486 val = *(char_u **)options[opt_idx].var;
5487
5488 /*
5489 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5490 * Escape spaces when expanding 'tags', they are used to separate file
5491 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005492 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005493 */
5494 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005495 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005496#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005497 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5498#endif
5499 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005500 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5501 return NULL;
5502
5503 return NameBuff;
5504}
5505
5506/*
5507 * After setting various option values: recompute variables that depend on
5508 * option values.
5509 */
5510 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005511didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005512{
5513 /* initialize the table for 'iskeyword' et.al. */
5514 (void)init_chartab();
5515
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005516#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005518#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005519 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005520 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521#ifdef FEAT_SESSION
5522 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5523 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5524#endif
5525#ifdef FEAT_FOLDING
5526 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5527#endif
5528 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005529 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005530#ifdef FEAT_VIRTUALEDIT
5531 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5532#endif
5533#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5534 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5535#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005536#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005537 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005538 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005539 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005540 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005541#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005542#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5543 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5544#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005545#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5547#endif
5548#ifdef FEAT_CMDWIN
5549 /* set cedit_key */
5550 (void)check_cedit();
5551#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005552#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005553 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005554#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005555#ifdef FEAT_LINEBREAK
5556 /* initialize the table for 'breakat'. */
5557 fill_breakat_flags();
5558#endif
5559
5560}
5561
5562/*
5563 * More side effects of setting options.
5564 */
5565 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005566didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005567{
5568 /* Initialize the highlight_attr[] table. */
5569 (void)highlight_changed();
5570
5571 /* Parse default for 'wildmode' */
5572 check_opt_wim();
5573
5574 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005575 /* Parse default for 'fillchars'. */
5576 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005577
5578#ifdef FEAT_CLIPBOARD
5579 /* Parse default for 'clipboard' */
5580 (void)check_clipboard_option();
5581#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582}
5583
5584/*
5585 * Check for string options that are NULL (normally only termcap options).
5586 */
5587 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005588check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589{
5590 int opt_idx;
5591
5592 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5593 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5594 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5595}
5596
5597/*
5598 * Check string options in a buffer for NULL value.
5599 */
5600 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005601check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005602{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005603 check_string_option(&buf->b_p_bh);
5604 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605#ifdef FEAT_MBYTE
5606 check_string_option(&buf->b_p_fenc);
5607#endif
5608 check_string_option(&buf->b_p_ff);
5609#ifdef FEAT_FIND_ID
5610 check_string_option(&buf->b_p_def);
5611 check_string_option(&buf->b_p_inc);
5612# ifdef FEAT_EVAL
5613 check_string_option(&buf->b_p_inex);
5614# endif
5615#endif
5616#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5617 check_string_option(&buf->b_p_inde);
5618 check_string_option(&buf->b_p_indk);
5619#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005620#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5621 check_string_option(&buf->b_p_bexpr);
5622#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005623#if defined(FEAT_CRYPT)
5624 check_string_option(&buf->b_p_cm);
5625#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005626 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005627#if defined(FEAT_EVAL)
5628 check_string_option(&buf->b_p_fex);
5629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630#ifdef FEAT_CRYPT
5631 check_string_option(&buf->b_p_key);
5632#endif
5633 check_string_option(&buf->b_p_kp);
5634 check_string_option(&buf->b_p_mps);
5635 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005636 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005637 check_string_option(&buf->b_p_isk);
5638#ifdef FEAT_COMMENTS
5639 check_string_option(&buf->b_p_com);
5640#endif
5641#ifdef FEAT_FOLDING
5642 check_string_option(&buf->b_p_cms);
5643#endif
5644 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005645#ifdef FEAT_TEXTOBJ
5646 check_string_option(&buf->b_p_qe);
5647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005648#ifdef FEAT_SYN_HL
5649 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005650 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005651#endif
5652#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005653 check_string_option(&buf->b_s.b_p_spc);
5654 check_string_option(&buf->b_s.b_p_spf);
5655 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656#endif
5657#ifdef FEAT_SEARCHPATH
5658 check_string_option(&buf->b_p_sua);
5659#endif
5660#ifdef FEAT_CINDENT
5661 check_string_option(&buf->b_p_cink);
5662 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005663 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664#endif
5665#ifdef FEAT_AUTOCMD
5666 check_string_option(&buf->b_p_ft);
5667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5669 check_string_option(&buf->b_p_cinw);
5670#endif
5671#ifdef FEAT_INS_EXPAND
5672 check_string_option(&buf->b_p_cpt);
5673#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005674#ifdef FEAT_COMPL_FUNC
5675 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005676 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005678#ifdef FEAT_KEYMAP
5679 check_string_option(&buf->b_p_keymap);
5680#endif
5681#ifdef FEAT_QUICKFIX
5682 check_string_option(&buf->b_p_gp);
5683 check_string_option(&buf->b_p_mp);
5684 check_string_option(&buf->b_p_efm);
5685#endif
5686 check_string_option(&buf->b_p_ep);
5687 check_string_option(&buf->b_p_path);
5688 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005689 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690#ifdef FEAT_INS_EXPAND
5691 check_string_option(&buf->b_p_dict);
5692 check_string_option(&buf->b_p_tsr);
5693#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005694#ifdef FEAT_LISP
5695 check_string_option(&buf->b_p_lw);
5696#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005697 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005698#ifdef FEAT_MBYTE
5699 check_string_option(&buf->b_p_menc);
5700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701}
5702
5703/*
5704 * Free the string allocated for an option.
5705 * Checks for the string being empty_option. This may happen if we're out of
5706 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5707 * check_options().
5708 * Does NOT check for P_ALLOCED flag!
5709 */
5710 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005711free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712{
5713 if (p != empty_option)
5714 vim_free(p);
5715}
5716
5717 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005718clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719{
5720 if (*pp != empty_option)
5721 vim_free(*pp);
5722 *pp = empty_option;
5723}
5724
5725 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005726check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727{
5728 if (*pp == NULL)
5729 *pp = empty_option;
5730}
5731
5732/*
5733 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5734 */
5735 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005736set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737{
5738 int opt_idx;
5739
5740 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5741 if (options[opt_idx].var == (char_u *)p)
5742 {
5743 options[opt_idx].flags |= P_ALLOCED;
5744 return;
5745 }
5746 return; /* cannot happen: didn't find it! */
5747}
5748
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005749#if defined(FEAT_EVAL) || defined(PROTO)
5750/*
5751 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5752 * Return FALSE when it wasn't.
5753 * Return -1 for an unknown option.
5754 */
5755 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005756was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005757{
5758 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005759 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005760
5761 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005762 {
5763 flagp = insecure_flag(idx, opt_flags);
5764 return (*flagp & P_INSECURE) != 0;
5765 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005766 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005767 return -1;
5768}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005769
5770/*
5771 * Get a pointer to the flags used for the P_INSECURE flag of option
5772 * "opt_idx". For some local options a local flags field is used.
5773 */
5774 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005775insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005776{
5777 if (opt_flags & OPT_LOCAL)
5778 switch ((int)options[opt_idx].indir)
5779 {
5780#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005781 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005782#endif
5783#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005784# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005785 case PV_FDE: return &curwin->w_p_fde_flags;
5786 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005787# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005788# ifdef FEAT_BEVAL
5789 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5790# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005791# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005792 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005793# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005794 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005795# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005796 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005797# endif
5798#endif
5799 }
5800
5801 /* Nothing special, return global flags field. */
5802 return &options[opt_idx].flags;
5803}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005804#endif
5805
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005806#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005807static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005808
5809/*
5810 * Redraw the window title and/or tab page text later.
5811 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005812static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005813{
5814 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005815 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005816}
5817#endif
5818
Bram Moolenaar071d4272004-06-13 20:20:40 +00005819/*
5820 * Set a string option to a new value (without checking the effect).
5821 * The string is copied into allocated memory.
5822 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005823 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005824 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005825 */
5826 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005827set_string_option_direct(
5828 char_u *name,
5829 int opt_idx,
5830 char_u *val,
5831 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5832 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005833{
5834 char_u *s;
5835 char_u **varp;
5836 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005837 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005838
Bram Moolenaar89d40322006-08-29 15:30:07 +00005839 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005840 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005841 idx = findoption(name);
5842 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005843 {
5844 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005845 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005847 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848 }
5849
Bram Moolenaar89d40322006-08-29 15:30:07 +00005850 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005851 return;
5852
5853 s = vim_strsave(val);
5854 if (s != NULL)
5855 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005856 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005857 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005858 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859 free_string_option(*varp);
5860 *varp = s;
5861
5862 /* For buffer/window local option may also set the global value. */
5863 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005864 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865
Bram Moolenaar89d40322006-08-29 15:30:07 +00005866 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867
5868 /* When setting both values of a global option with a local value,
5869 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005870 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871 {
5872 free_string_option(*varp);
5873 *varp = empty_option;
5874 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005875# ifdef FEAT_EVAL
5876 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005877 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005878 set_sid == 0 ? current_SID : set_sid);
5879# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880 }
5881}
5882
5883/*
5884 * Set global value for string option when it's a local option.
5885 */
5886 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005887set_string_option_global(
5888 int opt_idx, /* option index */
5889 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890{
5891 char_u **p, *s;
5892
5893 /* the global value is always allocated */
5894 if (options[opt_idx].var == VAR_WIN)
5895 p = (char_u **)GLOBAL_WO(varp);
5896 else
5897 p = (char_u **)options[opt_idx].var;
5898 if (options[opt_idx].indir != PV_NONE
5899 && p != varp
5900 && (s = vim_strsave(*varp)) != NULL)
5901 {
5902 free_string_option(*p);
5903 *p = s;
5904 }
5905}
5906
5907/*
5908 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005909 *
5910 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005912 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005913set_string_option(
5914 int opt_idx,
5915 char_u *value,
5916 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917{
5918 char_u *s;
5919 char_u **varp;
5920 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005921#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5922 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005923 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005924#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005925 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926
5927 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005928 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005929
5930 s = vim_strsave(value);
5931 if (s != NULL)
5932 {
5933 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5934 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005935 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005936 ? OPT_GLOBAL : OPT_LOCAL)
5937 : opt_flags);
5938 oldval = *varp;
5939 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005940
5941#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005942 if (!starting
5943# ifdef FEAT_CRYPT
5944 && options[opt_idx].indir != PV_KEY
5945# endif
5946 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005947 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005948 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005949 saved_newval = vim_strsave(s);
5950 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005951#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005952 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5953 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005954 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005955
Bram Moolenaar53744302015-07-17 17:38:22 +02005956#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005957 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005958 if (r == NULL)
5959 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005960 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005961 vim_free(saved_oldval);
5962 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005963#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005965 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966}
5967
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005968#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005970 * Return TRUE if "val" is a valid 'filetype' name.
5971 * Also used for 'syntax' and 'keymap'.
5972 */
5973 static int
5974valid_filetype(char_u *val)
5975{
5976 char_u *s;
5977
5978 for (s = val; *s != NUL; ++s)
5979 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5980 return FALSE;
5981 return TRUE;
5982}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005983#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005984
5985/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005986 * Handle string options that need some action to perform when changed.
5987 * Returns NULL for success, or an error message for an error.
5988 */
5989 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005990did_set_string_option(
5991 int opt_idx, /* index in options[] table */
5992 char_u **varp, /* pointer to the option variable */
5993 int new_value_alloced, /* new value was allocated */
5994 char_u *oldval, /* previous value of the option */
5995 char_u *errbuf, /* buffer for errors, or NULL */
5996 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005997{
5998 char_u *errmsg = NULL;
5999 char_u *s, *p;
6000 int did_chartab = FALSE;
6001 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006002 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006003#ifdef FEAT_GUI
6004 /* set when changing an option that only requires a redraw in the GUI */
6005 int redraw_gui_only = FALSE;
6006#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006007#ifdef FEAT_AUTOCMD
6008 int ft_changed = FALSE;
6009#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006010
6011 /* Get the global option to compare with, otherwise we would have to check
6012 * two values for all local options. */
6013 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6014
6015 /* Disallow changing some options from secure mode */
6016 if ((secure
6017#ifdef HAVE_SANDBOX
6018 || sandbox != 0
6019#endif
6020 ) && (options[opt_idx].flags & P_SECURE))
6021 {
6022 errmsg = e_secure;
6023 }
6024
Bram Moolenaar7554da42016-11-25 22:04:13 +01006025 /* Check for a "normal" directory or file name in some options. Disallow a
6026 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006027 * are often illegal in a file name. Be more permissive if "secure" is off.
6028 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006029 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006030 && vim_strpbrk(*varp, (char_u *)(secure
6031 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006032 || ((options[opt_idx].flags & P_NDNAME)
6033 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006034 {
6035 errmsg = e_invarg;
6036 }
6037
Bram Moolenaar071d4272004-06-13 20:20:40 +00006038 /* 'term' */
6039 else if (varp == &T_NAME)
6040 {
6041 if (T_NAME[0] == NUL)
6042 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6043#ifdef FEAT_GUI
6044 if (gui.in_use)
6045 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6046 else if (term_is_gui(T_NAME))
6047 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6048#endif
6049 else if (set_termname(T_NAME) == FAIL)
6050 errmsg = (char_u *)N_("E522: Not found in termcap");
6051 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006052 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006053 /* Screen colors may have changed. */
6054 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006055
6056 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6057 * P_ALLOCED flag on 'term'. */
6058 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006059 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006061 }
6062
6063 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006064 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006065 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006066 char_u *bkc = p_bkc;
6067 unsigned int *flags = &bkc_flags;
6068
6069 if (opt_flags & OPT_LOCAL)
6070 {
6071 bkc = curbuf->b_p_bkc;
6072 flags = &curbuf->b_bkc_flags;
6073 }
6074
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006075 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6076 /* make the local value empty: use the global value */
6077 *flags = 0;
6078 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006080 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6081 errmsg = e_invarg;
6082 if ((((int)*flags & BKC_AUTO) != 0)
6083 + (((int)*flags & BKC_YES) != 0)
6084 + (((int)*flags & BKC_NO) != 0) != 1)
6085 {
6086 /* Must have exactly one of "auto", "yes" and "no". */
6087 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6088 errmsg = e_invarg;
6089 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090 }
6091 }
6092
6093 /* 'backupext' and 'patchmode' */
6094 else if (varp == &p_bex || varp == &p_pm)
6095 {
6096 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6097 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6098 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6099 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006100#ifdef FEAT_LINEBREAK
6101 /* 'breakindentopt' */
6102 else if (varp == &curwin->w_p_briopt)
6103 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006104 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006105 errmsg = e_invarg;
6106 }
6107#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006108
6109 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006110 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006112 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113 */
6114 else if ( varp == &p_isi
6115 || varp == &(curbuf->b_p_isk)
6116 || varp == &p_isp
6117 || varp == &p_isf)
6118 {
6119 if (init_chartab() == FAIL)
6120 {
6121 did_chartab = TRUE; /* need to restore it below */
6122 errmsg = e_invarg; /* error in value */
6123 }
6124 }
6125
6126 /* 'helpfile' */
6127 else if (varp == &p_hf)
6128 {
6129 /* May compute new values for $VIM and $VIMRUNTIME */
6130 if (didset_vim)
6131 {
6132 vim_setenv((char_u *)"VIM", (char_u *)"");
6133 didset_vim = FALSE;
6134 }
6135 if (didset_vimruntime)
6136 {
6137 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6138 didset_vimruntime = FALSE;
6139 }
6140 }
6141
Bram Moolenaar1a384422010-07-14 19:53:30 +02006142#ifdef FEAT_SYN_HL
6143 /* 'colorcolumn' */
6144 else if (varp == &curwin->w_p_cc)
6145 errmsg = check_colorcolumn(curwin);
6146#endif
6147
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148#ifdef FEAT_MULTI_LANG
6149 /* 'helplang' */
6150 else if (varp == &p_hlg)
6151 {
6152 /* Check for "", "ab", "ab,cd", etc. */
6153 for (s = p_hlg; *s != NUL; s += 3)
6154 {
6155 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6156 {
6157 errmsg = e_invarg;
6158 break;
6159 }
6160 if (s[2] == NUL)
6161 break;
6162 }
6163 }
6164#endif
6165
6166 /* 'highlight' */
6167 else if (varp == &p_hl)
6168 {
6169 if (highlight_changed() == FAIL)
6170 errmsg = e_invarg; /* invalid flags */
6171 }
6172
6173 /* 'nrformats' */
6174 else if (gvarp == &p_nf)
6175 {
6176 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6177 errmsg = e_invarg;
6178 }
6179
6180#ifdef FEAT_SESSION
6181 /* 'sessionoptions' */
6182 else if (varp == &p_ssop)
6183 {
6184 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6185 errmsg = e_invarg;
6186 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6187 {
6188 /* Don't allow both "sesdir" and "curdir". */
6189 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6190 errmsg = e_invarg;
6191 }
6192 }
6193 /* 'viewoptions' */
6194 else if (varp == &p_vop)
6195 {
6196 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6197 errmsg = e_invarg;
6198 }
6199#endif
6200
6201 /* 'scrollopt' */
6202#ifdef FEAT_SCROLLBIND
6203 else if (varp == &p_sbo)
6204 {
6205 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6206 errmsg = e_invarg;
6207 }
6208#endif
6209
6210 /* 'ambiwidth' */
6211#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006212 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006213 {
6214 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6215 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006216 else if (set_chars_option(&p_lcs) != NULL)
6217 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006218 else if (set_chars_option(&p_fcs) != NULL)
6219 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006220 }
6221#endif
6222
6223 /* 'background' */
6224 else if (varp == &p_bg)
6225 {
6226 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6227 {
6228#ifdef FEAT_EVAL
6229 int dark = (*p_bg == 'd');
6230#endif
6231
6232 init_highlight(FALSE, FALSE);
6233
6234#ifdef FEAT_EVAL
6235 if (dark != (*p_bg == 'd')
6236 && get_var_value((char_u *)"g:colors_name") != NULL)
6237 {
6238 /* The color scheme must have set 'background' back to another
6239 * value, that's not what we want here. Disable the color
6240 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006241 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006242 free_string_option(p_bg);
6243 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6244 check_string_option(&p_bg);
6245 init_highlight(FALSE, FALSE);
6246 }
6247#endif
6248 }
6249 else
6250 errmsg = e_invarg;
6251 }
6252
6253 /* 'wildmode' */
6254 else if (varp == &p_wim)
6255 {
6256 if (check_opt_wim() == FAIL)
6257 errmsg = e_invarg;
6258 }
6259
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006260#ifdef FEAT_CMDL_COMPL
6261 /* 'wildoptions' */
6262 else if (varp == &p_wop)
6263 {
6264 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6265 errmsg = e_invarg;
6266 }
6267#endif
6268
Bram Moolenaar071d4272004-06-13 20:20:40 +00006269#ifdef FEAT_WAK
6270 /* 'winaltkeys' */
6271 else if (varp == &p_wak)
6272 {
6273 if (*p_wak == NUL
6274 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6275 errmsg = e_invarg;
6276# ifdef FEAT_MENU
6277# ifdef FEAT_GUI_MOTIF
6278 else if (gui.in_use)
6279 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6280# else
6281# ifdef FEAT_GUI_GTK
6282 else if (gui.in_use)
6283 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6284# endif
6285# endif
6286# endif
6287 }
6288#endif
6289
6290#ifdef FEAT_AUTOCMD
6291 /* 'eventignore' */
6292 else if (varp == &p_ei)
6293 {
6294 if (check_ei() == FAIL)
6295 errmsg = e_invarg;
6296 }
6297#endif
6298
6299#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006300 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6301 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6302 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 {
6304 if (gvarp == &p_fenc)
6305 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006306 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006307 errmsg = e_modifiable;
6308 else if (vim_strchr(*varp, ',') != NULL)
6309 /* No comma allowed in 'fileencoding'; catches confusing it
6310 * with 'fileencodings'. */
6311 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006312 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006313 {
6314# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006316 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006317# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006318 /* Add 'fileencoding' to the swap file. */
6319 ml_setflags(curbuf);
6320 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321 }
6322 if (errmsg == NULL)
6323 {
6324 /* canonize the value, so that STRCMP() can be used on it */
6325 p = enc_canonize(*varp);
6326 if (p != NULL)
6327 {
6328 vim_free(*varp);
6329 *varp = p;
6330 }
6331 if (varp == &p_enc)
6332 {
6333 errmsg = mb_init();
6334# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006335 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006336# endif
6337 }
6338 }
6339
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006340# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006341 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6342 {
6343 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6344 if (STRCMP(p_tenc, "utf-8") != 0)
6345 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6346 }
6347# endif
6348
6349 if (errmsg == NULL)
6350 {
6351# ifdef FEAT_KEYMAP
6352 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6353 * (with another encoding). */
6354 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6355 (void)keymap_init();
6356# endif
6357
6358 /* When 'termencoding' is not empty and 'encoding' changes or when
6359 * 'termencoding' changes, need to setup for keyboard input and
6360 * display output conversion. */
6361 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6362 {
6363 convert_setup(&input_conv, p_tenc, p_enc);
6364 convert_setup(&output_conv, p_enc, p_tenc);
6365 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006366
6367# if defined(WIN3264) && defined(FEAT_MBYTE)
6368 /* $HOME may have characters in active code page. */
6369 if (varp == &p_enc)
6370 init_homedir();
6371# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372 }
6373 }
6374#endif
6375
6376#if defined(FEAT_POSTSCRIPT)
6377 else if (varp == &p_penc)
6378 {
6379 /* Canonize printencoding if VIM standard one */
6380 p = enc_canonize(p_penc);
6381 if (p != NULL)
6382 {
6383 vim_free(p_penc);
6384 p_penc = p;
6385 }
6386 else
6387 {
6388 /* Ensure lower case and '-' for '_' */
6389 for (s = p_penc; *s != NUL; s++)
6390 {
6391 if (*s == '_')
6392 *s = '-';
6393 else
6394 *s = TOLOWER_ASC(*s);
6395 }
6396 }
6397 }
6398#endif
6399
Bram Moolenaar9372a112005-12-06 19:59:18 +00006400#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401 else if (varp == &p_imak)
6402 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006403 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006404 errmsg = e_invarg;
6405 }
6406#endif
6407
6408#ifdef FEAT_KEYMAP
6409 else if (varp == &curbuf->b_p_keymap)
6410 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006411 if (!valid_filetype(*varp))
6412 errmsg = e_invarg;
6413 else
6414 /* load or unload key mapping tables */
6415 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006416
Bram Moolenaarfab06232009-03-04 03:13:35 +00006417 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006419 if (*curbuf->b_p_keymap != NUL)
6420 {
6421 /* Installed a new keymap, switch on using it. */
6422 curbuf->b_p_iminsert = B_IMODE_LMAP;
6423 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6424 curbuf->b_p_imsearch = B_IMODE_LMAP;
6425 }
6426 else
6427 {
6428 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6429 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6430 curbuf->b_p_iminsert = B_IMODE_NONE;
6431 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6432 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6433 }
6434 if ((opt_flags & OPT_LOCAL) == 0)
6435 {
6436 set_iminsert_global();
6437 set_imsearch_global();
6438 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440 }
6441 }
6442#endif
6443
6444 /* 'fileformat' */
6445 else if (gvarp == &p_ff)
6446 {
6447 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6448 errmsg = e_modifiable;
6449 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6450 errmsg = e_invarg;
6451 else
6452 {
6453 /* may also change 'textmode' */
6454 if (get_fileformat(curbuf) == EOL_DOS)
6455 curbuf->b_p_tx = TRUE;
6456 else
6457 curbuf->b_p_tx = FALSE;
6458#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006459 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006460#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006461 /* update flag in swap file */
6462 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006463 /* Redraw needed when switching to/from "mac": a CR in the text
6464 * will be displayed differently. */
6465 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6466 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 }
6468 }
6469
6470 /* 'fileformats' */
6471 else if (varp == &p_ffs)
6472 {
6473 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6474 errmsg = e_invarg;
6475 else
6476 {
6477 /* also change 'textauto' */
6478 if (*p_ffs == NUL)
6479 p_ta = FALSE;
6480 else
6481 p_ta = TRUE;
6482 }
6483 }
6484
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006485#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006486 /* 'cryptkey' */
6487 else if (gvarp == &p_key)
6488 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006489# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490 /* Make sure the ":set" command doesn't show the new value in the
6491 * history. */
6492 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006493# endif
6494 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6495 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006496 ml_set_crypt_key(curbuf, oldval,
6497 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006498 }
6499
6500 else if (gvarp == &p_cm)
6501 {
6502 if (opt_flags & OPT_LOCAL)
6503 p = curbuf->b_p_cm;
6504 else
6505 p = p_cm;
6506 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6507 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006508 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006509 errmsg = e_invarg;
6510 else
6511 {
6512 /* When setting the global value to empty, make it "zip". */
6513 if (*p_cm == NUL)
6514 {
6515 if (new_value_alloced)
6516 free_string_option(p_cm);
6517 p_cm = vim_strsave((char_u *)"zip");
6518 new_value_alloced = TRUE;
6519 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006520 /* When using ":set cm=name" the local value is going to be empty.
6521 * Do that here, otherwise the crypt functions will still use the
6522 * local value. */
6523 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6524 {
6525 free_string_option(curbuf->b_p_cm);
6526 curbuf->b_p_cm = empty_option;
6527 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006528
6529 /* Need to update the swapfile when the effective method changed.
6530 * Set "s" to the effective old value, "p" to the effective new
6531 * method and compare. */
6532 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6533 s = p_cm; /* was previously using the global value */
6534 else
6535 s = oldval;
6536 if (*curbuf->b_p_cm == NUL)
6537 p = p_cm; /* is now using the global value */
6538 else
6539 p = curbuf->b_p_cm;
6540 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006541 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006542
6543 /* If the global value changes need to update the swapfile for all
6544 * buffers using that value. */
6545 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6546 {
6547 buf_T *buf;
6548
Bram Moolenaar29323592016-07-24 22:04:11 +02006549 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006550 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006551 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006552 }
6553 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554 }
6555#endif
6556
6557 /* 'matchpairs' */
6558 else if (gvarp == &p_mps)
6559 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006560#ifdef FEAT_MBYTE
6561 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006562 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006563 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006564 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006565 int x2 = -1;
6566 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006567
6568 if (*p != NUL)
6569 p += mb_ptr2len(p);
6570 if (*p != NUL)
6571 x2 = *p++;
6572 if (*p != NUL)
6573 {
6574 x3 = mb_ptr2char(p);
6575 p += mb_ptr2len(p);
6576 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006577 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006578 {
6579 errmsg = e_invarg;
6580 break;
6581 }
6582 if (*p == NUL)
6583 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006584 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006585 }
6586 else
6587#endif
6588 {
6589 /* Check for "x:y,x:y" */
6590 for (p = *varp; *p != NUL; p += 4)
6591 {
6592 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6593 {
6594 errmsg = e_invarg;
6595 break;
6596 }
6597 if (p[3] == NUL)
6598 break;
6599 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006600 }
6601 }
6602
6603#ifdef FEAT_COMMENTS
6604 /* 'comments' */
6605 else if (gvarp == &p_com)
6606 {
6607 for (s = *varp; *s; )
6608 {
6609 while (*s && *s != ':')
6610 {
6611 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6612 && !VIM_ISDIGIT(*s) && *s != '-')
6613 {
6614 errmsg = illegal_char(errbuf, *s);
6615 break;
6616 }
6617 ++s;
6618 }
6619 if (*s++ == NUL)
6620 errmsg = (char_u *)N_("E524: Missing colon");
6621 else if (*s == ',' || *s == NUL)
6622 errmsg = (char_u *)N_("E525: Zero length string");
6623 if (errmsg != NULL)
6624 break;
6625 while (*s && *s != ',')
6626 {
6627 if (*s == '\\' && s[1] != NUL)
6628 ++s;
6629 ++s;
6630 }
6631 s = skip_to_option_part(s);
6632 }
6633 }
6634#endif
6635
6636 /* 'listchars' */
6637 else if (varp == &p_lcs)
6638 {
6639 errmsg = set_chars_option(varp);
6640 }
6641
Bram Moolenaar071d4272004-06-13 20:20:40 +00006642 /* 'fillchars' */
6643 else if (varp == &p_fcs)
6644 {
6645 errmsg = set_chars_option(varp);
6646 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006647
6648#ifdef FEAT_CMDWIN
6649 /* 'cedit' */
6650 else if (varp == &p_cedit)
6651 {
6652 errmsg = check_cedit();
6653 }
6654#endif
6655
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006656 /* 'verbosefile' */
6657 else if (varp == &p_vfile)
6658 {
6659 verbose_stop();
6660 if (*p_vfile != NUL && verbose_open() == FAIL)
6661 errmsg = e_invarg;
6662 }
6663
Bram Moolenaar071d4272004-06-13 20:20:40 +00006664#ifdef FEAT_VIMINFO
6665 /* 'viminfo' */
6666 else if (varp == &p_viminfo)
6667 {
6668 for (s = p_viminfo; *s;)
6669 {
6670 /* Check it's a valid character */
6671 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6672 {
6673 errmsg = illegal_char(errbuf, *s);
6674 break;
6675 }
6676 if (*s == 'n') /* name is always last one */
6677 {
6678 break;
6679 }
6680 else if (*s == 'r') /* skip until next ',' */
6681 {
6682 while (*++s && *s != ',')
6683 ;
6684 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006685 else if (*s == '%')
6686 {
6687 /* optional number */
6688 while (vim_isdigit(*++s))
6689 ;
6690 }
6691 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006692 ++s; /* no extra chars */
6693 else /* must have a number */
6694 {
6695 while (vim_isdigit(*++s))
6696 ;
6697
6698 if (!VIM_ISDIGIT(*(s - 1)))
6699 {
6700 if (errbuf != NULL)
6701 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006702 sprintf((char *)errbuf,
6703 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006704 transchar_byte(*(s - 1)));
6705 errmsg = errbuf;
6706 }
6707 else
6708 errmsg = (char_u *)"";
6709 break;
6710 }
6711 }
6712 if (*s == ',')
6713 ++s;
6714 else if (*s)
6715 {
6716 if (errbuf != NULL)
6717 errmsg = (char_u *)N_("E527: Missing comma");
6718 else
6719 errmsg = (char_u *)"";
6720 break;
6721 }
6722 }
6723 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6724 errmsg = (char_u *)N_("E528: Must specify a ' value");
6725 }
6726#endif /* FEAT_VIMINFO */
6727
6728 /* terminal options */
6729 else if (istermoption(&options[opt_idx]) && full_screen)
6730 {
6731 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6732 if (varp == &T_CCO)
6733 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006734 int colors = atoi((char *)T_CCO);
6735
6736 /* Only reinitialize colors if t_Co value has really changed to
6737 * avoid expensive reload of colorscheme if t_Co is set to the
6738 * same value multiple times. */
6739 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006741 t_colors = colors;
6742 if (t_colors <= 1)
6743 {
6744 if (new_value_alloced)
6745 vim_free(T_CCO);
6746 T_CCO = empty_option;
6747 }
6748 /* We now have a different color setup, initialize it again. */
6749 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006750 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751 }
6752 ttest(FALSE);
6753 if (varp == &T_ME)
6754 {
6755 out_str(T_ME);
6756 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006757#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758 /* Since t_me has been set, this probably means that the user
6759 * wants to use this as default colors. Need to reset default
6760 * background/foreground colors. */
6761 mch_set_normal_colors();
6762#endif
6763 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006764 if (varp == &T_BE && termcap_active)
6765 {
6766 if (*T_BE == NUL)
6767 /* When clearing t_BE we assume the user no longer wants
6768 * bracketed paste, thus disable it by writing t_BD. */
6769 out_str(T_BD);
6770 else
6771 out_str(T_BE);
6772 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773 }
6774
6775#ifdef FEAT_LINEBREAK
6776 /* 'showbreak' */
6777 else if (varp == &p_sbr)
6778 {
6779 for (s = p_sbr; *s; )
6780 {
6781 if (ptr2cells(s) != 1)
6782 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006783 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006784 }
6785 }
6786#endif
6787
6788#ifdef FEAT_GUI
6789 /* 'guifont' */
6790 else if (varp == &p_guifont)
6791 {
6792 if (gui.in_use)
6793 {
6794 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006795# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796 /*
6797 * Put up a font dialog and let the user select a new value.
6798 * If this is cancelled go back to the old value but don't
6799 * give an error message.
6800 */
6801 if (STRCMP(p, "*") == 0)
6802 {
6803 p = gui_mch_font_dialog(oldval);
6804
6805 if (new_value_alloced)
6806 free_string_option(p_guifont);
6807
6808 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6809 new_value_alloced = TRUE;
6810 }
6811# endif
6812 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6813 {
6814# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6815 if (STRCMP(p_guifont, "*") == 0)
6816 {
6817 /* Dialog was cancelled: Keep the old value without giving
6818 * an error message. */
6819 if (new_value_alloced)
6820 free_string_option(p_guifont);
6821 p_guifont = vim_strsave(oldval);
6822 new_value_alloced = TRUE;
6823 }
6824 else
6825# endif
6826 errmsg = (char_u *)N_("E596: Invalid font(s)");
6827 }
6828 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006829 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006830 }
6831# ifdef FEAT_XFONTSET
6832 else if (varp == &p_guifontset)
6833 {
6834 if (STRCMP(p_guifontset, "*") == 0)
6835 errmsg = (char_u *)N_("E597: can't select fontset");
6836 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6837 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006838 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006839 }
6840# endif
6841# ifdef FEAT_MBYTE
6842 else if (varp == &p_guifontwide)
6843 {
6844 if (STRCMP(p_guifontwide, "*") == 0)
6845 errmsg = (char_u *)N_("E533: can't select wide font");
6846 else if (gui_get_wide_font() == FAIL)
6847 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006848 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006849 }
6850# endif
6851#endif
6852
6853#ifdef CURSOR_SHAPE
6854 /* 'guicursor' */
6855 else if (varp == &p_guicursor)
6856 errmsg = parse_shape_opt(SHAPE_CURSOR);
6857#endif
6858
6859#ifdef FEAT_MOUSESHAPE
6860 /* 'mouseshape' */
6861 else if (varp == &p_mouseshape)
6862 {
6863 errmsg = parse_shape_opt(SHAPE_MOUSE);
6864 update_mouseshape(-1);
6865 }
6866#endif
6867
6868#ifdef FEAT_PRINTER
6869 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006870 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006871# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006872 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006873 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006874# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006875#endif
6876
6877#ifdef FEAT_LANGMAP
6878 /* 'langmap' */
6879 else if (varp == &p_langmap)
6880 langmap_set();
6881#endif
6882
6883#ifdef FEAT_LINEBREAK
6884 /* 'breakat' */
6885 else if (varp == &p_breakat)
6886 fill_breakat_flags();
6887#endif
6888
6889#ifdef FEAT_TITLE
6890 /* 'titlestring' and 'iconstring' */
6891 else if (varp == &p_titlestring || varp == &p_iconstring)
6892 {
6893# ifdef FEAT_STL_OPT
6894 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6895
6896 /* NULL => statusline syntax */
6897 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6898 stl_syntax |= flagval;
6899 else
6900 stl_syntax &= ~flagval;
6901# endif
6902 did_set_title(varp == &p_iconstring);
6903
6904 }
6905#endif
6906
6907#ifdef FEAT_GUI
6908 /* 'guioptions' */
6909 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006910 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006912 redraw_gui_only = TRUE;
6913 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006914#endif
6915
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006916#if defined(FEAT_GUI_TABLINE)
6917 /* 'guitablabel' */
6918 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006919 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006920 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006921 redraw_gui_only = TRUE;
6922 }
6923 /* 'guitabtooltip' */
6924 else if (varp == &p_gtt)
6925 {
6926 redraw_gui_only = TRUE;
6927 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006928#endif
6929
Bram Moolenaar071d4272004-06-13 20:20:40 +00006930#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6931 /* 'ttymouse' */
6932 else if (varp == &p_ttym)
6933 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006934 /* Switch the mouse off before changing the escape sequences used for
6935 * that. */
6936 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006937 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6938 errmsg = e_invarg;
6939 else
6940 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006941 if (termcap_active)
6942 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 }
6944#endif
6945
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 /* 'selection' */
6947 else if (varp == &p_sel)
6948 {
6949 if (*p_sel == NUL
6950 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6951 errmsg = e_invarg;
6952 }
6953
6954 /* 'selectmode' */
6955 else if (varp == &p_slm)
6956 {
6957 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6958 errmsg = e_invarg;
6959 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006960
6961#ifdef FEAT_BROWSE
6962 /* 'browsedir' */
6963 else if (varp == &p_bsdir)
6964 {
6965 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6966 && !mch_isdir(p_bsdir))
6967 errmsg = e_invarg;
6968 }
6969#endif
6970
Bram Moolenaar071d4272004-06-13 20:20:40 +00006971 /* 'keymodel' */
6972 else if (varp == &p_km)
6973 {
6974 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6975 errmsg = e_invarg;
6976 else
6977 {
6978 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6979 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6980 }
6981 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982
6983 /* 'mousemodel' */
6984 else if (varp == &p_mousem)
6985 {
6986 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6987 errmsg = e_invarg;
6988#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6989 else if (*p_mousem != *oldval)
6990 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6991 * to create or delete the popup menus. */
6992 gui_motif_update_mousemodel(root_menu);
6993#endif
6994 }
6995
6996 /* 'switchbuf' */
6997 else if (varp == &p_swb)
6998 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006999 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007000 errmsg = e_invarg;
7001 }
7002
7003 /* 'debug' */
7004 else if (varp == &p_debug)
7005 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007006 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007007 errmsg = e_invarg;
7008 }
7009
7010 /* 'display' */
7011 else if (varp == &p_dy)
7012 {
7013 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7014 errmsg = e_invarg;
7015 else
7016 (void)init_chartab();
7017
7018 }
7019
Bram Moolenaar071d4272004-06-13 20:20:40 +00007020 /* 'eadirection' */
7021 else if (varp == &p_ead)
7022 {
7023 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7024 errmsg = e_invarg;
7025 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026
7027#ifdef FEAT_CLIPBOARD
7028 /* 'clipboard' */
7029 else if (varp == &p_cb)
7030 errmsg = check_clipboard_option();
7031#endif
7032
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007033#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007034 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7035 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007036 else if (varp == &(curwin->w_s->b_p_spl)
7037 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007038 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007039 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007040 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007041 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007042 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007043 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007044 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007045 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007046 /* 'spellsuggest' */
7047 else if (varp == &p_sps)
7048 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007049 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007050 errmsg = e_invarg;
7051 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007052 /* 'mkspellmem' */
7053 else if (varp == &p_msm)
7054 {
7055 if (spell_check_msm() != OK)
7056 errmsg = e_invarg;
7057 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007058#endif
7059
Bram Moolenaar071d4272004-06-13 20:20:40 +00007060 /* When 'bufhidden' is set, check for valid value. */
7061 else if (gvarp == &p_bh)
7062 {
7063 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7064 errmsg = e_invarg;
7065 }
7066
7067 /* When 'buftype' is set, check for valid value. */
7068 else if (gvarp == &p_bt)
7069 {
7070 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7071 errmsg = e_invarg;
7072 else
7073 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007074 if (curwin->w_status_height)
7075 {
7076 curwin->w_redr_status = TRUE;
7077 redraw_later(VALID);
7078 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007079 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007080#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007081 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007082#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007083 }
7084 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085
7086#ifdef FEAT_STL_OPT
7087 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007088 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007089 {
7090 int wid;
7091
7092 if (varp == &p_ruf) /* reset ru_wid first */
7093 ru_wid = 0;
7094 s = *varp;
7095 if (varp == &p_ruf && *s == '%')
7096 {
7097 /* set ru_wid if 'ruf' starts with "%99(" */
7098 if (*++s == '-') /* ignore a '-' */
7099 s++;
7100 wid = getdigits(&s);
7101 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7102 ru_wid = wid;
7103 else
7104 errmsg = check_stl_option(p_ruf);
7105 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007106 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007107 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007108 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007109 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110 comp_col();
7111 }
7112#endif
7113
7114#ifdef FEAT_INS_EXPAND
7115 /* check if it is a valid value for 'complete' -- Acevedo */
7116 else if (gvarp == &p_cpt)
7117 {
7118 for (s = *varp; *s;)
7119 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007120 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121 s++;
7122 if (!*s)
7123 break;
7124 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7125 {
7126 errmsg = illegal_char(errbuf, *s);
7127 break;
7128 }
7129 if (*++s != NUL && *s != ',' && *s != ' ')
7130 {
7131 if (s[-1] == 'k' || s[-1] == 's')
7132 {
7133 /* skip optional filename after 'k' and 's' */
7134 while (*s && *s != ',' && *s != ' ')
7135 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007136 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007137 ++s;
7138 ++s;
7139 }
7140 }
7141 else
7142 {
7143 if (errbuf != NULL)
7144 {
7145 sprintf((char *)errbuf,
7146 _("E535: Illegal character after <%c>"),
7147 *--s);
7148 errmsg = errbuf;
7149 }
7150 else
7151 errmsg = (char_u *)"";
7152 break;
7153 }
7154 }
7155 }
7156 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007157
7158 /* 'completeopt' */
7159 else if (varp == &p_cot)
7160 {
7161 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7162 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007163 else
7164 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007165 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007166#endif /* FEAT_INS_EXPAND */
7167
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007168#ifdef FEAT_SIGNS
7169 /* 'signcolumn' */
7170 else if (varp == &curwin->w_p_scl)
7171 {
7172 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7173 errmsg = e_invarg;
7174 }
7175#endif
7176
Bram Moolenaar071d4272004-06-13 20:20:40 +00007177
7178#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007179 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180 else if (varp == &p_toolbar)
7181 {
7182 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7183 &toolbar_flags, TRUE) != OK)
7184 errmsg = e_invarg;
7185 else
7186 {
7187 out_flush();
7188 gui_mch_show_toolbar((toolbar_flags &
7189 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7190 }
7191 }
7192#endif
7193
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007194#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007195 /* 'toolbariconsize': GTK+ 2 only */
7196 else if (varp == &p_tbis)
7197 {
7198 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7199 errmsg = e_invarg;
7200 else
7201 {
7202 out_flush();
7203 gui_mch_show_toolbar((toolbar_flags &
7204 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7205 }
7206 }
7207#endif
7208
7209 /* 'pastetoggle': translate key codes like in a mapping */
7210 else if (varp == &p_pt)
7211 {
7212 if (*p_pt)
7213 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007214 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007215 if (p != NULL)
7216 {
7217 if (new_value_alloced)
7218 free_string_option(p_pt);
7219 p_pt = p;
7220 new_value_alloced = TRUE;
7221 }
7222 }
7223 }
7224
7225 /* 'backspace' */
7226 else if (varp == &p_bs)
7227 {
7228 if (VIM_ISDIGIT(*p_bs))
7229 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007230 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007231 errmsg = e_invarg;
7232 }
7233 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7234 errmsg = e_invarg;
7235 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007236 else if (varp == &p_bo)
7237 {
7238 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7239 errmsg = e_invarg;
7240 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007241
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007242 /* 'tagcase' */
7243 else if (gvarp == &p_tc)
7244 {
7245 unsigned int *flags;
7246
7247 if (opt_flags & OPT_LOCAL)
7248 {
7249 p = curbuf->b_p_tc;
7250 flags = &curbuf->b_tc_flags;
7251 }
7252 else
7253 {
7254 p = p_tc;
7255 flags = &tc_flags;
7256 }
7257
7258 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7259 /* make the local value empty: use the global value */
7260 *flags = 0;
7261 else if (*p == NUL
7262 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7263 errmsg = e_invarg;
7264 }
7265
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007266#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007267 /* 'casemap' */
7268 else if (varp == &p_cmp)
7269 {
7270 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7271 errmsg = e_invarg;
7272 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007273#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007274
7275#ifdef FEAT_DIFF
7276 /* 'diffopt' */
7277 else if (varp == &p_dip)
7278 {
7279 if (diffopt_changed() == FAIL)
7280 errmsg = e_invarg;
7281 }
7282#endif
7283
7284#ifdef FEAT_FOLDING
7285 /* 'foldmethod' */
7286 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7287 {
7288 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7289 || *curwin->w_p_fdm == NUL)
7290 errmsg = e_invarg;
7291 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007292 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007293 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007294 if (foldmethodIsDiff(curwin))
7295 newFoldLevel();
7296 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007297 }
7298# ifdef FEAT_EVAL
7299 /* 'foldexpr' */
7300 else if (varp == &curwin->w_p_fde)
7301 {
7302 if (foldmethodIsExpr(curwin))
7303 foldUpdateAll(curwin);
7304 }
7305# endif
7306 /* 'foldmarker' */
7307 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7308 {
7309 p = vim_strchr(*varp, ',');
7310 if (p == NULL)
7311 errmsg = (char_u *)N_("E536: comma required");
7312 else if (p == *varp || p[1] == NUL)
7313 errmsg = e_invarg;
7314 else if (foldmethodIsMarker(curwin))
7315 foldUpdateAll(curwin);
7316 }
7317 /* 'commentstring' */
7318 else if (gvarp == &p_cms)
7319 {
7320 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7321 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7322 }
7323 /* 'foldopen' */
7324 else if (varp == &p_fdo)
7325 {
7326 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7327 errmsg = e_invarg;
7328 }
7329 /* 'foldclose' */
7330 else if (varp == &p_fcl)
7331 {
7332 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7333 errmsg = e_invarg;
7334 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007335 /* 'foldignore' */
7336 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7337 {
7338 if (foldmethodIsIndent(curwin))
7339 foldUpdateAll(curwin);
7340 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007341#endif
7342
7343#ifdef FEAT_VIRTUALEDIT
7344 /* 'virtualedit' */
7345 else if (varp == &p_ve)
7346 {
7347 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7348 errmsg = e_invarg;
7349 else if (STRCMP(p_ve, oldval) != 0)
7350 {
7351 /* Recompute cursor position in case the new 've' setting
7352 * changes something. */
7353 validate_virtcol();
7354 coladvance(curwin->w_virtcol);
7355 }
7356 }
7357#endif
7358
7359#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7360 else if (varp == &p_csqf)
7361 {
7362 if (p_csqf != NULL)
7363 {
7364 p = p_csqf;
7365 while (*p != NUL)
7366 {
7367 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7368 || p[1] == NUL
7369 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7370 || (p[2] != NUL && p[2] != ','))
7371 {
7372 errmsg = e_invarg;
7373 break;
7374 }
7375 else if (p[2] == NUL)
7376 break;
7377 else
7378 p += 3;
7379 }
7380 }
7381 }
7382#endif
7383
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007384#ifdef FEAT_CINDENT
7385 /* 'cinoptions' */
7386 else if (gvarp == &p_cino)
7387 {
7388 /* TODO: recognize errors */
7389 parse_cino(curbuf);
7390 }
7391#endif
7392
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007393#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007394 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007395 else if (varp == &p_rop && gui.in_use)
7396 {
7397 if (!gui_mch_set_rendering_options(p_rop))
7398 errmsg = e_invarg;
7399 }
7400#endif
7401
Bram Moolenaard0b51382016-11-04 15:23:45 +01007402#ifdef FEAT_AUTOCMD
7403 else if (gvarp == &p_ft)
7404 {
7405 if (!valid_filetype(*varp))
7406 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007407 else
7408 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007409 }
7410#endif
7411
7412#ifdef FEAT_SYN_HL
7413 else if (gvarp == &p_syn)
7414 {
7415 if (!valid_filetype(*varp))
7416 errmsg = e_invarg;
7417 }
7418#endif
7419
Bram Moolenaar825680f2017-07-22 17:04:02 +02007420#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007421 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007422 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007423 {
7424 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7425 errmsg = e_invarg;
7426 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007427 /* 'termsize' */
7428 else if (varp == &curwin->w_p_tms)
7429 {
7430 if (*curwin->w_p_tms != NUL)
7431 {
7432 p = skipdigits(curwin->w_p_tms);
7433 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7434 errmsg = e_invarg;
7435 }
7436 }
7437#endif
7438
Bram Moolenaar071d4272004-06-13 20:20:40 +00007439 /* Options that are a list of flags. */
7440 else
7441 {
7442 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007443 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007444 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007445 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007446 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007447 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007448 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007449 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007450 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007451#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007452 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007453 p = (char_u *)COCU_ALL;
7454#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007455 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007456 {
7457#ifdef FEAT_MOUSE
7458 p = (char_u *)MOUSE_ALL;
7459#else
7460 if (*p_mouse != NUL)
7461 errmsg = (char_u *)N_("E538: No mouse support");
7462#endif
7463 }
7464#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007465 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007466 p = (char_u *)GO_ALL;
7467#endif
7468 if (p != NULL)
7469 {
7470 for (s = *varp; *s; ++s)
7471 if (vim_strchr(p, *s) == NULL)
7472 {
7473 errmsg = illegal_char(errbuf, *s);
7474 break;
7475 }
7476 }
7477 }
7478
7479 /*
7480 * If error detected, restore the previous value.
7481 */
7482 if (errmsg != NULL)
7483 {
7484 if (new_value_alloced)
7485 free_string_option(*varp);
7486 *varp = oldval;
7487 /*
7488 * When resetting some values, need to act on it.
7489 */
7490 if (did_chartab)
7491 (void)init_chartab();
7492 if (varp == &p_hl)
7493 (void)highlight_changed();
7494 }
7495 else
7496 {
7497#ifdef FEAT_EVAL
7498 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007499 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007500#endif
7501 /*
7502 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007503 * Use "free_oldval", because recursiveness may change the flags under
7504 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007505 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007506 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007507 free_string_option(oldval);
7508 if (new_value_alloced)
7509 options[opt_idx].flags |= P_ALLOCED;
7510 else
7511 options[opt_idx].flags &= ~P_ALLOCED;
7512
7513 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007514 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007515 {
7516 /* global option with local value set to use global value; free
7517 * the local value and make it empty */
7518 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7519 free_string_option(*(char_u **)p);
7520 *(char_u **)p = empty_option;
7521 }
7522
7523 /* May set global value for local option. */
7524 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7525 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007526
7527#ifdef FEAT_AUTOCMD
7528 /*
7529 * Trigger the autocommand only after setting the flags.
7530 */
7531# ifdef FEAT_SYN_HL
7532 /* When 'syntax' is set, load the syntax of that name */
7533 if (varp == &(curbuf->b_p_syn))
7534 {
7535 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7536 curbuf->b_fname, TRUE, curbuf);
7537 }
7538# endif
7539 else if (varp == &(curbuf->b_p_ft))
7540 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007541 /* 'filetype' is set, trigger the FileType autocommand.
7542 * Skip this when called from a modeline and the filetype was
7543 * already set to this value. */
7544 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7545 {
7546 did_filetype = TRUE;
7547 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007548 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007549 /* Just in case the old "curbuf" is now invalid. */
7550 if (varp != &(curbuf->b_p_ft))
7551 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007552 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007553 }
7554#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007555#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007556 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007557 {
7558 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007559 char_u *q = curwin->w_s->b_p_spl;
7560
7561 /* Skip the first name if it is "cjk". */
7562 if (STRNCMP(q, "cjk,", 4) == 0)
7563 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007564
7565 /*
7566 * Source the spell/LANG.vim in 'runtimepath'.
7567 * They could set 'spellcapcheck' depending on the language.
7568 * Use the first name in 'spelllang' up to '_region' or
7569 * '.encoding'.
7570 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007571 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007572 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7573 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007574 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007575 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007576 }
7577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007578 }
7579
7580#ifdef FEAT_MOUSE
7581 if (varp == &p_mouse)
7582 {
7583# ifdef FEAT_MOUSE_TTY
7584 if (*p_mouse == NUL)
7585 mch_setmouse(FALSE); /* switch mouse off */
7586 else
7587# endif
7588 setmouse(); /* in case 'mouse' changed */
7589 }
7590#endif
7591
Bram Moolenaar913077c2012-03-28 19:59:04 +02007592 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007593 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007594 curwin->w_set_curswant = TRUE;
7595
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007596#ifdef FEAT_GUI
7597 /* check redraw when it's not a GUI option or the GUI is active. */
7598 if (!redraw_gui_only || gui.in_use)
7599#endif
7600 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601
7602 return errmsg;
7603}
7604
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007605#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007606/*
7607 * Simple int comparison function for use with qsort()
7608 */
7609 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007610int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007611{
7612 return *(const int *)a - *(const int *)b;
7613}
7614
7615/*
7616 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7617 * Returns error message, NULL if it's OK.
7618 */
7619 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007620check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007621{
7622 char_u *s;
7623 int col;
7624 int count = 0;
7625 int color_cols[256];
7626 int i;
7627 int j = 0;
7628
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007629 if (wp->w_buffer == NULL)
7630 return NULL; /* buffer was closed */
7631
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007632 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007633 {
7634 if (*s == '-' || *s == '+')
7635 {
7636 /* -N and +N: add to 'textwidth' */
7637 col = (*s == '-') ? -1 : 1;
7638 ++s;
7639 if (!VIM_ISDIGIT(*s))
7640 return e_invarg;
7641 col = col * getdigits(&s);
7642 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007643 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007644 col += wp->w_buffer->b_p_tw;
7645 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007646 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007647 }
7648 else if (VIM_ISDIGIT(*s))
7649 col = getdigits(&s);
7650 else
7651 return e_invarg;
7652 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007653skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007654 if (*s == NUL)
7655 break;
7656 if (*s != ',')
7657 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007658 if (*++s == NUL)
7659 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007660 }
7661
7662 vim_free(wp->w_p_cc_cols);
7663 if (count == 0)
7664 wp->w_p_cc_cols = NULL;
7665 else
7666 {
7667 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7668 if (wp->w_p_cc_cols != NULL)
7669 {
7670 /* sort the columns for faster usage on screen redraw inside
7671 * win_line() */
7672 qsort(color_cols, count, sizeof(int), int_cmp);
7673
7674 for (i = 0; i < count; ++i)
7675 /* skip duplicates */
7676 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7677 wp->w_p_cc_cols[j++] = color_cols[i];
7678 wp->w_p_cc_cols[j] = -1; /* end marker */
7679 }
7680 }
7681
7682 return NULL; /* no error */
7683}
7684#endif
7685
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686/*
7687 * Handle setting 'listchars' or 'fillchars'.
7688 * Returns error message, NULL if it's OK.
7689 */
7690 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007691set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007692{
7693 int round, i, len, entries;
7694 char_u *p, *s;
7695 int c1, c2 = 0;
7696 struct charstab
7697 {
7698 int *cp;
7699 char *name;
7700 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007701 static struct charstab filltab[] =
7702 {
7703 {&fill_stl, "stl"},
7704 {&fill_stlnc, "stlnc"},
7705 {&fill_vert, "vert"},
7706 {&fill_fold, "fold"},
7707 {&fill_diff, "diff"},
7708 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007709 static struct charstab lcstab[] =
7710 {
7711 {&lcs_eol, "eol"},
7712 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007713 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007714 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007715 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007716 {&lcs_tab2, "tab"},
7717 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007718#ifdef FEAT_CONCEAL
7719 {&lcs_conceal, "conceal"},
7720#else
7721 {NULL, "conceal"},
7722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 };
7724 struct charstab *tab;
7725
Bram Moolenaar071d4272004-06-13 20:20:40 +00007726 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007727 {
7728 tab = lcstab;
7729 entries = sizeof(lcstab) / sizeof(struct charstab);
7730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007731 else
7732 {
7733 tab = filltab;
7734 entries = sizeof(filltab) / sizeof(struct charstab);
7735 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736
7737 /* first round: check for valid value, second round: assign values */
7738 for (round = 0; round <= 1; ++round)
7739 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007740 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741 {
7742 /* After checking that the value is valid: set defaults: space for
7743 * 'fillchars', NUL for 'listchars' */
7744 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007745 if (tab[i].cp != NULL)
7746 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747 if (varp == &p_lcs)
7748 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749 else
7750 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007751 }
7752 p = *varp;
7753 while (*p)
7754 {
7755 for (i = 0; i < entries; ++i)
7756 {
7757 len = (int)STRLEN(tab[i].name);
7758 if (STRNCMP(p, tab[i].name, len) == 0
7759 && p[len] == ':'
7760 && p[len + 1] != NUL)
7761 {
7762 s = p + len + 1;
7763#ifdef FEAT_MBYTE
7764 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007765 if (mb_char2cells(c1) > 1)
7766 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767#else
7768 c1 = *s++;
7769#endif
7770 if (tab[i].cp == &lcs_tab2)
7771 {
7772 if (*s == NUL)
7773 continue;
7774#ifdef FEAT_MBYTE
7775 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007776 if (mb_char2cells(c2) > 1)
7777 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778#else
7779 c2 = *s++;
7780#endif
7781 }
7782 if (*s == ',' || *s == NUL)
7783 {
7784 if (round)
7785 {
7786 if (tab[i].cp == &lcs_tab2)
7787 {
7788 lcs_tab1 = c1;
7789 lcs_tab2 = c2;
7790 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007791 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792 *(tab[i].cp) = c1;
7793
7794 }
7795 p = s;
7796 break;
7797 }
7798 }
7799 }
7800
7801 if (i == entries)
7802 return e_invarg;
7803 if (*p == ',')
7804 ++p;
7805 }
7806 }
7807
7808 return NULL; /* no error */
7809}
7810
7811#ifdef FEAT_STL_OPT
7812/*
7813 * Check validity of options with the 'statusline' format.
7814 * Return error message or NULL.
7815 */
7816 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007817check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818{
7819 int itemcnt = 0;
7820 int groupdepth = 0;
7821 static char_u errbuf[80];
7822
7823 while (*s && itemcnt < STL_MAX_ITEM)
7824 {
7825 /* Check for valid keys after % sequences */
7826 while (*s && *s != '%')
7827 s++;
7828 if (!*s)
7829 break;
7830 s++;
7831 if (*s != '%' && *s != ')')
7832 ++itemcnt;
7833 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7834 {
7835 s++;
7836 continue;
7837 }
7838 if (*s == ')')
7839 {
7840 s++;
7841 if (--groupdepth < 0)
7842 break;
7843 continue;
7844 }
7845 if (*s == '-')
7846 s++;
7847 while (VIM_ISDIGIT(*s))
7848 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007849 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850 continue;
7851 if (*s == '.')
7852 {
7853 s++;
7854 while (*s && VIM_ISDIGIT(*s))
7855 s++;
7856 }
7857 if (*s == '(')
7858 {
7859 groupdepth++;
7860 continue;
7861 }
7862 if (vim_strchr(STL_ALL, *s) == NULL)
7863 {
7864 return illegal_char(errbuf, *s);
7865 }
7866 if (*s == '{')
7867 {
7868 s++;
7869 while (*s != '}' && *s)
7870 s++;
7871 if (*s != '}')
7872 return (char_u *)N_("E540: Unclosed expression sequence");
7873 }
7874 }
7875 if (itemcnt >= STL_MAX_ITEM)
7876 return (char_u *)N_("E541: too many items");
7877 if (groupdepth != 0)
7878 return (char_u *)N_("E542: unbalanced groups");
7879 return NULL;
7880}
7881#endif
7882
7883#ifdef FEAT_CLIPBOARD
7884/*
7885 * Extract the items in the 'clipboard' option and set global values.
7886 */
7887 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007888check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007890 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007891 int new_autoselect_star = FALSE;
7892 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007893 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007894 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895 regprog_T *new_exclude_prog = NULL;
7896 char_u *errmsg = NULL;
7897 char_u *p;
7898
7899 for (p = p_cb; *p != NUL; )
7900 {
7901 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7902 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007903 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 p += 7;
7905 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007906 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007907 && (p[11] == ',' || p[11] == NUL))
7908 {
7909 new_unnamed |= CLIP_UNNAMED_PLUS;
7910 p += 11;
7911 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007912 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007913 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007915 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007916 p += 10;
7917 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007918 else if (STRNCMP(p, "autoselectplus", 14) == 0
7919 && (p[14] == ',' || p[14] == NUL))
7920 {
7921 new_autoselect_plus = TRUE;
7922 p += 14;
7923 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007924 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007925 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926 {
7927 new_autoselectml = TRUE;
7928 p += 12;
7929 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007930 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7931 {
7932 new_html = TRUE;
7933 p += 4;
7934 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7936 {
7937 p += 8;
7938 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7939 if (new_exclude_prog == NULL)
7940 errmsg = e_invarg;
7941 break;
7942 }
7943 else
7944 {
7945 errmsg = e_invarg;
7946 break;
7947 }
7948 if (*p == ',')
7949 ++p;
7950 }
7951 if (errmsg == NULL)
7952 {
7953 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007954 clip_autoselect_star = new_autoselect_star;
7955 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007957 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007958 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007960#ifdef FEAT_GUI_GTK
7961 if (gui.in_use)
7962 {
7963 gui_gtk_set_selection_targets();
7964 gui_gtk_set_dnd_targets();
7965 }
7966#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 }
7968 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007969 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970
7971 return errmsg;
7972}
7973#endif
7974
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007975#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007976 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007977did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007978{
7979 char_u *errmsg = NULL;
7980 win_T *wp;
7981 int l;
7982
7983 if (is_spellfile)
7984 {
7985 l = (int)STRLEN(curwin->w_s->b_p_spf);
7986 if (l > 0 && (l < 4
7987 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7988 errmsg = e_invarg;
7989 }
7990
7991 if (errmsg == NULL)
7992 {
7993 FOR_ALL_WINDOWS(wp)
7994 if (wp->w_buffer == curbuf && wp->w_p_spell)
7995 {
7996 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007997 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007998 }
7999 }
8000 return errmsg;
8001}
8002
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008003/*
8004 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8005 * Return error message when failed, NULL when OK.
8006 */
8007 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008008compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008009{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008010 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008011 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008012
Bram Moolenaar860cae12010-06-05 23:22:07 +02008013 if (*synblock->b_p_spc == NUL)
8014 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008015 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008016 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008017 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008018 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008019 if (re != NULL)
8020 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008021 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008022 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008023 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008024 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008025 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008026 return e_invarg;
8027 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008028 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008029 }
8030
Bram Moolenaar473de612013-06-08 18:19:48 +02008031 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008032 return NULL;
8033}
8034#endif
8035
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008036#if defined(FEAT_EVAL) || defined(PROTO)
8037/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008038 * Set the scriptID for an option, taking care of setting the buffer- or
8039 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008040 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008041 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008042set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008043{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008044 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8045 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008046
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008047 /* Remember where the option was set. For local options need to do that
8048 * in the buffer or window structure. */
8049 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008050 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008051 if (both || (opt_flags & OPT_LOCAL))
8052 {
8053 if (indir & PV_BUF)
8054 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8055 else if (indir & PV_WIN)
8056 curwin->w_p_scriptID[indir & PV_MASK] = id;
8057 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008058}
8059#endif
8060
Bram Moolenaar071d4272004-06-13 20:20:40 +00008061/*
8062 * Set the value of a boolean option, and take care of side effects.
8063 * Returns NULL for success, or an error message for an error.
8064 */
8065 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008066set_bool_option(
8067 int opt_idx, /* index in options[] table */
8068 char_u *varp, /* pointer to the option variable */
8069 int value, /* new value */
8070 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008071{
8072 int old_value = *(int *)varp;
8073
Bram Moolenaar071d4272004-06-13 20:20:40 +00008074 /* Disallow changing some options from secure mode */
8075 if ((secure
8076#ifdef HAVE_SANDBOX
8077 || sandbox != 0
8078#endif
8079 ) && (options[opt_idx].flags & P_SECURE))
8080 return e_secure;
8081
8082 *(int *)varp = value; /* set the new value */
8083#ifdef FEAT_EVAL
8084 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008085 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086#endif
8087
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008088#ifdef FEAT_GUI
8089 need_mouse_correct = TRUE;
8090#endif
8091
Bram Moolenaar071d4272004-06-13 20:20:40 +00008092 /* May set global value for local option. */
8093 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8094 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8095
8096 /*
8097 * Handle side effects of changing a bool option.
8098 */
8099
8100 /* 'compatible' */
8101 if ((int *)varp == &p_cp)
8102 {
8103 compatible_set();
8104 }
8105
Bram Moolenaar920694c2016-08-21 17:45:02 +02008106#ifdef FEAT_LANGMAP
8107 if ((int *)varp == &p_lrm)
8108 /* 'langremap' -> !'langnoremap' */
8109 p_lnr = !p_lrm;
8110 else if ((int *)varp == &p_lnr)
8111 /* 'langnoremap' -> !'langremap' */
8112 p_lrm = !p_lnr;
8113#endif
8114
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008115#ifdef FEAT_PERSISTENT_UNDO
8116 /* 'undofile' */
8117 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8118 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008119 /* Only take action when the option was set. When reset we do not
8120 * delete the undo file, the option may be set again without making
8121 * any changes in between. */
8122 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008123 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008124 char_u hash[UNDO_HASH_SIZE];
8125 buf_T *save_curbuf = curbuf;
8126
Bram Moolenaar29323592016-07-24 22:04:11 +02008127 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008128 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008129 /* When 'undofile' is set globally: for every buffer, otherwise
8130 * only for the current buffer: Try to read in the undofile,
8131 * if one exists, the buffer wasn't changed and the buffer was
8132 * loaded */
8133 if ((curbuf == save_curbuf
8134 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8135 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8136 {
8137 u_compute_hash(hash);
8138 u_read_undo(NULL, hash, curbuf->b_fname);
8139 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008140 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008141 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008142 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008143 }
8144#endif
8145
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146 else if ((int *)varp == &curbuf->b_p_ro)
8147 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008148 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8150 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008151
8152 /* when 'readonly' is set may give W10 again */
8153 if (curbuf->b_p_ro)
8154 curbuf->b_did_warn = FALSE;
8155
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008157 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158#endif
8159 }
8160
Bram Moolenaar9c449722010-07-20 18:44:27 +02008161#ifdef FEAT_GUI
8162 else if ((int *)varp == &p_mh)
8163 {
8164 if (!p_mh)
8165 gui_mch_mousehide(FALSE);
8166 }
8167#endif
8168
Bram Moolenaara539df02010-08-01 14:35:05 +02008169 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008170 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008171 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008172# ifdef FEAT_TERMINAL
8173 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008174 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008175 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008176 {
8177 curbuf->b_p_ma = FALSE;
8178 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8179 }
8180# endif
8181# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008182 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008183# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008184 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008185#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008186 /* when 'endofline' is changed, redraw the window title */
8187 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008188 {
8189 redraw_titles();
8190 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008191 /* when 'fixeol' is changed, redraw the window title */
8192 else if ((int *)varp == &curbuf->b_p_fixeol)
8193 {
8194 redraw_titles();
8195 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008196# ifdef FEAT_MBYTE
8197 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008198 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008199 {
8200 redraw_titles();
8201 }
8202# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008203#endif
8204
8205 /* when 'bin' is set also set some other options */
8206 else if ((int *)varp == &curbuf->b_p_bin)
8207 {
8208 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8209#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008210 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008211#endif
8212 }
8213
8214#ifdef FEAT_AUTOCMD
8215 /* when 'buflisted' changes, trigger autocommands */
8216 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8217 {
8218 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8219 NULL, NULL, TRUE, curbuf);
8220 }
8221#endif
8222
8223 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8224 else if ((int *)varp == &curbuf->b_p_swf)
8225 {
8226 if (curbuf->b_p_swf && p_uc)
8227 ml_open_file(curbuf); /* create the swap file */
8228 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008229 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8230 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231 mf_close_file(curbuf, TRUE); /* remove the swap file */
8232 }
8233
8234 /* when 'terse' is set change 'shortmess' */
8235 else if ((int *)varp == &p_terse)
8236 {
8237 char_u *p;
8238
8239 p = vim_strchr(p_shm, SHM_SEARCH);
8240
8241 /* insert 's' in p_shm */
8242 if (p_terse && p == NULL)
8243 {
8244 STRCPY(IObuff, p_shm);
8245 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008246 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008247 }
8248 /* remove 's' from p_shm */
8249 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008250 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251 }
8252
8253 /* when 'paste' is set or reset also change other options */
8254 else if ((int *)varp == &p_paste)
8255 {
8256 paste_option_changed();
8257 }
8258
8259 /* when 'insertmode' is set from an autocommand need to do work here */
8260 else if ((int *)varp == &p_im)
8261 {
8262 if (p_im)
8263 {
8264 if ((State & INSERT) == 0)
8265 need_start_insertmode = TRUE;
8266 stop_insert_mode = FALSE;
8267 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008268 /* only reset if it was set previously */
8269 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008270 {
8271 need_start_insertmode = FALSE;
8272 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008273 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008274 clear_cmdline = TRUE; /* remove "(insert)" */
8275 restart_edit = 0;
8276 }
8277 }
8278
8279 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8280 else if ((int *)varp == &p_ic && p_hls)
8281 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008282 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008283 }
8284
8285#ifdef FEAT_SEARCH_EXTRA
8286 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8287 else if ((int *)varp == &p_hls)
8288 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008289 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 }
8291#endif
8292
8293#ifdef FEAT_SCROLLBIND
8294 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8295 * at the end of normal_cmd() */
8296 else if ((int *)varp == &curwin->w_p_scb)
8297 {
8298 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008299 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008301 curwin->w_scbind_pos = curwin->w_topline;
8302 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008303 }
8304#endif
8305
Bram Moolenaar4033c552017-09-16 20:54:51 +02008306#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008307 /* There can be only one window with 'previewwindow' set. */
8308 else if ((int *)varp == &curwin->w_p_pvw)
8309 {
8310 if (curwin->w_p_pvw)
8311 {
8312 win_T *win;
8313
Bram Moolenaar29323592016-07-24 22:04:11 +02008314 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008315 if (win->w_p_pvw && win != curwin)
8316 {
8317 curwin->w_p_pvw = FALSE;
8318 return (char_u *)N_("E590: A preview window already exists");
8319 }
8320 }
8321 }
8322#endif
8323
8324 /* when 'textmode' is set or reset also change 'fileformat' */
8325 else if ((int *)varp == &curbuf->b_p_tx)
8326 {
8327 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8328 }
8329
8330 /* when 'textauto' is set or reset also change 'fileformats' */
8331 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008332 set_string_option_direct((char_u *)"ffs", -1,
8333 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008334 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008335
8336 /*
8337 * When 'lisp' option changes include/exclude '-' in
8338 * keyword characters.
8339 */
8340#ifdef FEAT_LISP
8341 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8342 {
8343 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8344 }
8345#endif
8346
8347#ifdef FEAT_TITLE
8348 /* when 'title' changed, may need to change the title; same for 'icon' */
8349 else if ((int *)varp == &p_title)
8350 {
8351 did_set_title(FALSE);
8352 }
8353
8354 else if ((int *)varp == &p_icon)
8355 {
8356 did_set_title(TRUE);
8357 }
8358#endif
8359
8360 else if ((int *)varp == &curbuf->b_changed)
8361 {
8362 if (!value)
8363 save_file_ff(curbuf); /* Buffer is unchanged */
8364#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008365 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008366#endif
8367#ifdef FEAT_AUTOCMD
8368 modified_was_set = value;
8369#endif
8370 }
8371
8372#ifdef BACKSLASH_IN_FILENAME
8373 else if ((int *)varp == &p_ssl)
8374 {
8375 if (p_ssl)
8376 {
8377 psepc = '/';
8378 psepcN = '\\';
8379 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380 }
8381 else
8382 {
8383 psepc = '\\';
8384 psepcN = '/';
8385 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386 }
8387
8388 /* need to adjust the file name arguments and buffer names. */
8389 buflist_slash_adjust();
8390 alist_slash_adjust();
8391# ifdef FEAT_EVAL
8392 scriptnames_slash_adjust();
8393# endif
8394 }
8395#endif
8396
8397 /* If 'wrap' is set, set w_leftcol to zero. */
8398 else if ((int *)varp == &curwin->w_p_wrap)
8399 {
8400 if (curwin->w_p_wrap)
8401 curwin->w_leftcol = 0;
8402 }
8403
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404 else if ((int *)varp == &p_ea)
8405 {
8406 if (p_ea && !old_value)
8407 win_equal(curwin, FALSE, 0);
8408 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409
8410 else if ((int *)varp == &p_wiv)
8411 {
8412 /*
8413 * When 'weirdinvert' changed, set/reset 't_xs'.
8414 * Then set 'weirdinvert' according to value of 't_xs'.
8415 */
8416 if (p_wiv && !old_value)
8417 T_XS = (char_u *)"y";
8418 else if (!p_wiv && old_value)
8419 T_XS = empty_option;
8420 p_wiv = (*T_XS != NUL);
8421 }
8422
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008423#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424 else if ((int *)varp == &p_beval)
8425 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008426 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008427 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008428 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008429 gui_mch_disable_beval_area(balloonEval);
8430 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008432
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008433#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 else if ((int *)varp == &p_acd)
8435 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008436 /* Change directories when the 'acd' option is set now. */
8437 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008438 }
8439#endif
8440
8441#ifdef FEAT_DIFF
8442 /* 'diff' */
8443 else if ((int *)varp == &curwin->w_p_diff)
8444 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008445 /* May add or remove the buffer from the list of diff buffers. */
8446 diff_buf_adjust(curwin);
8447# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008448 if (foldmethodIsDiff(curwin))
8449 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008450# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451 }
8452#endif
8453
8454#ifdef USE_IM_CONTROL
8455 /* 'imdisable' */
8456 else if ((int *)varp == &p_imdisable)
8457 {
8458 /* Only de-activate it here, it will be enabled when changing mode. */
8459 if (p_imdisable)
8460 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008461 else if (State & INSERT)
8462 /* When the option is set from an autocommand, it may need to take
8463 * effect right away. */
8464 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008465 }
8466#endif
8467
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008468#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008469 /* 'spell' */
8470 else if ((int *)varp == &curwin->w_p_spell)
8471 {
8472 if (curwin->w_p_spell)
8473 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008474 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008475 if (errmsg != NULL)
8476 EMSG(_(errmsg));
8477 }
8478 }
8479#endif
8480
Bram Moolenaar071d4272004-06-13 20:20:40 +00008481#ifdef FEAT_FKMAP
8482 else if ((int *)varp == &p_altkeymap)
8483 {
8484 if (old_value != p_altkeymap)
8485 {
8486 if (!p_altkeymap)
8487 {
8488 p_hkmap = p_fkmap;
8489 p_fkmap = 0;
8490 }
8491 else
8492 {
8493 p_fkmap = p_hkmap;
8494 p_hkmap = 0;
8495 }
8496 (void)init_chartab();
8497 }
8498 }
8499
8500 /*
8501 * In case some second language keymapping options have changed, check
8502 * and correct the setting in a consistent way.
8503 */
8504
8505 /*
8506 * If hkmap or fkmap are set, reset Arabic keymapping.
8507 */
8508 if ((p_hkmap || p_fkmap) && p_altkeymap)
8509 {
8510 p_altkeymap = p_fkmap;
8511# ifdef FEAT_ARABIC
8512 curwin->w_p_arab = FALSE;
8513# endif
8514 (void)init_chartab();
8515 }
8516
8517 /*
8518 * If hkmap set, reset Farsi keymapping.
8519 */
8520 if (p_hkmap && p_altkeymap)
8521 {
8522 p_altkeymap = 0;
8523 p_fkmap = 0;
8524# ifdef FEAT_ARABIC
8525 curwin->w_p_arab = FALSE;
8526# endif
8527 (void)init_chartab();
8528 }
8529
8530 /*
8531 * If fkmap set, reset Hebrew keymapping.
8532 */
8533 if (p_fkmap && !p_altkeymap)
8534 {
8535 p_altkeymap = 1;
8536 p_hkmap = 0;
8537# ifdef FEAT_ARABIC
8538 curwin->w_p_arab = FALSE;
8539# endif
8540 (void)init_chartab();
8541 }
8542#endif
8543
8544#ifdef FEAT_ARABIC
8545 if ((int *)varp == &curwin->w_p_arab)
8546 {
8547 if (curwin->w_p_arab)
8548 {
8549 /*
8550 * 'arabic' is set, handle various sub-settings.
8551 */
8552 if (!p_tbidi)
8553 {
8554 /* set rightleft mode */
8555 if (!curwin->w_p_rl)
8556 {
8557 curwin->w_p_rl = TRUE;
8558 changed_window_setting();
8559 }
8560
8561 /* Enable Arabic shaping (major part of what Arabic requires) */
8562 if (!p_arshape)
8563 {
8564 p_arshape = TRUE;
8565 redraw_later_clear();
8566 }
8567 }
8568
8569 /* Arabic requires a utf-8 encoding, inform the user if its not
8570 * set. */
8571 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008572 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008573 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8574
Bram Moolenaar8820b482017-03-16 17:23:31 +01008575 msg_source(HL_ATTR(HLF_W));
8576 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008577#ifdef FEAT_EVAL
8578 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8579#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008581
8582# ifdef FEAT_MBYTE
8583 /* set 'delcombine' */
8584 p_deco = TRUE;
8585# endif
8586
8587# ifdef FEAT_KEYMAP
8588 /* Force-set the necessary keymap for arabic */
8589 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8590 OPT_LOCAL);
8591# endif
8592# ifdef FEAT_FKMAP
8593 p_altkeymap = 0;
8594 p_hkmap = 0;
8595 p_fkmap = 0;
8596 (void)init_chartab();
8597# endif
8598 }
8599 else
8600 {
8601 /*
8602 * 'arabic' is reset, handle various sub-settings.
8603 */
8604 if (!p_tbidi)
8605 {
8606 /* reset rightleft mode */
8607 if (curwin->w_p_rl)
8608 {
8609 curwin->w_p_rl = FALSE;
8610 changed_window_setting();
8611 }
8612
8613 /* 'arabicshape' isn't reset, it is a global option and
8614 * another window may still need it "on". */
8615 }
8616
8617 /* 'delcombine' isn't reset, it is a global option and another
8618 * window may still want it "on". */
8619
8620# ifdef FEAT_KEYMAP
8621 /* Revert to the default keymap */
8622 curbuf->b_p_iminsert = B_IMODE_NONE;
8623 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8624# endif
8625 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008626 }
8627
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008628#endif
8629
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008630#ifdef FEAT_TERMGUICOLORS
8631 /* 'termguicolors' */
8632 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008633 {
8634# ifdef FEAT_GUI
8635 if (!gui.in_use && !gui.starting)
8636# endif
8637 highlight_gui_started();
8638 }
8639#endif
8640
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 /*
8642 * End of handling side effects for bool options.
8643 */
8644
Bram Moolenaar53744302015-07-17 17:38:22 +02008645 /* after handling side effects, call autocommand */
8646
Bram Moolenaar071d4272004-06-13 20:20:40 +00008647 options[opt_idx].flags |= P_WAS_SET;
8648
Bram Moolenaar53744302015-07-17 17:38:22 +02008649#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8650 if (!starting)
8651 {
8652 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008653 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8654 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8655 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008656 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8657 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8658 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8659 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8660 reset_v_option_vars();
8661 }
8662#endif
8663
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008665 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008666 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008667 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668 check_redraw(options[opt_idx].flags);
8669
8670 return NULL;
8671}
8672
8673/*
8674 * Set the value of a number option, and take care of side effects.
8675 * Returns NULL for success, or an error message for an error.
8676 */
8677 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008678set_num_option(
8679 int opt_idx, /* index in options[] table */
8680 char_u *varp, /* pointer to the option variable */
8681 long value, /* new value */
8682 char_u *errbuf, /* buffer for error messages */
8683 size_t errbuflen, /* length of "errbuf" */
8684 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008685 OPT_MODELINE */
8686{
8687 char_u *errmsg = NULL;
8688 long old_value = *(long *)varp;
8689 long old_Rows = Rows; /* remember old Rows */
8690 long old_Columns = Columns; /* remember old Columns */
8691 long *pp = (long *)varp;
8692
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008693 /* Disallow changing some options from secure mode. */
8694 if ((secure
8695#ifdef HAVE_SANDBOX
8696 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008698 ) && (options[opt_idx].flags & P_SECURE))
8699 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008700
8701 *pp = value;
8702#ifdef FEAT_EVAL
8703 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008704 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008706#ifdef FEAT_GUI
8707 need_mouse_correct = TRUE;
8708#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709
Bram Moolenaar14f24742012-08-08 18:01:05 +02008710 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008711 {
8712 errmsg = e_positive;
8713 curbuf->b_p_sw = curbuf->b_p_ts;
8714 }
8715
8716 /*
8717 * Number options that need some action when changed
8718 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008719 if (pp == &p_wh || pp == &p_hh)
8720 {
8721 if (p_wh < 1)
8722 {
8723 errmsg = e_positive;
8724 p_wh = 1;
8725 }
8726 if (p_wmh > p_wh)
8727 {
8728 errmsg = e_winheight;
8729 p_wh = p_wmh;
8730 }
8731 if (p_hh < 0)
8732 {
8733 errmsg = e_positive;
8734 p_hh = 0;
8735 }
8736
8737 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008738 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008739 {
8740 if (pp == &p_wh && curwin->w_height < p_wh)
8741 win_setheight((int)p_wh);
8742 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8743 win_setheight((int)p_hh);
8744 }
8745 }
8746
8747 /* 'winminheight' */
8748 else if (pp == &p_wmh)
8749 {
8750 if (p_wmh < 0)
8751 {
8752 errmsg = e_positive;
8753 p_wmh = 0;
8754 }
8755 if (p_wmh > p_wh)
8756 {
8757 errmsg = e_winheight;
8758 p_wmh = p_wh;
8759 }
8760 win_setminheight();
8761 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008762 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763 {
8764 if (p_wiw < 1)
8765 {
8766 errmsg = e_positive;
8767 p_wiw = 1;
8768 }
8769 if (p_wmw > p_wiw)
8770 {
8771 errmsg = e_winwidth;
8772 p_wiw = p_wmw;
8773 }
8774
8775 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008776 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008777 win_setwidth((int)p_wiw);
8778 }
8779
8780 /* 'winminwidth' */
8781 else if (pp == &p_wmw)
8782 {
8783 if (p_wmw < 0)
8784 {
8785 errmsg = e_positive;
8786 p_wmw = 0;
8787 }
8788 if (p_wmw > p_wiw)
8789 {
8790 errmsg = e_winwidth;
8791 p_wmw = p_wiw;
8792 }
8793 win_setminheight();
8794 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796 /* (re)set last window status line */
8797 else if (pp == &p_ls)
8798 {
8799 last_status(FALSE);
8800 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008801
8802 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008803 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008804 {
8805 shell_new_rows(); /* recompute window positions and heights */
8806 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807
8808#ifdef FEAT_GUI
8809 else if (pp == &p_linespace)
8810 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008811 /* Recompute gui.char_height and resize the Vim window to keep the
8812 * same number of lines. */
8813 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008814 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008815 }
8816#endif
8817
8818#ifdef FEAT_FOLDING
8819 /* 'foldlevel' */
8820 else if (pp == &curwin->w_p_fdl)
8821 {
8822 if (curwin->w_p_fdl < 0)
8823 curwin->w_p_fdl = 0;
8824 newFoldLevel();
8825 }
8826
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008827 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828 else if (pp == &curwin->w_p_fml)
8829 {
8830 foldUpdateAll(curwin);
8831 }
8832
8833 /* 'foldnestmax' */
8834 else if (pp == &curwin->w_p_fdn)
8835 {
8836 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8837 foldUpdateAll(curwin);
8838 }
8839
8840 /* 'foldcolumn' */
8841 else if (pp == &curwin->w_p_fdc)
8842 {
8843 if (curwin->w_p_fdc < 0)
8844 {
8845 errmsg = e_positive;
8846 curwin->w_p_fdc = 0;
8847 }
8848 else if (curwin->w_p_fdc > 12)
8849 {
8850 errmsg = e_invarg;
8851 curwin->w_p_fdc = 12;
8852 }
8853 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008854#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008856#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 /* 'shiftwidth' or 'tabstop' */
8858 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8859 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008860# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 if (foldmethodIsIndent(curwin))
8862 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008863# endif
8864# ifdef FEAT_CINDENT
8865 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8866 * parse 'cinoptions'. */
8867 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8868 parse_cino(curbuf);
8869# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008870 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008873#ifdef FEAT_MBYTE
8874 /* 'maxcombine' */
8875 else if (pp == &p_mco)
8876 {
8877 if (p_mco > MAX_MCO)
8878 p_mco = MAX_MCO;
8879 else if (p_mco < 0)
8880 p_mco = 0;
8881 screenclear(); /* will re-allocate the screen */
8882 }
8883#endif
8884
Bram Moolenaar071d4272004-06-13 20:20:40 +00008885 else if (pp == &curbuf->b_p_iminsert)
8886 {
8887 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8888 {
8889 errmsg = e_invarg;
8890 curbuf->b_p_iminsert = B_IMODE_NONE;
8891 }
8892 p_iminsert = curbuf->b_p_iminsert;
8893 if (termcap_active) /* don't do this in the alternate screen */
8894 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008895#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008896 /* Show/unshow value of 'keymap' in status lines. */
8897 status_redraw_curbuf();
8898#endif
8899 }
8900
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008901#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8902 /* 'imstyle' */
8903 else if (pp == &p_imst)
8904 {
8905 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8906 errmsg = e_invarg;
8907 }
8908#endif
8909
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008910 else if (pp == &p_window)
8911 {
8912 if (p_window < 1)
8913 p_window = 1;
8914 else if (p_window >= Rows)
8915 p_window = Rows - 1;
8916 }
8917
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918 else if (pp == &curbuf->b_p_imsearch)
8919 {
8920 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8921 {
8922 errmsg = e_invarg;
8923 curbuf->b_p_imsearch = B_IMODE_NONE;
8924 }
8925 p_imsearch = curbuf->b_p_imsearch;
8926 }
8927
8928#ifdef FEAT_TITLE
8929 /* if 'titlelen' has changed, redraw the title */
8930 else if (pp == &p_titlelen)
8931 {
8932 if (p_titlelen < 0)
8933 {
8934 errmsg = e_positive;
8935 p_titlelen = 85;
8936 }
8937 if (starting != NO_SCREEN && old_value != p_titlelen)
8938 need_maketitle = TRUE;
8939 }
8940#endif
8941
8942 /* if p_ch changed value, change the command line height */
8943 else if (pp == &p_ch)
8944 {
8945 if (p_ch < 1)
8946 {
8947 errmsg = e_positive;
8948 p_ch = 1;
8949 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008950 if (p_ch > Rows - min_rows() + 1)
8951 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952
8953 /* Only compute the new window layout when startup has been
8954 * completed. Otherwise the frame sizes may be wrong. */
8955 if (p_ch != old_value && full_screen
8956#ifdef FEAT_GUI
8957 && !gui.starting
8958#endif
8959 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008960 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008961 }
8962
8963 /* when 'updatecount' changes from zero to non-zero, open swap files */
8964 else if (pp == &p_uc)
8965 {
8966 if (p_uc < 0)
8967 {
8968 errmsg = e_positive;
8969 p_uc = 100;
8970 }
8971 if (p_uc && !old_value)
8972 ml_open_files();
8973 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008974#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008975 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008976 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008977 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008978 {
8979 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008980 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008981 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008982 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008983 {
8984 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008985 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008986 }
8987 }
8988#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008989#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008990 else if (pp == &p_mzq)
8991 mzvim_reset_timer();
8992#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008994#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8995 /* 'pyxversion' */
8996 else if (pp == &p_pyx)
8997 {
8998 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8999 errmsg = e_invarg;
9000 }
9001#endif
9002
Bram Moolenaar071d4272004-06-13 20:20:40 +00009003 /* sync undo before 'undolevels' changes */
9004 else if (pp == &p_ul)
9005 {
9006 /* use the old value, otherwise u_sync() may not work properly */
9007 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009008 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009009 p_ul = value;
9010 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009011 else if (pp == &curbuf->b_p_ul)
9012 {
9013 /* use the old value, otherwise u_sync() may not work properly */
9014 curbuf->b_p_ul = old_value;
9015 u_sync(TRUE);
9016 curbuf->b_p_ul = value;
9017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009018
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009019#ifdef FEAT_LINEBREAK
9020 /* 'numberwidth' must be positive */
9021 else if (pp == &curwin->w_p_nuw)
9022 {
9023 if (curwin->w_p_nuw < 1)
9024 {
9025 errmsg = e_positive;
9026 curwin->w_p_nuw = 1;
9027 }
9028 if (curwin->w_p_nuw > 10)
9029 {
9030 errmsg = e_invarg;
9031 curwin->w_p_nuw = 10;
9032 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009033 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009034 }
9035#endif
9036
Bram Moolenaar1a384422010-07-14 19:53:30 +02009037 else if (pp == &curbuf->b_p_tw)
9038 {
9039 if (curbuf->b_p_tw < 0)
9040 {
9041 errmsg = e_positive;
9042 curbuf->b_p_tw = 0;
9043 }
9044#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009045 {
9046 win_T *wp;
9047 tabpage_T *tp;
9048
9049 FOR_ALL_TAB_WINDOWS(tp, wp)
9050 check_colorcolumn(wp);
9051 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009052#endif
9053 }
9054
Bram Moolenaar071d4272004-06-13 20:20:40 +00009055 /*
9056 * Check the bounds for numeric options here
9057 */
9058 if (Rows < min_rows() && full_screen)
9059 {
9060 if (errbuf != NULL)
9061 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009062 vim_snprintf((char *)errbuf, errbuflen,
9063 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009064 errmsg = errbuf;
9065 }
9066 Rows = min_rows();
9067 }
9068 if (Columns < MIN_COLUMNS && full_screen)
9069 {
9070 if (errbuf != NULL)
9071 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009072 vim_snprintf((char *)errbuf, errbuflen,
9073 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074 errmsg = errbuf;
9075 }
9076 Columns = MIN_COLUMNS;
9077 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009078 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009079
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080 /*
9081 * If the screen (shell) height has been changed, assume it is the
9082 * physical screenheight.
9083 */
9084 if (old_Rows != Rows || old_Columns != Columns)
9085 {
9086 /* Changing the screen size is not allowed while updating the screen. */
9087 if (updating_screen)
9088 *pp = old_value;
9089 else if (full_screen
9090#ifdef FEAT_GUI
9091 && !gui.starting
9092#endif
9093 )
9094 set_shellsize((int)Columns, (int)Rows, TRUE);
9095 else
9096 {
9097 /* Postpone the resizing; check the size and cmdline position for
9098 * messages. */
9099 check_shellsize();
9100 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9101 cmdline_row = Rows - p_ch;
9102 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009103 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009104 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009105 }
9106
Bram Moolenaar071d4272004-06-13 20:20:40 +00009107 if (curbuf->b_p_ts <= 0)
9108 {
9109 errmsg = e_positive;
9110 curbuf->b_p_ts = 8;
9111 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112 if (p_tm < 0)
9113 {
9114 errmsg = e_positive;
9115 p_tm = 0;
9116 }
9117 if ((curwin->w_p_scr <= 0
9118 || (curwin->w_p_scr > curwin->w_height
9119 && curwin->w_height > 0))
9120 && full_screen)
9121 {
9122 if (pp == &(curwin->w_p_scr))
9123 {
9124 if (curwin->w_p_scr != 0)
9125 errmsg = e_scroll;
9126 win_comp_scroll(curwin);
9127 }
9128 /* If 'scroll' became invalid because of a side effect silently adjust
9129 * it. */
9130 else if (curwin->w_p_scr <= 0)
9131 curwin->w_p_scr = 1;
9132 else /* curwin->w_p_scr > curwin->w_height */
9133 curwin->w_p_scr = curwin->w_height;
9134 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009135 if (p_hi < 0)
9136 {
9137 errmsg = e_positive;
9138 p_hi = 0;
9139 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009140 else if (p_hi > 10000)
9141 {
9142 errmsg = e_invarg;
9143 p_hi = 10000;
9144 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009145 if (p_re < 0 || p_re > 2)
9146 {
9147 errmsg = e_invarg;
9148 p_re = 0;
9149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009150 if (p_report < 0)
9151 {
9152 errmsg = e_positive;
9153 p_report = 1;
9154 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009155 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009156 {
9157 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9158 p_sj = Rows / 2;
9159 else
9160 {
9161 errmsg = e_scroll;
9162 p_sj = 1;
9163 }
9164 }
9165 if (p_so < 0 && full_screen)
9166 {
9167 errmsg = e_scroll;
9168 p_so = 0;
9169 }
9170 if (p_siso < 0 && full_screen)
9171 {
9172 errmsg = e_positive;
9173 p_siso = 0;
9174 }
9175#ifdef FEAT_CMDWIN
9176 if (p_cwh < 1)
9177 {
9178 errmsg = e_positive;
9179 p_cwh = 1;
9180 }
9181#endif
9182 if (p_ut < 0)
9183 {
9184 errmsg = e_positive;
9185 p_ut = 2000;
9186 }
9187 if (p_ss < 0)
9188 {
9189 errmsg = e_positive;
9190 p_ss = 0;
9191 }
9192
9193 /* May set global value for local option. */
9194 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9195 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9196
9197 options[opt_idx].flags |= P_WAS_SET;
9198
Bram Moolenaar53744302015-07-17 17:38:22 +02009199#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9200 if (!starting && errmsg == NULL)
9201 {
9202 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009203 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9204 vim_snprintf((char *)buf_new, 10, "%ld", value);
9205 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009206 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9207 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9208 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9209 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9210 reset_v_option_vars();
9211 }
9212#endif
9213
Bram Moolenaar071d4272004-06-13 20:20:40 +00009214 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009215 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009216 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009217 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009218 check_redraw(options[opt_idx].flags);
9219
9220 return errmsg;
9221}
9222
9223/*
9224 * Called after an option changed: check if something needs to be redrawn.
9225 */
9226 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009227check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009228{
9229 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009230 int doclear = (flags & P_RCLR) == P_RCLR;
9231 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009232
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9234 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009235
9236 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9237 changed_window_setting();
9238 if (flags & P_RBUF)
9239 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009240 if (flags & P_RWINONLY)
9241 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009242 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243 redraw_all_later(CLEAR);
9244 else if (all)
9245 redraw_all_later(NOT_VALID);
9246}
9247
9248/*
9249 * Find index for option 'arg'.
9250 * Return -1 if not found.
9251 */
9252 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009253findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009254{
9255 int opt_idx;
9256 char *s, *p;
9257 static short quick_tab[27] = {0, 0}; /* quick access table */
9258 int is_term_opt;
9259
9260 /*
9261 * For first call: Initialize the quick-access table.
9262 * It contains the index for the first option that starts with a certain
9263 * letter. There are 26 letters, plus the first "t_" option.
9264 */
9265 if (quick_tab[1] == 0)
9266 {
9267 p = options[0].fullname;
9268 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9269 {
9270 if (s[0] != p[0])
9271 {
9272 if (s[0] == 't' && s[1] == '_')
9273 quick_tab[26] = opt_idx;
9274 else
9275 quick_tab[CharOrdLow(s[0])] = opt_idx;
9276 }
9277 p = s;
9278 }
9279 }
9280
9281 /*
9282 * Check for name starting with an illegal character.
9283 */
9284#ifdef EBCDIC
9285 if (!islower(arg[0]))
9286#else
9287 if (arg[0] < 'a' || arg[0] > 'z')
9288#endif
9289 return -1;
9290
9291 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9292 if (is_term_opt)
9293 opt_idx = quick_tab[26];
9294 else
9295 opt_idx = quick_tab[CharOrdLow(arg[0])];
9296 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9297 {
9298 if (STRCMP(arg, s) == 0) /* match full name */
9299 break;
9300 }
9301 if (s == NULL && !is_term_opt)
9302 {
9303 opt_idx = quick_tab[CharOrdLow(arg[0])];
9304 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9305 {
9306 s = options[opt_idx].shortname;
9307 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9308 break;
9309 s = NULL;
9310 }
9311 }
9312 if (s == NULL)
9313 opt_idx = -1;
9314 return opt_idx;
9315}
9316
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009317#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009318/*
9319 * Get the value for an option.
9320 *
9321 * Returns:
9322 * Number or Toggle option: 1, *numval gets value.
9323 * String option: 0, *stringval gets allocated string.
9324 * Hidden Number or Toggle option: -1.
9325 * hidden String option: -2.
9326 * unknown option: -3.
9327 */
9328 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009329get_option_value(
9330 char_u *name,
9331 long *numval,
9332 char_u **stringval, /* NULL when only checking existence */
9333 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334{
9335 int opt_idx;
9336 char_u *varp;
9337
9338 opt_idx = findoption(name);
9339 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009340 {
9341 int key;
9342
9343 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9344 && (key = find_key_option(name)) != 0)
9345 {
9346 char_u key_name[2];
9347 char_u *p;
9348
9349 if (key < 0)
9350 {
9351 key_name[0] = KEY2TERMCAP0(key);
9352 key_name[1] = KEY2TERMCAP1(key);
9353 }
9354 else
9355 {
9356 key_name[0] = KS_KEY;
9357 key_name[1] = (key & 0xff);
9358 }
9359 p = find_termcode(key_name);
9360 if (p != NULL)
9361 {
9362 if (stringval != NULL)
9363 *stringval = vim_strsave(p);
9364 return 0;
9365 }
9366 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009369
9370 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9371
9372 if (options[opt_idx].flags & P_STRING)
9373 {
9374 if (varp == NULL) /* hidden option */
9375 return -2;
9376 if (stringval != NULL)
9377 {
9378#ifdef FEAT_CRYPT
9379 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009380 if ((char_u **)varp == &curbuf->b_p_key
9381 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382 *stringval = vim_strsave((char_u *)"*****");
9383 else
9384#endif
9385 *stringval = vim_strsave(*(char_u **)(varp));
9386 }
9387 return 0;
9388 }
9389
9390 if (varp == NULL) /* hidden option */
9391 return -1;
9392 if (options[opt_idx].flags & P_NUM)
9393 *numval = *(long *)varp;
9394 else
9395 {
9396 /* Special case: 'modified' is b_changed, but we also want to consider
9397 * it set when 'ff' or 'fenc' changed. */
9398 if ((int *)varp == &curbuf->b_changed)
9399 *numval = curbufIsChanged();
9400 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009401 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009402 }
9403 return 1;
9404}
9405#endif
9406
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009407#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009408/*
9409 * Returns the option attributes and its value. Unlike the above function it
9410 * will return either global value or local value of the option depending on
9411 * what was requested, but it will never return global value if it was
9412 * requested to return local one and vice versa. Neither it will return
9413 * buffer-local value if it was requested to return window-local one.
9414 *
9415 * Pretends that option is absent if it is not present in the requested scope
9416 * (i.e. has no global, window-local or buffer-local value depending on
9417 * opt_type). Uses
9418 *
9419 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009420 * 0 hidden or unknown option, also option that does not have requested
9421 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009422 * see SOPT_* in vim.h for other flags
9423 *
9424 * Possible opt_type values: see SREQ_* in vim.h
9425 */
9426 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009427get_option_value_strict(
9428 char_u *name,
9429 long *numval,
9430 char_u **stringval, /* NULL when only obtaining attributes */
9431 int opt_type,
9432 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009433{
9434 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009435 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009436 struct vimoption *p;
9437 int r = 0;
9438
9439 opt_idx = findoption(name);
9440 if (opt_idx < 0)
9441 return 0;
9442
9443 p = &(options[opt_idx]);
9444
9445 /* Hidden option */
9446 if (p->var == NULL)
9447 return 0;
9448
9449 if (p->flags & P_BOOL)
9450 r |= SOPT_BOOL;
9451 else if (p->flags & P_NUM)
9452 r |= SOPT_NUM;
9453 else if (p->flags & P_STRING)
9454 r |= SOPT_STRING;
9455
9456 if (p->indir == PV_NONE)
9457 {
9458 if (opt_type == SREQ_GLOBAL)
9459 r |= SOPT_GLOBAL;
9460 else
9461 return 0; /* Did not request global-only option */
9462 }
9463 else
9464 {
9465 if (p->indir & PV_BOTH)
9466 r |= SOPT_GLOBAL;
9467 else if (opt_type == SREQ_GLOBAL)
9468 return 0; /* Requested global option */
9469
9470 if (p->indir & PV_WIN)
9471 {
9472 if (opt_type == SREQ_BUF)
9473 return 0; /* Did not request window-local option */
9474 else
9475 r |= SOPT_WIN;
9476 }
9477 else if (p->indir & PV_BUF)
9478 {
9479 if (opt_type == SREQ_WIN)
9480 return 0; /* Did not request buffer-local option */
9481 else
9482 r |= SOPT_BUF;
9483 }
9484 }
9485
9486 if (stringval == NULL)
9487 return r;
9488
9489 if (opt_type == SREQ_GLOBAL)
9490 varp = p->var;
9491 else
9492 {
9493 if (opt_type == SREQ_BUF)
9494 {
9495 /* Special case: 'modified' is b_changed, but we also want to
9496 * consider it set when 'ff' or 'fenc' changed. */
9497 if (p->indir == PV_MOD)
9498 {
9499 *numval = bufIsChanged((buf_T *) from);
9500 varp = NULL;
9501 }
9502#ifdef FEAT_CRYPT
9503 else if (p->indir == PV_KEY)
9504 {
9505 /* never return the value of the crypt key */
9506 *stringval = NULL;
9507 varp = NULL;
9508 }
9509#endif
9510 else
9511 {
9512 aco_save_T aco;
9513 aucmd_prepbuf(&aco, (buf_T *) from);
9514 varp = get_varp(p);
9515 aucmd_restbuf(&aco);
9516 }
9517 }
9518 else if (opt_type == SREQ_WIN)
9519 {
9520 win_T *save_curwin;
9521 save_curwin = curwin;
9522 curwin = (win_T *) from;
9523 curbuf = curwin->w_buffer;
9524 varp = get_varp(p);
9525 curwin = save_curwin;
9526 curbuf = curwin->w_buffer;
9527 }
9528 if (varp == p->var)
9529 return (r | SOPT_UNSET);
9530 }
9531
9532 if (varp != NULL)
9533 {
9534 if (p->flags & P_STRING)
9535 *stringval = vim_strsave(*(char_u **)(varp));
9536 else if (p->flags & P_NUM)
9537 *numval = *(long *) varp;
9538 else
9539 *numval = *(int *)varp;
9540 }
9541
9542 return r;
9543}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009544
9545/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009546 * Iterate over options. First argument is a pointer to a pointer to a
9547 * structure inside options[] array, second is option type like in the above
9548 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009549 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009550 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009551 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009552 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009553 * first argument to NULL.
9554 *
9555 * Returns full option name for current option on each call.
9556 */
9557 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009558option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009559{
9560 struct vimoption *ret = NULL;
9561 do
9562 {
9563 if (*option == NULL)
9564 *option = (void *) options;
9565 else if (((struct vimoption *) (*option))->fullname == NULL)
9566 {
9567 *option = NULL;
9568 return NULL;
9569 }
9570 else
9571 *option = (void *) (((struct vimoption *) (*option)) + 1);
9572
9573 ret = ((struct vimoption *) (*option));
9574
9575 /* Hidden option */
9576 if (ret->var == NULL)
9577 {
9578 ret = NULL;
9579 continue;
9580 }
9581
9582 switch (opt_type)
9583 {
9584 case SREQ_GLOBAL:
9585 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9586 ret = NULL;
9587 break;
9588 case SREQ_BUF:
9589 if (!(ret->indir & PV_BUF))
9590 ret = NULL;
9591 break;
9592 case SREQ_WIN:
9593 if (!(ret->indir & PV_WIN))
9594 ret = NULL;
9595 break;
9596 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009597 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009598 return NULL;
9599 }
9600 }
9601 while (ret == NULL);
9602
9603 return (char_u *)ret->fullname;
9604}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009605#endif
9606
Bram Moolenaar071d4272004-06-13 20:20:40 +00009607/*
9608 * Set the value of option "name".
9609 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009610 *
9611 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009612 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009613 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009614set_option_value(
9615 char_u *name,
9616 long number,
9617 char_u *string,
9618 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009619{
9620 int opt_idx;
9621 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009622 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009623
9624 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009625 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009626 {
9627 int key;
9628
9629 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9630 && (key = find_key_option(name)) != 0)
9631 {
9632 char_u key_name[2];
9633
9634 if (key < 0)
9635 {
9636 key_name[0] = KEY2TERMCAP0(key);
9637 key_name[1] = KEY2TERMCAP1(key);
9638 }
9639 else
9640 {
9641 key_name[0] = KS_KEY;
9642 key_name[1] = (key & 0xff);
9643 }
9644 add_termcode(key_name, string, FALSE);
9645 if (full_screen)
9646 ttest(FALSE);
9647 redraw_all_later(CLEAR);
9648 return NULL;
9649 }
9650
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009652 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009653 else
9654 {
9655 flags = options[opt_idx].flags;
9656#ifdef HAVE_SANDBOX
9657 /* Disallow changing some options in the sandbox */
9658 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009659 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009661 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009662 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009663#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009664 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009665 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009666 else
9667 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009668 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669 if (varp != NULL) /* hidden option is not changed */
9670 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009671 if (number == 0 && string != NULL)
9672 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009673 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009674
9675 /* Either we are given a string or we are setting option
9676 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009677 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009678 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009679 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009680 {
9681 /* There's another character after zeros or the string
9682 * is empty. In both cases, we are trying to set a
9683 * num option using a string. */
9684 EMSG3(_("E521: Number required: &%s = '%s'"),
9685 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009686 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009687
9688 }
9689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009691 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009692 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009693 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009694 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009695 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009696 }
9697 }
9698 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009699 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009700}
9701
9702/*
9703 * Get the terminal code for a terminal option.
9704 * Returns NULL when not found.
9705 */
9706 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009707get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009708{
9709 int opt_idx;
9710 char_u *varp;
9711
9712 if (tname[0] != 't' || tname[1] != '_' ||
9713 tname[2] == NUL || tname[3] == NUL)
9714 return NULL;
9715 if ((opt_idx = findoption(tname)) >= 0)
9716 {
9717 varp = get_varp(&(options[opt_idx]));
9718 if (varp != NULL)
9719 varp = *(char_u **)(varp);
9720 return varp;
9721 }
9722 return find_termcode(tname + 2);
9723}
9724
9725 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009726get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009727{
9728 int i;
9729
9730 i = findoption((char_u *)"hl");
9731 if (i >= 0)
9732 return options[i].def_val[VI_DEFAULT];
9733 return (char_u *)NULL;
9734}
9735
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009736#if defined(FEAT_MBYTE) || defined(PROTO)
9737 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009738get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009739{
9740 int i;
9741
9742 i = findoption((char_u *)"enc");
9743 if (i >= 0)
9744 return options[i].def_val[VI_DEFAULT];
9745 return (char_u *)NULL;
9746}
9747#endif
9748
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749/*
9750 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9751 */
9752 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009753find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009754{
9755 int key;
9756 int modifiers;
9757
9758 /*
9759 * Don't use get_special_key_code() for t_xx, we don't want it to call
9760 * add_termcap_entry().
9761 */
9762 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9763 key = TERMCAP2KEY(arg[2], arg[3]);
9764 else
9765 {
9766 --arg; /* put arg at the '<' */
9767 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009768 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009769 if (modifiers) /* can't handle modifiers here */
9770 key = 0;
9771 }
9772 return key;
9773}
9774
9775/*
9776 * if 'all' == 0: show changed options
9777 * if 'all' == 1: show all normal options
9778 * if 'all' == 2: show all terminal options
9779 */
9780 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009781showoptions(
9782 int all,
9783 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009784{
9785 struct vimoption *p;
9786 int col;
9787 int isterm;
9788 char_u *varp;
9789 struct vimoption **items;
9790 int item_count;
9791 int run;
9792 int row, rows;
9793 int cols;
9794 int i;
9795 int len;
9796
9797#define INC 20
9798#define GAP 3
9799
9800 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9801 PARAM_COUNT));
9802 if (items == NULL)
9803 return;
9804
9805 /* Highlight title */
9806 if (all == 2)
9807 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9808 else if (opt_flags & OPT_GLOBAL)
9809 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9810 else if (opt_flags & OPT_LOCAL)
9811 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9812 else
9813 MSG_PUTS_TITLE(_("\n--- Options ---"));
9814
9815 /*
9816 * do the loop two times:
9817 * 1. display the short items
9818 * 2. display the long items (only strings and numbers)
9819 */
9820 for (run = 1; run <= 2 && !got_int; ++run)
9821 {
9822 /*
9823 * collect the items in items[]
9824 */
9825 item_count = 0;
9826 for (p = &options[0]; p->fullname != NULL; p++)
9827 {
9828 varp = NULL;
9829 isterm = istermoption(p);
9830 if (opt_flags != 0)
9831 {
9832 if (p->indir != PV_NONE && !isterm)
9833 varp = get_varp_scope(p, opt_flags);
9834 }
9835 else
9836 varp = get_varp(p);
9837 if (varp != NULL
9838 && ((all == 2 && isterm)
9839 || (all == 1 && !isterm)
9840 || (all == 0 && !optval_default(p, varp))))
9841 {
9842 if (p->flags & P_BOOL)
9843 len = 1; /* a toggle option fits always */
9844 else
9845 {
9846 option_value2string(p, opt_flags);
9847 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9848 }
9849 if ((len <= INC - GAP && run == 1) ||
9850 (len > INC - GAP && run == 2))
9851 items[item_count++] = p;
9852 }
9853 }
9854
9855 /*
9856 * display the items
9857 */
9858 if (run == 1)
9859 {
9860 cols = (Columns + GAP - 3) / INC;
9861 if (cols == 0)
9862 cols = 1;
9863 rows = (item_count + cols - 1) / cols;
9864 }
9865 else /* run == 2 */
9866 rows = item_count;
9867 for (row = 0; row < rows && !got_int; ++row)
9868 {
9869 msg_putchar('\n'); /* go to next line */
9870 if (got_int) /* 'q' typed in more */
9871 break;
9872 col = 0;
9873 for (i = row; i < item_count; i += rows)
9874 {
9875 msg_col = col; /* make columns */
9876 showoneopt(items[i], opt_flags);
9877 col += INC;
9878 }
9879 out_flush();
9880 ui_breakcheck();
9881 }
9882 }
9883 vim_free(items);
9884}
9885
9886/*
9887 * Return TRUE if option "p" has its default value.
9888 */
9889 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009890optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009891{
9892 int dvi;
9893
9894 if (varp == NULL)
9895 return TRUE; /* hidden option is always at default */
9896 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9897 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009898 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009900 /* the cast to long is required for Manx C, long_i is
9901 * needed for MSVC */
9902 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009903 /* P_STRING */
9904 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9905}
9906
9907/*
9908 * showoneopt: show the value of one option
9909 * must not be called with a hidden option!
9910 */
9911 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009912showoneopt(
9913 struct vimoption *p,
9914 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009916 char_u *varp;
9917 int save_silent = silent_mode;
9918
9919 silent_mode = FALSE;
9920 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921
9922 varp = get_varp_scope(p, opt_flags);
9923
9924 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9925 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9926 ? !curbufIsChanged() : !*(int *)varp))
9927 MSG_PUTS("no");
9928 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9929 MSG_PUTS("--");
9930 else
9931 MSG_PUTS(" ");
9932 MSG_PUTS(p->fullname);
9933 if (!(p->flags & P_BOOL))
9934 {
9935 msg_putchar('=');
9936 /* put value string in NameBuff */
9937 option_value2string(p, opt_flags);
9938 msg_outtrans(NameBuff);
9939 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009940
9941 silent_mode = save_silent;
9942 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009943}
9944
9945/*
9946 * Write modified options as ":set" commands to a file.
9947 *
9948 * There are three values for "opt_flags":
9949 * OPT_GLOBAL: Write global option values and fresh values of
9950 * buffer-local options (used for start of a session
9951 * file).
9952 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9953 * curwin (used for a vimrc file).
9954 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9955 * and local values for window-local options of
9956 * curwin. Local values are also written when at the
9957 * default value, because a modeline or autocommand
9958 * may have set them when doing ":edit file" and the
9959 * user has set them back at the default or fresh
9960 * value.
9961 * When "local_only" is TRUE, don't write fresh
9962 * values, only local values (for ":mkview").
9963 * (fresh value = value used for a new buffer or window for a local option).
9964 *
9965 * Return FAIL on error, OK otherwise.
9966 */
9967 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009968makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009969{
9970 struct vimoption *p;
9971 char_u *varp; /* currently used value */
9972 char_u *varp_fresh; /* local value */
9973 char_u *varp_local = NULL; /* fresh value */
9974 char *cmd;
9975 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009976 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977
9978 /*
9979 * The options that don't have a default (terminal name, columns, lines)
9980 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009981 * Do the loop over "options[]" twice: once for options with the
9982 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009984 for (pri = 1; pri >= 0; --pri)
9985 {
9986 for (p = &options[0]; !istermoption(p); p++)
9987 if (!(p->flags & P_NO_MKRC)
9988 && !istermoption(p)
9989 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009990 {
9991 /* skip global option when only doing locals */
9992 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9993 continue;
9994
9995 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9996 * file, they are always buffer-specific. */
9997 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9998 continue;
9999
10000 /* Global values are only written when not at the default value. */
10001 varp = get_varp_scope(p, opt_flags);
10002 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10003 continue;
10004
10005 round = 2;
10006 if (p->indir != PV_NONE)
10007 {
10008 if (p->var == VAR_WIN)
10009 {
10010 /* skip window-local option when only doing globals */
10011 if (!(opt_flags & OPT_LOCAL))
10012 continue;
10013 /* When fresh value of window-local option is not at the
10014 * default, need to write it too. */
10015 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10016 {
10017 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10018 if (!optval_default(p, varp_fresh))
10019 {
10020 round = 1;
10021 varp_local = varp;
10022 varp = varp_fresh;
10023 }
10024 }
10025 }
10026 }
10027
10028 /* Round 1: fresh value for window-local options.
10029 * Round 2: other values */
10030 for ( ; round <= 2; varp = varp_local, ++round)
10031 {
10032 if (round == 1 || (opt_flags & OPT_GLOBAL))
10033 cmd = "set";
10034 else
10035 cmd = "setlocal";
10036
10037 if (p->flags & P_BOOL)
10038 {
10039 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10040 return FAIL;
10041 }
10042 else if (p->flags & P_NUM)
10043 {
10044 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10045 return FAIL;
10046 }
10047 else /* P_STRING */
10048 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010049#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10050 int do_endif = FALSE;
10051
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052 /* Don't set 'syntax' and 'filetype' again if the value is
10053 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010054 if (
10055# if defined(FEAT_SYN_HL)
10056 p->indir == PV_SYN
10057# if defined(FEAT_AUTOCMD)
10058 ||
10059# endif
10060# endif
10061# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010062 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010063# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010064 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010065 {
10066 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10067 *(char_u **)(varp)) < 0
10068 || put_eol(fd) < 0)
10069 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010070 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010071 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010072#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010073 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10074 (p->flags & P_EXPAND) != 0) == FAIL)
10075 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010076#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10077 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010078 {
10079 if (put_line(fd, "endif") == FAIL)
10080 return FAIL;
10081 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010082#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010083 }
10084 }
10085 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010086 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010087 return OK;
10088}
10089
10090#if defined(FEAT_FOLDING) || defined(PROTO)
10091/*
10092 * Generate set commands for the local fold options only. Used when
10093 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10094 */
10095 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010096makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010097{
10098 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10099# ifdef FEAT_EVAL
10100 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10101 == FAIL
10102# endif
10103 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10104 == FAIL
10105 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10106 == FAIL
10107 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10108 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10109 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10110 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10111 )
10112 return FAIL;
10113
10114 return OK;
10115}
10116#endif
10117
10118 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010119put_setstring(
10120 FILE *fd,
10121 char *cmd,
10122 char *name,
10123 char_u **valuep,
10124 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125{
10126 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010127 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128
10129 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10130 return FAIL;
10131 if (*valuep != NULL)
10132 {
10133 /* Output 'pastetoggle' as key names. For other
10134 * options some characters have to be escaped with
10135 * CTRL-V or backslash */
10136 if (valuep == &p_pt)
10137 {
10138 s = *valuep;
10139 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010140 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141 return FAIL;
10142 }
10143 else if (expand)
10144 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010145 buf = alloc(MAXPATHL);
10146 if (buf == NULL)
10147 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010148 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10149 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010150 {
10151 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010152 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010153 }
10154 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010155 }
10156 else if (put_escstr(fd, *valuep, 2) == FAIL)
10157 return FAIL;
10158 }
10159 if (put_eol(fd) < 0)
10160 return FAIL;
10161 return OK;
10162}
10163
10164 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010165put_setnum(
10166 FILE *fd,
10167 char *cmd,
10168 char *name,
10169 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170{
10171 long wc;
10172
10173 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10174 return FAIL;
10175 if (wc_use_keyname((char_u *)valuep, &wc))
10176 {
10177 /* print 'wildchar' and 'wildcharm' as a key name */
10178 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10179 return FAIL;
10180 }
10181 else if (fprintf(fd, "%ld", *valuep) < 0)
10182 return FAIL;
10183 if (put_eol(fd) < 0)
10184 return FAIL;
10185 return OK;
10186}
10187
10188 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010189put_setbool(
10190 FILE *fd,
10191 char *cmd,
10192 char *name,
10193 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194{
Bram Moolenaar893de922007-10-02 18:40:57 +000010195 if (value < 0) /* global/local option using global value */
10196 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10198 || put_eol(fd) < 0)
10199 return FAIL;
10200 return OK;
10201}
10202
10203/*
10204 * Clear all the terminal options.
10205 * If the option has been allocated, free the memory.
10206 * Terminal options are never hidden or indirect.
10207 */
10208 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010209clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010210{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211 /*
10212 * Reset a few things before clearing the old options. This may cause
10213 * outputting a few things that the terminal doesn't understand, but the
10214 * screen will be cleared later, so this is OK.
10215 */
10216#ifdef FEAT_MOUSE_TTY
10217 mch_setmouse(FALSE); /* switch mouse off */
10218#endif
10219#ifdef FEAT_TITLE
10220 mch_restore_title(3); /* restore window titles */
10221#endif
10222#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10223 /* When starting the GUI close the display opened for the clipboard.
10224 * After restoring the title, because that will need the display. */
10225 if (gui.starting)
10226 clear_xterm_clip();
10227#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010228 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010230 free_termoptions();
10231}
10232
10233 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010234free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010235{
10236 struct vimoption *p;
10237
Bram Moolenaar071d4272004-06-13 20:20:40 +000010238 for (p = &options[0]; p->fullname != NULL; p++)
10239 if (istermoption(p))
10240 {
10241 if (p->flags & P_ALLOCED)
10242 free_string_option(*(char_u **)(p->var));
10243 if (p->flags & P_DEF_ALLOCED)
10244 free_string_option(p->def_val[VI_DEFAULT]);
10245 *(char_u **)(p->var) = empty_option;
10246 p->def_val[VI_DEFAULT] = empty_option;
10247 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10248 }
10249 clear_termcodes();
10250}
10251
10252/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010253 * Free the string for one term option, if it was allocated.
10254 * Set the string to empty_option and clear allocated flag.
10255 * "var" points to the option value.
10256 */
10257 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010258free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010259{
10260 struct vimoption *p;
10261
10262 for (p = &options[0]; p->fullname != NULL; p++)
10263 if (p->var == var)
10264 {
10265 if (p->flags & P_ALLOCED)
10266 free_string_option(*(char_u **)(p->var));
10267 *(char_u **)(p->var) = empty_option;
10268 p->flags &= ~P_ALLOCED;
10269 break;
10270 }
10271}
10272
10273/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274 * Set the terminal option defaults to the current value.
10275 * Used after setting the terminal name.
10276 */
10277 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010278set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279{
10280 struct vimoption *p;
10281
10282 for (p = &options[0]; p->fullname != NULL; p++)
10283 {
10284 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10285 {
10286 if (p->flags & P_DEF_ALLOCED)
10287 {
10288 free_string_option(p->def_val[VI_DEFAULT]);
10289 p->flags &= ~P_DEF_ALLOCED;
10290 }
10291 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10292 if (p->flags & P_ALLOCED)
10293 {
10294 p->flags |= P_DEF_ALLOCED;
10295 p->flags &= ~P_ALLOCED; /* don't free the value now */
10296 }
10297 }
10298 }
10299}
10300
10301/*
10302 * return TRUE if 'p' starts with 't_'
10303 */
10304 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010305istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306{
10307 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10308}
10309
10310/*
10311 * Compute columns for ruler and shown command. 'sc_col' is also used to
10312 * decide what the maximum length of a message on the status line can be.
10313 * If there is a status line for the last window, 'sc_col' is independent
10314 * of 'ru_col'.
10315 */
10316
10317#define COL_RULER 17 /* columns needed by standard ruler */
10318
10319 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010320comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010322#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010323 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324
10325 sc_col = 0;
10326 ru_col = 0;
10327 if (p_ru)
10328 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010329# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010331# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010332 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010333# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334 /* no last status line, adjust sc_col */
10335 if (!last_has_status)
10336 sc_col = ru_col;
10337 }
10338 if (p_sc)
10339 {
10340 sc_col += SHOWCMD_COLS;
10341 if (!p_ru || last_has_status) /* no need for separating space */
10342 ++sc_col;
10343 }
10344 sc_col = Columns - sc_col;
10345 ru_col = Columns - ru_col;
10346 if (sc_col <= 0) /* screen too narrow, will become a mess */
10347 sc_col = 1;
10348 if (ru_col <= 0)
10349 ru_col = 1;
10350#else
10351 sc_col = Columns;
10352 ru_col = Columns;
10353#endif
10354}
10355
10356/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010357 * Unset local option value, similar to ":set opt<".
10358 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010359 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010360unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010361{
10362 struct vimoption *p;
10363 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010364 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010365
10366 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010367 if (opt_idx < 0)
10368 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010369 p = &(options[opt_idx]);
10370
10371 switch ((int)p->indir)
10372 {
10373 /* global option with local value: use local value if it's been set */
10374 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010375 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010376 break;
10377 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010378 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010379 break;
10380 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010381 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010382 break;
10383 case PV_AR:
10384 buf->b_p_ar = -1;
10385 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010386 case PV_BKC:
10387 clear_string_option(&buf->b_p_bkc);
10388 buf->b_bkc_flags = 0;
10389 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010390 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010391 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010392 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010393 case PV_TC:
10394 clear_string_option(&buf->b_p_tc);
10395 buf->b_tc_flags = 0;
10396 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010397#ifdef FEAT_FIND_ID
10398 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010399 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010400 break;
10401 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010402 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010403 break;
10404#endif
10405#ifdef FEAT_INS_EXPAND
10406 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010407 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010408 break;
10409 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010410 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010411 break;
10412#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010413 case PV_FP:
10414 clear_string_option(&buf->b_p_fp);
10415 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010416#ifdef FEAT_QUICKFIX
10417 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010418 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010419 break;
10420 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010421 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010422 break;
10423 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010424 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010425 break;
10426#endif
10427#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10428 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010429 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010430 break;
10431#endif
10432#if defined(FEAT_CRYPT)
10433 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010434 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010435 break;
10436#endif
10437#ifdef FEAT_STL_OPT
10438 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010439 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010440 break;
10441#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010442 case PV_UL:
10443 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10444 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010445#ifdef FEAT_LISP
10446 case PV_LW:
10447 clear_string_option(&buf->b_p_lw);
10448 break;
10449#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010450#ifdef FEAT_MBYTE
10451 case PV_MENC:
10452 clear_string_option(&buf->b_p_menc);
10453 break;
10454#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010455 }
10456}
10457
10458/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459 * Get pointer to option variable, depending on local or global scope.
10460 */
10461 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010462get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010463{
10464 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10465 {
10466 if (p->var == VAR_WIN)
10467 return (char_u *)GLOBAL_WO(get_varp(p));
10468 return p->var;
10469 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010470 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010471 {
10472 switch ((int)p->indir)
10473 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010474 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010476 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10477 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10478 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010479#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010480 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10481 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10482 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010483 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010484 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010485 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010487 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10488 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010489#endif
10490#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010491 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10492 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010494#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10495 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10496#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010497#if defined(FEAT_CRYPT)
10498 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10499#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010500#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010501 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010502#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010503 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010504#ifdef FEAT_LISP
10505 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10506#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010507 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010508#ifdef FEAT_MBYTE
10509 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10510#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511 }
10512 return NULL; /* "cannot happen" */
10513 }
10514 return get_varp(p);
10515}
10516
10517/*
10518 * Get pointer to option variable.
10519 */
10520 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010521get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010522{
10523 /* hidden option, always return NULL */
10524 if (p->var == NULL)
10525 return NULL;
10526
10527 switch ((int)p->indir)
10528 {
10529 case PV_NONE: return p->var;
10530
10531 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010532 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010534 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010536 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010538 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010540 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010542 case PV_TC: return *curbuf->b_p_tc != NUL
10543 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010544 case PV_BKC: return *curbuf->b_p_bkc != NUL
10545 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010546#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010547 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010549 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010550 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10551#endif
10552#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010553 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010555 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10557#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010558 case PV_FP: return *curbuf->b_p_fp != NUL
10559 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010561 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010563 case PV_GP: return *curbuf->b_p_gp != NUL
10564 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10565 case PV_MP: return *curbuf->b_p_mp != NUL
10566 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010568#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10569 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10570 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10571#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010572#if defined(FEAT_CRYPT)
10573 case PV_CM: return *curbuf->b_p_cm != NUL
10574 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10575#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010576#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010577 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010578 ? (char_u *)&(curwin->w_p_stl) : p->var;
10579#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010580 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10581 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010582#ifdef FEAT_LISP
10583 case PV_LW: return *curbuf->b_p_lw != NUL
10584 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10585#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010586#ifdef FEAT_MBYTE
10587 case PV_MENC: return *curbuf->b_p_menc != NUL
10588 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10589#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590
10591#ifdef FEAT_ARABIC
10592 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10593#endif
10594 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010595#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010596 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10597#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010598#ifdef FEAT_SYN_HL
10599 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10600 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010601 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010602#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603#ifdef FEAT_DIFF
10604 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10605#endif
10606#ifdef FEAT_FOLDING
10607 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10608 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10609 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10610 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10611 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10612 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10613 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10614# ifdef FEAT_EVAL
10615 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10616 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10617# endif
10618 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10619#endif
10620 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010621 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010622#ifdef FEAT_LINEBREAK
10623 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10624#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010626 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010627#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10629#endif
10630#ifdef FEAT_RIGHTLEFT
10631 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10632 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10633#endif
10634 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10635 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10636#ifdef FEAT_LINEBREAK
10637 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010638 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10639 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010640#endif
10641#ifdef FEAT_SCROLLBIND
10642 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10643#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010644#ifdef FEAT_CURSORBIND
10645 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10646#endif
10647#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010648 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10649 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10650#endif
10651#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010652 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010653 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010654#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655
10656 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10657 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10658#ifdef FEAT_MBYTE
10659 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10660#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010661 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10662 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010663 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10664 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10665#ifdef FEAT_CINDENT
10666 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10667 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10668 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10669#endif
10670#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10671 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10672#endif
10673#ifdef FEAT_COMMENTS
10674 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10675#endif
10676#ifdef FEAT_FOLDING
10677 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10678#endif
10679#ifdef FEAT_INS_EXPAND
10680 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10681#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010682#ifdef FEAT_COMPL_FUNC
10683 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010684 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010685#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010687 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10689#ifdef FEAT_MBYTE
10690 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10691#endif
10692 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10693#ifdef FEAT_AUTOCMD
10694 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10695#endif
10696 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010697 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010698 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10699 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10700 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10701 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10702#ifdef FEAT_FIND_ID
10703# ifdef FEAT_EVAL
10704 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10705# endif
10706#endif
10707#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10708 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10709 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10710#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010711#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010712 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010714#ifdef FEAT_CRYPT
10715 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10716#endif
10717#ifdef FEAT_LISP
10718 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10719#endif
10720 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10721 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10722 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10723 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10724 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010725 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010726#ifdef FEAT_TEXTOBJ
10727 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10730#ifdef FEAT_SMARTINDENT
10731 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10732#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010733 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10735#ifdef FEAT_SEARCHPATH
10736 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10737#endif
10738 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10739#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010740 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010741 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10742#endif
10743#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010744 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10745 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10746 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010747#endif
10748 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10749 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10750 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10751 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010752#ifdef FEAT_PERSISTENT_UNDO
10753 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10756#ifdef FEAT_KEYMAP
10757 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10758#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010759#ifdef FEAT_SIGNS
10760 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10761#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010762 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763 }
10764 /* always return a valid pointer to avoid a crash! */
10765 return (char_u *)&(curbuf->b_p_wm);
10766}
10767
10768/*
10769 * Get the value of 'equalprg', either the buffer-local one or the global one.
10770 */
10771 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010772get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773{
10774 if (*curbuf->b_p_ep == NUL)
10775 return p_ep;
10776 return curbuf->b_p_ep;
10777}
10778
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779/*
10780 * Copy options from one window to another.
10781 * Used when splitting a window.
10782 */
10783 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010784win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785{
10786 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10787 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10788# ifdef FEAT_RIGHTLEFT
10789# ifdef FEAT_FKMAP
10790 /* Is this right? */
10791 wp_to->w_farsi = wp_from->w_farsi;
10792# endif
10793# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010794#if defined(FEAT_LINEBREAK)
10795 briopt_check(wp_to);
10796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798
10799/*
10800 * Copy the options from one winopt_T to another.
10801 * Doesn't free the old option values in "to", use clear_winopt() for that.
10802 * The 'scroll' option is not copied, because it depends on the window height.
10803 * The 'previewwindow' option is reset, there can be only one preview window.
10804 */
10805 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010806copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807{
10808#ifdef FEAT_ARABIC
10809 to->wo_arab = from->wo_arab;
10810#endif
10811 to->wo_list = from->wo_list;
10812 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010813 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010814#ifdef FEAT_LINEBREAK
10815 to->wo_nuw = from->wo_nuw;
10816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817#ifdef FEAT_RIGHTLEFT
10818 to->wo_rl = from->wo_rl;
10819 to->wo_rlc = vim_strsave(from->wo_rlc);
10820#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010821#ifdef FEAT_STL_OPT
10822 to->wo_stl = vim_strsave(from->wo_stl);
10823#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010824 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010825#ifdef FEAT_DIFF
10826 to->wo_wrap_save = from->wo_wrap_save;
10827#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828#ifdef FEAT_LINEBREAK
10829 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010830 to->wo_bri = from->wo_bri;
10831 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832#endif
10833#ifdef FEAT_SCROLLBIND
10834 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010835 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010836#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010837#ifdef FEAT_CURSORBIND
10838 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010839 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010840#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010841#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010842 to->wo_spell = from->wo_spell;
10843#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010844#ifdef FEAT_SYN_HL
10845 to->wo_cuc = from->wo_cuc;
10846 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010847 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010848#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849#ifdef FEAT_DIFF
10850 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010851 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010853#ifdef FEAT_CONCEAL
10854 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010855 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010856#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010857#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010858 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010859 to->wo_tms = vim_strsave(from->wo_tms);
10860#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010861#ifdef FEAT_FOLDING
10862 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010863 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010865 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866 to->wo_fdi = vim_strsave(from->wo_fdi);
10867 to->wo_fml = from->wo_fml;
10868 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010869 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010871 to->wo_fdm_save = from->wo_diff_saved
10872 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010873 to->wo_fdn = from->wo_fdn;
10874# ifdef FEAT_EVAL
10875 to->wo_fde = vim_strsave(from->wo_fde);
10876 to->wo_fdt = vim_strsave(from->wo_fdt);
10877# endif
10878 to->wo_fmr = vim_strsave(from->wo_fmr);
10879#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010880#ifdef FEAT_SIGNS
10881 to->wo_scl = vim_strsave(from->wo_scl);
10882#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883 check_winopt(to); /* don't want NULL pointers */
10884}
10885
10886/*
10887 * Check string options in a window for a NULL value.
10888 */
10889 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010890check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891{
10892 check_winopt(&win->w_onebuf_opt);
10893 check_winopt(&win->w_allbuf_opt);
10894}
10895
10896/*
10897 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10898 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010899 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010900check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901{
10902#ifdef FEAT_FOLDING
10903 check_string_option(&wop->wo_fdi);
10904 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010905 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010906# ifdef FEAT_EVAL
10907 check_string_option(&wop->wo_fde);
10908 check_string_option(&wop->wo_fdt);
10909# endif
10910 check_string_option(&wop->wo_fmr);
10911#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010912#ifdef FEAT_SIGNS
10913 check_string_option(&wop->wo_scl);
10914#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010915#ifdef FEAT_RIGHTLEFT
10916 check_string_option(&wop->wo_rlc);
10917#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010918#ifdef FEAT_STL_OPT
10919 check_string_option(&wop->wo_stl);
10920#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010921#ifdef FEAT_SYN_HL
10922 check_string_option(&wop->wo_cc);
10923#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010924#ifdef FEAT_CONCEAL
10925 check_string_option(&wop->wo_cocu);
10926#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010927#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010928 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010929 check_string_option(&wop->wo_tms);
10930#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010931#ifdef FEAT_LINEBREAK
10932 check_string_option(&wop->wo_briopt);
10933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010934}
10935
10936/*
10937 * Free the allocated memory inside a winopt_T.
10938 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010940clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941{
10942#ifdef FEAT_FOLDING
10943 clear_string_option(&wop->wo_fdi);
10944 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010945 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010946# ifdef FEAT_EVAL
10947 clear_string_option(&wop->wo_fde);
10948 clear_string_option(&wop->wo_fdt);
10949# endif
10950 clear_string_option(&wop->wo_fmr);
10951#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010952#ifdef FEAT_SIGNS
10953 clear_string_option(&wop->wo_scl);
10954#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010955#ifdef FEAT_LINEBREAK
10956 clear_string_option(&wop->wo_briopt);
10957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010958#ifdef FEAT_RIGHTLEFT
10959 clear_string_option(&wop->wo_rlc);
10960#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010961#ifdef FEAT_STL_OPT
10962 clear_string_option(&wop->wo_stl);
10963#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010964#ifdef FEAT_SYN_HL
10965 clear_string_option(&wop->wo_cc);
10966#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010967#ifdef FEAT_CONCEAL
10968 clear_string_option(&wop->wo_cocu);
10969#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010970#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010971 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010972 clear_string_option(&wop->wo_tms);
10973#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010974}
10975
10976/*
10977 * Copy global option values to local options for one buffer.
10978 * Used when creating a new buffer and sometimes when entering a buffer.
10979 * flags:
10980 * BCO_ENTER We will enter the buf buffer.
10981 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10982 * appropriate.
10983 * BCO_NOHELP Don't copy the values to a help buffer.
10984 */
10985 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010986buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010987{
10988 int should_copy = TRUE;
10989 char_u *save_p_isk = NULL; /* init for GCC */
10990 int dont_do_help;
10991 int did_isk = FALSE;
10992
10993 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994 * Skip this when the option defaults have not been set yet. Happens when
10995 * main() allocates the first buffer.
10996 */
10997 if (p_cpo != NULL)
10998 {
10999 /*
11000 * Always copy when entering and 'cpo' contains 'S'.
11001 * Don't copy when already initialized.
11002 * Don't copy when 'cpo' contains 's' and not entering.
11003 * 'S' BCO_ENTER initialized 's' should_copy
11004 * yes yes X X TRUE
11005 * yes no yes X FALSE
11006 * no X yes X FALSE
11007 * X no no yes FALSE
11008 * X no no no TRUE
11009 * no yes no X TRUE
11010 */
11011 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11012 && (buf->b_p_initialized
11013 || (!(flags & BCO_ENTER)
11014 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11015 should_copy = FALSE;
11016
11017 if (should_copy || (flags & BCO_ALWAYS))
11018 {
11019 /* Don't copy the options specific to a help buffer when
11020 * BCO_NOHELP is given or the options were initialized already
11021 * (jumping back to a help file with CTRL-T or CTRL-O) */
11022 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11023 || buf->b_p_initialized;
11024 if (dont_do_help) /* don't free b_p_isk */
11025 {
11026 save_p_isk = buf->b_p_isk;
11027 buf->b_p_isk = NULL;
11028 }
11029 /*
11030 * Always free the allocated strings.
11031 * If not already initialized, set 'readonly' and copy 'fileformat'.
11032 */
11033 if (!buf->b_p_initialized)
11034 {
11035 free_buf_options(buf, TRUE);
11036 buf->b_p_ro = FALSE; /* don't copy readonly */
11037 buf->b_p_tx = p_tx;
11038#ifdef FEAT_MBYTE
11039 buf->b_p_fenc = vim_strsave(p_fenc);
11040#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011041 switch (*p_ffs)
11042 {
11043 case 'm':
11044 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11045 case 'd':
11046 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11047 case 'u':
11048 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11049 default:
11050 buf->b_p_ff = vim_strsave(p_ff);
11051 }
11052 if (buf->b_p_ff != NULL)
11053 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054 buf->b_p_bh = empty_option;
11055 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011056 }
11057 else
11058 free_buf_options(buf, FALSE);
11059
11060 buf->b_p_ai = p_ai;
11061 buf->b_p_ai_nopaste = p_ai_nopaste;
11062 buf->b_p_sw = p_sw;
11063 buf->b_p_tw = p_tw;
11064 buf->b_p_tw_nopaste = p_tw_nopaste;
11065 buf->b_p_tw_nobin = p_tw_nobin;
11066 buf->b_p_wm = p_wm;
11067 buf->b_p_wm_nopaste = p_wm_nopaste;
11068 buf->b_p_wm_nobin = p_wm_nobin;
11069 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011070#ifdef FEAT_MBYTE
11071 buf->b_p_bomb = p_bomb;
11072#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011073 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074 buf->b_p_et = p_et;
11075 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011076 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077 buf->b_p_ml = p_ml;
11078 buf->b_p_ml_nobin = p_ml_nobin;
11079 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011080 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011081#ifdef FEAT_INS_EXPAND
11082 buf->b_p_cpt = vim_strsave(p_cpt);
11083#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011084#ifdef FEAT_COMPL_FUNC
11085 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011086 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011087#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011088 buf->b_p_sts = p_sts;
11089 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011090 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091#ifdef FEAT_COMMENTS
11092 buf->b_p_com = vim_strsave(p_com);
11093#endif
11094#ifdef FEAT_FOLDING
11095 buf->b_p_cms = vim_strsave(p_cms);
11096#endif
11097 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011098 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099 buf->b_p_nf = vim_strsave(p_nf);
11100 buf->b_p_mps = vim_strsave(p_mps);
11101#ifdef FEAT_SMARTINDENT
11102 buf->b_p_si = p_si;
11103#endif
11104 buf->b_p_ci = p_ci;
11105#ifdef FEAT_CINDENT
11106 buf->b_p_cin = p_cin;
11107 buf->b_p_cink = vim_strsave(p_cink);
11108 buf->b_p_cino = vim_strsave(p_cino);
11109#endif
11110#ifdef FEAT_AUTOCMD
11111 /* Don't copy 'filetype', it must be detected */
11112 buf->b_p_ft = empty_option;
11113#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114 buf->b_p_pi = p_pi;
11115#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11116 buf->b_p_cinw = vim_strsave(p_cinw);
11117#endif
11118#ifdef FEAT_LISP
11119 buf->b_p_lisp = p_lisp;
11120#endif
11121#ifdef FEAT_SYN_HL
11122 /* Don't copy 'syntax', it must be set */
11123 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011124 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011125 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011126#endif
11127#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011128 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011129 (void)compile_cap_prog(&buf->b_s);
11130 buf->b_s.b_p_spf = vim_strsave(p_spf);
11131 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132#endif
11133#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11134 buf->b_p_inde = vim_strsave(p_inde);
11135 buf->b_p_indk = vim_strsave(p_indk);
11136#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011137 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011138#if defined(FEAT_EVAL)
11139 buf->b_p_fex = vim_strsave(p_fex);
11140#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011141#ifdef FEAT_CRYPT
11142 buf->b_p_key = vim_strsave(p_key);
11143#endif
11144#ifdef FEAT_SEARCHPATH
11145 buf->b_p_sua = vim_strsave(p_sua);
11146#endif
11147#ifdef FEAT_KEYMAP
11148 buf->b_p_keymap = vim_strsave(p_keymap);
11149 buf->b_kmap_state |= KEYMAP_INIT;
11150#endif
11151 /* This isn't really an option, but copying the langmap and IME
11152 * state from the current buffer is better than resetting it. */
11153 buf->b_p_iminsert = p_iminsert;
11154 buf->b_p_imsearch = p_imsearch;
11155
11156 /* options that are normally global but also have a local value
11157 * are not copied, start using the global value */
11158 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011159 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011160 buf->b_p_bkc = empty_option;
11161 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011162#ifdef FEAT_QUICKFIX
11163 buf->b_p_gp = empty_option;
11164 buf->b_p_mp = empty_option;
11165 buf->b_p_efm = empty_option;
11166#endif
11167 buf->b_p_ep = empty_option;
11168 buf->b_p_kp = empty_option;
11169 buf->b_p_path = empty_option;
11170 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011171 buf->b_p_tc = empty_option;
11172 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173#ifdef FEAT_FIND_ID
11174 buf->b_p_def = empty_option;
11175 buf->b_p_inc = empty_option;
11176# ifdef FEAT_EVAL
11177 buf->b_p_inex = vim_strsave(p_inex);
11178# endif
11179#endif
11180#ifdef FEAT_INS_EXPAND
11181 buf->b_p_dict = empty_option;
11182 buf->b_p_tsr = empty_option;
11183#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011184#ifdef FEAT_TEXTOBJ
11185 buf->b_p_qe = vim_strsave(p_qe);
11186#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011187#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11188 buf->b_p_bexpr = empty_option;
11189#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011190#if defined(FEAT_CRYPT)
11191 buf->b_p_cm = empty_option;
11192#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011193#ifdef FEAT_PERSISTENT_UNDO
11194 buf->b_p_udf = p_udf;
11195#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011196#ifdef FEAT_LISP
11197 buf->b_p_lw = empty_option;
11198#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011199#ifdef FEAT_MBYTE
11200 buf->b_p_menc = empty_option;
11201#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202
11203 /*
11204 * Don't copy the options set by ex_help(), use the saved values,
11205 * when going from a help buffer to a non-help buffer.
11206 * Don't touch these at all when BCO_NOHELP is used and going from
11207 * or to a help buffer.
11208 */
11209 if (dont_do_help)
11210 buf->b_p_isk = save_p_isk;
11211 else
11212 {
11213 buf->b_p_isk = vim_strsave(p_isk);
11214 did_isk = TRUE;
11215 buf->b_p_ts = p_ts;
11216 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217 if (buf->b_p_bt[0] == 'h')
11218 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011219 buf->b_p_ma = p_ma;
11220 }
11221 }
11222
11223 /*
11224 * When the options should be copied (ignoring BCO_ALWAYS), set the
11225 * flag that indicates that the options have been initialized.
11226 */
11227 if (should_copy)
11228 buf->b_p_initialized = TRUE;
11229 }
11230
11231 check_buf_options(buf); /* make sure we don't have NULLs */
11232 if (did_isk)
11233 (void)buf_init_chartab(buf, FALSE);
11234}
11235
11236/*
11237 * Reset the 'modifiable' option and its default value.
11238 */
11239 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011240reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011241{
11242 int opt_idx;
11243
11244 curbuf->b_p_ma = FALSE;
11245 p_ma = FALSE;
11246 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011247 if (opt_idx >= 0)
11248 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011249}
11250
11251/*
11252 * Set the global value for 'iminsert' to the local value.
11253 */
11254 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011255set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011256{
11257 p_iminsert = curbuf->b_p_iminsert;
11258}
11259
11260/*
11261 * Set the global value for 'imsearch' to the local value.
11262 */
11263 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011264set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011265{
11266 p_imsearch = curbuf->b_p_imsearch;
11267}
11268
11269#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11270static int expand_option_idx = -1;
11271static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11272static int expand_option_flags = 0;
11273
11274 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011275set_context_in_set_cmd(
11276 expand_T *xp,
11277 char_u *arg,
11278 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011279{
11280 int nextchar;
11281 long_u flags = 0; /* init for GCC */
11282 int opt_idx = 0; /* init for GCC */
11283 char_u *p;
11284 char_u *s;
11285 int is_term_option = FALSE;
11286 int key;
11287
11288 expand_option_flags = opt_flags;
11289
11290 xp->xp_context = EXPAND_SETTINGS;
11291 if (*arg == NUL)
11292 {
11293 xp->xp_pattern = arg;
11294 return;
11295 }
11296 p = arg + STRLEN(arg) - 1;
11297 if (*p == ' ' && *(p - 1) != '\\')
11298 {
11299 xp->xp_pattern = p + 1;
11300 return;
11301 }
11302 while (p > arg)
11303 {
11304 s = p;
11305 /* count number of backslashes before ' ' or ',' */
11306 if (*p == ' ' || *p == ',')
11307 {
11308 while (s > arg && *(s - 1) == '\\')
11309 --s;
11310 }
11311 /* break at a space with an even number of backslashes */
11312 if (*p == ' ' && ((p - s) & 1) == 0)
11313 {
11314 ++p;
11315 break;
11316 }
11317 --p;
11318 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011319 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011320 {
11321 xp->xp_context = EXPAND_BOOL_SETTINGS;
11322 p += 2;
11323 }
11324 if (STRNCMP(p, "inv", 3) == 0)
11325 {
11326 xp->xp_context = EXPAND_BOOL_SETTINGS;
11327 p += 3;
11328 }
11329 xp->xp_pattern = arg = p;
11330 if (*arg == '<')
11331 {
11332 while (*p != '>')
11333 if (*p++ == NUL) /* expand terminal option name */
11334 return;
11335 key = get_special_key_code(arg + 1);
11336 if (key == 0) /* unknown name */
11337 {
11338 xp->xp_context = EXPAND_NOTHING;
11339 return;
11340 }
11341 nextchar = *++p;
11342 is_term_option = TRUE;
11343 expand_option_name[2] = KEY2TERMCAP0(key);
11344 expand_option_name[3] = KEY2TERMCAP1(key);
11345 }
11346 else
11347 {
11348 if (p[0] == 't' && p[1] == '_')
11349 {
11350 p += 2;
11351 if (*p != NUL)
11352 ++p;
11353 if (*p == NUL)
11354 return; /* expand option name */
11355 nextchar = *++p;
11356 is_term_option = TRUE;
11357 expand_option_name[2] = p[-2];
11358 expand_option_name[3] = p[-1];
11359 }
11360 else
11361 {
11362 /* Allow * wildcard */
11363 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11364 p++;
11365 if (*p == NUL)
11366 return;
11367 nextchar = *p;
11368 *p = NUL;
11369 opt_idx = findoption(arg);
11370 *p = nextchar;
11371 if (opt_idx == -1 || options[opt_idx].var == NULL)
11372 {
11373 xp->xp_context = EXPAND_NOTHING;
11374 return;
11375 }
11376 flags = options[opt_idx].flags;
11377 if (flags & P_BOOL)
11378 {
11379 xp->xp_context = EXPAND_NOTHING;
11380 return;
11381 }
11382 }
11383 }
11384 /* handle "-=" and "+=" */
11385 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11386 {
11387 ++p;
11388 nextchar = '=';
11389 }
11390 if ((nextchar != '=' && nextchar != ':')
11391 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11392 {
11393 xp->xp_context = EXPAND_UNSUCCESSFUL;
11394 return;
11395 }
11396 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11397 {
11398 xp->xp_context = EXPAND_OLD_SETTING;
11399 if (is_term_option)
11400 expand_option_idx = -1;
11401 else
11402 expand_option_idx = opt_idx;
11403 xp->xp_pattern = p + 1;
11404 return;
11405 }
11406 xp->xp_context = EXPAND_NOTHING;
11407 if (is_term_option || (flags & P_NUM))
11408 return;
11409
11410 xp->xp_pattern = p + 1;
11411
11412 if (flags & P_EXPAND)
11413 {
11414 p = options[opt_idx].var;
11415 if (p == (char_u *)&p_bdir
11416 || p == (char_u *)&p_dir
11417 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011418 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419 || p == (char_u *)&p_rtp
11420#ifdef FEAT_SEARCHPATH
11421 || p == (char_u *)&p_cdpath
11422#endif
11423#ifdef FEAT_SESSION
11424 || p == (char_u *)&p_vdir
11425#endif
11426 )
11427 {
11428 xp->xp_context = EXPAND_DIRECTORIES;
11429 if (p == (char_u *)&p_path
11430#ifdef FEAT_SEARCHPATH
11431 || p == (char_u *)&p_cdpath
11432#endif
11433 )
11434 xp->xp_backslash = XP_BS_THREE;
11435 else
11436 xp->xp_backslash = XP_BS_ONE;
11437 }
11438 else
11439 {
11440 xp->xp_context = EXPAND_FILES;
11441 /* for 'tags' need three backslashes for a space */
11442 if (p == (char_u *)&p_tags)
11443 xp->xp_backslash = XP_BS_THREE;
11444 else
11445 xp->xp_backslash = XP_BS_ONE;
11446 }
11447 }
11448
11449 /* For an option that is a list of file names, find the start of the
11450 * last file name. */
11451 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11452 {
11453 /* count number of backslashes before ' ' or ',' */
11454 if (*p == ' ' || *p == ',')
11455 {
11456 s = p;
11457 while (s > xp->xp_pattern && *(s - 1) == '\\')
11458 --s;
11459 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11460 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11461 {
11462 xp->xp_pattern = p + 1;
11463 break;
11464 }
11465 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011466
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011467#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011468 /* for 'spellsuggest' start at "file:" */
11469 if (options[opt_idx].var == (char_u *)&p_sps
11470 && STRNCMP(p, "file:", 5) == 0)
11471 {
11472 xp->xp_pattern = p + 5;
11473 break;
11474 }
11475#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011476 }
11477
11478 return;
11479}
11480
11481 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011482ExpandSettings(
11483 expand_T *xp,
11484 regmatch_T *regmatch,
11485 int *num_file,
11486 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011487{
11488 int num_normal = 0; /* Nr of matching non-term-code settings */
11489 int num_term = 0; /* Nr of matching terminal code settings */
11490 int opt_idx;
11491 int match;
11492 int count = 0;
11493 char_u *str;
11494 int loop;
11495 int is_term_opt;
11496 char_u name_buf[MAX_KEY_NAME_LEN];
11497 static char *(names[]) = {"all", "termcap"};
11498 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11499
11500 /* do this loop twice:
11501 * loop == 0: count the number of matching options
11502 * loop == 1: copy the matching options into allocated memory
11503 */
11504 for (loop = 0; loop <= 1; ++loop)
11505 {
11506 regmatch->rm_ic = ic;
11507 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11508 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011509 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11510 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011511 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11512 {
11513 if (loop == 0)
11514 num_normal++;
11515 else
11516 (*file)[count++] = vim_strsave((char_u *)names[match]);
11517 }
11518 }
11519 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11520 opt_idx++)
11521 {
11522 if (options[opt_idx].var == NULL)
11523 continue;
11524 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11525 && !(options[opt_idx].flags & P_BOOL))
11526 continue;
11527 is_term_opt = istermoption(&options[opt_idx]);
11528 if (is_term_opt && num_normal > 0)
11529 continue;
11530 match = FALSE;
11531 if (vim_regexec(regmatch, str, (colnr_T)0)
11532 || (options[opt_idx].shortname != NULL
11533 && vim_regexec(regmatch,
11534 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11535 match = TRUE;
11536 else if (is_term_opt)
11537 {
11538 name_buf[0] = '<';
11539 name_buf[1] = 't';
11540 name_buf[2] = '_';
11541 name_buf[3] = str[2];
11542 name_buf[4] = str[3];
11543 name_buf[5] = '>';
11544 name_buf[6] = NUL;
11545 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11546 {
11547 match = TRUE;
11548 str = name_buf;
11549 }
11550 }
11551 if (match)
11552 {
11553 if (loop == 0)
11554 {
11555 if (is_term_opt)
11556 num_term++;
11557 else
11558 num_normal++;
11559 }
11560 else
11561 (*file)[count++] = vim_strsave(str);
11562 }
11563 }
11564 /*
11565 * Check terminal key codes, these are not in the option table
11566 */
11567 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11568 {
11569 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11570 {
11571 if (!isprint(str[0]) || !isprint(str[1]))
11572 continue;
11573
11574 name_buf[0] = 't';
11575 name_buf[1] = '_';
11576 name_buf[2] = str[0];
11577 name_buf[3] = str[1];
11578 name_buf[4] = NUL;
11579
11580 match = FALSE;
11581 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11582 match = TRUE;
11583 else
11584 {
11585 name_buf[0] = '<';
11586 name_buf[1] = 't';
11587 name_buf[2] = '_';
11588 name_buf[3] = str[0];
11589 name_buf[4] = str[1];
11590 name_buf[5] = '>';
11591 name_buf[6] = NUL;
11592
11593 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11594 match = TRUE;
11595 }
11596 if (match)
11597 {
11598 if (loop == 0)
11599 num_term++;
11600 else
11601 (*file)[count++] = vim_strsave(name_buf);
11602 }
11603 }
11604
11605 /*
11606 * Check special key names.
11607 */
11608 regmatch->rm_ic = TRUE; /* ignore case here */
11609 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11610 {
11611 name_buf[0] = '<';
11612 STRCPY(name_buf + 1, str);
11613 STRCAT(name_buf, ">");
11614
11615 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11616 {
11617 if (loop == 0)
11618 num_term++;
11619 else
11620 (*file)[count++] = vim_strsave(name_buf);
11621 }
11622 }
11623 }
11624 if (loop == 0)
11625 {
11626 if (num_normal > 0)
11627 *num_file = num_normal;
11628 else if (num_term > 0)
11629 *num_file = num_term;
11630 else
11631 return OK;
11632 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11633 if (*file == NULL)
11634 {
11635 *file = (char_u **)"";
11636 return FAIL;
11637 }
11638 }
11639 }
11640 return OK;
11641}
11642
11643 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011644ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011645{
11646 char_u *var = NULL; /* init for GCC */
11647 char_u *buf;
11648
11649 *num_file = 0;
11650 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11651 if (*file == NULL)
11652 return FAIL;
11653
11654 /*
11655 * For a terminal key code expand_option_idx is < 0.
11656 */
11657 if (expand_option_idx < 0)
11658 {
11659 var = find_termcode(expand_option_name + 2);
11660 if (var == NULL)
11661 expand_option_idx = findoption(expand_option_name);
11662 }
11663
11664 if (expand_option_idx >= 0)
11665 {
11666 /* put string of option value in NameBuff */
11667 option_value2string(&options[expand_option_idx], expand_option_flags);
11668 var = NameBuff;
11669 }
11670 else if (var == NULL)
11671 var = (char_u *)"";
11672
11673 /* A backslash is required before some characters. This is the reverse of
11674 * what happens in do_set(). */
11675 buf = vim_strsave_escaped(var, escape_chars);
11676
11677 if (buf == NULL)
11678 {
11679 vim_free(*file);
11680 *file = NULL;
11681 return FAIL;
11682 }
11683
11684#ifdef BACKSLASH_IN_FILENAME
11685 /* For MS-Windows et al. we don't double backslashes at the start and
11686 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011687 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011688 if (var[0] == '\\' && var[1] == '\\'
11689 && expand_option_idx >= 0
11690 && (options[expand_option_idx].flags & P_EXPAND)
11691 && vim_isfilec(var[2])
11692 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011693 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011694#endif
11695
11696 *file[0] = buf;
11697 *num_file = 1;
11698 return OK;
11699}
11700#endif
11701
11702/*
11703 * Get the value for the numeric or string option *opp in a nice format into
11704 * NameBuff[]. Must not be called with a hidden option!
11705 */
11706 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011707option_value2string(
11708 struct vimoption *opp,
11709 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011710{
11711 char_u *varp;
11712
11713 varp = get_varp_scope(opp, opt_flags);
11714
11715 if (opp->flags & P_NUM)
11716 {
11717 long wc = 0;
11718
11719 if (wc_use_keyname(varp, &wc))
11720 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11721 else if (wc != 0)
11722 STRCPY(NameBuff, transchar((int)wc));
11723 else
11724 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11725 }
11726 else /* P_STRING */
11727 {
11728 varp = *(char_u **)(varp);
11729 if (varp == NULL) /* just in case */
11730 NameBuff[0] = NUL;
11731#ifdef FEAT_CRYPT
11732 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011733 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011734 STRCPY(NameBuff, "*****");
11735#endif
11736 else if (opp->flags & P_EXPAND)
11737 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11738 /* Translate 'pastetoggle' into special key names */
11739 else if ((char_u **)opp->var == &p_pt)
11740 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11741 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011742 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011743 }
11744}
11745
11746/*
11747 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11748 * printed as a keyname.
11749 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11750 */
11751 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011752wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011753{
11754 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11755 {
11756 *wcp = *(long *)varp;
11757 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11758 return TRUE;
11759 }
11760 return FALSE;
11761}
11762
Bram Moolenaar01615492015-02-03 13:00:38 +010011763#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011764/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011765 * Any character has an equivalent 'langmap' character. This is used for
11766 * keyboards that have a special language mode that sends characters above
11767 * 128 (although other characters can be translated too). The "to" field is a
11768 * Vim command character. This avoids having to switch the keyboard back to
11769 * ASCII mode when leaving Insert mode.
11770 *
11771 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11772 * commands.
11773 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11774 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11775 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011777# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011778/*
11779 * With multi-byte support use growarray for 'langmap' chars >= 256
11780 */
11781typedef struct
11782{
11783 int from;
11784 int to;
11785} langmap_entry_T;
11786
11787static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011788static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011789
11790/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011791 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11792 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011793 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011794 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011795langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011796{
11797 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011798 int a = 0;
11799 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011800
11801 /* Do a binary search for an existing entry. */
11802 while (a != b)
11803 {
11804 int i = (a + b) / 2;
11805 int d = entries[i].from - from;
11806
11807 if (d == 0)
11808 {
11809 entries[i].to = to;
11810 return;
11811 }
11812 if (d < 0)
11813 a = i + 1;
11814 else
11815 b = i;
11816 }
11817
11818 if (ga_grow(&langmap_mapga, 1) != OK)
11819 return; /* out of memory */
11820
11821 /* insert new entry at position "a" */
11822 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11823 mch_memmove(entries + 1, entries,
11824 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11825 ++langmap_mapga.ga_len;
11826 entries[0].from = from;
11827 entries[0].to = to;
11828}
11829
11830/*
11831 * Apply 'langmap' to multi-byte character "c" and return the result.
11832 */
11833 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011834langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011835{
11836 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11837 int a = 0;
11838 int b = langmap_mapga.ga_len;
11839
11840 while (a != b)
11841 {
11842 int i = (a + b) / 2;
11843 int d = entries[i].from - c;
11844
11845 if (d == 0)
11846 return entries[i].to; /* found matching entry */
11847 if (d < 0)
11848 a = i + 1;
11849 else
11850 b = i;
11851 }
11852 return c; /* no entry found, return "c" unmodified */
11853}
11854# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855
11856 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011857langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011858{
11859 int i;
11860
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011861 for (i = 0; i < 256; i++)
11862 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11863# ifdef FEAT_MBYTE
11864 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11865# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011866}
11867
11868/*
11869 * Called when langmap option is set; the language map can be
11870 * changed at any time!
11871 */
11872 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011873langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011874{
11875 char_u *p;
11876 char_u *p2;
11877 int from, to;
11878
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011879#ifdef FEAT_MBYTE
11880 ga_clear(&langmap_mapga); /* clear the previous map first */
11881#endif
11882 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883
11884 for (p = p_langmap; p[0] != NUL; )
11885 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011886 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011887 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011888 {
11889 if (p2[0] == '\\' && p2[1] != NUL)
11890 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011891 }
11892 if (p2[0] == ';')
11893 ++p2; /* abcd;ABCD form, p2 points to A */
11894 else
11895 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11896 while (p[0])
11897 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011898 if (p[0] == ',')
11899 {
11900 ++p;
11901 break;
11902 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011903 if (p[0] == '\\' && p[1] != NUL)
11904 ++p;
11905#ifdef FEAT_MBYTE
11906 from = (*mb_ptr2char)(p);
11907#else
11908 from = p[0];
11909#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011910 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011911 if (p2 == NULL)
11912 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011913 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011914 if (p[0] != ',')
11915 {
11916 if (p[0] == '\\')
11917 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011918#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011919 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011920#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011921 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011922#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011923 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011924 }
11925 else
11926 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011927 if (p2[0] != ',')
11928 {
11929 if (p2[0] == '\\')
11930 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011931#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011932 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011934 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011935#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011936 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011937 }
11938 if (to == NUL)
11939 {
11940 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11941 transchar(from));
11942 return;
11943 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011944
11945#ifdef FEAT_MBYTE
11946 if (from >= 256)
11947 langmap_set_entry(from, to);
11948 else
11949#endif
11950 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951
11952 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011953 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011954 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011956 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011957 if (*p == ';')
11958 {
11959 p = p2;
11960 if (p[0] != NUL)
11961 {
11962 if (p[0] != ',')
11963 {
11964 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11965 return;
11966 }
11967 ++p;
11968 }
11969 break;
11970 }
11971 }
11972 }
11973 }
11974}
11975#endif
11976
11977/*
11978 * Return TRUE if format option 'x' is in effect.
11979 * Take care of no formatting when 'paste' is set.
11980 */
11981 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011982has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983{
11984 if (p_paste)
11985 return FALSE;
11986 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11987}
11988
11989/*
11990 * Return TRUE if "x" is present in 'shortmess' option, or
11991 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11992 */
11993 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011994shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011995{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011996 return p_shm != NULL &&
11997 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011998 || (vim_strchr(p_shm, 'a') != NULL
11999 && vim_strchr((char_u *)SHM_A, x) != NULL));
12000}
12001
12002/*
12003 * paste_option_changed() - Called after p_paste was set or reset.
12004 */
12005 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012006paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012007{
12008 static int old_p_paste = FALSE;
12009 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012010 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012011#ifdef FEAT_CMDL_INFO
12012 static int save_ru = 0;
12013#endif
12014#ifdef FEAT_RIGHTLEFT
12015 static int save_ri = 0;
12016 static int save_hkmap = 0;
12017#endif
12018 buf_T *buf;
12019
12020 if (p_paste)
12021 {
12022 /*
12023 * Paste switched from off to on.
12024 * Save the current values, so they can be restored later.
12025 */
12026 if (!old_p_paste)
12027 {
12028 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012029 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012030 {
12031 buf->b_p_tw_nopaste = buf->b_p_tw;
12032 buf->b_p_wm_nopaste = buf->b_p_wm;
12033 buf->b_p_sts_nopaste = buf->b_p_sts;
12034 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012035 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036 }
12037
12038 /* save global options */
12039 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012040 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012041#ifdef FEAT_CMDL_INFO
12042 save_ru = p_ru;
12043#endif
12044#ifdef FEAT_RIGHTLEFT
12045 save_ri = p_ri;
12046 save_hkmap = p_hkmap;
12047#endif
12048 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012049 p_ai_nopaste = p_ai;
12050 p_et_nopaste = p_et;
12051 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012052 p_tw_nopaste = p_tw;
12053 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012054 }
12055
12056 /*
12057 * Always set the option values, also when 'paste' is set when it is
12058 * already on.
12059 */
12060 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012061 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012062 {
12063 buf->b_p_tw = 0; /* textwidth is 0 */
12064 buf->b_p_wm = 0; /* wrapmargin is 0 */
12065 buf->b_p_sts = 0; /* softtabstop is 0 */
12066 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012067 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068 }
12069
12070 /* set global options */
12071 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012072 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012073#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012074 if (p_ru)
12075 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012076 p_ru = 0; /* no ruler */
12077#endif
12078#ifdef FEAT_RIGHTLEFT
12079 p_ri = 0; /* no reverse insert */
12080 p_hkmap = 0; /* no Hebrew keyboard */
12081#endif
12082 /* set global values for local buffer options */
12083 p_tw = 0;
12084 p_wm = 0;
12085 p_sts = 0;
12086 p_ai = 0;
12087 }
12088
12089 /*
12090 * Paste switched from on to off: Restore saved values.
12091 */
12092 else if (old_p_paste)
12093 {
12094 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012095 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012096 {
12097 buf->b_p_tw = buf->b_p_tw_nopaste;
12098 buf->b_p_wm = buf->b_p_wm_nopaste;
12099 buf->b_p_sts = buf->b_p_sts_nopaste;
12100 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012101 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012102 }
12103
12104 /* restore global options */
12105 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012106 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012107#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108 if (p_ru != save_ru)
12109 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012110 p_ru = save_ru;
12111#endif
12112#ifdef FEAT_RIGHTLEFT
12113 p_ri = save_ri;
12114 p_hkmap = save_hkmap;
12115#endif
12116 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012117 p_ai = p_ai_nopaste;
12118 p_et = p_et_nopaste;
12119 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120 p_tw = p_tw_nopaste;
12121 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012122 }
12123
12124 old_p_paste = p_paste;
12125}
12126
12127/*
12128 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12129 *
12130 * Reset 'compatible' and set the values for options that didn't get set yet
12131 * to the Vim defaults.
12132 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012133 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012134 */
12135 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012136vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012137{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012138 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012139 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012140 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141
12142 if (!option_was_set((char_u *)"cp"))
12143 {
12144 p_cp = FALSE;
12145 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12146 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12147 set_option_default(opt_idx, OPT_FREE, FALSE);
12148 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012149 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012150 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012151
12152 if (fname != NULL)
12153 {
12154 p = vim_getenv(envname, &dofree);
12155 if (p == NULL)
12156 {
12157 /* Set $MYVIMRC to the first vimrc file found. */
12158 p = FullName_save(fname, FALSE);
12159 if (p != NULL)
12160 {
12161 vim_setenv(envname, p);
12162 vim_free(p);
12163 }
12164 }
12165 else if (dofree)
12166 vim_free(p);
12167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168}
12169
12170/*
12171 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12172 */
12173 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012174change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012176 int opt_idx;
12177
Bram Moolenaar071d4272004-06-13 20:20:40 +000012178 if (p_cp != on)
12179 {
12180 p_cp = on;
12181 compatible_set();
12182 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012183 opt_idx = findoption((char_u *)"cp");
12184 if (opt_idx >= 0)
12185 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186}
12187
12188/*
12189 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012190 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012191 */
12192 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012193option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012194{
12195 int idx;
12196
12197 idx = findoption(name);
12198 if (idx < 0) /* unknown option */
12199 return FALSE;
12200 if (options[idx].flags & P_WAS_SET)
12201 return TRUE;
12202 return FALSE;
12203}
12204
12205/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012206 * Reset the flag indicating option "name" was set.
12207 */
12208 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012209reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012210{
12211 int idx = findoption(name);
12212
12213 if (idx >= 0)
12214 options[idx].flags &= ~P_WAS_SET;
12215}
12216
12217/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012218 * compatible_set() - Called when 'compatible' has been set or unset.
12219 *
12220 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12221 * flag) to a Vi compatible value.
12222 * When 'compatible' is unset: Set all options that have a different default
12223 * for Vim (without the P_VI_DEF flag) to that default.
12224 */
12225 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012226compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012227{
12228 int opt_idx;
12229
12230 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12231 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12232 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12233 set_option_default(opt_idx, OPT_FREE, p_cp);
12234 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012235 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236}
12237
12238#ifdef FEAT_LINEBREAK
12239
12240# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12241 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012242 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012243# endif
12244
12245/*
12246 * fill_breakat_flags() -- called when 'breakat' changes value.
12247 */
12248 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012249fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012250{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012251 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012252 int i;
12253
12254 for (i = 0; i < 256; i++)
12255 breakat_flags[i] = FALSE;
12256
12257 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012258 for (p = p_breakat; *p; p++)
12259 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012260}
12261
12262# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012263 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012264# endif
12265
12266#endif
12267
12268/*
12269 * Check an option that can be a range of string values.
12270 *
12271 * Return OK for correct value, FAIL otherwise.
12272 * Empty is always OK.
12273 */
12274 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012275check_opt_strings(
12276 char_u *val,
12277 char **values,
12278 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012279{
12280 return opt_strings_flags(val, values, NULL, list);
12281}
12282
12283/*
12284 * Handle an option that can be a range of string values.
12285 * Set a flag in "*flagp" for each string present.
12286 *
12287 * Return OK for correct value, FAIL otherwise.
12288 * Empty is always OK.
12289 */
12290 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012291opt_strings_flags(
12292 char_u *val, /* new value */
12293 char **values, /* array of valid string values */
12294 unsigned *flagp,
12295 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012296{
12297 int i;
12298 int len;
12299 unsigned new_flags = 0;
12300
12301 while (*val)
12302 {
12303 for (i = 0; ; ++i)
12304 {
12305 if (values[i] == NULL) /* val not found in values[] */
12306 return FAIL;
12307
12308 len = (int)STRLEN(values[i]);
12309 if (STRNCMP(values[i], val, len) == 0
12310 && ((list && val[len] == ',') || val[len] == NUL))
12311 {
12312 val += len + (val[len] == ',');
12313 new_flags |= (1 << i);
12314 break; /* check next item in val list */
12315 }
12316 }
12317 }
12318 if (flagp != NULL)
12319 *flagp = new_flags;
12320
12321 return OK;
12322}
12323
12324/*
12325 * Read the 'wildmode' option, fill wim_flags[].
12326 */
12327 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012328check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012329{
12330 char_u new_wim_flags[4];
12331 char_u *p;
12332 int i;
12333 int idx = 0;
12334
12335 for (i = 0; i < 4; ++i)
12336 new_wim_flags[i] = 0;
12337
12338 for (p = p_wim; *p; ++p)
12339 {
12340 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12341 ;
12342 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12343 return FAIL;
12344 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12345 new_wim_flags[idx] |= WIM_LONGEST;
12346 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12347 new_wim_flags[idx] |= WIM_FULL;
12348 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12349 new_wim_flags[idx] |= WIM_LIST;
12350 else
12351 return FAIL;
12352 p += i;
12353 if (*p == NUL)
12354 break;
12355 if (*p == ',')
12356 {
12357 if (idx == 3)
12358 return FAIL;
12359 ++idx;
12360 }
12361 }
12362
12363 /* fill remaining entries with last flag */
12364 while (idx < 3)
12365 {
12366 new_wim_flags[idx + 1] = new_wim_flags[idx];
12367 ++idx;
12368 }
12369
12370 /* only when there are no errors, wim_flags[] is changed */
12371 for (i = 0; i < 4; ++i)
12372 wim_flags[i] = new_wim_flags[i];
12373 return OK;
12374}
12375
12376/*
12377 * Check if backspacing over something is allowed.
12378 */
12379 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012380can_bs(
12381 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012382{
12383 switch (*p_bs)
12384 {
12385 case '2': return TRUE;
12386 case '1': return (what != BS_START);
12387 case '0': return FALSE;
12388 }
12389 return vim_strchr(p_bs, what) != NULL;
12390}
12391
12392/*
12393 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12394 * the file must be considered changed when the value is different.
12395 */
12396 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012397save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012398{
12399 buf->b_start_ffc = *buf->b_p_ff;
12400 buf->b_start_eol = buf->b_p_eol;
12401#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012402 buf->b_start_bomb = buf->b_p_bomb;
12403
Bram Moolenaar071d4272004-06-13 20:20:40 +000012404 /* Only use free/alloc when necessary, they take time. */
12405 if (buf->b_start_fenc == NULL
12406 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12407 {
12408 vim_free(buf->b_start_fenc);
12409 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12410 }
12411#endif
12412}
12413
12414/*
12415 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12416 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012417 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12418 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012419 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012420 * When "ignore_empty" is true don't consider a new, empty buffer to be
12421 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422 */
12423 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012424file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012425{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012426 /* In a buffer that was never loaded the options are not valid. */
12427 if (buf->b_flags & BF_NEVERLOADED)
12428 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012429 if (ignore_empty
12430 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012431 && buf->b_ml.ml_line_count == 1
12432 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12433 return FALSE;
12434 if (buf->b_start_ffc != *buf->b_p_ff)
12435 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012436 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012437 return TRUE;
12438#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012439 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12440 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012441 if (buf->b_start_fenc == NULL)
12442 return (*buf->b_p_fenc != NUL);
12443 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12444#else
12445 return FALSE;
12446#endif
12447}
12448
12449/*
12450 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12451 */
12452 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012453check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012454{
12455 return check_opt_strings(p, p_ff_values, FALSE);
12456}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012457
12458/*
12459 * Return the effective shiftwidth value for current buffer, using the
12460 * 'tabstop' value when 'shiftwidth' is zero.
12461 */
12462 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012463get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012464{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012465 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012466}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012467
12468/*
12469 * Return the effective softtabstop value for the current buffer, using the
12470 * 'tabstop' value when 'softtabstop' is negative.
12471 */
12472 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012473get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012474{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012475 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012476}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012477
12478/*
12479 * Check matchpairs option for "*initc".
12480 * If there is a match set "*initc" to the matching character and "*findc" to
12481 * the opposite character. Set "*backwards" to the direction.
12482 * When "switchit" is TRUE swap the direction.
12483 */
12484 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012485find_mps_values(
12486 int *initc,
12487 int *findc,
12488 int *backwards,
12489 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012490{
12491 char_u *ptr;
12492
12493 ptr = curbuf->b_p_mps;
12494 while (*ptr != NUL)
12495 {
12496#ifdef FEAT_MBYTE
12497 if (has_mbyte)
12498 {
12499 char_u *prev;
12500
12501 if (mb_ptr2char(ptr) == *initc)
12502 {
12503 if (switchit)
12504 {
12505 *findc = *initc;
12506 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12507 *backwards = TRUE;
12508 }
12509 else
12510 {
12511 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12512 *backwards = FALSE;
12513 }
12514 return;
12515 }
12516 prev = ptr;
12517 ptr += mb_ptr2len(ptr) + 1;
12518 if (mb_ptr2char(ptr) == *initc)
12519 {
12520 if (switchit)
12521 {
12522 *findc = *initc;
12523 *initc = mb_ptr2char(prev);
12524 *backwards = FALSE;
12525 }
12526 else
12527 {
12528 *findc = mb_ptr2char(prev);
12529 *backwards = TRUE;
12530 }
12531 return;
12532 }
12533 ptr += mb_ptr2len(ptr);
12534 }
12535 else
12536#endif
12537 {
12538 if (*ptr == *initc)
12539 {
12540 if (switchit)
12541 {
12542 *backwards = TRUE;
12543 *findc = *initc;
12544 *initc = ptr[2];
12545 }
12546 else
12547 {
12548 *backwards = FALSE;
12549 *findc = ptr[2];
12550 }
12551 return;
12552 }
12553 ptr += 2;
12554 if (*ptr == *initc)
12555 {
12556 if (switchit)
12557 {
12558 *backwards = FALSE;
12559 *findc = *initc;
12560 *initc = ptr[-2];
12561 }
12562 else
12563 {
12564 *backwards = TRUE;
12565 *findc = ptr[-2];
12566 }
12567 return;
12568 }
12569 ++ptr;
12570 }
12571 if (*ptr == ',')
12572 ++ptr;
12573 }
12574}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012575
12576#if defined(FEAT_LINEBREAK) || defined(PROTO)
12577/*
12578 * This is called when 'breakindentopt' is changed and when a window is
12579 * initialized.
12580 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012581 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012582briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012583{
12584 char_u *p;
12585 int bri_shift = 0;
12586 long bri_min = 20;
12587 int bri_sbr = FALSE;
12588
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012589 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012590 while (*p != NUL)
12591 {
12592 if (STRNCMP(p, "shift:", 6) == 0
12593 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12594 {
12595 p += 6;
12596 bri_shift = getdigits(&p);
12597 }
12598 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12599 {
12600 p += 4;
12601 bri_min = getdigits(&p);
12602 }
12603 else if (STRNCMP(p, "sbr", 3) == 0)
12604 {
12605 p += 3;
12606 bri_sbr = TRUE;
12607 }
12608 if (*p != ',' && *p != NUL)
12609 return FAIL;
12610 if (*p == ',')
12611 ++p;
12612 }
12613
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012614 wp->w_p_brishift = bri_shift;
12615 wp->w_p_brimin = bri_min;
12616 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012617
12618 return OK;
12619}
12620#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012621
12622/*
12623 * Get the local or global value of 'backupcopy'.
12624 */
12625 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012626get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012627{
12628 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12629}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012630
12631#if defined(FEAT_SIGNS) || defined(PROTO)
12632/*
12633 * Return TRUE when window "wp" has a column to draw signs in.
12634 */
12635 int
12636signcolumn_on(win_T *wp)
12637{
12638 if (*wp->w_p_scl == 'n')
12639 return FALSE;
12640 if (*wp->w_p_scl == 'y')
12641 return TRUE;
12642 return (wp->w_buffer->b_signlist != NULL
12643# ifdef FEAT_NETBEANS_INTG
12644 || wp->w_buffer->b_has_sign_column
12645# endif
12646 );
12647}
12648#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012649
12650#if defined(FEAT_EVAL) || defined(PROTO)
12651/*
12652 * Get window or buffer local options.
12653 */
12654 dict_T *
12655get_winbuf_options(int bufopt)
12656{
12657 dict_T *d;
12658 int opt_idx;
12659
12660 d = dict_alloc();
12661 if (d == NULL)
12662 return NULL;
12663
12664 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12665 {
12666 struct vimoption *opt = &options[opt_idx];
12667
12668 if ((bufopt && (opt->indir & PV_BUF))
12669 || (!bufopt && (opt->indir & PV_WIN)))
12670 {
12671 char_u *varp = get_varp(opt);
12672
12673 if (varp != NULL)
12674 {
12675 if (opt->flags & P_STRING)
12676 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012677 else if (opt->flags & P_NUM)
12678 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012679 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012680 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012681 }
12682 }
12683 }
12684
12685 return d;
12686}
12687#endif