blob: ac0918dacc2a438e0fd2bbca004667eefbed9cbd [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200225#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#ifdef FEAT_CURSORBIND
252# define PV_CRBIND OPT_WIN(WV_CRBIND)
253#endif
254#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200255# define PV_COCU OPT_WIN(WV_COCU)
256# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200257#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200258#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200259# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260# define PV_TMS OPT_WIN(WV_TMS)
261#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200262#ifdef FEAT_SIGNS
263# define PV_SCL OPT_WIN(WV_SCL)
264#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000265
266/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267typedef enum
268{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000269 PV_NONE = 0,
270 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271} idopt_T;
272
273/*
274 * Options local to a window have a value local to a buffer and global to all
275 * buffers. Indicate this by setting "var" to VAR_WIN.
276 */
277#define VAR_WIN ((char_u *)-1)
278
279/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000280 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281 * Only to be used in option.c!
282 */
283static int p_ai;
284static int p_bin;
285#ifdef FEAT_MBYTE
286static int p_bomb;
287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288static char_u *p_bh;
289static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static int p_bl;
291static int p_ci;
292#ifdef FEAT_CINDENT
293static int p_cin;
294static char_u *p_cink;
295static char_u *p_cino;
296#endif
297#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
298static char_u *p_cinw;
299#endif
300#ifdef FEAT_COMMENTS
301static char_u *p_com;
302#endif
303#ifdef FEAT_FOLDING
304static char_u *p_cms;
305#endif
306#ifdef FEAT_INS_EXPAND
307static char_u *p_cpt;
308#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#ifdef FEAT_COMPL_FUNC
310static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000311static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
316#ifdef FEAT_MBYTE
317static char_u *p_fenc;
318#endif
319static char_u *p_ff;
320static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000321static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322#ifdef FEAT_AUTOCMD
323static char_u *p_ft;
324#endif
325static long p_iminsert;
326static long p_imsearch;
327#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
328static char_u *p_inex;
329#endif
330#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
331static char_u *p_inde;
332static char_u *p_indk;
333#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000334#if defined(FEAT_EVAL)
335static char_u *p_fex;
336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_inf;
338static char_u *p_isk;
339#ifdef FEAT_CRYPT
340static char_u *p_key;
341#endif
342#ifdef FEAT_LISP
343static int p_lisp;
344#endif
345static int p_ml;
346static int p_ma;
347static int p_mod;
348static char_u *p_mps;
349static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000351#ifdef FEAT_TEXTOBJ
352static char_u *p_qe;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_ro;
355#ifdef FEAT_SMARTINDENT
356static int p_si;
357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static long p_sts;
360#if defined(FEAT_SEARCHPATH)
361static char_u *p_sua;
362#endif
363static long p_sw;
364static int p_swf;
365#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000366static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000368#endif
369#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000370static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000371static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000372static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373#endif
374static long p_ts;
375static long p_tw;
376static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200377#ifdef FEAT_PERSISTENT_UNDO
378static int p_udf;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380static long p_wm;
381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
384
385/* Saved values for when 'bin' is set. */
386static int p_et_nobin;
387static int p_ml_nobin;
388static long p_tw_nobin;
389static long p_wm_nobin;
390
391/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200392static int p_ai_nopaste;
393static int p_et_nopaste;
394static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395static long p_tw_nopaste;
396static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398struct vimoption
399{
400 char *fullname; /* full option name */
401 char *shortname; /* permissible abbreviation */
402 long_u flags; /* see below */
403 char_u *var; /* global option: pointer to variable;
404 * window-local option: VAR_WIN;
405 * buffer-local option: global value */
406 idopt_T indir; /* global option: PV_NONE;
407 * local option: indirect option index */
408 char_u *def_val[2]; /* default values for variable (vi and vim) */
409#ifdef FEAT_EVAL
410 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411# define SCRIPTID_INIT , 0
412#else
413# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#endif
415};
416
417#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
418#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
419
420/*
421 * Flags
422 */
423#define P_BOOL 0x01 /* the option is boolean */
424#define P_NUM 0x02 /* the option is numeric */
425#define P_STRING 0x04 /* the option is a string */
426#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000427 must use free_string_option() when
428 assigning new value. Not set if default is
429 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
431 never be used for local or hidden options! */
432#define P_NODEFAULT 0x40 /* don't set to default value */
433#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
434 use vim_free() when assigning new value */
435#define P_WAS_SET 0x100 /* option has been set/reset */
436#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
437#define P_VI_DEF 0x400 /* Use Vi default for Vim */
438#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
439
440 /* when option changed, what to display: */
441#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100442#define P_RWIN 0x2000 /* redraw current window and recompute text */
443#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444#define P_RALL 0x6000 /* redraw all windows */
445#define P_RCLR 0x7000 /* clear and redraw all */
446
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200447#define P_COMMA 0x8000 /* comma separated list */
448#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
449 * commas */
450#define P_NODUP 0x20000L /* don't allow duplicate strings */
451#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
454#define P_GETTEXT 0x100000L /* expand default value with _() */
455#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
456#define P_NFNAME 0x400000L /* only normal file name chars allowed */
457#define P_INSECURE 0x800000L /* option was set from a modeline */
458#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_NO_ML 0x2000000L /* not allowed in modeline */
461#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200462 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100464#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000466#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000468/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100470#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000471# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000472#else
473# define ISP_LATIN1 (char_u *)"@,161-255"
474#endif
475
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200476# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000477
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100478/* Default python version for pyx* commands */
479#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
480# define DEFAULT_PYTHON_VER 0
481#elif defined(FEAT_PYTHON3)
482# define DEFAULT_PYTHON_VER 3
483#elif defined(FEAT_PYTHON)
484# define DEFAULT_PYTHON_VER 2
485#else
486# define DEFAULT_PYTHON_VER 0
487#endif
488
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489/*
490 * options[] is initialized here.
491 * The order of the options MUST be alphabetic for ":set all" and findoption().
492 * All option names MUST start with a lowercase letter (for findoption()).
493 * Exception: "t_" options are at the end.
494 * The options with a NULL variable are 'hidden': a set command for them is
495 * ignored and they are not printed.
496 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100497static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200499 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500#ifdef FEAT_RIGHTLEFT
501 (char_u *)&p_aleph, PV_NONE,
502#else
503 (char_u *)NULL, PV_NONE,
504#endif
505 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100506#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507 (char_u *)128L,
508#else
509 (char_u *)224L,
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200513#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (char_u *)&p_antialias, PV_NONE,
515 {(char_u *)FALSE, (char_u *)FALSE}
516#else
517 (char_u *)NULL, PV_NONE,
518 {(char_u *)FALSE, (char_u *)FALSE}
519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000520 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200521 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522#ifdef FEAT_ARABIC
523 (char_u *)VAR_WIN, PV_ARAB,
524#else
525 (char_u *)NULL, PV_NONE,
526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000527 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
529#ifdef FEAT_ARABIC
530 (char_u *)&p_arshape, PV_NONE,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000534 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
536#ifdef FEAT_RIGHTLEFT
537 (char_u *)&p_ari, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
543#ifdef FEAT_FKMAP
544 (char_u *)&p_altkeymap, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
550#if defined(FEAT_MBYTE)
551 (char_u *)&p_ambw, PV_NONE,
552 {(char_u *)"single", (char_u *)0L}
553#else
554 (char_u *)NULL, PV_NONE,
555 {(char_u *)0L, (char_u *)0L}
556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100559#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100561 {(char_u *)FALSE, (char_u *)0L}
562#else
563 (char_u *)NULL, PV_NONE,
564 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autoindent", "ai", P_BOOL|P_VI_DEF,
568 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autoprint", "ap", P_BOOL|P_VI_DEF,
571 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000574 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"autowrite", "aw", P_BOOL|P_VI_DEF,
577 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"autowriteall","awa", P_BOOL|P_VI_DEF,
580 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
583 (char_u *)&p_bg, PV_NONE,
584 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100585#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)"dark",
587#else
588 (char_u *)"light",
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
595 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200598 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599#ifdef UNIX
600 {(char_u *)"yes", (char_u *)"auto"}
601#else
602 {(char_u *)"auto", (char_u *)"auto"}
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200605 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
606 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000609 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610 (char_u *)&p_bex, PV_NONE,
611 {
612#ifdef VMS
613 (char_u *)"_",
614#else
615 (char_u *)"~",
616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200618 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_WILDIGN
620 (char_u *)&p_bsk, PV_NONE,
621 {(char_u *)"", (char_u *)0L}
622#else
623 (char_u *)NULL, PV_NONE,
624 {(char_u *)0L, (char_u *)0L}
625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 {(char_u *)600L, (char_u *)0L}
631#else
632 (char_u *)NULL, PV_NONE,
633 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635 SCRIPTID_INIT},
636 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100637#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100638 (char_u *)&p_beval, PV_NONE,
639 {(char_u *)FALSE, (char_u *)0L}
640#else
641 (char_u *)NULL, PV_NONE,
642 {(char_u *)0L, (char_u *)0L}
643#endif
644 SCRIPTID_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100645 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100646#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100647 (char_u *)&p_bevalterm, PV_NONE,
648 {(char_u *)FALSE, (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
653 SCRIPTID_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100654 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
655#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
656 (char_u *)&p_bexpr, PV_BEXPR,
657 {(char_u *)"", (char_u *)0L}
658#else
659 (char_u *)NULL, PV_NONE,
660 {(char_u *)0L, (char_u *)0L}
661#endif
662 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"beautify", "bf", P_BOOL|P_VI_DEF,
664 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200666 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
667 (char_u *)&p_bo, PV_NONE,
668 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
670 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000671 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000674 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
676#ifdef FEAT_MBYTE
677 (char_u *)&p_bomb, PV_BOMB,
678#else
679 (char_u *)NULL, PV_NONE,
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
683#ifdef FEAT_LINEBREAK
684 (char_u *)&p_breakat, PV_NONE,
685 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200691 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
692#ifdef FEAT_LINEBREAK
693 (char_u *)VAR_WIN, PV_BRI,
694 {(char_u *)FALSE, (char_u *)0L}
695#else
696 (char_u *)NULL, PV_NONE,
697 {(char_u *)0L, (char_u *)0L}
698#endif
699 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200700 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
701 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200702#ifdef FEAT_LINEBREAK
703 (char_u *)VAR_WIN, PV_BRIOPT,
704 {(char_u *)"", (char_u *)NULL}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)"", (char_u *)NULL}
708#endif
709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
711#ifdef FEAT_BROWSE
712 (char_u *)&p_bsdir, PV_NONE,
713 {(char_u *)"last", (char_u *)0L}
714#else
715 (char_u *)NULL, PV_NONE,
716 {(char_u *)0L, (char_u *)0L}
717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 (char_u *)&p_bh, PV_BH,
721 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
724 (char_u *)&p_bl, PV_BL,
725 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 (char_u *)&p_bt, PV_BT,
729 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200731 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000732#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733 (char_u *)&p_cmp, PV_NONE,
734 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
741#ifdef FEAT_SEARCHPATH
742 (char_u *)&p_cdpath, PV_NONE,
743 {(char_u *)",,", (char_u *)0L}
744#else
745 (char_u *)NULL, PV_NONE,
746 {(char_u *)0L, (char_u *)0L}
747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 {"cedit", NULL, P_STRING,
750#ifdef FEAT_CMDWIN
751 (char_u *)&p_cedit, PV_NONE,
752 {(char_u *)"", (char_u *)CTRL_F_STR}
753#else
754 (char_u *)NULL, PV_NONE,
755 {(char_u *)0L, (char_u *)0L}
756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000757 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
759#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
760 (char_u *)&p_ccv, PV_NONE,
761 {(char_u *)"", (char_u *)0L}
762#else
763 (char_u *)NULL, PV_NONE,
764 {(char_u *)0L, (char_u *)0L}
765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
768#ifdef FEAT_CINDENT
769 (char_u *)&p_cin, PV_CIN,
770#else
771 (char_u *)NULL, PV_NONE,
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775#ifdef FEAT_CINDENT
776 (char_u *)&p_cink, PV_CINK,
777 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
778#else
779 (char_u *)NULL, PV_NONE,
780 {(char_u *)0L, (char_u *)0L}
781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000782 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200783 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#ifdef FEAT_CINDENT
785 (char_u *)&p_cino, PV_CINO,
786#else
787 (char_u *)NULL, PV_NONE,
788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200790 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
792 (char_u *)&p_cinw, PV_CINW,
793 {(char_u *)"if,else,while,do,for,switch",
794 (char_u *)0L}
795#else
796 (char_u *)NULL, PV_NONE,
797 {(char_u *)0L, (char_u *)0L}
798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000799 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200800 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801#ifdef FEAT_CLIPBOARD
802 (char_u *)&p_cb, PV_NONE,
803# ifdef FEAT_XCLIPBOARD
804 {(char_u *)"autoselect,exclude:cons\\|linux",
805 (char_u *)0L}
806# else
807 {(char_u *)"", (char_u *)0L}
808# endif
809#else
810 (char_u *)NULL, PV_NONE,
811 {(char_u *)"", (char_u *)0L}
812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000813 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
815 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000816 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000817 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
818#ifdef FEAT_CMDWIN
819 (char_u *)&p_cwh, PV_NONE,
820#else
821 (char_u *)NULL, PV_NONE,
822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000823 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200824 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200825#ifdef FEAT_SYN_HL
826 (char_u *)VAR_WIN, PV_CC,
827#else
828 (char_u *)NULL, PV_NONE,
829#endif
830 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
832 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000833 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200834 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
835 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836#ifdef FEAT_COMMENTS
837 (char_u *)&p_com, PV_COM,
838 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
839 (char_u *)0L}
840#else
841 (char_u *)NULL, PV_NONE,
842 {(char_u *)0L, (char_u *)0L}
843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000844 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200845 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846#ifdef FEAT_FOLDING
847 (char_u *)&p_cms, PV_CMS,
848 {(char_u *)"/*%s*/", (char_u *)0L}
849#else
850 (char_u *)NULL, PV_NONE,
851 {(char_u *)0L, (char_u *)0L}
852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000853 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000854 /* P_PRI_MKRC isn't needed here, optval_default()
855 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000856 {"compatible", "cp", P_BOOL|P_RALL,
857 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200859 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000860#ifdef FEAT_INS_EXPAND
861 (char_u *)&p_cpt, PV_CPT,
862 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
863#else
864 (char_u *)NULL, PV_NONE,
865 {(char_u *)0L, (char_u *)0L}
866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000867 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200868 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200869#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 (char_u *)VAR_WIN, PV_COCU,
871 {(char_u *)"", (char_u *)NULL}
872#else
873 (char_u *)NULL, PV_NONE,
874 {(char_u *)NULL, (char_u *)0L}
875#endif
876 SCRIPTID_INIT},
877 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
878#ifdef FEAT_CONCEAL
879 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200880#else
881 (char_u *)NULL, PV_NONE,
882#endif
883 {(char_u *)0L, (char_u *)0L}
884 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000885 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
886#ifdef FEAT_COMPL_FUNC
887 (char_u *)&p_cfu, PV_CFU,
888 {(char_u *)"", (char_u *)0L}
889#else
890 (char_u *)NULL, PV_NONE,
891 {(char_u *)0L, (char_u *)0L}
892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000893 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200894 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000895#ifdef FEAT_INS_EXPAND
896 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000897 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000898#else
899 (char_u *)NULL, PV_NONE,
900 {(char_u *)0L, (char_u *)0L}
901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 {"confirm", "cf", P_BOOL|P_VI_DEF,
904#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
905 (char_u *)&p_confirm, PV_NONE,
906#else
907 (char_u *)NULL, PV_NONE,
908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000910 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
914 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000915 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
917 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000918 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
919 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200920 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200921#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200922 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200923 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200924#else
925 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200926 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200927#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
930#ifdef FEAT_CSCOPE
931 (char_u *)&p_cspc, PV_NONE,
932#else
933 (char_u *)NULL, PV_NONE,
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000936 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
937#ifdef FEAT_CSCOPE
938 (char_u *)&p_csprg, PV_NONE,
939 {(char_u *)"cscope", (char_u *)0L}
940#else
941 (char_u *)NULL, PV_NONE,
942 {(char_u *)0L, (char_u *)0L}
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200945 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
947 (char_u *)&p_csqf, PV_NONE,
948 {(char_u *)"", (char_u *)0L}
949#else
950 (char_u *)NULL, PV_NONE,
951 {(char_u *)0L, (char_u *)0L}
952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000953 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200954 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
955#ifdef FEAT_CSCOPE
956 (char_u *)&p_csre, PV_NONE,
957#else
958 (char_u *)NULL, PV_NONE,
959#endif
960 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
962#ifdef FEAT_CSCOPE
963 (char_u *)&p_cst, PV_NONE,
964#else
965 (char_u *)NULL, PV_NONE,
966#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000967 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000968 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
969#ifdef FEAT_CSCOPE
970 (char_u *)&p_csto, PV_NONE,
971#else
972 (char_u *)NULL, PV_NONE,
973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000974 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
976#ifdef FEAT_CSCOPE
977 (char_u *)&p_csverbose, PV_NONE,
978#else
979 (char_u *)NULL, PV_NONE,
980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000981 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200982 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
983#ifdef FEAT_CURSORBIND
984 (char_u *)VAR_WIN, PV_CRBIND,
985#else
986 (char_u *)NULL, PV_NONE,
987#endif
988 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000989 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
990#ifdef FEAT_SYN_HL
991 (char_u *)VAR_WIN, PV_CUC,
992#else
993 (char_u *)NULL, PV_NONE,
994#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000995 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100996 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000997#ifdef FEAT_SYN_HL
998 (char_u *)VAR_WIN, PV_CUL,
999#else
1000 (char_u *)NULL, PV_NONE,
1001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"debug", NULL, P_STRING|P_VI_DEF,
1004 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001006 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001008 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001009 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#else
1011 (char_u *)NULL, PV_NONE,
1012 {(char_u *)NULL, (char_u *)0L}
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1016#ifdef FEAT_MBYTE
1017 (char_u *)&p_deco, PV_NONE,
1018#else
1019 (char_u *)NULL, PV_NONE,
1020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001022 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001024 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#else
1026 (char_u *)NULL, PV_NONE,
1027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001028 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1030#ifdef FEAT_DIFF
1031 (char_u *)VAR_WIN, PV_DIFF,
1032#else
1033 (char_u *)NULL, PV_NONE,
1034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001036 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1038 (char_u *)&p_dex, PV_NONE,
1039 {(char_u *)"", (char_u *)0L}
1040#else
1041 (char_u *)NULL, PV_NONE,
1042 {(char_u *)0L, (char_u *)0L}
1043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001044 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001045 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1046 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047#ifdef FEAT_DIFF
1048 (char_u *)&p_dip, PV_NONE,
1049 {(char_u *)"filler", (char_u *)NULL}
1050#else
1051 (char_u *)NULL, PV_NONE,
1052 {(char_u *)"", (char_u *)NULL}
1053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1056#ifdef FEAT_DIGRAPHS
1057 (char_u *)&p_dg, PV_NONE,
1058#else
1059 (char_u *)NULL, PV_NONE,
1060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001061 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001062 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1063 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001065 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001066 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 (char_u *)&p_ead, PV_NONE,
1071 {(char_u *)"both", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1074 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001076 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1077#if defined(FEAT_MBYTE)
1078 (char_u *)&p_emoji, PV_NONE,
1079 {(char_u *)TRUE, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)0L, (char_u *)0L}
1083#endif
1084 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001085 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086#ifdef FEAT_MBYTE
1087 (char_u *)&p_enc, PV_NONE,
1088 {(char_u *)ENC_DFLT, (char_u *)0L}
1089#else
1090 (char_u *)NULL, PV_NONE,
1091 {(char_u *)0L, (char_u *)0L}
1092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1095 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1098 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001101 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1104 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1107#ifdef FEAT_QUICKFIX
1108 (char_u *)&p_ef, PV_NONE,
1109 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1110#else
1111 (char_u *)NULL, PV_NONE,
1112 {(char_u *)NULL, (char_u *)0L}
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001117 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119#else
1120 (char_u *)NULL, PV_NONE,
1121 {(char_u *)NULL, (char_u *)0L}
1122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 {"esckeys", "ek", P_BOOL|P_VIM,
1125 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001126 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001127 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128#ifdef FEAT_AUTOCMD
1129 (char_u *)&p_ei, PV_NONE,
1130#else
1131 (char_u *)NULL, PV_NONE,
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1135 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1138 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1141 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142#ifdef FEAT_MBYTE
1143 (char_u *)&p_fenc, PV_FENC,
1144 {(char_u *)"", (char_u *)0L}
1145#else
1146 (char_u *)NULL, PV_NONE,
1147 {(char_u *)0L, (char_u *)0L}
1148#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001150 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151#ifdef FEAT_MBYTE
1152 (char_u *)&p_fencs, PV_NONE,
1153 {(char_u *)"ucs-bom", (char_u *)0L}
1154#else
1155 (char_u *)NULL, PV_NONE,
1156 {(char_u *)0L, (char_u *)0L}
1157#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001158 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001159 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1160 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1166 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001167 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1168 (char_u *)&p_fic, PV_NONE,
1169 {
1170#ifdef CASE_INSENSITIVE_FILENAME
1171 (char_u *)TRUE,
1172#else
1173 (char_u *)FALSE,
1174#endif
1175 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001176 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177#ifdef FEAT_AUTOCMD
1178 (char_u *)&p_ft, PV_FT,
1179 {(char_u *)"", (char_u *)0L}
1180#else
1181 (char_u *)NULL, PV_NONE,
1182 {(char_u *)0L, (char_u *)0L}
1183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001185 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 (char_u *)&p_fcs, PV_NONE,
1187 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001189 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1190 (char_u *)&p_fixeol, PV_FIXEOL,
1191 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1193#ifdef FEAT_FKMAP
1194 (char_u *)&p_fkmap, PV_NONE,
1195#else
1196 (char_u *)NULL, PV_NONE,
1197#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"flash", "fl", P_BOOL|P_VI_DEF,
1200 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001202 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001203#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001205 {(char_u *)"", (char_u *)0L}
1206#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001209#endif
1210 SCRIPTID_INIT},
1211 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1212#ifdef FEAT_FOLDING
1213 (char_u *)VAR_WIN, PV_FDC,
1214 {(char_u *)FALSE, (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)NULL, (char_u *)0L}
1218#endif
1219 SCRIPTID_INIT},
1220 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1221#ifdef FEAT_FOLDING
1222 (char_u *)VAR_WIN, PV_FEN,
1223 {(char_u *)TRUE, (char_u *)0L}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
1227#endif
1228 SCRIPTID_INIT},
1229 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1230#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1231 (char_u *)VAR_WIN, PV_FDE,
1232 {(char_u *)"0", (char_u *)NULL}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001239#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001241 {(char_u *)"#", (char_u *)NULL}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001248#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001250 {(char_u *)0L, (char_u *)0L}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
1255 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001256 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001259 {(char_u *)-1L, (char_u *)0L}
1260#else
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)NULL, (char_u *)0L}
1263#endif
1264 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001266 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001267#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001270#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001274 SCRIPTID_INIT},
1275 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1276#ifdef FEAT_FOLDING
1277 (char_u *)VAR_WIN, PV_FDM,
1278 {(char_u *)"manual", (char_u *)NULL}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)NULL, (char_u *)0L}
1282#endif
1283 SCRIPTID_INIT},
1284 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1285#ifdef FEAT_FOLDING
1286 (char_u *)VAR_WIN, PV_FML,
1287 {(char_u *)1L, (char_u *)0L}
1288#else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
1291#endif
1292 SCRIPTID_INIT},
1293 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1294#ifdef FEAT_FOLDING
1295 (char_u *)VAR_WIN, PV_FDN,
1296 {(char_u *)20L, (char_u *)0L}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)NULL, (char_u *)0L}
1300#endif
1301 SCRIPTID_INIT},
1302 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1303#ifdef FEAT_FOLDING
1304 (char_u *)&p_fdo, PV_NONE,
1305 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1306 (char_u *)0L}
1307#else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310#endif
1311 SCRIPTID_INIT},
1312 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1313#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1314 (char_u *)VAR_WIN, PV_FDT,
1315 {(char_u *)"foldtext()", (char_u *)NULL}
1316#else
1317 (char_u *)NULL, PV_NONE,
1318 {(char_u *)NULL, (char_u *)0L}
1319#endif
1320 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001321 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001322#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001323 (char_u *)&p_fex, PV_FEX,
1324 {(char_u *)"", (char_u *)0L}
1325#else
1326 (char_u *)NULL, PV_NONE,
1327 {(char_u *)0L, (char_u *)0L}
1328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001329 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1331 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1333 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001334 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1335 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1337 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001339 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001341 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1342#ifdef HAVE_FSYNC
1343 (char_u *)&p_fs, PV_NONE,
1344 {(char_u *)TRUE, (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)FALSE, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1351 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"graphic", "gr", P_BOOL|P_VI_DEF,
1354 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001356 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357#ifdef FEAT_QUICKFIX
1358 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360#else
1361 (char_u *)NULL, PV_NONE,
1362 {(char_u *)NULL, (char_u *)0L}
1363#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1366#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001367 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {
1369# ifdef WIN3264
1370 /* may be changed to "grep -n" in os_win32.c */
1371 (char_u *)"findstr /n",
1372# else
1373# ifdef UNIX
1374 /* Add an extra file name so that grep will always
1375 * insert a file name in the match line. */
1376 (char_u *)"grep -n $* /dev/null",
1377# else
1378# ifdef VMS
1379 (char_u *)"SEARCH/NUMBERS ",
1380# else
1381 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382# endif
1383# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386#else
1387 (char_u *)NULL, PV_NONE,
1388 {(char_u *)NULL, (char_u *)0L}
1389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001390 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001391 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392#ifdef CURSOR_SHAPE
1393 (char_u *)&p_guicursor, PV_NONE,
1394 {
1395# ifdef FEAT_GUI
1396 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001397# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1399# endif
1400 (char_u *)0L}
1401#else
1402 (char_u *)NULL, PV_NONE,
1403 {(char_u *)NULL, (char_u *)0L}
1404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001406 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407#ifdef FEAT_GUI
1408 (char_u *)&p_guifont, PV_NONE,
1409 {(char_u *)"", (char_u *)0L}
1410#else
1411 (char_u *)NULL, PV_NONE,
1412 {(char_u *)NULL, (char_u *)0L}
1413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1417 (char_u *)&p_guifontset, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001424 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1426 (char_u *)&p_guifontwide, PV_NONE,
1427 {(char_u *)"", (char_u *)0L}
1428#else
1429 (char_u *)NULL, PV_NONE,
1430 {(char_u *)NULL, (char_u *)0L}
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001434#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 (char_u *)&p_ghr, PV_NONE,
1436#else
1437 (char_u *)NULL, PV_NONE,
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001441#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001443# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001444 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001446 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447# endif
1448#else
1449 (char_u *)NULL, PV_NONE,
1450 {(char_u *)NULL, (char_u *)0L}
1451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"guipty", NULL, P_BOOL|P_VI_DEF,
1454#if defined(FEAT_GUI)
1455 (char_u *)&p_guipty, PV_NONE,
1456#else
1457 (char_u *)NULL, PV_NONE,
1458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001460 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001461#if defined(FEAT_GUI_TABLINE)
1462 (char_u *)&p_gtl, PV_NONE,
1463 {(char_u *)"", (char_u *)0L}
1464#else
1465 (char_u *)NULL, PV_NONE,
1466 {(char_u *)NULL, (char_u *)0L}
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001469 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001470#if defined(FEAT_GUI_TABLINE)
1471 (char_u *)&p_gtt, PV_NONE,
1472 {(char_u *)"", (char_u *)0L}
1473#else
1474 (char_u *)NULL, PV_NONE,
1475 {(char_u *)NULL, (char_u *)0L}
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1479 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1482 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001483 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1484 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486 (char_u *)&p_hh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001488 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489#ifdef FEAT_MULTI_LANG
1490 (char_u *)&p_hlg, PV_NONE,
1491 {(char_u *)"", (char_u *)0L}
1492#else
1493 (char_u *)NULL, PV_NONE,
1494 {(char_u *)0L, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"hidden", "hid", P_BOOL|P_VI_DEF,
1498 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001500 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1503 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 {"history", "hi", P_NUM|P_VIM,
1505 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001506 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1508#ifdef FEAT_RIGHTLEFT
1509 (char_u *)&p_hkmap, PV_NONE,
1510#else
1511 (char_u *)NULL, PV_NONE,
1512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001513 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1515#ifdef FEAT_RIGHTLEFT
1516 (char_u *)&p_hkmapp, PV_NONE,
1517#else
1518 (char_u *)NULL, PV_NONE,
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1522 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 {"icon", NULL, P_BOOL|P_VI_DEF,
1525#ifdef FEAT_TITLE
1526 (char_u *)&p_icon, PV_NONE,
1527#else
1528 (char_u *)NULL, PV_NONE,
1529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"iconstring", NULL, P_STRING|P_VI_DEF,
1532#ifdef FEAT_TITLE
1533 (char_u *)&p_iconstring, PV_NONE,
1534#else
1535 (char_u *)NULL, PV_NONE,
1536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001537 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1539 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001541 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar6315a9a2017-11-25 15:20:02 +01001542#if defined(FEAT_EVAL) && defined(USE_IM_CONTROL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001543 (char_u *)&p_imaf, PV_NONE,
1544 {(char_u *)"", (char_u *)NULL}
1545# else
1546 (char_u *)NULL, PV_NONE,
1547 {(char_u *)NULL, (char_u *)0L}
1548# endif
1549 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001551#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 (char_u *)&p_imak, PV_NONE,
1553#else
1554 (char_u *)NULL, PV_NONE,
1555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1558#ifdef USE_IM_CONTROL
1559 (char_u *)&p_imcmdline, PV_NONE,
1560#else
1561 (char_u *)NULL, PV_NONE,
1562#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1565#ifdef USE_IM_CONTROL
1566 (char_u *)&p_imdisable, PV_NONE,
1567#else
1568 (char_u *)NULL, PV_NONE,
1569#endif
1570#ifdef __sgi
1571 {(char_u *)TRUE, (char_u *)0L}
1572#else
1573 {(char_u *)FALSE, (char_u *)0L}
1574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001575 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576 {"iminsert", "imi", P_NUM|P_VI_DEF,
1577 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001578 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"imsearch", "ims", P_NUM|P_VI_DEF,
1581 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001582 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001583 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001584 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar6315a9a2017-11-25 15:20:02 +01001585#if defined(FEAT_EVAL) && defined(USE_IM_CONTROL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001586 (char_u *)&p_imsf, PV_NONE,
1587 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001588#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001591#endif
1592 SCRIPTID_INIT},
1593 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1594#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1595 (char_u *)&p_imst, PV_NONE,
1596 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1597#else
1598 (char_u *)NULL, PV_NONE,
1599 {(char_u *)0L, (char_u *)0L}
1600#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001601 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1603#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001604 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1606#else
1607 (char_u *)NULL, PV_NONE,
1608 {(char_u *)0L, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1612#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1613 (char_u *)&p_inex, PV_INEX,
1614 {(char_u *)"", (char_u *)0L}
1615#else
1616 (char_u *)NULL, PV_NONE,
1617 {(char_u *)0L, (char_u *)0L}
1618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1621 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001622 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1624#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1625 (char_u *)&p_inde, PV_INDE,
1626 {(char_u *)"", (char_u *)0L}
1627#else
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)0L, (char_u *)0L}
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001632 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1634 (char_u *)&p_indk, PV_INDK,
1635 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1636#else
1637 (char_u *)NULL, PV_NONE,
1638 {(char_u *)0L, (char_u *)0L}
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"infercase", "inf", P_BOOL|P_VI_DEF,
1642 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1645 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1648 (char_u *)&p_isf, PV_NONE,
1649 {
1650#ifdef BACKSLASH_IN_FILENAME
1651 /* Excluded are: & and ^ are special in cmd.exe
1652 * ( and ) are used in text separating fnames */
1653 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1654#else
1655# ifdef AMIGA
1656 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1657# else
1658# ifdef VMS
1659 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1660# else /* UNIX et al. */
1661# ifdef EBCDIC
1662 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1663# else
1664 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1665# endif
1666# endif
1667# endif
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1671 (char_u *)&p_isi, PV_NONE,
1672 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001673#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 (char_u *)"@,48-57,_,128-167,224-235",
1675#else
1676# ifdef EBCDIC
1677 /* TODO: EBCDIC Check this! @ == isalpha()*/
1678 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1679 "112-120,128,140-142,156,158,172,"
1680 "174,186,191,203-207,219-225,235-239,"
1681 "251-254",
1682# else
1683 (char_u *)"@,48-57,_,192-255",
1684# endif
1685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001686 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1688 (char_u *)&p_isk, PV_ISK,
1689 {
1690#ifdef EBCDIC
1691 (char_u *)"@,240-249,_",
1692 /* TODO: EBCDIC Check this! @ == isalpha()*/
1693 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1694 "112-120,128,140-142,156,158,172,"
1695 "174,186,191,203-207,219-225,235-239,"
1696 "251-254",
1697#else
1698 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001699# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 (char_u *)"@,48-57,_,128-167,224-235"
1701# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001702 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703# endif
1704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1707 (char_u *)&p_isp, PV_NONE,
1708 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001709#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 (char_u *)"@,~-255",
1711#else
1712# ifdef EBCDIC
1713 /* all chars above 63 are printable */
1714 (char_u *)"63-255",
1715# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001716 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717# endif
1718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1721 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1724#ifdef FEAT_CRYPT
1725 (char_u *)&p_key, PV_KEY,
1726 {(char_u *)"", (char_u *)0L}
1727#else
1728 (char_u *)NULL, PV_NONE,
1729 {(char_u *)0L, (char_u *)0L}
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001732 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733#ifdef FEAT_KEYMAP
1734 (char_u *)&p_keymap, PV_KMAP,
1735 {(char_u *)"", (char_u *)0L}
1736#else
1737 (char_u *)NULL, PV_NONE,
1738 {(char_u *)"", (char_u *)0L}
1739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001740 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001741 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001745 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001747#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 (char_u *)":help",
1749#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001750# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001752# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001753# ifdef USEMAN_S
1754 (char_u *)"man -s",
1755# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001757# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758# endif
1759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001761 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762#ifdef FEAT_LANGMAP
1763 (char_u *)&p_langmap, PV_NONE,
1764 {(char_u *)"", /* unmatched } */
1765#else
1766 (char_u *)NULL, PV_NONE,
1767 {(char_u *)NULL,
1768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001770 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1772 (char_u *)&p_lm, PV_NONE,
1773#else
1774 (char_u *)NULL, PV_NONE,
1775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001777 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1778#ifdef FEAT_LANGMAP
1779 (char_u *)&p_lnr, PV_NONE,
1780#else
1781 (char_u *)NULL, PV_NONE,
1782#endif
1783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001784 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1785#ifdef FEAT_LANGMAP
1786 (char_u *)&p_lrm, PV_NONE,
1787#else
1788 (char_u *)NULL, PV_NONE,
1789#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001790 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 (char_u *)&p_ls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1795 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1798#ifdef FEAT_LINEBREAK
1799 (char_u *)VAR_WIN, PV_LBR,
1800#else
1801 (char_u *)NULL, PV_NONE,
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1805 (char_u *)&Rows, PV_NONE,
1806 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001807#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 (char_u *)25L,
1809#else
1810 (char_u *)24L,
1811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1814#ifdef FEAT_GUI
1815 (char_u *)&p_linespace, PV_NONE,
1816#else
1817 (char_u *)NULL, PV_NONE,
1818#endif
1819#ifdef FEAT_GUI_W32
1820 {(char_u *)1L, (char_u *)0L}
1821#else
1822 {(char_u *)0L, (char_u *)0L}
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"lisp", NULL, P_BOOL|P_VI_DEF,
1826#ifdef FEAT_LISP
1827 (char_u *)&p_lisp, PV_LISP,
1828#else
1829 (char_u *)NULL, PV_NONE,
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001832 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001834 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1836#else
1837 (char_u *)NULL, PV_NONE,
1838 {(char_u *)"", (char_u *)0L}
1839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1842 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001844 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001846 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001847 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1848 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001850 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001851#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001852 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001853 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001854#else
1855 (char_u *)NULL, PV_NONE,
1856 {(char_u *)"", (char_u *)0L}
1857#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001858 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001859 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001860#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001861 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001862 {(char_u *)TRUE, (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001866#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"magic", NULL, P_BOOL|P_VI_DEF,
1869 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001871 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872#ifdef FEAT_QUICKFIX
1873 (char_u *)&p_mef, PV_NONE,
1874 {(char_u *)"", (char_u *)0L}
1875#else
1876 (char_u *)NULL, PV_NONE,
1877 {(char_u *)NULL, (char_u *)0L}
1878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001880 {"makeencoding","menc", P_STRING|P_VI_DEF,
1881#ifdef FEAT_MBYTE
1882 (char_u *)&p_menc, PV_MENC,
1883 {(char_u *)"", (char_u *)0L}
1884#else
1885 (char_u *)NULL, PV_NONE,
1886 {(char_u *)0L, (char_u *)0L}
1887#endif
1888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1890#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001891 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892# ifdef VMS
1893 {(char_u *)"MMS", (char_u *)0L}
1894# else
1895 {(char_u *)"make", (char_u *)0L}
1896# endif
1897#else
1898 (char_u *)NULL, PV_NONE,
1899 {(char_u *)NULL, (char_u *)0L}
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001902 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001904 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1905 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"matchtime", "mat", P_NUM|P_VI_DEF,
1907 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001909 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001910#ifdef FEAT_MBYTE
1911 (char_u *)&p_mco, PV_NONE,
1912#else
1913 (char_u *)NULL, PV_NONE,
1914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1917#ifdef FEAT_EVAL
1918 (char_u *)&p_mfd, PV_NONE,
1919#else
1920 (char_u *)NULL, PV_NONE,
1921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1924 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {"maxmem", "mm", P_NUM|P_VI_DEF,
1927 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1929 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001930 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1931 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001932 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1934 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1936 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"menuitems", "mis", P_NUM|P_VI_DEF,
1938#ifdef FEAT_MENU
1939 (char_u *)&p_mis, PV_NONE,
1940#else
1941 (char_u *)NULL, PV_NONE,
1942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"mesg", NULL, P_BOOL|P_VI_DEF,
1945 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001947 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001948#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001949 (char_u *)&p_msm, PV_NONE,
1950 {(char_u *)"460000,2000,500", (char_u *)0L}
1951#else
1952 (char_u *)NULL, PV_NONE,
1953 {(char_u *)0L, (char_u *)0L}
1954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"modeline", "ml", P_BOOL|P_VIM,
1957 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"modelines", "mls", P_NUM|P_VI_DEF,
1960 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1963 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1966 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"more", NULL, P_BOOL|P_VIM,
1969 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1972 (char_u *)&p_mouse, PV_NONE,
1973 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001974#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 (char_u *)"a",
1976#else
1977 (char_u *)"",
1978#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001979 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1981#ifdef FEAT_GUI
1982 (char_u *)&p_mousef, PV_NONE,
1983#else
1984 (char_u *)NULL, PV_NONE,
1985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1988#ifdef FEAT_GUI
1989 (char_u *)&p_mh, PV_NONE,
1990#else
1991 (char_u *)NULL, PV_NONE,
1992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1995 (char_u *)&p_mousem, PV_NONE,
1996 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001997#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 (char_u *)"popup",
1999#else
Bram Moolenaard0573012017-10-28 21:11:06 +02002000# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 (char_u *)"popup_setpos",
2002# else
2003 (char_u *)"extend",
2004# endif
2005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002007 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008#ifdef FEAT_MOUSESHAPE
2009 (char_u *)&p_mouseshape, PV_NONE,
2010 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2011#else
2012 (char_u *)NULL, PV_NONE,
2013 {(char_u *)NULL, (char_u *)0L}
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2017 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02002019 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2020#if defined(DYNAMIC_MZSCHEME)
2021 (char_u *)&p_mzschemedll, PV_NONE,
2022 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2023#else
2024 (char_u *)NULL, PV_NONE,
2025 {(char_u *)"", (char_u *)0L}
2026#endif
2027 SCRIPTID_INIT},
2028 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2029#if defined(DYNAMIC_MZSCHEME)
2030 (char_u *)&p_mzschemegcdll, PV_NONE,
2031 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2032#else
2033 (char_u *)NULL, PV_NONE,
2034 {(char_u *)"", (char_u *)0L}
2035#endif
2036 SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002037 {"mzquantum", "mzq", P_NUM,
2038#ifdef FEAT_MZSCHEME
2039 (char_u *)&p_mzq, PV_NONE,
2040#else
2041 (char_u *)NULL, PV_NONE,
2042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002043 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044 {"novice", NULL, P_BOOL|P_VI_DEF,
2045 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002047 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002048 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002049 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2052 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002054 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2055#ifdef FEAT_LINEBREAK
2056 (char_u *)VAR_WIN, PV_NUW,
2057#else
2058 (char_u *)NULL, PV_NONE,
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002061 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002062#ifdef FEAT_COMPL_FUNC
2063 (char_u *)&p_ofu, PV_OFU,
2064 {(char_u *)"", (char_u *)0L}
2065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)0L, (char_u *)0L}
2068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"open", NULL, P_BOOL|P_VI_DEF,
2071 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002073 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002074#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002075 (char_u *)&p_odev, PV_NONE,
2076#else
2077 (char_u *)NULL, PV_NONE,
2078#endif
2079 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002081 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2082 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 {"optimize", "opt", P_BOOL|P_VI_DEF,
2085 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002089 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002090 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2091 |P_SECURE,
2092 (char_u *)&p_pp, PV_NONE,
2093 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2094 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"paragraphs", "para", P_STRING|P_VI_DEF,
2096 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002097 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002099 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2103 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2106#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2107 (char_u *)&p_pex, PV_NONE,
2108 {(char_u *)"", (char_u *)0L}
2109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)0L, (char_u *)0L}
2112#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002114 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002118 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002120#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 (char_u *)".,,",
2122#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002126 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002127#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002128 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002129 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002130#else
2131 (char_u *)NULL, PV_NONE,
2132 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002134 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2136 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002138 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002139#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 (char_u *)&p_pvh, PV_NONE,
2141#else
2142 (char_u *)NULL, PV_NONE,
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002146#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 (char_u *)VAR_WIN, PV_PVW,
2148#else
2149 (char_u *)NULL, PV_NONE,
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002152 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153#ifdef FEAT_PRINTER
2154 (char_u *)&p_pdev, PV_NONE,
2155 {(char_u *)"", (char_u *)0L}
2156#else
2157 (char_u *)NULL, PV_NONE,
2158 {(char_u *)NULL, (char_u *)0L}
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"printencoding", "penc", P_STRING|P_VI_DEF,
2162#ifdef FEAT_POSTSCRIPT
2163 (char_u *)&p_penc, PV_NONE,
2164 {(char_u *)"", (char_u *)0L}
2165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)NULL, (char_u *)0L}
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002170 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171#ifdef FEAT_POSTSCRIPT
2172 (char_u *)&p_pexpr, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"printfont", "pfn", P_STRING|P_VI_DEF,
2180#ifdef FEAT_PRINTER
2181 (char_u *)&p_pfn, PV_NONE,
2182 {
2183# ifdef MSWIN
2184 (char_u *)"Courier_New:h10",
2185# else
2186 (char_u *)"courier",
2187# endif
2188 (char_u *)0L}
2189#else
2190 (char_u *)NULL, PV_NONE,
2191 {(char_u *)NULL, (char_u *)0L}
2192#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2195#ifdef FEAT_PRINTER
2196 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002197 /* untranslated to avoid problems when 'encoding'
2198 * is changed */
2199 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002205 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2206#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2207 (char_u *)&p_pmcs, PV_NONE,
2208 {(char_u *)"", (char_u *)0L}
2209#else
2210 (char_u *)NULL, PV_NONE,
2211 {(char_u *)NULL, (char_u *)0L}
2212#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002213 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002214 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2215#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2216 (char_u *)&p_pmfn, PV_NONE,
2217 {(char_u *)"", (char_u *)0L}
2218#else
2219 (char_u *)NULL, PV_NONE,
2220 {(char_u *)NULL, (char_u *)0L}
2221#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002223 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224#ifdef FEAT_PRINTER
2225 (char_u *)&p_popt, PV_NONE,
2226 {(char_u *)"", (char_u *)0L}
2227#else
2228 (char_u *)NULL, PV_NONE,
2229 {(char_u *)NULL, (char_u *)0L}
2230#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002231 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002233 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002234 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002235 {"pumheight", "ph", P_NUM|P_VI_DEF,
2236#ifdef FEAT_INS_EXPAND
2237 (char_u *)&p_ph, PV_NONE,
2238#else
2239 (char_u *)NULL, PV_NONE,
2240#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002242 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002243#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002244 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002245 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002246#else
2247 (char_u *)NULL, PV_NONE,
2248 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002249#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002250 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002251 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002252#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002253 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002254 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002255#else
2256 (char_u *)NULL, PV_NONE,
2257 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002258#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002259 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002260 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2261#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2262 (char_u *)&p_pyx, PV_NONE,
2263#else
2264 (char_u *)NULL, PV_NONE,
2265#endif
2266 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2267 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002268 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2269#ifdef FEAT_TEXTOBJ
2270 (char_u *)&p_qe, PV_QE,
2271 {(char_u *)"\\", (char_u *)0L}
2272#else
2273 (char_u *)NULL, PV_NONE,
2274 {(char_u *)NULL, (char_u *)0L}
2275#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2278 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"redraw", NULL, P_BOOL|P_VI_DEF,
2281 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002283 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2284#ifdef FEAT_RELTIME
2285 (char_u *)&p_rdt, PV_NONE,
2286#else
2287 (char_u *)NULL, PV_NONE,
2288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002290 {"regexpengine", "re", P_NUM|P_VI_DEF,
2291 (char_u *)&p_re, PV_NONE,
2292 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002293 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2294 (char_u *)VAR_WIN, PV_RNU,
2295 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"remap", NULL, P_BOOL|P_VI_DEF,
2297 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002298 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002299 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002300#ifdef FEAT_RENDER_OPTIONS
2301 (char_u *)&p_rop, PV_NONE,
2302 {(char_u *)"", (char_u *)0L}
2303#else
2304 (char_u *)NULL, PV_NONE,
2305 {(char_u *)NULL, (char_u *)0L}
2306#endif
2307 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"report", NULL, P_NUM|P_VI_DEF,
2309 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2312#ifdef WIN3264
2313 (char_u *)&p_rs, PV_NONE,
2314#else
2315 (char_u *)NULL, PV_NONE,
2316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2319#ifdef FEAT_RIGHTLEFT
2320 (char_u *)&p_ri, PV_NONE,
2321#else
2322 (char_u *)NULL, PV_NONE,
2323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2326#ifdef FEAT_RIGHTLEFT
2327 (char_u *)VAR_WIN, PV_RL,
2328#else
2329 (char_u *)NULL, PV_NONE,
2330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2333#ifdef FEAT_RIGHTLEFT
2334 (char_u *)VAR_WIN, PV_RLC,
2335 {(char_u *)"search", (char_u *)NULL}
2336#else
2337 (char_u *)NULL, PV_NONE,
2338 {(char_u *)NULL, (char_u *)0L}
2339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002341 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002342#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002343 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002344 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002345#else
2346 (char_u *)NULL, PV_NONE,
2347 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002348#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2351#ifdef FEAT_CMDL_INFO
2352 (char_u *)&p_ru, PV_NONE,
2353#else
2354 (char_u *)NULL, PV_NONE,
2355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002356 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2358#ifdef FEAT_STL_OPT
2359 (char_u *)&p_ruf, PV_NONE,
2360#else
2361 (char_u *)NULL, PV_NONE,
2362#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002364 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2365 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2368 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2370 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01002371 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2373#ifdef FEAT_SCROLLBIND
2374 (char_u *)VAR_WIN, PV_SCBIND,
2375#else
2376 (char_u *)NULL, PV_NONE,
2377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2380 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2383 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002385 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386#ifdef FEAT_SCROLLBIND
2387 (char_u *)&p_sbo, PV_NONE,
2388 {(char_u *)"ver,jump", (char_u *)0L}
2389#else
2390 (char_u *)NULL, PV_NONE,
2391 {(char_u *)0L, (char_u *)0L}
2392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"sections", "sect", P_STRING|P_VI_DEF,
2395 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2397 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2399 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)"inclusive", (char_u *)0L}
2404 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002405 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002408 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409#ifdef FEAT_SESSION
2410 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002411 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 (char_u *)0L}
2413#else
2414 (char_u *)NULL, PV_NONE,
2415 {(char_u *)0L, (char_u *)0L}
2416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002417 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2419 (char_u *)&p_sh, PV_NONE,
2420 {
2421#ifdef VMS
2422 (char_u *)"-",
2423#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002424# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002426# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428# endif
2429#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2432 (char_u *)&p_shcf, PV_NONE,
2433 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002434#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 (char_u *)"/c",
2436#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2441#ifdef FEAT_QUICKFIX
2442 (char_u *)&p_sp, PV_NONE,
2443 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002444#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446#else
2447 (char_u *)">",
2448#endif
2449 (char_u *)0L}
2450#else
2451 (char_u *)NULL, PV_NONE,
2452 {(char_u *)0L, (char_u *)0L}
2453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2456 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002457 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2459 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2462#ifdef BACKSLASH_IN_FILENAME
2463 (char_u *)&p_ssl, PV_NONE,
2464#else
2465 (char_u *)NULL, PV_NONE,
2466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002468 {"shelltemp", "stmp", P_BOOL,
2469 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"shelltype", "st", P_NUM|P_VI_DEF,
2472#ifdef AMIGA
2473 (char_u *)&p_st, PV_NONE,
2474#else
2475 (char_u *)NULL, PV_NONE,
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2479 (char_u *)&p_sxq, PV_NONE,
2480 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002481#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 (char_u *)"\"",
2483#else
2484 (char_u *)"",
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002487 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2488 (char_u *)&p_sxe, PV_NONE,
2489 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002490#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002491 (char_u *)"\"&|<>()@^",
2492#else
2493 (char_u *)"",
2494#endif
2495 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2497 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2500 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2503 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)"", (char_u *)"filnxtToO"}
2505 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2510#ifdef FEAT_LINEBREAK
2511 (char_u *)&p_sbr, PV_NONE,
2512#else
2513 (char_u *)NULL, PV_NONE,
2514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"showcmd", "sc", P_BOOL|P_VIM,
2517#ifdef FEAT_CMDL_INFO
2518 (char_u *)&p_sc, PV_NONE,
2519#else
2520 (char_u *)NULL, PV_NONE,
2521#endif
2522 {(char_u *)FALSE,
2523#ifdef UNIX
2524 (char_u *)FALSE
2525#else
2526 (char_u *)TRUE
2527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2530 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2533 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"showmode", "smd", P_BOOL|P_VIM,
2536 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002538 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002539 (char_u *)&p_stal, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2542 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2545 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002547 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2548#ifdef FEAT_SIGNS
2549 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002550 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002551#else
2552 (char_u *)NULL, PV_NONE,
2553 {(char_u *)NULL, (char_u *)0L}
2554#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002555 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2557 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2560 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2563#ifdef FEAT_SMARTINDENT
2564 (char_u *)&p_si, PV_SI,
2565#else
2566 (char_u *)NULL, PV_NONE,
2567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2570 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2573 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2576 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002578 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002579#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002580 (char_u *)VAR_WIN, PV_SPELL,
2581#else
2582 (char_u *)NULL, PV_NONE,
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002585 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002586#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002587 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002588 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002589#else
2590 (char_u *)NULL, PV_NONE,
2591 {(char_u *)0L, (char_u *)0L}
2592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002594 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2595 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002596#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002597 (char_u *)&p_spf, PV_SPF,
2598 {(char_u *)"", (char_u *)0L}
2599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002604 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2605 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002606#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002607 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002608 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002609#else
2610 (char_u *)NULL, PV_NONE,
2611 {(char_u *)0L, (char_u *)0L}
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002614 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002615#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002616 (char_u *)&p_sps, PV_NONE,
2617 {(char_u *)"best", (char_u *)0L}
2618#else
2619 (char_u *)NULL, PV_NONE,
2620 {(char_u *)0L, (char_u *)0L}
2621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 (char_u *)&p_sb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 (char_u *)&p_spr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2630 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002632 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2633#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002634 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635#else
2636 (char_u *)NULL, PV_NONE,
2637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002638 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002639 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 (char_u *)&p_su, PV_NONE,
2641 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002643 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002644#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 (char_u *)&p_sua, PV_SUA,
2646 {(char_u *)"", (char_u *)0L}
2647#else
2648 (char_u *)NULL, PV_NONE,
2649 {(char_u *)0L, (char_u *)0L}
2650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2653 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"swapsync", "sws", P_STRING|P_VI_DEF,
2656 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002658 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002661 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2662#ifdef FEAT_SYN_HL
2663 (char_u *)&p_smc, PV_SMC,
2664 {(char_u *)3000L, (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002670 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671#ifdef FEAT_SYN_HL
2672 (char_u *)&p_syn, PV_SYN,
2673 {(char_u *)"", (char_u *)0L}
2674#else
2675 (char_u *)NULL, PV_NONE,
2676 {(char_u *)0L, (char_u *)0L}
2677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002679 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2680#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002681 (char_u *)&p_tal, PV_NONE,
2682#else
2683 (char_u *)NULL, PV_NONE,
2684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002685 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002686 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002687 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002688 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2690 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2693 (char_u *)&p_tbs, PV_NONE,
2694#ifdef VMS /* binary searching doesn't appear to work on VMS */
2695 {(char_u *)0L, (char_u *)0L}
2696#else
2697 {(char_u *)TRUE, (char_u *)0L}
2698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002700 {"tagcase", "tc", P_STRING|P_VIM,
2701 (char_u *)&p_tc, PV_TC,
2702 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 {"taglength", "tl", P_NUM|P_VI_DEF,
2704 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002705 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"tagrelative", "tr", P_BOOL|P_VIM,
2707 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002709 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002710 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {
2712#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2713 (char_u *)"./tags,./TAGS,tags,TAGS",
2714#else
2715 (char_u *)"./tags,tags",
2716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2719 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002721 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002722#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002723 (char_u *)&p_tcldll, PV_NONE,
2724 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002725#else
2726 (char_u *)NULL, PV_NONE,
2727 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002728#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2731 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2734#ifdef FEAT_ARABIC
2735 (char_u *)&p_tbidi, PV_NONE,
2736#else
2737 (char_u *)NULL, PV_NONE,
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2741#ifdef FEAT_MBYTE
2742 (char_u *)&p_tenc, PV_NONE,
2743 {(char_u *)"", (char_u *)0L}
2744#else
2745 (char_u *)NULL, PV_NONE,
2746 {(char_u *)0L, (char_u *)0L}
2747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002748 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002749 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2750#ifdef FEAT_TERMGUICOLORS
2751 (char_u *)&p_tgc, PV_NONE,
2752 {(char_u *)FALSE, (char_u *)FALSE}
2753#else
2754 (char_u*)NULL, PV_NONE,
2755 {(char_u *)FALSE, (char_u *)FALSE}
2756#endif
2757 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002758 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2759#ifdef FEAT_TERMINAL
2760 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002761 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002762#else
2763 (char_u *)NULL, PV_NONE,
2764 {(char_u *)NULL, (char_u *)0L}
2765#endif
2766 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002767 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2768#ifdef FEAT_TERMINAL
2769 (char_u *)VAR_WIN, PV_TMS,
2770 {(char_u *)"", (char_u *)NULL}
2771#else
2772 (char_u *)NULL, PV_NONE,
2773 {(char_u *)NULL, (char_u *)0L}
2774#endif
2775 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 {"terse", NULL, P_BOOL|P_VI_DEF,
2777 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"textauto", "ta", P_BOOL|P_VIM,
2780 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002781 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2782 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2784 (char_u *)&p_tx, PV_TX,
2785 {
2786#ifdef USE_CRNL
2787 (char_u *)TRUE,
2788#else
2789 (char_u *)FALSE,
2790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002792 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002795 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002797 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798#else
2799 (char_u *)NULL, PV_NONE,
2800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002801 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2803 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"timeout", "to", P_BOOL|P_VI_DEF,
2806 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2809 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"title", NULL, P_BOOL|P_VI_DEF,
2812#ifdef FEAT_TITLE
2813 (char_u *)&p_title, PV_NONE,
2814#else
2815 (char_u *)NULL, PV_NONE,
2816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002817 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"titlelen", NULL, P_NUM|P_VI_DEF,
2819#ifdef FEAT_TITLE
2820 (char_u *)&p_titlelen, PV_NONE,
2821#else
2822 (char_u *)NULL, PV_NONE,
2823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002825 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826#ifdef FEAT_TITLE
2827 (char_u *)&p_titleold, PV_NONE,
2828 {(char_u *)N_("Thanks for flying Vim"),
2829 (char_u *)0L}
2830#else
2831 (char_u *)NULL, PV_NONE,
2832 {(char_u *)0L, (char_u *)0L}
2833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"titlestring", NULL, P_STRING|P_VI_DEF,
2836#ifdef FEAT_TITLE
2837 (char_u *)&p_titlestring, PV_NONE,
2838#else
2839 (char_u *)NULL, PV_NONE,
2840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002842 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002843#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002846#else
2847 (char_u *)NULL, PV_NONE,
2848 {(char_u *)0L, (char_u *)0L}
2849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002852#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002854 {(char_u *)"small", (char_u *)0L}
2855#else
2856 (char_u *)NULL, PV_NONE,
2857 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002859 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2861 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2864 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2867 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002868 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2870 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2873#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2874 (char_u *)&p_ttym, PV_NONE,
2875#else
2876 (char_u *)NULL, PV_NONE,
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2880 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2883 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002884 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002885 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2886 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002887#ifdef FEAT_PERSISTENT_UNDO
2888 (char_u *)&p_udir, PV_NONE,
2889 {(char_u *)".", (char_u *)0L}
2890#else
2891 (char_u *)NULL, PV_NONE,
2892 {(char_u *)0L, (char_u *)0L}
2893#endif
2894 SCRIPTID_INIT},
2895 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2896#ifdef FEAT_PERSISTENT_UNDO
2897 (char_u *)&p_udf, PV_UDF,
2898#else
2899 (char_u *)NULL, PV_NONE,
2900#endif
2901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002903 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002905#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 (char_u *)1000L,
2907#else
2908 (char_u *)100L,
2909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002911 {"undoreload", "ur", P_NUM|P_VI_DEF,
2912 (char_u *)&p_ur, PV_NONE,
2913 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 {"updatecount", "uc", P_NUM|P_VI_DEF,
2915 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"updatetime", "ut", P_NUM|P_VI_DEF,
2918 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"verbose", "vbs", P_NUM|P_VI_DEF,
2921 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002923 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2924 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2927#ifdef FEAT_SESSION
2928 (char_u *)&p_vdir, PV_NONE,
2929 {(char_u *)DFLT_VDIR, (char_u *)0L}
2930#else
2931 (char_u *)NULL, PV_NONE,
2932 {(char_u *)0L, (char_u *)0L}
2933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002935 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936#ifdef FEAT_SESSION
2937 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002938 {(char_u *)"folds,options,cursor,curdir",
2939 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940#else
2941 (char_u *)NULL, PV_NONE,
2942 {(char_u *)0L, (char_u *)0L}
2943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002944 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002945 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946#ifdef FEAT_VIMINFO
2947 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002948#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002949 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950#else
2951# ifdef AMIGA
2952 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002953 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002955 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956# endif
2957#endif
2958#else
2959 (char_u *)NULL, PV_NONE,
2960 {(char_u *)0L, (char_u *)0L}
2961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002962 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002963 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2964#ifdef FEAT_VIMINFO
2965 (char_u *)&p_viminfofile, PV_NONE,
2966 {(char_u *)"", (char_u *)0L}
2967#else
2968 (char_u *)NULL, PV_NONE,
2969 {(char_u *)0L, (char_u *)0L}
2970#endif
2971 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002972 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2973 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974#ifdef FEAT_VIRTUALEDIT
2975 (char_u *)&p_ve, PV_NONE,
2976 {(char_u *)"", (char_u *)""}
2977#else
2978 (char_u *)NULL, PV_NONE,
2979 {(char_u *)0L, (char_u *)0L}
2980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2983 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 {"w300", NULL, P_NUM|P_VI_DEF,
2986 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 {"w1200", NULL, P_NUM|P_VI_DEF,
2989 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002990 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 {"w9600", NULL, P_NUM|P_VI_DEF,
2992 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002993 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 {"warn", NULL, P_BOOL|P_VI_DEF,
2995 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2998 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003000 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003002 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 {"wildchar", "wc", P_NUM|P_VIM,
3004 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003005 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3006 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003007 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003009 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003010 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011#ifdef FEAT_WILDIGN
3012 (char_u *)&p_wig, PV_NONE,
3013#else
3014 (char_u *)NULL, PV_NONE,
3015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003016 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003017 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3018 (char_u *)&p_wic, PV_NONE,
3019 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3021#ifdef FEAT_WILDMENU
3022 (char_u *)&p_wmnu, PV_NONE,
3023#else
3024 (char_u *)NULL, PV_NONE,
3025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003026 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003027 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003029 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003030 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3031#ifdef FEAT_CMDL_COMPL
3032 (char_u *)&p_wop, PV_NONE,
3033 {(char_u *)"", (char_u *)0L}
3034#else
3035 (char_u *)NULL, PV_NONE,
3036 {(char_u *)NULL, (char_u *)0L}
3037#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003038 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3040#ifdef FEAT_WAK
3041 (char_u *)&p_wak, PV_NONE,
3042 {(char_u *)"menu", (char_u *)0L}
3043#else
3044 (char_u *)NULL, PV_NONE,
3045 {(char_u *)NULL, (char_u *)0L}
3046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003049 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003050 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 (char_u *)&p_wh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003053 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003057 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003058 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003059 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003062 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003065 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003066 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003067#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003068 (char_u *)&p_winptydll, PV_NONE, {
3069# ifdef _WIN64
3070 (char_u *)"winpty64.dll",
3071# else
3072 (char_u *)"winpty32.dll",
3073# endif
3074 (char_u *)0L}
3075#else
3076 (char_u *)NULL, PV_NONE,
3077 {(char_u *)0L, (char_u *)0L}
3078#endif
3079 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003082 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3084 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003085 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3087 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003088 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3090 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003091 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 {"write", NULL, P_BOOL|P_VI_DEF,
3093 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003094 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 {"writeany", "wa", P_BOOL|P_VI_DEF,
3096 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3099 (char_u *)&p_wb, PV_NONE,
3100 {
3101#ifdef FEAT_WRITEBACKUP
3102 (char_u *)TRUE,
3103#else
3104 (char_u *)FALSE,
3105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003106 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 {"writedelay", "wd", P_NUM|P_VI_DEF,
3108 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003109 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110
3111/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003112#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003114 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115
3116 p_term("t_AB", T_CAB)
3117 p_term("t_AF", T_CAF)
3118 p_term("t_AL", T_CAL)
3119 p_term("t_al", T_AL)
3120 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003121 p_term("t_BE", T_BE)
3122 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_cd", T_CD)
3124 p_term("t_ce", T_CE)
3125 p_term("t_cl", T_CL)
3126 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003127 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 p_term("t_Co", T_CCO)
3129 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003130 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_da", T_DA)
3134 p_term("t_db", T_DB)
3135 p_term("t_DL", T_CDL)
3136 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003137 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003138 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003140 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_IE", T_CIE)
3142 p_term("t_IS", T_CIS)
3143 p_term("t_ke", T_KE)
3144 p_term("t_ks", T_KS)
3145 p_term("t_le", T_LE)
3146 p_term("t_mb", T_MB)
3147 p_term("t_md", T_MD)
3148 p_term("t_me", T_ME)
3149 p_term("t_mr", T_MR)
3150 p_term("t_ms", T_MS)
3151 p_term("t_nd", T_ND)
3152 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003153 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003154 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003155 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003157 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 p_term("t_RV", T_CRV)
3159 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003160 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003162 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003163 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003164 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003166 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003168 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_te", T_TE)
3170 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003171 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003172 p_term("t_ts", T_TS)
3173 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174 p_term("t_ue", T_UE)
3175 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003176 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_vb", T_VB)
3178 p_term("t_ve", T_VE)
3179 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003180 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 p_term("t_vs", T_VS)
3182 p_term("t_WP", T_CWP)
3183 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003184 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_xs", T_XS)
3186 p_term("t_ZH", T_CZH)
3187 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003188 p_term("t_8f", T_8F)
3189 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190
3191/* terminal key codes are not in here */
3192
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003193 /* end marker */
3194 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195};
3196
3197#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3198
3199#ifdef FEAT_MBYTE
3200static char *(p_ambw_values[]) = {"single", "double", NULL};
3201#endif
3202static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003203static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003205#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003206static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003207#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003208#ifdef FEAT_CMDL_COMPL
3209static char *(p_wop_values[]) = {"tagfile", NULL};
3210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211#ifdef FEAT_WAK
3212static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3213#endif
3214static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3216static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218#ifdef FEAT_BROWSE
3219static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3220#endif
3221#ifdef FEAT_SCROLLBIND
3222static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3223#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003224static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003226#ifdef FEAT_AUTOCMD
3227static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3228#else
3229static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003231static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3233#ifdef FEAT_FOLDING
3234static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003235# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003237# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 NULL};
3239static char *(p_fcl_values[]) = {"all", NULL};
3240#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003241#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003242static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003243#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003244#ifdef FEAT_SIGNS
3245static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3246#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003248static void set_option_default(int, int opt_flags, int compatible);
3249static void set_options_default(int opt_flags);
3250static char_u *term_bg_default(void);
3251static void did_set_option(int opt_idx, int opt_flags, int new_value);
3252static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003254static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255#endif
3256#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003257static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003259static char_u *option_expand(int opt_idx, char_u *val);
3260static void didset_options(void);
3261static void didset_options2(void);
3262static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003263#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003264static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003265#else
3266# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3267#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static void set_string_option_global(int opt_idx, char_u **varp);
3269static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3270static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3271static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003272#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003273static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003278#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003279static char_u *did_set_spell_option(int is_spellfile);
3280static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003281#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003282#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003284#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003285static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3286static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3287static void check_redraw(long_u flags);
3288static int findoption(char_u *);
3289static int find_key_option(char_u *);
3290static void showoptions(int all, int opt_flags);
3291static int optval_default(struct vimoption *, char_u *varp);
3292static void showoneopt(struct vimoption *, int opt_flags);
3293static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3294static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3295static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3296static int istermoption(struct vimoption *);
3297static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3298static char_u *get_varp(struct vimoption *);
3299static void option_value2string(struct vimoption *, int opt_flags);
3300static void check_winopt(winopt_T *wop);
3301static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003303static void langmap_init(void);
3304static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003306static void paste_option_changed(void);
3307static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003311static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3312static int check_opt_strings(char_u *val, char **values, int);
3313static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003314#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003315static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003316#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317
3318/*
3319 * Initialize the options, first part.
3320 *
3321 * Called only once from main(), just after creating the first buffer.
3322 */
3323 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003324set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325{
3326 char_u *p;
3327 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003328 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329
3330#ifdef FEAT_LANGMAP
3331 langmap_init();
3332#endif
3333
3334 /* Be Vi compatible by default */
3335 p_cp = TRUE;
3336
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003337 /* Use POSIX compatibility when $VIM_POSIX is set. */
3338 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003339 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003340 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003341 set_string_default("shm", (char_u *)"A");
3342 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003343
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 /*
3345 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003346 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003348 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003349#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003350 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003352 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353# endif
3354#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003355 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356 set_string_default("sh", p);
3357
3358#ifdef FEAT_WILDIGN
3359 /*
3360 * Set the default for 'backupskip' to include environment variables for
3361 * temp files.
3362 */
3363 {
3364# ifdef UNIX
3365 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3366# else
3367 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3368# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003369 int len;
3370 garray_T ga;
3371 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372
3373 ga_init2(&ga, 1, 100);
3374 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3375 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003376 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377# ifdef UNIX
3378 if (*names[n] == NUL)
3379 p = (char_u *)"/tmp";
3380 else
3381# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003382 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 if (p != NULL && *p != NUL)
3384 {
3385 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003386 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 if (ga_grow(&ga, len) == OK)
3388 {
3389 if (ga.ga_len > 0)
3390 STRCAT(ga.ga_data, ",");
3391 STRCAT(ga.ga_data, p);
3392 add_pathsep(ga.ga_data);
3393 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003394 ga.ga_len += len;
3395 }
3396 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003397 if (mustfree)
3398 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399 }
3400 if (ga.ga_data != NULL)
3401 {
3402 set_string_default("bsk", ga.ga_data);
3403 vim_free(ga.ga_data);
3404 }
3405 }
3406#endif
3407
3408 /*
3409 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3410 */
3411 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003412 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003414#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3415 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3416#endif
3417 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003419 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003420 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421#else
3422# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003423 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003424 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003426 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003427# endif
3428#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003430 opt_idx = findoption((char_u *)"maxmem");
3431 if (opt_idx >= 0)
3432 {
3433#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003434 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3435 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003436#endif
3437 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3438 }
3439 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 }
3441
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442#ifdef FEAT_SEARCHPATH
3443 {
3444 char_u *cdpath;
3445 char_u *buf;
3446 int i;
3447 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003448 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449
3450 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003451 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452 if (cdpath != NULL)
3453 {
3454 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3455 if (buf != NULL)
3456 {
3457 buf[0] = ','; /* start with ",", current dir first */
3458 j = 1;
3459 for (i = 0; cdpath[i] != NUL; ++i)
3460 {
3461 if (vim_ispathlistsep(cdpath[i]))
3462 buf[j++] = ',';
3463 else
3464 {
3465 if (cdpath[i] == ' ' || cdpath[i] == ',')
3466 buf[j++] = '\\';
3467 buf[j++] = cdpath[i];
3468 }
3469 }
3470 buf[j] = NUL;
3471 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003472 if (opt_idx >= 0)
3473 {
3474 options[opt_idx].def_val[VI_DEFAULT] = buf;
3475 options[opt_idx].flags |= P_DEF_ALLOCED;
3476 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003477 else
3478 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003480 if (mustfree)
3481 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482 }
3483 }
3484#endif
3485
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003486#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487 /* Set print encoding on platforms that don't default to latin1 */
3488 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003489# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490 (char_u *)"cp1252"
3491# else
3492# ifdef VMS
3493 (char_u *)"dec-mcs"
3494# else
3495# ifdef EBCDIC
3496 (char_u *)"ebcdic-uk"
3497# else
3498# ifdef MAC
3499 (char_u *)"mac-roman"
3500# else /* HPUX */
3501 (char_u *)"hp-roman8"
3502# endif
3503# endif
3504# endif
3505# endif
3506 );
3507#endif
3508
3509#ifdef FEAT_POSTSCRIPT
3510 /* 'printexpr' must be allocated to be able to evaluate it. */
3511 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003512# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003513 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514# else
3515# ifdef VMS
3516 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3517
3518# else
3519 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3520# endif
3521# endif
3522 );
3523#endif
3524
3525 /*
3526 * Set all the options (except the terminal options) to their default
3527 * value. Also set the global value for local options.
3528 */
3529 set_options_default(0);
3530
3531#ifdef FEAT_GUI
3532 if (found_reverse_arg)
3533 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3534#endif
3535
3536 curbuf->b_p_initialized = TRUE;
3537 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003538 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003539 check_buf_options(curbuf);
3540 check_win_options(curwin);
3541 check_options();
3542
3543 /* Must be before option_expand(), because that one needs vim_isIDc() */
3544 didset_options();
3545
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003546#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003547 /* Use the current chartab for the generic chartab. This is not in
3548 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003549 init_spell_chartab();
3550#endif
3551
Bram Moolenaar071d4272004-06-13 20:20:40 +00003552 /*
3553 * Expand environment variables and things like "~" for the defaults.
3554 * If option_expand() returns non-NULL the variable is expanded. This can
3555 * only happen for non-indirect options.
3556 * Also set the default to the expanded value, so ":set" does not list
3557 * them.
3558 * Don't set the P_ALLOCED flag, because we don't want to free the
3559 * default.
3560 */
3561 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3562 {
3563 if ((options[opt_idx].flags & P_GETTEXT)
3564 && options[opt_idx].var != NULL)
3565 p = (char_u *)_(*(char **)options[opt_idx].var);
3566 else
3567 p = option_expand(opt_idx, NULL);
3568 if (p != NULL && (p = vim_strsave(p)) != NULL)
3569 {
3570 *(char_u **)options[opt_idx].var = p;
3571 /* VIMEXP
3572 * Defaults for all expanded options are currently the same for Vi
3573 * and Vim. When this changes, add some code here! Also need to
3574 * split P_DEF_ALLOCED in two.
3575 */
3576 if (options[opt_idx].flags & P_DEF_ALLOCED)
3577 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3578 options[opt_idx].def_val[VI_DEFAULT] = p;
3579 options[opt_idx].flags |= P_DEF_ALLOCED;
3580 }
3581 }
3582
Bram Moolenaar071d4272004-06-13 20:20:40 +00003583 save_file_ff(curbuf); /* Buffer is unchanged */
3584
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585#if defined(FEAT_ARABIC)
3586 /* Detect use of mlterm.
3587 * Mlterm is a terminal emulator akin to xterm that has some special
3588 * abilities (bidi namely).
3589 * NOTE: mlterm's author is being asked to 'set' a variable
3590 * instead of an environment variable due to inheritance.
3591 */
3592 if (mch_getenv((char_u *)"MLTERM") != NULL)
3593 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3594#endif
3595
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003596 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597
3598#ifdef FEAT_MBYTE
3599# if defined(WIN3264) && defined(FEAT_GETTEXT)
3600 /*
3601 * If $LANG isn't set, try to get a good value for it. This makes the
3602 * right language be used automatically. Don't do this for English.
3603 */
3604 if (mch_getenv((char_u *)"LANG") == NULL)
3605 {
3606 char buf[20];
3607
3608 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3609 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3610 * only the first two. */
3611 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3612 (LPTSTR)buf, 20);
3613 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3614 {
3615 /* There are a few exceptions (probably more) */
3616 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3617 STRCPY(buf, "zh_TW");
3618 else if (STRNICMP(buf, "chs", 3) == 0
3619 || STRNICMP(buf, "zhc", 3) == 0)
3620 STRCPY(buf, "zh_CN");
3621 else if (STRNICMP(buf, "jp", 2) == 0)
3622 STRCPY(buf, "ja");
3623 else
3624 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003625 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626 }
3627 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003628# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003629# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003630 /* Moved to os_mac_conv.c to avoid dependency problems. */
3631 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003632# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003633# endif
3634
3635 /* enc_locale() will try to find the encoding of the current locale. */
3636 p = enc_locale();
3637 if (p != NULL)
3638 {
3639 char_u *save_enc;
3640
3641 /* Try setting 'encoding' and check if the value is valid.
3642 * If not, go back to the default "latin1". */
3643 save_enc = p_enc;
3644 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003645 if (STRCMP(p_enc, "gb18030") == 0)
3646 {
3647 /* We don't support "gb18030", but "cp936" is a good substitute
3648 * for practical purposes, thus use that. It's not an alias to
3649 * still support conversion between gb18030 and utf-8. */
3650 p_enc = vim_strsave((char_u *)"cp936");
3651 vim_free(p);
3652 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653 if (mb_init() == NULL)
3654 {
3655 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003656 if (opt_idx >= 0)
3657 {
3658 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3659 options[opt_idx].flags |= P_DEF_ALLOCED;
3660 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661
Bram Moolenaard0573012017-10-28 21:11:06 +02003662#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003663 if (STRCMP(p_enc, "latin1") == 0
3664# ifdef FEAT_MBYTE
3665 || enc_utf8
3666# endif
3667 )
3668 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003669 /* Adjust the default for 'isprint' and 'iskeyword' to match
3670 * latin1. Also set the defaults for when 'nocompatible' is
3671 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003672 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003673 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003674 set_string_option_direct((char_u *)"isk", -1,
3675 ISK_LATIN1, OPT_FREE, SID_NONE);
3676 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003677 if (opt_idx >= 0)
3678 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003679 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003680 if (opt_idx >= 0)
3681 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003682 (void)init_chartab();
3683 }
3684#endif
3685
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686# if defined(WIN3264) && !defined(FEAT_GUI)
3687 /* Win32 console: When GetACP() returns a different value from
3688 * GetConsoleCP() set 'termencoding'. */
3689 if (GetACP() != GetConsoleCP())
3690 {
3691 char buf[50];
3692
3693 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3694 p_tenc = vim_strsave((char_u *)buf);
3695 if (p_tenc != NULL)
3696 {
3697 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003698 if (opt_idx >= 0)
3699 {
3700 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3701 options[opt_idx].flags |= P_DEF_ALLOCED;
3702 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703 convert_setup(&input_conv, p_tenc, p_enc);
3704 convert_setup(&output_conv, p_enc, p_tenc);
3705 }
3706 else
3707 p_tenc = empty_option;
3708 }
3709# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003710# if defined(WIN3264) && defined(FEAT_MBYTE)
3711 /* $HOME may have characters in active code page. */
3712 init_homedir();
3713# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003714 }
3715 else
3716 {
3717 vim_free(p_enc);
3718 p_enc = save_enc;
3719 }
3720 }
3721#endif
3722
3723#ifdef FEAT_MULTI_LANG
3724 /* Set the default for 'helplang'. */
3725 set_helplang_default(get_mess_lang());
3726#endif
3727}
3728
3729/*
3730 * Set an option to its default value.
3731 * This does not take care of side effects!
3732 */
3733 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003734set_option_default(
3735 int opt_idx,
3736 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3737 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738{
3739 char_u *varp; /* pointer to variable for current option */
3740 int dvi; /* index in def_val[] */
3741 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003742 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3744
3745 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3746 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003747 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 {
3749 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3750 if (flags & P_STRING)
3751 {
3752 /* Use set_string_option_direct() for local options to handle
3753 * freeing and allocating the value. */
3754 if (options[opt_idx].indir != PV_NONE)
3755 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003756 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757 else
3758 {
3759 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3760 free_string_option(*(char_u **)(varp));
3761 *(char_u **)varp = options[opt_idx].def_val[dvi];
3762 options[opt_idx].flags &= ~P_ALLOCED;
3763 }
3764 }
3765 else if (flags & P_NUM)
3766 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003767 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768 win_comp_scroll(curwin);
3769 else
3770 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003771 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 /* May also set global value for local option. */
3773 if (both)
3774 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3775 *(long *)varp;
3776 }
3777 }
3778 else /* P_BOOL */
3779 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003780 /* the cast to long is required for Manx C, long_i is needed for
3781 * MSVC */
3782 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003783#ifdef UNIX
3784 /* 'modeline' defaults to off for root */
3785 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3786 *(int *)varp = FALSE;
3787#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 /* May also set global value for local option. */
3789 if (both)
3790 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3791 *(int *)varp;
3792 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003793
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003794 /* The default value is not insecure. */
3795 flagsp = insecure_flag(opt_idx, opt_flags);
3796 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 }
3798
3799#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003800 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801#endif
3802}
3803
3804/*
3805 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003806 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 */
3808 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003809set_options_default(
3810 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811{
3812 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003814 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815
3816 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003817 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003818#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003819 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003820 || (TRUE
3821# if defined(FEAT_MBYTE)
3822 && options[i].var != (char_u *)&p_enc
3823# endif
3824# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003825 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003826 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003827# endif
3828 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003829#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003830 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831 set_option_default(i, opt_flags, p_cp);
3832
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003834 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003836#ifdef FEAT_CINDENT
3837 parse_cino(curbuf);
3838#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839}
3840
3841/*
3842 * Set the Vi-default value of a string option.
3843 * Used for 'sh', 'backupskip' and 'term'.
3844 */
3845 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003846set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847{
3848 char_u *p;
3849 int opt_idx;
3850
3851 p = vim_strsave(val);
3852 if (p != NULL) /* we don't want a NULL */
3853 {
3854 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003855 if (opt_idx >= 0)
3856 {
3857 if (options[opt_idx].flags & P_DEF_ALLOCED)
3858 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3859 options[opt_idx].def_val[VI_DEFAULT] = p;
3860 options[opt_idx].flags |= P_DEF_ALLOCED;
3861 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 }
3863}
3864
3865/*
3866 * Set the Vi-default value of a number option.
3867 * Used for 'lines' and 'columns'.
3868 */
3869 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003870set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003872 int opt_idx;
3873
3874 opt_idx = findoption((char_u *)name);
3875 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003876 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877}
3878
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003879#if defined(EXITFREE) || defined(PROTO)
3880/*
3881 * Free all options.
3882 */
3883 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003884free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003885{
3886 int i;
3887
3888 for (i = 0; !istermoption(&options[i]); i++)
3889 {
3890 if (options[i].indir == PV_NONE)
3891 {
3892 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003893 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003894 free_string_option(*(char_u **)options[i].var);
3895 if (options[i].flags & P_DEF_ALLOCED)
3896 free_string_option(options[i].def_val[VI_DEFAULT]);
3897 }
3898 else if (options[i].var != VAR_WIN
3899 && (options[i].flags & P_STRING))
3900 /* buffer-local option: free global value */
3901 free_string_option(*(char_u **)options[i].var);
3902 }
3903}
3904#endif
3905
3906
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907/*
3908 * Initialize the options, part two: After getting Rows and Columns and
3909 * setting 'term'.
3910 */
3911 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003912set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003914 int idx;
3915
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003917 * 'scroll' defaults to half the window height. The stored default is zero,
3918 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003920 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003921 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003922 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 comp_col();
3924
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003925 /*
3926 * 'window' is only for backwards compatibility with Vi.
3927 * Default is Rows - 1.
3928 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003929 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003930 p_window = Rows - 1;
3931 set_number_default("window", Rows - 1);
3932
Bram Moolenaarf740b292006-02-16 22:11:02 +00003933 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003934#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003935 /*
3936 * If 'background' wasn't set by the user, try guessing the value,
3937 * depending on the terminal name. Only need to check for terminals
3938 * with a dark background, that can handle color.
3939 */
3940 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003941 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3942 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003944 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003945 /* don't mark it as set, when starting the GUI it may be
3946 * changed again */
3947 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 }
3949#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003950
3951#ifdef CURSOR_SHAPE
3952 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3953#endif
3954#ifdef FEAT_MOUSESHAPE
3955 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3956#endif
3957#ifdef FEAT_PRINTER
3958 (void)parse_printoptions(); /* parse 'printoptions' default value */
3959#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960}
3961
3962/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003963 * Return "dark" or "light" depending on the kind of terminal.
3964 * This is just guessing! Recognized are:
3965 * "linux" Linux console
3966 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003967 * "cygwin.*" Cygwin shell
3968 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003969 * We also check the COLORFGBG environment variable, which is set by
3970 * rxvt and derivatives. This variable contains either two or three
3971 * values separated by semicolons; we want the last value in either
3972 * case. If this value is 0-6 or 8, our background is dark.
3973 */
3974 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003975term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003976{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003977#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003978 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003979 return (char_u *)"dark";
3980#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003981 char_u *p;
3982
Bram Moolenaarf740b292006-02-16 22:11:02 +00003983 if (STRCMP(T_NAME, "linux") == 0
3984 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003985 || STRNCMP(T_NAME, "cygwin", 6) == 0
3986 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003987 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3988 && (p = vim_strrchr(p, ';')) != NULL
3989 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3990 && p[2] == NUL))
3991 return (char_u *)"dark";
3992 return (char_u *)"light";
3993#endif
3994}
3995
3996/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003997 * Initialize the options, part three: After reading the .vimrc
3998 */
3999 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004000set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004001{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004002#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003/*
4004 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4005 * This is done after other initializations, where 'shell' might have been
4006 * set, but only if they have not been set before.
4007 */
4008 char_u *p;
4009 int idx_srr;
4010 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004011# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012 int idx_sp;
4013 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004014# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015
4016 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004017 if (idx_srr < 0)
4018 do_srr = FALSE;
4019 else
4020 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004021# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004023 if (idx_sp < 0)
4024 do_sp = FALSE;
4025 else
4026 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004027# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004028 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 if (p != NULL)
4030 {
4031 /*
4032 * Default for p_sp is "| tee", for p_srr is ">".
4033 * For known shells it is changed here to include stderr.
4034 */
4035 if ( fnamecmp(p, "csh") == 0
4036 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004037# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 || fnamecmp(p, "csh.exe") == 0
4039 || fnamecmp(p, "tcsh.exe") == 0
4040# endif
4041 )
4042 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004043# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 if (do_sp)
4045 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004046# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004048# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004050# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4052 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004053# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 if (do_srr)
4055 {
4056 p_srr = (char_u *)">&";
4057 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4058 }
4059 }
4060 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 if ( fnamecmp(p, "sh") == 0
4063 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004064 || fnamecmp(p, "mksh") == 0
4065 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004067 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004069 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 || fnamecmp(p, "cmd") == 0
4072 || fnamecmp(p, "sh.exe") == 0
4073 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004074 || fnamecmp(p, "mksh.exe") == 0
4075 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004077 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 || fnamecmp(p, "bash.exe") == 0
4079 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004081 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004083# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 if (do_sp)
4085 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004088# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004090# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4092 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 if (do_srr)
4095 {
4096 p_srr = (char_u *)">%s 2>&1";
4097 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4098 }
4099 }
4100 vim_free(p);
4101 }
4102#endif
4103
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004104#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004106 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4107 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 * This is done after other initializations, where 'shell' might have been
4109 * set, but only if they have not been set before. Default for p_shcf is
4110 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004111 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004113 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 {
4115 int idx3;
4116
4117 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004118 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 {
4120 p_shcf = (char_u *)"-c";
4121 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4122 }
4123
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 /* Somehow Win32 requires the quotes around the redirection too */
4125 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004126 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
4128 p_sxq = (char_u *)"\"";
4129 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004132 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4133 {
4134 int idx3;
4135
4136 /*
4137 * cmd.exe on Windows will strip the first and last double quote given
4138 * on the command line, e.g. most of the time things like:
4139 * cmd /c "my path/to/echo" "my args to echo"
4140 * become:
4141 * my path/to/echo" "my args to echo
4142 * when executed.
4143 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004144 * To avoid this, set shellxquote to surround the command in
4145 * parenthesis. This appears to make most commands work, without
4146 * breaking commands that worked previously, such as
4147 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004148 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004149 idx3 = findoption((char_u *)"sxq");
4150 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4151 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004152 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004153 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4154 }
4155
Bram Moolenaara64ba222012-02-12 23:23:31 +01004156 idx3 = findoption((char_u *)"shcf");
4157 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4158 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004159 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004160 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4161 }
4162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163#endif
4164
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004165 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004166 {
4167 int idx_ffs = findoption((char_u *)"ffs");
4168
4169 /* Apply the first entry of 'fileformats' to the initial buffer. */
4170 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4171 set_fileformat(default_fileformat(), OPT_LOCAL);
4172 }
4173
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174#ifdef FEAT_TITLE
4175 set_title_defaults();
4176#endif
4177}
4178
4179#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4180/*
4181 * When 'helplang' is still at its default value, set it to "lang".
4182 * Only the first two characters of "lang" are used.
4183 */
4184 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004185set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186{
4187 int idx;
4188
4189 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4190 return;
4191 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004192 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 {
4194 if (options[idx].flags & P_ALLOCED)
4195 free_string_option(p_hlg);
4196 p_hlg = vim_strsave(lang);
4197 if (p_hlg == NULL)
4198 p_hlg = empty_option;
4199 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004200 {
4201 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4202 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4203 {
4204 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4205 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4206 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004208 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004209 options[idx].flags |= P_ALLOCED;
4210 }
4211}
4212#endif
4213
4214#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004215static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004216
4217 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004218gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219{
4220 if (gui_get_lightness(gui.back_pixel) < 127)
4221 return (char_u *)"dark";
4222 return (char_u *)"light";
4223}
4224
4225/*
4226 * Option initializations that can only be done after opening the GUI window.
4227 */
4228 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004229init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004230{
4231 /* Set the 'background' option according to the lightness of the
4232 * background color, unless the user has set it already. */
4233 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4234 {
4235 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4236 highlight_changed();
4237 }
4238}
4239#endif
4240
4241#ifdef FEAT_TITLE
4242/*
4243 * 'title' and 'icon' only default to true if they have not been set or reset
4244 * in .vimrc and we can read the old value.
4245 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4246 * they can be reset. This reduces startup time when using X on a remote
4247 * machine.
4248 */
4249 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004250set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004251{
4252 int idx1;
4253 long val;
4254
4255 /*
4256 * If GUI is (going to be) used, we can always set the window title and
4257 * icon name. Saves a bit of time, because the X11 display server does
4258 * not need to be contacted.
4259 */
4260 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004261 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262 {
4263#ifdef FEAT_GUI
4264 if (gui.starting || gui.in_use)
4265 val = TRUE;
4266 else
4267#endif
4268 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004269 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270 p_title = val;
4271 }
4272 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004273 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274 {
4275#ifdef FEAT_GUI
4276 if (gui.starting || gui.in_use)
4277 val = TRUE;
4278 else
4279#endif
4280 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004281 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282 p_icon = val;
4283 }
4284}
4285#endif
4286
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004287#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4288 static void
4289trigger_optionsset_string(
4290 int opt_idx,
4291 int opt_flags,
4292 char_u *oldval,
4293 char_u *newval)
4294{
4295 if (oldval != NULL && newval != NULL)
4296 {
4297 char_u buf_type[7];
4298
4299 sprintf((char *)buf_type, "%s",
4300 (opt_flags & OPT_LOCAL) ? "local" : "global");
4301 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4302 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4303 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4304 apply_autocmds(EVENT_OPTIONSET,
4305 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4306 reset_v_option_vars();
4307 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004308}
4309#endif
4310
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311/*
4312 * Parse 'arg' for option settings.
4313 *
4314 * 'arg' may be IObuff, but only when no errors can be present and option
4315 * does not need to be expanded with option_expand().
4316 * "opt_flags":
4317 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004318 * OPT_GLOBAL for ":setglobal"
4319 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004320 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004321 * OPT_WINONLY to only set window-local options
4322 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004323 *
4324 * returns FAIL if an error is detected, OK otherwise
4325 */
4326 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004327do_set(
4328 char_u *arg, /* option string (may be written to!) */
4329 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004330{
4331 int opt_idx;
4332 char_u *errmsg;
4333 char_u errbuf[80];
4334 char_u *startarg;
4335 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4336 int nextchar; /* next non-white char after option name */
4337 int afterchar; /* character just after option name */
4338 int len;
4339 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004340 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004341 int key;
4342 long_u flags; /* flags for current option */
4343 char_u *varp = NULL; /* pointer to variable for current option */
4344 int did_show = FALSE; /* already showed one value */
4345 int adding; /* "opt+=arg" */
4346 int prepending; /* "opt^=arg" */
4347 int removing; /* "opt-=arg" */
4348 int cp_val = 0;
4349 char_u key_name[2];
4350
4351 if (*arg == NUL)
4352 {
4353 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004354 did_show = TRUE;
4355 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004356 }
4357
4358 while (*arg != NUL) /* loop to process all options */
4359 {
4360 errmsg = NULL;
4361 startarg = arg; /* remember for error message */
4362
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004363 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4364 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004365 {
4366 /*
4367 * ":set all" show all options.
4368 * ":set all&" set all options to their default value.
4369 */
4370 arg += 3;
4371 if (*arg == '&')
4372 {
4373 ++arg;
4374 /* Only for :set command set global value of local options. */
4375 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004376 didset_options();
4377 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004378 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 }
4380 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004381 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004382 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004383 did_show = TRUE;
4384 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004386 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387 {
4388 showoptions(2, opt_flags);
4389 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004390 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004391 arg += 7;
4392 }
4393 else
4394 {
4395 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004396 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004397 {
4398 prefix = 0;
4399 arg += 2;
4400 }
4401 else if (STRNCMP(arg, "inv", 3) == 0)
4402 {
4403 prefix = 2;
4404 arg += 3;
4405 }
4406
4407 /* find end of name */
4408 key = 0;
4409 if (*arg == '<')
4410 {
4411 nextchar = 0;
4412 opt_idx = -1;
4413 /* look out for <t_>;> */
4414 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4415 len = 5;
4416 else
4417 {
4418 len = 1;
4419 while (arg[len] != NUL && arg[len] != '>')
4420 ++len;
4421 }
4422 if (arg[len] != '>')
4423 {
4424 errmsg = e_invarg;
4425 goto skip;
4426 }
4427 arg[len] = NUL; /* put NUL after name */
4428 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4429 opt_idx = findoption(arg + 1);
4430 arg[len++] = '>'; /* restore '>' */
4431 if (opt_idx == -1)
4432 key = find_key_option(arg + 1);
4433 }
4434 else
4435 {
4436 len = 0;
4437 /*
4438 * The two characters after "t_" may not be alphanumeric.
4439 */
4440 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4441 len = 4;
4442 else
4443 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4444 ++len;
4445 nextchar = arg[len];
4446 arg[len] = NUL; /* put NUL after name */
4447 opt_idx = findoption(arg);
4448 arg[len] = nextchar; /* restore nextchar */
4449 if (opt_idx == -1)
4450 key = find_key_option(arg);
4451 }
4452
4453 /* remember character after option name */
4454 afterchar = arg[len];
4455
4456 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004457 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004458 ++len;
4459
4460 adding = FALSE;
4461 prepending = FALSE;
4462 removing = FALSE;
4463 if (arg[len] != NUL && arg[len + 1] == '=')
4464 {
4465 if (arg[len] == '+')
4466 {
4467 adding = TRUE; /* "+=" */
4468 ++len;
4469 }
4470 else if (arg[len] == '^')
4471 {
4472 prepending = TRUE; /* "^=" */
4473 ++len;
4474 }
4475 else if (arg[len] == '-')
4476 {
4477 removing = TRUE; /* "-=" */
4478 ++len;
4479 }
4480 }
4481 nextchar = arg[len];
4482
4483 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4484 {
4485 errmsg = (char_u *)N_("E518: Unknown option");
4486 goto skip;
4487 }
4488
4489 if (opt_idx >= 0)
4490 {
4491 if (options[opt_idx].var == NULL) /* hidden option: skip */
4492 {
4493 /* Only give an error message when requesting the value of
4494 * a hidden option, ignore setting it. */
4495 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4496 && (!(options[opt_idx].flags & P_BOOL)
4497 || nextchar == '?'))
4498 errmsg = (char_u *)N_("E519: Option not supported");
4499 goto skip;
4500 }
4501
4502 flags = options[opt_idx].flags;
4503 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4504 }
4505 else
4506 {
4507 flags = P_STRING;
4508 if (key < 0)
4509 {
4510 key_name[0] = KEY2TERMCAP0(key);
4511 key_name[1] = KEY2TERMCAP1(key);
4512 }
4513 else
4514 {
4515 key_name[0] = KS_KEY;
4516 key_name[1] = (key & 0xff);
4517 }
4518 }
4519
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004520 /* Skip all options that are not window-local (used when showing
4521 * an already loaded buffer in a window). */
4522 if ((opt_flags & OPT_WINONLY)
4523 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4524 goto skip;
4525
Bram Moolenaara3227e22006-03-08 21:32:40 +00004526 /* Skip all options that are window-local (used for :vimgrep). */
4527 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4528 && options[opt_idx].var == VAR_WIN)
4529 goto skip;
4530
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004531 /* Disallow changing some options from modelines. */
4532 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004533 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004534 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004535 {
4536 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4537 goto skip;
4538 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004539#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004540 /* In diff mode some options are overruled. This avoids that
4541 * 'foldmethod' becomes "marker" instead of "diff" and that
4542 * "wrap" gets set. */
4543 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004544 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004545 && (
4546#ifdef FEAT_FOLDING
4547 options[opt_idx].indir == PV_FDM ||
4548#endif
4549 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004550 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004551#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004552 }
4553
4554#ifdef HAVE_SANDBOX
4555 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004556 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004557 {
4558 errmsg = (char_u *)_(e_sandbox);
4559 goto skip;
4560 }
4561#endif
4562
4563 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4564 {
4565 arg += len;
4566 cp_val = p_cp;
4567 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4568 {
4569 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4570 {
4571 cp_val = FALSE;
4572 arg += 3;
4573 }
4574 else /* "opt&vi": set to Vi default */
4575 {
4576 cp_val = TRUE;
4577 arg += 2;
4578 }
4579 }
4580 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004581 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004582 {
4583 errmsg = e_trailing;
4584 goto skip;
4585 }
4586 }
4587
4588 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004589 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4590 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004591 */
4592 if (nextchar == '?'
4593 || (prefix == 1
4594 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4595 && !(flags & P_BOOL)))
4596 {
4597 /*
4598 * print value
4599 */
4600 if (did_show)
4601 msg_putchar('\n'); /* cursor below last one */
4602 else
4603 {
4604 gotocmdline(TRUE); /* cursor at status line */
4605 did_show = TRUE; /* remember that we did a line */
4606 }
4607 if (opt_idx >= 0)
4608 {
4609 showoneopt(&options[opt_idx], opt_flags);
4610#ifdef FEAT_EVAL
4611 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004612 {
4613 /* Mention where the option was last set. */
4614 if (varp == options[opt_idx].var)
4615 last_set_msg(options[opt_idx].scriptID);
4616 else if ((int)options[opt_idx].indir & PV_WIN)
4617 last_set_msg(curwin->w_p_scriptID[
4618 (int)options[opt_idx].indir & PV_MASK]);
4619 else if ((int)options[opt_idx].indir & PV_BUF)
4620 last_set_msg(curbuf->b_p_scriptID[
4621 (int)options[opt_idx].indir & PV_MASK]);
4622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623#endif
4624 }
4625 else
4626 {
4627 char_u *p;
4628
4629 p = find_termcode(key_name);
4630 if (p == NULL)
4631 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004632 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004633 goto skip;
4634 }
4635 else
4636 (void)show_one_termcode(key_name, p, TRUE);
4637 }
4638 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004639 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004640 errmsg = e_trailing;
4641 }
4642 else
4643 {
4644 if (flags & P_BOOL) /* boolean */
4645 {
4646 if (nextchar == '=' || nextchar == ':')
4647 {
4648 errmsg = e_invarg;
4649 goto skip;
4650 }
4651
4652 /*
4653 * ":set opt!": invert
4654 * ":set opt&": reset to default value
4655 * ":set opt<": reset to global value
4656 */
4657 if (nextchar == '!')
4658 value = *(int *)(varp) ^ 1;
4659 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004660 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004661 ((flags & P_VI_DEF) || cp_val)
4662 ? VI_DEFAULT : VIM_DEFAULT];
4663 else if (nextchar == '<')
4664 {
4665 /* For 'autoread' -1 means to use global value. */
4666 if ((int *)varp == &curbuf->b_p_ar
4667 && opt_flags == OPT_LOCAL)
4668 value = -1;
4669 else
4670 value = *(int *)get_varp_scope(&(options[opt_idx]),
4671 OPT_GLOBAL);
4672 }
4673 else
4674 {
4675 /*
4676 * ":set invopt": invert
4677 * ":set opt" or ":set noopt": set or reset
4678 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004679 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004680 {
4681 errmsg = e_trailing;
4682 goto skip;
4683 }
4684 if (prefix == 2) /* inv */
4685 value = *(int *)(varp) ^ 1;
4686 else
4687 value = prefix;
4688 }
4689
4690 errmsg = set_bool_option(opt_idx, varp, (int)value,
4691 opt_flags);
4692 }
4693 else /* numeric or string */
4694 {
4695 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4696 || prefix != 1)
4697 {
4698 errmsg = e_invarg;
4699 goto skip;
4700 }
4701
4702 if (flags & P_NUM) /* numeric */
4703 {
4704 /*
4705 * Different ways to set a number option:
4706 * & set to default value
4707 * < set to global value
4708 * <xx> accept special key codes for 'wildchar'
4709 * c accept any non-digit for 'wildchar'
4710 * [-]0-9 set number
4711 * other error
4712 */
4713 ++arg;
4714 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004715 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 ((flags & P_VI_DEF) || cp_val)
4717 ? VI_DEFAULT : VIM_DEFAULT];
4718 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004719 {
4720 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4721 * use the global value. */
4722 if ((long *)varp == &curbuf->b_p_ul
4723 && opt_flags == OPT_LOCAL)
4724 value = NO_LOCAL_UNDOLEVEL;
4725 else
4726 value = *(long *)get_varp_scope(
4727 &(options[opt_idx]), OPT_GLOBAL);
4728 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004729 else if (((long *)varp == &p_wc
4730 || (long *)varp == &p_wcm)
4731 && (*arg == '<'
4732 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004733 || (*arg != NUL
4734 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004735 && !VIM_ISDIGIT(*arg))))
4736 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004737 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004738 if (value == 0 && (long *)varp != &p_wcm)
4739 {
4740 errmsg = e_invarg;
4741 goto skip;
4742 }
4743 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004744 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4745 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004746 /* Allow negative (for 'undolevels'), octal and
4747 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004748 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4749 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004750 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004751 {
4752 errmsg = e_invarg;
4753 goto skip;
4754 }
4755 }
4756 else
4757 {
4758 errmsg = (char_u *)N_("E521: Number required after =");
4759 goto skip;
4760 }
4761
4762 if (adding)
4763 value = *(long *)varp + value;
4764 if (prepending)
4765 value = *(long *)varp * value;
4766 if (removing)
4767 value = *(long *)varp - value;
4768 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004769 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004770 }
4771 else if (opt_idx >= 0) /* string */
4772 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004773 char_u *save_arg = NULL;
4774 char_u *s = NULL;
4775 char_u *oldval = NULL; /* previous value if *varp */
4776 char_u *newval;
4777 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004778#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004779 char_u *saved_origval = NULL;
4780 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004781#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004782 unsigned newlen;
4783 int comma;
4784 int bs;
4785 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004786 was allocated */
4787
4788 /* When using ":set opt=val" for a global option
4789 * with a local value the local value will be
4790 * reset, use the global value here. */
4791 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004792 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004793 varp = options[opt_idx].var;
4794
4795 /* The old value is kept until we are sure that the
4796 * new value is valid. */
4797 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004798
4799 /* When setting the local value of a global
4800 * option, the old value may be the global value. */
4801 if (((int)options[opt_idx].indir & PV_BOTH)
4802 && (opt_flags & OPT_LOCAL))
4803 origval = *(char_u **)get_varp(
4804 &options[opt_idx]);
4805 else
4806 origval = oldval;
4807
Bram Moolenaar071d4272004-06-13 20:20:40 +00004808 if (nextchar == '&') /* set to default val */
4809 {
4810 newval = options[opt_idx].def_val[
4811 ((flags & P_VI_DEF) || cp_val)
4812 ? VI_DEFAULT : VIM_DEFAULT];
4813 if ((char_u **)varp == &p_bg)
4814 {
4815 /* guess the value of 'background' */
4816#ifdef FEAT_GUI
4817 if (gui.in_use)
4818 newval = gui_bg_default();
4819 else
4820#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004821 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 }
4823
4824 /* expand environment variables and ~ (since the
4825 * default value was already expanded, only
4826 * required when an environment variable was set
4827 * later */
4828 if (newval == NULL)
4829 newval = empty_option;
4830 else
4831 {
4832 s = option_expand(opt_idx, newval);
4833 if (s == NULL)
4834 s = newval;
4835 newval = vim_strsave(s);
4836 }
4837 new_value_alloced = TRUE;
4838 }
4839 else if (nextchar == '<') /* set to global val */
4840 {
4841 newval = vim_strsave(*(char_u **)get_varp_scope(
4842 &(options[opt_idx]), OPT_GLOBAL));
4843 new_value_alloced = TRUE;
4844 }
4845 else
4846 {
4847 ++arg; /* jump to after the '=' or ':' */
4848
4849 /*
4850 * Set 'keywordprg' to ":help" if an empty
4851 * value was passed to :set by the user.
4852 * Misuse errbuf[] for the resulting string.
4853 */
4854 if (varp == (char_u *)&p_kp
4855 && (*arg == NUL || *arg == ' '))
4856 {
4857 STRCPY(errbuf, ":help");
4858 save_arg = arg;
4859 arg = errbuf;
4860 }
4861 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004862 * Convert 'backspace' number to string, for
4863 * adding, prepending and removing string.
4864 */
4865 else if (varp == (char_u *)&p_bs
4866 && VIM_ISDIGIT(**(char_u **)varp))
4867 {
4868 i = getdigits((char_u **)varp);
4869 switch (i)
4870 {
4871 case 0:
4872 *(char_u **)varp = empty_option;
4873 break;
4874 case 1:
4875 *(char_u **)varp = vim_strsave(
4876 (char_u *)"indent,eol");
4877 break;
4878 case 2:
4879 *(char_u **)varp = vim_strsave(
4880 (char_u *)"indent,eol,start");
4881 break;
4882 }
4883 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004884 if (origval == oldval)
4885 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004886 oldval = *(char_u **)varp;
4887 }
4888 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004889 * Convert 'whichwrap' number to string, for
4890 * backwards compatibility with Vim 3.0.
4891 * Misuse errbuf[] for the resulting string.
4892 */
4893 else if (varp == (char_u *)&p_ww
4894 && VIM_ISDIGIT(*arg))
4895 {
4896 *errbuf = NUL;
4897 i = getdigits(&arg);
4898 if (i & 1)
4899 STRCAT(errbuf, "b,");
4900 if (i & 2)
4901 STRCAT(errbuf, "s,");
4902 if (i & 4)
4903 STRCAT(errbuf, "h,l,");
4904 if (i & 8)
4905 STRCAT(errbuf, "<,>,");
4906 if (i & 16)
4907 STRCAT(errbuf, "[,],");
4908 if (*errbuf != NUL) /* remove trailing , */
4909 errbuf[STRLEN(errbuf) - 1] = NUL;
4910 save_arg = arg;
4911 arg = errbuf;
4912 }
4913 /*
4914 * Remove '>' before 'dir' and 'bdir', for
4915 * backwards compatibility with version 3.0
4916 */
4917 else if ( *arg == '>'
4918 && (varp == (char_u *)&p_dir
4919 || varp == (char_u *)&p_bdir))
4920 {
4921 ++arg;
4922 }
4923
Bram Moolenaar071d4272004-06-13 20:20:40 +00004924 /*
4925 * Copy the new string into allocated memory.
4926 * Can't use set_string_option_direct(), because
4927 * we need to remove the backslashes.
4928 */
4929 /* get a bit too much */
4930 newlen = (unsigned)STRLEN(arg) + 1;
4931 if (adding || prepending || removing)
4932 newlen += (unsigned)STRLEN(origval) + 1;
4933 newval = alloc(newlen);
4934 if (newval == NULL) /* out of mem, don't change */
4935 break;
4936 s = newval;
4937
4938 /*
4939 * Copy the string, skip over escaped chars.
4940 * For MS-DOS and WIN32 backslashes before normal
4941 * file name characters are not removed, and keep
4942 * backslash at start, for "\\machine\path", but
4943 * do remove it for "\\\\machine\\path".
4944 * The reverse is found in ExpandOldSetting().
4945 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004946 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004947 {
4948 if (*arg == '\\' && arg[1] != NUL
4949#ifdef BACKSLASH_IN_FILENAME
4950 && !((flags & P_EXPAND)
4951 && vim_isfilec(arg[1])
4952 && (arg[1] != '\\'
4953 || (s == newval
4954 && arg[2] != '\\')))
4955#endif
4956 )
4957 ++arg; /* remove backslash */
4958#ifdef FEAT_MBYTE
4959 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004960 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 {
4962 /* copy multibyte char */
4963 mch_memmove(s, arg, (size_t)i);
4964 arg += i;
4965 s += i;
4966 }
4967 else
4968#endif
4969 *s++ = *arg++;
4970 }
4971 *s = NUL;
4972
4973 /*
4974 * Expand environment variables and ~.
4975 * Don't do it when adding without inserting a
4976 * comma.
4977 */
4978 if (!(adding || prepending || removing)
4979 || (flags & P_COMMA))
4980 {
4981 s = option_expand(opt_idx, newval);
4982 if (s != NULL)
4983 {
4984 vim_free(newval);
4985 newlen = (unsigned)STRLEN(s) + 1;
4986 if (adding || prepending || removing)
4987 newlen += (unsigned)STRLEN(origval) + 1;
4988 newval = alloc(newlen);
4989 if (newval == NULL)
4990 break;
4991 STRCPY(newval, s);
4992 }
4993 }
4994
4995 /* locate newval[] in origval[] when removing it
4996 * and when adding to avoid duplicates */
4997 i = 0; /* init for GCC */
4998 if (removing || (flags & P_NODUP))
4999 {
5000 i = (int)STRLEN(newval);
5001 bs = 0;
5002 for (s = origval; *s; ++s)
5003 {
5004 if ((!(flags & P_COMMA)
5005 || s == origval
5006 || (s[-1] == ',' && !(bs & 1)))
5007 && STRNCMP(s, newval, i) == 0
5008 && (!(flags & P_COMMA)
5009 || s[i] == ','
5010 || s[i] == NUL))
5011 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005012 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005013 * even number of backslashes or a single
5014 * backslash preceded by a comma before it
5015 * is recognized as a separator */
5016 if ((s > origval + 1
5017 && s[-1] == '\\'
5018 && s[-2] != ',')
5019 || (s == origval + 1
5020 && s[-1] == '\\'))
5021
Bram Moolenaar071d4272004-06-13 20:20:40 +00005022 ++bs;
5023 else
5024 bs = 0;
5025 }
5026
5027 /* do not add if already there */
5028 if ((adding || prepending) && *s)
5029 {
5030 prepending = FALSE;
5031 adding = FALSE;
5032 STRCPY(newval, origval);
5033 }
5034 }
5035
5036 /* concatenate the two strings; add a ',' if
5037 * needed */
5038 if (adding || prepending)
5039 {
5040 comma = ((flags & P_COMMA) && *origval != NUL
5041 && *newval != NUL);
5042 if (adding)
5043 {
5044 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005045 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005046 if (comma && i > 1
5047 && (flags & P_ONECOMMA) == P_ONECOMMA
5048 && origval[i - 1] == ','
5049 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005050 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005051 mch_memmove(newval + i + comma, newval,
5052 STRLEN(newval) + 1);
5053 mch_memmove(newval, origval, (size_t)i);
5054 }
5055 else
5056 {
5057 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005058 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005059 }
5060 if (comma)
5061 newval[i] = ',';
5062 }
5063
5064 /* Remove newval[] from origval[]. (Note: "i" has
5065 * been set above and is used here). */
5066 if (removing)
5067 {
5068 STRCPY(newval, origval);
5069 if (*s)
5070 {
5071 /* may need to remove a comma */
5072 if (flags & P_COMMA)
5073 {
5074 if (s == origval)
5075 {
5076 /* include comma after string */
5077 if (s[i] == ',')
5078 ++i;
5079 }
5080 else
5081 {
5082 /* include comma before string */
5083 --s;
5084 ++i;
5085 }
5086 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005087 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005088 }
5089 }
5090
5091 if (flags & P_FLAGLIST)
5092 {
5093 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005094 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005095 {
5096 /* if options have P_FLAGLIST and
5097 * P_ONECOMMA such as 'whichwrap' */
5098 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005099 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005100 if (*s != ',' && *(s + 1) == ','
5101 && vim_strchr(s + 2, *s) != NULL)
5102 {
5103 /* Remove the duplicated value and
5104 * the next comma. */
5105 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005106 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005108 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005109 else
5110 {
5111 if ((!(flags & P_COMMA) || *s != ',')
5112 && vim_strchr(s + 1, *s) != NULL)
5113 {
5114 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005115 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005116 }
5117 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005118 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005119 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120 }
5121
5122 if (save_arg != NULL) /* number for 'whichwrap' */
5123 arg = save_arg;
5124 new_value_alloced = TRUE;
5125 }
5126
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005127 /*
5128 * Set the new value.
5129 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005130 *(char_u **)(varp) = newval;
5131
Bram Moolenaar53744302015-07-17 17:38:22 +02005132#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005133 if (!starting
5134# ifdef FEAT_CRYPT
5135 && options[opt_idx].indir != PV_KEY
5136# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005137 && origval != NULL && newval != NULL)
5138 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005139 /* origval may be freed by
5140 * did_set_string_option(), make a copy. */
5141 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005142 /* newval (and varp) may become invalid if the
5143 * buffer is closed by autocommands. */
5144 saved_newval = vim_strsave(newval);
5145 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005146#endif
5147
Bram Moolenaar071d4272004-06-13 20:20:40 +00005148 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005149 * ":set" on local options. Note: when setting 'syntax'
5150 * or 'filetype' autocommands may be triggered that can
5151 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5153 new_value_alloced, oldval, errbuf, opt_flags);
5154
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005155#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5156 if (errmsg == NULL)
5157 trigger_optionsset_string(opt_idx, opt_flags,
5158 saved_origval, saved_newval);
5159 vim_free(saved_origval);
5160 vim_free(saved_newval);
5161#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005162 /* If error detected, print the error message. */
5163 if (errmsg != NULL)
5164 goto skip;
5165 }
5166 else /* key code option */
5167 {
5168 char_u *p;
5169
5170 if (nextchar == '&')
5171 {
5172 if (add_termcap_entry(key_name, TRUE) == FAIL)
5173 errmsg = (char_u *)N_("E522: Not found in termcap");
5174 }
5175 else
5176 {
5177 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005178 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005179 if (*p == '\\' && p[1] != NUL)
5180 ++p;
5181 nextchar = *p;
5182 *p = NUL;
5183 add_termcode(key_name, arg, FALSE);
5184 *p = nextchar;
5185 }
5186 if (full_screen)
5187 ttest(FALSE);
5188 redraw_all_later(CLEAR);
5189 }
5190 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005191
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005193 did_set_option(opt_idx, opt_flags,
5194 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005195 }
5196
5197skip:
5198 /*
5199 * Advance to next argument.
5200 * - skip until a blank found, taking care of backslashes
5201 * - skip blanks
5202 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5203 */
5204 for (i = 0; i < 2 ; ++i)
5205 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005206 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005207 if (*arg++ == '\\' && *arg != NUL)
5208 ++arg;
5209 arg = skipwhite(arg);
5210 if (*arg != '=')
5211 break;
5212 }
5213 }
5214
5215 if (errmsg != NULL)
5216 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005217 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005218 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005219 if (i + (arg - startarg) < IOSIZE)
5220 {
5221 /* append the argument with the error */
5222 STRCAT(IObuff, ": ");
5223 mch_memmove(IObuff + i, startarg, (arg - startarg));
5224 IObuff[i + (arg - startarg)] = NUL;
5225 }
5226 /* make sure all characters are printable */
5227 trans_characters(IObuff, IOSIZE);
5228
5229 ++no_wait_return; /* wait_return done later */
5230 emsg(IObuff); /* show error highlighted */
5231 --no_wait_return;
5232
5233 return FAIL;
5234 }
5235
5236 arg = skipwhite(arg);
5237 }
5238
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005239theend:
5240 if (silent_mode && did_show)
5241 {
5242 /* After displaying option values in silent mode. */
5243 silent_mode = FALSE;
5244 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5245 msg_putchar('\n');
5246 cursor_on(); /* msg_start() switches it off */
5247 out_flush();
5248 silent_mode = TRUE;
5249 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5250 }
5251
Bram Moolenaar071d4272004-06-13 20:20:40 +00005252 return OK;
5253}
5254
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005255/*
5256 * Call this when an option has been given a new value through a user command.
5257 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5258 */
5259 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005260did_set_option(
5261 int opt_idx,
5262 int opt_flags, /* possibly with OPT_MODELINE */
5263 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005264{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005265 long_u *p;
5266
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005267 options[opt_idx].flags |= P_WAS_SET;
5268
5269 /* When an option is set in the sandbox, from a modeline or in secure mode
5270 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005271 * flag. */
5272 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005273 if (secure
5274#ifdef HAVE_SANDBOX
5275 || sandbox != 0
5276#endif
5277 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005278 *p = *p | P_INSECURE;
5279 else if (new_value)
5280 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005281}
5282
Bram Moolenaar071d4272004-06-13 20:20:40 +00005283 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005284illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285{
5286 if (errbuf == NULL)
5287 return (char_u *)"";
5288 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005289 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290 return errbuf;
5291}
5292
5293/*
5294 * Convert a key name or string into a key value.
5295 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005296 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005297 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005298 int
5299string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300{
5301 if (*arg == '<')
5302 return find_key_option(arg + 1);
5303 if (*arg == '^')
5304 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005305 if (multi_byte)
5306 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307 return *arg;
5308}
5309
5310#ifdef FEAT_CMDWIN
5311/*
5312 * Check value of 'cedit' and set cedit_key.
5313 * Returns NULL if value is OK, error message otherwise.
5314 */
5315 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005316check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317{
5318 int n;
5319
5320 if (*p_cedit == NUL)
5321 cedit_key = -1;
5322 else
5323 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005324 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325 if (vim_isprintc(n))
5326 return e_invarg;
5327 cedit_key = n;
5328 }
5329 return NULL;
5330}
5331#endif
5332
5333#ifdef FEAT_TITLE
5334/*
5335 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5336 * maketitle() to create and display it.
5337 * When switching the title or icon off, call mch_restore_title() to get
5338 * the old value back.
5339 */
5340 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005341did_set_title(
5342 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343{
5344 if (starting != NO_SCREEN
5345#ifdef FEAT_GUI
5346 && !gui.starting
5347#endif
5348 )
5349 {
5350 maketitle();
5351 if (icon)
5352 {
5353 if (!p_icon)
5354 mch_restore_title(2);
5355 }
5356 else
5357 {
5358 if (!p_title)
5359 mch_restore_title(1);
5360 }
5361 }
5362}
5363#endif
5364
5365/*
5366 * set_options_bin - called when 'bin' changes value.
5367 */
5368 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005369set_options_bin(
5370 int oldval,
5371 int newval,
5372 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373{
5374 /*
5375 * The option values that are changed when 'bin' changes are
5376 * copied when 'bin is set and restored when 'bin' is reset.
5377 */
5378 if (newval)
5379 {
5380 if (!oldval) /* switched on */
5381 {
5382 if (!(opt_flags & OPT_GLOBAL))
5383 {
5384 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5385 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5386 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5387 curbuf->b_p_et_nobin = curbuf->b_p_et;
5388 }
5389 if (!(opt_flags & OPT_LOCAL))
5390 {
5391 p_tw_nobin = p_tw;
5392 p_wm_nobin = p_wm;
5393 p_ml_nobin = p_ml;
5394 p_et_nobin = p_et;
5395 }
5396 }
5397
5398 if (!(opt_flags & OPT_GLOBAL))
5399 {
5400 curbuf->b_p_tw = 0; /* no automatic line wrap */
5401 curbuf->b_p_wm = 0; /* no automatic line wrap */
5402 curbuf->b_p_ml = 0; /* no modelines */
5403 curbuf->b_p_et = 0; /* no expandtab */
5404 }
5405 if (!(opt_flags & OPT_LOCAL))
5406 {
5407 p_tw = 0;
5408 p_wm = 0;
5409 p_ml = FALSE;
5410 p_et = FALSE;
5411 p_bin = TRUE; /* needed when called for the "-b" argument */
5412 }
5413 }
5414 else if (oldval) /* switched off */
5415 {
5416 if (!(opt_flags & OPT_GLOBAL))
5417 {
5418 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5419 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5420 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5421 curbuf->b_p_et = curbuf->b_p_et_nobin;
5422 }
5423 if (!(opt_flags & OPT_LOCAL))
5424 {
5425 p_tw = p_tw_nobin;
5426 p_wm = p_wm_nobin;
5427 p_ml = p_ml_nobin;
5428 p_et = p_et_nobin;
5429 }
5430 }
5431}
5432
5433#ifdef FEAT_VIMINFO
5434/*
5435 * Find the parameter represented by the given character (eg ', :, ", or /),
5436 * and return its associated value in the 'viminfo' string.
5437 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005438 * If the parameter is not specified in the string or there is no following
5439 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005440 */
5441 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005442get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005443{
5444 char_u *p;
5445
5446 p = find_viminfo_parameter(type);
5447 if (p != NULL && VIM_ISDIGIT(*p))
5448 return atoi((char *)p);
5449 return -1;
5450}
5451
5452/*
5453 * Find the parameter represented by the given character (eg ''', ':', '"', or
5454 * '/') in the 'viminfo' option and return a pointer to the string after it.
5455 * Return NULL if the parameter is not specified in the string.
5456 */
5457 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005458find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459{
5460 char_u *p;
5461
5462 for (p = p_viminfo; *p; ++p)
5463 {
5464 if (*p == type)
5465 return p + 1;
5466 if (*p == 'n') /* 'n' is always the last one */
5467 break;
5468 p = vim_strchr(p, ','); /* skip until next ',' */
5469 if (p == NULL) /* hit the end without finding parameter */
5470 break;
5471 }
5472 return NULL;
5473}
5474#endif
5475
5476/*
5477 * Expand environment variables for some string options.
5478 * These string options cannot be indirect!
5479 * If "val" is NULL expand the current value of the option.
5480 * Return pointer to NameBuff, or NULL when not expanded.
5481 */
5482 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005483option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005484{
5485 /* if option doesn't need expansion nothing to do */
5486 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5487 return NULL;
5488
5489 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5490 * expand_env() would truncate the string. */
5491 if (val != NULL && STRLEN(val) > MAXPATHL)
5492 return NULL;
5493
5494 if (val == NULL)
5495 val = *(char_u **)options[opt_idx].var;
5496
5497 /*
5498 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5499 * Escape spaces when expanding 'tags', they are used to separate file
5500 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005501 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502 */
5503 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005504 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005505#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005506 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5507#endif
5508 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5510 return NULL;
5511
5512 return NameBuff;
5513}
5514
5515/*
5516 * After setting various option values: recompute variables that depend on
5517 * option values.
5518 */
5519 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005520didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521{
5522 /* initialize the table for 'iskeyword' et.al. */
5523 (void)init_chartab();
5524
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005525#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005527#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005529 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005530#ifdef FEAT_SESSION
5531 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5532 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5533#endif
5534#ifdef FEAT_FOLDING
5535 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5536#endif
5537 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005538 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539#ifdef FEAT_VIRTUALEDIT
5540 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5541#endif
5542#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5543 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5544#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005545#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005546 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005547 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005548 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005549 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5552 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5553#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005554#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5556#endif
5557#ifdef FEAT_CMDWIN
5558 /* set cedit_key */
5559 (void)check_cedit();
5560#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005561#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005562 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005563#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005564#ifdef FEAT_LINEBREAK
5565 /* initialize the table for 'breakat'. */
5566 fill_breakat_flags();
5567#endif
5568
5569}
5570
5571/*
5572 * More side effects of setting options.
5573 */
5574 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005575didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005576{
5577 /* Initialize the highlight_attr[] table. */
5578 (void)highlight_changed();
5579
5580 /* Parse default for 'wildmode' */
5581 check_opt_wim();
5582
5583 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005584 /* Parse default for 'fillchars'. */
5585 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005586
5587#ifdef FEAT_CLIPBOARD
5588 /* Parse default for 'clipboard' */
5589 (void)check_clipboard_option();
5590#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591}
5592
5593/*
5594 * Check for string options that are NULL (normally only termcap options).
5595 */
5596 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005597check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598{
5599 int opt_idx;
5600
5601 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5602 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5603 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5604}
5605
5606/*
5607 * Check string options in a buffer for NULL value.
5608 */
5609 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005610check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005612 check_string_option(&buf->b_p_bh);
5613 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005614#ifdef FEAT_MBYTE
5615 check_string_option(&buf->b_p_fenc);
5616#endif
5617 check_string_option(&buf->b_p_ff);
5618#ifdef FEAT_FIND_ID
5619 check_string_option(&buf->b_p_def);
5620 check_string_option(&buf->b_p_inc);
5621# ifdef FEAT_EVAL
5622 check_string_option(&buf->b_p_inex);
5623# endif
5624#endif
5625#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5626 check_string_option(&buf->b_p_inde);
5627 check_string_option(&buf->b_p_indk);
5628#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005629#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5630 check_string_option(&buf->b_p_bexpr);
5631#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005632#if defined(FEAT_CRYPT)
5633 check_string_option(&buf->b_p_cm);
5634#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005635 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005636#if defined(FEAT_EVAL)
5637 check_string_option(&buf->b_p_fex);
5638#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639#ifdef FEAT_CRYPT
5640 check_string_option(&buf->b_p_key);
5641#endif
5642 check_string_option(&buf->b_p_kp);
5643 check_string_option(&buf->b_p_mps);
5644 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005645 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646 check_string_option(&buf->b_p_isk);
5647#ifdef FEAT_COMMENTS
5648 check_string_option(&buf->b_p_com);
5649#endif
5650#ifdef FEAT_FOLDING
5651 check_string_option(&buf->b_p_cms);
5652#endif
5653 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005654#ifdef FEAT_TEXTOBJ
5655 check_string_option(&buf->b_p_qe);
5656#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657#ifdef FEAT_SYN_HL
5658 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005659 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005660#endif
5661#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005662 check_string_option(&buf->b_s.b_p_spc);
5663 check_string_option(&buf->b_s.b_p_spf);
5664 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665#endif
5666#ifdef FEAT_SEARCHPATH
5667 check_string_option(&buf->b_p_sua);
5668#endif
5669#ifdef FEAT_CINDENT
5670 check_string_option(&buf->b_p_cink);
5671 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005672 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673#endif
5674#ifdef FEAT_AUTOCMD
5675 check_string_option(&buf->b_p_ft);
5676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5678 check_string_option(&buf->b_p_cinw);
5679#endif
5680#ifdef FEAT_INS_EXPAND
5681 check_string_option(&buf->b_p_cpt);
5682#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005683#ifdef FEAT_COMPL_FUNC
5684 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005685 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005687#ifdef FEAT_KEYMAP
5688 check_string_option(&buf->b_p_keymap);
5689#endif
5690#ifdef FEAT_QUICKFIX
5691 check_string_option(&buf->b_p_gp);
5692 check_string_option(&buf->b_p_mp);
5693 check_string_option(&buf->b_p_efm);
5694#endif
5695 check_string_option(&buf->b_p_ep);
5696 check_string_option(&buf->b_p_path);
5697 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005698 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699#ifdef FEAT_INS_EXPAND
5700 check_string_option(&buf->b_p_dict);
5701 check_string_option(&buf->b_p_tsr);
5702#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005703#ifdef FEAT_LISP
5704 check_string_option(&buf->b_p_lw);
5705#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005706 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005707#ifdef FEAT_MBYTE
5708 check_string_option(&buf->b_p_menc);
5709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710}
5711
5712/*
5713 * Free the string allocated for an option.
5714 * Checks for the string being empty_option. This may happen if we're out of
5715 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5716 * check_options().
5717 * Does NOT check for P_ALLOCED flag!
5718 */
5719 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005720free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005721{
5722 if (p != empty_option)
5723 vim_free(p);
5724}
5725
5726 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005727clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728{
5729 if (*pp != empty_option)
5730 vim_free(*pp);
5731 *pp = empty_option;
5732}
5733
5734 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005735check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736{
5737 if (*pp == NULL)
5738 *pp = empty_option;
5739}
5740
5741/*
5742 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5743 */
5744 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005745set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746{
5747 int opt_idx;
5748
5749 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5750 if (options[opt_idx].var == (char_u *)p)
5751 {
5752 options[opt_idx].flags |= P_ALLOCED;
5753 return;
5754 }
5755 return; /* cannot happen: didn't find it! */
5756}
5757
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005758#if defined(FEAT_EVAL) || defined(PROTO)
5759/*
5760 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5761 * Return FALSE when it wasn't.
5762 * Return -1 for an unknown option.
5763 */
5764 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005765was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005766{
5767 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005768 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005769
5770 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005771 {
5772 flagp = insecure_flag(idx, opt_flags);
5773 return (*flagp & P_INSECURE) != 0;
5774 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005775 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005776 return -1;
5777}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005778
5779/*
5780 * Get a pointer to the flags used for the P_INSECURE flag of option
5781 * "opt_idx". For some local options a local flags field is used.
5782 */
5783 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005784insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005785{
5786 if (opt_flags & OPT_LOCAL)
5787 switch ((int)options[opt_idx].indir)
5788 {
5789#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005790 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005791#endif
5792#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005793# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005794 case PV_FDE: return &curwin->w_p_fde_flags;
5795 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005796# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005797# ifdef FEAT_BEVAL
5798 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5799# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005800# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005801 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005802# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005803 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005804# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005805 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005806# endif
5807#endif
5808 }
5809
5810 /* Nothing special, return global flags field. */
5811 return &options[opt_idx].flags;
5812}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005813#endif
5814
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005815#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005816static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005817
5818/*
5819 * Redraw the window title and/or tab page text later.
5820 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005821static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005822{
5823 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005824 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005825}
5826#endif
5827
Bram Moolenaar071d4272004-06-13 20:20:40 +00005828/*
5829 * Set a string option to a new value (without checking the effect).
5830 * The string is copied into allocated memory.
5831 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005832 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005833 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005834 */
5835 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005836set_string_option_direct(
5837 char_u *name,
5838 int opt_idx,
5839 char_u *val,
5840 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5841 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005842{
5843 char_u *s;
5844 char_u **varp;
5845 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005846 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847
Bram Moolenaar89d40322006-08-29 15:30:07 +00005848 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005850 idx = findoption(name);
5851 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005852 {
5853 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005854 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005855 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005857 }
5858
Bram Moolenaar89d40322006-08-29 15:30:07 +00005859 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 return;
5861
5862 s = vim_strsave(val);
5863 if (s != NULL)
5864 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005865 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005867 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868 free_string_option(*varp);
5869 *varp = s;
5870
5871 /* For buffer/window local option may also set the global value. */
5872 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005873 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005874
Bram Moolenaar89d40322006-08-29 15:30:07 +00005875 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876
5877 /* When setting both values of a global option with a local value,
5878 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005879 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880 {
5881 free_string_option(*varp);
5882 *varp = empty_option;
5883 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005884# ifdef FEAT_EVAL
5885 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005886 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005887 set_sid == 0 ? current_SID : set_sid);
5888# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889 }
5890}
5891
5892/*
5893 * Set global value for string option when it's a local option.
5894 */
5895 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005896set_string_option_global(
5897 int opt_idx, /* option index */
5898 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899{
5900 char_u **p, *s;
5901
5902 /* the global value is always allocated */
5903 if (options[opt_idx].var == VAR_WIN)
5904 p = (char_u **)GLOBAL_WO(varp);
5905 else
5906 p = (char_u **)options[opt_idx].var;
5907 if (options[opt_idx].indir != PV_NONE
5908 && p != varp
5909 && (s = vim_strsave(*varp)) != NULL)
5910 {
5911 free_string_option(*p);
5912 *p = s;
5913 }
5914}
5915
5916/*
5917 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005918 *
5919 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005921 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005922set_string_option(
5923 int opt_idx,
5924 char_u *value,
5925 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926{
5927 char_u *s;
5928 char_u **varp;
5929 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005930#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5931 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005932 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005933#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005934 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935
5936 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005937 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938
5939 s = vim_strsave(value);
5940 if (s != NULL)
5941 {
5942 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5943 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005944 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005945 ? OPT_GLOBAL : OPT_LOCAL)
5946 : opt_flags);
5947 oldval = *varp;
5948 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005949
5950#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005951 if (!starting
5952# ifdef FEAT_CRYPT
5953 && options[opt_idx].indir != PV_KEY
5954# endif
5955 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005956 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005957 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005958 saved_newval = vim_strsave(s);
5959 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005960#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005961 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5962 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005963 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005964
Bram Moolenaar53744302015-07-17 17:38:22 +02005965#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005966 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005967 if (r == NULL)
5968 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005969 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005970 vim_free(saved_oldval);
5971 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005972#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005973 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005974 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975}
5976
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005977#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005978/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005979 * Return TRUE if "val" is a valid 'filetype' name.
5980 * Also used for 'syntax' and 'keymap'.
5981 */
5982 static int
5983valid_filetype(char_u *val)
5984{
5985 char_u *s;
5986
5987 for (s = val; *s != NUL; ++s)
5988 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5989 return FALSE;
5990 return TRUE;
5991}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005992#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005993
5994/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005995 * Handle string options that need some action to perform when changed.
5996 * Returns NULL for success, or an error message for an error.
5997 */
5998 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005999did_set_string_option(
6000 int opt_idx, /* index in options[] table */
6001 char_u **varp, /* pointer to the option variable */
6002 int new_value_alloced, /* new value was allocated */
6003 char_u *oldval, /* previous value of the option */
6004 char_u *errbuf, /* buffer for errors, or NULL */
6005 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006{
6007 char_u *errmsg = NULL;
6008 char_u *s, *p;
6009 int did_chartab = FALSE;
6010 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006011 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006012#ifdef FEAT_GUI
6013 /* set when changing an option that only requires a redraw in the GUI */
6014 int redraw_gui_only = FALSE;
6015#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006016#ifdef FEAT_AUTOCMD
6017 int ft_changed = FALSE;
6018#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006019
6020 /* Get the global option to compare with, otherwise we would have to check
6021 * two values for all local options. */
6022 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6023
6024 /* Disallow changing some options from secure mode */
6025 if ((secure
6026#ifdef HAVE_SANDBOX
6027 || sandbox != 0
6028#endif
6029 ) && (options[opt_idx].flags & P_SECURE))
6030 {
6031 errmsg = e_secure;
6032 }
6033
Bram Moolenaar7554da42016-11-25 22:04:13 +01006034 /* Check for a "normal" directory or file name in some options. Disallow a
6035 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006036 * are often illegal in a file name. Be more permissive if "secure" is off.
6037 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006038 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006039 && vim_strpbrk(*varp, (char_u *)(secure
6040 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006041 || ((options[opt_idx].flags & P_NDNAME)
6042 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006043 {
6044 errmsg = e_invarg;
6045 }
6046
Bram Moolenaar071d4272004-06-13 20:20:40 +00006047 /* 'term' */
6048 else if (varp == &T_NAME)
6049 {
6050 if (T_NAME[0] == NUL)
6051 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6052#ifdef FEAT_GUI
6053 if (gui.in_use)
6054 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6055 else if (term_is_gui(T_NAME))
6056 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6057#endif
6058 else if (set_termname(T_NAME) == FAIL)
6059 errmsg = (char_u *)N_("E522: Not found in termcap");
6060 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006061 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006062 /* Screen colors may have changed. */
6063 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006064
6065 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6066 * P_ALLOCED flag on 'term'. */
6067 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006068 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006069 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006070 }
6071
6072 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006073 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006075 char_u *bkc = p_bkc;
6076 unsigned int *flags = &bkc_flags;
6077
6078 if (opt_flags & OPT_LOCAL)
6079 {
6080 bkc = curbuf->b_p_bkc;
6081 flags = &curbuf->b_bkc_flags;
6082 }
6083
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006084 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6085 /* make the local value empty: use the global value */
6086 *flags = 0;
6087 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006088 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006089 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6090 errmsg = e_invarg;
6091 if ((((int)*flags & BKC_AUTO) != 0)
6092 + (((int)*flags & BKC_YES) != 0)
6093 + (((int)*flags & BKC_NO) != 0) != 1)
6094 {
6095 /* Must have exactly one of "auto", "yes" and "no". */
6096 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6097 errmsg = e_invarg;
6098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 }
6100 }
6101
6102 /* 'backupext' and 'patchmode' */
6103 else if (varp == &p_bex || varp == &p_pm)
6104 {
6105 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6106 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6107 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6108 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006109#ifdef FEAT_LINEBREAK
6110 /* 'breakindentopt' */
6111 else if (varp == &curwin->w_p_briopt)
6112 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006113 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006114 errmsg = e_invarg;
6115 }
6116#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117
6118 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006119 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006120 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006121 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006122 */
6123 else if ( varp == &p_isi
6124 || varp == &(curbuf->b_p_isk)
6125 || varp == &p_isp
6126 || varp == &p_isf)
6127 {
6128 if (init_chartab() == FAIL)
6129 {
6130 did_chartab = TRUE; /* need to restore it below */
6131 errmsg = e_invarg; /* error in value */
6132 }
6133 }
6134
6135 /* 'helpfile' */
6136 else if (varp == &p_hf)
6137 {
6138 /* May compute new values for $VIM and $VIMRUNTIME */
6139 if (didset_vim)
6140 {
6141 vim_setenv((char_u *)"VIM", (char_u *)"");
6142 didset_vim = FALSE;
6143 }
6144 if (didset_vimruntime)
6145 {
6146 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6147 didset_vimruntime = FALSE;
6148 }
6149 }
6150
Bram Moolenaar1a384422010-07-14 19:53:30 +02006151#ifdef FEAT_SYN_HL
6152 /* 'colorcolumn' */
6153 else if (varp == &curwin->w_p_cc)
6154 errmsg = check_colorcolumn(curwin);
6155#endif
6156
Bram Moolenaar071d4272004-06-13 20:20:40 +00006157#ifdef FEAT_MULTI_LANG
6158 /* 'helplang' */
6159 else if (varp == &p_hlg)
6160 {
6161 /* Check for "", "ab", "ab,cd", etc. */
6162 for (s = p_hlg; *s != NUL; s += 3)
6163 {
6164 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6165 {
6166 errmsg = e_invarg;
6167 break;
6168 }
6169 if (s[2] == NUL)
6170 break;
6171 }
6172 }
6173#endif
6174
6175 /* 'highlight' */
6176 else if (varp == &p_hl)
6177 {
6178 if (highlight_changed() == FAIL)
6179 errmsg = e_invarg; /* invalid flags */
6180 }
6181
6182 /* 'nrformats' */
6183 else if (gvarp == &p_nf)
6184 {
6185 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6186 errmsg = e_invarg;
6187 }
6188
6189#ifdef FEAT_SESSION
6190 /* 'sessionoptions' */
6191 else if (varp == &p_ssop)
6192 {
6193 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6194 errmsg = e_invarg;
6195 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6196 {
6197 /* Don't allow both "sesdir" and "curdir". */
6198 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6199 errmsg = e_invarg;
6200 }
6201 }
6202 /* 'viewoptions' */
6203 else if (varp == &p_vop)
6204 {
6205 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6206 errmsg = e_invarg;
6207 }
6208#endif
6209
6210 /* 'scrollopt' */
6211#ifdef FEAT_SCROLLBIND
6212 else if (varp == &p_sbo)
6213 {
6214 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6215 errmsg = e_invarg;
6216 }
6217#endif
6218
6219 /* 'ambiwidth' */
6220#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006221 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006222 {
6223 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6224 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006225 else if (set_chars_option(&p_lcs) != NULL)
6226 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006227 else if (set_chars_option(&p_fcs) != NULL)
6228 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006229 }
6230#endif
6231
6232 /* 'background' */
6233 else if (varp == &p_bg)
6234 {
6235 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6236 {
6237#ifdef FEAT_EVAL
6238 int dark = (*p_bg == 'd');
6239#endif
6240
6241 init_highlight(FALSE, FALSE);
6242
6243#ifdef FEAT_EVAL
6244 if (dark != (*p_bg == 'd')
6245 && get_var_value((char_u *)"g:colors_name") != NULL)
6246 {
6247 /* The color scheme must have set 'background' back to another
6248 * value, that's not what we want here. Disable the color
6249 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006250 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251 free_string_option(p_bg);
6252 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6253 check_string_option(&p_bg);
6254 init_highlight(FALSE, FALSE);
6255 }
6256#endif
6257 }
6258 else
6259 errmsg = e_invarg;
6260 }
6261
6262 /* 'wildmode' */
6263 else if (varp == &p_wim)
6264 {
6265 if (check_opt_wim() == FAIL)
6266 errmsg = e_invarg;
6267 }
6268
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006269#ifdef FEAT_CMDL_COMPL
6270 /* 'wildoptions' */
6271 else if (varp == &p_wop)
6272 {
6273 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6274 errmsg = e_invarg;
6275 }
6276#endif
6277
Bram Moolenaar071d4272004-06-13 20:20:40 +00006278#ifdef FEAT_WAK
6279 /* 'winaltkeys' */
6280 else if (varp == &p_wak)
6281 {
6282 if (*p_wak == NUL
6283 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6284 errmsg = e_invarg;
6285# ifdef FEAT_MENU
6286# ifdef FEAT_GUI_MOTIF
6287 else if (gui.in_use)
6288 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6289# else
6290# ifdef FEAT_GUI_GTK
6291 else if (gui.in_use)
6292 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6293# endif
6294# endif
6295# endif
6296 }
6297#endif
6298
6299#ifdef FEAT_AUTOCMD
6300 /* 'eventignore' */
6301 else if (varp == &p_ei)
6302 {
6303 if (check_ei() == FAIL)
6304 errmsg = e_invarg;
6305 }
6306#endif
6307
6308#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006309 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6310 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6311 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006312 {
6313 if (gvarp == &p_fenc)
6314 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006315 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316 errmsg = e_modifiable;
6317 else if (vim_strchr(*varp, ',') != NULL)
6318 /* No comma allowed in 'fileencoding'; catches confusing it
6319 * with 'fileencodings'. */
6320 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006322 {
6323# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006324 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006325 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006326# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006327 /* Add 'fileencoding' to the swap file. */
6328 ml_setflags(curbuf);
6329 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006330 }
6331 if (errmsg == NULL)
6332 {
6333 /* canonize the value, so that STRCMP() can be used on it */
6334 p = enc_canonize(*varp);
6335 if (p != NULL)
6336 {
6337 vim_free(*varp);
6338 *varp = p;
6339 }
6340 if (varp == &p_enc)
6341 {
6342 errmsg = mb_init();
6343# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006344 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006345# endif
6346 }
6347 }
6348
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006349# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6351 {
6352 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6353 if (STRCMP(p_tenc, "utf-8") != 0)
6354 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6355 }
6356# endif
6357
6358 if (errmsg == NULL)
6359 {
6360# ifdef FEAT_KEYMAP
6361 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6362 * (with another encoding). */
6363 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6364 (void)keymap_init();
6365# endif
6366
6367 /* When 'termencoding' is not empty and 'encoding' changes or when
6368 * 'termencoding' changes, need to setup for keyboard input and
6369 * display output conversion. */
6370 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6371 {
6372 convert_setup(&input_conv, p_tenc, p_enc);
6373 convert_setup(&output_conv, p_enc, p_tenc);
6374 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006375
6376# if defined(WIN3264) && defined(FEAT_MBYTE)
6377 /* $HOME may have characters in active code page. */
6378 if (varp == &p_enc)
6379 init_homedir();
6380# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006381 }
6382 }
6383#endif
6384
6385#if defined(FEAT_POSTSCRIPT)
6386 else if (varp == &p_penc)
6387 {
6388 /* Canonize printencoding if VIM standard one */
6389 p = enc_canonize(p_penc);
6390 if (p != NULL)
6391 {
6392 vim_free(p_penc);
6393 p_penc = p;
6394 }
6395 else
6396 {
6397 /* Ensure lower case and '-' for '_' */
6398 for (s = p_penc; *s != NUL; s++)
6399 {
6400 if (*s == '_')
6401 *s = '-';
6402 else
6403 *s = TOLOWER_ASC(*s);
6404 }
6405 }
6406 }
6407#endif
6408
Bram Moolenaar9372a112005-12-06 19:59:18 +00006409#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006410 else if (varp == &p_imak)
6411 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006412 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006413 errmsg = e_invarg;
6414 }
6415#endif
6416
6417#ifdef FEAT_KEYMAP
6418 else if (varp == &curbuf->b_p_keymap)
6419 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006420 if (!valid_filetype(*varp))
6421 errmsg = e_invarg;
6422 else
6423 /* load or unload key mapping tables */
6424 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006425
Bram Moolenaarfab06232009-03-04 03:13:35 +00006426 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006427 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006428 if (*curbuf->b_p_keymap != NUL)
6429 {
6430 /* Installed a new keymap, switch on using it. */
6431 curbuf->b_p_iminsert = B_IMODE_LMAP;
6432 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6433 curbuf->b_p_imsearch = B_IMODE_LMAP;
6434 }
6435 else
6436 {
6437 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6438 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6439 curbuf->b_p_iminsert = B_IMODE_NONE;
6440 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6441 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6442 }
6443 if ((opt_flags & OPT_LOCAL) == 0)
6444 {
6445 set_iminsert_global();
6446 set_imsearch_global();
6447 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006448 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449 }
6450 }
6451#endif
6452
6453 /* 'fileformat' */
6454 else if (gvarp == &p_ff)
6455 {
6456 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6457 errmsg = e_modifiable;
6458 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6459 errmsg = e_invarg;
6460 else
6461 {
6462 /* may also change 'textmode' */
6463 if (get_fileformat(curbuf) == EOL_DOS)
6464 curbuf->b_p_tx = TRUE;
6465 else
6466 curbuf->b_p_tx = FALSE;
6467#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006468 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006469#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006470 /* update flag in swap file */
6471 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006472 /* Redraw needed when switching to/from "mac": a CR in the text
6473 * will be displayed differently. */
6474 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6475 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006476 }
6477 }
6478
6479 /* 'fileformats' */
6480 else if (varp == &p_ffs)
6481 {
6482 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6483 errmsg = e_invarg;
6484 else
6485 {
6486 /* also change 'textauto' */
6487 if (*p_ffs == NUL)
6488 p_ta = FALSE;
6489 else
6490 p_ta = TRUE;
6491 }
6492 }
6493
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006494#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006495 /* 'cryptkey' */
6496 else if (gvarp == &p_key)
6497 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006498# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006499 /* Make sure the ":set" command doesn't show the new value in the
6500 * history. */
6501 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006502# endif
6503 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6504 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006505 ml_set_crypt_key(curbuf, oldval,
6506 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006507 }
6508
6509 else if (gvarp == &p_cm)
6510 {
6511 if (opt_flags & OPT_LOCAL)
6512 p = curbuf->b_p_cm;
6513 else
6514 p = p_cm;
6515 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6516 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006517 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006518 errmsg = e_invarg;
6519 else
6520 {
6521 /* When setting the global value to empty, make it "zip". */
6522 if (*p_cm == NUL)
6523 {
6524 if (new_value_alloced)
6525 free_string_option(p_cm);
6526 p_cm = vim_strsave((char_u *)"zip");
6527 new_value_alloced = TRUE;
6528 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006529 /* When using ":set cm=name" the local value is going to be empty.
6530 * Do that here, otherwise the crypt functions will still use the
6531 * local value. */
6532 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6533 {
6534 free_string_option(curbuf->b_p_cm);
6535 curbuf->b_p_cm = empty_option;
6536 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006537
6538 /* Need to update the swapfile when the effective method changed.
6539 * Set "s" to the effective old value, "p" to the effective new
6540 * method and compare. */
6541 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6542 s = p_cm; /* was previously using the global value */
6543 else
6544 s = oldval;
6545 if (*curbuf->b_p_cm == NUL)
6546 p = p_cm; /* is now using the global value */
6547 else
6548 p = curbuf->b_p_cm;
6549 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006550 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006551
6552 /* If the global value changes need to update the swapfile for all
6553 * buffers using that value. */
6554 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6555 {
6556 buf_T *buf;
6557
Bram Moolenaar29323592016-07-24 22:04:11 +02006558 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006559 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006560 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006561 }
6562 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563 }
6564#endif
6565
6566 /* 'matchpairs' */
6567 else if (gvarp == &p_mps)
6568 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006569#ifdef FEAT_MBYTE
6570 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006571 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006572 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006573 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006574 int x2 = -1;
6575 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006576
6577 if (*p != NUL)
6578 p += mb_ptr2len(p);
6579 if (*p != NUL)
6580 x2 = *p++;
6581 if (*p != NUL)
6582 {
6583 x3 = mb_ptr2char(p);
6584 p += mb_ptr2len(p);
6585 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006586 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006587 {
6588 errmsg = e_invarg;
6589 break;
6590 }
6591 if (*p == NUL)
6592 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006594 }
6595 else
6596#endif
6597 {
6598 /* Check for "x:y,x:y" */
6599 for (p = *varp; *p != NUL; p += 4)
6600 {
6601 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6602 {
6603 errmsg = e_invarg;
6604 break;
6605 }
6606 if (p[3] == NUL)
6607 break;
6608 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006609 }
6610 }
6611
6612#ifdef FEAT_COMMENTS
6613 /* 'comments' */
6614 else if (gvarp == &p_com)
6615 {
6616 for (s = *varp; *s; )
6617 {
6618 while (*s && *s != ':')
6619 {
6620 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6621 && !VIM_ISDIGIT(*s) && *s != '-')
6622 {
6623 errmsg = illegal_char(errbuf, *s);
6624 break;
6625 }
6626 ++s;
6627 }
6628 if (*s++ == NUL)
6629 errmsg = (char_u *)N_("E524: Missing colon");
6630 else if (*s == ',' || *s == NUL)
6631 errmsg = (char_u *)N_("E525: Zero length string");
6632 if (errmsg != NULL)
6633 break;
6634 while (*s && *s != ',')
6635 {
6636 if (*s == '\\' && s[1] != NUL)
6637 ++s;
6638 ++s;
6639 }
6640 s = skip_to_option_part(s);
6641 }
6642 }
6643#endif
6644
6645 /* 'listchars' */
6646 else if (varp == &p_lcs)
6647 {
6648 errmsg = set_chars_option(varp);
6649 }
6650
Bram Moolenaar071d4272004-06-13 20:20:40 +00006651 /* 'fillchars' */
6652 else if (varp == &p_fcs)
6653 {
6654 errmsg = set_chars_option(varp);
6655 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006656
6657#ifdef FEAT_CMDWIN
6658 /* 'cedit' */
6659 else if (varp == &p_cedit)
6660 {
6661 errmsg = check_cedit();
6662 }
6663#endif
6664
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006665 /* 'verbosefile' */
6666 else if (varp == &p_vfile)
6667 {
6668 verbose_stop();
6669 if (*p_vfile != NUL && verbose_open() == FAIL)
6670 errmsg = e_invarg;
6671 }
6672
Bram Moolenaar071d4272004-06-13 20:20:40 +00006673#ifdef FEAT_VIMINFO
6674 /* 'viminfo' */
6675 else if (varp == &p_viminfo)
6676 {
6677 for (s = p_viminfo; *s;)
6678 {
6679 /* Check it's a valid character */
6680 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6681 {
6682 errmsg = illegal_char(errbuf, *s);
6683 break;
6684 }
6685 if (*s == 'n') /* name is always last one */
6686 {
6687 break;
6688 }
6689 else if (*s == 'r') /* skip until next ',' */
6690 {
6691 while (*++s && *s != ',')
6692 ;
6693 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006694 else if (*s == '%')
6695 {
6696 /* optional number */
6697 while (vim_isdigit(*++s))
6698 ;
6699 }
6700 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006701 ++s; /* no extra chars */
6702 else /* must have a number */
6703 {
6704 while (vim_isdigit(*++s))
6705 ;
6706
6707 if (!VIM_ISDIGIT(*(s - 1)))
6708 {
6709 if (errbuf != NULL)
6710 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006711 sprintf((char *)errbuf,
6712 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006713 transchar_byte(*(s - 1)));
6714 errmsg = errbuf;
6715 }
6716 else
6717 errmsg = (char_u *)"";
6718 break;
6719 }
6720 }
6721 if (*s == ',')
6722 ++s;
6723 else if (*s)
6724 {
6725 if (errbuf != NULL)
6726 errmsg = (char_u *)N_("E527: Missing comma");
6727 else
6728 errmsg = (char_u *)"";
6729 break;
6730 }
6731 }
6732 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6733 errmsg = (char_u *)N_("E528: Must specify a ' value");
6734 }
6735#endif /* FEAT_VIMINFO */
6736
6737 /* terminal options */
6738 else if (istermoption(&options[opt_idx]) && full_screen)
6739 {
6740 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6741 if (varp == &T_CCO)
6742 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006743 int colors = atoi((char *)T_CCO);
6744
6745 /* Only reinitialize colors if t_Co value has really changed to
6746 * avoid expensive reload of colorscheme if t_Co is set to the
6747 * same value multiple times. */
6748 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006750 t_colors = colors;
6751 if (t_colors <= 1)
6752 {
6753 if (new_value_alloced)
6754 vim_free(T_CCO);
6755 T_CCO = empty_option;
6756 }
6757 /* We now have a different color setup, initialize it again. */
6758 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006760 }
6761 ttest(FALSE);
6762 if (varp == &T_ME)
6763 {
6764 out_str(T_ME);
6765 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006766#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006767 /* Since t_me has been set, this probably means that the user
6768 * wants to use this as default colors. Need to reset default
6769 * background/foreground colors. */
6770 mch_set_normal_colors();
6771#endif
6772 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006773 if (varp == &T_BE && termcap_active)
6774 {
6775 if (*T_BE == NUL)
6776 /* When clearing t_BE we assume the user no longer wants
6777 * bracketed paste, thus disable it by writing t_BD. */
6778 out_str(T_BD);
6779 else
6780 out_str(T_BE);
6781 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006782 }
6783
6784#ifdef FEAT_LINEBREAK
6785 /* 'showbreak' */
6786 else if (varp == &p_sbr)
6787 {
6788 for (s = p_sbr; *s; )
6789 {
6790 if (ptr2cells(s) != 1)
6791 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006792 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 }
6794 }
6795#endif
6796
6797#ifdef FEAT_GUI
6798 /* 'guifont' */
6799 else if (varp == &p_guifont)
6800 {
6801 if (gui.in_use)
6802 {
6803 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006804# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006805 /*
6806 * Put up a font dialog and let the user select a new value.
6807 * If this is cancelled go back to the old value but don't
6808 * give an error message.
6809 */
6810 if (STRCMP(p, "*") == 0)
6811 {
6812 p = gui_mch_font_dialog(oldval);
6813
6814 if (new_value_alloced)
6815 free_string_option(p_guifont);
6816
6817 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6818 new_value_alloced = TRUE;
6819 }
6820# endif
6821 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6822 {
6823# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6824 if (STRCMP(p_guifont, "*") == 0)
6825 {
6826 /* Dialog was cancelled: Keep the old value without giving
6827 * an error message. */
6828 if (new_value_alloced)
6829 free_string_option(p_guifont);
6830 p_guifont = vim_strsave(oldval);
6831 new_value_alloced = TRUE;
6832 }
6833 else
6834# endif
6835 errmsg = (char_u *)N_("E596: Invalid font(s)");
6836 }
6837 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006838 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006839 }
6840# ifdef FEAT_XFONTSET
6841 else if (varp == &p_guifontset)
6842 {
6843 if (STRCMP(p_guifontset, "*") == 0)
6844 errmsg = (char_u *)N_("E597: can't select fontset");
6845 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6846 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006847 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006848 }
6849# endif
6850# ifdef FEAT_MBYTE
6851 else if (varp == &p_guifontwide)
6852 {
6853 if (STRCMP(p_guifontwide, "*") == 0)
6854 errmsg = (char_u *)N_("E533: can't select wide font");
6855 else if (gui_get_wide_font() == FAIL)
6856 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006857 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006858 }
6859# endif
6860#endif
6861
6862#ifdef CURSOR_SHAPE
6863 /* 'guicursor' */
6864 else if (varp == &p_guicursor)
6865 errmsg = parse_shape_opt(SHAPE_CURSOR);
6866#endif
6867
6868#ifdef FEAT_MOUSESHAPE
6869 /* 'mouseshape' */
6870 else if (varp == &p_mouseshape)
6871 {
6872 errmsg = parse_shape_opt(SHAPE_MOUSE);
6873 update_mouseshape(-1);
6874 }
6875#endif
6876
6877#ifdef FEAT_PRINTER
6878 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006879 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006880# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006881 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006882 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006883# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884#endif
6885
6886#ifdef FEAT_LANGMAP
6887 /* 'langmap' */
6888 else if (varp == &p_langmap)
6889 langmap_set();
6890#endif
6891
6892#ifdef FEAT_LINEBREAK
6893 /* 'breakat' */
6894 else if (varp == &p_breakat)
6895 fill_breakat_flags();
6896#endif
6897
6898#ifdef FEAT_TITLE
6899 /* 'titlestring' and 'iconstring' */
6900 else if (varp == &p_titlestring || varp == &p_iconstring)
6901 {
6902# ifdef FEAT_STL_OPT
6903 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6904
6905 /* NULL => statusline syntax */
6906 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6907 stl_syntax |= flagval;
6908 else
6909 stl_syntax &= ~flagval;
6910# endif
6911 did_set_title(varp == &p_iconstring);
6912
6913 }
6914#endif
6915
6916#ifdef FEAT_GUI
6917 /* 'guioptions' */
6918 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006919 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006921 redraw_gui_only = TRUE;
6922 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923#endif
6924
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006925#if defined(FEAT_GUI_TABLINE)
6926 /* 'guitablabel' */
6927 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006928 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006929 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006930 redraw_gui_only = TRUE;
6931 }
6932 /* 'guitabtooltip' */
6933 else if (varp == &p_gtt)
6934 {
6935 redraw_gui_only = TRUE;
6936 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006937#endif
6938
Bram Moolenaar071d4272004-06-13 20:20:40 +00006939#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6940 /* 'ttymouse' */
6941 else if (varp == &p_ttym)
6942 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006943 /* Switch the mouse off before changing the escape sequences used for
6944 * that. */
6945 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6947 errmsg = e_invarg;
6948 else
6949 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006950 if (termcap_active)
6951 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006952 }
6953#endif
6954
Bram Moolenaar071d4272004-06-13 20:20:40 +00006955 /* 'selection' */
6956 else if (varp == &p_sel)
6957 {
6958 if (*p_sel == NUL
6959 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6960 errmsg = e_invarg;
6961 }
6962
6963 /* 'selectmode' */
6964 else if (varp == &p_slm)
6965 {
6966 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6967 errmsg = e_invarg;
6968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006969
6970#ifdef FEAT_BROWSE
6971 /* 'browsedir' */
6972 else if (varp == &p_bsdir)
6973 {
6974 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6975 && !mch_isdir(p_bsdir))
6976 errmsg = e_invarg;
6977 }
6978#endif
6979
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980 /* 'keymodel' */
6981 else if (varp == &p_km)
6982 {
6983 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6984 errmsg = e_invarg;
6985 else
6986 {
6987 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6988 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6989 }
6990 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006991
6992 /* 'mousemodel' */
6993 else if (varp == &p_mousem)
6994 {
6995 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6996 errmsg = e_invarg;
6997#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6998 else if (*p_mousem != *oldval)
6999 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7000 * to create or delete the popup menus. */
7001 gui_motif_update_mousemodel(root_menu);
7002#endif
7003 }
7004
7005 /* 'switchbuf' */
7006 else if (varp == &p_swb)
7007 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007008 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007009 errmsg = e_invarg;
7010 }
7011
7012 /* 'debug' */
7013 else if (varp == &p_debug)
7014 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007015 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007016 errmsg = e_invarg;
7017 }
7018
7019 /* 'display' */
7020 else if (varp == &p_dy)
7021 {
7022 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7023 errmsg = e_invarg;
7024 else
7025 (void)init_chartab();
7026
7027 }
7028
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029 /* 'eadirection' */
7030 else if (varp == &p_ead)
7031 {
7032 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7033 errmsg = e_invarg;
7034 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007035
7036#ifdef FEAT_CLIPBOARD
7037 /* 'clipboard' */
7038 else if (varp == &p_cb)
7039 errmsg = check_clipboard_option();
7040#endif
7041
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007042#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007043 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7044 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007045 else if (varp == &(curwin->w_s->b_p_spl)
7046 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007047 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007048 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007049 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007050 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007051 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007052 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007053 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007054 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007055 /* 'spellsuggest' */
7056 else if (varp == &p_sps)
7057 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007058 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007059 errmsg = e_invarg;
7060 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007061 /* 'mkspellmem' */
7062 else if (varp == &p_msm)
7063 {
7064 if (spell_check_msm() != OK)
7065 errmsg = e_invarg;
7066 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007067#endif
7068
Bram Moolenaar071d4272004-06-13 20:20:40 +00007069 /* When 'bufhidden' is set, check for valid value. */
7070 else if (gvarp == &p_bh)
7071 {
7072 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7073 errmsg = e_invarg;
7074 }
7075
7076 /* When 'buftype' is set, check for valid value. */
7077 else if (gvarp == &p_bt)
7078 {
7079 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7080 errmsg = e_invarg;
7081 else
7082 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007083 if (curwin->w_status_height)
7084 {
7085 curwin->w_redr_status = TRUE;
7086 redraw_later(VALID);
7087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007088 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007089#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007090 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007091#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007092 }
7093 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007094
7095#ifdef FEAT_STL_OPT
7096 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007097 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007098 {
7099 int wid;
7100
7101 if (varp == &p_ruf) /* reset ru_wid first */
7102 ru_wid = 0;
7103 s = *varp;
7104 if (varp == &p_ruf && *s == '%')
7105 {
7106 /* set ru_wid if 'ruf' starts with "%99(" */
7107 if (*++s == '-') /* ignore a '-' */
7108 s++;
7109 wid = getdigits(&s);
7110 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7111 ru_wid = wid;
7112 else
7113 errmsg = check_stl_option(p_ruf);
7114 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007115 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007116 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007117 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007118 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 comp_col();
7120 }
7121#endif
7122
7123#ifdef FEAT_INS_EXPAND
7124 /* check if it is a valid value for 'complete' -- Acevedo */
7125 else if (gvarp == &p_cpt)
7126 {
7127 for (s = *varp; *s;)
7128 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007129 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130 s++;
7131 if (!*s)
7132 break;
7133 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7134 {
7135 errmsg = illegal_char(errbuf, *s);
7136 break;
7137 }
7138 if (*++s != NUL && *s != ',' && *s != ' ')
7139 {
7140 if (s[-1] == 'k' || s[-1] == 's')
7141 {
7142 /* skip optional filename after 'k' and 's' */
7143 while (*s && *s != ',' && *s != ' ')
7144 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007145 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007146 ++s;
7147 ++s;
7148 }
7149 }
7150 else
7151 {
7152 if (errbuf != NULL)
7153 {
7154 sprintf((char *)errbuf,
7155 _("E535: Illegal character after <%c>"),
7156 *--s);
7157 errmsg = errbuf;
7158 }
7159 else
7160 errmsg = (char_u *)"";
7161 break;
7162 }
7163 }
7164 }
7165 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007166
7167 /* 'completeopt' */
7168 else if (varp == &p_cot)
7169 {
7170 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7171 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007172 else
7173 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007174 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007175#endif /* FEAT_INS_EXPAND */
7176
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007177#ifdef FEAT_SIGNS
7178 /* 'signcolumn' */
7179 else if (varp == &curwin->w_p_scl)
7180 {
7181 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7182 errmsg = e_invarg;
7183 }
7184#endif
7185
Bram Moolenaar071d4272004-06-13 20:20:40 +00007186
7187#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007188 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007189 else if (varp == &p_toolbar)
7190 {
7191 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7192 &toolbar_flags, TRUE) != OK)
7193 errmsg = e_invarg;
7194 else
7195 {
7196 out_flush();
7197 gui_mch_show_toolbar((toolbar_flags &
7198 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7199 }
7200 }
7201#endif
7202
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007203#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204 /* 'toolbariconsize': GTK+ 2 only */
7205 else if (varp == &p_tbis)
7206 {
7207 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7208 errmsg = e_invarg;
7209 else
7210 {
7211 out_flush();
7212 gui_mch_show_toolbar((toolbar_flags &
7213 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7214 }
7215 }
7216#endif
7217
7218 /* 'pastetoggle': translate key codes like in a mapping */
7219 else if (varp == &p_pt)
7220 {
7221 if (*p_pt)
7222 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007223 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224 if (p != NULL)
7225 {
7226 if (new_value_alloced)
7227 free_string_option(p_pt);
7228 p_pt = p;
7229 new_value_alloced = TRUE;
7230 }
7231 }
7232 }
7233
7234 /* 'backspace' */
7235 else if (varp == &p_bs)
7236 {
7237 if (VIM_ISDIGIT(*p_bs))
7238 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007239 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007240 errmsg = e_invarg;
7241 }
7242 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7243 errmsg = e_invarg;
7244 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007245 else if (varp == &p_bo)
7246 {
7247 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7248 errmsg = e_invarg;
7249 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007250
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007251 /* 'tagcase' */
7252 else if (gvarp == &p_tc)
7253 {
7254 unsigned int *flags;
7255
7256 if (opt_flags & OPT_LOCAL)
7257 {
7258 p = curbuf->b_p_tc;
7259 flags = &curbuf->b_tc_flags;
7260 }
7261 else
7262 {
7263 p = p_tc;
7264 flags = &tc_flags;
7265 }
7266
7267 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7268 /* make the local value empty: use the global value */
7269 *flags = 0;
7270 else if (*p == NUL
7271 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7272 errmsg = e_invarg;
7273 }
7274
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007275#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007276 /* 'casemap' */
7277 else if (varp == &p_cmp)
7278 {
7279 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7280 errmsg = e_invarg;
7281 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007283
7284#ifdef FEAT_DIFF
7285 /* 'diffopt' */
7286 else if (varp == &p_dip)
7287 {
7288 if (diffopt_changed() == FAIL)
7289 errmsg = e_invarg;
7290 }
7291#endif
7292
7293#ifdef FEAT_FOLDING
7294 /* 'foldmethod' */
7295 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7296 {
7297 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7298 || *curwin->w_p_fdm == NUL)
7299 errmsg = e_invarg;
7300 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007301 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007302 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007303 if (foldmethodIsDiff(curwin))
7304 newFoldLevel();
7305 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007306 }
7307# ifdef FEAT_EVAL
7308 /* 'foldexpr' */
7309 else if (varp == &curwin->w_p_fde)
7310 {
7311 if (foldmethodIsExpr(curwin))
7312 foldUpdateAll(curwin);
7313 }
7314# endif
7315 /* 'foldmarker' */
7316 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7317 {
7318 p = vim_strchr(*varp, ',');
7319 if (p == NULL)
7320 errmsg = (char_u *)N_("E536: comma required");
7321 else if (p == *varp || p[1] == NUL)
7322 errmsg = e_invarg;
7323 else if (foldmethodIsMarker(curwin))
7324 foldUpdateAll(curwin);
7325 }
7326 /* 'commentstring' */
7327 else if (gvarp == &p_cms)
7328 {
7329 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7330 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7331 }
7332 /* 'foldopen' */
7333 else if (varp == &p_fdo)
7334 {
7335 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7336 errmsg = e_invarg;
7337 }
7338 /* 'foldclose' */
7339 else if (varp == &p_fcl)
7340 {
7341 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7342 errmsg = e_invarg;
7343 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007344 /* 'foldignore' */
7345 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7346 {
7347 if (foldmethodIsIndent(curwin))
7348 foldUpdateAll(curwin);
7349 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350#endif
7351
7352#ifdef FEAT_VIRTUALEDIT
7353 /* 'virtualedit' */
7354 else if (varp == &p_ve)
7355 {
7356 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7357 errmsg = e_invarg;
7358 else if (STRCMP(p_ve, oldval) != 0)
7359 {
7360 /* Recompute cursor position in case the new 've' setting
7361 * changes something. */
7362 validate_virtcol();
7363 coladvance(curwin->w_virtcol);
7364 }
7365 }
7366#endif
7367
7368#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7369 else if (varp == &p_csqf)
7370 {
7371 if (p_csqf != NULL)
7372 {
7373 p = p_csqf;
7374 while (*p != NUL)
7375 {
7376 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7377 || p[1] == NUL
7378 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7379 || (p[2] != NUL && p[2] != ','))
7380 {
7381 errmsg = e_invarg;
7382 break;
7383 }
7384 else if (p[2] == NUL)
7385 break;
7386 else
7387 p += 3;
7388 }
7389 }
7390 }
7391#endif
7392
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007393#ifdef FEAT_CINDENT
7394 /* 'cinoptions' */
7395 else if (gvarp == &p_cino)
7396 {
7397 /* TODO: recognize errors */
7398 parse_cino(curbuf);
7399 }
7400#endif
7401
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007402#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007403 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007404 else if (varp == &p_rop && gui.in_use)
7405 {
7406 if (!gui_mch_set_rendering_options(p_rop))
7407 errmsg = e_invarg;
7408 }
7409#endif
7410
Bram Moolenaard0b51382016-11-04 15:23:45 +01007411#ifdef FEAT_AUTOCMD
7412 else if (gvarp == &p_ft)
7413 {
7414 if (!valid_filetype(*varp))
7415 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007416 else
7417 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007418 }
7419#endif
7420
7421#ifdef FEAT_SYN_HL
7422 else if (gvarp == &p_syn)
7423 {
7424 if (!valid_filetype(*varp))
7425 errmsg = e_invarg;
7426 }
7427#endif
7428
Bram Moolenaar825680f2017-07-22 17:04:02 +02007429#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007430 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007431 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007432 {
7433 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7434 errmsg = e_invarg;
7435 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007436 /* 'termsize' */
7437 else if (varp == &curwin->w_p_tms)
7438 {
7439 if (*curwin->w_p_tms != NUL)
7440 {
7441 p = skipdigits(curwin->w_p_tms);
7442 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7443 errmsg = e_invarg;
7444 }
7445 }
7446#endif
7447
Bram Moolenaar071d4272004-06-13 20:20:40 +00007448 /* Options that are a list of flags. */
7449 else
7450 {
7451 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007452 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007453 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007454 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007455 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007456 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007458 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007460#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007461 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007462 p = (char_u *)COCU_ALL;
7463#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007464 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007465 {
7466#ifdef FEAT_MOUSE
7467 p = (char_u *)MOUSE_ALL;
7468#else
7469 if (*p_mouse != NUL)
7470 errmsg = (char_u *)N_("E538: No mouse support");
7471#endif
7472 }
7473#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007474 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007475 p = (char_u *)GO_ALL;
7476#endif
7477 if (p != NULL)
7478 {
7479 for (s = *varp; *s; ++s)
7480 if (vim_strchr(p, *s) == NULL)
7481 {
7482 errmsg = illegal_char(errbuf, *s);
7483 break;
7484 }
7485 }
7486 }
7487
7488 /*
7489 * If error detected, restore the previous value.
7490 */
7491 if (errmsg != NULL)
7492 {
7493 if (new_value_alloced)
7494 free_string_option(*varp);
7495 *varp = oldval;
7496 /*
7497 * When resetting some values, need to act on it.
7498 */
7499 if (did_chartab)
7500 (void)init_chartab();
7501 if (varp == &p_hl)
7502 (void)highlight_changed();
7503 }
7504 else
7505 {
7506#ifdef FEAT_EVAL
7507 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007508 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007509#endif
7510 /*
7511 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007512 * Use "free_oldval", because recursiveness may change the flags under
7513 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007515 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007516 free_string_option(oldval);
7517 if (new_value_alloced)
7518 options[opt_idx].flags |= P_ALLOCED;
7519 else
7520 options[opt_idx].flags &= ~P_ALLOCED;
7521
7522 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007523 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007524 {
7525 /* global option with local value set to use global value; free
7526 * the local value and make it empty */
7527 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7528 free_string_option(*(char_u **)p);
7529 *(char_u **)p = empty_option;
7530 }
7531
7532 /* May set global value for local option. */
7533 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7534 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007535
7536#ifdef FEAT_AUTOCMD
7537 /*
7538 * Trigger the autocommand only after setting the flags.
7539 */
7540# ifdef FEAT_SYN_HL
7541 /* When 'syntax' is set, load the syntax of that name */
7542 if (varp == &(curbuf->b_p_syn))
7543 {
7544 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7545 curbuf->b_fname, TRUE, curbuf);
7546 }
7547# endif
7548 else if (varp == &(curbuf->b_p_ft))
7549 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007550 /* 'filetype' is set, trigger the FileType autocommand.
7551 * Skip this when called from a modeline and the filetype was
7552 * already set to this value. */
7553 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7554 {
7555 did_filetype = TRUE;
7556 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007557 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007558 /* Just in case the old "curbuf" is now invalid. */
7559 if (varp != &(curbuf->b_p_ft))
7560 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007561 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007562 }
7563#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007564#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007565 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007566 {
7567 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007568 char_u *q = curwin->w_s->b_p_spl;
7569
7570 /* Skip the first name if it is "cjk". */
7571 if (STRNCMP(q, "cjk,", 4) == 0)
7572 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007573
7574 /*
7575 * Source the spell/LANG.vim in 'runtimepath'.
7576 * They could set 'spellcapcheck' depending on the language.
7577 * Use the first name in 'spelllang' up to '_region' or
7578 * '.encoding'.
7579 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007580 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007581 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7582 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007583 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007584 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007585 }
7586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007587 }
7588
7589#ifdef FEAT_MOUSE
7590 if (varp == &p_mouse)
7591 {
7592# ifdef FEAT_MOUSE_TTY
7593 if (*p_mouse == NUL)
7594 mch_setmouse(FALSE); /* switch mouse off */
7595 else
7596# endif
7597 setmouse(); /* in case 'mouse' changed */
7598 }
7599#endif
7600
Bram Moolenaar913077c2012-03-28 19:59:04 +02007601 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007602 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007603 curwin->w_set_curswant = TRUE;
7604
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007605#ifdef FEAT_GUI
7606 /* check redraw when it's not a GUI option or the GUI is active. */
7607 if (!redraw_gui_only || gui.in_use)
7608#endif
7609 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007610
7611 return errmsg;
7612}
7613
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007614#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007615/*
7616 * Simple int comparison function for use with qsort()
7617 */
7618 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007619int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007620{
7621 return *(const int *)a - *(const int *)b;
7622}
7623
7624/*
7625 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7626 * Returns error message, NULL if it's OK.
7627 */
7628 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007629check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007630{
7631 char_u *s;
7632 int col;
7633 int count = 0;
7634 int color_cols[256];
7635 int i;
7636 int j = 0;
7637
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007638 if (wp->w_buffer == NULL)
7639 return NULL; /* buffer was closed */
7640
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007641 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007642 {
7643 if (*s == '-' || *s == '+')
7644 {
7645 /* -N and +N: add to 'textwidth' */
7646 col = (*s == '-') ? -1 : 1;
7647 ++s;
7648 if (!VIM_ISDIGIT(*s))
7649 return e_invarg;
7650 col = col * getdigits(&s);
7651 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007652 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007653 col += wp->w_buffer->b_p_tw;
7654 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007655 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007656 }
7657 else if (VIM_ISDIGIT(*s))
7658 col = getdigits(&s);
7659 else
7660 return e_invarg;
7661 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007662skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007663 if (*s == NUL)
7664 break;
7665 if (*s != ',')
7666 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007667 if (*++s == NUL)
7668 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007669 }
7670
7671 vim_free(wp->w_p_cc_cols);
7672 if (count == 0)
7673 wp->w_p_cc_cols = NULL;
7674 else
7675 {
7676 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7677 if (wp->w_p_cc_cols != NULL)
7678 {
7679 /* sort the columns for faster usage on screen redraw inside
7680 * win_line() */
7681 qsort(color_cols, count, sizeof(int), int_cmp);
7682
7683 for (i = 0; i < count; ++i)
7684 /* skip duplicates */
7685 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7686 wp->w_p_cc_cols[j++] = color_cols[i];
7687 wp->w_p_cc_cols[j] = -1; /* end marker */
7688 }
7689 }
7690
7691 return NULL; /* no error */
7692}
7693#endif
7694
Bram Moolenaar071d4272004-06-13 20:20:40 +00007695/*
7696 * Handle setting 'listchars' or 'fillchars'.
7697 * Returns error message, NULL if it's OK.
7698 */
7699 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007700set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007701{
7702 int round, i, len, entries;
7703 char_u *p, *s;
7704 int c1, c2 = 0;
7705 struct charstab
7706 {
7707 int *cp;
7708 char *name;
7709 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710 static struct charstab filltab[] =
7711 {
7712 {&fill_stl, "stl"},
7713 {&fill_stlnc, "stlnc"},
7714 {&fill_vert, "vert"},
7715 {&fill_fold, "fold"},
7716 {&fill_diff, "diff"},
7717 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718 static struct charstab lcstab[] =
7719 {
7720 {&lcs_eol, "eol"},
7721 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007722 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007724 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007725 {&lcs_tab2, "tab"},
7726 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007727#ifdef FEAT_CONCEAL
7728 {&lcs_conceal, "conceal"},
7729#else
7730 {NULL, "conceal"},
7731#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732 };
7733 struct charstab *tab;
7734
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 {
7737 tab = lcstab;
7738 entries = sizeof(lcstab) / sizeof(struct charstab);
7739 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007740 else
7741 {
7742 tab = filltab;
7743 entries = sizeof(filltab) / sizeof(struct charstab);
7744 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007745
7746 /* first round: check for valid value, second round: assign values */
7747 for (round = 0; round <= 1; ++round)
7748 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007749 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 {
7751 /* After checking that the value is valid: set defaults: space for
7752 * 'fillchars', NUL for 'listchars' */
7753 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007754 if (tab[i].cp != NULL)
7755 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007756 if (varp == &p_lcs)
7757 lcs_tab1 = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 else
7759 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007760 }
7761 p = *varp;
7762 while (*p)
7763 {
7764 for (i = 0; i < entries; ++i)
7765 {
7766 len = (int)STRLEN(tab[i].name);
7767 if (STRNCMP(p, tab[i].name, len) == 0
7768 && p[len] == ':'
7769 && p[len + 1] != NUL)
7770 {
7771 s = p + len + 1;
7772#ifdef FEAT_MBYTE
7773 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007774 if (mb_char2cells(c1) > 1)
7775 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007776#else
7777 c1 = *s++;
7778#endif
7779 if (tab[i].cp == &lcs_tab2)
7780 {
7781 if (*s == NUL)
7782 continue;
7783#ifdef FEAT_MBYTE
7784 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007785 if (mb_char2cells(c2) > 1)
7786 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787#else
7788 c2 = *s++;
7789#endif
7790 }
7791 if (*s == ',' || *s == NUL)
7792 {
7793 if (round)
7794 {
7795 if (tab[i].cp == &lcs_tab2)
7796 {
7797 lcs_tab1 = c1;
7798 lcs_tab2 = c2;
7799 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007800 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801 *(tab[i].cp) = c1;
7802
7803 }
7804 p = s;
7805 break;
7806 }
7807 }
7808 }
7809
7810 if (i == entries)
7811 return e_invarg;
7812 if (*p == ',')
7813 ++p;
7814 }
7815 }
7816
7817 return NULL; /* no error */
7818}
7819
7820#ifdef FEAT_STL_OPT
7821/*
7822 * Check validity of options with the 'statusline' format.
7823 * Return error message or NULL.
7824 */
7825 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007826check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007827{
7828 int itemcnt = 0;
7829 int groupdepth = 0;
7830 static char_u errbuf[80];
7831
7832 while (*s && itemcnt < STL_MAX_ITEM)
7833 {
7834 /* Check for valid keys after % sequences */
7835 while (*s && *s != '%')
7836 s++;
7837 if (!*s)
7838 break;
7839 s++;
7840 if (*s != '%' && *s != ')')
7841 ++itemcnt;
7842 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7843 {
7844 s++;
7845 continue;
7846 }
7847 if (*s == ')')
7848 {
7849 s++;
7850 if (--groupdepth < 0)
7851 break;
7852 continue;
7853 }
7854 if (*s == '-')
7855 s++;
7856 while (VIM_ISDIGIT(*s))
7857 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007858 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859 continue;
7860 if (*s == '.')
7861 {
7862 s++;
7863 while (*s && VIM_ISDIGIT(*s))
7864 s++;
7865 }
7866 if (*s == '(')
7867 {
7868 groupdepth++;
7869 continue;
7870 }
7871 if (vim_strchr(STL_ALL, *s) == NULL)
7872 {
7873 return illegal_char(errbuf, *s);
7874 }
7875 if (*s == '{')
7876 {
7877 s++;
7878 while (*s != '}' && *s)
7879 s++;
7880 if (*s != '}')
7881 return (char_u *)N_("E540: Unclosed expression sequence");
7882 }
7883 }
7884 if (itemcnt >= STL_MAX_ITEM)
7885 return (char_u *)N_("E541: too many items");
7886 if (groupdepth != 0)
7887 return (char_u *)N_("E542: unbalanced groups");
7888 return NULL;
7889}
7890#endif
7891
7892#ifdef FEAT_CLIPBOARD
7893/*
7894 * Extract the items in the 'clipboard' option and set global values.
7895 */
7896 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007897check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007899 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007900 int new_autoselect_star = FALSE;
7901 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007903 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 regprog_T *new_exclude_prog = NULL;
7905 char_u *errmsg = NULL;
7906 char_u *p;
7907
7908 for (p = p_cb; *p != NUL; )
7909 {
7910 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7911 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007912 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 p += 7;
7914 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007915 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007916 && (p[11] == ',' || p[11] == NUL))
7917 {
7918 new_unnamed |= CLIP_UNNAMED_PLUS;
7919 p += 11;
7920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007922 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007923 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007924 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 p += 10;
7926 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007927 else if (STRNCMP(p, "autoselectplus", 14) == 0
7928 && (p[14] == ',' || p[14] == NUL))
7929 {
7930 new_autoselect_plus = TRUE;
7931 p += 14;
7932 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007933 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007934 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935 {
7936 new_autoselectml = TRUE;
7937 p += 12;
7938 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007939 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7940 {
7941 new_html = TRUE;
7942 p += 4;
7943 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7945 {
7946 p += 8;
7947 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7948 if (new_exclude_prog == NULL)
7949 errmsg = e_invarg;
7950 break;
7951 }
7952 else
7953 {
7954 errmsg = e_invarg;
7955 break;
7956 }
7957 if (*p == ',')
7958 ++p;
7959 }
7960 if (errmsg == NULL)
7961 {
7962 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007963 clip_autoselect_star = new_autoselect_star;
7964 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007965 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007966 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007967 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007969#ifdef FEAT_GUI_GTK
7970 if (gui.in_use)
7971 {
7972 gui_gtk_set_selection_targets();
7973 gui_gtk_set_dnd_targets();
7974 }
7975#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976 }
7977 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007978 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007979
7980 return errmsg;
7981}
7982#endif
7983
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007984#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007985 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007986did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007987{
7988 char_u *errmsg = NULL;
7989 win_T *wp;
7990 int l;
7991
7992 if (is_spellfile)
7993 {
7994 l = (int)STRLEN(curwin->w_s->b_p_spf);
7995 if (l > 0 && (l < 4
7996 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7997 errmsg = e_invarg;
7998 }
7999
8000 if (errmsg == NULL)
8001 {
8002 FOR_ALL_WINDOWS(wp)
8003 if (wp->w_buffer == curbuf && wp->w_p_spell)
8004 {
8005 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008006 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008007 }
8008 }
8009 return errmsg;
8010}
8011
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008012/*
8013 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8014 * Return error message when failed, NULL when OK.
8015 */
8016 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008017compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008018{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008019 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008020 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008021
Bram Moolenaar860cae12010-06-05 23:22:07 +02008022 if (*synblock->b_p_spc == NUL)
8023 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008024 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008025 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008026 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008027 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008028 if (re != NULL)
8029 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008030 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008031 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008032 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008033 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008034 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008035 return e_invarg;
8036 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008037 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008038 }
8039
Bram Moolenaar473de612013-06-08 18:19:48 +02008040 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008041 return NULL;
8042}
8043#endif
8044
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008045#if defined(FEAT_EVAL) || defined(PROTO)
8046/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008047 * Set the scriptID for an option, taking care of setting the buffer- or
8048 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008049 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008050 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008051set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008052{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008053 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8054 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008055
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008056 /* Remember where the option was set. For local options need to do that
8057 * in the buffer or window structure. */
8058 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008059 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008060 if (both || (opt_flags & OPT_LOCAL))
8061 {
8062 if (indir & PV_BUF)
8063 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8064 else if (indir & PV_WIN)
8065 curwin->w_p_scriptID[indir & PV_MASK] = id;
8066 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008067}
8068#endif
8069
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070/*
8071 * Set the value of a boolean option, and take care of side effects.
8072 * Returns NULL for success, or an error message for an error.
8073 */
8074 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008075set_bool_option(
8076 int opt_idx, /* index in options[] table */
8077 char_u *varp, /* pointer to the option variable */
8078 int value, /* new value */
8079 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008080{
8081 int old_value = *(int *)varp;
8082
Bram Moolenaar071d4272004-06-13 20:20:40 +00008083 /* Disallow changing some options from secure mode */
8084 if ((secure
8085#ifdef HAVE_SANDBOX
8086 || sandbox != 0
8087#endif
8088 ) && (options[opt_idx].flags & P_SECURE))
8089 return e_secure;
8090
8091 *(int *)varp = value; /* set the new value */
8092#ifdef FEAT_EVAL
8093 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008094 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095#endif
8096
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008097#ifdef FEAT_GUI
8098 need_mouse_correct = TRUE;
8099#endif
8100
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101 /* May set global value for local option. */
8102 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8103 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8104
8105 /*
8106 * Handle side effects of changing a bool option.
8107 */
8108
8109 /* 'compatible' */
8110 if ((int *)varp == &p_cp)
8111 {
8112 compatible_set();
8113 }
8114
Bram Moolenaar920694c2016-08-21 17:45:02 +02008115#ifdef FEAT_LANGMAP
8116 if ((int *)varp == &p_lrm)
8117 /* 'langremap' -> !'langnoremap' */
8118 p_lnr = !p_lrm;
8119 else if ((int *)varp == &p_lnr)
8120 /* 'langnoremap' -> !'langremap' */
8121 p_lrm = !p_lnr;
8122#endif
8123
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008124#ifdef FEAT_PERSISTENT_UNDO
8125 /* 'undofile' */
8126 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8127 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008128 /* Only take action when the option was set. When reset we do not
8129 * delete the undo file, the option may be set again without making
8130 * any changes in between. */
8131 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008132 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008133 char_u hash[UNDO_HASH_SIZE];
8134 buf_T *save_curbuf = curbuf;
8135
Bram Moolenaar29323592016-07-24 22:04:11 +02008136 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008137 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008138 /* When 'undofile' is set globally: for every buffer, otherwise
8139 * only for the current buffer: Try to read in the undofile,
8140 * if one exists, the buffer wasn't changed and the buffer was
8141 * loaded */
8142 if ((curbuf == save_curbuf
8143 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8144 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8145 {
8146 u_compute_hash(hash);
8147 u_read_undo(NULL, hash, curbuf->b_fname);
8148 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008149 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008150 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008151 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008152 }
8153#endif
8154
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 else if ((int *)varp == &curbuf->b_p_ro)
8156 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008157 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8159 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008160
8161 /* when 'readonly' is set may give W10 again */
8162 if (curbuf->b_p_ro)
8163 curbuf->b_did_warn = FALSE;
8164
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008166 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167#endif
8168 }
8169
Bram Moolenaar9c449722010-07-20 18:44:27 +02008170#ifdef FEAT_GUI
8171 else if ((int *)varp == &p_mh)
8172 {
8173 if (!p_mh)
8174 gui_mch_mousehide(FALSE);
8175 }
8176#endif
8177
Bram Moolenaara539df02010-08-01 14:35:05 +02008178 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008179 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008180 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008181# ifdef FEAT_TERMINAL
8182 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008183 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008184 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008185 {
8186 curbuf->b_p_ma = FALSE;
8187 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8188 }
8189# endif
8190# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008191 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008192# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008193 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008194#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195 /* when 'endofline' is changed, redraw the window title */
8196 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008197 {
8198 redraw_titles();
8199 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008200 /* when 'fixeol' is changed, redraw the window title */
8201 else if ((int *)varp == &curbuf->b_p_fixeol)
8202 {
8203 redraw_titles();
8204 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008205# ifdef FEAT_MBYTE
8206 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008207 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008208 {
8209 redraw_titles();
8210 }
8211# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008212#endif
8213
8214 /* when 'bin' is set also set some other options */
8215 else if ((int *)varp == &curbuf->b_p_bin)
8216 {
8217 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8218#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008219 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220#endif
8221 }
8222
8223#ifdef FEAT_AUTOCMD
8224 /* when 'buflisted' changes, trigger autocommands */
8225 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8226 {
8227 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8228 NULL, NULL, TRUE, curbuf);
8229 }
8230#endif
8231
8232 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8233 else if ((int *)varp == &curbuf->b_p_swf)
8234 {
8235 if (curbuf->b_p_swf && p_uc)
8236 ml_open_file(curbuf); /* create the swap file */
8237 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008238 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8239 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008240 mf_close_file(curbuf, TRUE); /* remove the swap file */
8241 }
8242
8243 /* when 'terse' is set change 'shortmess' */
8244 else if ((int *)varp == &p_terse)
8245 {
8246 char_u *p;
8247
8248 p = vim_strchr(p_shm, SHM_SEARCH);
8249
8250 /* insert 's' in p_shm */
8251 if (p_terse && p == NULL)
8252 {
8253 STRCPY(IObuff, p_shm);
8254 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008255 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008256 }
8257 /* remove 's' from p_shm */
8258 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008259 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008260 }
8261
8262 /* when 'paste' is set or reset also change other options */
8263 else if ((int *)varp == &p_paste)
8264 {
8265 paste_option_changed();
8266 }
8267
8268 /* when 'insertmode' is set from an autocommand need to do work here */
8269 else if ((int *)varp == &p_im)
8270 {
8271 if (p_im)
8272 {
8273 if ((State & INSERT) == 0)
8274 need_start_insertmode = TRUE;
8275 stop_insert_mode = FALSE;
8276 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008277 /* only reset if it was set previously */
8278 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008279 {
8280 need_start_insertmode = FALSE;
8281 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008282 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008283 clear_cmdline = TRUE; /* remove "(insert)" */
8284 restart_edit = 0;
8285 }
8286 }
8287
8288 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8289 else if ((int *)varp == &p_ic && p_hls)
8290 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008291 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008292 }
8293
8294#ifdef FEAT_SEARCH_EXTRA
8295 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8296 else if ((int *)varp == &p_hls)
8297 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008298 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008299 }
8300#endif
8301
8302#ifdef FEAT_SCROLLBIND
8303 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8304 * at the end of normal_cmd() */
8305 else if ((int *)varp == &curwin->w_p_scb)
8306 {
8307 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008308 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008309 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008310 curwin->w_scbind_pos = curwin->w_topline;
8311 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008312 }
8313#endif
8314
Bram Moolenaar4033c552017-09-16 20:54:51 +02008315#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 /* There can be only one window with 'previewwindow' set. */
8317 else if ((int *)varp == &curwin->w_p_pvw)
8318 {
8319 if (curwin->w_p_pvw)
8320 {
8321 win_T *win;
8322
Bram Moolenaar29323592016-07-24 22:04:11 +02008323 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 if (win->w_p_pvw && win != curwin)
8325 {
8326 curwin->w_p_pvw = FALSE;
8327 return (char_u *)N_("E590: A preview window already exists");
8328 }
8329 }
8330 }
8331#endif
8332
8333 /* when 'textmode' is set or reset also change 'fileformat' */
8334 else if ((int *)varp == &curbuf->b_p_tx)
8335 {
8336 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8337 }
8338
8339 /* when 'textauto' is set or reset also change 'fileformats' */
8340 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008341 set_string_option_direct((char_u *)"ffs", -1,
8342 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008343 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008344
8345 /*
8346 * When 'lisp' option changes include/exclude '-' in
8347 * keyword characters.
8348 */
8349#ifdef FEAT_LISP
8350 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8351 {
8352 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8353 }
8354#endif
8355
8356#ifdef FEAT_TITLE
8357 /* when 'title' changed, may need to change the title; same for 'icon' */
8358 else if ((int *)varp == &p_title)
8359 {
8360 did_set_title(FALSE);
8361 }
8362
8363 else if ((int *)varp == &p_icon)
8364 {
8365 did_set_title(TRUE);
8366 }
8367#endif
8368
8369 else if ((int *)varp == &curbuf->b_changed)
8370 {
8371 if (!value)
8372 save_file_ff(curbuf); /* Buffer is unchanged */
8373#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008374 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375#endif
8376#ifdef FEAT_AUTOCMD
8377 modified_was_set = value;
8378#endif
8379 }
8380
8381#ifdef BACKSLASH_IN_FILENAME
8382 else if ((int *)varp == &p_ssl)
8383 {
8384 if (p_ssl)
8385 {
8386 psepc = '/';
8387 psepcN = '\\';
8388 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389 }
8390 else
8391 {
8392 psepc = '\\';
8393 psepcN = '/';
8394 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008395 }
8396
8397 /* need to adjust the file name arguments and buffer names. */
8398 buflist_slash_adjust();
8399 alist_slash_adjust();
8400# ifdef FEAT_EVAL
8401 scriptnames_slash_adjust();
8402# endif
8403 }
8404#endif
8405
8406 /* If 'wrap' is set, set w_leftcol to zero. */
8407 else if ((int *)varp == &curwin->w_p_wrap)
8408 {
8409 if (curwin->w_p_wrap)
8410 curwin->w_leftcol = 0;
8411 }
8412
Bram Moolenaar071d4272004-06-13 20:20:40 +00008413 else if ((int *)varp == &p_ea)
8414 {
8415 if (p_ea && !old_value)
8416 win_equal(curwin, FALSE, 0);
8417 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418
8419 else if ((int *)varp == &p_wiv)
8420 {
8421 /*
8422 * When 'weirdinvert' changed, set/reset 't_xs'.
8423 * Then set 'weirdinvert' according to value of 't_xs'.
8424 */
8425 if (p_wiv && !old_value)
8426 T_XS = (char_u *)"y";
8427 else if (!p_wiv && old_value)
8428 T_XS = empty_option;
8429 p_wiv = (*T_XS != NUL);
8430 }
8431
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008432#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433 else if ((int *)varp == &p_beval)
8434 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008435 if (!balloonEvalForTerm)
8436 {
8437 if (p_beval && !old_value)
8438 gui_mch_enable_beval_area(balloonEval);
8439 else if (!p_beval && old_value)
8440 gui_mch_disable_beval_area(balloonEval);
8441 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008442 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008443#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008444#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008445 else if ((int *)varp == &p_bevalterm)
8446 {
8447 mch_bevalterm_changed();
8448 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008449#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008451#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008452 else if ((int *)varp == &p_acd)
8453 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008454 /* Change directories when the 'acd' option is set now. */
8455 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008456 }
8457#endif
8458
8459#ifdef FEAT_DIFF
8460 /* 'diff' */
8461 else if ((int *)varp == &curwin->w_p_diff)
8462 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008463 /* May add or remove the buffer from the list of diff buffers. */
8464 diff_buf_adjust(curwin);
8465# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466 if (foldmethodIsDiff(curwin))
8467 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008468# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008469 }
8470#endif
8471
8472#ifdef USE_IM_CONTROL
8473 /* 'imdisable' */
8474 else if ((int *)varp == &p_imdisable)
8475 {
8476 /* Only de-activate it here, it will be enabled when changing mode. */
8477 if (p_imdisable)
8478 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008479 else if (State & INSERT)
8480 /* When the option is set from an autocommand, it may need to take
8481 * effect right away. */
8482 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 }
8484#endif
8485
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008486#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008487 /* 'spell' */
8488 else if ((int *)varp == &curwin->w_p_spell)
8489 {
8490 if (curwin->w_p_spell)
8491 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008492 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008493 if (errmsg != NULL)
8494 EMSG(_(errmsg));
8495 }
8496 }
8497#endif
8498
Bram Moolenaar071d4272004-06-13 20:20:40 +00008499#ifdef FEAT_FKMAP
8500 else if ((int *)varp == &p_altkeymap)
8501 {
8502 if (old_value != p_altkeymap)
8503 {
8504 if (!p_altkeymap)
8505 {
8506 p_hkmap = p_fkmap;
8507 p_fkmap = 0;
8508 }
8509 else
8510 {
8511 p_fkmap = p_hkmap;
8512 p_hkmap = 0;
8513 }
8514 (void)init_chartab();
8515 }
8516 }
8517
8518 /*
8519 * In case some second language keymapping options have changed, check
8520 * and correct the setting in a consistent way.
8521 */
8522
8523 /*
8524 * If hkmap or fkmap are set, reset Arabic keymapping.
8525 */
8526 if ((p_hkmap || p_fkmap) && p_altkeymap)
8527 {
8528 p_altkeymap = p_fkmap;
8529# ifdef FEAT_ARABIC
8530 curwin->w_p_arab = FALSE;
8531# endif
8532 (void)init_chartab();
8533 }
8534
8535 /*
8536 * If hkmap set, reset Farsi keymapping.
8537 */
8538 if (p_hkmap && p_altkeymap)
8539 {
8540 p_altkeymap = 0;
8541 p_fkmap = 0;
8542# ifdef FEAT_ARABIC
8543 curwin->w_p_arab = FALSE;
8544# endif
8545 (void)init_chartab();
8546 }
8547
8548 /*
8549 * If fkmap set, reset Hebrew keymapping.
8550 */
8551 if (p_fkmap && !p_altkeymap)
8552 {
8553 p_altkeymap = 1;
8554 p_hkmap = 0;
8555# ifdef FEAT_ARABIC
8556 curwin->w_p_arab = FALSE;
8557# endif
8558 (void)init_chartab();
8559 }
8560#endif
8561
8562#ifdef FEAT_ARABIC
8563 if ((int *)varp == &curwin->w_p_arab)
8564 {
8565 if (curwin->w_p_arab)
8566 {
8567 /*
8568 * 'arabic' is set, handle various sub-settings.
8569 */
8570 if (!p_tbidi)
8571 {
8572 /* set rightleft mode */
8573 if (!curwin->w_p_rl)
8574 {
8575 curwin->w_p_rl = TRUE;
8576 changed_window_setting();
8577 }
8578
8579 /* Enable Arabic shaping (major part of what Arabic requires) */
8580 if (!p_arshape)
8581 {
8582 p_arshape = TRUE;
8583 redraw_later_clear();
8584 }
8585 }
8586
8587 /* Arabic requires a utf-8 encoding, inform the user if its not
8588 * set. */
8589 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008590 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008591 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8592
Bram Moolenaar8820b482017-03-16 17:23:31 +01008593 msg_source(HL_ATTR(HLF_W));
8594 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008595#ifdef FEAT_EVAL
8596 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8597#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008598 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008599
8600# ifdef FEAT_MBYTE
8601 /* set 'delcombine' */
8602 p_deco = TRUE;
8603# endif
8604
8605# ifdef FEAT_KEYMAP
8606 /* Force-set the necessary keymap for arabic */
8607 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8608 OPT_LOCAL);
8609# endif
8610# ifdef FEAT_FKMAP
8611 p_altkeymap = 0;
8612 p_hkmap = 0;
8613 p_fkmap = 0;
8614 (void)init_chartab();
8615# endif
8616 }
8617 else
8618 {
8619 /*
8620 * 'arabic' is reset, handle various sub-settings.
8621 */
8622 if (!p_tbidi)
8623 {
8624 /* reset rightleft mode */
8625 if (curwin->w_p_rl)
8626 {
8627 curwin->w_p_rl = FALSE;
8628 changed_window_setting();
8629 }
8630
8631 /* 'arabicshape' isn't reset, it is a global option and
8632 * another window may still need it "on". */
8633 }
8634
8635 /* 'delcombine' isn't reset, it is a global option and another
8636 * window may still want it "on". */
8637
8638# ifdef FEAT_KEYMAP
8639 /* Revert to the default keymap */
8640 curbuf->b_p_iminsert = B_IMODE_NONE;
8641 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8642# endif
8643 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008644 }
8645
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008646#endif
8647
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008648#ifdef FEAT_TERMGUICOLORS
8649 /* 'termguicolors' */
8650 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008651 {
8652# ifdef FEAT_GUI
8653 if (!gui.in_use && !gui.starting)
8654# endif
8655 highlight_gui_started();
8656 }
8657#endif
8658
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659 /*
8660 * End of handling side effects for bool options.
8661 */
8662
Bram Moolenaar53744302015-07-17 17:38:22 +02008663 /* after handling side effects, call autocommand */
8664
Bram Moolenaar071d4272004-06-13 20:20:40 +00008665 options[opt_idx].flags |= P_WAS_SET;
8666
Bram Moolenaar53744302015-07-17 17:38:22 +02008667#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8668 if (!starting)
8669 {
8670 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008671 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8672 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8673 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008674 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8675 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8676 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8677 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8678 reset_v_option_vars();
8679 }
8680#endif
8681
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008683 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008684 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008685 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008686 check_redraw(options[opt_idx].flags);
8687
8688 return NULL;
8689}
8690
8691/*
8692 * Set the value of a number option, and take care of side effects.
8693 * Returns NULL for success, or an error message for an error.
8694 */
8695 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008696set_num_option(
8697 int opt_idx, /* index in options[] table */
8698 char_u *varp, /* pointer to the option variable */
8699 long value, /* new value */
8700 char_u *errbuf, /* buffer for error messages */
8701 size_t errbuflen, /* length of "errbuf" */
8702 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703 OPT_MODELINE */
8704{
8705 char_u *errmsg = NULL;
8706 long old_value = *(long *)varp;
8707 long old_Rows = Rows; /* remember old Rows */
8708 long old_Columns = Columns; /* remember old Columns */
8709 long *pp = (long *)varp;
8710
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008711 /* Disallow changing some options from secure mode. */
8712 if ((secure
8713#ifdef HAVE_SANDBOX
8714 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008715#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008716 ) && (options[opt_idx].flags & P_SECURE))
8717 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718
8719 *pp = value;
8720#ifdef FEAT_EVAL
8721 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008722 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008724#ifdef FEAT_GUI
8725 need_mouse_correct = TRUE;
8726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008727
Bram Moolenaar14f24742012-08-08 18:01:05 +02008728 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729 {
8730 errmsg = e_positive;
8731 curbuf->b_p_sw = curbuf->b_p_ts;
8732 }
8733
8734 /*
8735 * Number options that need some action when changed
8736 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008737 if (pp == &p_wh || pp == &p_hh)
8738 {
8739 if (p_wh < 1)
8740 {
8741 errmsg = e_positive;
8742 p_wh = 1;
8743 }
8744 if (p_wmh > p_wh)
8745 {
8746 errmsg = e_winheight;
8747 p_wh = p_wmh;
8748 }
8749 if (p_hh < 0)
8750 {
8751 errmsg = e_positive;
8752 p_hh = 0;
8753 }
8754
8755 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008756 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757 {
8758 if (pp == &p_wh && curwin->w_height < p_wh)
8759 win_setheight((int)p_wh);
8760 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8761 win_setheight((int)p_hh);
8762 }
8763 }
8764
8765 /* 'winminheight' */
8766 else if (pp == &p_wmh)
8767 {
8768 if (p_wmh < 0)
8769 {
8770 errmsg = e_positive;
8771 p_wmh = 0;
8772 }
8773 if (p_wmh > p_wh)
8774 {
8775 errmsg = e_winheight;
8776 p_wmh = p_wh;
8777 }
8778 win_setminheight();
8779 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008780 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781 {
8782 if (p_wiw < 1)
8783 {
8784 errmsg = e_positive;
8785 p_wiw = 1;
8786 }
8787 if (p_wmw > p_wiw)
8788 {
8789 errmsg = e_winwidth;
8790 p_wiw = p_wmw;
8791 }
8792
8793 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008794 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 win_setwidth((int)p_wiw);
8796 }
8797
8798 /* 'winminwidth' */
8799 else if (pp == &p_wmw)
8800 {
8801 if (p_wmw < 0)
8802 {
8803 errmsg = e_positive;
8804 p_wmw = 0;
8805 }
8806 if (p_wmw > p_wiw)
8807 {
8808 errmsg = e_winwidth;
8809 p_wmw = p_wiw;
8810 }
8811 win_setminheight();
8812 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813
Bram Moolenaar071d4272004-06-13 20:20:40 +00008814 /* (re)set last window status line */
8815 else if (pp == &p_ls)
8816 {
8817 last_status(FALSE);
8818 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008819
8820 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008821 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008822 {
8823 shell_new_rows(); /* recompute window positions and heights */
8824 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825
8826#ifdef FEAT_GUI
8827 else if (pp == &p_linespace)
8828 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008829 /* Recompute gui.char_height and resize the Vim window to keep the
8830 * same number of lines. */
8831 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008832 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833 }
8834#endif
8835
8836#ifdef FEAT_FOLDING
8837 /* 'foldlevel' */
8838 else if (pp == &curwin->w_p_fdl)
8839 {
8840 if (curwin->w_p_fdl < 0)
8841 curwin->w_p_fdl = 0;
8842 newFoldLevel();
8843 }
8844
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008845 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846 else if (pp == &curwin->w_p_fml)
8847 {
8848 foldUpdateAll(curwin);
8849 }
8850
8851 /* 'foldnestmax' */
8852 else if (pp == &curwin->w_p_fdn)
8853 {
8854 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8855 foldUpdateAll(curwin);
8856 }
8857
8858 /* 'foldcolumn' */
8859 else if (pp == &curwin->w_p_fdc)
8860 {
8861 if (curwin->w_p_fdc < 0)
8862 {
8863 errmsg = e_positive;
8864 curwin->w_p_fdc = 0;
8865 }
8866 else if (curwin->w_p_fdc > 12)
8867 {
8868 errmsg = e_invarg;
8869 curwin->w_p_fdc = 12;
8870 }
8871 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008872#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008874#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008875 /* 'shiftwidth' or 'tabstop' */
8876 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8877 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008878# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008879 if (foldmethodIsIndent(curwin))
8880 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008881# endif
8882# ifdef FEAT_CINDENT
8883 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8884 * parse 'cinoptions'. */
8885 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8886 parse_cino(curbuf);
8887# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008888 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008889#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008890
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008891#ifdef FEAT_MBYTE
8892 /* 'maxcombine' */
8893 else if (pp == &p_mco)
8894 {
8895 if (p_mco > MAX_MCO)
8896 p_mco = MAX_MCO;
8897 else if (p_mco < 0)
8898 p_mco = 0;
8899 screenclear(); /* will re-allocate the screen */
8900 }
8901#endif
8902
Bram Moolenaar071d4272004-06-13 20:20:40 +00008903 else if (pp == &curbuf->b_p_iminsert)
8904 {
8905 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8906 {
8907 errmsg = e_invarg;
8908 curbuf->b_p_iminsert = B_IMODE_NONE;
8909 }
8910 p_iminsert = curbuf->b_p_iminsert;
8911 if (termcap_active) /* don't do this in the alternate screen */
8912 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02008913#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008914 /* Show/unshow value of 'keymap' in status lines. */
8915 status_redraw_curbuf();
8916#endif
8917 }
8918
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02008919#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8920 /* 'imstyle' */
8921 else if (pp == &p_imst)
8922 {
8923 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8924 errmsg = e_invarg;
8925 }
8926#endif
8927
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008928 else if (pp == &p_window)
8929 {
8930 if (p_window < 1)
8931 p_window = 1;
8932 else if (p_window >= Rows)
8933 p_window = Rows - 1;
8934 }
8935
Bram Moolenaar071d4272004-06-13 20:20:40 +00008936 else if (pp == &curbuf->b_p_imsearch)
8937 {
8938 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8939 {
8940 errmsg = e_invarg;
8941 curbuf->b_p_imsearch = B_IMODE_NONE;
8942 }
8943 p_imsearch = curbuf->b_p_imsearch;
8944 }
8945
8946#ifdef FEAT_TITLE
8947 /* if 'titlelen' has changed, redraw the title */
8948 else if (pp == &p_titlelen)
8949 {
8950 if (p_titlelen < 0)
8951 {
8952 errmsg = e_positive;
8953 p_titlelen = 85;
8954 }
8955 if (starting != NO_SCREEN && old_value != p_titlelen)
8956 need_maketitle = TRUE;
8957 }
8958#endif
8959
8960 /* if p_ch changed value, change the command line height */
8961 else if (pp == &p_ch)
8962 {
8963 if (p_ch < 1)
8964 {
8965 errmsg = e_positive;
8966 p_ch = 1;
8967 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008968 if (p_ch > Rows - min_rows() + 1)
8969 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970
8971 /* Only compute the new window layout when startup has been
8972 * completed. Otherwise the frame sizes may be wrong. */
8973 if (p_ch != old_value && full_screen
8974#ifdef FEAT_GUI
8975 && !gui.starting
8976#endif
8977 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008978 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008979 }
8980
8981 /* when 'updatecount' changes from zero to non-zero, open swap files */
8982 else if (pp == &p_uc)
8983 {
8984 if (p_uc < 0)
8985 {
8986 errmsg = e_positive;
8987 p_uc = 100;
8988 }
8989 if (p_uc && !old_value)
8990 ml_open_files();
8991 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008992#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008993 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008994 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008995 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008996 {
8997 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008998 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008999 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009000 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009001 {
9002 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009003 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009004 }
9005 }
9006#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009007#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009008 else if (pp == &p_mzq)
9009 mzvim_reset_timer();
9010#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009011
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009012#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9013 /* 'pyxversion' */
9014 else if (pp == &p_pyx)
9015 {
9016 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9017 errmsg = e_invarg;
9018 }
9019#endif
9020
Bram Moolenaar071d4272004-06-13 20:20:40 +00009021 /* sync undo before 'undolevels' changes */
9022 else if (pp == &p_ul)
9023 {
9024 /* use the old value, otherwise u_sync() may not work properly */
9025 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009026 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009027 p_ul = value;
9028 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009029 else if (pp == &curbuf->b_p_ul)
9030 {
9031 /* use the old value, otherwise u_sync() may not work properly */
9032 curbuf->b_p_ul = old_value;
9033 u_sync(TRUE);
9034 curbuf->b_p_ul = value;
9035 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009036
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009037#ifdef FEAT_LINEBREAK
9038 /* 'numberwidth' must be positive */
9039 else if (pp == &curwin->w_p_nuw)
9040 {
9041 if (curwin->w_p_nuw < 1)
9042 {
9043 errmsg = e_positive;
9044 curwin->w_p_nuw = 1;
9045 }
9046 if (curwin->w_p_nuw > 10)
9047 {
9048 errmsg = e_invarg;
9049 curwin->w_p_nuw = 10;
9050 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009051 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009052 }
9053#endif
9054
Bram Moolenaar1a384422010-07-14 19:53:30 +02009055 else if (pp == &curbuf->b_p_tw)
9056 {
9057 if (curbuf->b_p_tw < 0)
9058 {
9059 errmsg = e_positive;
9060 curbuf->b_p_tw = 0;
9061 }
9062#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009063 {
9064 win_T *wp;
9065 tabpage_T *tp;
9066
9067 FOR_ALL_TAB_WINDOWS(tp, wp)
9068 check_colorcolumn(wp);
9069 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009070#endif
9071 }
9072
Bram Moolenaar071d4272004-06-13 20:20:40 +00009073 /*
9074 * Check the bounds for numeric options here
9075 */
9076 if (Rows < min_rows() && full_screen)
9077 {
9078 if (errbuf != NULL)
9079 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009080 vim_snprintf((char *)errbuf, errbuflen,
9081 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009082 errmsg = errbuf;
9083 }
9084 Rows = min_rows();
9085 }
9086 if (Columns < MIN_COLUMNS && full_screen)
9087 {
9088 if (errbuf != NULL)
9089 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009090 vim_snprintf((char *)errbuf, errbuflen,
9091 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092 errmsg = errbuf;
9093 }
9094 Columns = MIN_COLUMNS;
9095 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009096 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009097
Bram Moolenaar071d4272004-06-13 20:20:40 +00009098 /*
9099 * If the screen (shell) height has been changed, assume it is the
9100 * physical screenheight.
9101 */
9102 if (old_Rows != Rows || old_Columns != Columns)
9103 {
9104 /* Changing the screen size is not allowed while updating the screen. */
9105 if (updating_screen)
9106 *pp = old_value;
9107 else if (full_screen
9108#ifdef FEAT_GUI
9109 && !gui.starting
9110#endif
9111 )
9112 set_shellsize((int)Columns, (int)Rows, TRUE);
9113 else
9114 {
9115 /* Postpone the resizing; check the size and cmdline position for
9116 * messages. */
9117 check_shellsize();
9118 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9119 cmdline_row = Rows - p_ch;
9120 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009121 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009122 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009123 }
9124
Bram Moolenaar071d4272004-06-13 20:20:40 +00009125 if (curbuf->b_p_ts <= 0)
9126 {
9127 errmsg = e_positive;
9128 curbuf->b_p_ts = 8;
9129 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009130 if (p_tm < 0)
9131 {
9132 errmsg = e_positive;
9133 p_tm = 0;
9134 }
9135 if ((curwin->w_p_scr <= 0
9136 || (curwin->w_p_scr > curwin->w_height
9137 && curwin->w_height > 0))
9138 && full_screen)
9139 {
9140 if (pp == &(curwin->w_p_scr))
9141 {
9142 if (curwin->w_p_scr != 0)
9143 errmsg = e_scroll;
9144 win_comp_scroll(curwin);
9145 }
9146 /* If 'scroll' became invalid because of a side effect silently adjust
9147 * it. */
9148 else if (curwin->w_p_scr <= 0)
9149 curwin->w_p_scr = 1;
9150 else /* curwin->w_p_scr > curwin->w_height */
9151 curwin->w_p_scr = curwin->w_height;
9152 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009153 if (p_hi < 0)
9154 {
9155 errmsg = e_positive;
9156 p_hi = 0;
9157 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009158 else if (p_hi > 10000)
9159 {
9160 errmsg = e_invarg;
9161 p_hi = 10000;
9162 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009163 if (p_re < 0 || p_re > 2)
9164 {
9165 errmsg = e_invarg;
9166 p_re = 0;
9167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009168 if (p_report < 0)
9169 {
9170 errmsg = e_positive;
9171 p_report = 1;
9172 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009173 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009174 {
9175 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9176 p_sj = Rows / 2;
9177 else
9178 {
9179 errmsg = e_scroll;
9180 p_sj = 1;
9181 }
9182 }
9183 if (p_so < 0 && full_screen)
9184 {
9185 errmsg = e_scroll;
9186 p_so = 0;
9187 }
9188 if (p_siso < 0 && full_screen)
9189 {
9190 errmsg = e_positive;
9191 p_siso = 0;
9192 }
9193#ifdef FEAT_CMDWIN
9194 if (p_cwh < 1)
9195 {
9196 errmsg = e_positive;
9197 p_cwh = 1;
9198 }
9199#endif
9200 if (p_ut < 0)
9201 {
9202 errmsg = e_positive;
9203 p_ut = 2000;
9204 }
9205 if (p_ss < 0)
9206 {
9207 errmsg = e_positive;
9208 p_ss = 0;
9209 }
9210
9211 /* May set global value for local option. */
9212 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9213 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9214
9215 options[opt_idx].flags |= P_WAS_SET;
9216
Bram Moolenaar53744302015-07-17 17:38:22 +02009217#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9218 if (!starting && errmsg == NULL)
9219 {
9220 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009221 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9222 vim_snprintf((char *)buf_new, 10, "%ld", value);
9223 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009224 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9225 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9226 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9227 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9228 reset_v_option_vars();
9229 }
9230#endif
9231
Bram Moolenaar071d4272004-06-13 20:20:40 +00009232 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009233 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009234 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009235 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009236 check_redraw(options[opt_idx].flags);
9237
9238 return errmsg;
9239}
9240
9241/*
9242 * Called after an option changed: check if something needs to be redrawn.
9243 */
9244 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009245check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009246{
9247 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009248 int doclear = (flags & P_RCLR) == P_RCLR;
9249 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009250
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9252 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009253
9254 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9255 changed_window_setting();
9256 if (flags & P_RBUF)
9257 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009258 if (flags & P_RWINONLY)
9259 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009260 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009261 redraw_all_later(CLEAR);
9262 else if (all)
9263 redraw_all_later(NOT_VALID);
9264}
9265
9266/*
9267 * Find index for option 'arg'.
9268 * Return -1 if not found.
9269 */
9270 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009271findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009272{
9273 int opt_idx;
9274 char *s, *p;
9275 static short quick_tab[27] = {0, 0}; /* quick access table */
9276 int is_term_opt;
9277
9278 /*
9279 * For first call: Initialize the quick-access table.
9280 * It contains the index for the first option that starts with a certain
9281 * letter. There are 26 letters, plus the first "t_" option.
9282 */
9283 if (quick_tab[1] == 0)
9284 {
9285 p = options[0].fullname;
9286 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9287 {
9288 if (s[0] != p[0])
9289 {
9290 if (s[0] == 't' && s[1] == '_')
9291 quick_tab[26] = opt_idx;
9292 else
9293 quick_tab[CharOrdLow(s[0])] = opt_idx;
9294 }
9295 p = s;
9296 }
9297 }
9298
9299 /*
9300 * Check for name starting with an illegal character.
9301 */
9302#ifdef EBCDIC
9303 if (!islower(arg[0]))
9304#else
9305 if (arg[0] < 'a' || arg[0] > 'z')
9306#endif
9307 return -1;
9308
9309 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9310 if (is_term_opt)
9311 opt_idx = quick_tab[26];
9312 else
9313 opt_idx = quick_tab[CharOrdLow(arg[0])];
9314 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9315 {
9316 if (STRCMP(arg, s) == 0) /* match full name */
9317 break;
9318 }
9319 if (s == NULL && !is_term_opt)
9320 {
9321 opt_idx = quick_tab[CharOrdLow(arg[0])];
9322 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9323 {
9324 s = options[opt_idx].shortname;
9325 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9326 break;
9327 s = NULL;
9328 }
9329 }
9330 if (s == NULL)
9331 opt_idx = -1;
9332 return opt_idx;
9333}
9334
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009335#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336/*
9337 * Get the value for an option.
9338 *
9339 * Returns:
9340 * Number or Toggle option: 1, *numval gets value.
9341 * String option: 0, *stringval gets allocated string.
9342 * Hidden Number or Toggle option: -1.
9343 * hidden String option: -2.
9344 * unknown option: -3.
9345 */
9346 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009347get_option_value(
9348 char_u *name,
9349 long *numval,
9350 char_u **stringval, /* NULL when only checking existence */
9351 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009352{
9353 int opt_idx;
9354 char_u *varp;
9355
9356 opt_idx = findoption(name);
9357 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009358 {
9359 int key;
9360
9361 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9362 && (key = find_key_option(name)) != 0)
9363 {
9364 char_u key_name[2];
9365 char_u *p;
9366
9367 if (key < 0)
9368 {
9369 key_name[0] = KEY2TERMCAP0(key);
9370 key_name[1] = KEY2TERMCAP1(key);
9371 }
9372 else
9373 {
9374 key_name[0] = KS_KEY;
9375 key_name[1] = (key & 0xff);
9376 }
9377 p = find_termcode(key_name);
9378 if (p != NULL)
9379 {
9380 if (stringval != NULL)
9381 *stringval = vim_strsave(p);
9382 return 0;
9383 }
9384 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009385 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009386 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009387
9388 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9389
9390 if (options[opt_idx].flags & P_STRING)
9391 {
9392 if (varp == NULL) /* hidden option */
9393 return -2;
9394 if (stringval != NULL)
9395 {
9396#ifdef FEAT_CRYPT
9397 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009398 if ((char_u **)varp == &curbuf->b_p_key
9399 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009400 *stringval = vim_strsave((char_u *)"*****");
9401 else
9402#endif
9403 *stringval = vim_strsave(*(char_u **)(varp));
9404 }
9405 return 0;
9406 }
9407
9408 if (varp == NULL) /* hidden option */
9409 return -1;
9410 if (options[opt_idx].flags & P_NUM)
9411 *numval = *(long *)varp;
9412 else
9413 {
9414 /* Special case: 'modified' is b_changed, but we also want to consider
9415 * it set when 'ff' or 'fenc' changed. */
9416 if ((int *)varp == &curbuf->b_changed)
9417 *numval = curbufIsChanged();
9418 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009419 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420 }
9421 return 1;
9422}
9423#endif
9424
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009425#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009426/*
9427 * Returns the option attributes and its value. Unlike the above function it
9428 * will return either global value or local value of the option depending on
9429 * what was requested, but it will never return global value if it was
9430 * requested to return local one and vice versa. Neither it will return
9431 * buffer-local value if it was requested to return window-local one.
9432 *
9433 * Pretends that option is absent if it is not present in the requested scope
9434 * (i.e. has no global, window-local or buffer-local value depending on
9435 * opt_type). Uses
9436 *
9437 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009438 * 0 hidden or unknown option, also option that does not have requested
9439 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009440 * see SOPT_* in vim.h for other flags
9441 *
9442 * Possible opt_type values: see SREQ_* in vim.h
9443 */
9444 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009445get_option_value_strict(
9446 char_u *name,
9447 long *numval,
9448 char_u **stringval, /* NULL when only obtaining attributes */
9449 int opt_type,
9450 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009451{
9452 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009453 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009454 struct vimoption *p;
9455 int r = 0;
9456
9457 opt_idx = findoption(name);
9458 if (opt_idx < 0)
9459 return 0;
9460
9461 p = &(options[opt_idx]);
9462
9463 /* Hidden option */
9464 if (p->var == NULL)
9465 return 0;
9466
9467 if (p->flags & P_BOOL)
9468 r |= SOPT_BOOL;
9469 else if (p->flags & P_NUM)
9470 r |= SOPT_NUM;
9471 else if (p->flags & P_STRING)
9472 r |= SOPT_STRING;
9473
9474 if (p->indir == PV_NONE)
9475 {
9476 if (opt_type == SREQ_GLOBAL)
9477 r |= SOPT_GLOBAL;
9478 else
9479 return 0; /* Did not request global-only option */
9480 }
9481 else
9482 {
9483 if (p->indir & PV_BOTH)
9484 r |= SOPT_GLOBAL;
9485 else if (opt_type == SREQ_GLOBAL)
9486 return 0; /* Requested global option */
9487
9488 if (p->indir & PV_WIN)
9489 {
9490 if (opt_type == SREQ_BUF)
9491 return 0; /* Did not request window-local option */
9492 else
9493 r |= SOPT_WIN;
9494 }
9495 else if (p->indir & PV_BUF)
9496 {
9497 if (opt_type == SREQ_WIN)
9498 return 0; /* Did not request buffer-local option */
9499 else
9500 r |= SOPT_BUF;
9501 }
9502 }
9503
9504 if (stringval == NULL)
9505 return r;
9506
9507 if (opt_type == SREQ_GLOBAL)
9508 varp = p->var;
9509 else
9510 {
9511 if (opt_type == SREQ_BUF)
9512 {
9513 /* Special case: 'modified' is b_changed, but we also want to
9514 * consider it set when 'ff' or 'fenc' changed. */
9515 if (p->indir == PV_MOD)
9516 {
9517 *numval = bufIsChanged((buf_T *) from);
9518 varp = NULL;
9519 }
9520#ifdef FEAT_CRYPT
9521 else if (p->indir == PV_KEY)
9522 {
9523 /* never return the value of the crypt key */
9524 *stringval = NULL;
9525 varp = NULL;
9526 }
9527#endif
9528 else
9529 {
9530 aco_save_T aco;
9531 aucmd_prepbuf(&aco, (buf_T *) from);
9532 varp = get_varp(p);
9533 aucmd_restbuf(&aco);
9534 }
9535 }
9536 else if (opt_type == SREQ_WIN)
9537 {
9538 win_T *save_curwin;
9539 save_curwin = curwin;
9540 curwin = (win_T *) from;
9541 curbuf = curwin->w_buffer;
9542 varp = get_varp(p);
9543 curwin = save_curwin;
9544 curbuf = curwin->w_buffer;
9545 }
9546 if (varp == p->var)
9547 return (r | SOPT_UNSET);
9548 }
9549
9550 if (varp != NULL)
9551 {
9552 if (p->flags & P_STRING)
9553 *stringval = vim_strsave(*(char_u **)(varp));
9554 else if (p->flags & P_NUM)
9555 *numval = *(long *) varp;
9556 else
9557 *numval = *(int *)varp;
9558 }
9559
9560 return r;
9561}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009562
9563/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009564 * Iterate over options. First argument is a pointer to a pointer to a
9565 * structure inside options[] array, second is option type like in the above
9566 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009567 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009568 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009569 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009570 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009571 * first argument to NULL.
9572 *
9573 * Returns full option name for current option on each call.
9574 */
9575 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009576option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009577{
9578 struct vimoption *ret = NULL;
9579 do
9580 {
9581 if (*option == NULL)
9582 *option = (void *) options;
9583 else if (((struct vimoption *) (*option))->fullname == NULL)
9584 {
9585 *option = NULL;
9586 return NULL;
9587 }
9588 else
9589 *option = (void *) (((struct vimoption *) (*option)) + 1);
9590
9591 ret = ((struct vimoption *) (*option));
9592
9593 /* Hidden option */
9594 if (ret->var == NULL)
9595 {
9596 ret = NULL;
9597 continue;
9598 }
9599
9600 switch (opt_type)
9601 {
9602 case SREQ_GLOBAL:
9603 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9604 ret = NULL;
9605 break;
9606 case SREQ_BUF:
9607 if (!(ret->indir & PV_BUF))
9608 ret = NULL;
9609 break;
9610 case SREQ_WIN:
9611 if (!(ret->indir & PV_WIN))
9612 ret = NULL;
9613 break;
9614 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009615 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009616 return NULL;
9617 }
9618 }
9619 while (ret == NULL);
9620
9621 return (char_u *)ret->fullname;
9622}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009623#endif
9624
Bram Moolenaar071d4272004-06-13 20:20:40 +00009625/*
9626 * Set the value of option "name".
9627 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009628 *
9629 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009630 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009631 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009632set_option_value(
9633 char_u *name,
9634 long number,
9635 char_u *string,
9636 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009637{
9638 int opt_idx;
9639 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009640 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009641
9642 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009643 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009644 {
9645 int key;
9646
9647 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9648 && (key = find_key_option(name)) != 0)
9649 {
9650 char_u key_name[2];
9651
9652 if (key < 0)
9653 {
9654 key_name[0] = KEY2TERMCAP0(key);
9655 key_name[1] = KEY2TERMCAP1(key);
9656 }
9657 else
9658 {
9659 key_name[0] = KS_KEY;
9660 key_name[1] = (key & 0xff);
9661 }
9662 add_termcode(key_name, string, FALSE);
9663 if (full_screen)
9664 ttest(FALSE);
9665 redraw_all_later(CLEAR);
9666 return NULL;
9667 }
9668
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009670 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009671 else
9672 {
9673 flags = options[opt_idx].flags;
9674#ifdef HAVE_SANDBOX
9675 /* Disallow changing some options in the sandbox */
9676 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009677 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009678 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009679 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009682 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009683 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009684 else
9685 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009686 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009687 if (varp != NULL) /* hidden option is not changed */
9688 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009689 if (number == 0 && string != NULL)
9690 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009691 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009692
9693 /* Either we are given a string or we are setting option
9694 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009695 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009696 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009697 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009698 {
9699 /* There's another character after zeros or the string
9700 * is empty. In both cases, we are trying to set a
9701 * num option using a string. */
9702 EMSG3(_("E521: Number required: &%s = '%s'"),
9703 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009704 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009705
9706 }
9707 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009708 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009709 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009710 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009711 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009712 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009713 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009714 }
9715 }
9716 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009717 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009718}
9719
9720/*
9721 * Get the terminal code for a terminal option.
9722 * Returns NULL when not found.
9723 */
9724 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009725get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726{
9727 int opt_idx;
9728 char_u *varp;
9729
9730 if (tname[0] != 't' || tname[1] != '_' ||
9731 tname[2] == NUL || tname[3] == NUL)
9732 return NULL;
9733 if ((opt_idx = findoption(tname)) >= 0)
9734 {
9735 varp = get_varp(&(options[opt_idx]));
9736 if (varp != NULL)
9737 varp = *(char_u **)(varp);
9738 return varp;
9739 }
9740 return find_termcode(tname + 2);
9741}
9742
9743 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009744get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009745{
9746 int i;
9747
9748 i = findoption((char_u *)"hl");
9749 if (i >= 0)
9750 return options[i].def_val[VI_DEFAULT];
9751 return (char_u *)NULL;
9752}
9753
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009754#if defined(FEAT_MBYTE) || defined(PROTO)
9755 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009756get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009757{
9758 int i;
9759
9760 i = findoption((char_u *)"enc");
9761 if (i >= 0)
9762 return options[i].def_val[VI_DEFAULT];
9763 return (char_u *)NULL;
9764}
9765#endif
9766
Bram Moolenaar071d4272004-06-13 20:20:40 +00009767/*
9768 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9769 */
9770 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009771find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009772{
9773 int key;
9774 int modifiers;
9775
9776 /*
9777 * Don't use get_special_key_code() for t_xx, we don't want it to call
9778 * add_termcap_entry().
9779 */
9780 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9781 key = TERMCAP2KEY(arg[2], arg[3]);
9782 else
9783 {
9784 --arg; /* put arg at the '<' */
9785 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009786 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009787 if (modifiers) /* can't handle modifiers here */
9788 key = 0;
9789 }
9790 return key;
9791}
9792
9793/*
9794 * if 'all' == 0: show changed options
9795 * if 'all' == 1: show all normal options
9796 * if 'all' == 2: show all terminal options
9797 */
9798 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009799showoptions(
9800 int all,
9801 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009802{
9803 struct vimoption *p;
9804 int col;
9805 int isterm;
9806 char_u *varp;
9807 struct vimoption **items;
9808 int item_count;
9809 int run;
9810 int row, rows;
9811 int cols;
9812 int i;
9813 int len;
9814
9815#define INC 20
9816#define GAP 3
9817
9818 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9819 PARAM_COUNT));
9820 if (items == NULL)
9821 return;
9822
9823 /* Highlight title */
9824 if (all == 2)
9825 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9826 else if (opt_flags & OPT_GLOBAL)
9827 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9828 else if (opt_flags & OPT_LOCAL)
9829 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9830 else
9831 MSG_PUTS_TITLE(_("\n--- Options ---"));
9832
9833 /*
9834 * do the loop two times:
9835 * 1. display the short items
9836 * 2. display the long items (only strings and numbers)
9837 */
9838 for (run = 1; run <= 2 && !got_int; ++run)
9839 {
9840 /*
9841 * collect the items in items[]
9842 */
9843 item_count = 0;
9844 for (p = &options[0]; p->fullname != NULL; p++)
9845 {
9846 varp = NULL;
9847 isterm = istermoption(p);
9848 if (opt_flags != 0)
9849 {
9850 if (p->indir != PV_NONE && !isterm)
9851 varp = get_varp_scope(p, opt_flags);
9852 }
9853 else
9854 varp = get_varp(p);
9855 if (varp != NULL
9856 && ((all == 2 && isterm)
9857 || (all == 1 && !isterm)
9858 || (all == 0 && !optval_default(p, varp))))
9859 {
9860 if (p->flags & P_BOOL)
9861 len = 1; /* a toggle option fits always */
9862 else
9863 {
9864 option_value2string(p, opt_flags);
9865 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9866 }
9867 if ((len <= INC - GAP && run == 1) ||
9868 (len > INC - GAP && run == 2))
9869 items[item_count++] = p;
9870 }
9871 }
9872
9873 /*
9874 * display the items
9875 */
9876 if (run == 1)
9877 {
9878 cols = (Columns + GAP - 3) / INC;
9879 if (cols == 0)
9880 cols = 1;
9881 rows = (item_count + cols - 1) / cols;
9882 }
9883 else /* run == 2 */
9884 rows = item_count;
9885 for (row = 0; row < rows && !got_int; ++row)
9886 {
9887 msg_putchar('\n'); /* go to next line */
9888 if (got_int) /* 'q' typed in more */
9889 break;
9890 col = 0;
9891 for (i = row; i < item_count; i += rows)
9892 {
9893 msg_col = col; /* make columns */
9894 showoneopt(items[i], opt_flags);
9895 col += INC;
9896 }
9897 out_flush();
9898 ui_breakcheck();
9899 }
9900 }
9901 vim_free(items);
9902}
9903
9904/*
9905 * Return TRUE if option "p" has its default value.
9906 */
9907 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009908optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909{
9910 int dvi;
9911
9912 if (varp == NULL)
9913 return TRUE; /* hidden option is always at default */
9914 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9915 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009916 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009917 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009918 /* the cast to long is required for Manx C, long_i is
9919 * needed for MSVC */
9920 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921 /* P_STRING */
9922 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9923}
9924
9925/*
9926 * showoneopt: show the value of one option
9927 * must not be called with a hidden option!
9928 */
9929 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009930showoneopt(
9931 struct vimoption *p,
9932 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009933{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009934 char_u *varp;
9935 int save_silent = silent_mode;
9936
9937 silent_mode = FALSE;
9938 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009939
9940 varp = get_varp_scope(p, opt_flags);
9941
9942 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9943 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9944 ? !curbufIsChanged() : !*(int *)varp))
9945 MSG_PUTS("no");
9946 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9947 MSG_PUTS("--");
9948 else
9949 MSG_PUTS(" ");
9950 MSG_PUTS(p->fullname);
9951 if (!(p->flags & P_BOOL))
9952 {
9953 msg_putchar('=');
9954 /* put value string in NameBuff */
9955 option_value2string(p, opt_flags);
9956 msg_outtrans(NameBuff);
9957 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009958
9959 silent_mode = save_silent;
9960 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961}
9962
9963/*
9964 * Write modified options as ":set" commands to a file.
9965 *
9966 * There are three values for "opt_flags":
9967 * OPT_GLOBAL: Write global option values and fresh values of
9968 * buffer-local options (used for start of a session
9969 * file).
9970 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9971 * curwin (used for a vimrc file).
9972 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9973 * and local values for window-local options of
9974 * curwin. Local values are also written when at the
9975 * default value, because a modeline or autocommand
9976 * may have set them when doing ":edit file" and the
9977 * user has set them back at the default or fresh
9978 * value.
9979 * When "local_only" is TRUE, don't write fresh
9980 * values, only local values (for ":mkview").
9981 * (fresh value = value used for a new buffer or window for a local option).
9982 *
9983 * Return FAIL on error, OK otherwise.
9984 */
9985 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009986makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009987{
9988 struct vimoption *p;
9989 char_u *varp; /* currently used value */
9990 char_u *varp_fresh; /* local value */
9991 char_u *varp_local = NULL; /* fresh value */
9992 char *cmd;
9993 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009994 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009995
9996 /*
9997 * The options that don't have a default (terminal name, columns, lines)
9998 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009999 * Do the loop over "options[]" twice: once for options with the
10000 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010001 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010002 for (pri = 1; pri >= 0; --pri)
10003 {
10004 for (p = &options[0]; !istermoption(p); p++)
10005 if (!(p->flags & P_NO_MKRC)
10006 && !istermoption(p)
10007 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008 {
10009 /* skip global option when only doing locals */
10010 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10011 continue;
10012
10013 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10014 * file, they are always buffer-specific. */
10015 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10016 continue;
10017
10018 /* Global values are only written when not at the default value. */
10019 varp = get_varp_scope(p, opt_flags);
10020 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10021 continue;
10022
10023 round = 2;
10024 if (p->indir != PV_NONE)
10025 {
10026 if (p->var == VAR_WIN)
10027 {
10028 /* skip window-local option when only doing globals */
10029 if (!(opt_flags & OPT_LOCAL))
10030 continue;
10031 /* When fresh value of window-local option is not at the
10032 * default, need to write it too. */
10033 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10034 {
10035 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10036 if (!optval_default(p, varp_fresh))
10037 {
10038 round = 1;
10039 varp_local = varp;
10040 varp = varp_fresh;
10041 }
10042 }
10043 }
10044 }
10045
10046 /* Round 1: fresh value for window-local options.
10047 * Round 2: other values */
10048 for ( ; round <= 2; varp = varp_local, ++round)
10049 {
10050 if (round == 1 || (opt_flags & OPT_GLOBAL))
10051 cmd = "set";
10052 else
10053 cmd = "setlocal";
10054
10055 if (p->flags & P_BOOL)
10056 {
10057 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10058 return FAIL;
10059 }
10060 else if (p->flags & P_NUM)
10061 {
10062 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10063 return FAIL;
10064 }
10065 else /* P_STRING */
10066 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010067#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10068 int do_endif = FALSE;
10069
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070 /* Don't set 'syntax' and 'filetype' again if the value is
10071 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010072 if (
10073# if defined(FEAT_SYN_HL)
10074 p->indir == PV_SYN
10075# if defined(FEAT_AUTOCMD)
10076 ||
10077# endif
10078# endif
10079# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010080 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010081# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010082 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010083 {
10084 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10085 *(char_u **)(varp)) < 0
10086 || put_eol(fd) < 0)
10087 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010088 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010089 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010090#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010091 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10092 (p->flags & P_EXPAND) != 0) == FAIL)
10093 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010094#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10095 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010096 {
10097 if (put_line(fd, "endif") == FAIL)
10098 return FAIL;
10099 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101 }
10102 }
10103 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010104 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010105 return OK;
10106}
10107
10108#if defined(FEAT_FOLDING) || defined(PROTO)
10109/*
10110 * Generate set commands for the local fold options only. Used when
10111 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10112 */
10113 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010114makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010115{
10116 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10117# ifdef FEAT_EVAL
10118 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10119 == FAIL
10120# endif
10121 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10122 == FAIL
10123 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10124 == FAIL
10125 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10126 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10127 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10128 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10129 )
10130 return FAIL;
10131
10132 return OK;
10133}
10134#endif
10135
10136 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010137put_setstring(
10138 FILE *fd,
10139 char *cmd,
10140 char *name,
10141 char_u **valuep,
10142 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010143{
10144 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010145 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146
10147 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10148 return FAIL;
10149 if (*valuep != NULL)
10150 {
10151 /* Output 'pastetoggle' as key names. For other
10152 * options some characters have to be escaped with
10153 * CTRL-V or backslash */
10154 if (valuep == &p_pt)
10155 {
10156 s = *valuep;
10157 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010158 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159 return FAIL;
10160 }
10161 else if (expand)
10162 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010163 buf = alloc(MAXPATHL);
10164 if (buf == NULL)
10165 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10167 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010168 {
10169 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010171 }
10172 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173 }
10174 else if (put_escstr(fd, *valuep, 2) == FAIL)
10175 return FAIL;
10176 }
10177 if (put_eol(fd) < 0)
10178 return FAIL;
10179 return OK;
10180}
10181
10182 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010183put_setnum(
10184 FILE *fd,
10185 char *cmd,
10186 char *name,
10187 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188{
10189 long wc;
10190
10191 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10192 return FAIL;
10193 if (wc_use_keyname((char_u *)valuep, &wc))
10194 {
10195 /* print 'wildchar' and 'wildcharm' as a key name */
10196 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10197 return FAIL;
10198 }
10199 else if (fprintf(fd, "%ld", *valuep) < 0)
10200 return FAIL;
10201 if (put_eol(fd) < 0)
10202 return FAIL;
10203 return OK;
10204}
10205
10206 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010207put_setbool(
10208 FILE *fd,
10209 char *cmd,
10210 char *name,
10211 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212{
Bram Moolenaar893de922007-10-02 18:40:57 +000010213 if (value < 0) /* global/local option using global value */
10214 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10216 || put_eol(fd) < 0)
10217 return FAIL;
10218 return OK;
10219}
10220
10221/*
10222 * Clear all the terminal options.
10223 * If the option has been allocated, free the memory.
10224 * Terminal options are never hidden or indirect.
10225 */
10226 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010227clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229 /*
10230 * Reset a few things before clearing the old options. This may cause
10231 * outputting a few things that the terminal doesn't understand, but the
10232 * screen will be cleared later, so this is OK.
10233 */
10234#ifdef FEAT_MOUSE_TTY
10235 mch_setmouse(FALSE); /* switch mouse off */
10236#endif
10237#ifdef FEAT_TITLE
10238 mch_restore_title(3); /* restore window titles */
10239#endif
10240#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10241 /* When starting the GUI close the display opened for the clipboard.
10242 * After restoring the title, because that will need the display. */
10243 if (gui.starting)
10244 clear_xterm_clip();
10245#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010246 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010248 free_termoptions();
10249}
10250
10251 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010252free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010253{
10254 struct vimoption *p;
10255
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256 for (p = &options[0]; p->fullname != NULL; p++)
10257 if (istermoption(p))
10258 {
10259 if (p->flags & P_ALLOCED)
10260 free_string_option(*(char_u **)(p->var));
10261 if (p->flags & P_DEF_ALLOCED)
10262 free_string_option(p->def_val[VI_DEFAULT]);
10263 *(char_u **)(p->var) = empty_option;
10264 p->def_val[VI_DEFAULT] = empty_option;
10265 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10266 }
10267 clear_termcodes();
10268}
10269
10270/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010271 * Free the string for one term option, if it was allocated.
10272 * Set the string to empty_option and clear allocated flag.
10273 * "var" points to the option value.
10274 */
10275 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010276free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010277{
10278 struct vimoption *p;
10279
10280 for (p = &options[0]; p->fullname != NULL; p++)
10281 if (p->var == var)
10282 {
10283 if (p->flags & P_ALLOCED)
10284 free_string_option(*(char_u **)(p->var));
10285 *(char_u **)(p->var) = empty_option;
10286 p->flags &= ~P_ALLOCED;
10287 break;
10288 }
10289}
10290
10291/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292 * Set the terminal option defaults to the current value.
10293 * Used after setting the terminal name.
10294 */
10295 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010296set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297{
10298 struct vimoption *p;
10299
10300 for (p = &options[0]; p->fullname != NULL; p++)
10301 {
10302 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10303 {
10304 if (p->flags & P_DEF_ALLOCED)
10305 {
10306 free_string_option(p->def_val[VI_DEFAULT]);
10307 p->flags &= ~P_DEF_ALLOCED;
10308 }
10309 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10310 if (p->flags & P_ALLOCED)
10311 {
10312 p->flags |= P_DEF_ALLOCED;
10313 p->flags &= ~P_ALLOCED; /* don't free the value now */
10314 }
10315 }
10316 }
10317}
10318
10319/*
10320 * return TRUE if 'p' starts with 't_'
10321 */
10322 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010323istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324{
10325 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10326}
10327
10328/*
10329 * Compute columns for ruler and shown command. 'sc_col' is also used to
10330 * decide what the maximum length of a message on the status line can be.
10331 * If there is a status line for the last window, 'sc_col' is independent
10332 * of 'ru_col'.
10333 */
10334
10335#define COL_RULER 17 /* columns needed by standard ruler */
10336
10337 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010338comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010339{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010340#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010341 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342
10343 sc_col = 0;
10344 ru_col = 0;
10345 if (p_ru)
10346 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010347# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010349# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010350 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010351# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352 /* no last status line, adjust sc_col */
10353 if (!last_has_status)
10354 sc_col = ru_col;
10355 }
10356 if (p_sc)
10357 {
10358 sc_col += SHOWCMD_COLS;
10359 if (!p_ru || last_has_status) /* no need for separating space */
10360 ++sc_col;
10361 }
10362 sc_col = Columns - sc_col;
10363 ru_col = Columns - ru_col;
10364 if (sc_col <= 0) /* screen too narrow, will become a mess */
10365 sc_col = 1;
10366 if (ru_col <= 0)
10367 ru_col = 1;
10368#else
10369 sc_col = Columns;
10370 ru_col = Columns;
10371#endif
10372}
10373
10374/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010375 * Unset local option value, similar to ":set opt<".
10376 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010377 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010378unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010379{
10380 struct vimoption *p;
10381 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010382 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010383
10384 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010385 if (opt_idx < 0)
10386 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010387 p = &(options[opt_idx]);
10388
10389 switch ((int)p->indir)
10390 {
10391 /* global option with local value: use local value if it's been set */
10392 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010393 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010394 break;
10395 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010396 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010397 break;
10398 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010399 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010400 break;
10401 case PV_AR:
10402 buf->b_p_ar = -1;
10403 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010404 case PV_BKC:
10405 clear_string_option(&buf->b_p_bkc);
10406 buf->b_bkc_flags = 0;
10407 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010408 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010409 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010410 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010411 case PV_TC:
10412 clear_string_option(&buf->b_p_tc);
10413 buf->b_tc_flags = 0;
10414 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010415#ifdef FEAT_FIND_ID
10416 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010417 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010418 break;
10419 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010420 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010421 break;
10422#endif
10423#ifdef FEAT_INS_EXPAND
10424 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010425 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010426 break;
10427 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010428 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010429 break;
10430#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010431 case PV_FP:
10432 clear_string_option(&buf->b_p_fp);
10433 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010434#ifdef FEAT_QUICKFIX
10435 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010436 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010437 break;
10438 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010439 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010440 break;
10441 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010442 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010443 break;
10444#endif
10445#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10446 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010447 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010448 break;
10449#endif
10450#if defined(FEAT_CRYPT)
10451 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010452 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010453 break;
10454#endif
10455#ifdef FEAT_STL_OPT
10456 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010457 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010458 break;
10459#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010460 case PV_UL:
10461 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10462 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010463#ifdef FEAT_LISP
10464 case PV_LW:
10465 clear_string_option(&buf->b_p_lw);
10466 break;
10467#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010468#ifdef FEAT_MBYTE
10469 case PV_MENC:
10470 clear_string_option(&buf->b_p_menc);
10471 break;
10472#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010473 }
10474}
10475
10476/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010477 * Get pointer to option variable, depending on local or global scope.
10478 */
10479 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010480get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481{
10482 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10483 {
10484 if (p->var == VAR_WIN)
10485 return (char_u *)GLOBAL_WO(get_varp(p));
10486 return p->var;
10487 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010488 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010489 {
10490 switch ((int)p->indir)
10491 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010492 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010494 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10495 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10496 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010497#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010498 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10499 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10500 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010501 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010502 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010503 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010505 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10506 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507#endif
10508#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010509 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10510 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010512#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10513 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10514#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010515#if defined(FEAT_CRYPT)
10516 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10517#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010518#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010519 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010520#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010521 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010522#ifdef FEAT_LISP
10523 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10524#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010525 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010526#ifdef FEAT_MBYTE
10527 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10528#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 }
10530 return NULL; /* "cannot happen" */
10531 }
10532 return get_varp(p);
10533}
10534
10535/*
10536 * Get pointer to option variable.
10537 */
10538 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010539get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540{
10541 /* hidden option, always return NULL */
10542 if (p->var == NULL)
10543 return NULL;
10544
10545 switch ((int)p->indir)
10546 {
10547 case PV_NONE: return p->var;
10548
10549 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010550 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010552 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010554 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010556 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010557 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010558 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010559 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010560 case PV_TC: return *curbuf->b_p_tc != NUL
10561 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010562 case PV_BKC: return *curbuf->b_p_bkc != NUL
10563 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010565 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010567 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10569#endif
10570#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010571 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010573 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10575#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010576 case PV_FP: return *curbuf->b_p_fp != NUL
10577 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010579 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010581 case PV_GP: return *curbuf->b_p_gp != NUL
10582 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10583 case PV_MP: return *curbuf->b_p_mp != NUL
10584 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010586#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10587 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10588 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10589#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010590#if defined(FEAT_CRYPT)
10591 case PV_CM: return *curbuf->b_p_cm != NUL
10592 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10593#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010594#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010595 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010596 ? (char_u *)&(curwin->w_p_stl) : p->var;
10597#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010598 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10599 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010600#ifdef FEAT_LISP
10601 case PV_LW: return *curbuf->b_p_lw != NUL
10602 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10603#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010604#ifdef FEAT_MBYTE
10605 case PV_MENC: return *curbuf->b_p_menc != NUL
10606 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10607#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608
10609#ifdef FEAT_ARABIC
10610 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10611#endif
10612 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010613#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010614 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10615#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010616#ifdef FEAT_SYN_HL
10617 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10618 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010619 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621#ifdef FEAT_DIFF
10622 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10623#endif
10624#ifdef FEAT_FOLDING
10625 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10626 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10627 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10628 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10629 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10630 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10631 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10632# ifdef FEAT_EVAL
10633 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10634 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10635# endif
10636 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10637#endif
10638 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010639 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010640#ifdef FEAT_LINEBREAK
10641 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10642#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010643 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010644 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010645#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010646 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10647#endif
10648#ifdef FEAT_RIGHTLEFT
10649 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10650 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10651#endif
10652 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10653 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10654#ifdef FEAT_LINEBREAK
10655 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010656 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10657 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010658#endif
10659#ifdef FEAT_SCROLLBIND
10660 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10661#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010662#ifdef FEAT_CURSORBIND
10663 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10664#endif
10665#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010666 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10667 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10668#endif
10669#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010670 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010671 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010673
10674 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10675 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10676#ifdef FEAT_MBYTE
10677 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10678#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10680 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010681 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10682 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10683#ifdef FEAT_CINDENT
10684 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10685 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10686 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10687#endif
10688#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10689 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10690#endif
10691#ifdef FEAT_COMMENTS
10692 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10693#endif
10694#ifdef FEAT_FOLDING
10695 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10696#endif
10697#ifdef FEAT_INS_EXPAND
10698 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10699#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010700#ifdef FEAT_COMPL_FUNC
10701 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010702 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010705 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010706 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10707#ifdef FEAT_MBYTE
10708 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10709#endif
10710 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10711#ifdef FEAT_AUTOCMD
10712 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10713#endif
10714 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010715 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10717 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10718 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10719 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10720#ifdef FEAT_FIND_ID
10721# ifdef FEAT_EVAL
10722 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10723# endif
10724#endif
10725#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10726 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10727 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10728#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010729#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010730 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10731#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732#ifdef FEAT_CRYPT
10733 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10734#endif
10735#ifdef FEAT_LISP
10736 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10737#endif
10738 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10739 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10740 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10741 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10742 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010744#ifdef FEAT_TEXTOBJ
10745 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10746#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010747 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10748#ifdef FEAT_SMARTINDENT
10749 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10750#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10753#ifdef FEAT_SEARCHPATH
10754 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10755#endif
10756 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10757#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010758 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010759 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10760#endif
10761#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010762 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10763 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10764 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010765#endif
10766 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10767 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10768 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10769 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010770#ifdef FEAT_PERSISTENT_UNDO
10771 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10772#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10774#ifdef FEAT_KEYMAP
10775 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10776#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010777#ifdef FEAT_SIGNS
10778 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10779#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010780 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781 }
10782 /* always return a valid pointer to avoid a crash! */
10783 return (char_u *)&(curbuf->b_p_wm);
10784}
10785
10786/*
10787 * Get the value of 'equalprg', either the buffer-local one or the global one.
10788 */
10789 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010790get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010791{
10792 if (*curbuf->b_p_ep == NUL)
10793 return p_ep;
10794 return curbuf->b_p_ep;
10795}
10796
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797/*
10798 * Copy options from one window to another.
10799 * Used when splitting a window.
10800 */
10801 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010802win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803{
10804 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10805 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10806# ifdef FEAT_RIGHTLEFT
10807# ifdef FEAT_FKMAP
10808 /* Is this right? */
10809 wp_to->w_farsi = wp_from->w_farsi;
10810# endif
10811# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010812#if defined(FEAT_LINEBREAK)
10813 briopt_check(wp_to);
10814#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010815}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010816
10817/*
10818 * Copy the options from one winopt_T to another.
10819 * Doesn't free the old option values in "to", use clear_winopt() for that.
10820 * The 'scroll' option is not copied, because it depends on the window height.
10821 * The 'previewwindow' option is reset, there can be only one preview window.
10822 */
10823 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010824copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825{
10826#ifdef FEAT_ARABIC
10827 to->wo_arab = from->wo_arab;
10828#endif
10829 to->wo_list = from->wo_list;
10830 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010831 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010832#ifdef FEAT_LINEBREAK
10833 to->wo_nuw = from->wo_nuw;
10834#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835#ifdef FEAT_RIGHTLEFT
10836 to->wo_rl = from->wo_rl;
10837 to->wo_rlc = vim_strsave(from->wo_rlc);
10838#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010839#ifdef FEAT_STL_OPT
10840 to->wo_stl = vim_strsave(from->wo_stl);
10841#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010843#ifdef FEAT_DIFF
10844 to->wo_wrap_save = from->wo_wrap_save;
10845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846#ifdef FEAT_LINEBREAK
10847 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010848 to->wo_bri = from->wo_bri;
10849 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850#endif
10851#ifdef FEAT_SCROLLBIND
10852 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010853 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010855#ifdef FEAT_CURSORBIND
10856 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010857 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010858#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010859#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010860 to->wo_spell = from->wo_spell;
10861#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010862#ifdef FEAT_SYN_HL
10863 to->wo_cuc = from->wo_cuc;
10864 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010865 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010866#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010867#ifdef FEAT_DIFF
10868 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010869 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010871#ifdef FEAT_CONCEAL
10872 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010873 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010874#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010875#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010876 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010877 to->wo_tms = vim_strsave(from->wo_tms);
10878#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879#ifdef FEAT_FOLDING
10880 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010881 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010883 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884 to->wo_fdi = vim_strsave(from->wo_fdi);
10885 to->wo_fml = from->wo_fml;
10886 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010887 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010888 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010889 to->wo_fdm_save = from->wo_diff_saved
10890 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891 to->wo_fdn = from->wo_fdn;
10892# ifdef FEAT_EVAL
10893 to->wo_fde = vim_strsave(from->wo_fde);
10894 to->wo_fdt = vim_strsave(from->wo_fdt);
10895# endif
10896 to->wo_fmr = vim_strsave(from->wo_fmr);
10897#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010898#ifdef FEAT_SIGNS
10899 to->wo_scl = vim_strsave(from->wo_scl);
10900#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901 check_winopt(to); /* don't want NULL pointers */
10902}
10903
10904/*
10905 * Check string options in a window for a NULL value.
10906 */
10907 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010908check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909{
10910 check_winopt(&win->w_onebuf_opt);
10911 check_winopt(&win->w_allbuf_opt);
10912}
10913
10914/*
10915 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10916 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010917 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010918check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010919{
10920#ifdef FEAT_FOLDING
10921 check_string_option(&wop->wo_fdi);
10922 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010923 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924# ifdef FEAT_EVAL
10925 check_string_option(&wop->wo_fde);
10926 check_string_option(&wop->wo_fdt);
10927# endif
10928 check_string_option(&wop->wo_fmr);
10929#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010930#ifdef FEAT_SIGNS
10931 check_string_option(&wop->wo_scl);
10932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933#ifdef FEAT_RIGHTLEFT
10934 check_string_option(&wop->wo_rlc);
10935#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010936#ifdef FEAT_STL_OPT
10937 check_string_option(&wop->wo_stl);
10938#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010939#ifdef FEAT_SYN_HL
10940 check_string_option(&wop->wo_cc);
10941#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010942#ifdef FEAT_CONCEAL
10943 check_string_option(&wop->wo_cocu);
10944#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010945#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010946 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010947 check_string_option(&wop->wo_tms);
10948#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010949#ifdef FEAT_LINEBREAK
10950 check_string_option(&wop->wo_briopt);
10951#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010952}
10953
10954/*
10955 * Free the allocated memory inside a winopt_T.
10956 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010958clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010959{
10960#ifdef FEAT_FOLDING
10961 clear_string_option(&wop->wo_fdi);
10962 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010963 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010964# ifdef FEAT_EVAL
10965 clear_string_option(&wop->wo_fde);
10966 clear_string_option(&wop->wo_fdt);
10967# endif
10968 clear_string_option(&wop->wo_fmr);
10969#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010970#ifdef FEAT_SIGNS
10971 clear_string_option(&wop->wo_scl);
10972#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010973#ifdef FEAT_LINEBREAK
10974 clear_string_option(&wop->wo_briopt);
10975#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010976#ifdef FEAT_RIGHTLEFT
10977 clear_string_option(&wop->wo_rlc);
10978#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010979#ifdef FEAT_STL_OPT
10980 clear_string_option(&wop->wo_stl);
10981#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010982#ifdef FEAT_SYN_HL
10983 clear_string_option(&wop->wo_cc);
10984#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010985#ifdef FEAT_CONCEAL
10986 clear_string_option(&wop->wo_cocu);
10987#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010988#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010989 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010990 clear_string_option(&wop->wo_tms);
10991#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010992}
10993
10994/*
10995 * Copy global option values to local options for one buffer.
10996 * Used when creating a new buffer and sometimes when entering a buffer.
10997 * flags:
10998 * BCO_ENTER We will enter the buf buffer.
10999 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11000 * appropriate.
11001 * BCO_NOHELP Don't copy the values to a help buffer.
11002 */
11003 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011004buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011005{
11006 int should_copy = TRUE;
11007 char_u *save_p_isk = NULL; /* init for GCC */
11008 int dont_do_help;
11009 int did_isk = FALSE;
11010
11011 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011012 * Skip this when the option defaults have not been set yet. Happens when
11013 * main() allocates the first buffer.
11014 */
11015 if (p_cpo != NULL)
11016 {
11017 /*
11018 * Always copy when entering and 'cpo' contains 'S'.
11019 * Don't copy when already initialized.
11020 * Don't copy when 'cpo' contains 's' and not entering.
11021 * 'S' BCO_ENTER initialized 's' should_copy
11022 * yes yes X X TRUE
11023 * yes no yes X FALSE
11024 * no X yes X FALSE
11025 * X no no yes FALSE
11026 * X no no no TRUE
11027 * no yes no X TRUE
11028 */
11029 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11030 && (buf->b_p_initialized
11031 || (!(flags & BCO_ENTER)
11032 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11033 should_copy = FALSE;
11034
11035 if (should_copy || (flags & BCO_ALWAYS))
11036 {
11037 /* Don't copy the options specific to a help buffer when
11038 * BCO_NOHELP is given or the options were initialized already
11039 * (jumping back to a help file with CTRL-T or CTRL-O) */
11040 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11041 || buf->b_p_initialized;
11042 if (dont_do_help) /* don't free b_p_isk */
11043 {
11044 save_p_isk = buf->b_p_isk;
11045 buf->b_p_isk = NULL;
11046 }
11047 /*
11048 * Always free the allocated strings.
11049 * If not already initialized, set 'readonly' and copy 'fileformat'.
11050 */
11051 if (!buf->b_p_initialized)
11052 {
11053 free_buf_options(buf, TRUE);
11054 buf->b_p_ro = FALSE; /* don't copy readonly */
11055 buf->b_p_tx = p_tx;
11056#ifdef FEAT_MBYTE
11057 buf->b_p_fenc = vim_strsave(p_fenc);
11058#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011059 switch (*p_ffs)
11060 {
11061 case 'm':
11062 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11063 case 'd':
11064 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11065 case 'u':
11066 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11067 default:
11068 buf->b_p_ff = vim_strsave(p_ff);
11069 }
11070 if (buf->b_p_ff != NULL)
11071 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072 buf->b_p_bh = empty_option;
11073 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074 }
11075 else
11076 free_buf_options(buf, FALSE);
11077
11078 buf->b_p_ai = p_ai;
11079 buf->b_p_ai_nopaste = p_ai_nopaste;
11080 buf->b_p_sw = p_sw;
11081 buf->b_p_tw = p_tw;
11082 buf->b_p_tw_nopaste = p_tw_nopaste;
11083 buf->b_p_tw_nobin = p_tw_nobin;
11084 buf->b_p_wm = p_wm;
11085 buf->b_p_wm_nopaste = p_wm_nopaste;
11086 buf->b_p_wm_nobin = p_wm_nobin;
11087 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011088#ifdef FEAT_MBYTE
11089 buf->b_p_bomb = p_bomb;
11090#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011091 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011092 buf->b_p_et = p_et;
11093 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011094 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095 buf->b_p_ml = p_ml;
11096 buf->b_p_ml_nobin = p_ml_nobin;
11097 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011098 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099#ifdef FEAT_INS_EXPAND
11100 buf->b_p_cpt = vim_strsave(p_cpt);
11101#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011102#ifdef FEAT_COMPL_FUNC
11103 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011104 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011105#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011106 buf->b_p_sts = p_sts;
11107 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109#ifdef FEAT_COMMENTS
11110 buf->b_p_com = vim_strsave(p_com);
11111#endif
11112#ifdef FEAT_FOLDING
11113 buf->b_p_cms = vim_strsave(p_cms);
11114#endif
11115 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011116 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011117 buf->b_p_nf = vim_strsave(p_nf);
11118 buf->b_p_mps = vim_strsave(p_mps);
11119#ifdef FEAT_SMARTINDENT
11120 buf->b_p_si = p_si;
11121#endif
11122 buf->b_p_ci = p_ci;
11123#ifdef FEAT_CINDENT
11124 buf->b_p_cin = p_cin;
11125 buf->b_p_cink = vim_strsave(p_cink);
11126 buf->b_p_cino = vim_strsave(p_cino);
11127#endif
11128#ifdef FEAT_AUTOCMD
11129 /* Don't copy 'filetype', it must be detected */
11130 buf->b_p_ft = empty_option;
11131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132 buf->b_p_pi = p_pi;
11133#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11134 buf->b_p_cinw = vim_strsave(p_cinw);
11135#endif
11136#ifdef FEAT_LISP
11137 buf->b_p_lisp = p_lisp;
11138#endif
11139#ifdef FEAT_SYN_HL
11140 /* Don't copy 'syntax', it must be set */
11141 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011142 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011143 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011144#endif
11145#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011146 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011147 (void)compile_cap_prog(&buf->b_s);
11148 buf->b_s.b_p_spf = vim_strsave(p_spf);
11149 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011150#endif
11151#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11152 buf->b_p_inde = vim_strsave(p_inde);
11153 buf->b_p_indk = vim_strsave(p_indk);
11154#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011155 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011156#if defined(FEAT_EVAL)
11157 buf->b_p_fex = vim_strsave(p_fex);
11158#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011159#ifdef FEAT_CRYPT
11160 buf->b_p_key = vim_strsave(p_key);
11161#endif
11162#ifdef FEAT_SEARCHPATH
11163 buf->b_p_sua = vim_strsave(p_sua);
11164#endif
11165#ifdef FEAT_KEYMAP
11166 buf->b_p_keymap = vim_strsave(p_keymap);
11167 buf->b_kmap_state |= KEYMAP_INIT;
11168#endif
11169 /* This isn't really an option, but copying the langmap and IME
11170 * state from the current buffer is better than resetting it. */
11171 buf->b_p_iminsert = p_iminsert;
11172 buf->b_p_imsearch = p_imsearch;
11173
11174 /* options that are normally global but also have a local value
11175 * are not copied, start using the global value */
11176 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011177 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011178 buf->b_p_bkc = empty_option;
11179 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011180#ifdef FEAT_QUICKFIX
11181 buf->b_p_gp = empty_option;
11182 buf->b_p_mp = empty_option;
11183 buf->b_p_efm = empty_option;
11184#endif
11185 buf->b_p_ep = empty_option;
11186 buf->b_p_kp = empty_option;
11187 buf->b_p_path = empty_option;
11188 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011189 buf->b_p_tc = empty_option;
11190 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011191#ifdef FEAT_FIND_ID
11192 buf->b_p_def = empty_option;
11193 buf->b_p_inc = empty_option;
11194# ifdef FEAT_EVAL
11195 buf->b_p_inex = vim_strsave(p_inex);
11196# endif
11197#endif
11198#ifdef FEAT_INS_EXPAND
11199 buf->b_p_dict = empty_option;
11200 buf->b_p_tsr = empty_option;
11201#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011202#ifdef FEAT_TEXTOBJ
11203 buf->b_p_qe = vim_strsave(p_qe);
11204#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011205#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11206 buf->b_p_bexpr = empty_option;
11207#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011208#if defined(FEAT_CRYPT)
11209 buf->b_p_cm = empty_option;
11210#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011211#ifdef FEAT_PERSISTENT_UNDO
11212 buf->b_p_udf = p_udf;
11213#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011214#ifdef FEAT_LISP
11215 buf->b_p_lw = empty_option;
11216#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011217#ifdef FEAT_MBYTE
11218 buf->b_p_menc = empty_option;
11219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011220
11221 /*
11222 * Don't copy the options set by ex_help(), use the saved values,
11223 * when going from a help buffer to a non-help buffer.
11224 * Don't touch these at all when BCO_NOHELP is used and going from
11225 * or to a help buffer.
11226 */
11227 if (dont_do_help)
11228 buf->b_p_isk = save_p_isk;
11229 else
11230 {
11231 buf->b_p_isk = vim_strsave(p_isk);
11232 did_isk = TRUE;
11233 buf->b_p_ts = p_ts;
11234 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011235 if (buf->b_p_bt[0] == 'h')
11236 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237 buf->b_p_ma = p_ma;
11238 }
11239 }
11240
11241 /*
11242 * When the options should be copied (ignoring BCO_ALWAYS), set the
11243 * flag that indicates that the options have been initialized.
11244 */
11245 if (should_copy)
11246 buf->b_p_initialized = TRUE;
11247 }
11248
11249 check_buf_options(buf); /* make sure we don't have NULLs */
11250 if (did_isk)
11251 (void)buf_init_chartab(buf, FALSE);
11252}
11253
11254/*
11255 * Reset the 'modifiable' option and its default value.
11256 */
11257 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011258reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011259{
11260 int opt_idx;
11261
11262 curbuf->b_p_ma = FALSE;
11263 p_ma = FALSE;
11264 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011265 if (opt_idx >= 0)
11266 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267}
11268
11269/*
11270 * Set the global value for 'iminsert' to the local value.
11271 */
11272 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011273set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011274{
11275 p_iminsert = curbuf->b_p_iminsert;
11276}
11277
11278/*
11279 * Set the global value for 'imsearch' to the local value.
11280 */
11281 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011282set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011283{
11284 p_imsearch = curbuf->b_p_imsearch;
11285}
11286
11287#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11288static int expand_option_idx = -1;
11289static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11290static int expand_option_flags = 0;
11291
11292 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011293set_context_in_set_cmd(
11294 expand_T *xp,
11295 char_u *arg,
11296 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011297{
11298 int nextchar;
11299 long_u flags = 0; /* init for GCC */
11300 int opt_idx = 0; /* init for GCC */
11301 char_u *p;
11302 char_u *s;
11303 int is_term_option = FALSE;
11304 int key;
11305
11306 expand_option_flags = opt_flags;
11307
11308 xp->xp_context = EXPAND_SETTINGS;
11309 if (*arg == NUL)
11310 {
11311 xp->xp_pattern = arg;
11312 return;
11313 }
11314 p = arg + STRLEN(arg) - 1;
11315 if (*p == ' ' && *(p - 1) != '\\')
11316 {
11317 xp->xp_pattern = p + 1;
11318 return;
11319 }
11320 while (p > arg)
11321 {
11322 s = p;
11323 /* count number of backslashes before ' ' or ',' */
11324 if (*p == ' ' || *p == ',')
11325 {
11326 while (s > arg && *(s - 1) == '\\')
11327 --s;
11328 }
11329 /* break at a space with an even number of backslashes */
11330 if (*p == ' ' && ((p - s) & 1) == 0)
11331 {
11332 ++p;
11333 break;
11334 }
11335 --p;
11336 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011337 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338 {
11339 xp->xp_context = EXPAND_BOOL_SETTINGS;
11340 p += 2;
11341 }
11342 if (STRNCMP(p, "inv", 3) == 0)
11343 {
11344 xp->xp_context = EXPAND_BOOL_SETTINGS;
11345 p += 3;
11346 }
11347 xp->xp_pattern = arg = p;
11348 if (*arg == '<')
11349 {
11350 while (*p != '>')
11351 if (*p++ == NUL) /* expand terminal option name */
11352 return;
11353 key = get_special_key_code(arg + 1);
11354 if (key == 0) /* unknown name */
11355 {
11356 xp->xp_context = EXPAND_NOTHING;
11357 return;
11358 }
11359 nextchar = *++p;
11360 is_term_option = TRUE;
11361 expand_option_name[2] = KEY2TERMCAP0(key);
11362 expand_option_name[3] = KEY2TERMCAP1(key);
11363 }
11364 else
11365 {
11366 if (p[0] == 't' && p[1] == '_')
11367 {
11368 p += 2;
11369 if (*p != NUL)
11370 ++p;
11371 if (*p == NUL)
11372 return; /* expand option name */
11373 nextchar = *++p;
11374 is_term_option = TRUE;
11375 expand_option_name[2] = p[-2];
11376 expand_option_name[3] = p[-1];
11377 }
11378 else
11379 {
11380 /* Allow * wildcard */
11381 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11382 p++;
11383 if (*p == NUL)
11384 return;
11385 nextchar = *p;
11386 *p = NUL;
11387 opt_idx = findoption(arg);
11388 *p = nextchar;
11389 if (opt_idx == -1 || options[opt_idx].var == NULL)
11390 {
11391 xp->xp_context = EXPAND_NOTHING;
11392 return;
11393 }
11394 flags = options[opt_idx].flags;
11395 if (flags & P_BOOL)
11396 {
11397 xp->xp_context = EXPAND_NOTHING;
11398 return;
11399 }
11400 }
11401 }
11402 /* handle "-=" and "+=" */
11403 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11404 {
11405 ++p;
11406 nextchar = '=';
11407 }
11408 if ((nextchar != '=' && nextchar != ':')
11409 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11410 {
11411 xp->xp_context = EXPAND_UNSUCCESSFUL;
11412 return;
11413 }
11414 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11415 {
11416 xp->xp_context = EXPAND_OLD_SETTING;
11417 if (is_term_option)
11418 expand_option_idx = -1;
11419 else
11420 expand_option_idx = opt_idx;
11421 xp->xp_pattern = p + 1;
11422 return;
11423 }
11424 xp->xp_context = EXPAND_NOTHING;
11425 if (is_term_option || (flags & P_NUM))
11426 return;
11427
11428 xp->xp_pattern = p + 1;
11429
11430 if (flags & P_EXPAND)
11431 {
11432 p = options[opt_idx].var;
11433 if (p == (char_u *)&p_bdir
11434 || p == (char_u *)&p_dir
11435 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011436 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011437 || p == (char_u *)&p_rtp
11438#ifdef FEAT_SEARCHPATH
11439 || p == (char_u *)&p_cdpath
11440#endif
11441#ifdef FEAT_SESSION
11442 || p == (char_u *)&p_vdir
11443#endif
11444 )
11445 {
11446 xp->xp_context = EXPAND_DIRECTORIES;
11447 if (p == (char_u *)&p_path
11448#ifdef FEAT_SEARCHPATH
11449 || p == (char_u *)&p_cdpath
11450#endif
11451 )
11452 xp->xp_backslash = XP_BS_THREE;
11453 else
11454 xp->xp_backslash = XP_BS_ONE;
11455 }
11456 else
11457 {
11458 xp->xp_context = EXPAND_FILES;
11459 /* for 'tags' need three backslashes for a space */
11460 if (p == (char_u *)&p_tags)
11461 xp->xp_backslash = XP_BS_THREE;
11462 else
11463 xp->xp_backslash = XP_BS_ONE;
11464 }
11465 }
11466
11467 /* For an option that is a list of file names, find the start of the
11468 * last file name. */
11469 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11470 {
11471 /* count number of backslashes before ' ' or ',' */
11472 if (*p == ' ' || *p == ',')
11473 {
11474 s = p;
11475 while (s > xp->xp_pattern && *(s - 1) == '\\')
11476 --s;
11477 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11478 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11479 {
11480 xp->xp_pattern = p + 1;
11481 break;
11482 }
11483 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011484
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011485#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011486 /* for 'spellsuggest' start at "file:" */
11487 if (options[opt_idx].var == (char_u *)&p_sps
11488 && STRNCMP(p, "file:", 5) == 0)
11489 {
11490 xp->xp_pattern = p + 5;
11491 break;
11492 }
11493#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011494 }
11495
11496 return;
11497}
11498
11499 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011500ExpandSettings(
11501 expand_T *xp,
11502 regmatch_T *regmatch,
11503 int *num_file,
11504 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011505{
11506 int num_normal = 0; /* Nr of matching non-term-code settings */
11507 int num_term = 0; /* Nr of matching terminal code settings */
11508 int opt_idx;
11509 int match;
11510 int count = 0;
11511 char_u *str;
11512 int loop;
11513 int is_term_opt;
11514 char_u name_buf[MAX_KEY_NAME_LEN];
11515 static char *(names[]) = {"all", "termcap"};
11516 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11517
11518 /* do this loop twice:
11519 * loop == 0: count the number of matching options
11520 * loop == 1: copy the matching options into allocated memory
11521 */
11522 for (loop = 0; loop <= 1; ++loop)
11523 {
11524 regmatch->rm_ic = ic;
11525 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11526 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011527 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11528 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011529 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11530 {
11531 if (loop == 0)
11532 num_normal++;
11533 else
11534 (*file)[count++] = vim_strsave((char_u *)names[match]);
11535 }
11536 }
11537 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11538 opt_idx++)
11539 {
11540 if (options[opt_idx].var == NULL)
11541 continue;
11542 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11543 && !(options[opt_idx].flags & P_BOOL))
11544 continue;
11545 is_term_opt = istermoption(&options[opt_idx]);
11546 if (is_term_opt && num_normal > 0)
11547 continue;
11548 match = FALSE;
11549 if (vim_regexec(regmatch, str, (colnr_T)0)
11550 || (options[opt_idx].shortname != NULL
11551 && vim_regexec(regmatch,
11552 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11553 match = TRUE;
11554 else if (is_term_opt)
11555 {
11556 name_buf[0] = '<';
11557 name_buf[1] = 't';
11558 name_buf[2] = '_';
11559 name_buf[3] = str[2];
11560 name_buf[4] = str[3];
11561 name_buf[5] = '>';
11562 name_buf[6] = NUL;
11563 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11564 {
11565 match = TRUE;
11566 str = name_buf;
11567 }
11568 }
11569 if (match)
11570 {
11571 if (loop == 0)
11572 {
11573 if (is_term_opt)
11574 num_term++;
11575 else
11576 num_normal++;
11577 }
11578 else
11579 (*file)[count++] = vim_strsave(str);
11580 }
11581 }
11582 /*
11583 * Check terminal key codes, these are not in the option table
11584 */
11585 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11586 {
11587 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11588 {
11589 if (!isprint(str[0]) || !isprint(str[1]))
11590 continue;
11591
11592 name_buf[0] = 't';
11593 name_buf[1] = '_';
11594 name_buf[2] = str[0];
11595 name_buf[3] = str[1];
11596 name_buf[4] = NUL;
11597
11598 match = FALSE;
11599 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11600 match = TRUE;
11601 else
11602 {
11603 name_buf[0] = '<';
11604 name_buf[1] = 't';
11605 name_buf[2] = '_';
11606 name_buf[3] = str[0];
11607 name_buf[4] = str[1];
11608 name_buf[5] = '>';
11609 name_buf[6] = NUL;
11610
11611 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11612 match = TRUE;
11613 }
11614 if (match)
11615 {
11616 if (loop == 0)
11617 num_term++;
11618 else
11619 (*file)[count++] = vim_strsave(name_buf);
11620 }
11621 }
11622
11623 /*
11624 * Check special key names.
11625 */
11626 regmatch->rm_ic = TRUE; /* ignore case here */
11627 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11628 {
11629 name_buf[0] = '<';
11630 STRCPY(name_buf + 1, str);
11631 STRCAT(name_buf, ">");
11632
11633 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11634 {
11635 if (loop == 0)
11636 num_term++;
11637 else
11638 (*file)[count++] = vim_strsave(name_buf);
11639 }
11640 }
11641 }
11642 if (loop == 0)
11643 {
11644 if (num_normal > 0)
11645 *num_file = num_normal;
11646 else if (num_term > 0)
11647 *num_file = num_term;
11648 else
11649 return OK;
11650 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11651 if (*file == NULL)
11652 {
11653 *file = (char_u **)"";
11654 return FAIL;
11655 }
11656 }
11657 }
11658 return OK;
11659}
11660
11661 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011662ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011663{
11664 char_u *var = NULL; /* init for GCC */
11665 char_u *buf;
11666
11667 *num_file = 0;
11668 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11669 if (*file == NULL)
11670 return FAIL;
11671
11672 /*
11673 * For a terminal key code expand_option_idx is < 0.
11674 */
11675 if (expand_option_idx < 0)
11676 {
11677 var = find_termcode(expand_option_name + 2);
11678 if (var == NULL)
11679 expand_option_idx = findoption(expand_option_name);
11680 }
11681
11682 if (expand_option_idx >= 0)
11683 {
11684 /* put string of option value in NameBuff */
11685 option_value2string(&options[expand_option_idx], expand_option_flags);
11686 var = NameBuff;
11687 }
11688 else if (var == NULL)
11689 var = (char_u *)"";
11690
11691 /* A backslash is required before some characters. This is the reverse of
11692 * what happens in do_set(). */
11693 buf = vim_strsave_escaped(var, escape_chars);
11694
11695 if (buf == NULL)
11696 {
11697 vim_free(*file);
11698 *file = NULL;
11699 return FAIL;
11700 }
11701
11702#ifdef BACKSLASH_IN_FILENAME
11703 /* For MS-Windows et al. we don't double backslashes at the start and
11704 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011705 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011706 if (var[0] == '\\' && var[1] == '\\'
11707 && expand_option_idx >= 0
11708 && (options[expand_option_idx].flags & P_EXPAND)
11709 && vim_isfilec(var[2])
11710 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011711 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011712#endif
11713
11714 *file[0] = buf;
11715 *num_file = 1;
11716 return OK;
11717}
11718#endif
11719
11720/*
11721 * Get the value for the numeric or string option *opp in a nice format into
11722 * NameBuff[]. Must not be called with a hidden option!
11723 */
11724 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011725option_value2string(
11726 struct vimoption *opp,
11727 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011728{
11729 char_u *varp;
11730
11731 varp = get_varp_scope(opp, opt_flags);
11732
11733 if (opp->flags & P_NUM)
11734 {
11735 long wc = 0;
11736
11737 if (wc_use_keyname(varp, &wc))
11738 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11739 else if (wc != 0)
11740 STRCPY(NameBuff, transchar((int)wc));
11741 else
11742 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11743 }
11744 else /* P_STRING */
11745 {
11746 varp = *(char_u **)(varp);
11747 if (varp == NULL) /* just in case */
11748 NameBuff[0] = NUL;
11749#ifdef FEAT_CRYPT
11750 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011751 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752 STRCPY(NameBuff, "*****");
11753#endif
11754 else if (opp->flags & P_EXPAND)
11755 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11756 /* Translate 'pastetoggle' into special key names */
11757 else if ((char_u **)opp->var == &p_pt)
11758 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11759 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011760 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 }
11762}
11763
11764/*
11765 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11766 * printed as a keyname.
11767 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11768 */
11769 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011770wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771{
11772 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11773 {
11774 *wcp = *(long *)varp;
11775 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11776 return TRUE;
11777 }
11778 return FALSE;
11779}
11780
Bram Moolenaar01615492015-02-03 13:00:38 +010011781#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011783 * Any character has an equivalent 'langmap' character. This is used for
11784 * keyboards that have a special language mode that sends characters above
11785 * 128 (although other characters can be translated too). The "to" field is a
11786 * Vim command character. This avoids having to switch the keyboard back to
11787 * ASCII mode when leaving Insert mode.
11788 *
11789 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11790 * commands.
11791 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11792 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11793 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011795# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011796/*
11797 * With multi-byte support use growarray for 'langmap' chars >= 256
11798 */
11799typedef struct
11800{
11801 int from;
11802 int to;
11803} langmap_entry_T;
11804
11805static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011806static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807
11808/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011809 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11810 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011811 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011812 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011813langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011814{
11815 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011816 int a = 0;
11817 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011818
11819 /* Do a binary search for an existing entry. */
11820 while (a != b)
11821 {
11822 int i = (a + b) / 2;
11823 int d = entries[i].from - from;
11824
11825 if (d == 0)
11826 {
11827 entries[i].to = to;
11828 return;
11829 }
11830 if (d < 0)
11831 a = i + 1;
11832 else
11833 b = i;
11834 }
11835
11836 if (ga_grow(&langmap_mapga, 1) != OK)
11837 return; /* out of memory */
11838
11839 /* insert new entry at position "a" */
11840 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11841 mch_memmove(entries + 1, entries,
11842 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11843 ++langmap_mapga.ga_len;
11844 entries[0].from = from;
11845 entries[0].to = to;
11846}
11847
11848/*
11849 * Apply 'langmap' to multi-byte character "c" and return the result.
11850 */
11851 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011852langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011853{
11854 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11855 int a = 0;
11856 int b = langmap_mapga.ga_len;
11857
11858 while (a != b)
11859 {
11860 int i = (a + b) / 2;
11861 int d = entries[i].from - c;
11862
11863 if (d == 0)
11864 return entries[i].to; /* found matching entry */
11865 if (d < 0)
11866 a = i + 1;
11867 else
11868 b = i;
11869 }
11870 return c; /* no entry found, return "c" unmodified */
11871}
11872# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011873
11874 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011875langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876{
11877 int i;
11878
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011879 for (i = 0; i < 256; i++)
11880 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11881# ifdef FEAT_MBYTE
11882 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11883# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011884}
11885
11886/*
11887 * Called when langmap option is set; the language map can be
11888 * changed at any time!
11889 */
11890 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011891langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011892{
11893 char_u *p;
11894 char_u *p2;
11895 int from, to;
11896
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011897#ifdef FEAT_MBYTE
11898 ga_clear(&langmap_mapga); /* clear the previous map first */
11899#endif
11900 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901
11902 for (p = p_langmap; p[0] != NUL; )
11903 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011904 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011905 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906 {
11907 if (p2[0] == '\\' && p2[1] != NUL)
11908 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011909 }
11910 if (p2[0] == ';')
11911 ++p2; /* abcd;ABCD form, p2 points to A */
11912 else
11913 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11914 while (p[0])
11915 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011916 if (p[0] == ',')
11917 {
11918 ++p;
11919 break;
11920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011921 if (p[0] == '\\' && p[1] != NUL)
11922 ++p;
11923#ifdef FEAT_MBYTE
11924 from = (*mb_ptr2char)(p);
11925#else
11926 from = p[0];
11927#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011928 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011929 if (p2 == NULL)
11930 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011931 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011932 if (p[0] != ',')
11933 {
11934 if (p[0] == '\\')
11935 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011937 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011938#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011939 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011940#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011942 }
11943 else
11944 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011945 if (p2[0] != ',')
11946 {
11947 if (p2[0] == '\\')
11948 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011949#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011950 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011952 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011953#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 }
11956 if (to == NUL)
11957 {
11958 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11959 transchar(from));
11960 return;
11961 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011962
11963#ifdef FEAT_MBYTE
11964 if (from >= 256)
11965 langmap_set_entry(from, to);
11966 else
11967#endif
11968 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011969
11970 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011971 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011972 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011973 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011974 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011975 if (*p == ';')
11976 {
11977 p = p2;
11978 if (p[0] != NUL)
11979 {
11980 if (p[0] != ',')
11981 {
11982 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11983 return;
11984 }
11985 ++p;
11986 }
11987 break;
11988 }
11989 }
11990 }
11991 }
11992}
11993#endif
11994
11995/*
11996 * Return TRUE if format option 'x' is in effect.
11997 * Take care of no formatting when 'paste' is set.
11998 */
11999 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012000has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001{
12002 if (p_paste)
12003 return FALSE;
12004 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12005}
12006
12007/*
12008 * Return TRUE if "x" is present in 'shortmess' option, or
12009 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12010 */
12011 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012012shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012013{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012014 return p_shm != NULL &&
12015 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012016 || (vim_strchr(p_shm, 'a') != NULL
12017 && vim_strchr((char_u *)SHM_A, x) != NULL));
12018}
12019
12020/*
12021 * paste_option_changed() - Called after p_paste was set or reset.
12022 */
12023 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012024paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025{
12026 static int old_p_paste = FALSE;
12027 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012028 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029#ifdef FEAT_CMDL_INFO
12030 static int save_ru = 0;
12031#endif
12032#ifdef FEAT_RIGHTLEFT
12033 static int save_ri = 0;
12034 static int save_hkmap = 0;
12035#endif
12036 buf_T *buf;
12037
12038 if (p_paste)
12039 {
12040 /*
12041 * Paste switched from off to on.
12042 * Save the current values, so they can be restored later.
12043 */
12044 if (!old_p_paste)
12045 {
12046 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012047 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012048 {
12049 buf->b_p_tw_nopaste = buf->b_p_tw;
12050 buf->b_p_wm_nopaste = buf->b_p_wm;
12051 buf->b_p_sts_nopaste = buf->b_p_sts;
12052 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012053 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012054 }
12055
12056 /* save global options */
12057 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012058 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012059#ifdef FEAT_CMDL_INFO
12060 save_ru = p_ru;
12061#endif
12062#ifdef FEAT_RIGHTLEFT
12063 save_ri = p_ri;
12064 save_hkmap = p_hkmap;
12065#endif
12066 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012067 p_ai_nopaste = p_ai;
12068 p_et_nopaste = p_et;
12069 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070 p_tw_nopaste = p_tw;
12071 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012072 }
12073
12074 /*
12075 * Always set the option values, also when 'paste' is set when it is
12076 * already on.
12077 */
12078 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012079 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012080 {
12081 buf->b_p_tw = 0; /* textwidth is 0 */
12082 buf->b_p_wm = 0; /* wrapmargin is 0 */
12083 buf->b_p_sts = 0; /* softtabstop is 0 */
12084 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012085 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086 }
12087
12088 /* set global options */
12089 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012090 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012091#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092 if (p_ru)
12093 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012094 p_ru = 0; /* no ruler */
12095#endif
12096#ifdef FEAT_RIGHTLEFT
12097 p_ri = 0; /* no reverse insert */
12098 p_hkmap = 0; /* no Hebrew keyboard */
12099#endif
12100 /* set global values for local buffer options */
12101 p_tw = 0;
12102 p_wm = 0;
12103 p_sts = 0;
12104 p_ai = 0;
12105 }
12106
12107 /*
12108 * Paste switched from on to off: Restore saved values.
12109 */
12110 else if (old_p_paste)
12111 {
12112 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012113 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012114 {
12115 buf->b_p_tw = buf->b_p_tw_nopaste;
12116 buf->b_p_wm = buf->b_p_wm_nopaste;
12117 buf->b_p_sts = buf->b_p_sts_nopaste;
12118 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012119 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120 }
12121
12122 /* restore global options */
12123 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012124 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012125#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012126 if (p_ru != save_ru)
12127 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128 p_ru = save_ru;
12129#endif
12130#ifdef FEAT_RIGHTLEFT
12131 p_ri = save_ri;
12132 p_hkmap = save_hkmap;
12133#endif
12134 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012135 p_ai = p_ai_nopaste;
12136 p_et = p_et_nopaste;
12137 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012138 p_tw = p_tw_nopaste;
12139 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012140 }
12141
12142 old_p_paste = p_paste;
12143}
12144
12145/*
12146 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12147 *
12148 * Reset 'compatible' and set the values for options that didn't get set yet
12149 * to the Vim defaults.
12150 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012151 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152 */
12153 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012154vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012155{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012156 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012157 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012158 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012159
12160 if (!option_was_set((char_u *)"cp"))
12161 {
12162 p_cp = FALSE;
12163 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12164 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12165 set_option_default(opt_idx, OPT_FREE, FALSE);
12166 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012167 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012169
12170 if (fname != NULL)
12171 {
12172 p = vim_getenv(envname, &dofree);
12173 if (p == NULL)
12174 {
12175 /* Set $MYVIMRC to the first vimrc file found. */
12176 p = FullName_save(fname, FALSE);
12177 if (p != NULL)
12178 {
12179 vim_setenv(envname, p);
12180 vim_free(p);
12181 }
12182 }
12183 else if (dofree)
12184 vim_free(p);
12185 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186}
12187
12188/*
12189 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12190 */
12191 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012192change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012194 int opt_idx;
12195
Bram Moolenaar071d4272004-06-13 20:20:40 +000012196 if (p_cp != on)
12197 {
12198 p_cp = on;
12199 compatible_set();
12200 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012201 opt_idx = findoption((char_u *)"cp");
12202 if (opt_idx >= 0)
12203 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012204}
12205
12206/*
12207 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012208 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 */
12210 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012211option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012212{
12213 int idx;
12214
12215 idx = findoption(name);
12216 if (idx < 0) /* unknown option */
12217 return FALSE;
12218 if (options[idx].flags & P_WAS_SET)
12219 return TRUE;
12220 return FALSE;
12221}
12222
12223/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012224 * Reset the flag indicating option "name" was set.
12225 */
12226 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012227reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012228{
12229 int idx = findoption(name);
12230
12231 if (idx >= 0)
12232 options[idx].flags &= ~P_WAS_SET;
12233}
12234
12235/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236 * compatible_set() - Called when 'compatible' has been set or unset.
12237 *
12238 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12239 * flag) to a Vi compatible value.
12240 * When 'compatible' is unset: Set all options that have a different default
12241 * for Vim (without the P_VI_DEF flag) to that default.
12242 */
12243 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012244compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012245{
12246 int opt_idx;
12247
12248 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12249 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12250 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12251 set_option_default(opt_idx, OPT_FREE, p_cp);
12252 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012253 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012254}
12255
12256#ifdef FEAT_LINEBREAK
12257
12258# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12259 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012260 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261# endif
12262
12263/*
12264 * fill_breakat_flags() -- called when 'breakat' changes value.
12265 */
12266 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012267fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012268{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012269 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012270 int i;
12271
12272 for (i = 0; i < 256; i++)
12273 breakat_flags[i] = FALSE;
12274
12275 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012276 for (p = p_breakat; *p; p++)
12277 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012278}
12279
12280# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012281 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012282# endif
12283
12284#endif
12285
12286/*
12287 * Check an option that can be a range of string values.
12288 *
12289 * Return OK for correct value, FAIL otherwise.
12290 * Empty is always OK.
12291 */
12292 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012293check_opt_strings(
12294 char_u *val,
12295 char **values,
12296 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012297{
12298 return opt_strings_flags(val, values, NULL, list);
12299}
12300
12301/*
12302 * Handle an option that can be a range of string values.
12303 * Set a flag in "*flagp" for each string present.
12304 *
12305 * Return OK for correct value, FAIL otherwise.
12306 * Empty is always OK.
12307 */
12308 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012309opt_strings_flags(
12310 char_u *val, /* new value */
12311 char **values, /* array of valid string values */
12312 unsigned *flagp,
12313 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012314{
12315 int i;
12316 int len;
12317 unsigned new_flags = 0;
12318
12319 while (*val)
12320 {
12321 for (i = 0; ; ++i)
12322 {
12323 if (values[i] == NULL) /* val not found in values[] */
12324 return FAIL;
12325
12326 len = (int)STRLEN(values[i]);
12327 if (STRNCMP(values[i], val, len) == 0
12328 && ((list && val[len] == ',') || val[len] == NUL))
12329 {
12330 val += len + (val[len] == ',');
12331 new_flags |= (1 << i);
12332 break; /* check next item in val list */
12333 }
12334 }
12335 }
12336 if (flagp != NULL)
12337 *flagp = new_flags;
12338
12339 return OK;
12340}
12341
12342/*
12343 * Read the 'wildmode' option, fill wim_flags[].
12344 */
12345 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012346check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012347{
12348 char_u new_wim_flags[4];
12349 char_u *p;
12350 int i;
12351 int idx = 0;
12352
12353 for (i = 0; i < 4; ++i)
12354 new_wim_flags[i] = 0;
12355
12356 for (p = p_wim; *p; ++p)
12357 {
12358 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12359 ;
12360 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12361 return FAIL;
12362 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12363 new_wim_flags[idx] |= WIM_LONGEST;
12364 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12365 new_wim_flags[idx] |= WIM_FULL;
12366 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12367 new_wim_flags[idx] |= WIM_LIST;
12368 else
12369 return FAIL;
12370 p += i;
12371 if (*p == NUL)
12372 break;
12373 if (*p == ',')
12374 {
12375 if (idx == 3)
12376 return FAIL;
12377 ++idx;
12378 }
12379 }
12380
12381 /* fill remaining entries with last flag */
12382 while (idx < 3)
12383 {
12384 new_wim_flags[idx + 1] = new_wim_flags[idx];
12385 ++idx;
12386 }
12387
12388 /* only when there are no errors, wim_flags[] is changed */
12389 for (i = 0; i < 4; ++i)
12390 wim_flags[i] = new_wim_flags[i];
12391 return OK;
12392}
12393
12394/*
12395 * Check if backspacing over something is allowed.
12396 */
12397 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012398can_bs(
12399 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012400{
12401 switch (*p_bs)
12402 {
12403 case '2': return TRUE;
12404 case '1': return (what != BS_START);
12405 case '0': return FALSE;
12406 }
12407 return vim_strchr(p_bs, what) != NULL;
12408}
12409
12410/*
12411 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12412 * the file must be considered changed when the value is different.
12413 */
12414 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012415save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012416{
12417 buf->b_start_ffc = *buf->b_p_ff;
12418 buf->b_start_eol = buf->b_p_eol;
12419#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012420 buf->b_start_bomb = buf->b_p_bomb;
12421
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422 /* Only use free/alloc when necessary, they take time. */
12423 if (buf->b_start_fenc == NULL
12424 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12425 {
12426 vim_free(buf->b_start_fenc);
12427 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12428 }
12429#endif
12430}
12431
12432/*
12433 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12434 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012435 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12436 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012437 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012438 * When "ignore_empty" is true don't consider a new, empty buffer to be
12439 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440 */
12441 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012442file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012443{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012444 /* In a buffer that was never loaded the options are not valid. */
12445 if (buf->b_flags & BF_NEVERLOADED)
12446 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012447 if (ignore_empty
12448 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012449 && buf->b_ml.ml_line_count == 1
12450 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12451 return FALSE;
12452 if (buf->b_start_ffc != *buf->b_p_ff)
12453 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012454 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012455 return TRUE;
12456#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012457 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12458 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012459 if (buf->b_start_fenc == NULL)
12460 return (*buf->b_p_fenc != NUL);
12461 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12462#else
12463 return FALSE;
12464#endif
12465}
12466
12467/*
12468 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12469 */
12470 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012471check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472{
12473 return check_opt_strings(p, p_ff_values, FALSE);
12474}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012475
12476/*
12477 * Return the effective shiftwidth value for current buffer, using the
12478 * 'tabstop' value when 'shiftwidth' is zero.
12479 */
12480 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012481get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012482{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012483 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012484}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012485
12486/*
12487 * Return the effective softtabstop value for the current buffer, using the
12488 * 'tabstop' value when 'softtabstop' is negative.
12489 */
12490 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012491get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012492{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012493 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012494}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012495
12496/*
12497 * Check matchpairs option for "*initc".
12498 * If there is a match set "*initc" to the matching character and "*findc" to
12499 * the opposite character. Set "*backwards" to the direction.
12500 * When "switchit" is TRUE swap the direction.
12501 */
12502 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012503find_mps_values(
12504 int *initc,
12505 int *findc,
12506 int *backwards,
12507 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012508{
12509 char_u *ptr;
12510
12511 ptr = curbuf->b_p_mps;
12512 while (*ptr != NUL)
12513 {
12514#ifdef FEAT_MBYTE
12515 if (has_mbyte)
12516 {
12517 char_u *prev;
12518
12519 if (mb_ptr2char(ptr) == *initc)
12520 {
12521 if (switchit)
12522 {
12523 *findc = *initc;
12524 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12525 *backwards = TRUE;
12526 }
12527 else
12528 {
12529 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12530 *backwards = FALSE;
12531 }
12532 return;
12533 }
12534 prev = ptr;
12535 ptr += mb_ptr2len(ptr) + 1;
12536 if (mb_ptr2char(ptr) == *initc)
12537 {
12538 if (switchit)
12539 {
12540 *findc = *initc;
12541 *initc = mb_ptr2char(prev);
12542 *backwards = FALSE;
12543 }
12544 else
12545 {
12546 *findc = mb_ptr2char(prev);
12547 *backwards = TRUE;
12548 }
12549 return;
12550 }
12551 ptr += mb_ptr2len(ptr);
12552 }
12553 else
12554#endif
12555 {
12556 if (*ptr == *initc)
12557 {
12558 if (switchit)
12559 {
12560 *backwards = TRUE;
12561 *findc = *initc;
12562 *initc = ptr[2];
12563 }
12564 else
12565 {
12566 *backwards = FALSE;
12567 *findc = ptr[2];
12568 }
12569 return;
12570 }
12571 ptr += 2;
12572 if (*ptr == *initc)
12573 {
12574 if (switchit)
12575 {
12576 *backwards = FALSE;
12577 *findc = *initc;
12578 *initc = ptr[-2];
12579 }
12580 else
12581 {
12582 *backwards = TRUE;
12583 *findc = ptr[-2];
12584 }
12585 return;
12586 }
12587 ++ptr;
12588 }
12589 if (*ptr == ',')
12590 ++ptr;
12591 }
12592}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012593
12594#if defined(FEAT_LINEBREAK) || defined(PROTO)
12595/*
12596 * This is called when 'breakindentopt' is changed and when a window is
12597 * initialized.
12598 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012599 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012600briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012601{
12602 char_u *p;
12603 int bri_shift = 0;
12604 long bri_min = 20;
12605 int bri_sbr = FALSE;
12606
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012607 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012608 while (*p != NUL)
12609 {
12610 if (STRNCMP(p, "shift:", 6) == 0
12611 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12612 {
12613 p += 6;
12614 bri_shift = getdigits(&p);
12615 }
12616 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12617 {
12618 p += 4;
12619 bri_min = getdigits(&p);
12620 }
12621 else if (STRNCMP(p, "sbr", 3) == 0)
12622 {
12623 p += 3;
12624 bri_sbr = TRUE;
12625 }
12626 if (*p != ',' && *p != NUL)
12627 return FAIL;
12628 if (*p == ',')
12629 ++p;
12630 }
12631
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012632 wp->w_p_brishift = bri_shift;
12633 wp->w_p_brimin = bri_min;
12634 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012635
12636 return OK;
12637}
12638#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012639
12640/*
12641 * Get the local or global value of 'backupcopy'.
12642 */
12643 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012644get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012645{
12646 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12647}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012648
12649#if defined(FEAT_SIGNS) || defined(PROTO)
12650/*
12651 * Return TRUE when window "wp" has a column to draw signs in.
12652 */
12653 int
12654signcolumn_on(win_T *wp)
12655{
12656 if (*wp->w_p_scl == 'n')
12657 return FALSE;
12658 if (*wp->w_p_scl == 'y')
12659 return TRUE;
12660 return (wp->w_buffer->b_signlist != NULL
12661# ifdef FEAT_NETBEANS_INTG
12662 || wp->w_buffer->b_has_sign_column
12663# endif
12664 );
12665}
12666#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012667
12668#if defined(FEAT_EVAL) || defined(PROTO)
12669/*
12670 * Get window or buffer local options.
12671 */
12672 dict_T *
12673get_winbuf_options(int bufopt)
12674{
12675 dict_T *d;
12676 int opt_idx;
12677
12678 d = dict_alloc();
12679 if (d == NULL)
12680 return NULL;
12681
12682 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12683 {
12684 struct vimoption *opt = &options[opt_idx];
12685
12686 if ((bufopt && (opt->indir & PV_BUF))
12687 || (!bufopt && (opt->indir & PV_WIN)))
12688 {
12689 char_u *varp = get_varp(opt);
12690
12691 if (varp != NULL)
12692 {
12693 if (opt->flags & P_STRING)
12694 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012695 else if (opt->flags & P_NUM)
12696 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012697 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012698 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012699 }
12700 }
12701 }
12702
12703 return d;
12704}
12705#endif