blob: d1a25339bececa6a4b127382a62f92220dac9f43 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
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.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * 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 Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# 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 Moolenaar5e3cb7e2006-02-27 23:58:35 +0000110#ifdef FEAT_EVAL
111# define PV_FEX OPT_BUF(BV_FEX)
112#endif
113#define PV_FF OPT_BUF(BV_FF)
114#define PV_FLP OPT_BUF(BV_FLP)
115#define PV_FO OPT_BUF(BV_FO)
116#ifdef FEAT_AUTOCMD
117# define PV_FT OPT_BUF(BV_FT)
118#endif
119#define PV_IMI OPT_BUF(BV_IMI)
120#define PV_IMS OPT_BUF(BV_IMS)
121#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
122# define PV_INDE OPT_BUF(BV_INDE)
123# define PV_INDK OPT_BUF(BV_INDK)
124#endif
125#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
126# define PV_INEX OPT_BUF(BV_INEX)
127#endif
128#define PV_INF OPT_BUF(BV_INF)
129#define PV_ISK OPT_BUF(BV_ISK)
130#ifdef FEAT_CRYPT
131# define PV_KEY OPT_BUF(BV_KEY)
132#endif
133#ifdef FEAT_KEYMAP
134# define PV_KMAP OPT_BUF(BV_KMAP)
135#endif
136#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
137#ifdef FEAT_LISP
138# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100139# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000140#endif
141#define PV_MA OPT_BUF(BV_MA)
142#define PV_ML OPT_BUF(BV_ML)
143#define PV_MOD OPT_BUF(BV_MOD)
144#define PV_MPS OPT_BUF(BV_MPS)
145#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100158#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000159#ifdef FEAT_SYN_HL
160# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000161# define PV_SYN OPT_BUF(BV_SYN)
162#endif
163#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164# define PV_SPC OPT_BUF(BV_SPC)
165# define PV_SPF OPT_BUF(BV_SPF)
166# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000167#endif
168#define PV_STS OPT_BUF(BV_STS)
169#ifdef FEAT_SEARCHPATH
170# define PV_SUA OPT_BUF(BV_SUA)
171#endif
172#define PV_SW OPT_BUF(BV_SW)
173#define PV_SWF OPT_BUF(BV_SWF)
174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100175#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200179#ifdef FEAT_PERSISTENT_UNDO
180# define PV_UDF OPT_BUF(BV_UDF)
181#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
221#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
228#ifdef FEAT_SCROLLBIND
229# define PV_SCBIND OPT_WIN(WV_SCBIND)
230#endif
231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_WINDOWS
245# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000246# define PV_WFW OPT_WIN(WV_WFW)
247#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200249#ifdef FEAT_CURSORBIND
250# define PV_CRBIND OPT_WIN(WV_CRBIND)
251#endif
252#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200253# define PV_COCU OPT_WIN(WV_COCU)
254# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200255#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200256#ifdef FEAT_SIGNS
257# define PV_SCL OPT_WIN(WV_SCL)
258#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000259
260/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261typedef enum
262{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000263 PV_NONE = 0,
264 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265} idopt_T;
266
267/*
268 * Options local to a window have a value local to a buffer and global to all
269 * buffers. Indicate this by setting "var" to VAR_WIN.
270 */
271#define VAR_WIN ((char_u *)-1)
272
273/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000274 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275 * Only to be used in option.c!
276 */
277static int p_ai;
278static int p_bin;
279#ifdef FEAT_MBYTE
280static int p_bomb;
281#endif
282#if defined(FEAT_QUICKFIX)
283static char_u *p_bh;
284static char_u *p_bt;
285#endif
286static int p_bl;
287static int p_ci;
288#ifdef FEAT_CINDENT
289static int p_cin;
290static char_u *p_cink;
291static char_u *p_cino;
292#endif
293#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
294static char_u *p_cinw;
295#endif
296#ifdef FEAT_COMMENTS
297static char_u *p_com;
298#endif
299#ifdef FEAT_FOLDING
300static char_u *p_cms;
301#endif
302#ifdef FEAT_INS_EXPAND
303static char_u *p_cpt;
304#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#ifdef FEAT_COMPL_FUNC
306static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000307static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200310static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311static int p_et;
312#ifdef FEAT_MBYTE
313static char_u *p_fenc;
314#endif
315static char_u *p_ff;
316static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000317static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318#ifdef FEAT_AUTOCMD
319static char_u *p_ft;
320#endif
321static long p_iminsert;
322static long p_imsearch;
323#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
324static char_u *p_inex;
325#endif
326#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
327static char_u *p_inde;
328static char_u *p_indk;
329#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000330#if defined(FEAT_EVAL)
331static char_u *p_fex;
332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000333static int p_inf;
334static char_u *p_isk;
335#ifdef FEAT_CRYPT
336static char_u *p_key;
337#endif
338#ifdef FEAT_LISP
339static int p_lisp;
340#endif
341static int p_ml;
342static int p_ma;
343static int p_mod;
344static char_u *p_mps;
345static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000347#ifdef FEAT_TEXTOBJ
348static char_u *p_qe;
349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_ro;
351#ifdef FEAT_SMARTINDENT
352static int p_si;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static long p_sts;
356#if defined(FEAT_SEARCHPATH)
357static char_u *p_sua;
358#endif
359static long p_sw;
360static int p_swf;
361#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000362static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000364#endif
365#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000366static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000367static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000368static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369#endif
370static long p_ts;
371static long p_tw;
372static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200373#ifdef FEAT_PERSISTENT_UNDO
374static int p_udf;
375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376static long p_wm;
377#ifdef FEAT_KEYMAP
378static char_u *p_keymap;
379#endif
380
381/* Saved values for when 'bin' is set. */
382static int p_et_nobin;
383static int p_ml_nobin;
384static long p_tw_nobin;
385static long p_wm_nobin;
386
387/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200388static int p_ai_nopaste;
389static int p_et_nopaste;
390static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000391static long p_tw_nopaste;
392static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000393
394struct vimoption
395{
396 char *fullname; /* full option name */
397 char *shortname; /* permissible abbreviation */
398 long_u flags; /* see below */
399 char_u *var; /* global option: pointer to variable;
400 * window-local option: VAR_WIN;
401 * buffer-local option: global value */
402 idopt_T indir; /* global option: PV_NONE;
403 * local option: indirect option index */
404 char_u *def_val[2]; /* default values for variable (vi and vim) */
405#ifdef FEAT_EVAL
406 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000407# define SCRIPTID_INIT , 0
408#else
409# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410#endif
411};
412
413#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
414#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
415
416/*
417 * Flags
418 */
419#define P_BOOL 0x01 /* the option is boolean */
420#define P_NUM 0x02 /* the option is numeric */
421#define P_STRING 0x04 /* the option is a string */
422#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000423 must use free_string_option() when
424 assigning new value. Not set if default is
425 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
427 never be used for local or hidden options! */
428#define P_NODEFAULT 0x40 /* don't set to default value */
429#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
430 use vim_free() when assigning new value */
431#define P_WAS_SET 0x100 /* option has been set/reset */
432#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
433#define P_VI_DEF 0x400 /* Use Vi default for Vim */
434#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
435
436 /* when option changed, what to display: */
437#define P_RSTAT 0x1000 /* redraw status lines */
438#define P_RWIN 0x2000 /* redraw current window */
439#define P_RBUF 0x4000 /* redraw current buffer */
440#define P_RALL 0x6000 /* redraw all windows */
441#define P_RCLR 0x7000 /* clear and redraw all */
442
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200443#define P_COMMA 0x8000 /* comma separated list */
444#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
445 * commas */
446#define P_NODUP 0x20000L /* don't allow duplicate strings */
447#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000448
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200449#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
450#define P_GETTEXT 0x100000L /* expand default value with _() */
451#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
452#define P_NFNAME 0x400000L /* only normal file name chars allowed */
453#define P_INSECURE 0x800000L /* option was set from a modeline */
454#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000455 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200456#define P_NO_ML 0x2000000L /* not allowed in modeline */
457#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200458 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000459
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000460#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
461
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000462/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
463 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100464#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000465# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000466#else
467# define ISP_LATIN1 (char_u *)"@,161-255"
468#endif
469
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100470/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000471#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100472 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200473 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100474# define HIGHLIGHT_INIT "8:SpecialKey,@: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"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000475#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100476# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000477#endif
478
Bram Moolenaar071d4272004-06-13 20:20:40 +0000479/*
480 * options[] is initialized here.
481 * The order of the options MUST be alphabetic for ":set all" and findoption().
482 * All option names MUST start with a lowercase letter (for findoption()).
483 * Exception: "t_" options are at the end.
484 * The options with a NULL variable are 'hidden': a set command for them is
485 * ignored and they are not printed.
486 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100487static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000488{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200489 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000490#ifdef FEAT_RIGHTLEFT
491 (char_u *)&p_aleph, PV_NONE,
492#else
493 (char_u *)NULL, PV_NONE,
494#endif
495 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100496#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497 (char_u *)128L,
498#else
499 (char_u *)224L,
500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000501 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
503#if defined(FEAT_GUI) && defined(MACOS_X)
504 (char_u *)&p_antialias, PV_NONE,
505 {(char_u *)FALSE, (char_u *)FALSE}
506#else
507 (char_u *)NULL, PV_NONE,
508 {(char_u *)FALSE, (char_u *)FALSE}
509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000510 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200511 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512#ifdef FEAT_ARABIC
513 (char_u *)VAR_WIN, PV_ARAB,
514#else
515 (char_u *)NULL, PV_NONE,
516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000517 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
519#ifdef FEAT_ARABIC
520 (char_u *)&p_arshape, PV_NONE,
521#else
522 (char_u *)NULL, PV_NONE,
523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000524 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
526#ifdef FEAT_RIGHTLEFT
527 (char_u *)&p_ari, PV_NONE,
528#else
529 (char_u *)NULL, PV_NONE,
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
533#ifdef FEAT_FKMAP
534 (char_u *)&p_altkeymap, PV_NONE,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000538 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
540#if defined(FEAT_MBYTE)
541 (char_u *)&p_ambw, PV_NONE,
542 {(char_u *)"single", (char_u *)0L}
543#else
544 (char_u *)NULL, PV_NONE,
545 {(char_u *)0L, (char_u *)0L}
546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000547 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000548#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"autochdir", "acd", P_BOOL|P_VI_DEF,
550 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552#endif
553 {"autoindent", "ai", P_BOOL|P_VI_DEF,
554 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autoprint", "ap", P_BOOL|P_VI_DEF,
557 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000560 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autowrite", "aw", P_BOOL|P_VI_DEF,
563 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autowriteall","awa", P_BOOL|P_VI_DEF,
566 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
569 (char_u *)&p_bg, PV_NONE,
570 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100571#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 (char_u *)"dark",
573#else
574 (char_u *)"light",
575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200577 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
581 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200583 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200584 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585#ifdef UNIX
586 {(char_u *)"yes", (char_u *)"auto"}
587#else
588 {(char_u *)"auto", (char_u *)"auto"}
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
592 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000595 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 (char_u *)&p_bex, PV_NONE,
597 {
598#ifdef VMS
599 (char_u *)"_",
600#else
601 (char_u *)"~",
602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200604 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605#ifdef FEAT_WILDIGN
606 (char_u *)&p_bsk, PV_NONE,
607 {(char_u *)"", (char_u *)0L}
608#else
609 (char_u *)NULL, PV_NONE,
610 {(char_u *)0L, (char_u *)0L}
611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613#ifdef FEAT_BEVAL
614 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
615 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
618 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000620# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000621 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000622 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625#endif
626 {"beautify", "bf", P_BOOL|P_VI_DEF,
627 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200629 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
630 (char_u *)&p_bo, PV_NONE,
631 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
633 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
639#ifdef FEAT_MBYTE
640 (char_u *)&p_bomb, PV_BOMB,
641#else
642 (char_u *)NULL, PV_NONE,
643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000644 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
646#ifdef FEAT_LINEBREAK
647 (char_u *)&p_breakat, PV_NONE,
648 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000653 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200654 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
655#ifdef FEAT_LINEBREAK
656 (char_u *)VAR_WIN, PV_BRI,
657 {(char_u *)FALSE, (char_u *)0L}
658#else
659 (char_u *)NULL, PV_NONE,
660 {(char_u *)0L, (char_u *)0L}
661#endif
662 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200663 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
664 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200665#ifdef FEAT_LINEBREAK
666 (char_u *)VAR_WIN, PV_BRIOPT,
667 {(char_u *)"", (char_u *)NULL}
668#else
669 (char_u *)NULL, PV_NONE,
670 {(char_u *)"", (char_u *)NULL}
671#endif
672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
674#ifdef FEAT_BROWSE
675 (char_u *)&p_bsdir, PV_NONE,
676 {(char_u *)"last", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
683#if defined(FEAT_QUICKFIX)
684 (char_u *)&p_bh, PV_BH,
685 {(char_u *)"", (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 Moolenaar071d4272004-06-13 20:20:40 +0000691 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
692 (char_u *)&p_bl, PV_BL,
693 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
696#if defined(FEAT_QUICKFIX)
697 (char_u *)&p_bt, PV_BT,
698 {(char_u *)"", (char_u *)0L}
699#else
700 (char_u *)NULL, PV_NONE,
701 {(char_u *)0L, (char_u *)0L}
702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000703 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200704 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000705#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 (char_u *)&p_cmp, PV_NONE,
707 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000708#else
709 (char_u *)NULL, PV_NONE,
710 {(char_u *)0L, (char_u *)0L}
711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
714#ifdef FEAT_SEARCHPATH
715 (char_u *)&p_cdpath, PV_NONE,
716 {(char_u *)",,", (char_u *)0L}
717#else
718 (char_u *)NULL, PV_NONE,
719 {(char_u *)0L, (char_u *)0L}
720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"cedit", NULL, P_STRING,
723#ifdef FEAT_CMDWIN
724 (char_u *)&p_cedit, PV_NONE,
725 {(char_u *)"", (char_u *)CTRL_F_STR}
726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
732#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
733 (char_u *)&p_ccv, PV_NONE,
734 {(char_u *)"", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
741#ifdef FEAT_CINDENT
742 (char_u *)&p_cin, PV_CIN,
743#else
744 (char_u *)NULL, PV_NONE,
745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200747 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748#ifdef FEAT_CINDENT
749 (char_u *)&p_cink, PV_CINK,
750 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
751#else
752 (char_u *)NULL, PV_NONE,
753 {(char_u *)0L, (char_u *)0L}
754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000755 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200756 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757#ifdef FEAT_CINDENT
758 (char_u *)&p_cino, PV_CINO,
759#else
760 (char_u *)NULL, PV_NONE,
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200763 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
765 (char_u *)&p_cinw, PV_CINW,
766 {(char_u *)"if,else,while,do,for,switch",
767 (char_u *)0L}
768#else
769 (char_u *)NULL, PV_NONE,
770 {(char_u *)0L, (char_u *)0L}
771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000772 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200773 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774#ifdef FEAT_CLIPBOARD
775 (char_u *)&p_cb, PV_NONE,
776# ifdef FEAT_XCLIPBOARD
777 {(char_u *)"autoselect,exclude:cons\\|linux",
778 (char_u *)0L}
779# else
780 {(char_u *)"", (char_u *)0L}
781# endif
782#else
783 (char_u *)NULL, PV_NONE,
784 {(char_u *)"", (char_u *)0L}
785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
788 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
791#ifdef FEAT_CMDWIN
792 (char_u *)&p_cwh, PV_NONE,
793#else
794 (char_u *)NULL, PV_NONE,
795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000796 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200797 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200798#ifdef FEAT_SYN_HL
799 (char_u *)VAR_WIN, PV_CC,
800#else
801 (char_u *)NULL, PV_NONE,
802#endif
803 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
805 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000806 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200807 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
808 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809#ifdef FEAT_COMMENTS
810 (char_u *)&p_com, PV_COM,
811 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
812 (char_u *)0L}
813#else
814 (char_u *)NULL, PV_NONE,
815 {(char_u *)0L, (char_u *)0L}
816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200818 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819#ifdef FEAT_FOLDING
820 (char_u *)&p_cms, PV_CMS,
821 {(char_u *)"/*%s*/", (char_u *)0L}
822#else
823 (char_u *)NULL, PV_NONE,
824 {(char_u *)0L, (char_u *)0L}
825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000826 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000827 /* P_PRI_MKRC isn't needed here, optval_default()
828 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829 {"compatible", "cp", P_BOOL|P_RALL,
830 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200832 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833#ifdef FEAT_INS_EXPAND
834 (char_u *)&p_cpt, PV_CPT,
835 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
836#else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000840 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200841 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200842#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200843 (char_u *)VAR_WIN, PV_COCU,
844 {(char_u *)"", (char_u *)NULL}
845#else
846 (char_u *)NULL, PV_NONE,
847 {(char_u *)NULL, (char_u *)0L}
848#endif
849 SCRIPTID_INIT},
850 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
851#ifdef FEAT_CONCEAL
852 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200853#else
854 (char_u *)NULL, PV_NONE,
855#endif
856 {(char_u *)0L, (char_u *)0L}
857 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000858 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
859#ifdef FEAT_COMPL_FUNC
860 (char_u *)&p_cfu, PV_CFU,
861 {(char_u *)"", (char_u *)0L}
862#else
863 (char_u *)NULL, PV_NONE,
864 {(char_u *)0L, (char_u *)0L}
865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200867 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000868#ifdef FEAT_INS_EXPAND
869 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000870 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000871#else
872 (char_u *)NULL, PV_NONE,
873 {(char_u *)0L, (char_u *)0L}
874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000875 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000876 {"confirm", "cf", P_BOOL|P_VI_DEF,
877#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
878 (char_u *)&p_confirm, PV_NONE,
879#else
880 (char_u *)NULL, PV_NONE,
881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000884 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
887 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
890 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000891 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
892 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200893 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200894#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200895 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200896 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200897#else
898 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200899 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200900#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200901 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
903#ifdef FEAT_CSCOPE
904 (char_u *)&p_cspc, PV_NONE,
905#else
906 (char_u *)NULL, PV_NONE,
907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000908 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
910#ifdef FEAT_CSCOPE
911 (char_u *)&p_csprg, PV_NONE,
912 {(char_u *)"cscope", (char_u *)0L}
913#else
914 (char_u *)NULL, PV_NONE,
915 {(char_u *)0L, (char_u *)0L}
916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200918 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
920 (char_u *)&p_csqf, PV_NONE,
921 {(char_u *)"", (char_u *)0L}
922#else
923 (char_u *)NULL, PV_NONE,
924 {(char_u *)0L, (char_u *)0L}
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200927 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
928#ifdef FEAT_CSCOPE
929 (char_u *)&p_csre, PV_NONE,
930#else
931 (char_u *)NULL, PV_NONE,
932#endif
933 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
935#ifdef FEAT_CSCOPE
936 (char_u *)&p_cst, PV_NONE,
937#else
938 (char_u *)NULL, PV_NONE,
939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000940 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000941 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
942#ifdef FEAT_CSCOPE
943 (char_u *)&p_csto, PV_NONE,
944#else
945 (char_u *)NULL, PV_NONE,
946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000947 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
949#ifdef FEAT_CSCOPE
950 (char_u *)&p_csverbose, PV_NONE,
951#else
952 (char_u *)NULL, PV_NONE,
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200955 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
956#ifdef FEAT_CURSORBIND
957 (char_u *)VAR_WIN, PV_CRBIND,
958#else
959 (char_u *)NULL, PV_NONE,
960#endif
961 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000962 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
963#ifdef FEAT_SYN_HL
964 (char_u *)VAR_WIN, PV_CUC,
965#else
966 (char_u *)NULL, PV_NONE,
967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000969 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
970#ifdef FEAT_SYN_HL
971 (char_u *)VAR_WIN, PV_CUL,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"debug", NULL, P_STRING|P_VI_DEF,
977 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000978 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200979 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000981 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000982 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983#else
984 (char_u *)NULL, PV_NONE,
985 {(char_u *)NULL, (char_u *)0L}
986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
989#ifdef FEAT_MBYTE
990 (char_u *)&p_deco, PV_NONE,
991#else
992 (char_u *)NULL, PV_NONE,
993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200995 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000997 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#else
999 (char_u *)NULL, PV_NONE,
1000#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001001 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1003#ifdef FEAT_DIFF
1004 (char_u *)VAR_WIN, PV_DIFF,
1005#else
1006 (char_u *)NULL, PV_NONE,
1007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001009 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1011 (char_u *)&p_dex, PV_NONE,
1012 {(char_u *)"", (char_u *)0L}
1013#else
1014 (char_u *)NULL, PV_NONE,
1015 {(char_u *)0L, (char_u *)0L}
1016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001018 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1019 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020#ifdef FEAT_DIFF
1021 (char_u *)&p_dip, PV_NONE,
1022 {(char_u *)"filler", (char_u *)NULL}
1023#else
1024 (char_u *)NULL, PV_NONE,
1025 {(char_u *)"", (char_u *)NULL}
1026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1029#ifdef FEAT_DIGRAPHS
1030 (char_u *)&p_dg, PV_NONE,
1031#else
1032 (char_u *)NULL, PV_NONE,
1033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001034 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001035 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1036 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001039 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001043#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 (char_u *)&p_ead, PV_NONE,
1045 {(char_u *)"both", (char_u *)0L}
1046#else
1047 (char_u *)NULL, PV_NONE,
1048 {(char_u *)NULL, (char_u *)0L}
1049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1052 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001054 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1055#if defined(FEAT_MBYTE)
1056 (char_u *)&p_emoji, PV_NONE,
1057 {(char_u *)TRUE, (char_u *)0L}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)0L, (char_u *)0L}
1061#endif
1062 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001063 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064#ifdef FEAT_MBYTE
1065 (char_u *)&p_enc, PV_NONE,
1066 {(char_u *)ENC_DFLT, (char_u *)0L}
1067#else
1068 (char_u *)NULL, PV_NONE,
1069 {(char_u *)0L, (char_u *)0L}
1070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1073 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1076 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001079 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1082 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1085#ifdef FEAT_QUICKFIX
1086 (char_u *)&p_ef, PV_NONE,
1087 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1088#else
1089 (char_u *)NULL, PV_NONE,
1090 {(char_u *)NULL, (char_u *)0L}
1091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001092 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001093 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001095 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097#else
1098 (char_u *)NULL, PV_NONE,
1099 {(char_u *)NULL, (char_u *)0L}
1100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 {"esckeys", "ek", P_BOOL|P_VIM,
1103 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001105 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106#ifdef FEAT_AUTOCMD
1107 (char_u *)&p_ei, PV_NONE,
1108#else
1109 (char_u *)NULL, PV_NONE,
1110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1113 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1116 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001118 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1119 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120#ifdef FEAT_MBYTE
1121 (char_u *)&p_fenc, PV_FENC,
1122 {(char_u *)"", (char_u *)0L}
1123#else
1124 (char_u *)NULL, PV_NONE,
1125 {(char_u *)0L, (char_u *)0L}
1126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001128 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129#ifdef FEAT_MBYTE
1130 (char_u *)&p_fencs, PV_NONE,
1131 {(char_u *)"ucs-bom", (char_u *)0L}
1132#else
1133 (char_u *)NULL, PV_NONE,
1134 {(char_u *)0L, (char_u *)0L}
1135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001137 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1138 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001141 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1144 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001145 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1146 (char_u *)&p_fic, PV_NONE,
1147 {
1148#ifdef CASE_INSENSITIVE_FILENAME
1149 (char_u *)TRUE,
1150#else
1151 (char_u *)FALSE,
1152#endif
1153 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001154 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155#ifdef FEAT_AUTOCMD
1156 (char_u *)&p_ft, PV_FT,
1157 {(char_u *)"", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)0L, (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1165 (char_u *)&p_fcs, PV_NONE,
1166 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1167#else
1168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)"", (char_u *)0L}
1170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001172 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1173 (char_u *)&p_fixeol, PV_FIXEOL,
1174 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001175 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1176#ifdef FEAT_FKMAP
1177 (char_u *)&p_fkmap, PV_NONE,
1178#else
1179 (char_u *)NULL, PV_NONE,
1180#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"flash", "fl", P_BOOL|P_VI_DEF,
1183 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001185#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001186 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1190 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1193 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1196# ifdef FEAT_EVAL
1197 (char_u *)VAR_WIN, PV_FDE,
1198 {(char_u *)"0", (char_u *)NULL}
1199# else
1200 (char_u *)NULL, PV_NONE,
1201 {(char_u *)NULL, (char_u *)0L}
1202# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1205 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1208 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001210 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001214 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)"{{{,}}}", (char_u *)NULL}
1217 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1219 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1225 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001227 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 (char_u *)&p_fdo, PV_NONE,
1229 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1232# ifdef FEAT_EVAL
1233 (char_u *)VAR_WIN, PV_FDT,
1234 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001235# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236 (char_u *)NULL, PV_NONE,
1237 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001238# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001239 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001241 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001242#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001243 (char_u *)&p_fex, PV_FEX,
1244 {(char_u *)"", (char_u *)0L}
1245#else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)0L, (char_u *)0L}
1248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1251 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001252 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1253 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001254 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1255 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1257 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1259 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001261 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1262#ifdef HAVE_FSYNC
1263 (char_u *)&p_fs, PV_NONE,
1264 {(char_u *)TRUE, (char_u *)0L}
1265#else
1266 (char_u *)NULL, PV_NONE,
1267 {(char_u *)FALSE, (char_u *)0L}
1268#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1271 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 {"graphic", "gr", P_BOOL|P_VI_DEF,
1274 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001276 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277#ifdef FEAT_QUICKFIX
1278 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001279 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280#else
1281 (char_u *)NULL, PV_NONE,
1282 {(char_u *)NULL, (char_u *)0L}
1283#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1286#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001287 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 {
1289# ifdef WIN3264
1290 /* may be changed to "grep -n" in os_win32.c */
1291 (char_u *)"findstr /n",
1292# else
1293# ifdef UNIX
1294 /* Add an extra file name so that grep will always
1295 * insert a file name in the match line. */
1296 (char_u *)"grep -n $* /dev/null",
1297# else
1298# ifdef VMS
1299 (char_u *)"SEARCH/NUMBERS ",
1300# else
1301 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001302# endif
1303# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001305 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306#else
1307 (char_u *)NULL, PV_NONE,
1308 {(char_u *)NULL, (char_u *)0L}
1309#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001310 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001311 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001312#ifdef CURSOR_SHAPE
1313 (char_u *)&p_guicursor, PV_NONE,
1314 {
1315# ifdef FEAT_GUI
1316 (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 +01001317# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1319# endif
1320 (char_u *)0L}
1321#else
1322 (char_u *)NULL, PV_NONE,
1323 {(char_u *)NULL, (char_u *)0L}
1324#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001325 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001326 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327#ifdef FEAT_GUI
1328 (char_u *)&p_guifont, PV_NONE,
1329 {(char_u *)"", (char_u *)0L}
1330#else
1331 (char_u *)NULL, PV_NONE,
1332 {(char_u *)NULL, (char_u *)0L}
1333#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001334 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001335 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1337 (char_u *)&p_guifontset, PV_NONE,
1338 {(char_u *)"", (char_u *)0L}
1339#else
1340 (char_u *)NULL, PV_NONE,
1341 {(char_u *)NULL, (char_u *)0L}
1342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001344 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001345#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1346 (char_u *)&p_guifontwide, PV_NONE,
1347 {(char_u *)"", (char_u *)0L}
1348#else
1349 (char_u *)NULL, PV_NONE,
1350 {(char_u *)NULL, (char_u *)0L}
1351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001354#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001355 (char_u *)&p_ghr, PV_NONE,
1356#else
1357 (char_u *)NULL, PV_NONE,
1358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001361#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 (char_u *)&p_go, PV_NONE,
1363# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001364 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001366 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367# endif
1368#else
1369 (char_u *)NULL, PV_NONE,
1370 {(char_u *)NULL, (char_u *)0L}
1371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001372 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373 {"guipty", NULL, P_BOOL|P_VI_DEF,
1374#if defined(FEAT_GUI)
1375 (char_u *)&p_guipty, PV_NONE,
1376#else
1377 (char_u *)NULL, PV_NONE,
1378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001380 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001381#if defined(FEAT_GUI_TABLINE)
1382 (char_u *)&p_gtl, PV_NONE,
1383 {(char_u *)"", (char_u *)0L}
1384#else
1385 (char_u *)NULL, PV_NONE,
1386 {(char_u *)NULL, (char_u *)0L}
1387#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001389 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001390#if defined(FEAT_GUI_TABLINE)
1391 (char_u *)&p_gtt, PV_NONE,
1392 {(char_u *)"", (char_u *)0L}
1393#else
1394 (char_u *)NULL, PV_NONE,
1395 {(char_u *)NULL, (char_u *)0L}
1396#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1399 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1402 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1404 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 {"helpheight", "hh", P_NUM|P_VI_DEF,
1406#ifdef FEAT_WINDOWS
1407 (char_u *)&p_hh, PV_NONE,
1408#else
1409 (char_u *)NULL, PV_NONE,
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001412 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413#ifdef FEAT_MULTI_LANG
1414 (char_u *)&p_hlg, PV_NONE,
1415 {(char_u *)"", (char_u *)0L}
1416#else
1417 (char_u *)NULL, PV_NONE,
1418 {(char_u *)0L, (char_u *)0L}
1419#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001420 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001421 {"hidden", "hid", P_BOOL|P_VI_DEF,
1422 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001424 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1427 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"history", "hi", P_NUM|P_VIM,
1429 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001430 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1432#ifdef FEAT_RIGHTLEFT
1433 (char_u *)&p_hkmap, PV_NONE,
1434#else
1435 (char_u *)NULL, PV_NONE,
1436#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1439#ifdef FEAT_RIGHTLEFT
1440 (char_u *)&p_hkmapp, PV_NONE,
1441#else
1442 (char_u *)NULL, PV_NONE,
1443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1446 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"icon", NULL, P_BOOL|P_VI_DEF,
1449#ifdef FEAT_TITLE
1450 (char_u *)&p_icon, PV_NONE,
1451#else
1452 (char_u *)NULL, PV_NONE,
1453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001454 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"iconstring", NULL, P_STRING|P_VI_DEF,
1456#ifdef FEAT_TITLE
1457 (char_u *)&p_iconstring, PV_NONE,
1458#else
1459 (char_u *)NULL, PV_NONE,
1460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1463 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001465 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1466# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1467 (char_u *)&p_imaf, PV_NONE,
1468 {(char_u *)"", (char_u *)NULL}
1469# else
1470 (char_u *)NULL, PV_NONE,
1471 {(char_u *)NULL, (char_u *)0L}
1472# endif
1473 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001475#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 (char_u *)&p_imak, PV_NONE,
1477#else
1478 (char_u *)NULL, PV_NONE,
1479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1482#ifdef USE_IM_CONTROL
1483 (char_u *)&p_imcmdline, PV_NONE,
1484#else
1485 (char_u *)NULL, PV_NONE,
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1489#ifdef USE_IM_CONTROL
1490 (char_u *)&p_imdisable, PV_NONE,
1491#else
1492 (char_u *)NULL, PV_NONE,
1493#endif
1494#ifdef __sgi
1495 {(char_u *)TRUE, (char_u *)0L}
1496#else
1497 {(char_u *)FALSE, (char_u *)0L}
1498#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"iminsert", "imi", P_NUM|P_VI_DEF,
1501 (char_u *)&p_iminsert, PV_IMI,
1502#ifdef B_IMODE_IM
1503 {(char_u *)B_IMODE_IM, (char_u *)0L}
1504#else
1505 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001507 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"imsearch", "ims", P_NUM|P_VI_DEF,
1509 (char_u *)&p_imsearch, PV_IMS,
1510#ifdef B_IMODE_IM
1511 {(char_u *)B_IMODE_IM, (char_u *)0L}
1512#else
1513 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001516 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001517# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1518 (char_u *)&p_imsf, PV_NONE,
1519 {(char_u *)"", (char_u *)NULL}
1520# else
1521 (char_u *)NULL, PV_NONE,
1522 {(char_u *)NULL, (char_u *)0L}
1523# endif
1524 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1526#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001527 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1529#else
1530 (char_u *)NULL, PV_NONE,
1531 {(char_u *)0L, (char_u *)0L}
1532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001533 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001534 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1535#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1536 (char_u *)&p_inex, PV_INEX,
1537 {(char_u *)"", (char_u *)0L}
1538#else
1539 (char_u *)NULL, PV_NONE,
1540 {(char_u *)0L, (char_u *)0L}
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1544 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1547#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1548 (char_u *)&p_inde, PV_INDE,
1549 {(char_u *)"", (char_u *)0L}
1550#else
1551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)0L, (char_u *)0L}
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001555 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001556#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1557 (char_u *)&p_indk, PV_INDK,
1558 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1559#else
1560 (char_u *)NULL, PV_NONE,
1561 {(char_u *)0L, (char_u *)0L}
1562#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"infercase", "inf", P_BOOL|P_VI_DEF,
1565 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1568 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1571 (char_u *)&p_isf, PV_NONE,
1572 {
1573#ifdef BACKSLASH_IN_FILENAME
1574 /* Excluded are: & and ^ are special in cmd.exe
1575 * ( and ) are used in text separating fnames */
1576 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1577#else
1578# ifdef AMIGA
1579 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1580# else
1581# ifdef VMS
1582 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1583# else /* UNIX et al. */
1584# ifdef EBCDIC
1585 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1586# else
1587 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1588# endif
1589# endif
1590# endif
1591#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001592 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1594 (char_u *)&p_isi, PV_NONE,
1595 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001596#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001597 (char_u *)"@,48-57,_,128-167,224-235",
1598#else
1599# ifdef EBCDIC
1600 /* TODO: EBCDIC Check this! @ == isalpha()*/
1601 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1602 "112-120,128,140-142,156,158,172,"
1603 "174,186,191,203-207,219-225,235-239,"
1604 "251-254",
1605# else
1606 (char_u *)"@,48-57,_,192-255",
1607# endif
1608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001609 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001610 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1611 (char_u *)&p_isk, PV_ISK,
1612 {
1613#ifdef EBCDIC
1614 (char_u *)"@,240-249,_",
1615 /* TODO: EBCDIC Check this! @ == isalpha()*/
1616 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1617 "112-120,128,140-142,156,158,172,"
1618 "174,186,191,203-207,219-225,235-239,"
1619 "251-254",
1620#else
1621 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001622# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 (char_u *)"@,48-57,_,128-167,224-235"
1624# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001625 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626# endif
1627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001628 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1630 (char_u *)&p_isp, PV_NONE,
1631 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001632#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633 || defined(VMS)
1634 (char_u *)"@,~-255",
1635#else
1636# ifdef EBCDIC
1637 /* all chars above 63 are printable */
1638 (char_u *)"63-255",
1639# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001640 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641# endif
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1645 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1648#ifdef FEAT_CRYPT
1649 (char_u *)&p_key, PV_KEY,
1650 {(char_u *)"", (char_u *)0L}
1651#else
1652 (char_u *)NULL, PV_NONE,
1653 {(char_u *)0L, (char_u *)0L}
1654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001656 {"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 +00001657#ifdef FEAT_KEYMAP
1658 (char_u *)&p_keymap, PV_KMAP,
1659 {(char_u *)"", (char_u *)0L}
1660#else
1661 (char_u *)NULL, PV_NONE,
1662 {(char_u *)"", (char_u *)0L}
1663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001665 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001669 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001671#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 (char_u *)":help",
1673#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001674# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001676# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001677# ifdef USEMAN_S
1678 (char_u *)"man -s",
1679# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001680 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001681# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682# endif
1683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001684 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001685 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686#ifdef FEAT_LANGMAP
1687 (char_u *)&p_langmap, PV_NONE,
1688 {(char_u *)"", /* unmatched } */
1689#else
1690 (char_u *)NULL, PV_NONE,
1691 {(char_u *)NULL,
1692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001693 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001694 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1696 (char_u *)&p_lm, PV_NONE,
1697#else
1698 (char_u *)NULL, PV_NONE,
1699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001700 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001701 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1702#ifdef FEAT_LANGMAP
1703 (char_u *)&p_lnr, PV_NONE,
1704#else
1705 (char_u *)NULL, PV_NONE,
1706#endif
1707 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1709#ifdef FEAT_WINDOWS
1710 (char_u *)&p_ls, PV_NONE,
1711#else
1712 (char_u *)NULL, PV_NONE,
1713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1716 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001717 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1719#ifdef FEAT_LINEBREAK
1720 (char_u *)VAR_WIN, PV_LBR,
1721#else
1722 (char_u *)NULL, PV_NONE,
1723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1726 (char_u *)&Rows, PV_NONE,
1727 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001728#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 (char_u *)25L,
1730#else
1731 (char_u *)24L,
1732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001733 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1735#ifdef FEAT_GUI
1736 (char_u *)&p_linespace, PV_NONE,
1737#else
1738 (char_u *)NULL, PV_NONE,
1739#endif
1740#ifdef FEAT_GUI_W32
1741 {(char_u *)1L, (char_u *)0L}
1742#else
1743 {(char_u *)0L, (char_u *)0L}
1744#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"lisp", NULL, P_BOOL|P_VI_DEF,
1747#ifdef FEAT_LISP
1748 (char_u *)&p_lisp, PV_LISP,
1749#else
1750 (char_u *)NULL, PV_NONE,
1751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001753 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001755 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1757#else
1758 (char_u *)NULL, PV_NONE,
1759 {(char_u *)"", (char_u *)0L}
1760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001761 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1763 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001765 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1769 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001771#if defined(DYNAMIC_LUA)
Bram Moolenaara6e42502016-04-20 16:19:52 +02001772 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001773 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001774 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1775 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001776#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001777#ifdef FEAT_GUI_MAC
1778 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1779 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001781#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {"magic", NULL, P_BOOL|P_VI_DEF,
1783 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001785 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786#ifdef FEAT_QUICKFIX
1787 (char_u *)&p_mef, PV_NONE,
1788 {(char_u *)"", (char_u *)0L}
1789#else
1790 (char_u *)NULL, PV_NONE,
1791 {(char_u *)NULL, (char_u *)0L}
1792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1795#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001796 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797# ifdef VMS
1798 {(char_u *)"MMS", (char_u *)0L}
1799# else
1800 {(char_u *)"make", (char_u *)0L}
1801# endif
1802#else
1803 (char_u *)NULL, PV_NONE,
1804 {(char_u *)NULL, (char_u *)0L}
1805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001806 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001807 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001809 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1810 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {"matchtime", "mat", P_NUM|P_VI_DEF,
1812 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001814 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001815#ifdef FEAT_MBYTE
1816 (char_u *)&p_mco, PV_NONE,
1817#else
1818 (char_u *)NULL, PV_NONE,
1819#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1822#ifdef FEAT_EVAL
1823 (char_u *)&p_mfd, PV_NONE,
1824#else
1825 (char_u *)NULL, PV_NONE,
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1829 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 {"maxmem", "mm", P_NUM|P_VI_DEF,
1832 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001833 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1834 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001835 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001838 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1839 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1841 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"menuitems", "mis", P_NUM|P_VI_DEF,
1843#ifdef FEAT_MENU
1844 (char_u *)&p_mis, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"mesg", NULL, P_BOOL|P_VI_DEF,
1850 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001852 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001853#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001854 (char_u *)&p_msm, PV_NONE,
1855 {(char_u *)"460000,2000,500", (char_u *)0L}
1856#else
1857 (char_u *)NULL, PV_NONE,
1858 {(char_u *)0L, (char_u *)0L}
1859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"modeline", "ml", P_BOOL|P_VIM,
1862 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"modelines", "mls", P_NUM|P_VI_DEF,
1865 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1868 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1871 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"more", NULL, P_BOOL|P_VIM,
1874 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1877 (char_u *)&p_mouse, PV_NONE,
1878 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001879#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 (char_u *)"a",
1881#else
1882 (char_u *)"",
1883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001884 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1886#ifdef FEAT_GUI
1887 (char_u *)&p_mousef, PV_NONE,
1888#else
1889 (char_u *)NULL, PV_NONE,
1890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1893#ifdef FEAT_GUI
1894 (char_u *)&p_mh, PV_NONE,
1895#else
1896 (char_u *)NULL, PV_NONE,
1897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1900 (char_u *)&p_mousem, PV_NONE,
1901 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001902#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 (char_u *)"popup",
1904#else
1905# if defined(MACOS)
1906 (char_u *)"popup_setpos",
1907# else
1908 (char_u *)"extend",
1909# endif
1910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001912 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913#ifdef FEAT_MOUSESHAPE
1914 (char_u *)&p_mouseshape, PV_NONE,
1915 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1916#else
1917 (char_u *)NULL, PV_NONE,
1918 {(char_u *)NULL, (char_u *)0L}
1919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1922 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001923 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001924 {"mzquantum", "mzq", P_NUM,
1925#ifdef FEAT_MZSCHEME
1926 (char_u *)&p_mzq, PV_NONE,
1927#else
1928 (char_u *)NULL, PV_NONE,
1929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"novice", NULL, P_BOOL|P_VI_DEF,
1932 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001933 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001934 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001936 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1939 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001941 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1942#ifdef FEAT_LINEBREAK
1943 (char_u *)VAR_WIN, PV_NUW,
1944#else
1945 (char_u *)NULL, PV_NONE,
1946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001948 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001949#ifdef FEAT_COMPL_FUNC
1950 (char_u *)&p_ofu, PV_OFU,
1951 {(char_u *)"", (char_u *)0L}
1952#else
1953 (char_u *)NULL, PV_NONE,
1954 {(char_u *)0L, (char_u *)0L}
1955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 {"open", NULL, P_BOOL|P_VI_DEF,
1958 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001960 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001961#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001962 (char_u *)&p_odev, PV_NONE,
1963#else
1964 (char_u *)NULL, PV_NONE,
1965#endif
1966 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001968 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1969 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"optimize", "opt", P_BOOL|P_VI_DEF,
1972 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001973 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001976 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001977 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1978 |P_SECURE,
1979 (char_u *)&p_pp, PV_NONE,
1980 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
1981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"paragraphs", "para", P_STRING|P_VI_DEF,
1983 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001984 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001986 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1990 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1993#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1994 (char_u *)&p_pex, PV_NONE,
1995 {(char_u *)"", (char_u *)0L}
1996#else
1997 (char_u *)NULL, PV_NONE,
1998 {(char_u *)0L, (char_u *)0L}
1999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002001 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002003 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002005 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002007#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 (char_u *)".,,",
2009#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002013#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002014 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002015 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002016 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2017 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002018#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002019 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2020 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002022 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2024 (char_u *)&p_pvh, PV_NONE,
2025#else
2026 (char_u *)NULL, PV_NONE,
2027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002028 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2030#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2031 (char_u *)VAR_WIN, PV_PVW,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002036 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037#ifdef FEAT_PRINTER
2038 (char_u *)&p_pdev, PV_NONE,
2039 {(char_u *)"", (char_u *)0L}
2040#else
2041 (char_u *)NULL, PV_NONE,
2042 {(char_u *)NULL, (char_u *)0L}
2043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 {"printencoding", "penc", P_STRING|P_VI_DEF,
2046#ifdef FEAT_POSTSCRIPT
2047 (char_u *)&p_penc, PV_NONE,
2048 {(char_u *)"", (char_u *)0L}
2049#else
2050 (char_u *)NULL, PV_NONE,
2051 {(char_u *)NULL, (char_u *)0L}
2052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2055#ifdef FEAT_POSTSCRIPT
2056 (char_u *)&p_pexpr, PV_NONE,
2057 {(char_u *)"", (char_u *)0L}
2058#else
2059 (char_u *)NULL, PV_NONE,
2060 {(char_u *)NULL, (char_u *)0L}
2061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002063 {"printfont", "pfn", P_STRING|P_VI_DEF,
2064#ifdef FEAT_PRINTER
2065 (char_u *)&p_pfn, PV_NONE,
2066 {
2067# ifdef MSWIN
2068 (char_u *)"Courier_New:h10",
2069# else
2070 (char_u *)"courier",
2071# endif
2072 (char_u *)0L}
2073#else
2074 (char_u *)NULL, PV_NONE,
2075 {(char_u *)NULL, (char_u *)0L}
2076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2079#ifdef FEAT_PRINTER
2080 (char_u *)&p_header, PV_NONE,
2081 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2082#else
2083 (char_u *)NULL, PV_NONE,
2084 {(char_u *)NULL, (char_u *)0L}
2085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002087 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2088#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2089 (char_u *)&p_pmcs, PV_NONE,
2090 {(char_u *)"", (char_u *)0L}
2091#else
2092 (char_u *)NULL, PV_NONE,
2093 {(char_u *)NULL, (char_u *)0L}
2094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002096 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2097#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2098 (char_u *)&p_pmfn, PV_NONE,
2099 {(char_u *)"", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)NULL, (char_u *)0L}
2103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002105 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106#ifdef FEAT_PRINTER
2107 (char_u *)&p_popt, PV_NONE,
2108 {(char_u *)"", (char_u *)0L}
2109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)NULL, (char_u *)0L}
2112#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002115 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002117 {"pumheight", "ph", P_NUM|P_VI_DEF,
2118#ifdef FEAT_INS_EXPAND
2119 (char_u *)&p_ph, PV_NONE,
2120#else
2121 (char_u *)NULL, PV_NONE,
2122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002124#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002125 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002126 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002127 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2128 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002129#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002130#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002131 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002132 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002133 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2134 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002135#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002136 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2137#ifdef FEAT_TEXTOBJ
2138 (char_u *)&p_qe, PV_QE,
2139 {(char_u *)"\\", (char_u *)0L}
2140#else
2141 (char_u *)NULL, PV_NONE,
2142 {(char_u *)NULL, (char_u *)0L}
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2146 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002147 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 {"redraw", NULL, P_BOOL|P_VI_DEF,
2149 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002150 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002151 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2152#ifdef FEAT_RELTIME
2153 (char_u *)&p_rdt, PV_NONE,
2154#else
2155 (char_u *)NULL, PV_NONE,
2156#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002158 {"regexpengine", "re", P_NUM|P_VI_DEF,
2159 (char_u *)&p_re, PV_NONE,
2160 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002161 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2162 (char_u *)VAR_WIN, PV_RNU,
2163 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164 {"remap", NULL, P_BOOL|P_VI_DEF,
2165 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002166 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002167 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002168#ifdef FEAT_RENDER_OPTIONS
2169 (char_u *)&p_rop, PV_NONE,
2170 {(char_u *)"", (char_u *)0L}
2171#else
2172 (char_u *)NULL, PV_NONE,
2173 {(char_u *)NULL, (char_u *)0L}
2174#endif
2175 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 {"report", NULL, P_NUM|P_VI_DEF,
2177 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2180#ifdef WIN3264
2181 (char_u *)&p_rs, PV_NONE,
2182#else
2183 (char_u *)NULL, PV_NONE,
2184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2187#ifdef FEAT_RIGHTLEFT
2188 (char_u *)&p_ri, PV_NONE,
2189#else
2190 (char_u *)NULL, PV_NONE,
2191#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2194#ifdef FEAT_RIGHTLEFT
2195 (char_u *)VAR_WIN, PV_RL,
2196#else
2197 (char_u *)NULL, PV_NONE,
2198#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002199 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2201#ifdef FEAT_RIGHTLEFT
2202 (char_u *)VAR_WIN, PV_RLC,
2203 {(char_u *)"search", (char_u *)NULL}
2204#else
2205 (char_u *)NULL, PV_NONE,
2206 {(char_u *)NULL, (char_u *)0L}
2207#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002208 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002209#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002210 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002211 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002212 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2213 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002214#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2216#ifdef FEAT_CMDL_INFO
2217 (char_u *)&p_ru, PV_NONE,
2218#else
2219 (char_u *)NULL, PV_NONE,
2220#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2223#ifdef FEAT_STL_OPT
2224 (char_u *)&p_ruf, PV_NONE,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002229 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2230 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002232 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2233 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2235 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2238#ifdef FEAT_SCROLLBIND
2239 (char_u *)VAR_WIN, PV_SCBIND,
2240#else
2241 (char_u *)NULL, PV_NONE,
2242#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2245 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2248 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002249 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002250 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251#ifdef FEAT_SCROLLBIND
2252 (char_u *)&p_sbo, PV_NONE,
2253 {(char_u *)"ver,jump", (char_u *)0L}
2254#else
2255 (char_u *)NULL, PV_NONE,
2256 {(char_u *)0L, (char_u *)0L}
2257#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002258 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002259 {"sections", "sect", P_STRING|P_VI_DEF,
2260 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002261 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2262 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2264 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)"inclusive", (char_u *)0L}
2269 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002270 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002273 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274#ifdef FEAT_SESSION
2275 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002276 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 (char_u *)0L}
2278#else
2279 (char_u *)NULL, PV_NONE,
2280 {(char_u *)0L, (char_u *)0L}
2281#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2284 (char_u *)&p_sh, PV_NONE,
2285 {
2286#ifdef VMS
2287 (char_u *)"-",
2288#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002289# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002291# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293# endif
2294#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2297 (char_u *)&p_shcf, PV_NONE,
2298 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002299#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 (char_u *)"/c",
2301#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2306#ifdef FEAT_QUICKFIX
2307 (char_u *)&p_sp, PV_NONE,
2308 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002309#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311#else
2312 (char_u *)">",
2313#endif
2314 (char_u *)0L}
2315#else
2316 (char_u *)NULL, PV_NONE,
2317 {(char_u *)0L, (char_u *)0L}
2318#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2321 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2324 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002325 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2327#ifdef BACKSLASH_IN_FILENAME
2328 (char_u *)&p_ssl, PV_NONE,
2329#else
2330 (char_u *)NULL, PV_NONE,
2331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002333 {"shelltemp", "stmp", P_BOOL,
2334 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"shelltype", "st", P_NUM|P_VI_DEF,
2337#ifdef AMIGA
2338 (char_u *)&p_st, PV_NONE,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2344 (char_u *)&p_sxq, PV_NONE,
2345 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002346#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 (char_u *)"\"",
2348#else
2349 (char_u *)"",
2350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002352 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2353 (char_u *)&p_sxe, PV_NONE,
2354 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002355#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002356 (char_u *)"\"&|<>()@^",
2357#else
2358 (char_u *)"",
2359#endif
2360 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2362 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2365 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2368 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)"", (char_u *)"filnxtToO"}
2370 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2375#ifdef FEAT_LINEBREAK
2376 (char_u *)&p_sbr, PV_NONE,
2377#else
2378 (char_u *)NULL, PV_NONE,
2379#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"showcmd", "sc", P_BOOL|P_VIM,
2382#ifdef FEAT_CMDL_INFO
2383 (char_u *)&p_sc, PV_NONE,
2384#else
2385 (char_u *)NULL, PV_NONE,
2386#endif
2387 {(char_u *)FALSE,
2388#ifdef UNIX
2389 (char_u *)FALSE
2390#else
2391 (char_u *)TRUE
2392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2395 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2398 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"showmode", "smd", P_BOOL|P_VIM,
2401 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002403 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2404#ifdef FEAT_WINDOWS
2405 (char_u *)&p_stal, PV_NONE,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2411 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2414 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002416 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2417#ifdef FEAT_SIGNS
2418 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002419 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002420#else
2421 (char_u *)NULL, PV_NONE,
2422 {(char_u *)NULL, (char_u *)0L}
2423#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002424 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2426 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002427 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2429 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2432#ifdef FEAT_SMARTINDENT
2433 (char_u *)&p_si, PV_SI,
2434#else
2435 (char_u *)NULL, PV_NONE,
2436#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2439 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002440 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2442 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002443 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2445 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002446 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002447 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002448#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002449 (char_u *)VAR_WIN, PV_SPELL,
2450#else
2451 (char_u *)NULL, PV_NONE,
2452#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002454 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002455#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002456 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002457 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002458#else
2459 (char_u *)NULL, PV_NONE,
2460 {(char_u *)0L, (char_u *)0L}
2461#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002462 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002463 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2464 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002465#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002466 (char_u *)&p_spf, PV_SPF,
2467 {(char_u *)"", (char_u *)0L}
2468#else
2469 (char_u *)NULL, PV_NONE,
2470 {(char_u *)0L, (char_u *)0L}
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002473 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2474 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002475#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002476 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002477 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002478#else
2479 (char_u *)NULL, PV_NONE,
2480 {(char_u *)0L, (char_u *)0L}
2481#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002483 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002484#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002485 (char_u *)&p_sps, PV_NONE,
2486 {(char_u *)"best", (char_u *)0L}
2487#else
2488 (char_u *)NULL, PV_NONE,
2489 {(char_u *)0L, (char_u *)0L}
2490#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002491 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2493#ifdef FEAT_WINDOWS
2494 (char_u *)&p_sb, PV_NONE,
2495#else
2496 (char_u *)NULL, PV_NONE,
2497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002500#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 (char_u *)&p_spr, PV_NONE,
2502#else
2503 (char_u *)NULL, PV_NONE,
2504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2507 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2510#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002511 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512#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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002516 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 (char_u *)&p_su, PV_NONE,
2518 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002520 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002521#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 (char_u *)&p_sua, PV_SUA,
2523 {(char_u *)"", (char_u *)0L}
2524#else
2525 (char_u *)NULL, PV_NONE,
2526 {(char_u *)0L, (char_u *)0L}
2527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2530 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"swapsync", "sws", P_STRING|P_VI_DEF,
2533 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002535 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002538 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2539#ifdef FEAT_SYN_HL
2540 (char_u *)&p_smc, PV_SMC,
2541 {(char_u *)3000L, (char_u *)0L}
2542#else
2543 (char_u *)NULL, PV_NONE,
2544 {(char_u *)0L, (char_u *)0L}
2545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002547 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548#ifdef FEAT_SYN_HL
2549 (char_u *)&p_syn, PV_SYN,
2550 {(char_u *)"", (char_u *)0L}
2551#else
2552 (char_u *)NULL, PV_NONE,
2553 {(char_u *)0L, (char_u *)0L}
2554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002556 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2557#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002558 (char_u *)&p_tal, PV_NONE,
2559#else
2560 (char_u *)NULL, PV_NONE,
2561#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002563 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2564#ifdef FEAT_WINDOWS
2565 (char_u *)&p_tpm, PV_NONE,
2566#else
2567 (char_u *)NULL, PV_NONE,
2568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2571 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2574 (char_u *)&p_tbs, PV_NONE,
2575#ifdef VMS /* binary searching doesn't appear to work on VMS */
2576 {(char_u *)0L, (char_u *)0L}
2577#else
2578 {(char_u *)TRUE, (char_u *)0L}
2579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002580 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002581 {"tagcase", "tc", P_STRING|P_VIM,
2582 (char_u *)&p_tc, PV_TC,
2583 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {"taglength", "tl", P_NUM|P_VI_DEF,
2585 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"tagrelative", "tr", P_BOOL|P_VIM,
2588 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002590 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002591 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {
2593#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2594 (char_u *)"./tags,./TAGS,tags,TAGS",
2595#else
2596 (char_u *)"./tags,tags",
2597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2600 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002602#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002603 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002604 (char_u *)&p_tcldll, PV_NONE,
2605 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2606 SCRIPTID_INIT},
2607#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2609 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002610 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2612#ifdef FEAT_ARABIC
2613 (char_u *)&p_tbidi, PV_NONE,
2614#else
2615 (char_u *)NULL, PV_NONE,
2616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2619#ifdef FEAT_MBYTE
2620 (char_u *)&p_tenc, PV_NONE,
2621 {(char_u *)"", (char_u *)0L}
2622#else
2623 (char_u *)NULL, PV_NONE,
2624 {(char_u *)0L, (char_u *)0L}
2625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002627 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2628#ifdef FEAT_TERMGUICOLORS
2629 (char_u *)&p_tgc, PV_NONE,
2630 {(char_u *)FALSE, (char_u *)FALSE}
2631#else
2632 (char_u*)NULL, PV_NONE,
2633 {(char_u *)FALSE, (char_u *)FALSE}
2634#endif
2635 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 {"terse", NULL, P_BOOL|P_VI_DEF,
2637 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002638 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 {"textauto", "ta", P_BOOL|P_VIM,
2640 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002641 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2642 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2644 (char_u *)&p_tx, PV_TX,
2645 {
2646#ifdef USE_CRNL
2647 (char_u *)TRUE,
2648#else
2649 (char_u *)FALSE,
2650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002652 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002655 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002657 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658#else
2659 (char_u *)NULL, PV_NONE,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2663 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"timeout", "to", P_BOOL|P_VI_DEF,
2666 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2669 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 {"title", NULL, P_BOOL|P_VI_DEF,
2672#ifdef FEAT_TITLE
2673 (char_u *)&p_title, PV_NONE,
2674#else
2675 (char_u *)NULL, PV_NONE,
2676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"titlelen", NULL, P_NUM|P_VI_DEF,
2679#ifdef FEAT_TITLE
2680 (char_u *)&p_titlelen, PV_NONE,
2681#else
2682 (char_u *)NULL, PV_NONE,
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002685 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686#ifdef FEAT_TITLE
2687 (char_u *)&p_titleold, PV_NONE,
2688 {(char_u *)N_("Thanks for flying Vim"),
2689 (char_u *)0L}
2690#else
2691 (char_u *)NULL, PV_NONE,
2692 {(char_u *)0L, (char_u *)0L}
2693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695 {"titlestring", NULL, P_STRING|P_VI_DEF,
2696#ifdef FEAT_TITLE
2697 (char_u *)&p_titlestring, PV_NONE,
2698#else
2699 (char_u *)NULL, PV_NONE,
2700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002703 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002705 {(char_u *)"icons,tooltips", (char_u *)0L}
2706 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002708#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2710 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712#endif
2713 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2714 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2717 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2720 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2723 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2726#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2727 (char_u *)&p_ttym, PV_NONE,
2728#else
2729 (char_u *)NULL, PV_NONE,
2730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2733 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002735 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2736 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002737 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002738 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2739 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002740#ifdef FEAT_PERSISTENT_UNDO
2741 (char_u *)&p_udir, PV_NONE,
2742 {(char_u *)".", (char_u *)0L}
2743#else
2744 (char_u *)NULL, PV_NONE,
2745 {(char_u *)0L, (char_u *)0L}
2746#endif
2747 SCRIPTID_INIT},
2748 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2749#ifdef FEAT_PERSISTENT_UNDO
2750 (char_u *)&p_udf, PV_UDF,
2751#else
2752 (char_u *)NULL, PV_NONE,
2753#endif
2754 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002756 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002758#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 (char_u *)1000L,
2760#else
2761 (char_u *)100L,
2762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002763 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002764 {"undoreload", "ur", P_NUM|P_VI_DEF,
2765 (char_u *)&p_ur, PV_NONE,
2766 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"updatecount", "uc", P_NUM|P_VI_DEF,
2768 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002769 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 {"updatetime", "ut", P_NUM|P_VI_DEF,
2771 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002772 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773 {"verbose", "vbs", P_NUM|P_VI_DEF,
2774 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002776 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2777 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2780#ifdef FEAT_SESSION
2781 (char_u *)&p_vdir, PV_NONE,
2782 {(char_u *)DFLT_VDIR, (char_u *)0L}
2783#else
2784 (char_u *)NULL, PV_NONE,
2785 {(char_u *)0L, (char_u *)0L}
2786#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002787 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002788 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789#ifdef FEAT_SESSION
2790 (char_u *)&p_vop, PV_NONE,
2791 {(char_u *)"folds,options,cursor", (char_u *)0L}
2792#else
2793 (char_u *)NULL, PV_NONE,
2794 {(char_u *)0L, (char_u *)0L}
2795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002797 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798#ifdef FEAT_VIMINFO
2799 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002800#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002801 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802#else
2803# ifdef AMIGA
2804 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002805 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002807 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808# endif
2809#endif
2810#else
2811 (char_u *)NULL, PV_NONE,
2812 {(char_u *)0L, (char_u *)0L}
2813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002814 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002815 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2816 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817#ifdef FEAT_VIRTUALEDIT
2818 (char_u *)&p_ve, PV_NONE,
2819 {(char_u *)"", (char_u *)""}
2820#else
2821 (char_u *)NULL, PV_NONE,
2822 {(char_u *)0L, (char_u *)0L}
2823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2826 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002827 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 {"w300", NULL, P_NUM|P_VI_DEF,
2829 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002830 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 {"w1200", NULL, P_NUM|P_VI_DEF,
2832 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"w9600", NULL, P_NUM|P_VI_DEF,
2835 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"warn", NULL, P_BOOL|P_VI_DEF,
2838 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2841 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002843 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"wildchar", "wc", P_NUM|P_VIM,
2847 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2849 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002850 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002853 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854#ifdef FEAT_WILDIGN
2855 (char_u *)&p_wig, PV_NONE,
2856#else
2857 (char_u *)NULL, PV_NONE,
2858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002860 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2861 (char_u *)&p_wic, PV_NONE,
2862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2864#ifdef FEAT_WILDMENU
2865 (char_u *)&p_wmnu, PV_NONE,
2866#else
2867 (char_u *)NULL, PV_NONE,
2868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002870 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002873 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2874#ifdef FEAT_CMDL_COMPL
2875 (char_u *)&p_wop, PV_NONE,
2876 {(char_u *)"", (char_u *)0L}
2877#else
2878 (char_u *)NULL, PV_NONE,
2879 {(char_u *)NULL, (char_u *)0L}
2880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2883#ifdef FEAT_WAK
2884 (char_u *)&p_wak, PV_NONE,
2885 {(char_u *)"menu", (char_u *)0L}
2886#else
2887 (char_u *)NULL, PV_NONE,
2888 {(char_u *)NULL, (char_u *)0L}
2889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002892 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"winheight", "wh", P_NUM|P_VI_DEF,
2895#ifdef FEAT_WINDOWS
2896 (char_u *)&p_wh, PV_NONE,
2897#else
2898 (char_u *)NULL, PV_NONE,
2899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002902#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903 (char_u *)VAR_WIN, PV_WFH,
2904#else
2905 (char_u *)NULL, PV_NONE,
2906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002907 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002908 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002909#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002910 (char_u *)VAR_WIN, PV_WFW,
2911#else
2912 (char_u *)NULL, PV_NONE,
2913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2916#ifdef FEAT_WINDOWS
2917 (char_u *)&p_wmh, PV_NONE,
2918#else
2919 (char_u *)NULL, PV_NONE,
2920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002923#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 (char_u *)&p_wmw, PV_NONE,
2925#else
2926 (char_u *)NULL, PV_NONE,
2927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002928 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002930#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 (char_u *)&p_wiw, PV_NONE,
2932#else
2933 (char_u *)NULL, PV_NONE,
2934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2937 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2940 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002941 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2943 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002944 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945 {"write", NULL, P_BOOL|P_VI_DEF,
2946 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 {"writeany", "wa", P_BOOL|P_VI_DEF,
2949 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2952 (char_u *)&p_wb, PV_NONE,
2953 {
2954#ifdef FEAT_WRITEBACKUP
2955 (char_u *)TRUE,
2956#else
2957 (char_u *)FALSE,
2958#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002959 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 {"writedelay", "wd", P_NUM|P_VI_DEF,
2961 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002962 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963
2964/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002965#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002967 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968
2969 p_term("t_AB", T_CAB)
2970 p_term("t_AF", T_CAF)
2971 p_term("t_AL", T_CAL)
2972 p_term("t_al", T_AL)
2973 p_term("t_bc", T_BC)
2974 p_term("t_cd", T_CD)
2975 p_term("t_ce", T_CE)
2976 p_term("t_cl", T_CL)
2977 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002978 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 p_term("t_Co", T_CCO)
2980 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002981 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002983#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984 p_term("t_CV", T_CSV)
2985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 p_term("t_da", T_DA)
2987 p_term("t_db", T_DB)
2988 p_term("t_DL", T_CDL)
2989 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002990 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 p_term("t_fs", T_FS)
2992 p_term("t_IE", T_CIE)
2993 p_term("t_IS", T_CIS)
2994 p_term("t_ke", T_KE)
2995 p_term("t_ks", T_KS)
2996 p_term("t_le", T_LE)
2997 p_term("t_mb", T_MB)
2998 p_term("t_md", T_MD)
2999 p_term("t_me", T_ME)
3000 p_term("t_mr", T_MR)
3001 p_term("t_ms", T_MS)
3002 p_term("t_nd", T_ND)
3003 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003004 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 p_term("t_RI", T_CRI)
3006 p_term("t_RV", T_CRV)
3007 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003009 p_term("t_Sf", T_CSF)
3010 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003012 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 p_term("t_te", T_TE)
3015 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003016 p_term("t_ts", T_TS)
3017 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 p_term("t_ue", T_UE)
3019 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003020 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 p_term("t_vb", T_VB)
3022 p_term("t_ve", T_VE)
3023 p_term("t_vi", T_VI)
3024 p_term("t_vs", T_VS)
3025 p_term("t_WP", T_CWP)
3026 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003027 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 p_term("t_xs", T_XS)
3029 p_term("t_ZH", T_CZH)
3030 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003031 p_term("t_8f", T_8F)
3032 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033
3034/* terminal key codes are not in here */
3035
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003036 /* end marker */
3037 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038};
3039
3040#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3041
3042#ifdef FEAT_MBYTE
3043static char *(p_ambw_values[]) = {"single", "double", NULL};
3044#endif
3045static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003046static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003048#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003049static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003050#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003051#ifdef FEAT_CMDL_COMPL
3052static char *(p_wop_values[]) = {"tagfile", NULL};
3053#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054#ifdef FEAT_WAK
3055static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3056#endif
3057static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3059static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061#ifdef FEAT_BROWSE
3062static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3063#endif
3064#ifdef FEAT_SCROLLBIND
3065static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3066#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003067static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003068#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3070#endif
3071#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003072# ifdef FEAT_AUTOCMD
3073static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3074# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003076# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3078#endif
3079static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3080#ifdef FEAT_FOLDING
3081static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003082# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003084# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 NULL};
3086static char *(p_fcl_values[]) = {"all", NULL};
3087#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003088#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003089static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003090#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003091#ifdef FEAT_SIGNS
3092static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3093#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003095static void set_option_default(int, int opt_flags, int compatible);
3096static void set_options_default(int opt_flags);
3097static char_u *term_bg_default(void);
3098static void did_set_option(int opt_idx, int opt_flags, int new_value);
3099static char_u *illegal_char(char_u *, int);
3100static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003102static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103#endif
3104#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003105static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003107static char_u *option_expand(int opt_idx, char_u *val);
3108static void didset_options(void);
3109static void didset_options2(void);
3110static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003111#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003112static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003113#else
3114# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3115#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003116static void set_string_option_global(int opt_idx, char_u **varp);
3117static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3118static 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);
3119static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003120#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003121static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003122#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003124static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003126#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003127static char_u *did_set_spell_option(int is_spellfile);
3128static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003129#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003130#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003131static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003132#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003133static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3134static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3135static void check_redraw(long_u flags);
3136static int findoption(char_u *);
3137static int find_key_option(char_u *);
3138static void showoptions(int all, int opt_flags);
3139static int optval_default(struct vimoption *, char_u *varp);
3140static void showoneopt(struct vimoption *, int opt_flags);
3141static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3142static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3143static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3144static int istermoption(struct vimoption *);
3145static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3146static char_u *get_varp(struct vimoption *);
3147static void option_value2string(struct vimoption *, int opt_flags);
3148static void check_winopt(winopt_T *wop);
3149static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003151static void langmap_init(void);
3152static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003154static void paste_option_changed(void);
3155static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003157static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003159static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3160static int check_opt_strings(char_u *val, char **values, int);
3161static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003162#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003163static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003164#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165
3166/*
3167 * Initialize the options, first part.
3168 *
3169 * Called only once from main(), just after creating the first buffer.
3170 */
3171 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003172set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173{
3174 char_u *p;
3175 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003176 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177
3178#ifdef FEAT_LANGMAP
3179 langmap_init();
3180#endif
3181
3182 /* Be Vi compatible by default */
3183 p_cp = TRUE;
3184
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003185 /* Use POSIX compatibility when $VIM_POSIX is set. */
3186 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003187 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003188 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003189 set_string_default("shm", (char_u *)"A");
3190 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003191
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192 /*
3193 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003194 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003196 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003197#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003198 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003200 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201# endif
3202#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003203 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204 set_string_default("sh", p);
3205
3206#ifdef FEAT_WILDIGN
3207 /*
3208 * Set the default for 'backupskip' to include environment variables for
3209 * temp files.
3210 */
3211 {
3212# ifdef UNIX
3213 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3214# else
3215 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3216# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003217 int len;
3218 garray_T ga;
3219 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220
3221 ga_init2(&ga, 1, 100);
3222 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3223 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003224 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225# ifdef UNIX
3226 if (*names[n] == NUL)
3227 p = (char_u *)"/tmp";
3228 else
3229# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003230 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231 if (p != NULL && *p != NUL)
3232 {
3233 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003234 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235 if (ga_grow(&ga, len) == OK)
3236 {
3237 if (ga.ga_len > 0)
3238 STRCAT(ga.ga_data, ",");
3239 STRCAT(ga.ga_data, p);
3240 add_pathsep(ga.ga_data);
3241 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242 ga.ga_len += len;
3243 }
3244 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003245 if (mustfree)
3246 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247 }
3248 if (ga.ga_data != NULL)
3249 {
3250 set_string_default("bsk", ga.ga_data);
3251 vim_free(ga.ga_data);
3252 }
3253 }
3254#endif
3255
3256 /*
3257 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3258 */
3259 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003260 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003262#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3263 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3264#endif
3265 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003267 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003268 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269#else
3270# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003271 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003272 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003274 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275# endif
3276#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003278 opt_idx = findoption((char_u *)"maxmem");
3279 if (opt_idx >= 0)
3280 {
3281#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003282 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3283 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003284#endif
3285 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3286 }
3287 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288 }
3289
3290#ifdef FEAT_GUI_W32
3291 /* force 'shortname' for Win32s */
3292 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003293 {
3294 opt_idx = findoption((char_u *)"shortname");
3295 if (opt_idx >= 0)
3296 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3297 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298#endif
3299
3300#ifdef FEAT_SEARCHPATH
3301 {
3302 char_u *cdpath;
3303 char_u *buf;
3304 int i;
3305 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003306 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307
3308 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003309 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 if (cdpath != NULL)
3311 {
3312 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3313 if (buf != NULL)
3314 {
3315 buf[0] = ','; /* start with ",", current dir first */
3316 j = 1;
3317 for (i = 0; cdpath[i] != NUL; ++i)
3318 {
3319 if (vim_ispathlistsep(cdpath[i]))
3320 buf[j++] = ',';
3321 else
3322 {
3323 if (cdpath[i] == ' ' || cdpath[i] == ',')
3324 buf[j++] = '\\';
3325 buf[j++] = cdpath[i];
3326 }
3327 }
3328 buf[j] = NUL;
3329 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003330 if (opt_idx >= 0)
3331 {
3332 options[opt_idx].def_val[VI_DEFAULT] = buf;
3333 options[opt_idx].flags |= P_DEF_ALLOCED;
3334 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003335 else
3336 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003338 if (mustfree)
3339 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340 }
3341 }
3342#endif
3343
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003344#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 /* Set print encoding on platforms that don't default to latin1 */
3346 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003347# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 (char_u *)"cp1252"
3349# else
3350# ifdef VMS
3351 (char_u *)"dec-mcs"
3352# else
3353# ifdef EBCDIC
3354 (char_u *)"ebcdic-uk"
3355# else
3356# ifdef MAC
3357 (char_u *)"mac-roman"
3358# else /* HPUX */
3359 (char_u *)"hp-roman8"
3360# endif
3361# endif
3362# endif
3363# endif
3364 );
3365#endif
3366
3367#ifdef FEAT_POSTSCRIPT
3368 /* 'printexpr' must be allocated to be able to evaluate it. */
3369 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003370# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003371 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372# else
3373# ifdef VMS
3374 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3375
3376# else
3377 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3378# endif
3379# endif
3380 );
3381#endif
3382
3383 /*
3384 * Set all the options (except the terminal options) to their default
3385 * value. Also set the global value for local options.
3386 */
3387 set_options_default(0);
3388
3389#ifdef FEAT_GUI
3390 if (found_reverse_arg)
3391 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3392#endif
3393
3394 curbuf->b_p_initialized = TRUE;
3395 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003396 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 check_buf_options(curbuf);
3398 check_win_options(curwin);
3399 check_options();
3400
3401 /* Must be before option_expand(), because that one needs vim_isIDc() */
3402 didset_options();
3403
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003404#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003405 /* Use the current chartab for the generic chartab. This is not in
3406 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003407 init_spell_chartab();
3408#endif
3409
Bram Moolenaar071d4272004-06-13 20:20:40 +00003410 /*
3411 * Expand environment variables and things like "~" for the defaults.
3412 * If option_expand() returns non-NULL the variable is expanded. This can
3413 * only happen for non-indirect options.
3414 * Also set the default to the expanded value, so ":set" does not list
3415 * them.
3416 * Don't set the P_ALLOCED flag, because we don't want to free the
3417 * default.
3418 */
3419 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3420 {
3421 if ((options[opt_idx].flags & P_GETTEXT)
3422 && options[opt_idx].var != NULL)
3423 p = (char_u *)_(*(char **)options[opt_idx].var);
3424 else
3425 p = option_expand(opt_idx, NULL);
3426 if (p != NULL && (p = vim_strsave(p)) != NULL)
3427 {
3428 *(char_u **)options[opt_idx].var = p;
3429 /* VIMEXP
3430 * Defaults for all expanded options are currently the same for Vi
3431 * and Vim. When this changes, add some code here! Also need to
3432 * split P_DEF_ALLOCED in two.
3433 */
3434 if (options[opt_idx].flags & P_DEF_ALLOCED)
3435 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3436 options[opt_idx].def_val[VI_DEFAULT] = p;
3437 options[opt_idx].flags |= P_DEF_ALLOCED;
3438 }
3439 }
3440
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 save_file_ff(curbuf); /* Buffer is unchanged */
3442
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443#if defined(FEAT_ARABIC)
3444 /* Detect use of mlterm.
3445 * Mlterm is a terminal emulator akin to xterm that has some special
3446 * abilities (bidi namely).
3447 * NOTE: mlterm's author is being asked to 'set' a variable
3448 * instead of an environment variable due to inheritance.
3449 */
3450 if (mch_getenv((char_u *)"MLTERM") != NULL)
3451 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3452#endif
3453
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003454 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003455
3456#ifdef FEAT_MBYTE
3457# if defined(WIN3264) && defined(FEAT_GETTEXT)
3458 /*
3459 * If $LANG isn't set, try to get a good value for it. This makes the
3460 * right language be used automatically. Don't do this for English.
3461 */
3462 if (mch_getenv((char_u *)"LANG") == NULL)
3463 {
3464 char buf[20];
3465
3466 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3467 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3468 * only the first two. */
3469 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3470 (LPTSTR)buf, 20);
3471 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3472 {
3473 /* There are a few exceptions (probably more) */
3474 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3475 STRCPY(buf, "zh_TW");
3476 else if (STRNICMP(buf, "chs", 3) == 0
3477 || STRNICMP(buf, "zhc", 3) == 0)
3478 STRCPY(buf, "zh_CN");
3479 else if (STRNICMP(buf, "jp", 2) == 0)
3480 STRCPY(buf, "ja");
3481 else
3482 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003483 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484 }
3485 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003486# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003487# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003488 /* Moved to os_mac_conv.c to avoid dependency problems. */
3489 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003490# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491# endif
3492
3493 /* enc_locale() will try to find the encoding of the current locale. */
3494 p = enc_locale();
3495 if (p != NULL)
3496 {
3497 char_u *save_enc;
3498
3499 /* Try setting 'encoding' and check if the value is valid.
3500 * If not, go back to the default "latin1". */
3501 save_enc = p_enc;
3502 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003503 if (STRCMP(p_enc, "gb18030") == 0)
3504 {
3505 /* We don't support "gb18030", but "cp936" is a good substitute
3506 * for practical purposes, thus use that. It's not an alias to
3507 * still support conversion between gb18030 and utf-8. */
3508 p_enc = vim_strsave((char_u *)"cp936");
3509 vim_free(p);
3510 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511 if (mb_init() == NULL)
3512 {
3513 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003514 if (opt_idx >= 0)
3515 {
3516 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3517 options[opt_idx].flags |= P_DEF_ALLOCED;
3518 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003520#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003521 if (STRCMP(p_enc, "latin1") == 0
3522# ifdef FEAT_MBYTE
3523 || enc_utf8
3524# endif
3525 )
3526 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003527 /* Adjust the default for 'isprint' and 'iskeyword' to match
3528 * latin1. Also set the defaults for when 'nocompatible' is
3529 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003530 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003531 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003532 set_string_option_direct((char_u *)"isk", -1,
3533 ISK_LATIN1, OPT_FREE, SID_NONE);
3534 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003535 if (opt_idx >= 0)
3536 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003537 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003538 if (opt_idx >= 0)
3539 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003540 (void)init_chartab();
3541 }
3542#endif
3543
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544# if defined(WIN3264) && !defined(FEAT_GUI)
3545 /* Win32 console: When GetACP() returns a different value from
3546 * GetConsoleCP() set 'termencoding'. */
3547 if (GetACP() != GetConsoleCP())
3548 {
3549 char buf[50];
3550
3551 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3552 p_tenc = vim_strsave((char_u *)buf);
3553 if (p_tenc != NULL)
3554 {
3555 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003556 if (opt_idx >= 0)
3557 {
3558 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3559 options[opt_idx].flags |= P_DEF_ALLOCED;
3560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561 convert_setup(&input_conv, p_tenc, p_enc);
3562 convert_setup(&output_conv, p_enc, p_tenc);
3563 }
3564 else
3565 p_tenc = empty_option;
3566 }
3567# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003568# if defined(WIN3264) && defined(FEAT_MBYTE)
3569 /* $HOME may have characters in active code page. */
3570 init_homedir();
3571# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 }
3573 else
3574 {
3575 vim_free(p_enc);
3576 p_enc = save_enc;
3577 }
3578 }
3579#endif
3580
3581#ifdef FEAT_MULTI_LANG
3582 /* Set the default for 'helplang'. */
3583 set_helplang_default(get_mess_lang());
3584#endif
3585}
3586
3587/*
3588 * Set an option to its default value.
3589 * This does not take care of side effects!
3590 */
3591 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003592set_option_default(
3593 int opt_idx,
3594 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3595 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596{
3597 char_u *varp; /* pointer to variable for current option */
3598 int dvi; /* index in def_val[] */
3599 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003600 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3602
3603 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3604 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003605 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003606 {
3607 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3608 if (flags & P_STRING)
3609 {
3610 /* Use set_string_option_direct() for local options to handle
3611 * freeing and allocating the value. */
3612 if (options[opt_idx].indir != PV_NONE)
3613 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003614 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615 else
3616 {
3617 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3618 free_string_option(*(char_u **)(varp));
3619 *(char_u **)varp = options[opt_idx].def_val[dvi];
3620 options[opt_idx].flags &= ~P_ALLOCED;
3621 }
3622 }
3623 else if (flags & P_NUM)
3624 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003625 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626 win_comp_scroll(curwin);
3627 else
3628 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003629 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630 /* May also set global value for local option. */
3631 if (both)
3632 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3633 *(long *)varp;
3634 }
3635 }
3636 else /* P_BOOL */
3637 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003638 /* the cast to long is required for Manx C, long_i is needed for
3639 * MSVC */
3640 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003641#ifdef UNIX
3642 /* 'modeline' defaults to off for root */
3643 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3644 *(int *)varp = FALSE;
3645#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 /* May also set global value for local option. */
3647 if (both)
3648 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3649 *(int *)varp;
3650 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003651
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003652 /* The default value is not insecure. */
3653 flagsp = insecure_flag(opt_idx, opt_flags);
3654 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655 }
3656
3657#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003658 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003659#endif
3660}
3661
3662/*
3663 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003664 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665 */
3666 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003667set_options_default(
3668 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003669{
3670 int i;
3671#ifdef FEAT_WINDOWS
3672 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003673 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674#endif
3675
3676 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003677 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003678#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003679 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003680 || (TRUE
3681# if defined(FEAT_MBYTE)
3682 && options[i].var != (char_u *)&p_enc
3683# endif
3684# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003685 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003686 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003687# endif
3688 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003689#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003690 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691 set_option_default(i, opt_flags, p_cp);
3692
3693#ifdef FEAT_WINDOWS
3694 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003695 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 win_comp_scroll(wp);
3697#else
3698 win_comp_scroll(curwin);
3699#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003700#ifdef FEAT_CINDENT
3701 parse_cino(curbuf);
3702#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703}
3704
3705/*
3706 * Set the Vi-default value of a string option.
3707 * Used for 'sh', 'backupskip' and 'term'.
3708 */
3709 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003710set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711{
3712 char_u *p;
3713 int opt_idx;
3714
3715 p = vim_strsave(val);
3716 if (p != NULL) /* we don't want a NULL */
3717 {
3718 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003719 if (opt_idx >= 0)
3720 {
3721 if (options[opt_idx].flags & P_DEF_ALLOCED)
3722 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3723 options[opt_idx].def_val[VI_DEFAULT] = p;
3724 options[opt_idx].flags |= P_DEF_ALLOCED;
3725 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003726 }
3727}
3728
3729/*
3730 * Set the Vi-default value of a number option.
3731 * Used for 'lines' and 'columns'.
3732 */
3733 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003734set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003735{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003736 int opt_idx;
3737
3738 opt_idx = findoption((char_u *)name);
3739 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003740 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003741}
3742
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003743#if defined(EXITFREE) || defined(PROTO)
3744/*
3745 * Free all options.
3746 */
3747 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003748free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003749{
3750 int i;
3751
3752 for (i = 0; !istermoption(&options[i]); i++)
3753 {
3754 if (options[i].indir == PV_NONE)
3755 {
3756 /* global option: free value and default value. */
3757 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3758 free_string_option(*(char_u **)options[i].var);
3759 if (options[i].flags & P_DEF_ALLOCED)
3760 free_string_option(options[i].def_val[VI_DEFAULT]);
3761 }
3762 else if (options[i].var != VAR_WIN
3763 && (options[i].flags & P_STRING))
3764 /* buffer-local option: free global value */
3765 free_string_option(*(char_u **)options[i].var);
3766 }
3767}
3768#endif
3769
3770
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771/*
3772 * Initialize the options, part two: After getting Rows and Columns and
3773 * setting 'term'.
3774 */
3775 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003776set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003778 int idx;
3779
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780 /*
3781 * 'scroll' defaults to half the window height. Note that this default is
3782 * wrong when the window height changes.
3783 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003784 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003785 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003786 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003787 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 comp_col();
3789
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003790 /*
3791 * 'window' is only for backwards compatibility with Vi.
3792 * Default is Rows - 1.
3793 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003794 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003795 p_window = Rows - 1;
3796 set_number_default("window", Rows - 1);
3797
Bram Moolenaarf740b292006-02-16 22:11:02 +00003798 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003799#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003800 /*
3801 * If 'background' wasn't set by the user, try guessing the value,
3802 * depending on the terminal name. Only need to check for terminals
3803 * with a dark background, that can handle color.
3804 */
3805 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003806 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3807 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003809 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003810 /* don't mark it as set, when starting the GUI it may be
3811 * changed again */
3812 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 }
3814#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003815
3816#ifdef CURSOR_SHAPE
3817 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3818#endif
3819#ifdef FEAT_MOUSESHAPE
3820 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3821#endif
3822#ifdef FEAT_PRINTER
3823 (void)parse_printoptions(); /* parse 'printoptions' default value */
3824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825}
3826
3827/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003828 * Return "dark" or "light" depending on the kind of terminal.
3829 * This is just guessing! Recognized are:
3830 * "linux" Linux console
3831 * "screen.linux" Linux console with screen
3832 * "cygwin" Cygwin shell
3833 * "putty" Putty program
3834 * We also check the COLORFGBG environment variable, which is set by
3835 * rxvt and derivatives. This variable contains either two or three
3836 * values separated by semicolons; we want the last value in either
3837 * case. If this value is 0-6 or 8, our background is dark.
3838 */
3839 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003840term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003841{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003842#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003843 /* DOS console nearly always black */
3844 return (char_u *)"dark";
3845#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003846 char_u *p;
3847
Bram Moolenaarf740b292006-02-16 22:11:02 +00003848 if (STRCMP(T_NAME, "linux") == 0
3849 || STRCMP(T_NAME, "screen.linux") == 0
3850 || STRCMP(T_NAME, "cygwin") == 0
3851 || STRCMP(T_NAME, "putty") == 0
3852 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3853 && (p = vim_strrchr(p, ';')) != NULL
3854 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3855 && p[2] == NUL))
3856 return (char_u *)"dark";
3857 return (char_u *)"light";
3858#endif
3859}
3860
3861/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 * Initialize the options, part three: After reading the .vimrc
3863 */
3864 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003865set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003866{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003867#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868/*
3869 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3870 * This is done after other initializations, where 'shell' might have been
3871 * set, but only if they have not been set before.
3872 */
3873 char_u *p;
3874 int idx_srr;
3875 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003876# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 int idx_sp;
3878 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003879# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880
3881 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003882 if (idx_srr < 0)
3883 do_srr = FALSE;
3884 else
3885 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003886# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003888 if (idx_sp < 0)
3889 do_sp = FALSE;
3890 else
3891 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003892# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003893 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 if (p != NULL)
3895 {
3896 /*
3897 * Default for p_sp is "| tee", for p_srr is ">".
3898 * For known shells it is changed here to include stderr.
3899 */
3900 if ( fnamecmp(p, "csh") == 0
3901 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003902# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903 || fnamecmp(p, "csh.exe") == 0
3904 || fnamecmp(p, "tcsh.exe") == 0
3905# endif
3906 )
3907 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003908# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909 if (do_sp)
3910 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003911# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003913# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003915# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3917 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003918# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 if (do_srr)
3920 {
3921 p_srr = (char_u *)">&";
3922 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3923 }
3924 }
3925 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003926 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927 if ( fnamecmp(p, "sh") == 0
3928 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003929 || fnamecmp(p, "mksh") == 0
3930 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003932 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003934 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003935# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936 || fnamecmp(p, "cmd") == 0
3937 || fnamecmp(p, "sh.exe") == 0
3938 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003939 || fnamecmp(p, "mksh.exe") == 0
3940 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003942 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 || fnamecmp(p, "bash.exe") == 0
3944 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003946 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003948# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 if (do_sp)
3950 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003951# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003953# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003955# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3957 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003958# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959 if (do_srr)
3960 {
3961 p_srr = (char_u *)">%s 2>&1";
3962 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3963 }
3964 }
3965 vim_free(p);
3966 }
3967#endif
3968
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003969#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003971 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3972 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973 * This is done after other initializations, where 'shell' might have been
3974 * set, but only if they have not been set before. Default for p_shcf is
3975 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003976 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003978 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 {
3980 int idx3;
3981
3982 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003983 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 {
3985 p_shcf = (char_u *)"-c";
3986 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3987 }
3988
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003989# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990 /* Somehow Win32 requires the quotes around the redirection too */
3991 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003992 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993 {
3994 p_sxq = (char_u *)"\"";
3995 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3996 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003997# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003999 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 {
4001 p_shq = (char_u *)"\"";
4002 options[idx3].def_val[VI_DEFAULT] = p_shq;
4003 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004004# endif
4005 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004006 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4007 {
4008 int idx3;
4009
4010 /*
4011 * cmd.exe on Windows will strip the first and last double quote given
4012 * on the command line, e.g. most of the time things like:
4013 * cmd /c "my path/to/echo" "my args to echo"
4014 * become:
4015 * my path/to/echo" "my args to echo
4016 * when executed.
4017 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004018 * To avoid this, set shellxquote to surround the command in
4019 * parenthesis. This appears to make most commands work, without
4020 * breaking commands that worked previously, such as
4021 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004022 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004023 idx3 = findoption((char_u *)"sxq");
4024 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4025 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004026 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004027 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4028 }
4029
Bram Moolenaara64ba222012-02-12 23:23:31 +01004030 idx3 = findoption((char_u *)"shcf");
4031 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4032 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004033 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004034 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4035 }
4036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037#endif
4038
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004039 if (bufempty())
4040 {
4041 int idx_ffs = findoption((char_u *)"ffs");
4042
4043 /* Apply the first entry of 'fileformats' to the initial buffer. */
4044 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4045 set_fileformat(default_fileformat(), OPT_LOCAL);
4046 }
4047
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048#ifdef FEAT_TITLE
4049 set_title_defaults();
4050#endif
4051}
4052
4053#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4054/*
4055 * When 'helplang' is still at its default value, set it to "lang".
4056 * Only the first two characters of "lang" are used.
4057 */
4058 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004059set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060{
4061 int idx;
4062
4063 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4064 return;
4065 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004066 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 {
4068 if (options[idx].flags & P_ALLOCED)
4069 free_string_option(p_hlg);
4070 p_hlg = vim_strsave(lang);
4071 if (p_hlg == NULL)
4072 p_hlg = empty_option;
4073 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004074 {
4075 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4076 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4077 {
4078 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4079 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4080 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004082 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 options[idx].flags |= P_ALLOCED;
4084 }
4085}
4086#endif
4087
4088#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004089static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090
4091 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004092gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093{
4094 if (gui_get_lightness(gui.back_pixel) < 127)
4095 return (char_u *)"dark";
4096 return (char_u *)"light";
4097}
4098
4099/*
4100 * Option initializations that can only be done after opening the GUI window.
4101 */
4102 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004103init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104{
4105 /* Set the 'background' option according to the lightness of the
4106 * background color, unless the user has set it already. */
4107 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4108 {
4109 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4110 highlight_changed();
4111 }
4112}
4113#endif
4114
4115#ifdef FEAT_TITLE
4116/*
4117 * 'title' and 'icon' only default to true if they have not been set or reset
4118 * in .vimrc and we can read the old value.
4119 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4120 * they can be reset. This reduces startup time when using X on a remote
4121 * machine.
4122 */
4123 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004124set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125{
4126 int idx1;
4127 long val;
4128
4129 /*
4130 * If GUI is (going to be) used, we can always set the window title and
4131 * icon name. Saves a bit of time, because the X11 display server does
4132 * not need to be contacted.
4133 */
4134 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004135 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 {
4137#ifdef FEAT_GUI
4138 if (gui.starting || gui.in_use)
4139 val = TRUE;
4140 else
4141#endif
4142 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004143 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 p_title = val;
4145 }
4146 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004147 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 {
4149#ifdef FEAT_GUI
4150 if (gui.starting || gui.in_use)
4151 val = TRUE;
4152 else
4153#endif
4154 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004155 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156 p_icon = val;
4157 }
4158}
4159#endif
4160
4161/*
4162 * Parse 'arg' for option settings.
4163 *
4164 * 'arg' may be IObuff, but only when no errors can be present and option
4165 * does not need to be expanded with option_expand().
4166 * "opt_flags":
4167 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004168 * OPT_GLOBAL for ":setglobal"
4169 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004170 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004171 * OPT_WINONLY to only set window-local options
4172 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004173 *
4174 * returns FAIL if an error is detected, OK otherwise
4175 */
4176 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004177do_set(
4178 char_u *arg, /* option string (may be written to!) */
4179 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180{
4181 int opt_idx;
4182 char_u *errmsg;
4183 char_u errbuf[80];
4184 char_u *startarg;
4185 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4186 int nextchar; /* next non-white char after option name */
4187 int afterchar; /* character just after option name */
4188 int len;
4189 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004190 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 int key;
4192 long_u flags; /* flags for current option */
4193 char_u *varp = NULL; /* pointer to variable for current option */
4194 int did_show = FALSE; /* already showed one value */
4195 int adding; /* "opt+=arg" */
4196 int prepending; /* "opt^=arg" */
4197 int removing; /* "opt-=arg" */
4198 int cp_val = 0;
4199 char_u key_name[2];
4200
4201 if (*arg == NUL)
4202 {
4203 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004204 did_show = TRUE;
4205 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206 }
4207
4208 while (*arg != NUL) /* loop to process all options */
4209 {
4210 errmsg = NULL;
4211 startarg = arg; /* remember for error message */
4212
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004213 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4214 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215 {
4216 /*
4217 * ":set all" show all options.
4218 * ":set all&" set all options to their default value.
4219 */
4220 arg += 3;
4221 if (*arg == '&')
4222 {
4223 ++arg;
4224 /* Only for :set command set global value of local options. */
4225 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004226 didset_options();
4227 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004228 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229 }
4230 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004231 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004233 did_show = TRUE;
4234 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004236 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004237 {
4238 showoptions(2, opt_flags);
4239 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004240 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004241 arg += 7;
4242 }
4243 else
4244 {
4245 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004246 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004247 {
4248 prefix = 0;
4249 arg += 2;
4250 }
4251 else if (STRNCMP(arg, "inv", 3) == 0)
4252 {
4253 prefix = 2;
4254 arg += 3;
4255 }
4256
4257 /* find end of name */
4258 key = 0;
4259 if (*arg == '<')
4260 {
4261 nextchar = 0;
4262 opt_idx = -1;
4263 /* look out for <t_>;> */
4264 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4265 len = 5;
4266 else
4267 {
4268 len = 1;
4269 while (arg[len] != NUL && arg[len] != '>')
4270 ++len;
4271 }
4272 if (arg[len] != '>')
4273 {
4274 errmsg = e_invarg;
4275 goto skip;
4276 }
4277 arg[len] = NUL; /* put NUL after name */
4278 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4279 opt_idx = findoption(arg + 1);
4280 arg[len++] = '>'; /* restore '>' */
4281 if (opt_idx == -1)
4282 key = find_key_option(arg + 1);
4283 }
4284 else
4285 {
4286 len = 0;
4287 /*
4288 * The two characters after "t_" may not be alphanumeric.
4289 */
4290 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4291 len = 4;
4292 else
4293 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4294 ++len;
4295 nextchar = arg[len];
4296 arg[len] = NUL; /* put NUL after name */
4297 opt_idx = findoption(arg);
4298 arg[len] = nextchar; /* restore nextchar */
4299 if (opt_idx == -1)
4300 key = find_key_option(arg);
4301 }
4302
4303 /* remember character after option name */
4304 afterchar = arg[len];
4305
4306 /* skip white space, allow ":set ai ?" */
4307 while (vim_iswhite(arg[len]))
4308 ++len;
4309
4310 adding = FALSE;
4311 prepending = FALSE;
4312 removing = FALSE;
4313 if (arg[len] != NUL && arg[len + 1] == '=')
4314 {
4315 if (arg[len] == '+')
4316 {
4317 adding = TRUE; /* "+=" */
4318 ++len;
4319 }
4320 else if (arg[len] == '^')
4321 {
4322 prepending = TRUE; /* "^=" */
4323 ++len;
4324 }
4325 else if (arg[len] == '-')
4326 {
4327 removing = TRUE; /* "-=" */
4328 ++len;
4329 }
4330 }
4331 nextchar = arg[len];
4332
4333 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4334 {
4335 errmsg = (char_u *)N_("E518: Unknown option");
4336 goto skip;
4337 }
4338
4339 if (opt_idx >= 0)
4340 {
4341 if (options[opt_idx].var == NULL) /* hidden option: skip */
4342 {
4343 /* Only give an error message when requesting the value of
4344 * a hidden option, ignore setting it. */
4345 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4346 && (!(options[opt_idx].flags & P_BOOL)
4347 || nextchar == '?'))
4348 errmsg = (char_u *)N_("E519: Option not supported");
4349 goto skip;
4350 }
4351
4352 flags = options[opt_idx].flags;
4353 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4354 }
4355 else
4356 {
4357 flags = P_STRING;
4358 if (key < 0)
4359 {
4360 key_name[0] = KEY2TERMCAP0(key);
4361 key_name[1] = KEY2TERMCAP1(key);
4362 }
4363 else
4364 {
4365 key_name[0] = KS_KEY;
4366 key_name[1] = (key & 0xff);
4367 }
4368 }
4369
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004370 /* Skip all options that are not window-local (used when showing
4371 * an already loaded buffer in a window). */
4372 if ((opt_flags & OPT_WINONLY)
4373 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4374 goto skip;
4375
Bram Moolenaara3227e22006-03-08 21:32:40 +00004376 /* Skip all options that are window-local (used for :vimgrep). */
4377 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4378 && options[opt_idx].var == VAR_WIN)
4379 goto skip;
4380
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004381 /* Disallow changing some options from modelines. */
4382 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004384 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004385 {
4386 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4387 goto skip;
4388 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004389#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004390 /* In diff mode some options are overruled. This avoids that
4391 * 'foldmethod' becomes "marker" instead of "diff" and that
4392 * "wrap" gets set. */
4393 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004394 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004395 && (options[opt_idx].indir == PV_FDM
4396 || options[opt_idx].indir == PV_WRAP))
4397 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399 }
4400
4401#ifdef HAVE_SANDBOX
4402 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004403 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 {
4405 errmsg = (char_u *)_(e_sandbox);
4406 goto skip;
4407 }
4408#endif
4409
4410 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4411 {
4412 arg += len;
4413 cp_val = p_cp;
4414 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4415 {
4416 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4417 {
4418 cp_val = FALSE;
4419 arg += 3;
4420 }
4421 else /* "opt&vi": set to Vi default */
4422 {
4423 cp_val = TRUE;
4424 arg += 2;
4425 }
4426 }
4427 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4428 && arg[1] != NUL && !vim_iswhite(arg[1]))
4429 {
4430 errmsg = e_trailing;
4431 goto skip;
4432 }
4433 }
4434
4435 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004436 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4437 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004438 */
4439 if (nextchar == '?'
4440 || (prefix == 1
4441 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4442 && !(flags & P_BOOL)))
4443 {
4444 /*
4445 * print value
4446 */
4447 if (did_show)
4448 msg_putchar('\n'); /* cursor below last one */
4449 else
4450 {
4451 gotocmdline(TRUE); /* cursor at status line */
4452 did_show = TRUE; /* remember that we did a line */
4453 }
4454 if (opt_idx >= 0)
4455 {
4456 showoneopt(&options[opt_idx], opt_flags);
4457#ifdef FEAT_EVAL
4458 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004459 {
4460 /* Mention where the option was last set. */
4461 if (varp == options[opt_idx].var)
4462 last_set_msg(options[opt_idx].scriptID);
4463 else if ((int)options[opt_idx].indir & PV_WIN)
4464 last_set_msg(curwin->w_p_scriptID[
4465 (int)options[opt_idx].indir & PV_MASK]);
4466 else if ((int)options[opt_idx].indir & PV_BUF)
4467 last_set_msg(curbuf->b_p_scriptID[
4468 (int)options[opt_idx].indir & PV_MASK]);
4469 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004470#endif
4471 }
4472 else
4473 {
4474 char_u *p;
4475
4476 p = find_termcode(key_name);
4477 if (p == NULL)
4478 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004479 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004480 goto skip;
4481 }
4482 else
4483 (void)show_one_termcode(key_name, p, TRUE);
4484 }
4485 if (nextchar != '?'
4486 && nextchar != NUL && !vim_iswhite(afterchar))
4487 errmsg = e_trailing;
4488 }
4489 else
4490 {
4491 if (flags & P_BOOL) /* boolean */
4492 {
4493 if (nextchar == '=' || nextchar == ':')
4494 {
4495 errmsg = e_invarg;
4496 goto skip;
4497 }
4498
4499 /*
4500 * ":set opt!": invert
4501 * ":set opt&": reset to default value
4502 * ":set opt<": reset to global value
4503 */
4504 if (nextchar == '!')
4505 value = *(int *)(varp) ^ 1;
4506 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004507 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004508 ((flags & P_VI_DEF) || cp_val)
4509 ? VI_DEFAULT : VIM_DEFAULT];
4510 else if (nextchar == '<')
4511 {
4512 /* For 'autoread' -1 means to use global value. */
4513 if ((int *)varp == &curbuf->b_p_ar
4514 && opt_flags == OPT_LOCAL)
4515 value = -1;
4516 else
4517 value = *(int *)get_varp_scope(&(options[opt_idx]),
4518 OPT_GLOBAL);
4519 }
4520 else
4521 {
4522 /*
4523 * ":set invopt": invert
4524 * ":set opt" or ":set noopt": set or reset
4525 */
4526 if (nextchar != NUL && !vim_iswhite(afterchar))
4527 {
4528 errmsg = e_trailing;
4529 goto skip;
4530 }
4531 if (prefix == 2) /* inv */
4532 value = *(int *)(varp) ^ 1;
4533 else
4534 value = prefix;
4535 }
4536
4537 errmsg = set_bool_option(opt_idx, varp, (int)value,
4538 opt_flags);
4539 }
4540 else /* numeric or string */
4541 {
4542 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4543 || prefix != 1)
4544 {
4545 errmsg = e_invarg;
4546 goto skip;
4547 }
4548
4549 if (flags & P_NUM) /* numeric */
4550 {
4551 /*
4552 * Different ways to set a number option:
4553 * & set to default value
4554 * < set to global value
4555 * <xx> accept special key codes for 'wildchar'
4556 * c accept any non-digit for 'wildchar'
4557 * [-]0-9 set number
4558 * other error
4559 */
4560 ++arg;
4561 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004562 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004563 ((flags & P_VI_DEF) || cp_val)
4564 ? VI_DEFAULT : VIM_DEFAULT];
4565 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004566 {
4567 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4568 * use the global value. */
4569 if ((long *)varp == &curbuf->b_p_ul
4570 && opt_flags == OPT_LOCAL)
4571 value = NO_LOCAL_UNDOLEVEL;
4572 else
4573 value = *(long *)get_varp_scope(
4574 &(options[opt_idx]), OPT_GLOBAL);
4575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004576 else if (((long *)varp == &p_wc
4577 || (long *)varp == &p_wcm)
4578 && (*arg == '<'
4579 || *arg == '^'
4580 || ((!arg[1] || vim_iswhite(arg[1]))
4581 && !VIM_ISDIGIT(*arg))))
4582 {
4583 value = string_to_key(arg);
4584 if (value == 0 && (long *)varp != &p_wcm)
4585 {
4586 errmsg = e_invarg;
4587 goto skip;
4588 }
4589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004590 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4591 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004592 /* Allow negative (for 'undolevels'), octal and
4593 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004594 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4595 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004596 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4597 {
4598 errmsg = e_invarg;
4599 goto skip;
4600 }
4601 }
4602 else
4603 {
4604 errmsg = (char_u *)N_("E521: Number required after =");
4605 goto skip;
4606 }
4607
4608 if (adding)
4609 value = *(long *)varp + value;
4610 if (prepending)
4611 value = *(long *)varp * value;
4612 if (removing)
4613 value = *(long *)varp - value;
4614 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004615 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004616 }
4617 else if (opt_idx >= 0) /* string */
4618 {
4619 char_u *save_arg = NULL;
4620 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004621 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004622 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004623 char_u *origval = NULL;
4624#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4625 char_u *saved_origval = NULL;
4626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004627 unsigned newlen;
4628 int comma;
4629 int bs;
4630 int new_value_alloced; /* new string option
4631 was allocated */
4632
4633 /* When using ":set opt=val" for a global option
4634 * with a local value the local value will be
4635 * reset, use the global value here. */
4636 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004637 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004638 varp = options[opt_idx].var;
4639
4640 /* The old value is kept until we are sure that the
4641 * new value is valid. */
4642 oldval = *(char_u **)varp;
4643 if (nextchar == '&') /* set to default val */
4644 {
4645 newval = options[opt_idx].def_val[
4646 ((flags & P_VI_DEF) || cp_val)
4647 ? VI_DEFAULT : VIM_DEFAULT];
4648 if ((char_u **)varp == &p_bg)
4649 {
4650 /* guess the value of 'background' */
4651#ifdef FEAT_GUI
4652 if (gui.in_use)
4653 newval = gui_bg_default();
4654 else
4655#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004656 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004657 }
4658
4659 /* expand environment variables and ~ (since the
4660 * default value was already expanded, only
4661 * required when an environment variable was set
4662 * later */
4663 if (newval == NULL)
4664 newval = empty_option;
4665 else
4666 {
4667 s = option_expand(opt_idx, newval);
4668 if (s == NULL)
4669 s = newval;
4670 newval = vim_strsave(s);
4671 }
4672 new_value_alloced = TRUE;
4673 }
4674 else if (nextchar == '<') /* set to global val */
4675 {
4676 newval = vim_strsave(*(char_u **)get_varp_scope(
4677 &(options[opt_idx]), OPT_GLOBAL));
4678 new_value_alloced = TRUE;
4679 }
4680 else
4681 {
4682 ++arg; /* jump to after the '=' or ':' */
4683
4684 /*
4685 * Set 'keywordprg' to ":help" if an empty
4686 * value was passed to :set by the user.
4687 * Misuse errbuf[] for the resulting string.
4688 */
4689 if (varp == (char_u *)&p_kp
4690 && (*arg == NUL || *arg == ' '))
4691 {
4692 STRCPY(errbuf, ":help");
4693 save_arg = arg;
4694 arg = errbuf;
4695 }
4696 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004697 * Convert 'backspace' number to string, for
4698 * adding, prepending and removing string.
4699 */
4700 else if (varp == (char_u *)&p_bs
4701 && VIM_ISDIGIT(**(char_u **)varp))
4702 {
4703 i = getdigits((char_u **)varp);
4704 switch (i)
4705 {
4706 case 0:
4707 *(char_u **)varp = empty_option;
4708 break;
4709 case 1:
4710 *(char_u **)varp = vim_strsave(
4711 (char_u *)"indent,eol");
4712 break;
4713 case 2:
4714 *(char_u **)varp = vim_strsave(
4715 (char_u *)"indent,eol,start");
4716 break;
4717 }
4718 vim_free(oldval);
4719 oldval = *(char_u **)varp;
4720 }
4721 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004722 * Convert 'whichwrap' number to string, for
4723 * backwards compatibility with Vim 3.0.
4724 * Misuse errbuf[] for the resulting string.
4725 */
4726 else if (varp == (char_u *)&p_ww
4727 && VIM_ISDIGIT(*arg))
4728 {
4729 *errbuf = NUL;
4730 i = getdigits(&arg);
4731 if (i & 1)
4732 STRCAT(errbuf, "b,");
4733 if (i & 2)
4734 STRCAT(errbuf, "s,");
4735 if (i & 4)
4736 STRCAT(errbuf, "h,l,");
4737 if (i & 8)
4738 STRCAT(errbuf, "<,>,");
4739 if (i & 16)
4740 STRCAT(errbuf, "[,],");
4741 if (*errbuf != NUL) /* remove trailing , */
4742 errbuf[STRLEN(errbuf) - 1] = NUL;
4743 save_arg = arg;
4744 arg = errbuf;
4745 }
4746 /*
4747 * Remove '>' before 'dir' and 'bdir', for
4748 * backwards compatibility with version 3.0
4749 */
4750 else if ( *arg == '>'
4751 && (varp == (char_u *)&p_dir
4752 || varp == (char_u *)&p_bdir))
4753 {
4754 ++arg;
4755 }
4756
4757 /* When setting the local value of a global
4758 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004759 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760 && (opt_flags & OPT_LOCAL))
4761 origval = *(char_u **)get_varp(
4762 &options[opt_idx]);
4763 else
4764 origval = oldval;
4765
4766 /*
4767 * Copy the new string into allocated memory.
4768 * Can't use set_string_option_direct(), because
4769 * we need to remove the backslashes.
4770 */
4771 /* get a bit too much */
4772 newlen = (unsigned)STRLEN(arg) + 1;
4773 if (adding || prepending || removing)
4774 newlen += (unsigned)STRLEN(origval) + 1;
4775 newval = alloc(newlen);
4776 if (newval == NULL) /* out of mem, don't change */
4777 break;
4778 s = newval;
4779
4780 /*
4781 * Copy the string, skip over escaped chars.
4782 * For MS-DOS and WIN32 backslashes before normal
4783 * file name characters are not removed, and keep
4784 * backslash at start, for "\\machine\path", but
4785 * do remove it for "\\\\machine\\path".
4786 * The reverse is found in ExpandOldSetting().
4787 */
4788 while (*arg && !vim_iswhite(*arg))
4789 {
4790 if (*arg == '\\' && arg[1] != NUL
4791#ifdef BACKSLASH_IN_FILENAME
4792 && !((flags & P_EXPAND)
4793 && vim_isfilec(arg[1])
4794 && (arg[1] != '\\'
4795 || (s == newval
4796 && arg[2] != '\\')))
4797#endif
4798 )
4799 ++arg; /* remove backslash */
4800#ifdef FEAT_MBYTE
4801 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004802 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004803 {
4804 /* copy multibyte char */
4805 mch_memmove(s, arg, (size_t)i);
4806 arg += i;
4807 s += i;
4808 }
4809 else
4810#endif
4811 *s++ = *arg++;
4812 }
4813 *s = NUL;
4814
4815 /*
4816 * Expand environment variables and ~.
4817 * Don't do it when adding without inserting a
4818 * comma.
4819 */
4820 if (!(adding || prepending || removing)
4821 || (flags & P_COMMA))
4822 {
4823 s = option_expand(opt_idx, newval);
4824 if (s != NULL)
4825 {
4826 vim_free(newval);
4827 newlen = (unsigned)STRLEN(s) + 1;
4828 if (adding || prepending || removing)
4829 newlen += (unsigned)STRLEN(origval) + 1;
4830 newval = alloc(newlen);
4831 if (newval == NULL)
4832 break;
4833 STRCPY(newval, s);
4834 }
4835 }
4836
4837 /* locate newval[] in origval[] when removing it
4838 * and when adding to avoid duplicates */
4839 i = 0; /* init for GCC */
4840 if (removing || (flags & P_NODUP))
4841 {
4842 i = (int)STRLEN(newval);
4843 bs = 0;
4844 for (s = origval; *s; ++s)
4845 {
4846 if ((!(flags & P_COMMA)
4847 || s == origval
4848 || (s[-1] == ',' && !(bs & 1)))
4849 && STRNCMP(s, newval, i) == 0
4850 && (!(flags & P_COMMA)
4851 || s[i] == ','
4852 || s[i] == NUL))
4853 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004854 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004855 * even number of backslashes or a single
4856 * backslash preceded by a comma before it
4857 * is recognized as a separator */
4858 if ((s > origval + 1
4859 && s[-1] == '\\'
4860 && s[-2] != ',')
4861 || (s == origval + 1
4862 && s[-1] == '\\'))
4863
Bram Moolenaar071d4272004-06-13 20:20:40 +00004864 ++bs;
4865 else
4866 bs = 0;
4867 }
4868
4869 /* do not add if already there */
4870 if ((adding || prepending) && *s)
4871 {
4872 prepending = FALSE;
4873 adding = FALSE;
4874 STRCPY(newval, origval);
4875 }
4876 }
4877
4878 /* concatenate the two strings; add a ',' if
4879 * needed */
4880 if (adding || prepending)
4881 {
4882 comma = ((flags & P_COMMA) && *origval != NUL
4883 && *newval != NUL);
4884 if (adding)
4885 {
4886 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004887 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004888 if (comma && i > 1
4889 && (flags & P_ONECOMMA) == P_ONECOMMA
4890 && origval[i - 1] == ','
4891 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004892 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004893 mch_memmove(newval + i + comma, newval,
4894 STRLEN(newval) + 1);
4895 mch_memmove(newval, origval, (size_t)i);
4896 }
4897 else
4898 {
4899 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004900 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004901 }
4902 if (comma)
4903 newval[i] = ',';
4904 }
4905
4906 /* Remove newval[] from origval[]. (Note: "i" has
4907 * been set above and is used here). */
4908 if (removing)
4909 {
4910 STRCPY(newval, origval);
4911 if (*s)
4912 {
4913 /* may need to remove a comma */
4914 if (flags & P_COMMA)
4915 {
4916 if (s == origval)
4917 {
4918 /* include comma after string */
4919 if (s[i] == ',')
4920 ++i;
4921 }
4922 else
4923 {
4924 /* include comma before string */
4925 --s;
4926 ++i;
4927 }
4928 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004929 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004930 }
4931 }
4932
4933 if (flags & P_FLAGLIST)
4934 {
4935 /* Remove flags that appear twice. */
4936 for (s = newval; *s; ++s)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004937 {
4938 /* if options have P_FLAGLIST and
4939 * P_ONECOMMA such as 'whichwrap' */
4940 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004941 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004942 if (*s != ',' && *(s + 1) == ','
4943 && vim_strchr(s + 2, *s) != NULL)
4944 {
4945 /* Remove the duplicated value and
4946 * the next comma. */
4947 STRMOVE(s, s + 2);
4948 s -= 2;
4949 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004950 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004951 else
4952 {
4953 if ((!(flags & P_COMMA) || *s != ',')
4954 && vim_strchr(s + 1, *s) != NULL)
4955 {
4956 STRMOVE(s, s + 1);
4957 --s;
4958 }
4959 }
4960 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 }
4962
4963 if (save_arg != NULL) /* number for 'whichwrap' */
4964 arg = save_arg;
4965 new_value_alloced = TRUE;
4966 }
4967
4968 /* Set the new value. */
4969 *(char_u **)(varp) = newval;
4970
Bram Moolenaar53744302015-07-17 17:38:22 +02004971#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004972 if (!starting
4973# ifdef FEAT_CRYPT
4974 && options[opt_idx].indir != PV_KEY
4975# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004976 && origval != NULL)
4977 /* origval may be freed by
4978 * did_set_string_option(), make a copy. */
4979 saved_origval = vim_strsave(origval);
4980#endif
4981
Bram Moolenaar071d4272004-06-13 20:20:40 +00004982 /* Handle side effects, and set the global value for
4983 * ":set" on local options. */
4984 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4985 new_value_alloced, oldval, errbuf, opt_flags);
4986
4987 /* If error detected, print the error message. */
4988 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004989 {
4990#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4991 vim_free(saved_origval);
4992#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004993 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004994 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004995#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4996 if (saved_origval != NULL)
4997 {
4998 char_u buf_type[7];
4999
5000 sprintf((char *)buf_type, "%s",
5001 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005002 set_vim_var_string(VV_OPTION_NEW,
5003 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005004 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5005 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5006 apply_autocmds(EVENT_OPTIONSET,
5007 (char_u *)options[opt_idx].fullname,
5008 NULL, FALSE, NULL);
5009 reset_v_option_vars();
5010 vim_free(saved_origval);
5011 }
5012#endif
5013
Bram Moolenaar071d4272004-06-13 20:20:40 +00005014 }
5015 else /* key code option */
5016 {
5017 char_u *p;
5018
5019 if (nextchar == '&')
5020 {
5021 if (add_termcap_entry(key_name, TRUE) == FAIL)
5022 errmsg = (char_u *)N_("E522: Not found in termcap");
5023 }
5024 else
5025 {
5026 ++arg; /* jump to after the '=' or ':' */
5027 for (p = arg; *p && !vim_iswhite(*p); ++p)
5028 if (*p == '\\' && p[1] != NUL)
5029 ++p;
5030 nextchar = *p;
5031 *p = NUL;
5032 add_termcode(key_name, arg, FALSE);
5033 *p = nextchar;
5034 }
5035 if (full_screen)
5036 ttest(FALSE);
5037 redraw_all_later(CLEAR);
5038 }
5039 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005040
Bram Moolenaar071d4272004-06-13 20:20:40 +00005041 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005042 did_set_option(opt_idx, opt_flags,
5043 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005044 }
5045
5046skip:
5047 /*
5048 * Advance to next argument.
5049 * - skip until a blank found, taking care of backslashes
5050 * - skip blanks
5051 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5052 */
5053 for (i = 0; i < 2 ; ++i)
5054 {
5055 while (*arg != NUL && !vim_iswhite(*arg))
5056 if (*arg++ == '\\' && *arg != NUL)
5057 ++arg;
5058 arg = skipwhite(arg);
5059 if (*arg != '=')
5060 break;
5061 }
5062 }
5063
5064 if (errmsg != NULL)
5065 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005066 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005067 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005068 if (i + (arg - startarg) < IOSIZE)
5069 {
5070 /* append the argument with the error */
5071 STRCAT(IObuff, ": ");
5072 mch_memmove(IObuff + i, startarg, (arg - startarg));
5073 IObuff[i + (arg - startarg)] = NUL;
5074 }
5075 /* make sure all characters are printable */
5076 trans_characters(IObuff, IOSIZE);
5077
5078 ++no_wait_return; /* wait_return done later */
5079 emsg(IObuff); /* show error highlighted */
5080 --no_wait_return;
5081
5082 return FAIL;
5083 }
5084
5085 arg = skipwhite(arg);
5086 }
5087
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005088theend:
5089 if (silent_mode && did_show)
5090 {
5091 /* After displaying option values in silent mode. */
5092 silent_mode = FALSE;
5093 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5094 msg_putchar('\n');
5095 cursor_on(); /* msg_start() switches it off */
5096 out_flush();
5097 silent_mode = TRUE;
5098 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5099 }
5100
Bram Moolenaar071d4272004-06-13 20:20:40 +00005101 return OK;
5102}
5103
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005104/*
5105 * Call this when an option has been given a new value through a user command.
5106 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5107 */
5108 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005109did_set_option(
5110 int opt_idx,
5111 int opt_flags, /* possibly with OPT_MODELINE */
5112 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005113{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005114 long_u *p;
5115
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005116 options[opt_idx].flags |= P_WAS_SET;
5117
5118 /* When an option is set in the sandbox, from a modeline or in secure mode
5119 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005120 * flag. */
5121 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005122 if (secure
5123#ifdef HAVE_SANDBOX
5124 || sandbox != 0
5125#endif
5126 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005127 *p = *p | P_INSECURE;
5128 else if (new_value)
5129 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005130}
5131
Bram Moolenaar071d4272004-06-13 20:20:40 +00005132 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005133illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134{
5135 if (errbuf == NULL)
5136 return (char_u *)"";
5137 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005138 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005139 return errbuf;
5140}
5141
5142/*
5143 * Convert a key name or string into a key value.
5144 * Used for 'wildchar' and 'cedit' options.
5145 */
5146 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005147string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005148{
5149 if (*arg == '<')
5150 return find_key_option(arg + 1);
5151 if (*arg == '^')
5152 return Ctrl_chr(arg[1]);
5153 return *arg;
5154}
5155
5156#ifdef FEAT_CMDWIN
5157/*
5158 * Check value of 'cedit' and set cedit_key.
5159 * Returns NULL if value is OK, error message otherwise.
5160 */
5161 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005162check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005163{
5164 int n;
5165
5166 if (*p_cedit == NUL)
5167 cedit_key = -1;
5168 else
5169 {
5170 n = string_to_key(p_cedit);
5171 if (vim_isprintc(n))
5172 return e_invarg;
5173 cedit_key = n;
5174 }
5175 return NULL;
5176}
5177#endif
5178
5179#ifdef FEAT_TITLE
5180/*
5181 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5182 * maketitle() to create and display it.
5183 * When switching the title or icon off, call mch_restore_title() to get
5184 * the old value back.
5185 */
5186 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005187did_set_title(
5188 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005189{
5190 if (starting != NO_SCREEN
5191#ifdef FEAT_GUI
5192 && !gui.starting
5193#endif
5194 )
5195 {
5196 maketitle();
5197 if (icon)
5198 {
5199 if (!p_icon)
5200 mch_restore_title(2);
5201 }
5202 else
5203 {
5204 if (!p_title)
5205 mch_restore_title(1);
5206 }
5207 }
5208}
5209#endif
5210
5211/*
5212 * set_options_bin - called when 'bin' changes value.
5213 */
5214 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005215set_options_bin(
5216 int oldval,
5217 int newval,
5218 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005219{
5220 /*
5221 * The option values that are changed when 'bin' changes are
5222 * copied when 'bin is set and restored when 'bin' is reset.
5223 */
5224 if (newval)
5225 {
5226 if (!oldval) /* switched on */
5227 {
5228 if (!(opt_flags & OPT_GLOBAL))
5229 {
5230 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5231 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5232 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5233 curbuf->b_p_et_nobin = curbuf->b_p_et;
5234 }
5235 if (!(opt_flags & OPT_LOCAL))
5236 {
5237 p_tw_nobin = p_tw;
5238 p_wm_nobin = p_wm;
5239 p_ml_nobin = p_ml;
5240 p_et_nobin = p_et;
5241 }
5242 }
5243
5244 if (!(opt_flags & OPT_GLOBAL))
5245 {
5246 curbuf->b_p_tw = 0; /* no automatic line wrap */
5247 curbuf->b_p_wm = 0; /* no automatic line wrap */
5248 curbuf->b_p_ml = 0; /* no modelines */
5249 curbuf->b_p_et = 0; /* no expandtab */
5250 }
5251 if (!(opt_flags & OPT_LOCAL))
5252 {
5253 p_tw = 0;
5254 p_wm = 0;
5255 p_ml = FALSE;
5256 p_et = FALSE;
5257 p_bin = TRUE; /* needed when called for the "-b" argument */
5258 }
5259 }
5260 else if (oldval) /* switched off */
5261 {
5262 if (!(opt_flags & OPT_GLOBAL))
5263 {
5264 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5265 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5266 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5267 curbuf->b_p_et = curbuf->b_p_et_nobin;
5268 }
5269 if (!(opt_flags & OPT_LOCAL))
5270 {
5271 p_tw = p_tw_nobin;
5272 p_wm = p_wm_nobin;
5273 p_ml = p_ml_nobin;
5274 p_et = p_et_nobin;
5275 }
5276 }
5277}
5278
5279#ifdef FEAT_VIMINFO
5280/*
5281 * Find the parameter represented by the given character (eg ', :, ", or /),
5282 * and return its associated value in the 'viminfo' string.
5283 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005284 * If the parameter is not specified in the string or there is no following
5285 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005286 */
5287 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005288get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005289{
5290 char_u *p;
5291
5292 p = find_viminfo_parameter(type);
5293 if (p != NULL && VIM_ISDIGIT(*p))
5294 return atoi((char *)p);
5295 return -1;
5296}
5297
5298/*
5299 * Find the parameter represented by the given character (eg ''', ':', '"', or
5300 * '/') in the 'viminfo' option and return a pointer to the string after it.
5301 * Return NULL if the parameter is not specified in the string.
5302 */
5303 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005304find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005305{
5306 char_u *p;
5307
5308 for (p = p_viminfo; *p; ++p)
5309 {
5310 if (*p == type)
5311 return p + 1;
5312 if (*p == 'n') /* 'n' is always the last one */
5313 break;
5314 p = vim_strchr(p, ','); /* skip until next ',' */
5315 if (p == NULL) /* hit the end without finding parameter */
5316 break;
5317 }
5318 return NULL;
5319}
5320#endif
5321
5322/*
5323 * Expand environment variables for some string options.
5324 * These string options cannot be indirect!
5325 * If "val" is NULL expand the current value of the option.
5326 * Return pointer to NameBuff, or NULL when not expanded.
5327 */
5328 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005329option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330{
5331 /* if option doesn't need expansion nothing to do */
5332 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5333 return NULL;
5334
5335 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5336 * expand_env() would truncate the string. */
5337 if (val != NULL && STRLEN(val) > MAXPATHL)
5338 return NULL;
5339
5340 if (val == NULL)
5341 val = *(char_u **)options[opt_idx].var;
5342
5343 /*
5344 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5345 * Escape spaces when expanding 'tags', they are used to separate file
5346 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005347 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 */
5349 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005350 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005351#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005352 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5353#endif
5354 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5356 return NULL;
5357
5358 return NameBuff;
5359}
5360
5361/*
5362 * After setting various option values: recompute variables that depend on
5363 * option values.
5364 */
5365 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005366didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367{
5368 /* initialize the table for 'iskeyword' et.al. */
5369 (void)init_chartab();
5370
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005371#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005375 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376#ifdef FEAT_SESSION
5377 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5378 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5379#endif
5380#ifdef FEAT_FOLDING
5381 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5382#endif
5383 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005384 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385#ifdef FEAT_VIRTUALEDIT
5386 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5387#endif
5388#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5389 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5390#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005391#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005392 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005393 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005394 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005395 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5398 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5399#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005400#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005401 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5402#endif
5403#ifdef FEAT_CMDWIN
5404 /* set cedit_key */
5405 (void)check_cedit();
5406#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005407#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005408 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005409#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005410#ifdef FEAT_LINEBREAK
5411 /* initialize the table for 'breakat'. */
5412 fill_breakat_flags();
5413#endif
5414
5415}
5416
5417/*
5418 * More side effects of setting options.
5419 */
5420 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005421didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005422{
5423 /* Initialize the highlight_attr[] table. */
5424 (void)highlight_changed();
5425
5426 /* Parse default for 'wildmode' */
5427 check_opt_wim();
5428
5429 (void)set_chars_option(&p_lcs);
5430#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5431 /* Parse default for 'fillchars'. */
5432 (void)set_chars_option(&p_fcs);
5433#endif
5434
5435#ifdef FEAT_CLIPBOARD
5436 /* Parse default for 'clipboard' */
5437 (void)check_clipboard_option();
5438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005439}
5440
5441/*
5442 * Check for string options that are NULL (normally only termcap options).
5443 */
5444 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005445check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446{
5447 int opt_idx;
5448
5449 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5450 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5451 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5452}
5453
5454/*
5455 * Check string options in a buffer for NULL value.
5456 */
5457 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005458check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459{
5460#if defined(FEAT_QUICKFIX)
5461 check_string_option(&buf->b_p_bh);
5462 check_string_option(&buf->b_p_bt);
5463#endif
5464#ifdef FEAT_MBYTE
5465 check_string_option(&buf->b_p_fenc);
5466#endif
5467 check_string_option(&buf->b_p_ff);
5468#ifdef FEAT_FIND_ID
5469 check_string_option(&buf->b_p_def);
5470 check_string_option(&buf->b_p_inc);
5471# ifdef FEAT_EVAL
5472 check_string_option(&buf->b_p_inex);
5473# endif
5474#endif
5475#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5476 check_string_option(&buf->b_p_inde);
5477 check_string_option(&buf->b_p_indk);
5478#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005479#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5480 check_string_option(&buf->b_p_bexpr);
5481#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005482#if defined(FEAT_CRYPT)
5483 check_string_option(&buf->b_p_cm);
5484#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005485#if defined(FEAT_EVAL)
5486 check_string_option(&buf->b_p_fex);
5487#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005488#ifdef FEAT_CRYPT
5489 check_string_option(&buf->b_p_key);
5490#endif
5491 check_string_option(&buf->b_p_kp);
5492 check_string_option(&buf->b_p_mps);
5493 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005494 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495 check_string_option(&buf->b_p_isk);
5496#ifdef FEAT_COMMENTS
5497 check_string_option(&buf->b_p_com);
5498#endif
5499#ifdef FEAT_FOLDING
5500 check_string_option(&buf->b_p_cms);
5501#endif
5502 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005503#ifdef FEAT_TEXTOBJ
5504 check_string_option(&buf->b_p_qe);
5505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005506#ifdef FEAT_SYN_HL
5507 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005508 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005509#endif
5510#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005511 check_string_option(&buf->b_s.b_p_spc);
5512 check_string_option(&buf->b_s.b_p_spf);
5513 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514#endif
5515#ifdef FEAT_SEARCHPATH
5516 check_string_option(&buf->b_p_sua);
5517#endif
5518#ifdef FEAT_CINDENT
5519 check_string_option(&buf->b_p_cink);
5520 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005521 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522#endif
5523#ifdef FEAT_AUTOCMD
5524 check_string_option(&buf->b_p_ft);
5525#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5527 check_string_option(&buf->b_p_cinw);
5528#endif
5529#ifdef FEAT_INS_EXPAND
5530 check_string_option(&buf->b_p_cpt);
5531#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005532#ifdef FEAT_COMPL_FUNC
5533 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005534 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005535#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536#ifdef FEAT_KEYMAP
5537 check_string_option(&buf->b_p_keymap);
5538#endif
5539#ifdef FEAT_QUICKFIX
5540 check_string_option(&buf->b_p_gp);
5541 check_string_option(&buf->b_p_mp);
5542 check_string_option(&buf->b_p_efm);
5543#endif
5544 check_string_option(&buf->b_p_ep);
5545 check_string_option(&buf->b_p_path);
5546 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005547 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005548#ifdef FEAT_INS_EXPAND
5549 check_string_option(&buf->b_p_dict);
5550 check_string_option(&buf->b_p_tsr);
5551#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005552#ifdef FEAT_LISP
5553 check_string_option(&buf->b_p_lw);
5554#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005555 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005556}
5557
5558/*
5559 * Free the string allocated for an option.
5560 * Checks for the string being empty_option. This may happen if we're out of
5561 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5562 * check_options().
5563 * Does NOT check for P_ALLOCED flag!
5564 */
5565 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005566free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005567{
5568 if (p != empty_option)
5569 vim_free(p);
5570}
5571
5572 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005573clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005574{
5575 if (*pp != empty_option)
5576 vim_free(*pp);
5577 *pp = empty_option;
5578}
5579
5580 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005581check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582{
5583 if (*pp == NULL)
5584 *pp = empty_option;
5585}
5586
5587/*
5588 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5589 */
5590 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005591set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005592{
5593 int opt_idx;
5594
5595 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5596 if (options[opt_idx].var == (char_u *)p)
5597 {
5598 options[opt_idx].flags |= P_ALLOCED;
5599 return;
5600 }
5601 return; /* cannot happen: didn't find it! */
5602}
5603
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005604#if defined(FEAT_EVAL) || defined(PROTO)
5605/*
5606 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5607 * Return FALSE when it wasn't.
5608 * Return -1 for an unknown option.
5609 */
5610 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005611was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005612{
5613 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005614 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005615
5616 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005617 {
5618 flagp = insecure_flag(idx, opt_flags);
5619 return (*flagp & P_INSECURE) != 0;
5620 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005621 EMSG2(_(e_intern2), "was_set_insecurely()");
5622 return -1;
5623}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005624
5625/*
5626 * Get a pointer to the flags used for the P_INSECURE flag of option
5627 * "opt_idx". For some local options a local flags field is used.
5628 */
5629 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005630insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005631{
5632 if (opt_flags & OPT_LOCAL)
5633 switch ((int)options[opt_idx].indir)
5634 {
5635#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005636 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005637#endif
5638#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005639# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005640 case PV_FDE: return &curwin->w_p_fde_flags;
5641 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005642# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005643# ifdef FEAT_BEVAL
5644 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5645# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005646# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005647 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005648# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005649 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005650# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005651 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005652# endif
5653#endif
5654 }
5655
5656 /* Nothing special, return global flags field. */
5657 return &options[opt_idx].flags;
5658}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005659#endif
5660
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005661#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005662static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005663
5664/*
5665 * Redraw the window title and/or tab page text later.
5666 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005667static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005668{
5669 need_maketitle = TRUE;
5670# ifdef FEAT_WINDOWS
5671 redraw_tabline = TRUE;
5672# endif
5673}
5674#endif
5675
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676/*
5677 * Set a string option to a new value (without checking the effect).
5678 * The string is copied into allocated memory.
5679 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005680 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005681 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682 */
5683 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005684set_string_option_direct(
5685 char_u *name,
5686 int opt_idx,
5687 char_u *val,
5688 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5689 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690{
5691 char_u *s;
5692 char_u **varp;
5693 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005694 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695
Bram Moolenaar89d40322006-08-29 15:30:07 +00005696 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005698 idx = findoption(name);
5699 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005700 {
5701 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005702 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005703 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705 }
5706
Bram Moolenaar89d40322006-08-29 15:30:07 +00005707 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708 return;
5709
5710 s = vim_strsave(val);
5711 if (s != NULL)
5712 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005713 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005714 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005715 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716 free_string_option(*varp);
5717 *varp = s;
5718
5719 /* For buffer/window local option may also set the global value. */
5720 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005721 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722
Bram Moolenaar89d40322006-08-29 15:30:07 +00005723 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005724
5725 /* When setting both values of a global option with a local value,
5726 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005727 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728 {
5729 free_string_option(*varp);
5730 *varp = empty_option;
5731 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005732# ifdef FEAT_EVAL
5733 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005734 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005735 set_sid == 0 ? current_SID : set_sid);
5736# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737 }
5738}
5739
5740/*
5741 * Set global value for string option when it's a local option.
5742 */
5743 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005744set_string_option_global(
5745 int opt_idx, /* option index */
5746 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747{
5748 char_u **p, *s;
5749
5750 /* the global value is always allocated */
5751 if (options[opt_idx].var == VAR_WIN)
5752 p = (char_u **)GLOBAL_WO(varp);
5753 else
5754 p = (char_u **)options[opt_idx].var;
5755 if (options[opt_idx].indir != PV_NONE
5756 && p != varp
5757 && (s = vim_strsave(*varp)) != NULL)
5758 {
5759 free_string_option(*p);
5760 *p = s;
5761 }
5762}
5763
5764/*
5765 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005766 *
5767 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005768 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005769 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005770set_string_option(
5771 int opt_idx,
5772 char_u *value,
5773 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005774{
5775 char_u *s;
5776 char_u **varp;
5777 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005778#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5779 char_u *saved_oldval = NULL;
5780#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005781 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005782
5783 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005784 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785
5786 s = vim_strsave(value);
5787 if (s != NULL)
5788 {
5789 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5790 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005791 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005792 ? OPT_GLOBAL : OPT_LOCAL)
5793 : opt_flags);
5794 oldval = *varp;
5795 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005796
5797#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005798 if (!starting
5799# ifdef FEAT_CRYPT
5800 && options[opt_idx].indir != PV_KEY
5801# endif
5802 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005803 saved_oldval = vim_strsave(oldval);
5804#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005805 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5806 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005807 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005808
5809 /* call autocomamnd after handling side effects */
5810#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5811 if (saved_oldval != NULL)
5812 {
5813 char_u buf_type[7];
5814 sprintf((char *)buf_type, "%s",
5815 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005816 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5817 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005818 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5819 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5820 reset_v_option_vars();
5821 vim_free(saved_oldval);
5822 }
5823#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005824 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005825 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826}
5827
5828/*
5829 * Handle string options that need some action to perform when changed.
5830 * Returns NULL for success, or an error message for an error.
5831 */
5832 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005833did_set_string_option(
5834 int opt_idx, /* index in options[] table */
5835 char_u **varp, /* pointer to the option variable */
5836 int new_value_alloced, /* new value was allocated */
5837 char_u *oldval, /* previous value of the option */
5838 char_u *errbuf, /* buffer for errors, or NULL */
5839 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005840{
5841 char_u *errmsg = NULL;
5842 char_u *s, *p;
5843 int did_chartab = FALSE;
5844 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005845 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005846#ifdef FEAT_GUI
5847 /* set when changing an option that only requires a redraw in the GUI */
5848 int redraw_gui_only = FALSE;
5849#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005850
5851 /* Get the global option to compare with, otherwise we would have to check
5852 * two values for all local options. */
5853 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5854
5855 /* Disallow changing some options from secure mode */
5856 if ((secure
5857#ifdef HAVE_SANDBOX
5858 || sandbox != 0
5859#endif
5860 ) && (options[opt_idx].flags & P_SECURE))
5861 {
5862 errmsg = e_secure;
5863 }
5864
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005865 /* Check for a "normal" file name in some options. Disallow a path
5866 * separator (slash and/or backslash), wildcards and characters that are
5867 * often illegal in a file name. */
5868 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005869 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005870 {
5871 errmsg = e_invarg;
5872 }
5873
Bram Moolenaar071d4272004-06-13 20:20:40 +00005874 /* 'term' */
5875 else if (varp == &T_NAME)
5876 {
5877 if (T_NAME[0] == NUL)
5878 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5879#ifdef FEAT_GUI
5880 if (gui.in_use)
5881 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5882 else if (term_is_gui(T_NAME))
5883 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5884#endif
5885 else if (set_termname(T_NAME) == FAIL)
5886 errmsg = (char_u *)N_("E522: Not found in termcap");
5887 else
5888 /* Screen colors may have changed. */
5889 redraw_later_clear();
5890 }
5891
5892 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005893 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005895 char_u *bkc = p_bkc;
5896 unsigned int *flags = &bkc_flags;
5897
5898 if (opt_flags & OPT_LOCAL)
5899 {
5900 bkc = curbuf->b_p_bkc;
5901 flags = &curbuf->b_bkc_flags;
5902 }
5903
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005904 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5905 /* make the local value empty: use the global value */
5906 *flags = 0;
5907 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005908 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005909 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5910 errmsg = e_invarg;
5911 if ((((int)*flags & BKC_AUTO) != 0)
5912 + (((int)*flags & BKC_YES) != 0)
5913 + (((int)*flags & BKC_NO) != 0) != 1)
5914 {
5915 /* Must have exactly one of "auto", "yes" and "no". */
5916 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5917 errmsg = e_invarg;
5918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 }
5920 }
5921
5922 /* 'backupext' and 'patchmode' */
5923 else if (varp == &p_bex || varp == &p_pm)
5924 {
5925 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5926 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5927 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5928 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005929#ifdef FEAT_LINEBREAK
5930 /* 'breakindentopt' */
5931 else if (varp == &curwin->w_p_briopt)
5932 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005933 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005934 errmsg = e_invarg;
5935 }
5936#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937
5938 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005939 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005941 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005942 */
5943 else if ( varp == &p_isi
5944 || varp == &(curbuf->b_p_isk)
5945 || varp == &p_isp
5946 || varp == &p_isf)
5947 {
5948 if (init_chartab() == FAIL)
5949 {
5950 did_chartab = TRUE; /* need to restore it below */
5951 errmsg = e_invarg; /* error in value */
5952 }
5953 }
5954
5955 /* 'helpfile' */
5956 else if (varp == &p_hf)
5957 {
5958 /* May compute new values for $VIM and $VIMRUNTIME */
5959 if (didset_vim)
5960 {
5961 vim_setenv((char_u *)"VIM", (char_u *)"");
5962 didset_vim = FALSE;
5963 }
5964 if (didset_vimruntime)
5965 {
5966 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5967 didset_vimruntime = FALSE;
5968 }
5969 }
5970
Bram Moolenaar1a384422010-07-14 19:53:30 +02005971#ifdef FEAT_SYN_HL
5972 /* 'colorcolumn' */
5973 else if (varp == &curwin->w_p_cc)
5974 errmsg = check_colorcolumn(curwin);
5975#endif
5976
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977#ifdef FEAT_MULTI_LANG
5978 /* 'helplang' */
5979 else if (varp == &p_hlg)
5980 {
5981 /* Check for "", "ab", "ab,cd", etc. */
5982 for (s = p_hlg; *s != NUL; s += 3)
5983 {
5984 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5985 {
5986 errmsg = e_invarg;
5987 break;
5988 }
5989 if (s[2] == NUL)
5990 break;
5991 }
5992 }
5993#endif
5994
5995 /* 'highlight' */
5996 else if (varp == &p_hl)
5997 {
5998 if (highlight_changed() == FAIL)
5999 errmsg = e_invarg; /* invalid flags */
6000 }
6001
6002 /* 'nrformats' */
6003 else if (gvarp == &p_nf)
6004 {
6005 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6006 errmsg = e_invarg;
6007 }
6008
6009#ifdef FEAT_SESSION
6010 /* 'sessionoptions' */
6011 else if (varp == &p_ssop)
6012 {
6013 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6014 errmsg = e_invarg;
6015 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6016 {
6017 /* Don't allow both "sesdir" and "curdir". */
6018 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6019 errmsg = e_invarg;
6020 }
6021 }
6022 /* 'viewoptions' */
6023 else if (varp == &p_vop)
6024 {
6025 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6026 errmsg = e_invarg;
6027 }
6028#endif
6029
6030 /* 'scrollopt' */
6031#ifdef FEAT_SCROLLBIND
6032 else if (varp == &p_sbo)
6033 {
6034 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6035 errmsg = e_invarg;
6036 }
6037#endif
6038
6039 /* 'ambiwidth' */
6040#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006041 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006042 {
6043 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6044 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006045 else if (set_chars_option(&p_lcs) != NULL)
6046 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6047# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6048 else if (set_chars_option(&p_fcs) != NULL)
6049 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6050# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006051 }
6052#endif
6053
6054 /* 'background' */
6055 else if (varp == &p_bg)
6056 {
6057 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6058 {
6059#ifdef FEAT_EVAL
6060 int dark = (*p_bg == 'd');
6061#endif
6062
6063 init_highlight(FALSE, FALSE);
6064
6065#ifdef FEAT_EVAL
6066 if (dark != (*p_bg == 'd')
6067 && get_var_value((char_u *)"g:colors_name") != NULL)
6068 {
6069 /* The color scheme must have set 'background' back to another
6070 * value, that's not what we want here. Disable the color
6071 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006072 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073 free_string_option(p_bg);
6074 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6075 check_string_option(&p_bg);
6076 init_highlight(FALSE, FALSE);
6077 }
6078#endif
6079 }
6080 else
6081 errmsg = e_invarg;
6082 }
6083
6084 /* 'wildmode' */
6085 else if (varp == &p_wim)
6086 {
6087 if (check_opt_wim() == FAIL)
6088 errmsg = e_invarg;
6089 }
6090
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006091#ifdef FEAT_CMDL_COMPL
6092 /* 'wildoptions' */
6093 else if (varp == &p_wop)
6094 {
6095 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6096 errmsg = e_invarg;
6097 }
6098#endif
6099
Bram Moolenaar071d4272004-06-13 20:20:40 +00006100#ifdef FEAT_WAK
6101 /* 'winaltkeys' */
6102 else if (varp == &p_wak)
6103 {
6104 if (*p_wak == NUL
6105 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6106 errmsg = e_invarg;
6107# ifdef FEAT_MENU
6108# ifdef FEAT_GUI_MOTIF
6109 else if (gui.in_use)
6110 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6111# else
6112# ifdef FEAT_GUI_GTK
6113 else if (gui.in_use)
6114 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6115# endif
6116# endif
6117# endif
6118 }
6119#endif
6120
6121#ifdef FEAT_AUTOCMD
6122 /* 'eventignore' */
6123 else if (varp == &p_ei)
6124 {
6125 if (check_ei() == FAIL)
6126 errmsg = e_invarg;
6127 }
6128#endif
6129
6130#ifdef FEAT_MBYTE
6131 /* 'encoding' and 'fileencoding' */
6132 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6133 {
6134 if (gvarp == &p_fenc)
6135 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006136 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 errmsg = e_modifiable;
6138 else if (vim_strchr(*varp, ',') != NULL)
6139 /* No comma allowed in 'fileencoding'; catches confusing it
6140 * with 'fileencodings'. */
6141 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006143 {
6144# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006145 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006146 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006147# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006148 /* Add 'fileencoding' to the swap file. */
6149 ml_setflags(curbuf);
6150 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151 }
6152 if (errmsg == NULL)
6153 {
6154 /* canonize the value, so that STRCMP() can be used on it */
6155 p = enc_canonize(*varp);
6156 if (p != NULL)
6157 {
6158 vim_free(*varp);
6159 *varp = p;
6160 }
6161 if (varp == &p_enc)
6162 {
6163 errmsg = mb_init();
6164# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006165 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006166# endif
6167 }
6168 }
6169
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006170# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006171 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6172 {
6173 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6174 if (STRCMP(p_tenc, "utf-8") != 0)
6175 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6176 }
6177# endif
6178
6179 if (errmsg == NULL)
6180 {
6181# ifdef FEAT_KEYMAP
6182 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6183 * (with another encoding). */
6184 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6185 (void)keymap_init();
6186# endif
6187
6188 /* When 'termencoding' is not empty and 'encoding' changes or when
6189 * 'termencoding' changes, need to setup for keyboard input and
6190 * display output conversion. */
6191 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6192 {
6193 convert_setup(&input_conv, p_tenc, p_enc);
6194 convert_setup(&output_conv, p_enc, p_tenc);
6195 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006196
6197# if defined(WIN3264) && defined(FEAT_MBYTE)
6198 /* $HOME may have characters in active code page. */
6199 if (varp == &p_enc)
6200 init_homedir();
6201# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 }
6203 }
6204#endif
6205
6206#if defined(FEAT_POSTSCRIPT)
6207 else if (varp == &p_penc)
6208 {
6209 /* Canonize printencoding if VIM standard one */
6210 p = enc_canonize(p_penc);
6211 if (p != NULL)
6212 {
6213 vim_free(p_penc);
6214 p_penc = p;
6215 }
6216 else
6217 {
6218 /* Ensure lower case and '-' for '_' */
6219 for (s = p_penc; *s != NUL; s++)
6220 {
6221 if (*s == '_')
6222 *s = '-';
6223 else
6224 *s = TOLOWER_ASC(*s);
6225 }
6226 }
6227 }
6228#endif
6229
Bram Moolenaar9372a112005-12-06 19:59:18 +00006230#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006231 else if (varp == &p_imak)
6232 {
6233 if (gui.in_use && !im_xim_isvalid_imactivate())
6234 errmsg = e_invarg;
6235 }
6236#endif
6237
6238#ifdef FEAT_KEYMAP
6239 else if (varp == &curbuf->b_p_keymap)
6240 {
6241 /* load or unload key mapping tables */
6242 errmsg = keymap_init();
6243
Bram Moolenaarfab06232009-03-04 03:13:35 +00006244 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006245 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006246 if (*curbuf->b_p_keymap != NUL)
6247 {
6248 /* Installed a new keymap, switch on using it. */
6249 curbuf->b_p_iminsert = B_IMODE_LMAP;
6250 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6251 curbuf->b_p_imsearch = B_IMODE_LMAP;
6252 }
6253 else
6254 {
6255 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6256 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6257 curbuf->b_p_iminsert = B_IMODE_NONE;
6258 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6259 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6260 }
6261 if ((opt_flags & OPT_LOCAL) == 0)
6262 {
6263 set_iminsert_global();
6264 set_imsearch_global();
6265 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266# ifdef FEAT_WINDOWS
6267 status_redraw_curbuf();
6268# endif
6269 }
6270 }
6271#endif
6272
6273 /* 'fileformat' */
6274 else if (gvarp == &p_ff)
6275 {
6276 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6277 errmsg = e_modifiable;
6278 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6279 errmsg = e_invarg;
6280 else
6281 {
6282 /* may also change 'textmode' */
6283 if (get_fileformat(curbuf) == EOL_DOS)
6284 curbuf->b_p_tx = TRUE;
6285 else
6286 curbuf->b_p_tx = FALSE;
6287#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006288 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006290 /* update flag in swap file */
6291 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006292 /* Redraw needed when switching to/from "mac": a CR in the text
6293 * will be displayed differently. */
6294 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6295 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296 }
6297 }
6298
6299 /* 'fileformats' */
6300 else if (varp == &p_ffs)
6301 {
6302 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6303 errmsg = e_invarg;
6304 else
6305 {
6306 /* also change 'textauto' */
6307 if (*p_ffs == NUL)
6308 p_ta = FALSE;
6309 else
6310 p_ta = TRUE;
6311 }
6312 }
6313
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006314#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315 /* 'cryptkey' */
6316 else if (gvarp == &p_key)
6317 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006318# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319 /* Make sure the ":set" command doesn't show the new value in the
6320 * history. */
6321 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006322# endif
6323 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6324 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006325 ml_set_crypt_key(curbuf, oldval,
6326 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006327 }
6328
6329 else if (gvarp == &p_cm)
6330 {
6331 if (opt_flags & OPT_LOCAL)
6332 p = curbuf->b_p_cm;
6333 else
6334 p = p_cm;
6335 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6336 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006337 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006338 errmsg = e_invarg;
6339 else
6340 {
6341 /* When setting the global value to empty, make it "zip". */
6342 if (*p_cm == NUL)
6343 {
6344 if (new_value_alloced)
6345 free_string_option(p_cm);
6346 p_cm = vim_strsave((char_u *)"zip");
6347 new_value_alloced = TRUE;
6348 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006349 /* When using ":set cm=name" the local value is going to be empty.
6350 * Do that here, otherwise the crypt functions will still use the
6351 * local value. */
6352 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6353 {
6354 free_string_option(curbuf->b_p_cm);
6355 curbuf->b_p_cm = empty_option;
6356 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006357
6358 /* Need to update the swapfile when the effective method changed.
6359 * Set "s" to the effective old value, "p" to the effective new
6360 * method and compare. */
6361 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6362 s = p_cm; /* was previously using the global value */
6363 else
6364 s = oldval;
6365 if (*curbuf->b_p_cm == NUL)
6366 p = p_cm; /* is now using the global value */
6367 else
6368 p = curbuf->b_p_cm;
6369 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006370 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006371
6372 /* If the global value changes need to update the swapfile for all
6373 * buffers using that value. */
6374 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6375 {
6376 buf_T *buf;
6377
Bram Moolenaar29323592016-07-24 22:04:11 +02006378 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006379 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006380 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006381 }
6382 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 }
6384#endif
6385
6386 /* 'matchpairs' */
6387 else if (gvarp == &p_mps)
6388 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006389#ifdef FEAT_MBYTE
6390 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006391 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006392 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006393 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006394 int x2 = -1;
6395 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006396
6397 if (*p != NUL)
6398 p += mb_ptr2len(p);
6399 if (*p != NUL)
6400 x2 = *p++;
6401 if (*p != NUL)
6402 {
6403 x3 = mb_ptr2char(p);
6404 p += mb_ptr2len(p);
6405 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006406 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006407 {
6408 errmsg = e_invarg;
6409 break;
6410 }
6411 if (*p == NUL)
6412 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006413 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006414 }
6415 else
6416#endif
6417 {
6418 /* Check for "x:y,x:y" */
6419 for (p = *varp; *p != NUL; p += 4)
6420 {
6421 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6422 {
6423 errmsg = e_invarg;
6424 break;
6425 }
6426 if (p[3] == NUL)
6427 break;
6428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006429 }
6430 }
6431
6432#ifdef FEAT_COMMENTS
6433 /* 'comments' */
6434 else if (gvarp == &p_com)
6435 {
6436 for (s = *varp; *s; )
6437 {
6438 while (*s && *s != ':')
6439 {
6440 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6441 && !VIM_ISDIGIT(*s) && *s != '-')
6442 {
6443 errmsg = illegal_char(errbuf, *s);
6444 break;
6445 }
6446 ++s;
6447 }
6448 if (*s++ == NUL)
6449 errmsg = (char_u *)N_("E524: Missing colon");
6450 else if (*s == ',' || *s == NUL)
6451 errmsg = (char_u *)N_("E525: Zero length string");
6452 if (errmsg != NULL)
6453 break;
6454 while (*s && *s != ',')
6455 {
6456 if (*s == '\\' && s[1] != NUL)
6457 ++s;
6458 ++s;
6459 }
6460 s = skip_to_option_part(s);
6461 }
6462 }
6463#endif
6464
6465 /* 'listchars' */
6466 else if (varp == &p_lcs)
6467 {
6468 errmsg = set_chars_option(varp);
6469 }
6470
6471#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6472 /* 'fillchars' */
6473 else if (varp == &p_fcs)
6474 {
6475 errmsg = set_chars_option(varp);
6476 }
6477#endif
6478
6479#ifdef FEAT_CMDWIN
6480 /* 'cedit' */
6481 else if (varp == &p_cedit)
6482 {
6483 errmsg = check_cedit();
6484 }
6485#endif
6486
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006487 /* 'verbosefile' */
6488 else if (varp == &p_vfile)
6489 {
6490 verbose_stop();
6491 if (*p_vfile != NUL && verbose_open() == FAIL)
6492 errmsg = e_invarg;
6493 }
6494
Bram Moolenaar071d4272004-06-13 20:20:40 +00006495#ifdef FEAT_VIMINFO
6496 /* 'viminfo' */
6497 else if (varp == &p_viminfo)
6498 {
6499 for (s = p_viminfo; *s;)
6500 {
6501 /* Check it's a valid character */
6502 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6503 {
6504 errmsg = illegal_char(errbuf, *s);
6505 break;
6506 }
6507 if (*s == 'n') /* name is always last one */
6508 {
6509 break;
6510 }
6511 else if (*s == 'r') /* skip until next ',' */
6512 {
6513 while (*++s && *s != ',')
6514 ;
6515 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006516 else if (*s == '%')
6517 {
6518 /* optional number */
6519 while (vim_isdigit(*++s))
6520 ;
6521 }
6522 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006523 ++s; /* no extra chars */
6524 else /* must have a number */
6525 {
6526 while (vim_isdigit(*++s))
6527 ;
6528
6529 if (!VIM_ISDIGIT(*(s - 1)))
6530 {
6531 if (errbuf != NULL)
6532 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006533 sprintf((char *)errbuf,
6534 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006535 transchar_byte(*(s - 1)));
6536 errmsg = errbuf;
6537 }
6538 else
6539 errmsg = (char_u *)"";
6540 break;
6541 }
6542 }
6543 if (*s == ',')
6544 ++s;
6545 else if (*s)
6546 {
6547 if (errbuf != NULL)
6548 errmsg = (char_u *)N_("E527: Missing comma");
6549 else
6550 errmsg = (char_u *)"";
6551 break;
6552 }
6553 }
6554 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6555 errmsg = (char_u *)N_("E528: Must specify a ' value");
6556 }
6557#endif /* FEAT_VIMINFO */
6558
6559 /* terminal options */
6560 else if (istermoption(&options[opt_idx]) && full_screen)
6561 {
6562 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6563 if (varp == &T_CCO)
6564 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006565 int colors = atoi((char *)T_CCO);
6566
6567 /* Only reinitialize colors if t_Co value has really changed to
6568 * avoid expensive reload of colorscheme if t_Co is set to the
6569 * same value multiple times. */
6570 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006571 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006572 t_colors = colors;
6573 if (t_colors <= 1)
6574 {
6575 if (new_value_alloced)
6576 vim_free(T_CCO);
6577 T_CCO = empty_option;
6578 }
6579 /* We now have a different color setup, initialize it again. */
6580 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 }
6583 ttest(FALSE);
6584 if (varp == &T_ME)
6585 {
6586 out_str(T_ME);
6587 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006588#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006589 /* Since t_me has been set, this probably means that the user
6590 * wants to use this as default colors. Need to reset default
6591 * background/foreground colors. */
6592 mch_set_normal_colors();
6593#endif
6594 }
6595 }
6596
6597#ifdef FEAT_LINEBREAK
6598 /* 'showbreak' */
6599 else if (varp == &p_sbr)
6600 {
6601 for (s = p_sbr; *s; )
6602 {
6603 if (ptr2cells(s) != 1)
6604 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006605 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 }
6607 }
6608#endif
6609
6610#ifdef FEAT_GUI
6611 /* 'guifont' */
6612 else if (varp == &p_guifont)
6613 {
6614 if (gui.in_use)
6615 {
6616 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006617# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 /*
6619 * Put up a font dialog and let the user select a new value.
6620 * If this is cancelled go back to the old value but don't
6621 * give an error message.
6622 */
6623 if (STRCMP(p, "*") == 0)
6624 {
6625 p = gui_mch_font_dialog(oldval);
6626
6627 if (new_value_alloced)
6628 free_string_option(p_guifont);
6629
6630 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6631 new_value_alloced = TRUE;
6632 }
6633# endif
6634 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6635 {
6636# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6637 if (STRCMP(p_guifont, "*") == 0)
6638 {
6639 /* Dialog was cancelled: Keep the old value without giving
6640 * an error message. */
6641 if (new_value_alloced)
6642 free_string_option(p_guifont);
6643 p_guifont = vim_strsave(oldval);
6644 new_value_alloced = TRUE;
6645 }
6646 else
6647# endif
6648 errmsg = (char_u *)N_("E596: Invalid font(s)");
6649 }
6650 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006651 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006652 }
6653# ifdef FEAT_XFONTSET
6654 else if (varp == &p_guifontset)
6655 {
6656 if (STRCMP(p_guifontset, "*") == 0)
6657 errmsg = (char_u *)N_("E597: can't select fontset");
6658 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6659 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006660 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006661 }
6662# endif
6663# ifdef FEAT_MBYTE
6664 else if (varp == &p_guifontwide)
6665 {
6666 if (STRCMP(p_guifontwide, "*") == 0)
6667 errmsg = (char_u *)N_("E533: can't select wide font");
6668 else if (gui_get_wide_font() == FAIL)
6669 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006670 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006671 }
6672# endif
6673#endif
6674
6675#ifdef CURSOR_SHAPE
6676 /* 'guicursor' */
6677 else if (varp == &p_guicursor)
6678 errmsg = parse_shape_opt(SHAPE_CURSOR);
6679#endif
6680
6681#ifdef FEAT_MOUSESHAPE
6682 /* 'mouseshape' */
6683 else if (varp == &p_mouseshape)
6684 {
6685 errmsg = parse_shape_opt(SHAPE_MOUSE);
6686 update_mouseshape(-1);
6687 }
6688#endif
6689
6690#ifdef FEAT_PRINTER
6691 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006692 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006693# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006694 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006695 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006696# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006697#endif
6698
6699#ifdef FEAT_LANGMAP
6700 /* 'langmap' */
6701 else if (varp == &p_langmap)
6702 langmap_set();
6703#endif
6704
6705#ifdef FEAT_LINEBREAK
6706 /* 'breakat' */
6707 else if (varp == &p_breakat)
6708 fill_breakat_flags();
6709#endif
6710
6711#ifdef FEAT_TITLE
6712 /* 'titlestring' and 'iconstring' */
6713 else if (varp == &p_titlestring || varp == &p_iconstring)
6714 {
6715# ifdef FEAT_STL_OPT
6716 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6717
6718 /* NULL => statusline syntax */
6719 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6720 stl_syntax |= flagval;
6721 else
6722 stl_syntax &= ~flagval;
6723# endif
6724 did_set_title(varp == &p_iconstring);
6725
6726 }
6727#endif
6728
6729#ifdef FEAT_GUI
6730 /* 'guioptions' */
6731 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006732 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006734 redraw_gui_only = TRUE;
6735 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006736#endif
6737
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006738#if defined(FEAT_GUI_TABLINE)
6739 /* 'guitablabel' */
6740 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006741 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006742 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006743 redraw_gui_only = TRUE;
6744 }
6745 /* 'guitabtooltip' */
6746 else if (varp == &p_gtt)
6747 {
6748 redraw_gui_only = TRUE;
6749 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006750#endif
6751
Bram Moolenaar071d4272004-06-13 20:20:40 +00006752#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6753 /* 'ttymouse' */
6754 else if (varp == &p_ttym)
6755 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006756 /* Switch the mouse off before changing the escape sequences used for
6757 * that. */
6758 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6760 errmsg = e_invarg;
6761 else
6762 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006763 if (termcap_active)
6764 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765 }
6766#endif
6767
Bram Moolenaar071d4272004-06-13 20:20:40 +00006768 /* 'selection' */
6769 else if (varp == &p_sel)
6770 {
6771 if (*p_sel == NUL
6772 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6773 errmsg = e_invarg;
6774 }
6775
6776 /* 'selectmode' */
6777 else if (varp == &p_slm)
6778 {
6779 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6780 errmsg = e_invarg;
6781 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006782
6783#ifdef FEAT_BROWSE
6784 /* 'browsedir' */
6785 else if (varp == &p_bsdir)
6786 {
6787 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6788 && !mch_isdir(p_bsdir))
6789 errmsg = e_invarg;
6790 }
6791#endif
6792
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 /* 'keymodel' */
6794 else if (varp == &p_km)
6795 {
6796 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6797 errmsg = e_invarg;
6798 else
6799 {
6800 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6801 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6802 }
6803 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006804
6805 /* 'mousemodel' */
6806 else if (varp == &p_mousem)
6807 {
6808 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6809 errmsg = e_invarg;
6810#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6811 else if (*p_mousem != *oldval)
6812 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6813 * to create or delete the popup menus. */
6814 gui_motif_update_mousemodel(root_menu);
6815#endif
6816 }
6817
6818 /* 'switchbuf' */
6819 else if (varp == &p_swb)
6820 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006821 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822 errmsg = e_invarg;
6823 }
6824
6825 /* 'debug' */
6826 else if (varp == &p_debug)
6827 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006828 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 errmsg = e_invarg;
6830 }
6831
6832 /* 'display' */
6833 else if (varp == &p_dy)
6834 {
6835 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6836 errmsg = e_invarg;
6837 else
6838 (void)init_chartab();
6839
6840 }
6841
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006842#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006843 /* 'eadirection' */
6844 else if (varp == &p_ead)
6845 {
6846 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6847 errmsg = e_invarg;
6848 }
6849#endif
6850
6851#ifdef FEAT_CLIPBOARD
6852 /* 'clipboard' */
6853 else if (varp == &p_cb)
6854 errmsg = check_clipboard_option();
6855#endif
6856
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006857#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006858 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6859 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006860 else if (varp == &(curwin->w_s->b_p_spl)
6861 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006862 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006863 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006864 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006865 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006866 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006867 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006868 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006869 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006870 /* 'spellsuggest' */
6871 else if (varp == &p_sps)
6872 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006873 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006874 errmsg = e_invarg;
6875 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006876 /* 'mkspellmem' */
6877 else if (varp == &p_msm)
6878 {
6879 if (spell_check_msm() != OK)
6880 errmsg = e_invarg;
6881 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006882#endif
6883
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884#ifdef FEAT_QUICKFIX
6885 /* When 'bufhidden' is set, check for valid value. */
6886 else if (gvarp == &p_bh)
6887 {
6888 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6889 errmsg = e_invarg;
6890 }
6891
6892 /* When 'buftype' is set, check for valid value. */
6893 else if (gvarp == &p_bt)
6894 {
6895 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6896 errmsg = e_invarg;
6897 else
6898 {
6899# ifdef FEAT_WINDOWS
6900 if (curwin->w_status_height)
6901 {
6902 curwin->w_redr_status = TRUE;
6903 redraw_later(VALID);
6904 }
6905# endif
6906 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006907# ifdef FEAT_TITLE
6908 redraw_titles();
6909# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 }
6911 }
6912#endif
6913
6914#ifdef FEAT_STL_OPT
6915 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006916 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 {
6918 int wid;
6919
6920 if (varp == &p_ruf) /* reset ru_wid first */
6921 ru_wid = 0;
6922 s = *varp;
6923 if (varp == &p_ruf && *s == '%')
6924 {
6925 /* set ru_wid if 'ruf' starts with "%99(" */
6926 if (*++s == '-') /* ignore a '-' */
6927 s++;
6928 wid = getdigits(&s);
6929 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6930 ru_wid = wid;
6931 else
6932 errmsg = check_stl_option(p_ruf);
6933 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006934 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006935 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006937 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938 comp_col();
6939 }
6940#endif
6941
6942#ifdef FEAT_INS_EXPAND
6943 /* check if it is a valid value for 'complete' -- Acevedo */
6944 else if (gvarp == &p_cpt)
6945 {
6946 for (s = *varp; *s;)
6947 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006948 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006949 s++;
6950 if (!*s)
6951 break;
6952 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6953 {
6954 errmsg = illegal_char(errbuf, *s);
6955 break;
6956 }
6957 if (*++s != NUL && *s != ',' && *s != ' ')
6958 {
6959 if (s[-1] == 'k' || s[-1] == 's')
6960 {
6961 /* skip optional filename after 'k' and 's' */
6962 while (*s && *s != ',' && *s != ' ')
6963 {
6964 if (*s == '\\')
6965 ++s;
6966 ++s;
6967 }
6968 }
6969 else
6970 {
6971 if (errbuf != NULL)
6972 {
6973 sprintf((char *)errbuf,
6974 _("E535: Illegal character after <%c>"),
6975 *--s);
6976 errmsg = errbuf;
6977 }
6978 else
6979 errmsg = (char_u *)"";
6980 break;
6981 }
6982 }
6983 }
6984 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006985
6986 /* 'completeopt' */
6987 else if (varp == &p_cot)
6988 {
6989 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6990 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02006991 else
6992 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006993 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006994#endif /* FEAT_INS_EXPAND */
6995
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02006996#ifdef FEAT_SIGNS
6997 /* 'signcolumn' */
6998 else if (varp == &curwin->w_p_scl)
6999 {
7000 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7001 errmsg = e_invarg;
7002 }
7003#endif
7004
Bram Moolenaar071d4272004-06-13 20:20:40 +00007005
7006#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
7007 else if (varp == &p_toolbar)
7008 {
7009 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7010 &toolbar_flags, TRUE) != OK)
7011 errmsg = e_invarg;
7012 else
7013 {
7014 out_flush();
7015 gui_mch_show_toolbar((toolbar_flags &
7016 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7017 }
7018 }
7019#endif
7020
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007021#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007022 /* 'toolbariconsize': GTK+ 2 only */
7023 else if (varp == &p_tbis)
7024 {
7025 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7026 errmsg = e_invarg;
7027 else
7028 {
7029 out_flush();
7030 gui_mch_show_toolbar((toolbar_flags &
7031 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7032 }
7033 }
7034#endif
7035
7036 /* 'pastetoggle': translate key codes like in a mapping */
7037 else if (varp == &p_pt)
7038 {
7039 if (*p_pt)
7040 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007041 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 if (p != NULL)
7043 {
7044 if (new_value_alloced)
7045 free_string_option(p_pt);
7046 p_pt = p;
7047 new_value_alloced = TRUE;
7048 }
7049 }
7050 }
7051
7052 /* 'backspace' */
7053 else if (varp == &p_bs)
7054 {
7055 if (VIM_ISDIGIT(*p_bs))
7056 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007057 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007058 errmsg = e_invarg;
7059 }
7060 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7061 errmsg = e_invarg;
7062 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007063 else if (varp == &p_bo)
7064 {
7065 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7066 errmsg = e_invarg;
7067 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007069 /* 'tagcase' */
7070 else if (gvarp == &p_tc)
7071 {
7072 unsigned int *flags;
7073
7074 if (opt_flags & OPT_LOCAL)
7075 {
7076 p = curbuf->b_p_tc;
7077 flags = &curbuf->b_tc_flags;
7078 }
7079 else
7080 {
7081 p = p_tc;
7082 flags = &tc_flags;
7083 }
7084
7085 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7086 /* make the local value empty: use the global value */
7087 *flags = 0;
7088 else if (*p == NUL
7089 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7090 errmsg = e_invarg;
7091 }
7092
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007093#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007094 /* 'casemap' */
7095 else if (varp == &p_cmp)
7096 {
7097 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7098 errmsg = e_invarg;
7099 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007101
7102#ifdef FEAT_DIFF
7103 /* 'diffopt' */
7104 else if (varp == &p_dip)
7105 {
7106 if (diffopt_changed() == FAIL)
7107 errmsg = e_invarg;
7108 }
7109#endif
7110
7111#ifdef FEAT_FOLDING
7112 /* 'foldmethod' */
7113 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7114 {
7115 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7116 || *curwin->w_p_fdm == NUL)
7117 errmsg = e_invarg;
7118 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007119 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007121 if (foldmethodIsDiff(curwin))
7122 newFoldLevel();
7123 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007124 }
7125# ifdef FEAT_EVAL
7126 /* 'foldexpr' */
7127 else if (varp == &curwin->w_p_fde)
7128 {
7129 if (foldmethodIsExpr(curwin))
7130 foldUpdateAll(curwin);
7131 }
7132# endif
7133 /* 'foldmarker' */
7134 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7135 {
7136 p = vim_strchr(*varp, ',');
7137 if (p == NULL)
7138 errmsg = (char_u *)N_("E536: comma required");
7139 else if (p == *varp || p[1] == NUL)
7140 errmsg = e_invarg;
7141 else if (foldmethodIsMarker(curwin))
7142 foldUpdateAll(curwin);
7143 }
7144 /* 'commentstring' */
7145 else if (gvarp == &p_cms)
7146 {
7147 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7148 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7149 }
7150 /* 'foldopen' */
7151 else if (varp == &p_fdo)
7152 {
7153 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7154 errmsg = e_invarg;
7155 }
7156 /* 'foldclose' */
7157 else if (varp == &p_fcl)
7158 {
7159 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7160 errmsg = e_invarg;
7161 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007162 /* 'foldignore' */
7163 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7164 {
7165 if (foldmethodIsIndent(curwin))
7166 foldUpdateAll(curwin);
7167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007168#endif
7169
7170#ifdef FEAT_VIRTUALEDIT
7171 /* 'virtualedit' */
7172 else if (varp == &p_ve)
7173 {
7174 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7175 errmsg = e_invarg;
7176 else if (STRCMP(p_ve, oldval) != 0)
7177 {
7178 /* Recompute cursor position in case the new 've' setting
7179 * changes something. */
7180 validate_virtcol();
7181 coladvance(curwin->w_virtcol);
7182 }
7183 }
7184#endif
7185
7186#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7187 else if (varp == &p_csqf)
7188 {
7189 if (p_csqf != NULL)
7190 {
7191 p = p_csqf;
7192 while (*p != NUL)
7193 {
7194 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7195 || p[1] == NUL
7196 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7197 || (p[2] != NUL && p[2] != ','))
7198 {
7199 errmsg = e_invarg;
7200 break;
7201 }
7202 else if (p[2] == NUL)
7203 break;
7204 else
7205 p += 3;
7206 }
7207 }
7208 }
7209#endif
7210
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007211#ifdef FEAT_CINDENT
7212 /* 'cinoptions' */
7213 else if (gvarp == &p_cino)
7214 {
7215 /* TODO: recognize errors */
7216 parse_cino(curbuf);
7217 }
7218#endif
7219
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007220#if defined(FEAT_RENDER_OPTIONS)
7221 else if (varp == &p_rop && gui.in_use)
7222 {
7223 if (!gui_mch_set_rendering_options(p_rop))
7224 errmsg = e_invarg;
7225 }
7226#endif
7227
Bram Moolenaar071d4272004-06-13 20:20:40 +00007228 /* Options that are a list of flags. */
7229 else
7230 {
7231 p = NULL;
7232 if (varp == &p_ww)
7233 p = (char_u *)WW_ALL;
7234 if (varp == &p_shm)
7235 p = (char_u *)SHM_ALL;
7236 else if (varp == &(p_cpo))
7237 p = (char_u *)CPO_ALL;
7238 else if (varp == &(curbuf->b_p_fo))
7239 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007240#ifdef FEAT_CONCEAL
7241 else if (varp == &curwin->w_p_cocu)
7242 p = (char_u *)COCU_ALL;
7243#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007244 else if (varp == &p_mouse)
7245 {
7246#ifdef FEAT_MOUSE
7247 p = (char_u *)MOUSE_ALL;
7248#else
7249 if (*p_mouse != NUL)
7250 errmsg = (char_u *)N_("E538: No mouse support");
7251#endif
7252 }
7253#if defined(FEAT_GUI)
7254 else if (varp == &p_go)
7255 p = (char_u *)GO_ALL;
7256#endif
7257 if (p != NULL)
7258 {
7259 for (s = *varp; *s; ++s)
7260 if (vim_strchr(p, *s) == NULL)
7261 {
7262 errmsg = illegal_char(errbuf, *s);
7263 break;
7264 }
7265 }
7266 }
7267
7268 /*
7269 * If error detected, restore the previous value.
7270 */
7271 if (errmsg != NULL)
7272 {
7273 if (new_value_alloced)
7274 free_string_option(*varp);
7275 *varp = oldval;
7276 /*
7277 * When resetting some values, need to act on it.
7278 */
7279 if (did_chartab)
7280 (void)init_chartab();
7281 if (varp == &p_hl)
7282 (void)highlight_changed();
7283 }
7284 else
7285 {
7286#ifdef FEAT_EVAL
7287 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007288 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007289#endif
7290 /*
7291 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007292 * Use "free_oldval", because recursiveness may change the flags under
7293 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007294 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007295 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007296 free_string_option(oldval);
7297 if (new_value_alloced)
7298 options[opt_idx].flags |= P_ALLOCED;
7299 else
7300 options[opt_idx].flags &= ~P_ALLOCED;
7301
7302 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007303 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007304 {
7305 /* global option with local value set to use global value; free
7306 * the local value and make it empty */
7307 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7308 free_string_option(*(char_u **)p);
7309 *(char_u **)p = empty_option;
7310 }
7311
7312 /* May set global value for local option. */
7313 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7314 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007315
7316#ifdef FEAT_AUTOCMD
7317 /*
7318 * Trigger the autocommand only after setting the flags.
7319 */
7320# ifdef FEAT_SYN_HL
7321 /* When 'syntax' is set, load the syntax of that name */
7322 if (varp == &(curbuf->b_p_syn))
7323 {
7324 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7325 curbuf->b_fname, TRUE, curbuf);
7326 }
7327# endif
7328 else if (varp == &(curbuf->b_p_ft))
7329 {
7330 /* 'filetype' is set, trigger the FileType autocommand */
7331 did_filetype = TRUE;
7332 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7333 curbuf->b_fname, TRUE, curbuf);
7334 }
7335#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007336#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007337 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007338 {
7339 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007340 char_u *q = curwin->w_s->b_p_spl;
7341
7342 /* Skip the first name if it is "cjk". */
7343 if (STRNCMP(q, "cjk,", 4) == 0)
7344 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007345
7346 /*
7347 * Source the spell/LANG.vim in 'runtimepath'.
7348 * They could set 'spellcapcheck' depending on the language.
7349 * Use the first name in 'spelllang' up to '_region' or
7350 * '.encoding'.
7351 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007352 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007353 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7354 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007355 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007356 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007357 }
7358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359 }
7360
7361#ifdef FEAT_MOUSE
7362 if (varp == &p_mouse)
7363 {
7364# ifdef FEAT_MOUSE_TTY
7365 if (*p_mouse == NUL)
7366 mch_setmouse(FALSE); /* switch mouse off */
7367 else
7368# endif
7369 setmouse(); /* in case 'mouse' changed */
7370 }
7371#endif
7372
Bram Moolenaar913077c2012-03-28 19:59:04 +02007373 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007374 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007375 curwin->w_set_curswant = TRUE;
7376
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007377#ifdef FEAT_GUI
7378 /* check redraw when it's not a GUI option or the GUI is active. */
7379 if (!redraw_gui_only || gui.in_use)
7380#endif
7381 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007382
7383 return errmsg;
7384}
7385
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007386#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007387/*
7388 * Simple int comparison function for use with qsort()
7389 */
7390 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007391int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007392{
7393 return *(const int *)a - *(const int *)b;
7394}
7395
7396/*
7397 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7398 * Returns error message, NULL if it's OK.
7399 */
7400 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007401check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007402{
7403 char_u *s;
7404 int col;
7405 int count = 0;
7406 int color_cols[256];
7407 int i;
7408 int j = 0;
7409
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007410 if (wp->w_buffer == NULL)
7411 return NULL; /* buffer was closed */
7412
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007413 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007414 {
7415 if (*s == '-' || *s == '+')
7416 {
7417 /* -N and +N: add to 'textwidth' */
7418 col = (*s == '-') ? -1 : 1;
7419 ++s;
7420 if (!VIM_ISDIGIT(*s))
7421 return e_invarg;
7422 col = col * getdigits(&s);
7423 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007424 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007425 col += wp->w_buffer->b_p_tw;
7426 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007427 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007428 }
7429 else if (VIM_ISDIGIT(*s))
7430 col = getdigits(&s);
7431 else
7432 return e_invarg;
7433 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007434skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007435 if (*s == NUL)
7436 break;
7437 if (*s != ',')
7438 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007439 if (*++s == NUL)
7440 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007441 }
7442
7443 vim_free(wp->w_p_cc_cols);
7444 if (count == 0)
7445 wp->w_p_cc_cols = NULL;
7446 else
7447 {
7448 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7449 if (wp->w_p_cc_cols != NULL)
7450 {
7451 /* sort the columns for faster usage on screen redraw inside
7452 * win_line() */
7453 qsort(color_cols, count, sizeof(int), int_cmp);
7454
7455 for (i = 0; i < count; ++i)
7456 /* skip duplicates */
7457 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7458 wp->w_p_cc_cols[j++] = color_cols[i];
7459 wp->w_p_cc_cols[j] = -1; /* end marker */
7460 }
7461 }
7462
7463 return NULL; /* no error */
7464}
7465#endif
7466
Bram Moolenaar071d4272004-06-13 20:20:40 +00007467/*
7468 * Handle setting 'listchars' or 'fillchars'.
7469 * Returns error message, NULL if it's OK.
7470 */
7471 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007472set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007473{
7474 int round, i, len, entries;
7475 char_u *p, *s;
7476 int c1, c2 = 0;
7477 struct charstab
7478 {
7479 int *cp;
7480 char *name;
7481 };
7482#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7483 static struct charstab filltab[] =
7484 {
7485 {&fill_stl, "stl"},
7486 {&fill_stlnc, "stlnc"},
7487 {&fill_vert, "vert"},
7488 {&fill_fold, "fold"},
7489 {&fill_diff, "diff"},
7490 };
7491#endif
7492 static struct charstab lcstab[] =
7493 {
7494 {&lcs_eol, "eol"},
7495 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007496 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007497 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007498 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499 {&lcs_tab2, "tab"},
7500 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007501#ifdef FEAT_CONCEAL
7502 {&lcs_conceal, "conceal"},
7503#else
7504 {NULL, "conceal"},
7505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 };
7507 struct charstab *tab;
7508
7509#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7510 if (varp == &p_lcs)
7511#endif
7512 {
7513 tab = lcstab;
7514 entries = sizeof(lcstab) / sizeof(struct charstab);
7515 }
7516#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7517 else
7518 {
7519 tab = filltab;
7520 entries = sizeof(filltab) / sizeof(struct charstab);
7521 }
7522#endif
7523
7524 /* first round: check for valid value, second round: assign values */
7525 for (round = 0; round <= 1; ++round)
7526 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007527 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007528 {
7529 /* After checking that the value is valid: set defaults: space for
7530 * 'fillchars', NUL for 'listchars' */
7531 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007532 if (tab[i].cp != NULL)
7533 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007534 if (varp == &p_lcs)
7535 lcs_tab1 = NUL;
7536#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7537 else
7538 fill_diff = '-';
7539#endif
7540 }
7541 p = *varp;
7542 while (*p)
7543 {
7544 for (i = 0; i < entries; ++i)
7545 {
7546 len = (int)STRLEN(tab[i].name);
7547 if (STRNCMP(p, tab[i].name, len) == 0
7548 && p[len] == ':'
7549 && p[len + 1] != NUL)
7550 {
7551 s = p + len + 1;
7552#ifdef FEAT_MBYTE
7553 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007554 if (mb_char2cells(c1) > 1)
7555 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007556#else
7557 c1 = *s++;
7558#endif
7559 if (tab[i].cp == &lcs_tab2)
7560 {
7561 if (*s == NUL)
7562 continue;
7563#ifdef FEAT_MBYTE
7564 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007565 if (mb_char2cells(c2) > 1)
7566 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007567#else
7568 c2 = *s++;
7569#endif
7570 }
7571 if (*s == ',' || *s == NUL)
7572 {
7573 if (round)
7574 {
7575 if (tab[i].cp == &lcs_tab2)
7576 {
7577 lcs_tab1 = c1;
7578 lcs_tab2 = c2;
7579 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007580 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007581 *(tab[i].cp) = c1;
7582
7583 }
7584 p = s;
7585 break;
7586 }
7587 }
7588 }
7589
7590 if (i == entries)
7591 return e_invarg;
7592 if (*p == ',')
7593 ++p;
7594 }
7595 }
7596
7597 return NULL; /* no error */
7598}
7599
7600#ifdef FEAT_STL_OPT
7601/*
7602 * Check validity of options with the 'statusline' format.
7603 * Return error message or NULL.
7604 */
7605 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007606check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007607{
7608 int itemcnt = 0;
7609 int groupdepth = 0;
7610 static char_u errbuf[80];
7611
7612 while (*s && itemcnt < STL_MAX_ITEM)
7613 {
7614 /* Check for valid keys after % sequences */
7615 while (*s && *s != '%')
7616 s++;
7617 if (!*s)
7618 break;
7619 s++;
7620 if (*s != '%' && *s != ')')
7621 ++itemcnt;
7622 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7623 {
7624 s++;
7625 continue;
7626 }
7627 if (*s == ')')
7628 {
7629 s++;
7630 if (--groupdepth < 0)
7631 break;
7632 continue;
7633 }
7634 if (*s == '-')
7635 s++;
7636 while (VIM_ISDIGIT(*s))
7637 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007638 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007639 continue;
7640 if (*s == '.')
7641 {
7642 s++;
7643 while (*s && VIM_ISDIGIT(*s))
7644 s++;
7645 }
7646 if (*s == '(')
7647 {
7648 groupdepth++;
7649 continue;
7650 }
7651 if (vim_strchr(STL_ALL, *s) == NULL)
7652 {
7653 return illegal_char(errbuf, *s);
7654 }
7655 if (*s == '{')
7656 {
7657 s++;
7658 while (*s != '}' && *s)
7659 s++;
7660 if (*s != '}')
7661 return (char_u *)N_("E540: Unclosed expression sequence");
7662 }
7663 }
7664 if (itemcnt >= STL_MAX_ITEM)
7665 return (char_u *)N_("E541: too many items");
7666 if (groupdepth != 0)
7667 return (char_u *)N_("E542: unbalanced groups");
7668 return NULL;
7669}
7670#endif
7671
7672#ifdef FEAT_CLIPBOARD
7673/*
7674 * Extract the items in the 'clipboard' option and set global values.
7675 */
7676 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007677check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007678{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007679 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007680 int new_autoselect_star = FALSE;
7681 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007683 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684 regprog_T *new_exclude_prog = NULL;
7685 char_u *errmsg = NULL;
7686 char_u *p;
7687
7688 for (p = p_cb; *p != NUL; )
7689 {
7690 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7691 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007692 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007693 p += 7;
7694 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007695 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007696 && (p[11] == ',' || p[11] == NUL))
7697 {
7698 new_unnamed |= CLIP_UNNAMED_PLUS;
7699 p += 11;
7700 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007701 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007702 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007703 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007704 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 p += 10;
7706 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007707 else if (STRNCMP(p, "autoselectplus", 14) == 0
7708 && (p[14] == ',' || p[14] == NUL))
7709 {
7710 new_autoselect_plus = TRUE;
7711 p += 14;
7712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007714 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715 {
7716 new_autoselectml = TRUE;
7717 p += 12;
7718 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007719 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7720 {
7721 new_html = TRUE;
7722 p += 4;
7723 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7725 {
7726 p += 8;
7727 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7728 if (new_exclude_prog == NULL)
7729 errmsg = e_invarg;
7730 break;
7731 }
7732 else
7733 {
7734 errmsg = e_invarg;
7735 break;
7736 }
7737 if (*p == ',')
7738 ++p;
7739 }
7740 if (errmsg == NULL)
7741 {
7742 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007743 clip_autoselect_star = new_autoselect_star;
7744 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007745 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007746 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007747 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007749#ifdef FEAT_GUI_GTK
7750 if (gui.in_use)
7751 {
7752 gui_gtk_set_selection_targets();
7753 gui_gtk_set_dnd_targets();
7754 }
7755#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007756 }
7757 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007758 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759
7760 return errmsg;
7761}
7762#endif
7763
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007764#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007765 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007766did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007767{
7768 char_u *errmsg = NULL;
7769 win_T *wp;
7770 int l;
7771
7772 if (is_spellfile)
7773 {
7774 l = (int)STRLEN(curwin->w_s->b_p_spf);
7775 if (l > 0 && (l < 4
7776 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7777 errmsg = e_invarg;
7778 }
7779
7780 if (errmsg == NULL)
7781 {
7782 FOR_ALL_WINDOWS(wp)
7783 if (wp->w_buffer == curbuf && wp->w_p_spell)
7784 {
7785 errmsg = did_set_spelllang(wp);
7786# ifdef FEAT_WINDOWS
7787 break;
7788# endif
7789 }
7790 }
7791 return errmsg;
7792}
7793
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007794/*
7795 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7796 * Return error message when failed, NULL when OK.
7797 */
7798 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007799compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007800{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007801 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007802 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007803
Bram Moolenaar860cae12010-06-05 23:22:07 +02007804 if (*synblock->b_p_spc == NUL)
7805 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007806 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007807 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007808 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007809 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007810 if (re != NULL)
7811 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007812 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007813 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007814 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007815 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007816 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007817 return e_invarg;
7818 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007819 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007820 }
7821
Bram Moolenaar473de612013-06-08 18:19:48 +02007822 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007823 return NULL;
7824}
7825#endif
7826
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007827#if defined(FEAT_EVAL) || defined(PROTO)
7828/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007829 * Set the scriptID for an option, taking care of setting the buffer- or
7830 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007831 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007832 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007833set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007834{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007835 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7836 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007837
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007838 /* Remember where the option was set. For local options need to do that
7839 * in the buffer or window structure. */
7840 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007841 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007842 if (both || (opt_flags & OPT_LOCAL))
7843 {
7844 if (indir & PV_BUF)
7845 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7846 else if (indir & PV_WIN)
7847 curwin->w_p_scriptID[indir & PV_MASK] = id;
7848 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007849}
7850#endif
7851
Bram Moolenaar071d4272004-06-13 20:20:40 +00007852/*
7853 * Set the value of a boolean option, and take care of side effects.
7854 * Returns NULL for success, or an error message for an error.
7855 */
7856 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007857set_bool_option(
7858 int opt_idx, /* index in options[] table */
7859 char_u *varp, /* pointer to the option variable */
7860 int value, /* new value */
7861 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007862{
7863 int old_value = *(int *)varp;
7864
Bram Moolenaar071d4272004-06-13 20:20:40 +00007865 /* Disallow changing some options from secure mode */
7866 if ((secure
7867#ifdef HAVE_SANDBOX
7868 || sandbox != 0
7869#endif
7870 ) && (options[opt_idx].flags & P_SECURE))
7871 return e_secure;
7872
7873 *(int *)varp = value; /* set the new value */
7874#ifdef FEAT_EVAL
7875 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007876 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877#endif
7878
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007879#ifdef FEAT_GUI
7880 need_mouse_correct = TRUE;
7881#endif
7882
Bram Moolenaar071d4272004-06-13 20:20:40 +00007883 /* May set global value for local option. */
7884 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7885 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7886
7887 /*
7888 * Handle side effects of changing a bool option.
7889 */
7890
7891 /* 'compatible' */
7892 if ((int *)varp == &p_cp)
7893 {
7894 compatible_set();
7895 }
7896
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007897#ifdef FEAT_PERSISTENT_UNDO
7898 /* 'undofile' */
7899 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7900 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007901 /* Only take action when the option was set. When reset we do not
7902 * delete the undo file, the option may be set again without making
7903 * any changes in between. */
7904 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007905 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007906 char_u hash[UNDO_HASH_SIZE];
7907 buf_T *save_curbuf = curbuf;
7908
Bram Moolenaar29323592016-07-24 22:04:11 +02007909 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007910 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007911 /* When 'undofile' is set globally: for every buffer, otherwise
7912 * only for the current buffer: Try to read in the undofile,
7913 * if one exists, the buffer wasn't changed and the buffer was
7914 * loaded */
7915 if ((curbuf == save_curbuf
7916 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7917 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7918 {
7919 u_compute_hash(hash);
7920 u_read_undo(NULL, hash, curbuf->b_fname);
7921 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007922 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007923 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007924 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007925 }
7926#endif
7927
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928 else if ((int *)varp == &curbuf->b_p_ro)
7929 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007930 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007931 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7932 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007933
7934 /* when 'readonly' is set may give W10 again */
7935 if (curbuf->b_p_ro)
7936 curbuf->b_did_warn = FALSE;
7937
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007939 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007940#endif
7941 }
7942
Bram Moolenaar9c449722010-07-20 18:44:27 +02007943#ifdef FEAT_GUI
7944 else if ((int *)varp == &p_mh)
7945 {
7946 if (!p_mh)
7947 gui_mch_mousehide(FALSE);
7948 }
7949#endif
7950
Bram Moolenaara539df02010-08-01 14:35:05 +02007951#ifdef FEAT_TITLE
7952 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007954 {
7955 redraw_titles();
7956 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957 /* when 'endofline' is changed, redraw the window title */
7958 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007959 {
7960 redraw_titles();
7961 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007962 /* when 'fixeol' is changed, redraw the window title */
7963 else if ((int *)varp == &curbuf->b_p_fixeol)
7964 {
7965 redraw_titles();
7966 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007967# ifdef FEAT_MBYTE
7968 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007969 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007970 {
7971 redraw_titles();
7972 }
7973# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007974#endif
7975
7976 /* when 'bin' is set also set some other options */
7977 else if ((int *)varp == &curbuf->b_p_bin)
7978 {
7979 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7980#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007981 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007982#endif
7983 }
7984
7985#ifdef FEAT_AUTOCMD
7986 /* when 'buflisted' changes, trigger autocommands */
7987 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7988 {
7989 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7990 NULL, NULL, TRUE, curbuf);
7991 }
7992#endif
7993
7994 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7995 else if ((int *)varp == &curbuf->b_p_swf)
7996 {
7997 if (curbuf->b_p_swf && p_uc)
7998 ml_open_file(curbuf); /* create the swap file */
7999 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008000 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8001 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 mf_close_file(curbuf, TRUE); /* remove the swap file */
8003 }
8004
8005 /* when 'terse' is set change 'shortmess' */
8006 else if ((int *)varp == &p_terse)
8007 {
8008 char_u *p;
8009
8010 p = vim_strchr(p_shm, SHM_SEARCH);
8011
8012 /* insert 's' in p_shm */
8013 if (p_terse && p == NULL)
8014 {
8015 STRCPY(IObuff, p_shm);
8016 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008017 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 }
8019 /* remove 's' from p_shm */
8020 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008021 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008022 }
8023
8024 /* when 'paste' is set or reset also change other options */
8025 else if ((int *)varp == &p_paste)
8026 {
8027 paste_option_changed();
8028 }
8029
8030 /* when 'insertmode' is set from an autocommand need to do work here */
8031 else if ((int *)varp == &p_im)
8032 {
8033 if (p_im)
8034 {
8035 if ((State & INSERT) == 0)
8036 need_start_insertmode = TRUE;
8037 stop_insert_mode = FALSE;
8038 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008039 /* only reset if it was set previously */
8040 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008041 {
8042 need_start_insertmode = FALSE;
8043 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008044 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045 clear_cmdline = TRUE; /* remove "(insert)" */
8046 restart_edit = 0;
8047 }
8048 }
8049
8050 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8051 else if ((int *)varp == &p_ic && p_hls)
8052 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008053 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008054 }
8055
8056#ifdef FEAT_SEARCH_EXTRA
8057 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8058 else if ((int *)varp == &p_hls)
8059 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008060 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008061 }
8062#endif
8063
8064#ifdef FEAT_SCROLLBIND
8065 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8066 * at the end of normal_cmd() */
8067 else if ((int *)varp == &curwin->w_p_scb)
8068 {
8069 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008070 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008071 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008072 curwin->w_scbind_pos = curwin->w_topline;
8073 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008074 }
8075#endif
8076
8077#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8078 /* There can be only one window with 'previewwindow' set. */
8079 else if ((int *)varp == &curwin->w_p_pvw)
8080 {
8081 if (curwin->w_p_pvw)
8082 {
8083 win_T *win;
8084
Bram Moolenaar29323592016-07-24 22:04:11 +02008085 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086 if (win->w_p_pvw && win != curwin)
8087 {
8088 curwin->w_p_pvw = FALSE;
8089 return (char_u *)N_("E590: A preview window already exists");
8090 }
8091 }
8092 }
8093#endif
8094
8095 /* when 'textmode' is set or reset also change 'fileformat' */
8096 else if ((int *)varp == &curbuf->b_p_tx)
8097 {
8098 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8099 }
8100
8101 /* when 'textauto' is set or reset also change 'fileformats' */
8102 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008103 set_string_option_direct((char_u *)"ffs", -1,
8104 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008105 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008106
8107 /*
8108 * When 'lisp' option changes include/exclude '-' in
8109 * keyword characters.
8110 */
8111#ifdef FEAT_LISP
8112 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8113 {
8114 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8115 }
8116#endif
8117
8118#ifdef FEAT_TITLE
8119 /* when 'title' changed, may need to change the title; same for 'icon' */
8120 else if ((int *)varp == &p_title)
8121 {
8122 did_set_title(FALSE);
8123 }
8124
8125 else if ((int *)varp == &p_icon)
8126 {
8127 did_set_title(TRUE);
8128 }
8129#endif
8130
8131 else if ((int *)varp == &curbuf->b_changed)
8132 {
8133 if (!value)
8134 save_file_ff(curbuf); /* Buffer is unchanged */
8135#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008136 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137#endif
8138#ifdef FEAT_AUTOCMD
8139 modified_was_set = value;
8140#endif
8141 }
8142
8143#ifdef BACKSLASH_IN_FILENAME
8144 else if ((int *)varp == &p_ssl)
8145 {
8146 if (p_ssl)
8147 {
8148 psepc = '/';
8149 psepcN = '\\';
8150 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151 }
8152 else
8153 {
8154 psepc = '\\';
8155 psepcN = '/';
8156 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 }
8158
8159 /* need to adjust the file name arguments and buffer names. */
8160 buflist_slash_adjust();
8161 alist_slash_adjust();
8162# ifdef FEAT_EVAL
8163 scriptnames_slash_adjust();
8164# endif
8165 }
8166#endif
8167
8168 /* If 'wrap' is set, set w_leftcol to zero. */
8169 else if ((int *)varp == &curwin->w_p_wrap)
8170 {
8171 if (curwin->w_p_wrap)
8172 curwin->w_leftcol = 0;
8173 }
8174
8175#ifdef FEAT_WINDOWS
8176 else if ((int *)varp == &p_ea)
8177 {
8178 if (p_ea && !old_value)
8179 win_equal(curwin, FALSE, 0);
8180 }
8181#endif
8182
8183 else if ((int *)varp == &p_wiv)
8184 {
8185 /*
8186 * When 'weirdinvert' changed, set/reset 't_xs'.
8187 * Then set 'weirdinvert' according to value of 't_xs'.
8188 */
8189 if (p_wiv && !old_value)
8190 T_XS = (char_u *)"y";
8191 else if (!p_wiv && old_value)
8192 T_XS = empty_option;
8193 p_wiv = (*T_XS != NUL);
8194 }
8195
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008196#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197 else if ((int *)varp == &p_beval)
8198 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008199 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008201 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 gui_mch_disable_beval_area(balloonEval);
8203 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008204#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008206#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008207 else if ((int *)varp == &p_acd)
8208 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008209 /* Change directories when the 'acd' option is set now. */
8210 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008211 }
8212#endif
8213
8214#ifdef FEAT_DIFF
8215 /* 'diff' */
8216 else if ((int *)varp == &curwin->w_p_diff)
8217 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008218 /* May add or remove the buffer from the list of diff buffers. */
8219 diff_buf_adjust(curwin);
8220# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008221 if (foldmethodIsDiff(curwin))
8222 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008223# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008224 }
8225#endif
8226
8227#ifdef USE_IM_CONTROL
8228 /* 'imdisable' */
8229 else if ((int *)varp == &p_imdisable)
8230 {
8231 /* Only de-activate it here, it will be enabled when changing mode. */
8232 if (p_imdisable)
8233 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008234 else if (State & INSERT)
8235 /* When the option is set from an autocommand, it may need to take
8236 * effect right away. */
8237 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008238 }
8239#endif
8240
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008241#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008242 /* 'spell' */
8243 else if ((int *)varp == &curwin->w_p_spell)
8244 {
8245 if (curwin->w_p_spell)
8246 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008247 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008248 if (errmsg != NULL)
8249 EMSG(_(errmsg));
8250 }
8251 }
8252#endif
8253
Bram Moolenaar071d4272004-06-13 20:20:40 +00008254#ifdef FEAT_FKMAP
8255 else if ((int *)varp == &p_altkeymap)
8256 {
8257 if (old_value != p_altkeymap)
8258 {
8259 if (!p_altkeymap)
8260 {
8261 p_hkmap = p_fkmap;
8262 p_fkmap = 0;
8263 }
8264 else
8265 {
8266 p_fkmap = p_hkmap;
8267 p_hkmap = 0;
8268 }
8269 (void)init_chartab();
8270 }
8271 }
8272
8273 /*
8274 * In case some second language keymapping options have changed, check
8275 * and correct the setting in a consistent way.
8276 */
8277
8278 /*
8279 * If hkmap or fkmap are set, reset Arabic keymapping.
8280 */
8281 if ((p_hkmap || p_fkmap) && p_altkeymap)
8282 {
8283 p_altkeymap = p_fkmap;
8284# ifdef FEAT_ARABIC
8285 curwin->w_p_arab = FALSE;
8286# endif
8287 (void)init_chartab();
8288 }
8289
8290 /*
8291 * If hkmap set, reset Farsi keymapping.
8292 */
8293 if (p_hkmap && p_altkeymap)
8294 {
8295 p_altkeymap = 0;
8296 p_fkmap = 0;
8297# ifdef FEAT_ARABIC
8298 curwin->w_p_arab = FALSE;
8299# endif
8300 (void)init_chartab();
8301 }
8302
8303 /*
8304 * If fkmap set, reset Hebrew keymapping.
8305 */
8306 if (p_fkmap && !p_altkeymap)
8307 {
8308 p_altkeymap = 1;
8309 p_hkmap = 0;
8310# ifdef FEAT_ARABIC
8311 curwin->w_p_arab = FALSE;
8312# endif
8313 (void)init_chartab();
8314 }
8315#endif
8316
8317#ifdef FEAT_ARABIC
8318 if ((int *)varp == &curwin->w_p_arab)
8319 {
8320 if (curwin->w_p_arab)
8321 {
8322 /*
8323 * 'arabic' is set, handle various sub-settings.
8324 */
8325 if (!p_tbidi)
8326 {
8327 /* set rightleft mode */
8328 if (!curwin->w_p_rl)
8329 {
8330 curwin->w_p_rl = TRUE;
8331 changed_window_setting();
8332 }
8333
8334 /* Enable Arabic shaping (major part of what Arabic requires) */
8335 if (!p_arshape)
8336 {
8337 p_arshape = TRUE;
8338 redraw_later_clear();
8339 }
8340 }
8341
8342 /* Arabic requires a utf-8 encoding, inform the user if its not
8343 * set. */
8344 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008345 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008346 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8347
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008348 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008349 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8350#ifdef FEAT_EVAL
8351 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8352#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008353 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354
8355# ifdef FEAT_MBYTE
8356 /* set 'delcombine' */
8357 p_deco = TRUE;
8358# endif
8359
8360# ifdef FEAT_KEYMAP
8361 /* Force-set the necessary keymap for arabic */
8362 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8363 OPT_LOCAL);
8364# endif
8365# ifdef FEAT_FKMAP
8366 p_altkeymap = 0;
8367 p_hkmap = 0;
8368 p_fkmap = 0;
8369 (void)init_chartab();
8370# endif
8371 }
8372 else
8373 {
8374 /*
8375 * 'arabic' is reset, handle various sub-settings.
8376 */
8377 if (!p_tbidi)
8378 {
8379 /* reset rightleft mode */
8380 if (curwin->w_p_rl)
8381 {
8382 curwin->w_p_rl = FALSE;
8383 changed_window_setting();
8384 }
8385
8386 /* 'arabicshape' isn't reset, it is a global option and
8387 * another window may still need it "on". */
8388 }
8389
8390 /* 'delcombine' isn't reset, it is a global option and another
8391 * window may still want it "on". */
8392
8393# ifdef FEAT_KEYMAP
8394 /* Revert to the default keymap */
8395 curbuf->b_p_iminsert = B_IMODE_NONE;
8396 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8397# endif
8398 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008399 }
8400
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008401#endif
8402
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008403#ifdef FEAT_TERMGUICOLORS
8404 /* 'termguicolors' */
8405 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008406 {
8407# ifdef FEAT_GUI
8408 if (!gui.in_use && !gui.starting)
8409# endif
8410 highlight_gui_started();
8411 }
8412#endif
8413
Bram Moolenaar071d4272004-06-13 20:20:40 +00008414 /*
8415 * End of handling side effects for bool options.
8416 */
8417
Bram Moolenaar53744302015-07-17 17:38:22 +02008418 /* after handling side effects, call autocommand */
8419
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420 options[opt_idx].flags |= P_WAS_SET;
8421
Bram Moolenaar53744302015-07-17 17:38:22 +02008422#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8423 if (!starting)
8424 {
8425 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008426 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8427 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8428 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008429 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8430 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8431 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8432 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8433 reset_v_option_vars();
8434 }
8435#endif
8436
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008438 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008439 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008440 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441 check_redraw(options[opt_idx].flags);
8442
8443 return NULL;
8444}
8445
8446/*
8447 * Set the value of a number option, and take care of side effects.
8448 * Returns NULL for success, or an error message for an error.
8449 */
8450 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008451set_num_option(
8452 int opt_idx, /* index in options[] table */
8453 char_u *varp, /* pointer to the option variable */
8454 long value, /* new value */
8455 char_u *errbuf, /* buffer for error messages */
8456 size_t errbuflen, /* length of "errbuf" */
8457 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008458 OPT_MODELINE */
8459{
8460 char_u *errmsg = NULL;
8461 long old_value = *(long *)varp;
8462 long old_Rows = Rows; /* remember old Rows */
8463 long old_Columns = Columns; /* remember old Columns */
8464 long *pp = (long *)varp;
8465
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008466 /* Disallow changing some options from secure mode. */
8467 if ((secure
8468#ifdef HAVE_SANDBOX
8469 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008470#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008471 ) && (options[opt_idx].flags & P_SECURE))
8472 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473
8474 *pp = value;
8475#ifdef FEAT_EVAL
8476 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008477 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008479#ifdef FEAT_GUI
8480 need_mouse_correct = TRUE;
8481#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008482
Bram Moolenaar14f24742012-08-08 18:01:05 +02008483 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008484 {
8485 errmsg = e_positive;
8486 curbuf->b_p_sw = curbuf->b_p_ts;
8487 }
8488
8489 /*
8490 * Number options that need some action when changed
8491 */
8492#ifdef FEAT_WINDOWS
8493 if (pp == &p_wh || pp == &p_hh)
8494 {
8495 if (p_wh < 1)
8496 {
8497 errmsg = e_positive;
8498 p_wh = 1;
8499 }
8500 if (p_wmh > p_wh)
8501 {
8502 errmsg = e_winheight;
8503 p_wh = p_wmh;
8504 }
8505 if (p_hh < 0)
8506 {
8507 errmsg = e_positive;
8508 p_hh = 0;
8509 }
8510
8511 /* Change window height NOW */
8512 if (lastwin != firstwin)
8513 {
8514 if (pp == &p_wh && curwin->w_height < p_wh)
8515 win_setheight((int)p_wh);
8516 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8517 win_setheight((int)p_hh);
8518 }
8519 }
8520
8521 /* 'winminheight' */
8522 else if (pp == &p_wmh)
8523 {
8524 if (p_wmh < 0)
8525 {
8526 errmsg = e_positive;
8527 p_wmh = 0;
8528 }
8529 if (p_wmh > p_wh)
8530 {
8531 errmsg = e_winheight;
8532 p_wmh = p_wh;
8533 }
8534 win_setminheight();
8535 }
8536
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008537# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008538 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008539 {
8540 if (p_wiw < 1)
8541 {
8542 errmsg = e_positive;
8543 p_wiw = 1;
8544 }
8545 if (p_wmw > p_wiw)
8546 {
8547 errmsg = e_winwidth;
8548 p_wiw = p_wmw;
8549 }
8550
8551 /* Change window width NOW */
8552 if (lastwin != firstwin && curwin->w_width < p_wiw)
8553 win_setwidth((int)p_wiw);
8554 }
8555
8556 /* 'winminwidth' */
8557 else if (pp == &p_wmw)
8558 {
8559 if (p_wmw < 0)
8560 {
8561 errmsg = e_positive;
8562 p_wmw = 0;
8563 }
8564 if (p_wmw > p_wiw)
8565 {
8566 errmsg = e_winwidth;
8567 p_wmw = p_wiw;
8568 }
8569 win_setminheight();
8570 }
8571# endif
8572
8573#endif
8574
8575#ifdef FEAT_WINDOWS
8576 /* (re)set last window status line */
8577 else if (pp == &p_ls)
8578 {
8579 last_status(FALSE);
8580 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008581
8582 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008583 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008584 {
8585 shell_new_rows(); /* recompute window positions and heights */
8586 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587#endif
8588
8589#ifdef FEAT_GUI
8590 else if (pp == &p_linespace)
8591 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008592 /* Recompute gui.char_height and resize the Vim window to keep the
8593 * same number of lines. */
8594 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008595 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596 }
8597#endif
8598
8599#ifdef FEAT_FOLDING
8600 /* 'foldlevel' */
8601 else if (pp == &curwin->w_p_fdl)
8602 {
8603 if (curwin->w_p_fdl < 0)
8604 curwin->w_p_fdl = 0;
8605 newFoldLevel();
8606 }
8607
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008608 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008609 else if (pp == &curwin->w_p_fml)
8610 {
8611 foldUpdateAll(curwin);
8612 }
8613
8614 /* 'foldnestmax' */
8615 else if (pp == &curwin->w_p_fdn)
8616 {
8617 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8618 foldUpdateAll(curwin);
8619 }
8620
8621 /* 'foldcolumn' */
8622 else if (pp == &curwin->w_p_fdc)
8623 {
8624 if (curwin->w_p_fdc < 0)
8625 {
8626 errmsg = e_positive;
8627 curwin->w_p_fdc = 0;
8628 }
8629 else if (curwin->w_p_fdc > 12)
8630 {
8631 errmsg = e_invarg;
8632 curwin->w_p_fdc = 12;
8633 }
8634 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008635#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008637#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638 /* 'shiftwidth' or 'tabstop' */
8639 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8640 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008641# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 if (foldmethodIsIndent(curwin))
8643 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008644# endif
8645# ifdef FEAT_CINDENT
8646 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8647 * parse 'cinoptions'. */
8648 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8649 parse_cino(curbuf);
8650# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008651 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008653
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008654#ifdef FEAT_MBYTE
8655 /* 'maxcombine' */
8656 else if (pp == &p_mco)
8657 {
8658 if (p_mco > MAX_MCO)
8659 p_mco = MAX_MCO;
8660 else if (p_mco < 0)
8661 p_mco = 0;
8662 screenclear(); /* will re-allocate the screen */
8663 }
8664#endif
8665
Bram Moolenaar071d4272004-06-13 20:20:40 +00008666 else if (pp == &curbuf->b_p_iminsert)
8667 {
8668 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8669 {
8670 errmsg = e_invarg;
8671 curbuf->b_p_iminsert = B_IMODE_NONE;
8672 }
8673 p_iminsert = curbuf->b_p_iminsert;
8674 if (termcap_active) /* don't do this in the alternate screen */
8675 showmode();
8676#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8677 /* Show/unshow value of 'keymap' in status lines. */
8678 status_redraw_curbuf();
8679#endif
8680 }
8681
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008682 else if (pp == &p_window)
8683 {
8684 if (p_window < 1)
8685 p_window = 1;
8686 else if (p_window >= Rows)
8687 p_window = Rows - 1;
8688 }
8689
Bram Moolenaar071d4272004-06-13 20:20:40 +00008690 else if (pp == &curbuf->b_p_imsearch)
8691 {
8692 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8693 {
8694 errmsg = e_invarg;
8695 curbuf->b_p_imsearch = B_IMODE_NONE;
8696 }
8697 p_imsearch = curbuf->b_p_imsearch;
8698 }
8699
8700#ifdef FEAT_TITLE
8701 /* if 'titlelen' has changed, redraw the title */
8702 else if (pp == &p_titlelen)
8703 {
8704 if (p_titlelen < 0)
8705 {
8706 errmsg = e_positive;
8707 p_titlelen = 85;
8708 }
8709 if (starting != NO_SCREEN && old_value != p_titlelen)
8710 need_maketitle = TRUE;
8711 }
8712#endif
8713
8714 /* if p_ch changed value, change the command line height */
8715 else if (pp == &p_ch)
8716 {
8717 if (p_ch < 1)
8718 {
8719 errmsg = e_positive;
8720 p_ch = 1;
8721 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008722 if (p_ch > Rows - min_rows() + 1)
8723 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008724
8725 /* Only compute the new window layout when startup has been
8726 * completed. Otherwise the frame sizes may be wrong. */
8727 if (p_ch != old_value && full_screen
8728#ifdef FEAT_GUI
8729 && !gui.starting
8730#endif
8731 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008732 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008733 }
8734
8735 /* when 'updatecount' changes from zero to non-zero, open swap files */
8736 else if (pp == &p_uc)
8737 {
8738 if (p_uc < 0)
8739 {
8740 errmsg = e_positive;
8741 p_uc = 100;
8742 }
8743 if (p_uc && !old_value)
8744 ml_open_files();
8745 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008746#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008747 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008748 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008749 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008750 {
8751 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008752 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008753 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008754 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008755 {
8756 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008757 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008758 }
8759 }
8760#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008761#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008762 else if (pp == &p_mzq)
8763 mzvim_reset_timer();
8764#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765
8766 /* sync undo before 'undolevels' changes */
8767 else if (pp == &p_ul)
8768 {
8769 /* use the old value, otherwise u_sync() may not work properly */
8770 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008771 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 p_ul = value;
8773 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008774 else if (pp == &curbuf->b_p_ul)
8775 {
8776 /* use the old value, otherwise u_sync() may not work properly */
8777 curbuf->b_p_ul = old_value;
8778 u_sync(TRUE);
8779 curbuf->b_p_ul = value;
8780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008782#ifdef FEAT_LINEBREAK
8783 /* 'numberwidth' must be positive */
8784 else if (pp == &curwin->w_p_nuw)
8785 {
8786 if (curwin->w_p_nuw < 1)
8787 {
8788 errmsg = e_positive;
8789 curwin->w_p_nuw = 1;
8790 }
8791 if (curwin->w_p_nuw > 10)
8792 {
8793 errmsg = e_invarg;
8794 curwin->w_p_nuw = 10;
8795 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008796 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008797 }
8798#endif
8799
Bram Moolenaar1a384422010-07-14 19:53:30 +02008800 else if (pp == &curbuf->b_p_tw)
8801 {
8802 if (curbuf->b_p_tw < 0)
8803 {
8804 errmsg = e_positive;
8805 curbuf->b_p_tw = 0;
8806 }
8807#ifdef FEAT_SYN_HL
8808# ifdef FEAT_WINDOWS
8809 {
8810 win_T *wp;
8811 tabpage_T *tp;
8812
8813 FOR_ALL_TAB_WINDOWS(tp, wp)
8814 check_colorcolumn(wp);
8815 }
8816# else
8817 check_colorcolumn(curwin);
8818# endif
8819#endif
8820 }
8821
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822 /*
8823 * Check the bounds for numeric options here
8824 */
8825 if (Rows < min_rows() && full_screen)
8826 {
8827 if (errbuf != NULL)
8828 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008829 vim_snprintf((char *)errbuf, errbuflen,
8830 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008831 errmsg = errbuf;
8832 }
8833 Rows = min_rows();
8834 }
8835 if (Columns < MIN_COLUMNS && full_screen)
8836 {
8837 if (errbuf != NULL)
8838 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008839 vim_snprintf((char *)errbuf, errbuflen,
8840 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008841 errmsg = errbuf;
8842 }
8843 Columns = MIN_COLUMNS;
8844 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008845 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846
Bram Moolenaar071d4272004-06-13 20:20:40 +00008847 /*
8848 * If the screen (shell) height has been changed, assume it is the
8849 * physical screenheight.
8850 */
8851 if (old_Rows != Rows || old_Columns != Columns)
8852 {
8853 /* Changing the screen size is not allowed while updating the screen. */
8854 if (updating_screen)
8855 *pp = old_value;
8856 else if (full_screen
8857#ifdef FEAT_GUI
8858 && !gui.starting
8859#endif
8860 )
8861 set_shellsize((int)Columns, (int)Rows, TRUE);
8862 else
8863 {
8864 /* Postpone the resizing; check the size and cmdline position for
8865 * messages. */
8866 check_shellsize();
8867 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8868 cmdline_row = Rows - p_ch;
8869 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008870 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008871 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872 }
8873
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874 if (curbuf->b_p_ts <= 0)
8875 {
8876 errmsg = e_positive;
8877 curbuf->b_p_ts = 8;
8878 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008879 if (p_tm < 0)
8880 {
8881 errmsg = e_positive;
8882 p_tm = 0;
8883 }
8884 if ((curwin->w_p_scr <= 0
8885 || (curwin->w_p_scr > curwin->w_height
8886 && curwin->w_height > 0))
8887 && full_screen)
8888 {
8889 if (pp == &(curwin->w_p_scr))
8890 {
8891 if (curwin->w_p_scr != 0)
8892 errmsg = e_scroll;
8893 win_comp_scroll(curwin);
8894 }
8895 /* If 'scroll' became invalid because of a side effect silently adjust
8896 * it. */
8897 else if (curwin->w_p_scr <= 0)
8898 curwin->w_p_scr = 1;
8899 else /* curwin->w_p_scr > curwin->w_height */
8900 curwin->w_p_scr = curwin->w_height;
8901 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008902 if (p_hi < 0)
8903 {
8904 errmsg = e_positive;
8905 p_hi = 0;
8906 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008907 else if (p_hi > 10000)
8908 {
8909 errmsg = e_invarg;
8910 p_hi = 10000;
8911 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008912 if (p_re < 0 || p_re > 2)
8913 {
8914 errmsg = e_invarg;
8915 p_re = 0;
8916 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008917 if (p_report < 0)
8918 {
8919 errmsg = e_positive;
8920 p_report = 1;
8921 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008922 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923 {
8924 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8925 p_sj = Rows / 2;
8926 else
8927 {
8928 errmsg = e_scroll;
8929 p_sj = 1;
8930 }
8931 }
8932 if (p_so < 0 && full_screen)
8933 {
8934 errmsg = e_scroll;
8935 p_so = 0;
8936 }
8937 if (p_siso < 0 && full_screen)
8938 {
8939 errmsg = e_positive;
8940 p_siso = 0;
8941 }
8942#ifdef FEAT_CMDWIN
8943 if (p_cwh < 1)
8944 {
8945 errmsg = e_positive;
8946 p_cwh = 1;
8947 }
8948#endif
8949 if (p_ut < 0)
8950 {
8951 errmsg = e_positive;
8952 p_ut = 2000;
8953 }
8954 if (p_ss < 0)
8955 {
8956 errmsg = e_positive;
8957 p_ss = 0;
8958 }
8959
8960 /* May set global value for local option. */
8961 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8962 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8963
8964 options[opt_idx].flags |= P_WAS_SET;
8965
Bram Moolenaar53744302015-07-17 17:38:22 +02008966#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8967 if (!starting && errmsg == NULL)
8968 {
8969 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008970 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8971 vim_snprintf((char *)buf_new, 10, "%ld", value);
8972 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008973 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8974 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8975 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8976 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8977 reset_v_option_vars();
8978 }
8979#endif
8980
Bram Moolenaar071d4272004-06-13 20:20:40 +00008981 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008982 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008983 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008984 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985 check_redraw(options[opt_idx].flags);
8986
8987 return errmsg;
8988}
8989
8990/*
8991 * Called after an option changed: check if something needs to be redrawn.
8992 */
8993 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008994check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995{
8996 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008997 int doclear = (flags & P_RCLR) == P_RCLR;
8998 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008999
9000#ifdef FEAT_WINDOWS
9001 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9002 status_redraw_all();
9003#endif
9004
9005 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9006 changed_window_setting();
9007 if (flags & P_RBUF)
9008 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009009 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009010 redraw_all_later(CLEAR);
9011 else if (all)
9012 redraw_all_later(NOT_VALID);
9013}
9014
9015/*
9016 * Find index for option 'arg'.
9017 * Return -1 if not found.
9018 */
9019 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009020findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009021{
9022 int opt_idx;
9023 char *s, *p;
9024 static short quick_tab[27] = {0, 0}; /* quick access table */
9025 int is_term_opt;
9026
9027 /*
9028 * For first call: Initialize the quick-access table.
9029 * It contains the index for the first option that starts with a certain
9030 * letter. There are 26 letters, plus the first "t_" option.
9031 */
9032 if (quick_tab[1] == 0)
9033 {
9034 p = options[0].fullname;
9035 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9036 {
9037 if (s[0] != p[0])
9038 {
9039 if (s[0] == 't' && s[1] == '_')
9040 quick_tab[26] = opt_idx;
9041 else
9042 quick_tab[CharOrdLow(s[0])] = opt_idx;
9043 }
9044 p = s;
9045 }
9046 }
9047
9048 /*
9049 * Check for name starting with an illegal character.
9050 */
9051#ifdef EBCDIC
9052 if (!islower(arg[0]))
9053#else
9054 if (arg[0] < 'a' || arg[0] > 'z')
9055#endif
9056 return -1;
9057
9058 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9059 if (is_term_opt)
9060 opt_idx = quick_tab[26];
9061 else
9062 opt_idx = quick_tab[CharOrdLow(arg[0])];
9063 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9064 {
9065 if (STRCMP(arg, s) == 0) /* match full name */
9066 break;
9067 }
9068 if (s == NULL && !is_term_opt)
9069 {
9070 opt_idx = quick_tab[CharOrdLow(arg[0])];
9071 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9072 {
9073 s = options[opt_idx].shortname;
9074 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9075 break;
9076 s = NULL;
9077 }
9078 }
9079 if (s == NULL)
9080 opt_idx = -1;
9081 return opt_idx;
9082}
9083
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009084#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085/*
9086 * Get the value for an option.
9087 *
9088 * Returns:
9089 * Number or Toggle option: 1, *numval gets value.
9090 * String option: 0, *stringval gets allocated string.
9091 * Hidden Number or Toggle option: -1.
9092 * hidden String option: -2.
9093 * unknown option: -3.
9094 */
9095 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009096get_option_value(
9097 char_u *name,
9098 long *numval,
9099 char_u **stringval, /* NULL when only checking existence */
9100 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009101{
9102 int opt_idx;
9103 char_u *varp;
9104
9105 opt_idx = findoption(name);
9106 if (opt_idx < 0) /* unknown option */
9107 return -3;
9108
9109 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9110
9111 if (options[opt_idx].flags & P_STRING)
9112 {
9113 if (varp == NULL) /* hidden option */
9114 return -2;
9115 if (stringval != NULL)
9116 {
9117#ifdef FEAT_CRYPT
9118 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009119 if ((char_u **)varp == &curbuf->b_p_key
9120 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121 *stringval = vim_strsave((char_u *)"*****");
9122 else
9123#endif
9124 *stringval = vim_strsave(*(char_u **)(varp));
9125 }
9126 return 0;
9127 }
9128
9129 if (varp == NULL) /* hidden option */
9130 return -1;
9131 if (options[opt_idx].flags & P_NUM)
9132 *numval = *(long *)varp;
9133 else
9134 {
9135 /* Special case: 'modified' is b_changed, but we also want to consider
9136 * it set when 'ff' or 'fenc' changed. */
9137 if ((int *)varp == &curbuf->b_changed)
9138 *numval = curbufIsChanged();
9139 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009140 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009141 }
9142 return 1;
9143}
9144#endif
9145
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009146#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009147/*
9148 * Returns the option attributes and its value. Unlike the above function it
9149 * will return either global value or local value of the option depending on
9150 * what was requested, but it will never return global value if it was
9151 * requested to return local one and vice versa. Neither it will return
9152 * buffer-local value if it was requested to return window-local one.
9153 *
9154 * Pretends that option is absent if it is not present in the requested scope
9155 * (i.e. has no global, window-local or buffer-local value depending on
9156 * opt_type). Uses
9157 *
9158 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009159 * 0 hidden or unknown option, also option that does not have requested
9160 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009161 * see SOPT_* in vim.h for other flags
9162 *
9163 * Possible opt_type values: see SREQ_* in vim.h
9164 */
9165 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009166get_option_value_strict(
9167 char_u *name,
9168 long *numval,
9169 char_u **stringval, /* NULL when only obtaining attributes */
9170 int opt_type,
9171 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009172{
9173 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009174 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009175 struct vimoption *p;
9176 int r = 0;
9177
9178 opt_idx = findoption(name);
9179 if (opt_idx < 0)
9180 return 0;
9181
9182 p = &(options[opt_idx]);
9183
9184 /* Hidden option */
9185 if (p->var == NULL)
9186 return 0;
9187
9188 if (p->flags & P_BOOL)
9189 r |= SOPT_BOOL;
9190 else if (p->flags & P_NUM)
9191 r |= SOPT_NUM;
9192 else if (p->flags & P_STRING)
9193 r |= SOPT_STRING;
9194
9195 if (p->indir == PV_NONE)
9196 {
9197 if (opt_type == SREQ_GLOBAL)
9198 r |= SOPT_GLOBAL;
9199 else
9200 return 0; /* Did not request global-only option */
9201 }
9202 else
9203 {
9204 if (p->indir & PV_BOTH)
9205 r |= SOPT_GLOBAL;
9206 else if (opt_type == SREQ_GLOBAL)
9207 return 0; /* Requested global option */
9208
9209 if (p->indir & PV_WIN)
9210 {
9211 if (opt_type == SREQ_BUF)
9212 return 0; /* Did not request window-local option */
9213 else
9214 r |= SOPT_WIN;
9215 }
9216 else if (p->indir & PV_BUF)
9217 {
9218 if (opt_type == SREQ_WIN)
9219 return 0; /* Did not request buffer-local option */
9220 else
9221 r |= SOPT_BUF;
9222 }
9223 }
9224
9225 if (stringval == NULL)
9226 return r;
9227
9228 if (opt_type == SREQ_GLOBAL)
9229 varp = p->var;
9230 else
9231 {
9232 if (opt_type == SREQ_BUF)
9233 {
9234 /* Special case: 'modified' is b_changed, but we also want to
9235 * consider it set when 'ff' or 'fenc' changed. */
9236 if (p->indir == PV_MOD)
9237 {
9238 *numval = bufIsChanged((buf_T *) from);
9239 varp = NULL;
9240 }
9241#ifdef FEAT_CRYPT
9242 else if (p->indir == PV_KEY)
9243 {
9244 /* never return the value of the crypt key */
9245 *stringval = NULL;
9246 varp = NULL;
9247 }
9248#endif
9249 else
9250 {
9251 aco_save_T aco;
9252 aucmd_prepbuf(&aco, (buf_T *) from);
9253 varp = get_varp(p);
9254 aucmd_restbuf(&aco);
9255 }
9256 }
9257 else if (opt_type == SREQ_WIN)
9258 {
9259 win_T *save_curwin;
9260 save_curwin = curwin;
9261 curwin = (win_T *) from;
9262 curbuf = curwin->w_buffer;
9263 varp = get_varp(p);
9264 curwin = save_curwin;
9265 curbuf = curwin->w_buffer;
9266 }
9267 if (varp == p->var)
9268 return (r | SOPT_UNSET);
9269 }
9270
9271 if (varp != NULL)
9272 {
9273 if (p->flags & P_STRING)
9274 *stringval = vim_strsave(*(char_u **)(varp));
9275 else if (p->flags & P_NUM)
9276 *numval = *(long *) varp;
9277 else
9278 *numval = *(int *)varp;
9279 }
9280
9281 return r;
9282}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009283
9284/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009285 * Iterate over options. First argument is a pointer to a pointer to a
9286 * structure inside options[] array, second is option type like in the above
9287 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009288 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009289 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009290 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009291 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009292 * first argument to NULL.
9293 *
9294 * Returns full option name for current option on each call.
9295 */
9296 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009297option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009298{
9299 struct vimoption *ret = NULL;
9300 do
9301 {
9302 if (*option == NULL)
9303 *option = (void *) options;
9304 else if (((struct vimoption *) (*option))->fullname == NULL)
9305 {
9306 *option = NULL;
9307 return NULL;
9308 }
9309 else
9310 *option = (void *) (((struct vimoption *) (*option)) + 1);
9311
9312 ret = ((struct vimoption *) (*option));
9313
9314 /* Hidden option */
9315 if (ret->var == NULL)
9316 {
9317 ret = NULL;
9318 continue;
9319 }
9320
9321 switch (opt_type)
9322 {
9323 case SREQ_GLOBAL:
9324 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9325 ret = NULL;
9326 break;
9327 case SREQ_BUF:
9328 if (!(ret->indir & PV_BUF))
9329 ret = NULL;
9330 break;
9331 case SREQ_WIN:
9332 if (!(ret->indir & PV_WIN))
9333 ret = NULL;
9334 break;
9335 default:
9336 EMSG2(_(e_intern2), "option_iter_next()");
9337 return NULL;
9338 }
9339 }
9340 while (ret == NULL);
9341
9342 return (char_u *)ret->fullname;
9343}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009344#endif
9345
Bram Moolenaar071d4272004-06-13 20:20:40 +00009346/*
9347 * Set the value of option "name".
9348 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009349 *
9350 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009351 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009352 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009353set_option_value(
9354 char_u *name,
9355 long number,
9356 char_u *string,
9357 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009358{
9359 int opt_idx;
9360 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009361 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362
9363 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009364 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365 EMSG2(_("E355: Unknown option: %s"), name);
9366 else
9367 {
9368 flags = options[opt_idx].flags;
9369#ifdef HAVE_SANDBOX
9370 /* Disallow changing some options in the sandbox */
9371 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009372 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009373 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009374 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009375 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009377 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009378 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379 else
9380 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009381 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382 if (varp != NULL) /* hidden option is not changed */
9383 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009384 if (number == 0 && string != NULL)
9385 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009386 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009387
9388 /* Either we are given a string or we are setting option
9389 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009390 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009391 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009392 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009393 {
9394 /* There's another character after zeros or the string
9395 * is empty. In both cases, we are trying to set a
9396 * num option using a string. */
9397 EMSG3(_("E521: Number required: &%s = '%s'"),
9398 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009399 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009400
9401 }
9402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009403 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009404 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009405 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009406 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009407 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009408 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009409 }
9410 }
9411 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009412 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413}
9414
9415/*
9416 * Get the terminal code for a terminal option.
9417 * Returns NULL when not found.
9418 */
9419 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009420get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009421{
9422 int opt_idx;
9423 char_u *varp;
9424
9425 if (tname[0] != 't' || tname[1] != '_' ||
9426 tname[2] == NUL || tname[3] == NUL)
9427 return NULL;
9428 if ((opt_idx = findoption(tname)) >= 0)
9429 {
9430 varp = get_varp(&(options[opt_idx]));
9431 if (varp != NULL)
9432 varp = *(char_u **)(varp);
9433 return varp;
9434 }
9435 return find_termcode(tname + 2);
9436}
9437
9438 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009439get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009440{
9441 int i;
9442
9443 i = findoption((char_u *)"hl");
9444 if (i >= 0)
9445 return options[i].def_val[VI_DEFAULT];
9446 return (char_u *)NULL;
9447}
9448
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009449#if defined(FEAT_MBYTE) || defined(PROTO)
9450 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009451get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009452{
9453 int i;
9454
9455 i = findoption((char_u *)"enc");
9456 if (i >= 0)
9457 return options[i].def_val[VI_DEFAULT];
9458 return (char_u *)NULL;
9459}
9460#endif
9461
Bram Moolenaar071d4272004-06-13 20:20:40 +00009462/*
9463 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9464 */
9465 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009466find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009467{
9468 int key;
9469 int modifiers;
9470
9471 /*
9472 * Don't use get_special_key_code() for t_xx, we don't want it to call
9473 * add_termcap_entry().
9474 */
9475 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9476 key = TERMCAP2KEY(arg[2], arg[3]);
9477 else
9478 {
9479 --arg; /* put arg at the '<' */
9480 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009481 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009482 if (modifiers) /* can't handle modifiers here */
9483 key = 0;
9484 }
9485 return key;
9486}
9487
9488/*
9489 * if 'all' == 0: show changed options
9490 * if 'all' == 1: show all normal options
9491 * if 'all' == 2: show all terminal options
9492 */
9493 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009494showoptions(
9495 int all,
9496 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009497{
9498 struct vimoption *p;
9499 int col;
9500 int isterm;
9501 char_u *varp;
9502 struct vimoption **items;
9503 int item_count;
9504 int run;
9505 int row, rows;
9506 int cols;
9507 int i;
9508 int len;
9509
9510#define INC 20
9511#define GAP 3
9512
9513 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9514 PARAM_COUNT));
9515 if (items == NULL)
9516 return;
9517
9518 /* Highlight title */
9519 if (all == 2)
9520 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9521 else if (opt_flags & OPT_GLOBAL)
9522 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9523 else if (opt_flags & OPT_LOCAL)
9524 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9525 else
9526 MSG_PUTS_TITLE(_("\n--- Options ---"));
9527
9528 /*
9529 * do the loop two times:
9530 * 1. display the short items
9531 * 2. display the long items (only strings and numbers)
9532 */
9533 for (run = 1; run <= 2 && !got_int; ++run)
9534 {
9535 /*
9536 * collect the items in items[]
9537 */
9538 item_count = 0;
9539 for (p = &options[0]; p->fullname != NULL; p++)
9540 {
9541 varp = NULL;
9542 isterm = istermoption(p);
9543 if (opt_flags != 0)
9544 {
9545 if (p->indir != PV_NONE && !isterm)
9546 varp = get_varp_scope(p, opt_flags);
9547 }
9548 else
9549 varp = get_varp(p);
9550 if (varp != NULL
9551 && ((all == 2 && isterm)
9552 || (all == 1 && !isterm)
9553 || (all == 0 && !optval_default(p, varp))))
9554 {
9555 if (p->flags & P_BOOL)
9556 len = 1; /* a toggle option fits always */
9557 else
9558 {
9559 option_value2string(p, opt_flags);
9560 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9561 }
9562 if ((len <= INC - GAP && run == 1) ||
9563 (len > INC - GAP && run == 2))
9564 items[item_count++] = p;
9565 }
9566 }
9567
9568 /*
9569 * display the items
9570 */
9571 if (run == 1)
9572 {
9573 cols = (Columns + GAP - 3) / INC;
9574 if (cols == 0)
9575 cols = 1;
9576 rows = (item_count + cols - 1) / cols;
9577 }
9578 else /* run == 2 */
9579 rows = item_count;
9580 for (row = 0; row < rows && !got_int; ++row)
9581 {
9582 msg_putchar('\n'); /* go to next line */
9583 if (got_int) /* 'q' typed in more */
9584 break;
9585 col = 0;
9586 for (i = row; i < item_count; i += rows)
9587 {
9588 msg_col = col; /* make columns */
9589 showoneopt(items[i], opt_flags);
9590 col += INC;
9591 }
9592 out_flush();
9593 ui_breakcheck();
9594 }
9595 }
9596 vim_free(items);
9597}
9598
9599/*
9600 * Return TRUE if option "p" has its default value.
9601 */
9602 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009603optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009604{
9605 int dvi;
9606
9607 if (varp == NULL)
9608 return TRUE; /* hidden option is always at default */
9609 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9610 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009611 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009612 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009613 /* the cast to long is required for Manx C, long_i is
9614 * needed for MSVC */
9615 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009616 /* P_STRING */
9617 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9618}
9619
9620/*
9621 * showoneopt: show the value of one option
9622 * must not be called with a hidden option!
9623 */
9624 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009625showoneopt(
9626 struct vimoption *p,
9627 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009628{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009629 char_u *varp;
9630 int save_silent = silent_mode;
9631
9632 silent_mode = FALSE;
9633 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009634
9635 varp = get_varp_scope(p, opt_flags);
9636
9637 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9638 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9639 ? !curbufIsChanged() : !*(int *)varp))
9640 MSG_PUTS("no");
9641 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9642 MSG_PUTS("--");
9643 else
9644 MSG_PUTS(" ");
9645 MSG_PUTS(p->fullname);
9646 if (!(p->flags & P_BOOL))
9647 {
9648 msg_putchar('=');
9649 /* put value string in NameBuff */
9650 option_value2string(p, opt_flags);
9651 msg_outtrans(NameBuff);
9652 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009653
9654 silent_mode = save_silent;
9655 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009656}
9657
9658/*
9659 * Write modified options as ":set" commands to a file.
9660 *
9661 * There are three values for "opt_flags":
9662 * OPT_GLOBAL: Write global option values and fresh values of
9663 * buffer-local options (used for start of a session
9664 * file).
9665 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9666 * curwin (used for a vimrc file).
9667 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9668 * and local values for window-local options of
9669 * curwin. Local values are also written when at the
9670 * default value, because a modeline or autocommand
9671 * may have set them when doing ":edit file" and the
9672 * user has set them back at the default or fresh
9673 * value.
9674 * When "local_only" is TRUE, don't write fresh
9675 * values, only local values (for ":mkview").
9676 * (fresh value = value used for a new buffer or window for a local option).
9677 *
9678 * Return FAIL on error, OK otherwise.
9679 */
9680 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009681makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009682{
9683 struct vimoption *p;
9684 char_u *varp; /* currently used value */
9685 char_u *varp_fresh; /* local value */
9686 char_u *varp_local = NULL; /* fresh value */
9687 char *cmd;
9688 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009689 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690
9691 /*
9692 * The options that don't have a default (terminal name, columns, lines)
9693 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009694 * Do the loop over "options[]" twice: once for options with the
9695 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009696 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009697 for (pri = 1; pri >= 0; --pri)
9698 {
9699 for (p = &options[0]; !istermoption(p); p++)
9700 if (!(p->flags & P_NO_MKRC)
9701 && !istermoption(p)
9702 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009703 {
9704 /* skip global option when only doing locals */
9705 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9706 continue;
9707
9708 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9709 * file, they are always buffer-specific. */
9710 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9711 continue;
9712
9713 /* Global values are only written when not at the default value. */
9714 varp = get_varp_scope(p, opt_flags);
9715 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9716 continue;
9717
9718 round = 2;
9719 if (p->indir != PV_NONE)
9720 {
9721 if (p->var == VAR_WIN)
9722 {
9723 /* skip window-local option when only doing globals */
9724 if (!(opt_flags & OPT_LOCAL))
9725 continue;
9726 /* When fresh value of window-local option is not at the
9727 * default, need to write it too. */
9728 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9729 {
9730 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9731 if (!optval_default(p, varp_fresh))
9732 {
9733 round = 1;
9734 varp_local = varp;
9735 varp = varp_fresh;
9736 }
9737 }
9738 }
9739 }
9740
9741 /* Round 1: fresh value for window-local options.
9742 * Round 2: other values */
9743 for ( ; round <= 2; varp = varp_local, ++round)
9744 {
9745 if (round == 1 || (opt_flags & OPT_GLOBAL))
9746 cmd = "set";
9747 else
9748 cmd = "setlocal";
9749
9750 if (p->flags & P_BOOL)
9751 {
9752 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9753 return FAIL;
9754 }
9755 else if (p->flags & P_NUM)
9756 {
9757 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9758 return FAIL;
9759 }
9760 else /* P_STRING */
9761 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009762#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9763 int do_endif = FALSE;
9764
Bram Moolenaar071d4272004-06-13 20:20:40 +00009765 /* Don't set 'syntax' and 'filetype' again if the value is
9766 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009767 if (
9768# if defined(FEAT_SYN_HL)
9769 p->indir == PV_SYN
9770# if defined(FEAT_AUTOCMD)
9771 ||
9772# endif
9773# endif
9774# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009775 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009776# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009777 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009778 {
9779 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9780 *(char_u **)(varp)) < 0
9781 || put_eol(fd) < 0)
9782 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009783 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009784 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009786 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9787 (p->flags & P_EXPAND) != 0) == FAIL)
9788 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009789#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9790 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009791 {
9792 if (put_line(fd, "endif") == FAIL)
9793 return FAIL;
9794 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009796 }
9797 }
9798 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009799 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009800 return OK;
9801}
9802
9803#if defined(FEAT_FOLDING) || defined(PROTO)
9804/*
9805 * Generate set commands for the local fold options only. Used when
9806 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9807 */
9808 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009809makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810{
9811 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9812# ifdef FEAT_EVAL
9813 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9814 == FAIL
9815# endif
9816 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9817 == FAIL
9818 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9819 == FAIL
9820 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9821 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9822 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9823 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9824 )
9825 return FAIL;
9826
9827 return OK;
9828}
9829#endif
9830
9831 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009832put_setstring(
9833 FILE *fd,
9834 char *cmd,
9835 char *name,
9836 char_u **valuep,
9837 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009838{
9839 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009840 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009841
9842 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9843 return FAIL;
9844 if (*valuep != NULL)
9845 {
9846 /* Output 'pastetoggle' as key names. For other
9847 * options some characters have to be escaped with
9848 * CTRL-V or backslash */
9849 if (valuep == &p_pt)
9850 {
9851 s = *valuep;
9852 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009853 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009854 return FAIL;
9855 }
9856 else if (expand)
9857 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009858 buf = alloc(MAXPATHL);
9859 if (buf == NULL)
9860 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009861 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9862 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009863 {
9864 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009866 }
9867 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009868 }
9869 else if (put_escstr(fd, *valuep, 2) == FAIL)
9870 return FAIL;
9871 }
9872 if (put_eol(fd) < 0)
9873 return FAIL;
9874 return OK;
9875}
9876
9877 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009878put_setnum(
9879 FILE *fd,
9880 char *cmd,
9881 char *name,
9882 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009883{
9884 long wc;
9885
9886 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9887 return FAIL;
9888 if (wc_use_keyname((char_u *)valuep, &wc))
9889 {
9890 /* print 'wildchar' and 'wildcharm' as a key name */
9891 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9892 return FAIL;
9893 }
9894 else if (fprintf(fd, "%ld", *valuep) < 0)
9895 return FAIL;
9896 if (put_eol(fd) < 0)
9897 return FAIL;
9898 return OK;
9899}
9900
9901 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009902put_setbool(
9903 FILE *fd,
9904 char *cmd,
9905 char *name,
9906 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009907{
Bram Moolenaar893de922007-10-02 18:40:57 +00009908 if (value < 0) /* global/local option using global value */
9909 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9911 || put_eol(fd) < 0)
9912 return FAIL;
9913 return OK;
9914}
9915
9916/*
9917 * Clear all the terminal options.
9918 * If the option has been allocated, free the memory.
9919 * Terminal options are never hidden or indirect.
9920 */
9921 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009922clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009924 /*
9925 * Reset a few things before clearing the old options. This may cause
9926 * outputting a few things that the terminal doesn't understand, but the
9927 * screen will be cleared later, so this is OK.
9928 */
9929#ifdef FEAT_MOUSE_TTY
9930 mch_setmouse(FALSE); /* switch mouse off */
9931#endif
9932#ifdef FEAT_TITLE
9933 mch_restore_title(3); /* restore window titles */
9934#endif
9935#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9936 /* When starting the GUI close the display opened for the clipboard.
9937 * After restoring the title, because that will need the display. */
9938 if (gui.starting)
9939 clear_xterm_clip();
9940#endif
9941#ifdef WIN3264
9942 /*
9943 * Check if this is allowed now.
9944 */
9945 if (can_end_termcap_mode(FALSE) == TRUE)
9946#endif
9947 stoptermcap(); /* stop termcap mode */
9948
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009949 free_termoptions();
9950}
9951
9952 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009953free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009954{
9955 struct vimoption *p;
9956
Bram Moolenaar071d4272004-06-13 20:20:40 +00009957 for (p = &options[0]; p->fullname != NULL; p++)
9958 if (istermoption(p))
9959 {
9960 if (p->flags & P_ALLOCED)
9961 free_string_option(*(char_u **)(p->var));
9962 if (p->flags & P_DEF_ALLOCED)
9963 free_string_option(p->def_val[VI_DEFAULT]);
9964 *(char_u **)(p->var) = empty_option;
9965 p->def_val[VI_DEFAULT] = empty_option;
9966 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9967 }
9968 clear_termcodes();
9969}
9970
9971/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009972 * Free the string for one term option, if it was allocated.
9973 * Set the string to empty_option and clear allocated flag.
9974 * "var" points to the option value.
9975 */
9976 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009977free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009978{
9979 struct vimoption *p;
9980
9981 for (p = &options[0]; p->fullname != NULL; p++)
9982 if (p->var == var)
9983 {
9984 if (p->flags & P_ALLOCED)
9985 free_string_option(*(char_u **)(p->var));
9986 *(char_u **)(p->var) = empty_option;
9987 p->flags &= ~P_ALLOCED;
9988 break;
9989 }
9990}
9991
9992/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993 * Set the terminal option defaults to the current value.
9994 * Used after setting the terminal name.
9995 */
9996 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009997set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998{
9999 struct vimoption *p;
10000
10001 for (p = &options[0]; p->fullname != NULL; p++)
10002 {
10003 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10004 {
10005 if (p->flags & P_DEF_ALLOCED)
10006 {
10007 free_string_option(p->def_val[VI_DEFAULT]);
10008 p->flags &= ~P_DEF_ALLOCED;
10009 }
10010 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10011 if (p->flags & P_ALLOCED)
10012 {
10013 p->flags |= P_DEF_ALLOCED;
10014 p->flags &= ~P_ALLOCED; /* don't free the value now */
10015 }
10016 }
10017 }
10018}
10019
10020/*
10021 * return TRUE if 'p' starts with 't_'
10022 */
10023 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010024istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010025{
10026 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10027}
10028
10029/*
10030 * Compute columns for ruler and shown command. 'sc_col' is also used to
10031 * decide what the maximum length of a message on the status line can be.
10032 * If there is a status line for the last window, 'sc_col' is independent
10033 * of 'ru_col'.
10034 */
10035
10036#define COL_RULER 17 /* columns needed by standard ruler */
10037
10038 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010039comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040{
10041#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10042 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10043
10044 sc_col = 0;
10045 ru_col = 0;
10046 if (p_ru)
10047 {
10048#ifdef FEAT_STL_OPT
10049 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10050#else
10051 ru_col = COL_RULER + 1;
10052#endif
10053 /* no last status line, adjust sc_col */
10054 if (!last_has_status)
10055 sc_col = ru_col;
10056 }
10057 if (p_sc)
10058 {
10059 sc_col += SHOWCMD_COLS;
10060 if (!p_ru || last_has_status) /* no need for separating space */
10061 ++sc_col;
10062 }
10063 sc_col = Columns - sc_col;
10064 ru_col = Columns - ru_col;
10065 if (sc_col <= 0) /* screen too narrow, will become a mess */
10066 sc_col = 1;
10067 if (ru_col <= 0)
10068 ru_col = 1;
10069#else
10070 sc_col = Columns;
10071 ru_col = Columns;
10072#endif
10073}
10074
10075/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010076 * Unset local option value, similar to ":set opt<".
10077 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010078 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010079unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080{
10081 struct vimoption *p;
10082 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010083 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010084
10085 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010086 if (opt_idx < 0)
10087 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010088 p = &(options[opt_idx]);
10089
10090 switch ((int)p->indir)
10091 {
10092 /* global option with local value: use local value if it's been set */
10093 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010094 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010095 break;
10096 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010097 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010098 break;
10099 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010100 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010101 break;
10102 case PV_AR:
10103 buf->b_p_ar = -1;
10104 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010105 case PV_BKC:
10106 clear_string_option(&buf->b_p_bkc);
10107 buf->b_bkc_flags = 0;
10108 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010109 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010110 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010111 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010112 case PV_TC:
10113 clear_string_option(&buf->b_p_tc);
10114 buf->b_tc_flags = 0;
10115 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010116#ifdef FEAT_FIND_ID
10117 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010118 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010119 break;
10120 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010121 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010122 break;
10123#endif
10124#ifdef FEAT_INS_EXPAND
10125 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010126 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010127 break;
10128 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010129 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010130 break;
10131#endif
10132#ifdef FEAT_QUICKFIX
10133 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010134 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010135 break;
10136 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010137 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010138 break;
10139 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010140 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010141 break;
10142#endif
10143#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10144 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010145 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010146 break;
10147#endif
10148#if defined(FEAT_CRYPT)
10149 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010150 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010151 break;
10152#endif
10153#ifdef FEAT_STL_OPT
10154 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010155 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010156 break;
10157#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010158 case PV_UL:
10159 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10160 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010161#ifdef FEAT_LISP
10162 case PV_LW:
10163 clear_string_option(&buf->b_p_lw);
10164 break;
10165#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010166 }
10167}
10168
10169/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170 * Get pointer to option variable, depending on local or global scope.
10171 */
10172 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010173get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174{
10175 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10176 {
10177 if (p->var == VAR_WIN)
10178 return (char_u *)GLOBAL_WO(get_varp(p));
10179 return p->var;
10180 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010181 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182 {
10183 switch ((int)p->indir)
10184 {
10185#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010186 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10187 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10188 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010190 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10191 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10192 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010193 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010194 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010195 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010197 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10198 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199#endif
10200#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010201 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10202 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010204#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10205 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10206#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010207#if defined(FEAT_CRYPT)
10208 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10209#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010210#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010211 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010212#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010213 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010214#ifdef FEAT_LISP
10215 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10216#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010217 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218 }
10219 return NULL; /* "cannot happen" */
10220 }
10221 return get_varp(p);
10222}
10223
10224/*
10225 * Get pointer to option variable.
10226 */
10227 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010228get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229{
10230 /* hidden option, always return NULL */
10231 if (p->var == NULL)
10232 return NULL;
10233
10234 switch ((int)p->indir)
10235 {
10236 case PV_NONE: return p->var;
10237
10238 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010239 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010240 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010241 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010242 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010243 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010244 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010245 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010247 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010249 case PV_TC: return *curbuf->b_p_tc != NUL
10250 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010251 case PV_BKC: return *curbuf->b_p_bkc != NUL
10252 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010254 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010256 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10258#endif
10259#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010260 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010262 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010263 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10264#endif
10265#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010266 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010267 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010268 case PV_GP: return *curbuf->b_p_gp != NUL
10269 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10270 case PV_MP: return *curbuf->b_p_mp != NUL
10271 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010273#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10274 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10275 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10276#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010277#if defined(FEAT_CRYPT)
10278 case PV_CM: return *curbuf->b_p_cm != NUL
10279 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10280#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010281#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010282 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010283 ? (char_u *)&(curwin->w_p_stl) : p->var;
10284#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010285 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10286 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010287#ifdef FEAT_LISP
10288 case PV_LW: return *curbuf->b_p_lw != NUL
10289 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10290#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010291
10292#ifdef FEAT_ARABIC
10293 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10294#endif
10295 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010296#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010297 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10298#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010299#ifdef FEAT_SYN_HL
10300 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10301 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010302 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010303#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010304#ifdef FEAT_DIFF
10305 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10306#endif
10307#ifdef FEAT_FOLDING
10308 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10309 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10310 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10311 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10312 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10313 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10314 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10315# ifdef FEAT_EVAL
10316 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10317 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10318# endif
10319 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10320#endif
10321 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010322 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010323#ifdef FEAT_LINEBREAK
10324 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10325#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010326#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010327 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010328 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10331 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10332#endif
10333#ifdef FEAT_RIGHTLEFT
10334 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10335 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10336#endif
10337 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10338 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10339#ifdef FEAT_LINEBREAK
10340 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010341 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10342 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343#endif
10344#ifdef FEAT_SCROLLBIND
10345 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10346#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010347#ifdef FEAT_CURSORBIND
10348 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10349#endif
10350#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010351 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10352 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010354
10355 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10356 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10357#ifdef FEAT_MBYTE
10358 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10359#endif
10360#if defined(FEAT_QUICKFIX)
10361 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10362 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10363#endif
10364 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10365 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10366#ifdef FEAT_CINDENT
10367 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10368 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10369 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10370#endif
10371#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10372 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10373#endif
10374#ifdef FEAT_COMMENTS
10375 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10376#endif
10377#ifdef FEAT_FOLDING
10378 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10379#endif
10380#ifdef FEAT_INS_EXPAND
10381 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10382#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010383#ifdef FEAT_COMPL_FUNC
10384 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010385 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010388 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10390#ifdef FEAT_MBYTE
10391 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10392#endif
10393 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10394#ifdef FEAT_AUTOCMD
10395 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10396#endif
10397 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010398 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10400 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10401 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10402 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10403#ifdef FEAT_FIND_ID
10404# ifdef FEAT_EVAL
10405 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10406# endif
10407#endif
10408#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10409 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10410 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10411#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010412#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010413 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10414#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415#ifdef FEAT_CRYPT
10416 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10417#endif
10418#ifdef FEAT_LISP
10419 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10420#endif
10421 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10422 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10423 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10424 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10425 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010427#ifdef FEAT_TEXTOBJ
10428 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010430 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10431#ifdef FEAT_SMARTINDENT
10432 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10433#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10436#ifdef FEAT_SEARCHPATH
10437 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10438#endif
10439 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10440#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010441 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010442 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10443#endif
10444#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010445 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10446 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10447 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448#endif
10449 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10450 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10451 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10452 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010453#ifdef FEAT_PERSISTENT_UNDO
10454 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10455#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010456 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10457#ifdef FEAT_KEYMAP
10458 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10459#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010460#ifdef FEAT_SIGNS
10461 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10462#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010463 default: EMSG(_("E356: get_varp ERROR"));
10464 }
10465 /* always return a valid pointer to avoid a crash! */
10466 return (char_u *)&(curbuf->b_p_wm);
10467}
10468
10469/*
10470 * Get the value of 'equalprg', either the buffer-local one or the global one.
10471 */
10472 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010473get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010474{
10475 if (*curbuf->b_p_ep == NUL)
10476 return p_ep;
10477 return curbuf->b_p_ep;
10478}
10479
10480#if defined(FEAT_WINDOWS) || defined(PROTO)
10481/*
10482 * Copy options from one window to another.
10483 * Used when splitting a window.
10484 */
10485 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010486win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487{
10488 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10489 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10490# ifdef FEAT_RIGHTLEFT
10491# ifdef FEAT_FKMAP
10492 /* Is this right? */
10493 wp_to->w_farsi = wp_from->w_farsi;
10494# endif
10495# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010496#if defined(FEAT_LINEBREAK)
10497 briopt_check(wp_to);
10498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499}
10500#endif
10501
10502/*
10503 * Copy the options from one winopt_T to another.
10504 * Doesn't free the old option values in "to", use clear_winopt() for that.
10505 * The 'scroll' option is not copied, because it depends on the window height.
10506 * The 'previewwindow' option is reset, there can be only one preview window.
10507 */
10508 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010509copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510{
10511#ifdef FEAT_ARABIC
10512 to->wo_arab = from->wo_arab;
10513#endif
10514 to->wo_list = from->wo_list;
10515 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010516 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010517#ifdef FEAT_LINEBREAK
10518 to->wo_nuw = from->wo_nuw;
10519#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520#ifdef FEAT_RIGHTLEFT
10521 to->wo_rl = from->wo_rl;
10522 to->wo_rlc = vim_strsave(from->wo_rlc);
10523#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010524#ifdef FEAT_STL_OPT
10525 to->wo_stl = vim_strsave(from->wo_stl);
10526#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010528#ifdef FEAT_DIFF
10529 to->wo_wrap_save = from->wo_wrap_save;
10530#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010531#ifdef FEAT_LINEBREAK
10532 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010533 to->wo_bri = from->wo_bri;
10534 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535#endif
10536#ifdef FEAT_SCROLLBIND
10537 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010538 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010540#ifdef FEAT_CURSORBIND
10541 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010542 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010543#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010544#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010545 to->wo_spell = from->wo_spell;
10546#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010547#ifdef FEAT_SYN_HL
10548 to->wo_cuc = from->wo_cuc;
10549 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010550 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010551#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552#ifdef FEAT_DIFF
10553 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010554 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010556#ifdef FEAT_CONCEAL
10557 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010558 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560#ifdef FEAT_FOLDING
10561 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010562 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010564 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010565 to->wo_fdi = vim_strsave(from->wo_fdi);
10566 to->wo_fml = from->wo_fml;
10567 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010568 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010570 to->wo_fdm_save = from->wo_diff_saved
10571 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572 to->wo_fdn = from->wo_fdn;
10573# ifdef FEAT_EVAL
10574 to->wo_fde = vim_strsave(from->wo_fde);
10575 to->wo_fdt = vim_strsave(from->wo_fdt);
10576# endif
10577 to->wo_fmr = vim_strsave(from->wo_fmr);
10578#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010579#ifdef FEAT_SIGNS
10580 to->wo_scl = vim_strsave(from->wo_scl);
10581#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582 check_winopt(to); /* don't want NULL pointers */
10583}
10584
10585/*
10586 * Check string options in a window for a NULL value.
10587 */
10588 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010589check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590{
10591 check_winopt(&win->w_onebuf_opt);
10592 check_winopt(&win->w_allbuf_opt);
10593}
10594
10595/*
10596 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10597 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010598 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010599check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600{
10601#ifdef FEAT_FOLDING
10602 check_string_option(&wop->wo_fdi);
10603 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010604 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605# ifdef FEAT_EVAL
10606 check_string_option(&wop->wo_fde);
10607 check_string_option(&wop->wo_fdt);
10608# endif
10609 check_string_option(&wop->wo_fmr);
10610#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010611#ifdef FEAT_SIGNS
10612 check_string_option(&wop->wo_scl);
10613#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010614#ifdef FEAT_RIGHTLEFT
10615 check_string_option(&wop->wo_rlc);
10616#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010617#ifdef FEAT_STL_OPT
10618 check_string_option(&wop->wo_stl);
10619#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010620#ifdef FEAT_SYN_HL
10621 check_string_option(&wop->wo_cc);
10622#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010623#ifdef FEAT_CONCEAL
10624 check_string_option(&wop->wo_cocu);
10625#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010626#ifdef FEAT_LINEBREAK
10627 check_string_option(&wop->wo_briopt);
10628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629}
10630
10631/*
10632 * Free the allocated memory inside a winopt_T.
10633 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010635clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636{
10637#ifdef FEAT_FOLDING
10638 clear_string_option(&wop->wo_fdi);
10639 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010640 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010641# ifdef FEAT_EVAL
10642 clear_string_option(&wop->wo_fde);
10643 clear_string_option(&wop->wo_fdt);
10644# endif
10645 clear_string_option(&wop->wo_fmr);
10646#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010647#ifdef FEAT_SIGNS
10648 clear_string_option(&wop->wo_scl);
10649#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010650#ifdef FEAT_LINEBREAK
10651 clear_string_option(&wop->wo_briopt);
10652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653#ifdef FEAT_RIGHTLEFT
10654 clear_string_option(&wop->wo_rlc);
10655#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010656#ifdef FEAT_STL_OPT
10657 clear_string_option(&wop->wo_stl);
10658#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010659#ifdef FEAT_SYN_HL
10660 clear_string_option(&wop->wo_cc);
10661#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010662#ifdef FEAT_CONCEAL
10663 clear_string_option(&wop->wo_cocu);
10664#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010665}
10666
10667/*
10668 * Copy global option values to local options for one buffer.
10669 * Used when creating a new buffer and sometimes when entering a buffer.
10670 * flags:
10671 * BCO_ENTER We will enter the buf buffer.
10672 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10673 * appropriate.
10674 * BCO_NOHELP Don't copy the values to a help buffer.
10675 */
10676 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010677buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010678{
10679 int should_copy = TRUE;
10680 char_u *save_p_isk = NULL; /* init for GCC */
10681 int dont_do_help;
10682 int did_isk = FALSE;
10683
10684 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685 * Skip this when the option defaults have not been set yet. Happens when
10686 * main() allocates the first buffer.
10687 */
10688 if (p_cpo != NULL)
10689 {
10690 /*
10691 * Always copy when entering and 'cpo' contains 'S'.
10692 * Don't copy when already initialized.
10693 * Don't copy when 'cpo' contains 's' and not entering.
10694 * 'S' BCO_ENTER initialized 's' should_copy
10695 * yes yes X X TRUE
10696 * yes no yes X FALSE
10697 * no X yes X FALSE
10698 * X no no yes FALSE
10699 * X no no no TRUE
10700 * no yes no X TRUE
10701 */
10702 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10703 && (buf->b_p_initialized
10704 || (!(flags & BCO_ENTER)
10705 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10706 should_copy = FALSE;
10707
10708 if (should_copy || (flags & BCO_ALWAYS))
10709 {
10710 /* Don't copy the options specific to a help buffer when
10711 * BCO_NOHELP is given or the options were initialized already
10712 * (jumping back to a help file with CTRL-T or CTRL-O) */
10713 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10714 || buf->b_p_initialized;
10715 if (dont_do_help) /* don't free b_p_isk */
10716 {
10717 save_p_isk = buf->b_p_isk;
10718 buf->b_p_isk = NULL;
10719 }
10720 /*
10721 * Always free the allocated strings.
10722 * If not already initialized, set 'readonly' and copy 'fileformat'.
10723 */
10724 if (!buf->b_p_initialized)
10725 {
10726 free_buf_options(buf, TRUE);
10727 buf->b_p_ro = FALSE; /* don't copy readonly */
10728 buf->b_p_tx = p_tx;
10729#ifdef FEAT_MBYTE
10730 buf->b_p_fenc = vim_strsave(p_fenc);
10731#endif
10732 buf->b_p_ff = vim_strsave(p_ff);
10733#if defined(FEAT_QUICKFIX)
10734 buf->b_p_bh = empty_option;
10735 buf->b_p_bt = empty_option;
10736#endif
10737 }
10738 else
10739 free_buf_options(buf, FALSE);
10740
10741 buf->b_p_ai = p_ai;
10742 buf->b_p_ai_nopaste = p_ai_nopaste;
10743 buf->b_p_sw = p_sw;
10744 buf->b_p_tw = p_tw;
10745 buf->b_p_tw_nopaste = p_tw_nopaste;
10746 buf->b_p_tw_nobin = p_tw_nobin;
10747 buf->b_p_wm = p_wm;
10748 buf->b_p_wm_nopaste = p_wm_nopaste;
10749 buf->b_p_wm_nobin = p_wm_nobin;
10750 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010751#ifdef FEAT_MBYTE
10752 buf->b_p_bomb = p_bomb;
10753#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010754 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755 buf->b_p_et = p_et;
10756 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010757 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010758 buf->b_p_ml = p_ml;
10759 buf->b_p_ml_nobin = p_ml_nobin;
10760 buf->b_p_inf = p_inf;
10761 buf->b_p_swf = p_swf;
10762#ifdef FEAT_INS_EXPAND
10763 buf->b_p_cpt = vim_strsave(p_cpt);
10764#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010765#ifdef FEAT_COMPL_FUNC
10766 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010767 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010768#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010769 buf->b_p_sts = p_sts;
10770 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772#ifdef FEAT_COMMENTS
10773 buf->b_p_com = vim_strsave(p_com);
10774#endif
10775#ifdef FEAT_FOLDING
10776 buf->b_p_cms = vim_strsave(p_cms);
10777#endif
10778 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010779 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780 buf->b_p_nf = vim_strsave(p_nf);
10781 buf->b_p_mps = vim_strsave(p_mps);
10782#ifdef FEAT_SMARTINDENT
10783 buf->b_p_si = p_si;
10784#endif
10785 buf->b_p_ci = p_ci;
10786#ifdef FEAT_CINDENT
10787 buf->b_p_cin = p_cin;
10788 buf->b_p_cink = vim_strsave(p_cink);
10789 buf->b_p_cino = vim_strsave(p_cino);
10790#endif
10791#ifdef FEAT_AUTOCMD
10792 /* Don't copy 'filetype', it must be detected */
10793 buf->b_p_ft = empty_option;
10794#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010795 buf->b_p_pi = p_pi;
10796#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10797 buf->b_p_cinw = vim_strsave(p_cinw);
10798#endif
10799#ifdef FEAT_LISP
10800 buf->b_p_lisp = p_lisp;
10801#endif
10802#ifdef FEAT_SYN_HL
10803 /* Don't copy 'syntax', it must be set */
10804 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010805 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010806 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010807#endif
10808#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010809 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010810 (void)compile_cap_prog(&buf->b_s);
10811 buf->b_s.b_p_spf = vim_strsave(p_spf);
10812 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813#endif
10814#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10815 buf->b_p_inde = vim_strsave(p_inde);
10816 buf->b_p_indk = vim_strsave(p_indk);
10817#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010818#if defined(FEAT_EVAL)
10819 buf->b_p_fex = vim_strsave(p_fex);
10820#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821#ifdef FEAT_CRYPT
10822 buf->b_p_key = vim_strsave(p_key);
10823#endif
10824#ifdef FEAT_SEARCHPATH
10825 buf->b_p_sua = vim_strsave(p_sua);
10826#endif
10827#ifdef FEAT_KEYMAP
10828 buf->b_p_keymap = vim_strsave(p_keymap);
10829 buf->b_kmap_state |= KEYMAP_INIT;
10830#endif
10831 /* This isn't really an option, but copying the langmap and IME
10832 * state from the current buffer is better than resetting it. */
10833 buf->b_p_iminsert = p_iminsert;
10834 buf->b_p_imsearch = p_imsearch;
10835
10836 /* options that are normally global but also have a local value
10837 * are not copied, start using the global value */
10838 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010839 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010840 buf->b_p_bkc = empty_option;
10841 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842#ifdef FEAT_QUICKFIX
10843 buf->b_p_gp = empty_option;
10844 buf->b_p_mp = empty_option;
10845 buf->b_p_efm = empty_option;
10846#endif
10847 buf->b_p_ep = empty_option;
10848 buf->b_p_kp = empty_option;
10849 buf->b_p_path = empty_option;
10850 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010851 buf->b_p_tc = empty_option;
10852 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853#ifdef FEAT_FIND_ID
10854 buf->b_p_def = empty_option;
10855 buf->b_p_inc = empty_option;
10856# ifdef FEAT_EVAL
10857 buf->b_p_inex = vim_strsave(p_inex);
10858# endif
10859#endif
10860#ifdef FEAT_INS_EXPAND
10861 buf->b_p_dict = empty_option;
10862 buf->b_p_tsr = empty_option;
10863#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010864#ifdef FEAT_TEXTOBJ
10865 buf->b_p_qe = vim_strsave(p_qe);
10866#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010867#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10868 buf->b_p_bexpr = empty_option;
10869#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010870#if defined(FEAT_CRYPT)
10871 buf->b_p_cm = empty_option;
10872#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010873#ifdef FEAT_PERSISTENT_UNDO
10874 buf->b_p_udf = p_udf;
10875#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010876#ifdef FEAT_LISP
10877 buf->b_p_lw = empty_option;
10878#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879
10880 /*
10881 * Don't copy the options set by ex_help(), use the saved values,
10882 * when going from a help buffer to a non-help buffer.
10883 * Don't touch these at all when BCO_NOHELP is used and going from
10884 * or to a help buffer.
10885 */
10886 if (dont_do_help)
10887 buf->b_p_isk = save_p_isk;
10888 else
10889 {
10890 buf->b_p_isk = vim_strsave(p_isk);
10891 did_isk = TRUE;
10892 buf->b_p_ts = p_ts;
10893 buf->b_help = FALSE;
10894#ifdef FEAT_QUICKFIX
10895 if (buf->b_p_bt[0] == 'h')
10896 clear_string_option(&buf->b_p_bt);
10897#endif
10898 buf->b_p_ma = p_ma;
10899 }
10900 }
10901
10902 /*
10903 * When the options should be copied (ignoring BCO_ALWAYS), set the
10904 * flag that indicates that the options have been initialized.
10905 */
10906 if (should_copy)
10907 buf->b_p_initialized = TRUE;
10908 }
10909
10910 check_buf_options(buf); /* make sure we don't have NULLs */
10911 if (did_isk)
10912 (void)buf_init_chartab(buf, FALSE);
10913}
10914
10915/*
10916 * Reset the 'modifiable' option and its default value.
10917 */
10918 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010919reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920{
10921 int opt_idx;
10922
10923 curbuf->b_p_ma = FALSE;
10924 p_ma = FALSE;
10925 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010926 if (opt_idx >= 0)
10927 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010928}
10929
10930/*
10931 * Set the global value for 'iminsert' to the local value.
10932 */
10933 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010934set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935{
10936 p_iminsert = curbuf->b_p_iminsert;
10937}
10938
10939/*
10940 * Set the global value for 'imsearch' to the local value.
10941 */
10942 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010943set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944{
10945 p_imsearch = curbuf->b_p_imsearch;
10946}
10947
10948#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10949static int expand_option_idx = -1;
10950static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10951static int expand_option_flags = 0;
10952
10953 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010954set_context_in_set_cmd(
10955 expand_T *xp,
10956 char_u *arg,
10957 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010958{
10959 int nextchar;
10960 long_u flags = 0; /* init for GCC */
10961 int opt_idx = 0; /* init for GCC */
10962 char_u *p;
10963 char_u *s;
10964 int is_term_option = FALSE;
10965 int key;
10966
10967 expand_option_flags = opt_flags;
10968
10969 xp->xp_context = EXPAND_SETTINGS;
10970 if (*arg == NUL)
10971 {
10972 xp->xp_pattern = arg;
10973 return;
10974 }
10975 p = arg + STRLEN(arg) - 1;
10976 if (*p == ' ' && *(p - 1) != '\\')
10977 {
10978 xp->xp_pattern = p + 1;
10979 return;
10980 }
10981 while (p > arg)
10982 {
10983 s = p;
10984 /* count number of backslashes before ' ' or ',' */
10985 if (*p == ' ' || *p == ',')
10986 {
10987 while (s > arg && *(s - 1) == '\\')
10988 --s;
10989 }
10990 /* break at a space with an even number of backslashes */
10991 if (*p == ' ' && ((p - s) & 1) == 0)
10992 {
10993 ++p;
10994 break;
10995 }
10996 --p;
10997 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010998 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010999 {
11000 xp->xp_context = EXPAND_BOOL_SETTINGS;
11001 p += 2;
11002 }
11003 if (STRNCMP(p, "inv", 3) == 0)
11004 {
11005 xp->xp_context = EXPAND_BOOL_SETTINGS;
11006 p += 3;
11007 }
11008 xp->xp_pattern = arg = p;
11009 if (*arg == '<')
11010 {
11011 while (*p != '>')
11012 if (*p++ == NUL) /* expand terminal option name */
11013 return;
11014 key = get_special_key_code(arg + 1);
11015 if (key == 0) /* unknown name */
11016 {
11017 xp->xp_context = EXPAND_NOTHING;
11018 return;
11019 }
11020 nextchar = *++p;
11021 is_term_option = TRUE;
11022 expand_option_name[2] = KEY2TERMCAP0(key);
11023 expand_option_name[3] = KEY2TERMCAP1(key);
11024 }
11025 else
11026 {
11027 if (p[0] == 't' && p[1] == '_')
11028 {
11029 p += 2;
11030 if (*p != NUL)
11031 ++p;
11032 if (*p == NUL)
11033 return; /* expand option name */
11034 nextchar = *++p;
11035 is_term_option = TRUE;
11036 expand_option_name[2] = p[-2];
11037 expand_option_name[3] = p[-1];
11038 }
11039 else
11040 {
11041 /* Allow * wildcard */
11042 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11043 p++;
11044 if (*p == NUL)
11045 return;
11046 nextchar = *p;
11047 *p = NUL;
11048 opt_idx = findoption(arg);
11049 *p = nextchar;
11050 if (opt_idx == -1 || options[opt_idx].var == NULL)
11051 {
11052 xp->xp_context = EXPAND_NOTHING;
11053 return;
11054 }
11055 flags = options[opt_idx].flags;
11056 if (flags & P_BOOL)
11057 {
11058 xp->xp_context = EXPAND_NOTHING;
11059 return;
11060 }
11061 }
11062 }
11063 /* handle "-=" and "+=" */
11064 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11065 {
11066 ++p;
11067 nextchar = '=';
11068 }
11069 if ((nextchar != '=' && nextchar != ':')
11070 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11071 {
11072 xp->xp_context = EXPAND_UNSUCCESSFUL;
11073 return;
11074 }
11075 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11076 {
11077 xp->xp_context = EXPAND_OLD_SETTING;
11078 if (is_term_option)
11079 expand_option_idx = -1;
11080 else
11081 expand_option_idx = opt_idx;
11082 xp->xp_pattern = p + 1;
11083 return;
11084 }
11085 xp->xp_context = EXPAND_NOTHING;
11086 if (is_term_option || (flags & P_NUM))
11087 return;
11088
11089 xp->xp_pattern = p + 1;
11090
11091 if (flags & P_EXPAND)
11092 {
11093 p = options[opt_idx].var;
11094 if (p == (char_u *)&p_bdir
11095 || p == (char_u *)&p_dir
11096 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011097 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098 || p == (char_u *)&p_rtp
11099#ifdef FEAT_SEARCHPATH
11100 || p == (char_u *)&p_cdpath
11101#endif
11102#ifdef FEAT_SESSION
11103 || p == (char_u *)&p_vdir
11104#endif
11105 )
11106 {
11107 xp->xp_context = EXPAND_DIRECTORIES;
11108 if (p == (char_u *)&p_path
11109#ifdef FEAT_SEARCHPATH
11110 || p == (char_u *)&p_cdpath
11111#endif
11112 )
11113 xp->xp_backslash = XP_BS_THREE;
11114 else
11115 xp->xp_backslash = XP_BS_ONE;
11116 }
11117 else
11118 {
11119 xp->xp_context = EXPAND_FILES;
11120 /* for 'tags' need three backslashes for a space */
11121 if (p == (char_u *)&p_tags)
11122 xp->xp_backslash = XP_BS_THREE;
11123 else
11124 xp->xp_backslash = XP_BS_ONE;
11125 }
11126 }
11127
11128 /* For an option that is a list of file names, find the start of the
11129 * last file name. */
11130 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11131 {
11132 /* count number of backslashes before ' ' or ',' */
11133 if (*p == ' ' || *p == ',')
11134 {
11135 s = p;
11136 while (s > xp->xp_pattern && *(s - 1) == '\\')
11137 --s;
11138 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11139 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11140 {
11141 xp->xp_pattern = p + 1;
11142 break;
11143 }
11144 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011145
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011146#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011147 /* for 'spellsuggest' start at "file:" */
11148 if (options[opt_idx].var == (char_u *)&p_sps
11149 && STRNCMP(p, "file:", 5) == 0)
11150 {
11151 xp->xp_pattern = p + 5;
11152 break;
11153 }
11154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155 }
11156
11157 return;
11158}
11159
11160 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011161ExpandSettings(
11162 expand_T *xp,
11163 regmatch_T *regmatch,
11164 int *num_file,
11165 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166{
11167 int num_normal = 0; /* Nr of matching non-term-code settings */
11168 int num_term = 0; /* Nr of matching terminal code settings */
11169 int opt_idx;
11170 int match;
11171 int count = 0;
11172 char_u *str;
11173 int loop;
11174 int is_term_opt;
11175 char_u name_buf[MAX_KEY_NAME_LEN];
11176 static char *(names[]) = {"all", "termcap"};
11177 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11178
11179 /* do this loop twice:
11180 * loop == 0: count the number of matching options
11181 * loop == 1: copy the matching options into allocated memory
11182 */
11183 for (loop = 0; loop <= 1; ++loop)
11184 {
11185 regmatch->rm_ic = ic;
11186 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11187 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011188 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11189 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011190 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11191 {
11192 if (loop == 0)
11193 num_normal++;
11194 else
11195 (*file)[count++] = vim_strsave((char_u *)names[match]);
11196 }
11197 }
11198 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11199 opt_idx++)
11200 {
11201 if (options[opt_idx].var == NULL)
11202 continue;
11203 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11204 && !(options[opt_idx].flags & P_BOOL))
11205 continue;
11206 is_term_opt = istermoption(&options[opt_idx]);
11207 if (is_term_opt && num_normal > 0)
11208 continue;
11209 match = FALSE;
11210 if (vim_regexec(regmatch, str, (colnr_T)0)
11211 || (options[opt_idx].shortname != NULL
11212 && vim_regexec(regmatch,
11213 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11214 match = TRUE;
11215 else if (is_term_opt)
11216 {
11217 name_buf[0] = '<';
11218 name_buf[1] = 't';
11219 name_buf[2] = '_';
11220 name_buf[3] = str[2];
11221 name_buf[4] = str[3];
11222 name_buf[5] = '>';
11223 name_buf[6] = NUL;
11224 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11225 {
11226 match = TRUE;
11227 str = name_buf;
11228 }
11229 }
11230 if (match)
11231 {
11232 if (loop == 0)
11233 {
11234 if (is_term_opt)
11235 num_term++;
11236 else
11237 num_normal++;
11238 }
11239 else
11240 (*file)[count++] = vim_strsave(str);
11241 }
11242 }
11243 /*
11244 * Check terminal key codes, these are not in the option table
11245 */
11246 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11247 {
11248 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11249 {
11250 if (!isprint(str[0]) || !isprint(str[1]))
11251 continue;
11252
11253 name_buf[0] = 't';
11254 name_buf[1] = '_';
11255 name_buf[2] = str[0];
11256 name_buf[3] = str[1];
11257 name_buf[4] = NUL;
11258
11259 match = FALSE;
11260 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11261 match = TRUE;
11262 else
11263 {
11264 name_buf[0] = '<';
11265 name_buf[1] = 't';
11266 name_buf[2] = '_';
11267 name_buf[3] = str[0];
11268 name_buf[4] = str[1];
11269 name_buf[5] = '>';
11270 name_buf[6] = NUL;
11271
11272 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11273 match = TRUE;
11274 }
11275 if (match)
11276 {
11277 if (loop == 0)
11278 num_term++;
11279 else
11280 (*file)[count++] = vim_strsave(name_buf);
11281 }
11282 }
11283
11284 /*
11285 * Check special key names.
11286 */
11287 regmatch->rm_ic = TRUE; /* ignore case here */
11288 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11289 {
11290 name_buf[0] = '<';
11291 STRCPY(name_buf + 1, str);
11292 STRCAT(name_buf, ">");
11293
11294 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11295 {
11296 if (loop == 0)
11297 num_term++;
11298 else
11299 (*file)[count++] = vim_strsave(name_buf);
11300 }
11301 }
11302 }
11303 if (loop == 0)
11304 {
11305 if (num_normal > 0)
11306 *num_file = num_normal;
11307 else if (num_term > 0)
11308 *num_file = num_term;
11309 else
11310 return OK;
11311 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11312 if (*file == NULL)
11313 {
11314 *file = (char_u **)"";
11315 return FAIL;
11316 }
11317 }
11318 }
11319 return OK;
11320}
11321
11322 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011323ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011324{
11325 char_u *var = NULL; /* init for GCC */
11326 char_u *buf;
11327
11328 *num_file = 0;
11329 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11330 if (*file == NULL)
11331 return FAIL;
11332
11333 /*
11334 * For a terminal key code expand_option_idx is < 0.
11335 */
11336 if (expand_option_idx < 0)
11337 {
11338 var = find_termcode(expand_option_name + 2);
11339 if (var == NULL)
11340 expand_option_idx = findoption(expand_option_name);
11341 }
11342
11343 if (expand_option_idx >= 0)
11344 {
11345 /* put string of option value in NameBuff */
11346 option_value2string(&options[expand_option_idx], expand_option_flags);
11347 var = NameBuff;
11348 }
11349 else if (var == NULL)
11350 var = (char_u *)"";
11351
11352 /* A backslash is required before some characters. This is the reverse of
11353 * what happens in do_set(). */
11354 buf = vim_strsave_escaped(var, escape_chars);
11355
11356 if (buf == NULL)
11357 {
11358 vim_free(*file);
11359 *file = NULL;
11360 return FAIL;
11361 }
11362
11363#ifdef BACKSLASH_IN_FILENAME
11364 /* For MS-Windows et al. we don't double backslashes at the start and
11365 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011366 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011367 if (var[0] == '\\' && var[1] == '\\'
11368 && expand_option_idx >= 0
11369 && (options[expand_option_idx].flags & P_EXPAND)
11370 && vim_isfilec(var[2])
11371 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011372 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011373#endif
11374
11375 *file[0] = buf;
11376 *num_file = 1;
11377 return OK;
11378}
11379#endif
11380
11381/*
11382 * Get the value for the numeric or string option *opp in a nice format into
11383 * NameBuff[]. Must not be called with a hidden option!
11384 */
11385 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011386option_value2string(
11387 struct vimoption *opp,
11388 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389{
11390 char_u *varp;
11391
11392 varp = get_varp_scope(opp, opt_flags);
11393
11394 if (opp->flags & P_NUM)
11395 {
11396 long wc = 0;
11397
11398 if (wc_use_keyname(varp, &wc))
11399 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11400 else if (wc != 0)
11401 STRCPY(NameBuff, transchar((int)wc));
11402 else
11403 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11404 }
11405 else /* P_STRING */
11406 {
11407 varp = *(char_u **)(varp);
11408 if (varp == NULL) /* just in case */
11409 NameBuff[0] = NUL;
11410#ifdef FEAT_CRYPT
11411 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011412 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011413 STRCPY(NameBuff, "*****");
11414#endif
11415 else if (opp->flags & P_EXPAND)
11416 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11417 /* Translate 'pastetoggle' into special key names */
11418 else if ((char_u **)opp->var == &p_pt)
11419 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11420 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011421 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011422 }
11423}
11424
11425/*
11426 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11427 * printed as a keyname.
11428 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11429 */
11430 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011431wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011432{
11433 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11434 {
11435 *wcp = *(long *)varp;
11436 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11437 return TRUE;
11438 }
11439 return FALSE;
11440}
11441
Bram Moolenaar01615492015-02-03 13:00:38 +010011442#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011443/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011444 * Any character has an equivalent 'langmap' character. This is used for
11445 * keyboards that have a special language mode that sends characters above
11446 * 128 (although other characters can be translated too). The "to" field is a
11447 * Vim command character. This avoids having to switch the keyboard back to
11448 * ASCII mode when leaving Insert mode.
11449 *
11450 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11451 * commands.
11452 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11453 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11454 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011455 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011456# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011457/*
11458 * With multi-byte support use growarray for 'langmap' chars >= 256
11459 */
11460typedef struct
11461{
11462 int from;
11463 int to;
11464} langmap_entry_T;
11465
11466static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011467static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011468
11469/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011470 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11471 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011472 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011473 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011474langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011475{
11476 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011477 int a = 0;
11478 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011479
11480 /* Do a binary search for an existing entry. */
11481 while (a != b)
11482 {
11483 int i = (a + b) / 2;
11484 int d = entries[i].from - from;
11485
11486 if (d == 0)
11487 {
11488 entries[i].to = to;
11489 return;
11490 }
11491 if (d < 0)
11492 a = i + 1;
11493 else
11494 b = i;
11495 }
11496
11497 if (ga_grow(&langmap_mapga, 1) != OK)
11498 return; /* out of memory */
11499
11500 /* insert new entry at position "a" */
11501 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11502 mch_memmove(entries + 1, entries,
11503 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11504 ++langmap_mapga.ga_len;
11505 entries[0].from = from;
11506 entries[0].to = to;
11507}
11508
11509/*
11510 * Apply 'langmap' to multi-byte character "c" and return the result.
11511 */
11512 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011513langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011514{
11515 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11516 int a = 0;
11517 int b = langmap_mapga.ga_len;
11518
11519 while (a != b)
11520 {
11521 int i = (a + b) / 2;
11522 int d = entries[i].from - c;
11523
11524 if (d == 0)
11525 return entries[i].to; /* found matching entry */
11526 if (d < 0)
11527 a = i + 1;
11528 else
11529 b = i;
11530 }
11531 return c; /* no entry found, return "c" unmodified */
11532}
11533# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534
11535 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011536langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011537{
11538 int i;
11539
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011540 for (i = 0; i < 256; i++)
11541 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11542# ifdef FEAT_MBYTE
11543 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11544# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011545}
11546
11547/*
11548 * Called when langmap option is set; the language map can be
11549 * changed at any time!
11550 */
11551 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011552langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553{
11554 char_u *p;
11555 char_u *p2;
11556 int from, to;
11557
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011558#ifdef FEAT_MBYTE
11559 ga_clear(&langmap_mapga); /* clear the previous map first */
11560#endif
11561 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011562
11563 for (p = p_langmap; p[0] != NUL; )
11564 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011565 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11566 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011567 {
11568 if (p2[0] == '\\' && p2[1] != NUL)
11569 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011570 }
11571 if (p2[0] == ';')
11572 ++p2; /* abcd;ABCD form, p2 points to A */
11573 else
11574 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11575 while (p[0])
11576 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011577 if (p[0] == ',')
11578 {
11579 ++p;
11580 break;
11581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011582 if (p[0] == '\\' && p[1] != NUL)
11583 ++p;
11584#ifdef FEAT_MBYTE
11585 from = (*mb_ptr2char)(p);
11586#else
11587 from = p[0];
11588#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011589 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590 if (p2 == NULL)
11591 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011592 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011593 if (p[0] != ',')
11594 {
11595 if (p[0] == '\\')
11596 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011597#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011598 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011599#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011600 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011601#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011603 }
11604 else
11605 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011606 if (p2[0] != ',')
11607 {
11608 if (p2[0] == '\\')
11609 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011611 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011613 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011614#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011615 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616 }
11617 if (to == NUL)
11618 {
11619 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11620 transchar(from));
11621 return;
11622 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011623
11624#ifdef FEAT_MBYTE
11625 if (from >= 256)
11626 langmap_set_entry(from, to);
11627 else
11628#endif
11629 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011630
11631 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011632 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011633 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011634 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011635 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011636 if (*p == ';')
11637 {
11638 p = p2;
11639 if (p[0] != NUL)
11640 {
11641 if (p[0] != ',')
11642 {
11643 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11644 return;
11645 }
11646 ++p;
11647 }
11648 break;
11649 }
11650 }
11651 }
11652 }
11653}
11654#endif
11655
11656/*
11657 * Return TRUE if format option 'x' is in effect.
11658 * Take care of no formatting when 'paste' is set.
11659 */
11660 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011661has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011662{
11663 if (p_paste)
11664 return FALSE;
11665 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11666}
11667
11668/*
11669 * Return TRUE if "x" is present in 'shortmess' option, or
11670 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11671 */
11672 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011673shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011674{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011675 return p_shm != NULL &&
11676 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011677 || (vim_strchr(p_shm, 'a') != NULL
11678 && vim_strchr((char_u *)SHM_A, x) != NULL));
11679}
11680
11681/*
11682 * paste_option_changed() - Called after p_paste was set or reset.
11683 */
11684 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011685paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011686{
11687 static int old_p_paste = FALSE;
11688 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011689 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011690#ifdef FEAT_CMDL_INFO
11691 static int save_ru = 0;
11692#endif
11693#ifdef FEAT_RIGHTLEFT
11694 static int save_ri = 0;
11695 static int save_hkmap = 0;
11696#endif
11697 buf_T *buf;
11698
11699 if (p_paste)
11700 {
11701 /*
11702 * Paste switched from off to on.
11703 * Save the current values, so they can be restored later.
11704 */
11705 if (!old_p_paste)
11706 {
11707 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011708 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011709 {
11710 buf->b_p_tw_nopaste = buf->b_p_tw;
11711 buf->b_p_wm_nopaste = buf->b_p_wm;
11712 buf->b_p_sts_nopaste = buf->b_p_sts;
11713 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011714 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011715 }
11716
11717 /* save global options */
11718 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011719 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011720#ifdef FEAT_CMDL_INFO
11721 save_ru = p_ru;
11722#endif
11723#ifdef FEAT_RIGHTLEFT
11724 save_ri = p_ri;
11725 save_hkmap = p_hkmap;
11726#endif
11727 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011728 p_ai_nopaste = p_ai;
11729 p_et_nopaste = p_et;
11730 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731 p_tw_nopaste = p_tw;
11732 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011733 }
11734
11735 /*
11736 * Always set the option values, also when 'paste' is set when it is
11737 * already on.
11738 */
11739 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011740 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741 {
11742 buf->b_p_tw = 0; /* textwidth is 0 */
11743 buf->b_p_wm = 0; /* wrapmargin is 0 */
11744 buf->b_p_sts = 0; /* softtabstop is 0 */
11745 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011746 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011747 }
11748
11749 /* set global options */
11750 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011751 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752#ifdef FEAT_CMDL_INFO
11753# ifdef FEAT_WINDOWS
11754 if (p_ru)
11755 status_redraw_all(); /* redraw to remove the ruler */
11756# endif
11757 p_ru = 0; /* no ruler */
11758#endif
11759#ifdef FEAT_RIGHTLEFT
11760 p_ri = 0; /* no reverse insert */
11761 p_hkmap = 0; /* no Hebrew keyboard */
11762#endif
11763 /* set global values for local buffer options */
11764 p_tw = 0;
11765 p_wm = 0;
11766 p_sts = 0;
11767 p_ai = 0;
11768 }
11769
11770 /*
11771 * Paste switched from on to off: Restore saved values.
11772 */
11773 else if (old_p_paste)
11774 {
11775 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011776 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011777 {
11778 buf->b_p_tw = buf->b_p_tw_nopaste;
11779 buf->b_p_wm = buf->b_p_wm_nopaste;
11780 buf->b_p_sts = buf->b_p_sts_nopaste;
11781 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011782 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011783 }
11784
11785 /* restore global options */
11786 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011787 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011788#ifdef FEAT_CMDL_INFO
11789# ifdef FEAT_WINDOWS
11790 if (p_ru != save_ru)
11791 status_redraw_all(); /* redraw to draw the ruler */
11792# endif
11793 p_ru = save_ru;
11794#endif
11795#ifdef FEAT_RIGHTLEFT
11796 p_ri = save_ri;
11797 p_hkmap = save_hkmap;
11798#endif
11799 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011800 p_ai = p_ai_nopaste;
11801 p_et = p_et_nopaste;
11802 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011803 p_tw = p_tw_nopaste;
11804 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805 }
11806
11807 old_p_paste = p_paste;
11808}
11809
11810/*
11811 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11812 *
11813 * Reset 'compatible' and set the values for options that didn't get set yet
11814 * to the Vim defaults.
11815 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011816 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011817 */
11818 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011819vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011821 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011822 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011823 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011824
11825 if (!option_was_set((char_u *)"cp"))
11826 {
11827 p_cp = FALSE;
11828 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11829 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11830 set_option_default(opt_idx, OPT_FREE, FALSE);
11831 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011832 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011833 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011834
11835 if (fname != NULL)
11836 {
11837 p = vim_getenv(envname, &dofree);
11838 if (p == NULL)
11839 {
11840 /* Set $MYVIMRC to the first vimrc file found. */
11841 p = FullName_save(fname, FALSE);
11842 if (p != NULL)
11843 {
11844 vim_setenv(envname, p);
11845 vim_free(p);
11846 }
11847 }
11848 else if (dofree)
11849 vim_free(p);
11850 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011851}
11852
11853/*
11854 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11855 */
11856 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011857change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011858{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011859 int opt_idx;
11860
Bram Moolenaar071d4272004-06-13 20:20:40 +000011861 if (p_cp != on)
11862 {
11863 p_cp = on;
11864 compatible_set();
11865 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011866 opt_idx = findoption((char_u *)"cp");
11867 if (opt_idx >= 0)
11868 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869}
11870
11871/*
11872 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011873 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011874 */
11875 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011876option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877{
11878 int idx;
11879
11880 idx = findoption(name);
11881 if (idx < 0) /* unknown option */
11882 return FALSE;
11883 if (options[idx].flags & P_WAS_SET)
11884 return TRUE;
11885 return FALSE;
11886}
11887
11888/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011889 * Reset the flag indicating option "name" was set.
11890 */
11891 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011892reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011893{
11894 int idx = findoption(name);
11895
11896 if (idx >= 0)
11897 options[idx].flags &= ~P_WAS_SET;
11898}
11899
11900/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901 * compatible_set() - Called when 'compatible' has been set or unset.
11902 *
11903 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11904 * flag) to a Vi compatible value.
11905 * When 'compatible' is unset: Set all options that have a different default
11906 * for Vim (without the P_VI_DEF flag) to that default.
11907 */
11908 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011909compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011910{
11911 int opt_idx;
11912
11913 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11914 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11915 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11916 set_option_default(opt_idx, OPT_FREE, p_cp);
11917 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011918 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919}
11920
11921#ifdef FEAT_LINEBREAK
11922
11923# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11924 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011925 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011926# endif
11927
11928/*
11929 * fill_breakat_flags() -- called when 'breakat' changes value.
11930 */
11931 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011932fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011934 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011935 int i;
11936
11937 for (i = 0; i < 256; i++)
11938 breakat_flags[i] = FALSE;
11939
11940 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011941 for (p = p_breakat; *p; p++)
11942 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011943}
11944
11945# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011946 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947# endif
11948
11949#endif
11950
11951/*
11952 * Check an option that can be a range of string values.
11953 *
11954 * Return OK for correct value, FAIL otherwise.
11955 * Empty is always OK.
11956 */
11957 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011958check_opt_strings(
11959 char_u *val,
11960 char **values,
11961 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011962{
11963 return opt_strings_flags(val, values, NULL, list);
11964}
11965
11966/*
11967 * Handle an option that can be a range of string values.
11968 * Set a flag in "*flagp" for each string present.
11969 *
11970 * Return OK for correct value, FAIL otherwise.
11971 * Empty is always OK.
11972 */
11973 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011974opt_strings_flags(
11975 char_u *val, /* new value */
11976 char **values, /* array of valid string values */
11977 unsigned *flagp,
11978 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011979{
11980 int i;
11981 int len;
11982 unsigned new_flags = 0;
11983
11984 while (*val)
11985 {
11986 for (i = 0; ; ++i)
11987 {
11988 if (values[i] == NULL) /* val not found in values[] */
11989 return FAIL;
11990
11991 len = (int)STRLEN(values[i]);
11992 if (STRNCMP(values[i], val, len) == 0
11993 && ((list && val[len] == ',') || val[len] == NUL))
11994 {
11995 val += len + (val[len] == ',');
11996 new_flags |= (1 << i);
11997 break; /* check next item in val list */
11998 }
11999 }
12000 }
12001 if (flagp != NULL)
12002 *flagp = new_flags;
12003
12004 return OK;
12005}
12006
12007/*
12008 * Read the 'wildmode' option, fill wim_flags[].
12009 */
12010 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012011check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012{
12013 char_u new_wim_flags[4];
12014 char_u *p;
12015 int i;
12016 int idx = 0;
12017
12018 for (i = 0; i < 4; ++i)
12019 new_wim_flags[i] = 0;
12020
12021 for (p = p_wim; *p; ++p)
12022 {
12023 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12024 ;
12025 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12026 return FAIL;
12027 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12028 new_wim_flags[idx] |= WIM_LONGEST;
12029 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12030 new_wim_flags[idx] |= WIM_FULL;
12031 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12032 new_wim_flags[idx] |= WIM_LIST;
12033 else
12034 return FAIL;
12035 p += i;
12036 if (*p == NUL)
12037 break;
12038 if (*p == ',')
12039 {
12040 if (idx == 3)
12041 return FAIL;
12042 ++idx;
12043 }
12044 }
12045
12046 /* fill remaining entries with last flag */
12047 while (idx < 3)
12048 {
12049 new_wim_flags[idx + 1] = new_wim_flags[idx];
12050 ++idx;
12051 }
12052
12053 /* only when there are no errors, wim_flags[] is changed */
12054 for (i = 0; i < 4; ++i)
12055 wim_flags[i] = new_wim_flags[i];
12056 return OK;
12057}
12058
12059/*
12060 * Check if backspacing over something is allowed.
12061 */
12062 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012063can_bs(
12064 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012065{
12066 switch (*p_bs)
12067 {
12068 case '2': return TRUE;
12069 case '1': return (what != BS_START);
12070 case '0': return FALSE;
12071 }
12072 return vim_strchr(p_bs, what) != NULL;
12073}
12074
12075/*
12076 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12077 * the file must be considered changed when the value is different.
12078 */
12079 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012080save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081{
12082 buf->b_start_ffc = *buf->b_p_ff;
12083 buf->b_start_eol = buf->b_p_eol;
12084#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012085 buf->b_start_bomb = buf->b_p_bomb;
12086
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087 /* Only use free/alloc when necessary, they take time. */
12088 if (buf->b_start_fenc == NULL
12089 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12090 {
12091 vim_free(buf->b_start_fenc);
12092 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12093 }
12094#endif
12095}
12096
12097/*
12098 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12099 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012100 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12101 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012102 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012103 * When "ignore_empty" is true don't consider a new, empty buffer to be
12104 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012105 */
12106 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012107file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012109 /* In a buffer that was never loaded the options are not valid. */
12110 if (buf->b_flags & BF_NEVERLOADED)
12111 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012112 if (ignore_empty
12113 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012114 && buf->b_ml.ml_line_count == 1
12115 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12116 return FALSE;
12117 if (buf->b_start_ffc != *buf->b_p_ff)
12118 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012119 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120 return TRUE;
12121#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012122 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12123 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012124 if (buf->b_start_fenc == NULL)
12125 return (*buf->b_p_fenc != NUL);
12126 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12127#else
12128 return FALSE;
12129#endif
12130}
12131
12132/*
12133 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12134 */
12135 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012136check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012137{
12138 return check_opt_strings(p, p_ff_values, FALSE);
12139}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012140
12141/*
12142 * Return the effective shiftwidth value for current buffer, using the
12143 * 'tabstop' value when 'shiftwidth' is zero.
12144 */
12145 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012146get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012147{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012148 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012149}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012150
12151/*
12152 * Return the effective softtabstop value for the current buffer, using the
12153 * 'tabstop' value when 'softtabstop' is negative.
12154 */
12155 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012156get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012157{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012158 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012159}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012160
12161/*
12162 * Check matchpairs option for "*initc".
12163 * If there is a match set "*initc" to the matching character and "*findc" to
12164 * the opposite character. Set "*backwards" to the direction.
12165 * When "switchit" is TRUE swap the direction.
12166 */
12167 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012168find_mps_values(
12169 int *initc,
12170 int *findc,
12171 int *backwards,
12172 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012173{
12174 char_u *ptr;
12175
12176 ptr = curbuf->b_p_mps;
12177 while (*ptr != NUL)
12178 {
12179#ifdef FEAT_MBYTE
12180 if (has_mbyte)
12181 {
12182 char_u *prev;
12183
12184 if (mb_ptr2char(ptr) == *initc)
12185 {
12186 if (switchit)
12187 {
12188 *findc = *initc;
12189 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12190 *backwards = TRUE;
12191 }
12192 else
12193 {
12194 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12195 *backwards = FALSE;
12196 }
12197 return;
12198 }
12199 prev = ptr;
12200 ptr += mb_ptr2len(ptr) + 1;
12201 if (mb_ptr2char(ptr) == *initc)
12202 {
12203 if (switchit)
12204 {
12205 *findc = *initc;
12206 *initc = mb_ptr2char(prev);
12207 *backwards = FALSE;
12208 }
12209 else
12210 {
12211 *findc = mb_ptr2char(prev);
12212 *backwards = TRUE;
12213 }
12214 return;
12215 }
12216 ptr += mb_ptr2len(ptr);
12217 }
12218 else
12219#endif
12220 {
12221 if (*ptr == *initc)
12222 {
12223 if (switchit)
12224 {
12225 *backwards = TRUE;
12226 *findc = *initc;
12227 *initc = ptr[2];
12228 }
12229 else
12230 {
12231 *backwards = FALSE;
12232 *findc = ptr[2];
12233 }
12234 return;
12235 }
12236 ptr += 2;
12237 if (*ptr == *initc)
12238 {
12239 if (switchit)
12240 {
12241 *backwards = FALSE;
12242 *findc = *initc;
12243 *initc = ptr[-2];
12244 }
12245 else
12246 {
12247 *backwards = TRUE;
12248 *findc = ptr[-2];
12249 }
12250 return;
12251 }
12252 ++ptr;
12253 }
12254 if (*ptr == ',')
12255 ++ptr;
12256 }
12257}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012258
12259#if defined(FEAT_LINEBREAK) || defined(PROTO)
12260/*
12261 * This is called when 'breakindentopt' is changed and when a window is
12262 * initialized.
12263 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012264 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012265briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012266{
12267 char_u *p;
12268 int bri_shift = 0;
12269 long bri_min = 20;
12270 int bri_sbr = FALSE;
12271
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012272 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012273 while (*p != NUL)
12274 {
12275 if (STRNCMP(p, "shift:", 6) == 0
12276 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12277 {
12278 p += 6;
12279 bri_shift = getdigits(&p);
12280 }
12281 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12282 {
12283 p += 4;
12284 bri_min = getdigits(&p);
12285 }
12286 else if (STRNCMP(p, "sbr", 3) == 0)
12287 {
12288 p += 3;
12289 bri_sbr = TRUE;
12290 }
12291 if (*p != ',' && *p != NUL)
12292 return FAIL;
12293 if (*p == ',')
12294 ++p;
12295 }
12296
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012297 wp->w_p_brishift = bri_shift;
12298 wp->w_p_brimin = bri_min;
12299 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012300
12301 return OK;
12302}
12303#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012304
12305/*
12306 * Get the local or global value of 'backupcopy'.
12307 */
12308 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012309get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012310{
12311 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12312}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012313
12314#if defined(FEAT_SIGNS) || defined(PROTO)
12315/*
12316 * Return TRUE when window "wp" has a column to draw signs in.
12317 */
12318 int
12319signcolumn_on(win_T *wp)
12320{
12321 if (*wp->w_p_scl == 'n')
12322 return FALSE;
12323 if (*wp->w_p_scl == 'y')
12324 return TRUE;
12325 return (wp->w_buffer->b_signlist != NULL
12326# ifdef FEAT_NETBEANS_INTG
12327 || wp->w_buffer->b_has_sign_column
12328# endif
12329 );
12330}
12331#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012332
12333#if defined(FEAT_EVAL) || defined(PROTO)
12334/*
12335 * Get window or buffer local options.
12336 */
12337 dict_T *
12338get_winbuf_options(int bufopt)
12339{
12340 dict_T *d;
12341 int opt_idx;
12342
12343 d = dict_alloc();
12344 if (d == NULL)
12345 return NULL;
12346
12347 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12348 {
12349 struct vimoption *opt = &options[opt_idx];
12350
12351 if ((bufopt && (opt->indir & PV_BUF))
12352 || (!bufopt && (opt->indir & PV_WIN)))
12353 {
12354 char_u *varp = get_varp(opt);
12355
12356 if (varp != NULL)
12357 {
12358 if (opt->flags & P_STRING)
12359 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
12360 else
12361 dict_add_nr_str(d, opt->fullname, *varp, NULL);
12362 }
12363 }
12364 }
12365
12366 return d;
12367}
12368#endif