blob: fe2ae179a9e05d0a13d12c9ab4ec377f6640e3d3 [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)
246#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000247#ifdef FEAT_VERTSPLIT
248# define PV_WFW OPT_WIN(WV_WFW)
249#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#ifdef FEAT_CURSORBIND
252# define PV_CRBIND OPT_WIN(WV_CRBIND)
253#endif
254#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200255# define PV_COCU OPT_WIN(WV_COCU)
256# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200257#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000258
259/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260typedef enum
261{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000262 PV_NONE = 0,
263 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264} idopt_T;
265
266/*
267 * Options local to a window have a value local to a buffer and global to all
268 * buffers. Indicate this by setting "var" to VAR_WIN.
269 */
270#define VAR_WIN ((char_u *)-1)
271
272/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000273 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274 * Only to be used in option.c!
275 */
276static int p_ai;
277static int p_bin;
278#ifdef FEAT_MBYTE
279static int p_bomb;
280#endif
281#if defined(FEAT_QUICKFIX)
282static char_u *p_bh;
283static char_u *p_bt;
284#endif
285static int p_bl;
286static int p_ci;
287#ifdef FEAT_CINDENT
288static int p_cin;
289static char_u *p_cink;
290static char_u *p_cino;
291#endif
292#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
293static char_u *p_cinw;
294#endif
295#ifdef FEAT_COMMENTS
296static char_u *p_com;
297#endif
298#ifdef FEAT_FOLDING
299static char_u *p_cms;
300#endif
301#ifdef FEAT_INS_EXPAND
302static char_u *p_cpt;
303#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000304#ifdef FEAT_COMPL_FUNC
305static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000306static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200309static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static int p_et;
311#ifdef FEAT_MBYTE
312static char_u *p_fenc;
313#endif
314static char_u *p_ff;
315static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000316static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317#ifdef FEAT_AUTOCMD
318static char_u *p_ft;
319#endif
320static long p_iminsert;
321static long p_imsearch;
322#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
323static char_u *p_inex;
324#endif
325#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
326static char_u *p_inde;
327static char_u *p_indk;
328#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000329#if defined(FEAT_EVAL)
330static char_u *p_fex;
331#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000332static int p_inf;
333static char_u *p_isk;
334#ifdef FEAT_CRYPT
335static char_u *p_key;
336#endif
337#ifdef FEAT_LISP
338static int p_lisp;
339#endif
340static int p_ml;
341static int p_ma;
342static int p_mod;
343static char_u *p_mps;
344static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000345static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000346#ifdef FEAT_TEXTOBJ
347static char_u *p_qe;
348#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000349static int p_ro;
350#ifdef FEAT_SMARTINDENT
351static int p_si;
352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000353static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static long p_sts;
355#if defined(FEAT_SEARCHPATH)
356static char_u *p_sua;
357#endif
358static long p_sw;
359static int p_swf;
360#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000361static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000363#endif
364#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000365static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000366static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000367static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368#endif
369static long p_ts;
370static long p_tw;
371static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200372#ifdef FEAT_PERSISTENT_UNDO
373static int p_udf;
374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375static long p_wm;
376#ifdef FEAT_KEYMAP
377static char_u *p_keymap;
378#endif
379
380/* Saved values for when 'bin' is set. */
381static int p_et_nobin;
382static int p_ml_nobin;
383static long p_tw_nobin;
384static long p_wm_nobin;
385
386/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200387static int p_ai_nopaste;
388static int p_et_nopaste;
389static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390static long p_tw_nopaste;
391static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392
393struct vimoption
394{
395 char *fullname; /* full option name */
396 char *shortname; /* permissible abbreviation */
397 long_u flags; /* see below */
398 char_u *var; /* global option: pointer to variable;
399 * window-local option: VAR_WIN;
400 * buffer-local option: global value */
401 idopt_T indir; /* global option: PV_NONE;
402 * local option: indirect option index */
403 char_u *def_val[2]; /* default values for variable (vi and vim) */
404#ifdef FEAT_EVAL
405 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000406# define SCRIPTID_INIT , 0
407#else
408# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409#endif
410};
411
412#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
413#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
414
415/*
416 * Flags
417 */
418#define P_BOOL 0x01 /* the option is boolean */
419#define P_NUM 0x02 /* the option is numeric */
420#define P_STRING 0x04 /* the option is a string */
421#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000422 must use free_string_option() when
423 assigning new value. Not set if default is
424 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000425#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
426 never be used for local or hidden options! */
427#define P_NODEFAULT 0x40 /* don't set to default value */
428#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
429 use vim_free() when assigning new value */
430#define P_WAS_SET 0x100 /* option has been set/reset */
431#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
432#define P_VI_DEF 0x400 /* Use Vi default for Vim */
433#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
434
435 /* when option changed, what to display: */
436#define P_RSTAT 0x1000 /* redraw status lines */
437#define P_RWIN 0x2000 /* redraw current window */
438#define P_RBUF 0x4000 /* redraw current buffer */
439#define P_RALL 0x6000 /* redraw all windows */
440#define P_RCLR 0x7000 /* clear and redraw all */
441
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200442#define P_COMMA 0x8000 /* comma separated list */
443#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
444 * commas */
445#define P_NODUP 0x20000L /* don't allow duplicate strings */
446#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000447
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200448#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
449#define P_GETTEXT 0x100000L /* expand default value with _() */
450#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
451#define P_NFNAME 0x400000L /* only normal file name chars allowed */
452#define P_INSECURE 0x800000L /* option was set from a modeline */
453#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000454 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200455#define P_NO_ML 0x2000000L /* not allowed in modeline */
456#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200457 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000458
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000459#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
460
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000461/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
462 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100463#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000464# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000465#else
466# define ISP_LATIN1 (char_u *)"@,161-255"
467#endif
468
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000469/* The 16 bit MS-DOS version is low on space, make the string as short as
470 * possible when compiling with few features. */
471#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
472 || defined(FEAT_VERTSPLIT) || 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,
1043#ifdef FEAT_VERTSPLIT
1044 (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 Moolenaar0e7c4b92015-06-20 15:30:03 +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 Moolenaar48e330a2016-02-23 14:53:34 +01001671#if defined(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 Moolenaard94464e2015-11-02 15:28:18 +01001772 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1773 (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
2010# if defined(__EMX__)
2011 (char_u *)".,/emx/include,,",
2012# else /* Unix, probably */
2013 (char_u *)".,/usr/include,,",
2014# endif
2015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002016 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002017#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002018 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2019 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002020 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2021 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002022#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2024 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002026 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2028 (char_u *)&p_pvh, PV_NONE,
2029#else
2030 (char_u *)NULL, PV_NONE,
2031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2034#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2035 (char_u *)VAR_WIN, PV_PVW,
2036#else
2037 (char_u *)NULL, PV_NONE,
2038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002039 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002040 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002041#ifdef FEAT_PRINTER
2042 (char_u *)&p_pdev, PV_NONE,
2043 {(char_u *)"", (char_u *)0L}
2044#else
2045 (char_u *)NULL, PV_NONE,
2046 {(char_u *)NULL, (char_u *)0L}
2047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002048 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 {"printencoding", "penc", P_STRING|P_VI_DEF,
2050#ifdef FEAT_POSTSCRIPT
2051 (char_u *)&p_penc, PV_NONE,
2052 {(char_u *)"", (char_u *)0L}
2053#else
2054 (char_u *)NULL, PV_NONE,
2055 {(char_u *)NULL, (char_u *)0L}
2056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002057 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2059#ifdef FEAT_POSTSCRIPT
2060 (char_u *)&p_pexpr, PV_NONE,
2061 {(char_u *)"", (char_u *)0L}
2062#else
2063 (char_u *)NULL, PV_NONE,
2064 {(char_u *)NULL, (char_u *)0L}
2065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 {"printfont", "pfn", P_STRING|P_VI_DEF,
2068#ifdef FEAT_PRINTER
2069 (char_u *)&p_pfn, PV_NONE,
2070 {
2071# ifdef MSWIN
2072 (char_u *)"Courier_New:h10",
2073# else
2074 (char_u *)"courier",
2075# endif
2076 (char_u *)0L}
2077#else
2078 (char_u *)NULL, PV_NONE,
2079 {(char_u *)NULL, (char_u *)0L}
2080#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002081 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002082 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2083#ifdef FEAT_PRINTER
2084 (char_u *)&p_header, PV_NONE,
2085 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2086#else
2087 (char_u *)NULL, PV_NONE,
2088 {(char_u *)NULL, (char_u *)0L}
2089#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002090 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002091 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2092#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2093 (char_u *)&p_pmcs, PV_NONE,
2094 {(char_u *)"", (char_u *)0L}
2095#else
2096 (char_u *)NULL, PV_NONE,
2097 {(char_u *)NULL, (char_u *)0L}
2098#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002099 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002100 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2101#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2102 (char_u *)&p_pmfn, PV_NONE,
2103 {(char_u *)"", (char_u *)0L}
2104#else
2105 (char_u *)NULL, PV_NONE,
2106 {(char_u *)NULL, (char_u *)0L}
2107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002108 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002109 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110#ifdef FEAT_PRINTER
2111 (char_u *)&p_popt, PV_NONE,
2112 {(char_u *)"", (char_u *)0L}
2113#else
2114 (char_u *)NULL, PV_NONE,
2115 {(char_u *)NULL, (char_u *)0L}
2116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002119 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002121 {"pumheight", "ph", P_NUM|P_VI_DEF,
2122#ifdef FEAT_INS_EXPAND
2123 (char_u *)&p_ph, PV_NONE,
2124#else
2125 (char_u *)NULL, PV_NONE,
2126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002127 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002128#if defined(DYNAMIC_PYTHON3)
Bram Moolenaar0796c062015-11-10 19:41:37 +01002129 {"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002130 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002131 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2132 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002134#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002135 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2136 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002137 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2138 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002139#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002140 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2141#ifdef FEAT_TEXTOBJ
2142 (char_u *)&p_qe, PV_QE,
2143 {(char_u *)"\\", (char_u *)0L}
2144#else
2145 (char_u *)NULL, PV_NONE,
2146 {(char_u *)NULL, (char_u *)0L}
2147#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2150 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 {"redraw", NULL, P_BOOL|P_VI_DEF,
2153 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002155 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2156#ifdef FEAT_RELTIME
2157 (char_u *)&p_rdt, PV_NONE,
2158#else
2159 (char_u *)NULL, PV_NONE,
2160#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002161 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002162 {"regexpengine", "re", P_NUM|P_VI_DEF,
2163 (char_u *)&p_re, PV_NONE,
2164 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002165 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2166 (char_u *)VAR_WIN, PV_RNU,
2167 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168 {"remap", NULL, P_BOOL|P_VI_DEF,
2169 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002170 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002171 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002172#ifdef FEAT_RENDER_OPTIONS
2173 (char_u *)&p_rop, PV_NONE,
2174 {(char_u *)"", (char_u *)0L}
2175#else
2176 (char_u *)NULL, PV_NONE,
2177 {(char_u *)NULL, (char_u *)0L}
2178#endif
2179 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180 {"report", NULL, P_NUM|P_VI_DEF,
2181 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002182 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2184#ifdef WIN3264
2185 (char_u *)&p_rs, PV_NONE,
2186#else
2187 (char_u *)NULL, PV_NONE,
2188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002189 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2191#ifdef FEAT_RIGHTLEFT
2192 (char_u *)&p_ri, PV_NONE,
2193#else
2194 (char_u *)NULL, PV_NONE,
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2198#ifdef FEAT_RIGHTLEFT
2199 (char_u *)VAR_WIN, PV_RL,
2200#else
2201 (char_u *)NULL, PV_NONE,
2202#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002203 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002204 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2205#ifdef FEAT_RIGHTLEFT
2206 (char_u *)VAR_WIN, PV_RLC,
2207 {(char_u *)"search", (char_u *)NULL}
2208#else
2209 (char_u *)NULL, PV_NONE,
2210 {(char_u *)NULL, (char_u *)0L}
2211#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002212 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002213#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002214 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2215 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002216 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2217 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002218#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2220#ifdef FEAT_CMDL_INFO
2221 (char_u *)&p_ru, PV_NONE,
2222#else
2223 (char_u *)NULL, PV_NONE,
2224#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2227#ifdef FEAT_STL_OPT
2228 (char_u *)&p_ruf, PV_NONE,
2229#else
2230 (char_u *)NULL, PV_NONE,
2231#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002232 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002233 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2234 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002235 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2239 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002240 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2242#ifdef FEAT_SCROLLBIND
2243 (char_u *)VAR_WIN, PV_SCBIND,
2244#else
2245 (char_u *)NULL, PV_NONE,
2246#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002247 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002248 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2249 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002250 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2252 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002254 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002255#ifdef FEAT_SCROLLBIND
2256 (char_u *)&p_sbo, PV_NONE,
2257 {(char_u *)"ver,jump", (char_u *)0L}
2258#else
2259 (char_u *)NULL, PV_NONE,
2260 {(char_u *)0L, (char_u *)0L}
2261#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002262 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"sections", "sect", P_STRING|P_VI_DEF,
2264 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2266 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2268 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002269 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 {(char_u *)"inclusive", (char_u *)0L}
2273 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002274 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002277 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278#ifdef FEAT_SESSION
2279 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002280 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 (char_u *)0L}
2282#else
2283 (char_u *)NULL, PV_NONE,
2284 {(char_u *)0L, (char_u *)0L}
2285#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002286 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2288 (char_u *)&p_sh, PV_NONE,
2289 {
2290#ifdef VMS
2291 (char_u *)"-",
2292#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002293# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002295# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297# endif
2298#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002299 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2301 (char_u *)&p_shcf, PV_NONE,
2302 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002303#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304 (char_u *)"/c",
2305#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2310#ifdef FEAT_QUICKFIX
2311 (char_u *)&p_sp, PV_NONE,
2312 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002313#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315#else
2316 (char_u *)">",
2317#endif
2318 (char_u *)0L}
2319#else
2320 (char_u *)NULL, PV_NONE,
2321 {(char_u *)0L, (char_u *)0L}
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2325 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2328 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2331#ifdef BACKSLASH_IN_FILENAME
2332 (char_u *)&p_ssl, PV_NONE,
2333#else
2334 (char_u *)NULL, PV_NONE,
2335#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002337 {"shelltemp", "stmp", P_BOOL,
2338 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"shelltype", "st", P_NUM|P_VI_DEF,
2341#ifdef AMIGA
2342 (char_u *)&p_st, PV_NONE,
2343#else
2344 (char_u *)NULL, PV_NONE,
2345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2348 (char_u *)&p_sxq, PV_NONE,
2349 {
2350#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2351 (char_u *)"\"",
2352#else
2353 (char_u *)"",
2354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002356 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2357 (char_u *)&p_sxe, PV_NONE,
2358 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002359#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002360 (char_u *)"\"&|<>()@^",
2361#else
2362 (char_u *)"",
2363#endif
2364 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2366 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2369 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2372 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)"", (char_u *)"filnxtToO"}
2374 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2379#ifdef FEAT_LINEBREAK
2380 (char_u *)&p_sbr, PV_NONE,
2381#else
2382 (char_u *)NULL, PV_NONE,
2383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"showcmd", "sc", P_BOOL|P_VIM,
2386#ifdef FEAT_CMDL_INFO
2387 (char_u *)&p_sc, PV_NONE,
2388#else
2389 (char_u *)NULL, PV_NONE,
2390#endif
2391 {(char_u *)FALSE,
2392#ifdef UNIX
2393 (char_u *)FALSE
2394#else
2395 (char_u *)TRUE
2396#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002397 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2399 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2402 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"showmode", "smd", P_BOOL|P_VIM,
2405 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002407 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2408#ifdef FEAT_WINDOWS
2409 (char_u *)&p_stal, PV_NONE,
2410#else
2411 (char_u *)NULL, PV_NONE,
2412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2415 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2418 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2421 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2424 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2427#ifdef FEAT_SMARTINDENT
2428 (char_u *)&p_si, PV_SI,
2429#else
2430 (char_u *)NULL, PV_NONE,
2431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2434 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2437 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2440 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002442 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002443#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002444 (char_u *)VAR_WIN, PV_SPELL,
2445#else
2446 (char_u *)NULL, PV_NONE,
2447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002449 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002450#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002451 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002452 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002453#else
2454 (char_u *)NULL, PV_NONE,
2455 {(char_u *)0L, (char_u *)0L}
2456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002457 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002458 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2459 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002460#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002461 (char_u *)&p_spf, PV_SPF,
2462 {(char_u *)"", (char_u *)0L}
2463#else
2464 (char_u *)NULL, PV_NONE,
2465 {(char_u *)0L, (char_u *)0L}
2466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002468 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2469 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002470#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002471 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002472 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002473#else
2474 (char_u *)NULL, PV_NONE,
2475 {(char_u *)0L, (char_u *)0L}
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002478 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002479#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002480 (char_u *)&p_sps, PV_NONE,
2481 {(char_u *)"best", (char_u *)0L}
2482#else
2483 (char_u *)NULL, PV_NONE,
2484 {(char_u *)0L, (char_u *)0L}
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2488#ifdef FEAT_WINDOWS
2489 (char_u *)&p_sb, PV_NONE,
2490#else
2491 (char_u *)NULL, PV_NONE,
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"splitright", "spr", P_BOOL|P_VI_DEF,
2495#ifdef FEAT_VERTSPLIT
2496 (char_u *)&p_spr, PV_NONE,
2497#else
2498 (char_u *)NULL, PV_NONE,
2499#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2502 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2505#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002506 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507#else
2508 (char_u *)NULL, PV_NONE,
2509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002511 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 (char_u *)&p_su, PV_NONE,
2513 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002515 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002516#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 (char_u *)&p_sua, PV_SUA,
2518 {(char_u *)"", (char_u *)0L}
2519#else
2520 (char_u *)NULL, PV_NONE,
2521 {(char_u *)0L, (char_u *)0L}
2522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2525 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"swapsync", "sws", P_STRING|P_VI_DEF,
2528 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002530 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002533 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2534#ifdef FEAT_SYN_HL
2535 (char_u *)&p_smc, PV_SMC,
2536 {(char_u *)3000L, (char_u *)0L}
2537#else
2538 (char_u *)NULL, PV_NONE,
2539 {(char_u *)0L, (char_u *)0L}
2540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002542 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543#ifdef FEAT_SYN_HL
2544 (char_u *)&p_syn, PV_SYN,
2545 {(char_u *)"", (char_u *)0L}
2546#else
2547 (char_u *)NULL, PV_NONE,
2548 {(char_u *)0L, (char_u *)0L}
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002551 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2552#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002553 (char_u *)&p_tal, PV_NONE,
2554#else
2555 (char_u *)NULL, PV_NONE,
2556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002558 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2559#ifdef FEAT_WINDOWS
2560 (char_u *)&p_tpm, PV_NONE,
2561#else
2562 (char_u *)NULL, PV_NONE,
2563#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2566 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002567 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2569 (char_u *)&p_tbs, PV_NONE,
2570#ifdef VMS /* binary searching doesn't appear to work on VMS */
2571 {(char_u *)0L, (char_u *)0L}
2572#else
2573 {(char_u *)TRUE, (char_u *)0L}
2574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002576 {"tagcase", "tc", P_STRING|P_VIM,
2577 (char_u *)&p_tc, PV_TC,
2578 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"taglength", "tl", P_NUM|P_VI_DEF,
2580 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"tagrelative", "tr", P_BOOL|P_VIM,
2583 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002585 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002586 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {
2588#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2589 (char_u *)"./tags,./TAGS,tags,TAGS",
2590#else
2591 (char_u *)"./tags,tags",
2592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2595 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002597#if defined(DYNAMIC_TCL)
2598 {"tcldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2599 (char_u *)&p_tcldll, PV_NONE,
2600 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2601 SCRIPTID_INIT},
2602#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2604 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2607#ifdef FEAT_ARABIC
2608 (char_u *)&p_tbidi, PV_NONE,
2609#else
2610 (char_u *)NULL, PV_NONE,
2611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002612 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2614#ifdef FEAT_MBYTE
2615 (char_u *)&p_tenc, PV_NONE,
2616 {(char_u *)"", (char_u *)0L}
2617#else
2618 (char_u *)NULL, PV_NONE,
2619 {(char_u *)0L, (char_u *)0L}
2620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"terse", NULL, P_BOOL|P_VI_DEF,
2623 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {"textauto", "ta", P_BOOL|P_VIM,
2626 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2628 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2630 (char_u *)&p_tx, PV_TX,
2631 {
2632#ifdef USE_CRNL
2633 (char_u *)TRUE,
2634#else
2635 (char_u *)FALSE,
2636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002638 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002640 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002641 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002643 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644#else
2645 (char_u *)NULL, PV_NONE,
2646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2649 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"timeout", "to", P_BOOL|P_VI_DEF,
2652 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2655 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657 {"title", NULL, P_BOOL|P_VI_DEF,
2658#ifdef FEAT_TITLE
2659 (char_u *)&p_title, PV_NONE,
2660#else
2661 (char_u *)NULL, PV_NONE,
2662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"titlelen", NULL, P_NUM|P_VI_DEF,
2665#ifdef FEAT_TITLE
2666 (char_u *)&p_titlelen, PV_NONE,
2667#else
2668 (char_u *)NULL, PV_NONE,
2669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002671 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672#ifdef FEAT_TITLE
2673 (char_u *)&p_titleold, PV_NONE,
2674 {(char_u *)N_("Thanks for flying Vim"),
2675 (char_u *)0L}
2676#else
2677 (char_u *)NULL, PV_NONE,
2678 {(char_u *)0L, (char_u *)0L}
2679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 {"titlestring", NULL, P_STRING|P_VI_DEF,
2682#ifdef FEAT_TITLE
2683 (char_u *)&p_titlestring, PV_NONE,
2684#else
2685 (char_u *)NULL, PV_NONE,
2686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002689 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)"icons,tooltips", (char_u *)0L}
2692 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002694#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2696 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698#endif
2699 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2700 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2703 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2706 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2709 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2712#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2713 (char_u *)&p_ttym, PV_NONE,
2714#else
2715 (char_u *)NULL, PV_NONE,
2716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2719 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2722 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002724 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2725 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002726#ifdef FEAT_PERSISTENT_UNDO
2727 (char_u *)&p_udir, PV_NONE,
2728 {(char_u *)".", (char_u *)0L}
2729#else
2730 (char_u *)NULL, PV_NONE,
2731 {(char_u *)0L, (char_u *)0L}
2732#endif
2733 SCRIPTID_INIT},
2734 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2735#ifdef FEAT_PERSISTENT_UNDO
2736 (char_u *)&p_udf, PV_UDF,
2737#else
2738 (char_u *)NULL, PV_NONE,
2739#endif
2740 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002741 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002742 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002744#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 (char_u *)1000L,
2746#else
2747 (char_u *)100L,
2748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002750 {"undoreload", "ur", P_NUM|P_VI_DEF,
2751 (char_u *)&p_ur, PV_NONE,
2752 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"updatecount", "uc", P_NUM|P_VI_DEF,
2754 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"updatetime", "ut", P_NUM|P_VI_DEF,
2757 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"verbose", "vbs", P_NUM|P_VI_DEF,
2760 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002762 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2763 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2766#ifdef FEAT_SESSION
2767 (char_u *)&p_vdir, PV_NONE,
2768 {(char_u *)DFLT_VDIR, (char_u *)0L}
2769#else
2770 (char_u *)NULL, PV_NONE,
2771 {(char_u *)0L, (char_u *)0L}
2772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002774 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775#ifdef FEAT_SESSION
2776 (char_u *)&p_vop, PV_NONE,
2777 {(char_u *)"folds,options,cursor", (char_u *)0L}
2778#else
2779 (char_u *)NULL, PV_NONE,
2780 {(char_u *)0L, (char_u *)0L}
2781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002783 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784#ifdef FEAT_VIMINFO
2785 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002786#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002787 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788#else
2789# ifdef AMIGA
2790 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002791 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002793 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794# endif
2795#endif
2796#else
2797 (char_u *)NULL, PV_NONE,
2798 {(char_u *)0L, (char_u *)0L}
2799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002801 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2802 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803#ifdef FEAT_VIRTUALEDIT
2804 (char_u *)&p_ve, PV_NONE,
2805 {(char_u *)"", (char_u *)""}
2806#else
2807 (char_u *)NULL, PV_NONE,
2808 {(char_u *)0L, (char_u *)0L}
2809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2812 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"w300", NULL, P_NUM|P_VI_DEF,
2815 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"w1200", NULL, P_NUM|P_VI_DEF,
2818 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"w9600", NULL, P_NUM|P_VI_DEF,
2821 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"warn", NULL, P_BOOL|P_VI_DEF,
2824 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2827 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002829 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"wildchar", "wc", P_NUM|P_VIM,
2833 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2835 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002836 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002839 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840#ifdef FEAT_WILDIGN
2841 (char_u *)&p_wig, PV_NONE,
2842#else
2843 (char_u *)NULL, PV_NONE,
2844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002846 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2847 (char_u *)&p_wic, PV_NONE,
2848 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2850#ifdef FEAT_WILDMENU
2851 (char_u *)&p_wmnu, PV_NONE,
2852#else
2853 (char_u *)NULL, PV_NONE,
2854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002856 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002859 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2860#ifdef FEAT_CMDL_COMPL
2861 (char_u *)&p_wop, PV_NONE,
2862 {(char_u *)"", (char_u *)0L}
2863#else
2864 (char_u *)NULL, PV_NONE,
2865 {(char_u *)NULL, (char_u *)0L}
2866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2869#ifdef FEAT_WAK
2870 (char_u *)&p_wak, PV_NONE,
2871 {(char_u *)"menu", (char_u *)0L}
2872#else
2873 (char_u *)NULL, PV_NONE,
2874 {(char_u *)NULL, (char_u *)0L}
2875#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002878 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 {"winheight", "wh", P_NUM|P_VI_DEF,
2881#ifdef FEAT_WINDOWS
2882 (char_u *)&p_wh, PV_NONE,
2883#else
2884 (char_u *)NULL, PV_NONE,
2885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002888#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 (char_u *)VAR_WIN, PV_WFH,
2890#else
2891 (char_u *)NULL, PV_NONE,
2892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002894 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2895#ifdef FEAT_VERTSPLIT
2896 (char_u *)VAR_WIN, PV_WFW,
2897#else
2898 (char_u *)NULL, PV_NONE,
2899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2902#ifdef FEAT_WINDOWS
2903 (char_u *)&p_wmh, PV_NONE,
2904#else
2905 (char_u *)NULL, PV_NONE,
2906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002907 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2909#ifdef FEAT_VERTSPLIT
2910 (char_u *)&p_wmw, PV_NONE,
2911#else
2912 (char_u *)NULL, PV_NONE,
2913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2916#ifdef FEAT_VERTSPLIT
2917 (char_u *)&p_wiw, PV_NONE,
2918#else
2919 (char_u *)NULL, PV_NONE,
2920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2923 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2926 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2929 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002930 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 {"write", NULL, P_BOOL|P_VI_DEF,
2932 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002933 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 {"writeany", "wa", P_BOOL|P_VI_DEF,
2935 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2938 (char_u *)&p_wb, PV_NONE,
2939 {
2940#ifdef FEAT_WRITEBACKUP
2941 (char_u *)TRUE,
2942#else
2943 (char_u *)FALSE,
2944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002945 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946 {"writedelay", "wd", P_NUM|P_VI_DEF,
2947 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949
2950/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002951#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002953 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954
2955 p_term("t_AB", T_CAB)
2956 p_term("t_AF", T_CAF)
2957 p_term("t_AL", T_CAL)
2958 p_term("t_al", T_AL)
2959 p_term("t_bc", T_BC)
2960 p_term("t_cd", T_CD)
2961 p_term("t_ce", T_CE)
2962 p_term("t_cl", T_CL)
2963 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002964 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 p_term("t_Co", T_CCO)
2966 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002967 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968 p_term("t_cs", T_CS)
2969#ifdef FEAT_VERTSPLIT
2970 p_term("t_CV", T_CSV)
2971#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 p_term("t_da", T_DA)
2973 p_term("t_db", T_DB)
2974 p_term("t_DL", T_CDL)
2975 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002976 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 p_term("t_fs", T_FS)
2978 p_term("t_IE", T_CIE)
2979 p_term("t_IS", T_CIS)
2980 p_term("t_ke", T_KE)
2981 p_term("t_ks", T_KS)
2982 p_term("t_le", T_LE)
2983 p_term("t_mb", T_MB)
2984 p_term("t_md", T_MD)
2985 p_term("t_me", T_ME)
2986 p_term("t_mr", T_MR)
2987 p_term("t_ms", T_MS)
2988 p_term("t_nd", T_ND)
2989 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002990 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 p_term("t_RI", T_CRI)
2992 p_term("t_RV", T_CRV)
2993 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002995 p_term("t_Sf", T_CSF)
2996 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02002998 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 p_term("t_te", T_TE)
3001 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003002 p_term("t_ts", T_TS)
3003 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 p_term("t_ue", T_UE)
3005 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003006 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 p_term("t_vb", T_VB)
3008 p_term("t_ve", T_VE)
3009 p_term("t_vi", T_VI)
3010 p_term("t_vs", T_VS)
3011 p_term("t_WP", T_CWP)
3012 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003013 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 p_term("t_xs", T_XS)
3015 p_term("t_ZH", T_CZH)
3016 p_term("t_ZR", T_CZR)
3017
3018/* terminal key codes are not in here */
3019
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 /* end marker */
3021 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022};
3023
3024#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3025
3026#ifdef FEAT_MBYTE
3027static char *(p_ambw_values[]) = {"single", "double", NULL};
3028#endif
3029static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003030static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003032#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003033static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003034#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003035#ifdef FEAT_CMDL_COMPL
3036static char *(p_wop_values[]) = {"tagfile", NULL};
3037#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038#ifdef FEAT_WAK
3039static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3040#endif
3041static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3043static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045#ifdef FEAT_BROWSE
3046static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3047#endif
3048#ifdef FEAT_SCROLLBIND
3049static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3050#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003051static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052#ifdef FEAT_VERTSPLIT
3053static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3054#endif
3055#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003056# ifdef FEAT_AUTOCMD
3057static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3058# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003060# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3062#endif
3063static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3064#ifdef FEAT_FOLDING
3065static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003066# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003068# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069 NULL};
3070static char *(p_fcl_values[]) = {"all", NULL};
3071#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003072#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003073static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003074#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003076static void set_option_default(int, int opt_flags, int compatible);
3077static void set_options_default(int opt_flags);
3078static char_u *term_bg_default(void);
3079static void did_set_option(int opt_idx, int opt_flags, int new_value);
3080static char_u *illegal_char(char_u *, int);
3081static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003083static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084#endif
3085#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003086static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003088static char_u *option_expand(int opt_idx, char_u *val);
3089static void didset_options(void);
3090static void didset_options2(void);
3091static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003092#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003093static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003094#else
3095# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3096#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003097static void set_string_option_global(int opt_idx, char_u **varp);
3098static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3099static 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);
3100static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003101#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003102static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003103#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003105static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003107#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003108static char_u *did_set_spell_option(int is_spellfile);
3109static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003110#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003111#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003112static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003113#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003114static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3115static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3116static void check_redraw(long_u flags);
3117static int findoption(char_u *);
3118static int find_key_option(char_u *);
3119static void showoptions(int all, int opt_flags);
3120static int optval_default(struct vimoption *, char_u *varp);
3121static void showoneopt(struct vimoption *, int opt_flags);
3122static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3123static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3124static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3125static int istermoption(struct vimoption *);
3126static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3127static char_u *get_varp(struct vimoption *);
3128static void option_value2string(struct vimoption *, int opt_flags);
3129static void check_winopt(winopt_T *wop);
3130static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003132static void langmap_init(void);
3133static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003135static void paste_option_changed(void);
3136static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003138static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003140static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3141static int check_opt_strings(char_u *val, char **values, int);
3142static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003143#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003144static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003145#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146
3147/*
3148 * Initialize the options, first part.
3149 *
3150 * Called only once from main(), just after creating the first buffer.
3151 */
3152 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003153set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154{
3155 char_u *p;
3156 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003157 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158
3159#ifdef FEAT_LANGMAP
3160 langmap_init();
3161#endif
3162
3163 /* Be Vi compatible by default */
3164 p_cp = TRUE;
3165
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003166 /* Use POSIX compatibility when $VIM_POSIX is set. */
3167 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003168 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003169 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003170 set_string_default("shm", (char_u *)"A");
3171 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003172
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 /*
3174 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003175 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003177 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003178#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003180 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003182 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003184 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185# endif
3186#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003187 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188 set_string_default("sh", p);
3189
3190#ifdef FEAT_WILDIGN
3191 /*
3192 * Set the default for 'backupskip' to include environment variables for
3193 * temp files.
3194 */
3195 {
3196# ifdef UNIX
3197 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3198# else
3199 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3200# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003201 int len;
3202 garray_T ga;
3203 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204
3205 ga_init2(&ga, 1, 100);
3206 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3207 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003208 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209# ifdef UNIX
3210 if (*names[n] == NUL)
3211 p = (char_u *)"/tmp";
3212 else
3213# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003214 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215 if (p != NULL && *p != NUL)
3216 {
3217 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003218 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 if (ga_grow(&ga, len) == OK)
3220 {
3221 if (ga.ga_len > 0)
3222 STRCAT(ga.ga_data, ",");
3223 STRCAT(ga.ga_data, p);
3224 add_pathsep(ga.ga_data);
3225 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 ga.ga_len += len;
3227 }
3228 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003229 if (mustfree)
3230 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231 }
3232 if (ga.ga_data != NULL)
3233 {
3234 set_string_default("bsk", ga.ga_data);
3235 vim_free(ga.ga_data);
3236 }
3237 }
3238#endif
3239
3240 /*
3241 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3242 */
3243 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003244 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003246#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3247 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3248#endif
3249 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003251 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003252 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253#else
3254# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003255 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003256 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003258 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259# endif
3260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003262 opt_idx = findoption((char_u *)"maxmem");
3263 if (opt_idx >= 0)
3264 {
3265#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003266 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3267 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003268#endif
3269 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3270 }
3271 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272 }
3273
3274#ifdef FEAT_GUI_W32
3275 /* force 'shortname' for Win32s */
3276 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003277 {
3278 opt_idx = findoption((char_u *)"shortname");
3279 if (opt_idx >= 0)
3280 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3281 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282#endif
3283
3284#ifdef FEAT_SEARCHPATH
3285 {
3286 char_u *cdpath;
3287 char_u *buf;
3288 int i;
3289 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003290 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291
3292 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003293 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294 if (cdpath != NULL)
3295 {
3296 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3297 if (buf != NULL)
3298 {
3299 buf[0] = ','; /* start with ",", current dir first */
3300 j = 1;
3301 for (i = 0; cdpath[i] != NUL; ++i)
3302 {
3303 if (vim_ispathlistsep(cdpath[i]))
3304 buf[j++] = ',';
3305 else
3306 {
3307 if (cdpath[i] == ' ' || cdpath[i] == ',')
3308 buf[j++] = '\\';
3309 buf[j++] = cdpath[i];
3310 }
3311 }
3312 buf[j] = NUL;
3313 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003314 if (opt_idx >= 0)
3315 {
3316 options[opt_idx].def_val[VI_DEFAULT] = buf;
3317 options[opt_idx].flags |= P_DEF_ALLOCED;
3318 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003319 else
3320 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003322 if (mustfree)
3323 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324 }
3325 }
3326#endif
3327
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003328#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329 /* Set print encoding on platforms that don't default to latin1 */
3330 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003331# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332 (char_u *)"cp1252"
3333# else
3334# ifdef VMS
3335 (char_u *)"dec-mcs"
3336# else
3337# ifdef EBCDIC
3338 (char_u *)"ebcdic-uk"
3339# else
3340# ifdef MAC
3341 (char_u *)"mac-roman"
3342# else /* HPUX */
3343 (char_u *)"hp-roman8"
3344# endif
3345# endif
3346# endif
3347# endif
3348 );
3349#endif
3350
3351#ifdef FEAT_POSTSCRIPT
3352 /* 'printexpr' must be allocated to be able to evaluate it. */
3353 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003354# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003355 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356# else
3357# ifdef VMS
3358 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3359
3360# else
3361 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3362# endif
3363# endif
3364 );
3365#endif
3366
3367 /*
3368 * Set all the options (except the terminal options) to their default
3369 * value. Also set the global value for local options.
3370 */
3371 set_options_default(0);
3372
3373#ifdef FEAT_GUI
3374 if (found_reverse_arg)
3375 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3376#endif
3377
3378 curbuf->b_p_initialized = TRUE;
3379 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003380 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381 check_buf_options(curbuf);
3382 check_win_options(curwin);
3383 check_options();
3384
3385 /* Must be before option_expand(), because that one needs vim_isIDc() */
3386 didset_options();
3387
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003388#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003389 /* Use the current chartab for the generic chartab. This is not in
3390 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003391 init_spell_chartab();
3392#endif
3393
Bram Moolenaar071d4272004-06-13 20:20:40 +00003394 /*
3395 * Expand environment variables and things like "~" for the defaults.
3396 * If option_expand() returns non-NULL the variable is expanded. This can
3397 * only happen for non-indirect options.
3398 * Also set the default to the expanded value, so ":set" does not list
3399 * them.
3400 * Don't set the P_ALLOCED flag, because we don't want to free the
3401 * default.
3402 */
3403 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3404 {
3405 if ((options[opt_idx].flags & P_GETTEXT)
3406 && options[opt_idx].var != NULL)
3407 p = (char_u *)_(*(char **)options[opt_idx].var);
3408 else
3409 p = option_expand(opt_idx, NULL);
3410 if (p != NULL && (p = vim_strsave(p)) != NULL)
3411 {
3412 *(char_u **)options[opt_idx].var = p;
3413 /* VIMEXP
3414 * Defaults for all expanded options are currently the same for Vi
3415 * and Vim. When this changes, add some code here! Also need to
3416 * split P_DEF_ALLOCED in two.
3417 */
3418 if (options[opt_idx].flags & P_DEF_ALLOCED)
3419 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3420 options[opt_idx].def_val[VI_DEFAULT] = p;
3421 options[opt_idx].flags |= P_DEF_ALLOCED;
3422 }
3423 }
3424
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425 save_file_ff(curbuf); /* Buffer is unchanged */
3426
Bram Moolenaar071d4272004-06-13 20:20:40 +00003427#if defined(FEAT_ARABIC)
3428 /* Detect use of mlterm.
3429 * Mlterm is a terminal emulator akin to xterm that has some special
3430 * abilities (bidi namely).
3431 * NOTE: mlterm's author is being asked to 'set' a variable
3432 * instead of an environment variable due to inheritance.
3433 */
3434 if (mch_getenv((char_u *)"MLTERM") != NULL)
3435 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3436#endif
3437
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003438 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439
3440#ifdef FEAT_MBYTE
3441# if defined(WIN3264) && defined(FEAT_GETTEXT)
3442 /*
3443 * If $LANG isn't set, try to get a good value for it. This makes the
3444 * right language be used automatically. Don't do this for English.
3445 */
3446 if (mch_getenv((char_u *)"LANG") == NULL)
3447 {
3448 char buf[20];
3449
3450 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3451 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3452 * only the first two. */
3453 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3454 (LPTSTR)buf, 20);
3455 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3456 {
3457 /* There are a few exceptions (probably more) */
3458 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3459 STRCPY(buf, "zh_TW");
3460 else if (STRNICMP(buf, "chs", 3) == 0
3461 || STRNICMP(buf, "zhc", 3) == 0)
3462 STRCPY(buf, "zh_CN");
3463 else if (STRNICMP(buf, "jp", 2) == 0)
3464 STRCPY(buf, "ja");
3465 else
3466 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003467 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468 }
3469 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003470# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003471# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003472 /* Moved to os_mac_conv.c to avoid dependency problems. */
3473 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003474# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475# endif
3476
3477 /* enc_locale() will try to find the encoding of the current locale. */
3478 p = enc_locale();
3479 if (p != NULL)
3480 {
3481 char_u *save_enc;
3482
3483 /* Try setting 'encoding' and check if the value is valid.
3484 * If not, go back to the default "latin1". */
3485 save_enc = p_enc;
3486 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003487 if (STRCMP(p_enc, "gb18030") == 0)
3488 {
3489 /* We don't support "gb18030", but "cp936" is a good substitute
3490 * for practical purposes, thus use that. It's not an alias to
3491 * still support conversion between gb18030 and utf-8. */
3492 p_enc = vim_strsave((char_u *)"cp936");
3493 vim_free(p);
3494 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003495 if (mb_init() == NULL)
3496 {
3497 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003498 if (opt_idx >= 0)
3499 {
3500 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3501 options[opt_idx].flags |= P_DEF_ALLOCED;
3502 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003503
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003504#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003505 if (STRCMP(p_enc, "latin1") == 0
3506# ifdef FEAT_MBYTE
3507 || enc_utf8
3508# endif
3509 )
3510 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003511 /* Adjust the default for 'isprint' and 'iskeyword' to match
3512 * latin1. Also set the defaults for when 'nocompatible' is
3513 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003514 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003515 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003516 set_string_option_direct((char_u *)"isk", -1,
3517 ISK_LATIN1, OPT_FREE, SID_NONE);
3518 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003519 if (opt_idx >= 0)
3520 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003521 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003522 if (opt_idx >= 0)
3523 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003524 (void)init_chartab();
3525 }
3526#endif
3527
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528# if defined(WIN3264) && !defined(FEAT_GUI)
3529 /* Win32 console: When GetACP() returns a different value from
3530 * GetConsoleCP() set 'termencoding'. */
3531 if (GetACP() != GetConsoleCP())
3532 {
3533 char buf[50];
3534
3535 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3536 p_tenc = vim_strsave((char_u *)buf);
3537 if (p_tenc != NULL)
3538 {
3539 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003540 if (opt_idx >= 0)
3541 {
3542 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3543 options[opt_idx].flags |= P_DEF_ALLOCED;
3544 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003545 convert_setup(&input_conv, p_tenc, p_enc);
3546 convert_setup(&output_conv, p_enc, p_tenc);
3547 }
3548 else
3549 p_tenc = empty_option;
3550 }
3551# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003552# if defined(WIN3264) && defined(FEAT_MBYTE)
3553 /* $HOME may have characters in active code page. */
3554 init_homedir();
3555# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003556 }
3557 else
3558 {
3559 vim_free(p_enc);
3560 p_enc = save_enc;
3561 }
3562 }
3563#endif
3564
3565#ifdef FEAT_MULTI_LANG
3566 /* Set the default for 'helplang'. */
3567 set_helplang_default(get_mess_lang());
3568#endif
3569}
3570
3571/*
3572 * Set an option to its default value.
3573 * This does not take care of side effects!
3574 */
3575 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003576set_option_default(
3577 int opt_idx,
3578 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3579 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003580{
3581 char_u *varp; /* pointer to variable for current option */
3582 int dvi; /* index in def_val[] */
3583 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003584 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3586
3587 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3588 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003589 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003590 {
3591 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3592 if (flags & P_STRING)
3593 {
3594 /* Use set_string_option_direct() for local options to handle
3595 * freeing and allocating the value. */
3596 if (options[opt_idx].indir != PV_NONE)
3597 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003598 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599 else
3600 {
3601 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3602 free_string_option(*(char_u **)(varp));
3603 *(char_u **)varp = options[opt_idx].def_val[dvi];
3604 options[opt_idx].flags &= ~P_ALLOCED;
3605 }
3606 }
3607 else if (flags & P_NUM)
3608 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003609 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003610 win_comp_scroll(curwin);
3611 else
3612 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003613 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003614 /* May also set global value for local option. */
3615 if (both)
3616 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3617 *(long *)varp;
3618 }
3619 }
3620 else /* P_BOOL */
3621 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003622 /* the cast to long is required for Manx C, long_i is needed for
3623 * MSVC */
3624 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003625#ifdef UNIX
3626 /* 'modeline' defaults to off for root */
3627 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3628 *(int *)varp = FALSE;
3629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630 /* May also set global value for local option. */
3631 if (both)
3632 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3633 *(int *)varp;
3634 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003635
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003636 /* The default value is not insecure. */
3637 flagsp = insecure_flag(opt_idx, opt_flags);
3638 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003639 }
3640
3641#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003642 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643#endif
3644}
3645
3646/*
3647 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003648 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649 */
3650 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003651set_options_default(
3652 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653{
3654 int i;
3655#ifdef FEAT_WINDOWS
3656 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003657 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658#endif
3659
3660 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003661 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003662#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003663 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003664 || (TRUE
3665# if defined(FEAT_MBYTE)
3666 && options[i].var != (char_u *)&p_enc
3667# endif
3668# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003669 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003670 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003671# endif
3672 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003673#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003674 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003675 set_option_default(i, opt_flags, p_cp);
3676
3677#ifdef FEAT_WINDOWS
3678 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003679 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680 win_comp_scroll(wp);
3681#else
3682 win_comp_scroll(curwin);
3683#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003684#ifdef FEAT_CINDENT
3685 parse_cino(curbuf);
3686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687}
3688
3689/*
3690 * Set the Vi-default value of a string option.
3691 * Used for 'sh', 'backupskip' and 'term'.
3692 */
3693 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003694set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695{
3696 char_u *p;
3697 int opt_idx;
3698
3699 p = vim_strsave(val);
3700 if (p != NULL) /* we don't want a NULL */
3701 {
3702 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003703 if (opt_idx >= 0)
3704 {
3705 if (options[opt_idx].flags & P_DEF_ALLOCED)
3706 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3707 options[opt_idx].def_val[VI_DEFAULT] = p;
3708 options[opt_idx].flags |= P_DEF_ALLOCED;
3709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710 }
3711}
3712
3713/*
3714 * Set the Vi-default value of a number option.
3715 * Used for 'lines' and 'columns'.
3716 */
3717 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003718set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003719{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003720 int opt_idx;
3721
3722 opt_idx = findoption((char_u *)name);
3723 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003724 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725}
3726
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003727#if defined(EXITFREE) || defined(PROTO)
3728/*
3729 * Free all options.
3730 */
3731 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003732free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003733{
3734 int i;
3735
3736 for (i = 0; !istermoption(&options[i]); i++)
3737 {
3738 if (options[i].indir == PV_NONE)
3739 {
3740 /* global option: free value and default value. */
3741 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3742 free_string_option(*(char_u **)options[i].var);
3743 if (options[i].flags & P_DEF_ALLOCED)
3744 free_string_option(options[i].def_val[VI_DEFAULT]);
3745 }
3746 else if (options[i].var != VAR_WIN
3747 && (options[i].flags & P_STRING))
3748 /* buffer-local option: free global value */
3749 free_string_option(*(char_u **)options[i].var);
3750 }
3751}
3752#endif
3753
3754
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755/*
3756 * Initialize the options, part two: After getting Rows and Columns and
3757 * setting 'term'.
3758 */
3759 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003760set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003762 int idx;
3763
Bram Moolenaar071d4272004-06-13 20:20:40 +00003764 /*
3765 * 'scroll' defaults to half the window height. Note that this default is
3766 * wrong when the window height changes.
3767 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003768 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003769 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003770 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003771 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 comp_col();
3773
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003774 /*
3775 * 'window' is only for backwards compatibility with Vi.
3776 * Default is Rows - 1.
3777 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003778 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003779 p_window = Rows - 1;
3780 set_number_default("window", Rows - 1);
3781
Bram Moolenaarf740b292006-02-16 22:11:02 +00003782 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003783#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003784 /*
3785 * If 'background' wasn't set by the user, try guessing the value,
3786 * depending on the terminal name. Only need to check for terminals
3787 * with a dark background, that can handle color.
3788 */
3789 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003790 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3791 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003793 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003794 /* don't mark it as set, when starting the GUI it may be
3795 * changed again */
3796 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 }
3798#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003799
3800#ifdef CURSOR_SHAPE
3801 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3802#endif
3803#ifdef FEAT_MOUSESHAPE
3804 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3805#endif
3806#ifdef FEAT_PRINTER
3807 (void)parse_printoptions(); /* parse 'printoptions' default value */
3808#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809}
3810
3811/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003812 * Return "dark" or "light" depending on the kind of terminal.
3813 * This is just guessing! Recognized are:
3814 * "linux" Linux console
3815 * "screen.linux" Linux console with screen
3816 * "cygwin" Cygwin shell
3817 * "putty" Putty program
3818 * We also check the COLORFGBG environment variable, which is set by
3819 * rxvt and derivatives. This variable contains either two or three
3820 * values separated by semicolons; we want the last value in either
3821 * case. If this value is 0-6 or 8, our background is dark.
3822 */
3823 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003824term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003825{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003826#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003827 /* DOS console nearly always black */
3828 return (char_u *)"dark";
3829#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003830 char_u *p;
3831
Bram Moolenaarf740b292006-02-16 22:11:02 +00003832 if (STRCMP(T_NAME, "linux") == 0
3833 || STRCMP(T_NAME, "screen.linux") == 0
3834 || STRCMP(T_NAME, "cygwin") == 0
3835 || STRCMP(T_NAME, "putty") == 0
3836 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3837 && (p = vim_strrchr(p, ';')) != NULL
3838 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3839 && p[2] == NUL))
3840 return (char_u *)"dark";
3841 return (char_u *)"light";
3842#endif
3843}
3844
3845/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846 * Initialize the options, part three: After reading the .vimrc
3847 */
3848 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003849set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003851#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852/*
3853 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3854 * This is done after other initializations, where 'shell' might have been
3855 * set, but only if they have not been set before.
3856 */
3857 char_u *p;
3858 int idx_srr;
3859 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003860# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861 int idx_sp;
3862 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003863# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864
3865 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003866 if (idx_srr < 0)
3867 do_srr = FALSE;
3868 else
3869 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003870# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003872 if (idx_sp < 0)
3873 do_sp = FALSE;
3874 else
3875 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003876# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003877 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878 if (p != NULL)
3879 {
3880 /*
3881 * Default for p_sp is "| tee", for p_srr is ">".
3882 * For known shells it is changed here to include stderr.
3883 */
3884 if ( fnamecmp(p, "csh") == 0
3885 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003886# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 || fnamecmp(p, "csh.exe") == 0
3888 || fnamecmp(p, "tcsh.exe") == 0
3889# endif
3890 )
3891 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003892# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 if (do_sp)
3894 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003895# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003897# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003899# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3901 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003902# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903 if (do_srr)
3904 {
3905 p_srr = (char_u *)">&";
3906 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3907 }
3908 }
3909 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003910 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 if ( fnamecmp(p, "sh") == 0
3912 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003913 || fnamecmp(p, "mksh") == 0
3914 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003916 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003918 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003919# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920 || fnamecmp(p, "cmd") == 0
3921 || fnamecmp(p, "sh.exe") == 0
3922 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003923 || fnamecmp(p, "mksh.exe") == 0
3924 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003926 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927 || fnamecmp(p, "bash.exe") == 0
3928 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003930 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003932# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 if (do_sp)
3934 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003935# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003937# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003939# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3941 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003942# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 if (do_srr)
3944 {
3945 p_srr = (char_u *)">%s 2>&1";
3946 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3947 }
3948 }
3949 vim_free(p);
3950 }
3951#endif
3952
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003953#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003955 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3956 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003957 * This is done after other initializations, where 'shell' might have been
3958 * set, but only if they have not been set before. Default for p_shcf is
3959 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003960 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003962 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 {
3964 int idx3;
3965
3966 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003967 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968 {
3969 p_shcf = (char_u *)"-c";
3970 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3971 }
3972
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003973# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 /* Somehow Win32 requires the quotes around the redirection too */
3975 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003976 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 {
3978 p_sxq = (char_u *)"\"";
3979 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3980 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003981# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982 idx3 = findoption((char_u *)"shq");
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_shq = (char_u *)"\"";
3986 options[idx3].def_val[VI_DEFAULT] = p_shq;
3987 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988# endif
3989 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003990 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3991 {
3992 int idx3;
3993
3994 /*
3995 * cmd.exe on Windows will strip the first and last double quote given
3996 * on the command line, e.g. most of the time things like:
3997 * cmd /c "my path/to/echo" "my args to echo"
3998 * become:
3999 * my path/to/echo" "my args to echo
4000 * when executed.
4001 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004002 * To avoid this, set shellxquote to surround the command in
4003 * parenthesis. This appears to make most commands work, without
4004 * breaking commands that worked previously, such as
4005 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004006 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004007 idx3 = findoption((char_u *)"sxq");
4008 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4009 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004010 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004011 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4012 }
4013
Bram Moolenaara64ba222012-02-12 23:23:31 +01004014 idx3 = findoption((char_u *)"shcf");
4015 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4016 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004017 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004018 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4019 }
4020 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021#endif
4022
4023#ifdef FEAT_TITLE
4024 set_title_defaults();
4025#endif
4026}
4027
4028#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4029/*
4030 * When 'helplang' is still at its default value, set it to "lang".
4031 * Only the first two characters of "lang" are used.
4032 */
4033 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004034set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035{
4036 int idx;
4037
4038 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4039 return;
4040 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004041 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042 {
4043 if (options[idx].flags & P_ALLOCED)
4044 free_string_option(p_hlg);
4045 p_hlg = vim_strsave(lang);
4046 if (p_hlg == NULL)
4047 p_hlg = empty_option;
4048 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004049 {
4050 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4051 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4052 {
4053 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4054 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4055 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 options[idx].flags |= P_ALLOCED;
4059 }
4060}
4061#endif
4062
4063#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004064static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065
4066 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004067gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068{
4069 if (gui_get_lightness(gui.back_pixel) < 127)
4070 return (char_u *)"dark";
4071 return (char_u *)"light";
4072}
4073
4074/*
4075 * Option initializations that can only be done after opening the GUI window.
4076 */
4077 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004078init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079{
4080 /* Set the 'background' option according to the lightness of the
4081 * background color, unless the user has set it already. */
4082 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4083 {
4084 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4085 highlight_changed();
4086 }
4087}
4088#endif
4089
4090#ifdef FEAT_TITLE
4091/*
4092 * 'title' and 'icon' only default to true if they have not been set or reset
4093 * in .vimrc and we can read the old value.
4094 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4095 * they can be reset. This reduces startup time when using X on a remote
4096 * machine.
4097 */
4098 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004099set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100{
4101 int idx1;
4102 long val;
4103
4104 /*
4105 * If GUI is (going to be) used, we can always set the window title and
4106 * icon name. Saves a bit of time, because the X11 display server does
4107 * not need to be contacted.
4108 */
4109 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004110 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 {
4112#ifdef FEAT_GUI
4113 if (gui.starting || gui.in_use)
4114 val = TRUE;
4115 else
4116#endif
4117 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004118 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 p_title = val;
4120 }
4121 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004122 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 {
4124#ifdef FEAT_GUI
4125 if (gui.starting || gui.in_use)
4126 val = TRUE;
4127 else
4128#endif
4129 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004130 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 p_icon = val;
4132 }
4133}
4134#endif
4135
4136/*
4137 * Parse 'arg' for option settings.
4138 *
4139 * 'arg' may be IObuff, but only when no errors can be present and option
4140 * does not need to be expanded with option_expand().
4141 * "opt_flags":
4142 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004143 * OPT_GLOBAL for ":setglobal"
4144 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004146 * OPT_WINONLY to only set window-local options
4147 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 *
4149 * returns FAIL if an error is detected, OK otherwise
4150 */
4151 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004152do_set(
4153 char_u *arg, /* option string (may be written to!) */
4154 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155{
4156 int opt_idx;
4157 char_u *errmsg;
4158 char_u errbuf[80];
4159 char_u *startarg;
4160 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4161 int nextchar; /* next non-white char after option name */
4162 int afterchar; /* character just after option name */
4163 int len;
4164 int i;
4165 long value;
4166 int key;
4167 long_u flags; /* flags for current option */
4168 char_u *varp = NULL; /* pointer to variable for current option */
4169 int did_show = FALSE; /* already showed one value */
4170 int adding; /* "opt+=arg" */
4171 int prepending; /* "opt^=arg" */
4172 int removing; /* "opt-=arg" */
4173 int cp_val = 0;
4174 char_u key_name[2];
4175
4176 if (*arg == NUL)
4177 {
4178 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004179 did_show = TRUE;
4180 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004181 }
4182
4183 while (*arg != NUL) /* loop to process all options */
4184 {
4185 errmsg = NULL;
4186 startarg = arg; /* remember for error message */
4187
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004188 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4189 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190 {
4191 /*
4192 * ":set all" show all options.
4193 * ":set all&" set all options to their default value.
4194 */
4195 arg += 3;
4196 if (*arg == '&')
4197 {
4198 ++arg;
4199 /* Only for :set command set global value of local options. */
4200 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004201 didset_options();
4202 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004203 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004204 }
4205 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004206 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004208 did_show = TRUE;
4209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004211 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 {
4213 showoptions(2, opt_flags);
4214 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004215 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004216 arg += 7;
4217 }
4218 else
4219 {
4220 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004221 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 {
4223 prefix = 0;
4224 arg += 2;
4225 }
4226 else if (STRNCMP(arg, "inv", 3) == 0)
4227 {
4228 prefix = 2;
4229 arg += 3;
4230 }
4231
4232 /* find end of name */
4233 key = 0;
4234 if (*arg == '<')
4235 {
4236 nextchar = 0;
4237 opt_idx = -1;
4238 /* look out for <t_>;> */
4239 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4240 len = 5;
4241 else
4242 {
4243 len = 1;
4244 while (arg[len] != NUL && arg[len] != '>')
4245 ++len;
4246 }
4247 if (arg[len] != '>')
4248 {
4249 errmsg = e_invarg;
4250 goto skip;
4251 }
4252 arg[len] = NUL; /* put NUL after name */
4253 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4254 opt_idx = findoption(arg + 1);
4255 arg[len++] = '>'; /* restore '>' */
4256 if (opt_idx == -1)
4257 key = find_key_option(arg + 1);
4258 }
4259 else
4260 {
4261 len = 0;
4262 /*
4263 * The two characters after "t_" may not be alphanumeric.
4264 */
4265 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4266 len = 4;
4267 else
4268 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4269 ++len;
4270 nextchar = arg[len];
4271 arg[len] = NUL; /* put NUL after name */
4272 opt_idx = findoption(arg);
4273 arg[len] = nextchar; /* restore nextchar */
4274 if (opt_idx == -1)
4275 key = find_key_option(arg);
4276 }
4277
4278 /* remember character after option name */
4279 afterchar = arg[len];
4280
4281 /* skip white space, allow ":set ai ?" */
4282 while (vim_iswhite(arg[len]))
4283 ++len;
4284
4285 adding = FALSE;
4286 prepending = FALSE;
4287 removing = FALSE;
4288 if (arg[len] != NUL && arg[len + 1] == '=')
4289 {
4290 if (arg[len] == '+')
4291 {
4292 adding = TRUE; /* "+=" */
4293 ++len;
4294 }
4295 else if (arg[len] == '^')
4296 {
4297 prepending = TRUE; /* "^=" */
4298 ++len;
4299 }
4300 else if (arg[len] == '-')
4301 {
4302 removing = TRUE; /* "-=" */
4303 ++len;
4304 }
4305 }
4306 nextchar = arg[len];
4307
4308 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4309 {
4310 errmsg = (char_u *)N_("E518: Unknown option");
4311 goto skip;
4312 }
4313
4314 if (opt_idx >= 0)
4315 {
4316 if (options[opt_idx].var == NULL) /* hidden option: skip */
4317 {
4318 /* Only give an error message when requesting the value of
4319 * a hidden option, ignore setting it. */
4320 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4321 && (!(options[opt_idx].flags & P_BOOL)
4322 || nextchar == '?'))
4323 errmsg = (char_u *)N_("E519: Option not supported");
4324 goto skip;
4325 }
4326
4327 flags = options[opt_idx].flags;
4328 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4329 }
4330 else
4331 {
4332 flags = P_STRING;
4333 if (key < 0)
4334 {
4335 key_name[0] = KEY2TERMCAP0(key);
4336 key_name[1] = KEY2TERMCAP1(key);
4337 }
4338 else
4339 {
4340 key_name[0] = KS_KEY;
4341 key_name[1] = (key & 0xff);
4342 }
4343 }
4344
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004345 /* Skip all options that are not window-local (used when showing
4346 * an already loaded buffer in a window). */
4347 if ((opt_flags & OPT_WINONLY)
4348 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4349 goto skip;
4350
Bram Moolenaara3227e22006-03-08 21:32:40 +00004351 /* Skip all options that are window-local (used for :vimgrep). */
4352 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4353 && options[opt_idx].var == VAR_WIN)
4354 goto skip;
4355
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004356 /* Disallow changing some options from modelines. */
4357 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004358 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004359 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004360 {
4361 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4362 goto skip;
4363 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004364#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004365 /* In diff mode some options are overruled. This avoids that
4366 * 'foldmethod' becomes "marker" instead of "diff" and that
4367 * "wrap" gets set. */
4368 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004369 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004370 && (options[opt_idx].indir == PV_FDM
4371 || options[opt_idx].indir == PV_WRAP))
4372 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374 }
4375
4376#ifdef HAVE_SANDBOX
4377 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004378 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 {
4380 errmsg = (char_u *)_(e_sandbox);
4381 goto skip;
4382 }
4383#endif
4384
4385 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4386 {
4387 arg += len;
4388 cp_val = p_cp;
4389 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4390 {
4391 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4392 {
4393 cp_val = FALSE;
4394 arg += 3;
4395 }
4396 else /* "opt&vi": set to Vi default */
4397 {
4398 cp_val = TRUE;
4399 arg += 2;
4400 }
4401 }
4402 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4403 && arg[1] != NUL && !vim_iswhite(arg[1]))
4404 {
4405 errmsg = e_trailing;
4406 goto skip;
4407 }
4408 }
4409
4410 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004411 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4412 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004413 */
4414 if (nextchar == '?'
4415 || (prefix == 1
4416 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4417 && !(flags & P_BOOL)))
4418 {
4419 /*
4420 * print value
4421 */
4422 if (did_show)
4423 msg_putchar('\n'); /* cursor below last one */
4424 else
4425 {
4426 gotocmdline(TRUE); /* cursor at status line */
4427 did_show = TRUE; /* remember that we did a line */
4428 }
4429 if (opt_idx >= 0)
4430 {
4431 showoneopt(&options[opt_idx], opt_flags);
4432#ifdef FEAT_EVAL
4433 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004434 {
4435 /* Mention where the option was last set. */
4436 if (varp == options[opt_idx].var)
4437 last_set_msg(options[opt_idx].scriptID);
4438 else if ((int)options[opt_idx].indir & PV_WIN)
4439 last_set_msg(curwin->w_p_scriptID[
4440 (int)options[opt_idx].indir & PV_MASK]);
4441 else if ((int)options[opt_idx].indir & PV_BUF)
4442 last_set_msg(curbuf->b_p_scriptID[
4443 (int)options[opt_idx].indir & PV_MASK]);
4444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445#endif
4446 }
4447 else
4448 {
4449 char_u *p;
4450
4451 p = find_termcode(key_name);
4452 if (p == NULL)
4453 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004454 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004455 goto skip;
4456 }
4457 else
4458 (void)show_one_termcode(key_name, p, TRUE);
4459 }
4460 if (nextchar != '?'
4461 && nextchar != NUL && !vim_iswhite(afterchar))
4462 errmsg = e_trailing;
4463 }
4464 else
4465 {
4466 if (flags & P_BOOL) /* boolean */
4467 {
4468 if (nextchar == '=' || nextchar == ':')
4469 {
4470 errmsg = e_invarg;
4471 goto skip;
4472 }
4473
4474 /*
4475 * ":set opt!": invert
4476 * ":set opt&": reset to default value
4477 * ":set opt<": reset to global value
4478 */
4479 if (nextchar == '!')
4480 value = *(int *)(varp) ^ 1;
4481 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004482 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004483 ((flags & P_VI_DEF) || cp_val)
4484 ? VI_DEFAULT : VIM_DEFAULT];
4485 else if (nextchar == '<')
4486 {
4487 /* For 'autoread' -1 means to use global value. */
4488 if ((int *)varp == &curbuf->b_p_ar
4489 && opt_flags == OPT_LOCAL)
4490 value = -1;
4491 else
4492 value = *(int *)get_varp_scope(&(options[opt_idx]),
4493 OPT_GLOBAL);
4494 }
4495 else
4496 {
4497 /*
4498 * ":set invopt": invert
4499 * ":set opt" or ":set noopt": set or reset
4500 */
4501 if (nextchar != NUL && !vim_iswhite(afterchar))
4502 {
4503 errmsg = e_trailing;
4504 goto skip;
4505 }
4506 if (prefix == 2) /* inv */
4507 value = *(int *)(varp) ^ 1;
4508 else
4509 value = prefix;
4510 }
4511
4512 errmsg = set_bool_option(opt_idx, varp, (int)value,
4513 opt_flags);
4514 }
4515 else /* numeric or string */
4516 {
4517 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4518 || prefix != 1)
4519 {
4520 errmsg = e_invarg;
4521 goto skip;
4522 }
4523
4524 if (flags & P_NUM) /* numeric */
4525 {
4526 /*
4527 * Different ways to set a number option:
4528 * & set to default value
4529 * < set to global value
4530 * <xx> accept special key codes for 'wildchar'
4531 * c accept any non-digit for 'wildchar'
4532 * [-]0-9 set number
4533 * other error
4534 */
4535 ++arg;
4536 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004537 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004538 ((flags & P_VI_DEF) || cp_val)
4539 ? VI_DEFAULT : VIM_DEFAULT];
4540 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004541 {
4542 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4543 * use the global value. */
4544 if ((long *)varp == &curbuf->b_p_ul
4545 && opt_flags == OPT_LOCAL)
4546 value = NO_LOCAL_UNDOLEVEL;
4547 else
4548 value = *(long *)get_varp_scope(
4549 &(options[opt_idx]), OPT_GLOBAL);
4550 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004551 else if (((long *)varp == &p_wc
4552 || (long *)varp == &p_wcm)
4553 && (*arg == '<'
4554 || *arg == '^'
4555 || ((!arg[1] || vim_iswhite(arg[1]))
4556 && !VIM_ISDIGIT(*arg))))
4557 {
4558 value = string_to_key(arg);
4559 if (value == 0 && (long *)varp != &p_wcm)
4560 {
4561 errmsg = e_invarg;
4562 goto skip;
4563 }
4564 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4566 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004567 /* Allow negative (for 'undolevels'), octal and
4568 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004569 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4570 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004571 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4572 {
4573 errmsg = e_invarg;
4574 goto skip;
4575 }
4576 }
4577 else
4578 {
4579 errmsg = (char_u *)N_("E521: Number required after =");
4580 goto skip;
4581 }
4582
4583 if (adding)
4584 value = *(long *)varp + value;
4585 if (prepending)
4586 value = *(long *)varp * value;
4587 if (removing)
4588 value = *(long *)varp - value;
4589 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004590 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004591 }
4592 else if (opt_idx >= 0) /* string */
4593 {
4594 char_u *save_arg = NULL;
4595 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004596 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004597 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004598 char_u *origval = NULL;
4599#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4600 char_u *saved_origval = NULL;
4601#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004602 unsigned newlen;
4603 int comma;
4604 int bs;
4605 int new_value_alloced; /* new string option
4606 was allocated */
4607
4608 /* When using ":set opt=val" for a global option
4609 * with a local value the local value will be
4610 * reset, use the global value here. */
4611 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004612 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613 varp = options[opt_idx].var;
4614
4615 /* The old value is kept until we are sure that the
4616 * new value is valid. */
4617 oldval = *(char_u **)varp;
4618 if (nextchar == '&') /* set to default val */
4619 {
4620 newval = options[opt_idx].def_val[
4621 ((flags & P_VI_DEF) || cp_val)
4622 ? VI_DEFAULT : VIM_DEFAULT];
4623 if ((char_u **)varp == &p_bg)
4624 {
4625 /* guess the value of 'background' */
4626#ifdef FEAT_GUI
4627 if (gui.in_use)
4628 newval = gui_bg_default();
4629 else
4630#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004631 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004632 }
4633
4634 /* expand environment variables and ~ (since the
4635 * default value was already expanded, only
4636 * required when an environment variable was set
4637 * later */
4638 if (newval == NULL)
4639 newval = empty_option;
4640 else
4641 {
4642 s = option_expand(opt_idx, newval);
4643 if (s == NULL)
4644 s = newval;
4645 newval = vim_strsave(s);
4646 }
4647 new_value_alloced = TRUE;
4648 }
4649 else if (nextchar == '<') /* set to global val */
4650 {
4651 newval = vim_strsave(*(char_u **)get_varp_scope(
4652 &(options[opt_idx]), OPT_GLOBAL));
4653 new_value_alloced = TRUE;
4654 }
4655 else
4656 {
4657 ++arg; /* jump to after the '=' or ':' */
4658
4659 /*
4660 * Set 'keywordprg' to ":help" if an empty
4661 * value was passed to :set by the user.
4662 * Misuse errbuf[] for the resulting string.
4663 */
4664 if (varp == (char_u *)&p_kp
4665 && (*arg == NUL || *arg == ' '))
4666 {
4667 STRCPY(errbuf, ":help");
4668 save_arg = arg;
4669 arg = errbuf;
4670 }
4671 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004672 * Convert 'backspace' number to string, for
4673 * adding, prepending and removing string.
4674 */
4675 else if (varp == (char_u *)&p_bs
4676 && VIM_ISDIGIT(**(char_u **)varp))
4677 {
4678 i = getdigits((char_u **)varp);
4679 switch (i)
4680 {
4681 case 0:
4682 *(char_u **)varp = empty_option;
4683 break;
4684 case 1:
4685 *(char_u **)varp = vim_strsave(
4686 (char_u *)"indent,eol");
4687 break;
4688 case 2:
4689 *(char_u **)varp = vim_strsave(
4690 (char_u *)"indent,eol,start");
4691 break;
4692 }
4693 vim_free(oldval);
4694 oldval = *(char_u **)varp;
4695 }
4696 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004697 * Convert 'whichwrap' number to string, for
4698 * backwards compatibility with Vim 3.0.
4699 * Misuse errbuf[] for the resulting string.
4700 */
4701 else if (varp == (char_u *)&p_ww
4702 && VIM_ISDIGIT(*arg))
4703 {
4704 *errbuf = NUL;
4705 i = getdigits(&arg);
4706 if (i & 1)
4707 STRCAT(errbuf, "b,");
4708 if (i & 2)
4709 STRCAT(errbuf, "s,");
4710 if (i & 4)
4711 STRCAT(errbuf, "h,l,");
4712 if (i & 8)
4713 STRCAT(errbuf, "<,>,");
4714 if (i & 16)
4715 STRCAT(errbuf, "[,],");
4716 if (*errbuf != NUL) /* remove trailing , */
4717 errbuf[STRLEN(errbuf) - 1] = NUL;
4718 save_arg = arg;
4719 arg = errbuf;
4720 }
4721 /*
4722 * Remove '>' before 'dir' and 'bdir', for
4723 * backwards compatibility with version 3.0
4724 */
4725 else if ( *arg == '>'
4726 && (varp == (char_u *)&p_dir
4727 || varp == (char_u *)&p_bdir))
4728 {
4729 ++arg;
4730 }
4731
4732 /* When setting the local value of a global
4733 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004734 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004735 && (opt_flags & OPT_LOCAL))
4736 origval = *(char_u **)get_varp(
4737 &options[opt_idx]);
4738 else
4739 origval = oldval;
4740
4741 /*
4742 * Copy the new string into allocated memory.
4743 * Can't use set_string_option_direct(), because
4744 * we need to remove the backslashes.
4745 */
4746 /* get a bit too much */
4747 newlen = (unsigned)STRLEN(arg) + 1;
4748 if (adding || prepending || removing)
4749 newlen += (unsigned)STRLEN(origval) + 1;
4750 newval = alloc(newlen);
4751 if (newval == NULL) /* out of mem, don't change */
4752 break;
4753 s = newval;
4754
4755 /*
4756 * Copy the string, skip over escaped chars.
4757 * For MS-DOS and WIN32 backslashes before normal
4758 * file name characters are not removed, and keep
4759 * backslash at start, for "\\machine\path", but
4760 * do remove it for "\\\\machine\\path".
4761 * The reverse is found in ExpandOldSetting().
4762 */
4763 while (*arg && !vim_iswhite(*arg))
4764 {
4765 if (*arg == '\\' && arg[1] != NUL
4766#ifdef BACKSLASH_IN_FILENAME
4767 && !((flags & P_EXPAND)
4768 && vim_isfilec(arg[1])
4769 && (arg[1] != '\\'
4770 || (s == newval
4771 && arg[2] != '\\')))
4772#endif
4773 )
4774 ++arg; /* remove backslash */
4775#ifdef FEAT_MBYTE
4776 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004777 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004778 {
4779 /* copy multibyte char */
4780 mch_memmove(s, arg, (size_t)i);
4781 arg += i;
4782 s += i;
4783 }
4784 else
4785#endif
4786 *s++ = *arg++;
4787 }
4788 *s = NUL;
4789
4790 /*
4791 * Expand environment variables and ~.
4792 * Don't do it when adding without inserting a
4793 * comma.
4794 */
4795 if (!(adding || prepending || removing)
4796 || (flags & P_COMMA))
4797 {
4798 s = option_expand(opt_idx, newval);
4799 if (s != NULL)
4800 {
4801 vim_free(newval);
4802 newlen = (unsigned)STRLEN(s) + 1;
4803 if (adding || prepending || removing)
4804 newlen += (unsigned)STRLEN(origval) + 1;
4805 newval = alloc(newlen);
4806 if (newval == NULL)
4807 break;
4808 STRCPY(newval, s);
4809 }
4810 }
4811
4812 /* locate newval[] in origval[] when removing it
4813 * and when adding to avoid duplicates */
4814 i = 0; /* init for GCC */
4815 if (removing || (flags & P_NODUP))
4816 {
4817 i = (int)STRLEN(newval);
4818 bs = 0;
4819 for (s = origval; *s; ++s)
4820 {
4821 if ((!(flags & P_COMMA)
4822 || s == origval
4823 || (s[-1] == ',' && !(bs & 1)))
4824 && STRNCMP(s, newval, i) == 0
4825 && (!(flags & P_COMMA)
4826 || s[i] == ','
4827 || s[i] == NUL))
4828 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004829 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004830 * even number of backslashes or a single
4831 * backslash preceded by a comma before it
4832 * is recognized as a separator */
4833 if ((s > origval + 1
4834 && s[-1] == '\\'
4835 && s[-2] != ',')
4836 || (s == origval + 1
4837 && s[-1] == '\\'))
4838
Bram Moolenaar071d4272004-06-13 20:20:40 +00004839 ++bs;
4840 else
4841 bs = 0;
4842 }
4843
4844 /* do not add if already there */
4845 if ((adding || prepending) && *s)
4846 {
4847 prepending = FALSE;
4848 adding = FALSE;
4849 STRCPY(newval, origval);
4850 }
4851 }
4852
4853 /* concatenate the two strings; add a ',' if
4854 * needed */
4855 if (adding || prepending)
4856 {
4857 comma = ((flags & P_COMMA) && *origval != NUL
4858 && *newval != NUL);
4859 if (adding)
4860 {
4861 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004862 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004863 if (comma && i > 1
4864 && (flags & P_ONECOMMA) == P_ONECOMMA
4865 && origval[i - 1] == ','
4866 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004867 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004868 mch_memmove(newval + i + comma, newval,
4869 STRLEN(newval) + 1);
4870 mch_memmove(newval, origval, (size_t)i);
4871 }
4872 else
4873 {
4874 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004875 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004876 }
4877 if (comma)
4878 newval[i] = ',';
4879 }
4880
4881 /* Remove newval[] from origval[]. (Note: "i" has
4882 * been set above and is used here). */
4883 if (removing)
4884 {
4885 STRCPY(newval, origval);
4886 if (*s)
4887 {
4888 /* may need to remove a comma */
4889 if (flags & P_COMMA)
4890 {
4891 if (s == origval)
4892 {
4893 /* include comma after string */
4894 if (s[i] == ',')
4895 ++i;
4896 }
4897 else
4898 {
4899 /* include comma before string */
4900 --s;
4901 ++i;
4902 }
4903 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004904 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004905 }
4906 }
4907
4908 if (flags & P_FLAGLIST)
4909 {
4910 /* Remove flags that appear twice. */
4911 for (s = newval; *s; ++s)
4912 if ((!(flags & P_COMMA) || *s != ',')
4913 && vim_strchr(s + 1, *s) != NULL)
4914 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004915 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004916 --s;
4917 }
4918 }
4919
4920 if (save_arg != NULL) /* number for 'whichwrap' */
4921 arg = save_arg;
4922 new_value_alloced = TRUE;
4923 }
4924
4925 /* Set the new value. */
4926 *(char_u **)(varp) = newval;
4927
Bram Moolenaar53744302015-07-17 17:38:22 +02004928#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004929 if (!starting
4930# ifdef FEAT_CRYPT
4931 && options[opt_idx].indir != PV_KEY
4932# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004933 && origval != NULL)
4934 /* origval may be freed by
4935 * did_set_string_option(), make a copy. */
4936 saved_origval = vim_strsave(origval);
4937#endif
4938
Bram Moolenaar071d4272004-06-13 20:20:40 +00004939 /* Handle side effects, and set the global value for
4940 * ":set" on local options. */
4941 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4942 new_value_alloced, oldval, errbuf, opt_flags);
4943
4944 /* If error detected, print the error message. */
4945 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004946 {
4947#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4948 vim_free(saved_origval);
4949#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004950 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004951 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004952#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4953 if (saved_origval != NULL)
4954 {
4955 char_u buf_type[7];
4956
4957 sprintf((char *)buf_type, "%s",
4958 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004959 set_vim_var_string(VV_OPTION_NEW,
4960 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004961 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4962 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4963 apply_autocmds(EVENT_OPTIONSET,
4964 (char_u *)options[opt_idx].fullname,
4965 NULL, FALSE, NULL);
4966 reset_v_option_vars();
4967 vim_free(saved_origval);
4968 }
4969#endif
4970
Bram Moolenaar071d4272004-06-13 20:20:40 +00004971 }
4972 else /* key code option */
4973 {
4974 char_u *p;
4975
4976 if (nextchar == '&')
4977 {
4978 if (add_termcap_entry(key_name, TRUE) == FAIL)
4979 errmsg = (char_u *)N_("E522: Not found in termcap");
4980 }
4981 else
4982 {
4983 ++arg; /* jump to after the '=' or ':' */
4984 for (p = arg; *p && !vim_iswhite(*p); ++p)
4985 if (*p == '\\' && p[1] != NUL)
4986 ++p;
4987 nextchar = *p;
4988 *p = NUL;
4989 add_termcode(key_name, arg, FALSE);
4990 *p = nextchar;
4991 }
4992 if (full_screen)
4993 ttest(FALSE);
4994 redraw_all_later(CLEAR);
4995 }
4996 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004997
Bram Moolenaar071d4272004-06-13 20:20:40 +00004998 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004999 did_set_option(opt_idx, opt_flags,
5000 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005001 }
5002
5003skip:
5004 /*
5005 * Advance to next argument.
5006 * - skip until a blank found, taking care of backslashes
5007 * - skip blanks
5008 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5009 */
5010 for (i = 0; i < 2 ; ++i)
5011 {
5012 while (*arg != NUL && !vim_iswhite(*arg))
5013 if (*arg++ == '\\' && *arg != NUL)
5014 ++arg;
5015 arg = skipwhite(arg);
5016 if (*arg != '=')
5017 break;
5018 }
5019 }
5020
5021 if (errmsg != NULL)
5022 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005023 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005024 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005025 if (i + (arg - startarg) < IOSIZE)
5026 {
5027 /* append the argument with the error */
5028 STRCAT(IObuff, ": ");
5029 mch_memmove(IObuff + i, startarg, (arg - startarg));
5030 IObuff[i + (arg - startarg)] = NUL;
5031 }
5032 /* make sure all characters are printable */
5033 trans_characters(IObuff, IOSIZE);
5034
5035 ++no_wait_return; /* wait_return done later */
5036 emsg(IObuff); /* show error highlighted */
5037 --no_wait_return;
5038
5039 return FAIL;
5040 }
5041
5042 arg = skipwhite(arg);
5043 }
5044
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005045theend:
5046 if (silent_mode && did_show)
5047 {
5048 /* After displaying option values in silent mode. */
5049 silent_mode = FALSE;
5050 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5051 msg_putchar('\n');
5052 cursor_on(); /* msg_start() switches it off */
5053 out_flush();
5054 silent_mode = TRUE;
5055 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5056 }
5057
Bram Moolenaar071d4272004-06-13 20:20:40 +00005058 return OK;
5059}
5060
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005061/*
5062 * Call this when an option has been given a new value through a user command.
5063 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5064 */
5065 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005066did_set_option(
5067 int opt_idx,
5068 int opt_flags, /* possibly with OPT_MODELINE */
5069 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005070{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005071 long_u *p;
5072
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005073 options[opt_idx].flags |= P_WAS_SET;
5074
5075 /* When an option is set in the sandbox, from a modeline or in secure mode
5076 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005077 * flag. */
5078 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005079 if (secure
5080#ifdef HAVE_SANDBOX
5081 || sandbox != 0
5082#endif
5083 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005084 *p = *p | P_INSECURE;
5085 else if (new_value)
5086 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005087}
5088
Bram Moolenaar071d4272004-06-13 20:20:40 +00005089 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005090illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005091{
5092 if (errbuf == NULL)
5093 return (char_u *)"";
5094 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005095 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005096 return errbuf;
5097}
5098
5099/*
5100 * Convert a key name or string into a key value.
5101 * Used for 'wildchar' and 'cedit' options.
5102 */
5103 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005104string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005105{
5106 if (*arg == '<')
5107 return find_key_option(arg + 1);
5108 if (*arg == '^')
5109 return Ctrl_chr(arg[1]);
5110 return *arg;
5111}
5112
5113#ifdef FEAT_CMDWIN
5114/*
5115 * Check value of 'cedit' and set cedit_key.
5116 * Returns NULL if value is OK, error message otherwise.
5117 */
5118 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005119check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120{
5121 int n;
5122
5123 if (*p_cedit == NUL)
5124 cedit_key = -1;
5125 else
5126 {
5127 n = string_to_key(p_cedit);
5128 if (vim_isprintc(n))
5129 return e_invarg;
5130 cedit_key = n;
5131 }
5132 return NULL;
5133}
5134#endif
5135
5136#ifdef FEAT_TITLE
5137/*
5138 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5139 * maketitle() to create and display it.
5140 * When switching the title or icon off, call mch_restore_title() to get
5141 * the old value back.
5142 */
5143 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005144did_set_title(
5145 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005146{
5147 if (starting != NO_SCREEN
5148#ifdef FEAT_GUI
5149 && !gui.starting
5150#endif
5151 )
5152 {
5153 maketitle();
5154 if (icon)
5155 {
5156 if (!p_icon)
5157 mch_restore_title(2);
5158 }
5159 else
5160 {
5161 if (!p_title)
5162 mch_restore_title(1);
5163 }
5164 }
5165}
5166#endif
5167
5168/*
5169 * set_options_bin - called when 'bin' changes value.
5170 */
5171 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005172set_options_bin(
5173 int oldval,
5174 int newval,
5175 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005176{
5177 /*
5178 * The option values that are changed when 'bin' changes are
5179 * copied when 'bin is set and restored when 'bin' is reset.
5180 */
5181 if (newval)
5182 {
5183 if (!oldval) /* switched on */
5184 {
5185 if (!(opt_flags & OPT_GLOBAL))
5186 {
5187 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5188 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5189 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5190 curbuf->b_p_et_nobin = curbuf->b_p_et;
5191 }
5192 if (!(opt_flags & OPT_LOCAL))
5193 {
5194 p_tw_nobin = p_tw;
5195 p_wm_nobin = p_wm;
5196 p_ml_nobin = p_ml;
5197 p_et_nobin = p_et;
5198 }
5199 }
5200
5201 if (!(opt_flags & OPT_GLOBAL))
5202 {
5203 curbuf->b_p_tw = 0; /* no automatic line wrap */
5204 curbuf->b_p_wm = 0; /* no automatic line wrap */
5205 curbuf->b_p_ml = 0; /* no modelines */
5206 curbuf->b_p_et = 0; /* no expandtab */
5207 }
5208 if (!(opt_flags & OPT_LOCAL))
5209 {
5210 p_tw = 0;
5211 p_wm = 0;
5212 p_ml = FALSE;
5213 p_et = FALSE;
5214 p_bin = TRUE; /* needed when called for the "-b" argument */
5215 }
5216 }
5217 else if (oldval) /* switched off */
5218 {
5219 if (!(opt_flags & OPT_GLOBAL))
5220 {
5221 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5222 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5223 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5224 curbuf->b_p_et = curbuf->b_p_et_nobin;
5225 }
5226 if (!(opt_flags & OPT_LOCAL))
5227 {
5228 p_tw = p_tw_nobin;
5229 p_wm = p_wm_nobin;
5230 p_ml = p_ml_nobin;
5231 p_et = p_et_nobin;
5232 }
5233 }
5234}
5235
5236#ifdef FEAT_VIMINFO
5237/*
5238 * Find the parameter represented by the given character (eg ', :, ", or /),
5239 * and return its associated value in the 'viminfo' string.
5240 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005241 * If the parameter is not specified in the string or there is no following
5242 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005243 */
5244 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005245get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005246{
5247 char_u *p;
5248
5249 p = find_viminfo_parameter(type);
5250 if (p != NULL && VIM_ISDIGIT(*p))
5251 return atoi((char *)p);
5252 return -1;
5253}
5254
5255/*
5256 * Find the parameter represented by the given character (eg ''', ':', '"', or
5257 * '/') in the 'viminfo' option and return a pointer to the string after it.
5258 * Return NULL if the parameter is not specified in the string.
5259 */
5260 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005261find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005262{
5263 char_u *p;
5264
5265 for (p = p_viminfo; *p; ++p)
5266 {
5267 if (*p == type)
5268 return p + 1;
5269 if (*p == 'n') /* 'n' is always the last one */
5270 break;
5271 p = vim_strchr(p, ','); /* skip until next ',' */
5272 if (p == NULL) /* hit the end without finding parameter */
5273 break;
5274 }
5275 return NULL;
5276}
5277#endif
5278
5279/*
5280 * Expand environment variables for some string options.
5281 * These string options cannot be indirect!
5282 * If "val" is NULL expand the current value of the option.
5283 * Return pointer to NameBuff, or NULL when not expanded.
5284 */
5285 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005286option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005287{
5288 /* if option doesn't need expansion nothing to do */
5289 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5290 return NULL;
5291
5292 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5293 * expand_env() would truncate the string. */
5294 if (val != NULL && STRLEN(val) > MAXPATHL)
5295 return NULL;
5296
5297 if (val == NULL)
5298 val = *(char_u **)options[opt_idx].var;
5299
5300 /*
5301 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5302 * Escape spaces when expanding 'tags', they are used to separate file
5303 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005304 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005305 */
5306 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005307 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005308#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005309 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5310#endif
5311 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5313 return NULL;
5314
5315 return NameBuff;
5316}
5317
5318/*
5319 * After setting various option values: recompute variables that depend on
5320 * option values.
5321 */
5322 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005323didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005324{
5325 /* initialize the table for 'iskeyword' et.al. */
5326 (void)init_chartab();
5327
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005328#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005329 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005331 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005332 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333#ifdef FEAT_SESSION
5334 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5335 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5336#endif
5337#ifdef FEAT_FOLDING
5338 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5339#endif
5340 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005341 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005342#ifdef FEAT_VIRTUALEDIT
5343 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5344#endif
5345#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5346 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5347#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005348#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005349 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005350 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005351 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005352 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5355 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5356#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005357#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5359#endif
5360#ifdef FEAT_CMDWIN
5361 /* set cedit_key */
5362 (void)check_cedit();
5363#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005364#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005365 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005366#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005367#ifdef FEAT_LINEBREAK
5368 /* initialize the table for 'breakat'. */
5369 fill_breakat_flags();
5370#endif
5371
5372}
5373
5374/*
5375 * More side effects of setting options.
5376 */
5377 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005378didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005379{
5380 /* Initialize the highlight_attr[] table. */
5381 (void)highlight_changed();
5382
5383 /* Parse default for 'wildmode' */
5384 check_opt_wim();
5385
5386 (void)set_chars_option(&p_lcs);
5387#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5388 /* Parse default for 'fillchars'. */
5389 (void)set_chars_option(&p_fcs);
5390#endif
5391
5392#ifdef FEAT_CLIPBOARD
5393 /* Parse default for 'clipboard' */
5394 (void)check_clipboard_option();
5395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005396}
5397
5398/*
5399 * Check for string options that are NULL (normally only termcap options).
5400 */
5401 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005402check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005403{
5404 int opt_idx;
5405
5406 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5407 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5408 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5409}
5410
5411/*
5412 * Check string options in a buffer for NULL value.
5413 */
5414 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005415check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005416{
5417#if defined(FEAT_QUICKFIX)
5418 check_string_option(&buf->b_p_bh);
5419 check_string_option(&buf->b_p_bt);
5420#endif
5421#ifdef FEAT_MBYTE
5422 check_string_option(&buf->b_p_fenc);
5423#endif
5424 check_string_option(&buf->b_p_ff);
5425#ifdef FEAT_FIND_ID
5426 check_string_option(&buf->b_p_def);
5427 check_string_option(&buf->b_p_inc);
5428# ifdef FEAT_EVAL
5429 check_string_option(&buf->b_p_inex);
5430# endif
5431#endif
5432#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5433 check_string_option(&buf->b_p_inde);
5434 check_string_option(&buf->b_p_indk);
5435#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005436#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5437 check_string_option(&buf->b_p_bexpr);
5438#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005439#if defined(FEAT_CRYPT)
5440 check_string_option(&buf->b_p_cm);
5441#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005442#if defined(FEAT_EVAL)
5443 check_string_option(&buf->b_p_fex);
5444#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005445#ifdef FEAT_CRYPT
5446 check_string_option(&buf->b_p_key);
5447#endif
5448 check_string_option(&buf->b_p_kp);
5449 check_string_option(&buf->b_p_mps);
5450 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005451 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005452 check_string_option(&buf->b_p_isk);
5453#ifdef FEAT_COMMENTS
5454 check_string_option(&buf->b_p_com);
5455#endif
5456#ifdef FEAT_FOLDING
5457 check_string_option(&buf->b_p_cms);
5458#endif
5459 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005460#ifdef FEAT_TEXTOBJ
5461 check_string_option(&buf->b_p_qe);
5462#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463#ifdef FEAT_SYN_HL
5464 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005465 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005466#endif
5467#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005468 check_string_option(&buf->b_s.b_p_spc);
5469 check_string_option(&buf->b_s.b_p_spf);
5470 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005471#endif
5472#ifdef FEAT_SEARCHPATH
5473 check_string_option(&buf->b_p_sua);
5474#endif
5475#ifdef FEAT_CINDENT
5476 check_string_option(&buf->b_p_cink);
5477 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005478 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005479#endif
5480#ifdef FEAT_AUTOCMD
5481 check_string_option(&buf->b_p_ft);
5482#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005483#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5484 check_string_option(&buf->b_p_cinw);
5485#endif
5486#ifdef FEAT_INS_EXPAND
5487 check_string_option(&buf->b_p_cpt);
5488#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005489#ifdef FEAT_COMPL_FUNC
5490 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005491 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005492#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005493#ifdef FEAT_KEYMAP
5494 check_string_option(&buf->b_p_keymap);
5495#endif
5496#ifdef FEAT_QUICKFIX
5497 check_string_option(&buf->b_p_gp);
5498 check_string_option(&buf->b_p_mp);
5499 check_string_option(&buf->b_p_efm);
5500#endif
5501 check_string_option(&buf->b_p_ep);
5502 check_string_option(&buf->b_p_path);
5503 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005504 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005505#ifdef FEAT_INS_EXPAND
5506 check_string_option(&buf->b_p_dict);
5507 check_string_option(&buf->b_p_tsr);
5508#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005509#ifdef FEAT_LISP
5510 check_string_option(&buf->b_p_lw);
5511#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005512 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513}
5514
5515/*
5516 * Free the string allocated for an option.
5517 * Checks for the string being empty_option. This may happen if we're out of
5518 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5519 * check_options().
5520 * Does NOT check for P_ALLOCED flag!
5521 */
5522 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005523free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005524{
5525 if (p != empty_option)
5526 vim_free(p);
5527}
5528
5529 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005530clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005531{
5532 if (*pp != empty_option)
5533 vim_free(*pp);
5534 *pp = empty_option;
5535}
5536
5537 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005538check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539{
5540 if (*pp == NULL)
5541 *pp = empty_option;
5542}
5543
5544/*
5545 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5546 */
5547 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005548set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549{
5550 int opt_idx;
5551
5552 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5553 if (options[opt_idx].var == (char_u *)p)
5554 {
5555 options[opt_idx].flags |= P_ALLOCED;
5556 return;
5557 }
5558 return; /* cannot happen: didn't find it! */
5559}
5560
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005561#if defined(FEAT_EVAL) || defined(PROTO)
5562/*
5563 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5564 * Return FALSE when it wasn't.
5565 * Return -1 for an unknown option.
5566 */
5567 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005568was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005569{
5570 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005571 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005572
5573 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005574 {
5575 flagp = insecure_flag(idx, opt_flags);
5576 return (*flagp & P_INSECURE) != 0;
5577 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005578 EMSG2(_(e_intern2), "was_set_insecurely()");
5579 return -1;
5580}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005581
5582/*
5583 * Get a pointer to the flags used for the P_INSECURE flag of option
5584 * "opt_idx". For some local options a local flags field is used.
5585 */
5586 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005587insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005588{
5589 if (opt_flags & OPT_LOCAL)
5590 switch ((int)options[opt_idx].indir)
5591 {
5592#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005593 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005594#endif
5595#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005596# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005597 case PV_FDE: return &curwin->w_p_fde_flags;
5598 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005599# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005600# ifdef FEAT_BEVAL
5601 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5602# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005603# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005604 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005605# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005606 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005607# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005608 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005609# endif
5610#endif
5611 }
5612
5613 /* Nothing special, return global flags field. */
5614 return &options[opt_idx].flags;
5615}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005616#endif
5617
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005618#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005619static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005620
5621/*
5622 * Redraw the window title and/or tab page text later.
5623 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005624static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005625{
5626 need_maketitle = TRUE;
5627# ifdef FEAT_WINDOWS
5628 redraw_tabline = TRUE;
5629# endif
5630}
5631#endif
5632
Bram Moolenaar071d4272004-06-13 20:20:40 +00005633/*
5634 * Set a string option to a new value (without checking the effect).
5635 * The string is copied into allocated memory.
5636 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005637 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005638 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639 */
5640 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005641set_string_option_direct(
5642 char_u *name,
5643 int opt_idx,
5644 char_u *val,
5645 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5646 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005647{
5648 char_u *s;
5649 char_u **varp;
5650 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005651 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652
Bram Moolenaar89d40322006-08-29 15:30:07 +00005653 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005655 idx = findoption(name);
5656 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005657 {
5658 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005659 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005660 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662 }
5663
Bram Moolenaar89d40322006-08-29 15:30:07 +00005664 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665 return;
5666
5667 s = vim_strsave(val);
5668 if (s != NULL)
5669 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005670 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005672 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673 free_string_option(*varp);
5674 *varp = s;
5675
5676 /* For buffer/window local option may also set the global value. */
5677 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005678 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005679
Bram Moolenaar89d40322006-08-29 15:30:07 +00005680 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681
5682 /* When setting both values of a global option with a local value,
5683 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005684 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685 {
5686 free_string_option(*varp);
5687 *varp = empty_option;
5688 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005689# ifdef FEAT_EVAL
5690 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005691 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005692 set_sid == 0 ? current_SID : set_sid);
5693# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694 }
5695}
5696
5697/*
5698 * Set global value for string option when it's a local option.
5699 */
5700 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005701set_string_option_global(
5702 int opt_idx, /* option index */
5703 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704{
5705 char_u **p, *s;
5706
5707 /* the global value is always allocated */
5708 if (options[opt_idx].var == VAR_WIN)
5709 p = (char_u **)GLOBAL_WO(varp);
5710 else
5711 p = (char_u **)options[opt_idx].var;
5712 if (options[opt_idx].indir != PV_NONE
5713 && p != varp
5714 && (s = vim_strsave(*varp)) != NULL)
5715 {
5716 free_string_option(*p);
5717 *p = s;
5718 }
5719}
5720
5721/*
5722 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005723 *
5724 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005726 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005727set_string_option(
5728 int opt_idx,
5729 char_u *value,
5730 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731{
5732 char_u *s;
5733 char_u **varp;
5734 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005735#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5736 char_u *saved_oldval = NULL;
5737#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005738 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739
5740 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005741 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742
5743 s = vim_strsave(value);
5744 if (s != NULL)
5745 {
5746 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5747 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005748 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005749 ? OPT_GLOBAL : OPT_LOCAL)
5750 : opt_flags);
5751 oldval = *varp;
5752 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005753
5754#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005755 if (!starting
5756# ifdef FEAT_CRYPT
5757 && options[opt_idx].indir != PV_KEY
5758# endif
5759 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005760 saved_oldval = vim_strsave(oldval);
5761#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005762 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5763 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005764 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005765
5766 /* call autocomamnd after handling side effects */
5767#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5768 if (saved_oldval != NULL)
5769 {
5770 char_u buf_type[7];
5771 sprintf((char *)buf_type, "%s",
5772 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005773 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5774 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005775 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5776 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5777 reset_v_option_vars();
5778 vim_free(saved_oldval);
5779 }
5780#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005781 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005782 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783}
5784
5785/*
5786 * Handle string options that need some action to perform when changed.
5787 * Returns NULL for success, or an error message for an error.
5788 */
5789 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005790did_set_string_option(
5791 int opt_idx, /* index in options[] table */
5792 char_u **varp, /* pointer to the option variable */
5793 int new_value_alloced, /* new value was allocated */
5794 char_u *oldval, /* previous value of the option */
5795 char_u *errbuf, /* buffer for errors, or NULL */
5796 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005797{
5798 char_u *errmsg = NULL;
5799 char_u *s, *p;
5800 int did_chartab = FALSE;
5801 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005802 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005803#ifdef FEAT_GUI
5804 /* set when changing an option that only requires a redraw in the GUI */
5805 int redraw_gui_only = FALSE;
5806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005807
5808 /* Get the global option to compare with, otherwise we would have to check
5809 * two values for all local options. */
5810 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5811
5812 /* Disallow changing some options from secure mode */
5813 if ((secure
5814#ifdef HAVE_SANDBOX
5815 || sandbox != 0
5816#endif
5817 ) && (options[opt_idx].flags & P_SECURE))
5818 {
5819 errmsg = e_secure;
5820 }
5821
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005822 /* Check for a "normal" file name in some options. Disallow a path
5823 * separator (slash and/or backslash), wildcards and characters that are
5824 * often illegal in a file name. */
5825 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005826 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005827 {
5828 errmsg = e_invarg;
5829 }
5830
Bram Moolenaar071d4272004-06-13 20:20:40 +00005831 /* 'term' */
5832 else if (varp == &T_NAME)
5833 {
5834 if (T_NAME[0] == NUL)
5835 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5836#ifdef FEAT_GUI
5837 if (gui.in_use)
5838 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5839 else if (term_is_gui(T_NAME))
5840 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5841#endif
5842 else if (set_termname(T_NAME) == FAIL)
5843 errmsg = (char_u *)N_("E522: Not found in termcap");
5844 else
5845 /* Screen colors may have changed. */
5846 redraw_later_clear();
5847 }
5848
5849 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005850 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005851 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005852 char_u *bkc = p_bkc;
5853 unsigned int *flags = &bkc_flags;
5854
5855 if (opt_flags & OPT_LOCAL)
5856 {
5857 bkc = curbuf->b_p_bkc;
5858 flags = &curbuf->b_bkc_flags;
5859 }
5860
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005861 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5862 /* make the local value empty: use the global value */
5863 *flags = 0;
5864 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005866 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5867 errmsg = e_invarg;
5868 if ((((int)*flags & BKC_AUTO) != 0)
5869 + (((int)*flags & BKC_YES) != 0)
5870 + (((int)*flags & BKC_NO) != 0) != 1)
5871 {
5872 /* Must have exactly one of "auto", "yes" and "no". */
5873 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5874 errmsg = e_invarg;
5875 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876 }
5877 }
5878
5879 /* 'backupext' and 'patchmode' */
5880 else if (varp == &p_bex || varp == &p_pm)
5881 {
5882 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5883 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5884 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5885 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005886#ifdef FEAT_LINEBREAK
5887 /* 'breakindentopt' */
5888 else if (varp == &curwin->w_p_briopt)
5889 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005890 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005891 errmsg = e_invarg;
5892 }
5893#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894
5895 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005896 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005898 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899 */
5900 else if ( varp == &p_isi
5901 || varp == &(curbuf->b_p_isk)
5902 || varp == &p_isp
5903 || varp == &p_isf)
5904 {
5905 if (init_chartab() == FAIL)
5906 {
5907 did_chartab = TRUE; /* need to restore it below */
5908 errmsg = e_invarg; /* error in value */
5909 }
5910 }
5911
5912 /* 'helpfile' */
5913 else if (varp == &p_hf)
5914 {
5915 /* May compute new values for $VIM and $VIMRUNTIME */
5916 if (didset_vim)
5917 {
5918 vim_setenv((char_u *)"VIM", (char_u *)"");
5919 didset_vim = FALSE;
5920 }
5921 if (didset_vimruntime)
5922 {
5923 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5924 didset_vimruntime = FALSE;
5925 }
5926 }
5927
Bram Moolenaar1a384422010-07-14 19:53:30 +02005928#ifdef FEAT_SYN_HL
5929 /* 'colorcolumn' */
5930 else if (varp == &curwin->w_p_cc)
5931 errmsg = check_colorcolumn(curwin);
5932#endif
5933
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934#ifdef FEAT_MULTI_LANG
5935 /* 'helplang' */
5936 else if (varp == &p_hlg)
5937 {
5938 /* Check for "", "ab", "ab,cd", etc. */
5939 for (s = p_hlg; *s != NUL; s += 3)
5940 {
5941 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5942 {
5943 errmsg = e_invarg;
5944 break;
5945 }
5946 if (s[2] == NUL)
5947 break;
5948 }
5949 }
5950#endif
5951
5952 /* 'highlight' */
5953 else if (varp == &p_hl)
5954 {
5955 if (highlight_changed() == FAIL)
5956 errmsg = e_invarg; /* invalid flags */
5957 }
5958
5959 /* 'nrformats' */
5960 else if (gvarp == &p_nf)
5961 {
5962 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5963 errmsg = e_invarg;
5964 }
5965
5966#ifdef FEAT_SESSION
5967 /* 'sessionoptions' */
5968 else if (varp == &p_ssop)
5969 {
5970 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5971 errmsg = e_invarg;
5972 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5973 {
5974 /* Don't allow both "sesdir" and "curdir". */
5975 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5976 errmsg = e_invarg;
5977 }
5978 }
5979 /* 'viewoptions' */
5980 else if (varp == &p_vop)
5981 {
5982 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5983 errmsg = e_invarg;
5984 }
5985#endif
5986
5987 /* 'scrollopt' */
5988#ifdef FEAT_SCROLLBIND
5989 else if (varp == &p_sbo)
5990 {
5991 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5992 errmsg = e_invarg;
5993 }
5994#endif
5995
5996 /* 'ambiwidth' */
5997#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01005998 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999 {
6000 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6001 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006002 else if (set_chars_option(&p_lcs) != NULL)
6003 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6004# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6005 else if (set_chars_option(&p_fcs) != NULL)
6006 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6007# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006008 }
6009#endif
6010
6011 /* 'background' */
6012 else if (varp == &p_bg)
6013 {
6014 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6015 {
6016#ifdef FEAT_EVAL
6017 int dark = (*p_bg == 'd');
6018#endif
6019
6020 init_highlight(FALSE, FALSE);
6021
6022#ifdef FEAT_EVAL
6023 if (dark != (*p_bg == 'd')
6024 && get_var_value((char_u *)"g:colors_name") != NULL)
6025 {
6026 /* The color scheme must have set 'background' back to another
6027 * value, that's not what we want here. Disable the color
6028 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006029 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006030 free_string_option(p_bg);
6031 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6032 check_string_option(&p_bg);
6033 init_highlight(FALSE, FALSE);
6034 }
6035#endif
6036 }
6037 else
6038 errmsg = e_invarg;
6039 }
6040
6041 /* 'wildmode' */
6042 else if (varp == &p_wim)
6043 {
6044 if (check_opt_wim() == FAIL)
6045 errmsg = e_invarg;
6046 }
6047
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006048#ifdef FEAT_CMDL_COMPL
6049 /* 'wildoptions' */
6050 else if (varp == &p_wop)
6051 {
6052 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6053 errmsg = e_invarg;
6054 }
6055#endif
6056
Bram Moolenaar071d4272004-06-13 20:20:40 +00006057#ifdef FEAT_WAK
6058 /* 'winaltkeys' */
6059 else if (varp == &p_wak)
6060 {
6061 if (*p_wak == NUL
6062 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6063 errmsg = e_invarg;
6064# ifdef FEAT_MENU
6065# ifdef FEAT_GUI_MOTIF
6066 else if (gui.in_use)
6067 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6068# else
6069# ifdef FEAT_GUI_GTK
6070 else if (gui.in_use)
6071 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6072# endif
6073# endif
6074# endif
6075 }
6076#endif
6077
6078#ifdef FEAT_AUTOCMD
6079 /* 'eventignore' */
6080 else if (varp == &p_ei)
6081 {
6082 if (check_ei() == FAIL)
6083 errmsg = e_invarg;
6084 }
6085#endif
6086
6087#ifdef FEAT_MBYTE
6088 /* 'encoding' and 'fileencoding' */
6089 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6090 {
6091 if (gvarp == &p_fenc)
6092 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006093 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006094 errmsg = e_modifiable;
6095 else if (vim_strchr(*varp, ',') != NULL)
6096 /* No comma allowed in 'fileencoding'; catches confusing it
6097 * with 'fileencodings'. */
6098 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006100 {
6101# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006102 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006103 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006104# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006105 /* Add 'fileencoding' to the swap file. */
6106 ml_setflags(curbuf);
6107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006108 }
6109 if (errmsg == NULL)
6110 {
6111 /* canonize the value, so that STRCMP() can be used on it */
6112 p = enc_canonize(*varp);
6113 if (p != NULL)
6114 {
6115 vim_free(*varp);
6116 *varp = p;
6117 }
6118 if (varp == &p_enc)
6119 {
6120 errmsg = mb_init();
6121# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006122 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123# endif
6124 }
6125 }
6126
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006127# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6129 {
6130 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6131 if (STRCMP(p_tenc, "utf-8") != 0)
6132 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6133 }
6134# endif
6135
6136 if (errmsg == NULL)
6137 {
6138# ifdef FEAT_KEYMAP
6139 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6140 * (with another encoding). */
6141 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6142 (void)keymap_init();
6143# endif
6144
6145 /* When 'termencoding' is not empty and 'encoding' changes or when
6146 * 'termencoding' changes, need to setup for keyboard input and
6147 * display output conversion. */
6148 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6149 {
6150 convert_setup(&input_conv, p_tenc, p_enc);
6151 convert_setup(&output_conv, p_enc, p_tenc);
6152 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006153
6154# if defined(WIN3264) && defined(FEAT_MBYTE)
6155 /* $HOME may have characters in active code page. */
6156 if (varp == &p_enc)
6157 init_homedir();
6158# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006159 }
6160 }
6161#endif
6162
6163#if defined(FEAT_POSTSCRIPT)
6164 else if (varp == &p_penc)
6165 {
6166 /* Canonize printencoding if VIM standard one */
6167 p = enc_canonize(p_penc);
6168 if (p != NULL)
6169 {
6170 vim_free(p_penc);
6171 p_penc = p;
6172 }
6173 else
6174 {
6175 /* Ensure lower case and '-' for '_' */
6176 for (s = p_penc; *s != NUL; s++)
6177 {
6178 if (*s == '_')
6179 *s = '-';
6180 else
6181 *s = TOLOWER_ASC(*s);
6182 }
6183 }
6184 }
6185#endif
6186
Bram Moolenaar9372a112005-12-06 19:59:18 +00006187#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188 else if (varp == &p_imak)
6189 {
6190 if (gui.in_use && !im_xim_isvalid_imactivate())
6191 errmsg = e_invarg;
6192 }
6193#endif
6194
6195#ifdef FEAT_KEYMAP
6196 else if (varp == &curbuf->b_p_keymap)
6197 {
6198 /* load or unload key mapping tables */
6199 errmsg = keymap_init();
6200
Bram Moolenaarfab06232009-03-04 03:13:35 +00006201 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006203 if (*curbuf->b_p_keymap != NUL)
6204 {
6205 /* Installed a new keymap, switch on using it. */
6206 curbuf->b_p_iminsert = B_IMODE_LMAP;
6207 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6208 curbuf->b_p_imsearch = B_IMODE_LMAP;
6209 }
6210 else
6211 {
6212 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6213 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6214 curbuf->b_p_iminsert = B_IMODE_NONE;
6215 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6216 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6217 }
6218 if ((opt_flags & OPT_LOCAL) == 0)
6219 {
6220 set_iminsert_global();
6221 set_imsearch_global();
6222 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006223# ifdef FEAT_WINDOWS
6224 status_redraw_curbuf();
6225# endif
6226 }
6227 }
6228#endif
6229
6230 /* 'fileformat' */
6231 else if (gvarp == &p_ff)
6232 {
6233 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6234 errmsg = e_modifiable;
6235 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6236 errmsg = e_invarg;
6237 else
6238 {
6239 /* may also change 'textmode' */
6240 if (get_fileformat(curbuf) == EOL_DOS)
6241 curbuf->b_p_tx = TRUE;
6242 else
6243 curbuf->b_p_tx = FALSE;
6244#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006245 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006246#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006247 /* update flag in swap file */
6248 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006249 /* Redraw needed when switching to/from "mac": a CR in the text
6250 * will be displayed differently. */
6251 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6252 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006253 }
6254 }
6255
6256 /* 'fileformats' */
6257 else if (varp == &p_ffs)
6258 {
6259 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6260 errmsg = e_invarg;
6261 else
6262 {
6263 /* also change 'textauto' */
6264 if (*p_ffs == NUL)
6265 p_ta = FALSE;
6266 else
6267 p_ta = TRUE;
6268 }
6269 }
6270
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006271#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006272 /* 'cryptkey' */
6273 else if (gvarp == &p_key)
6274 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006275# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276 /* Make sure the ":set" command doesn't show the new value in the
6277 * history. */
6278 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006279# endif
6280 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6281 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006282 ml_set_crypt_key(curbuf, oldval,
6283 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006284 }
6285
6286 else if (gvarp == &p_cm)
6287 {
6288 if (opt_flags & OPT_LOCAL)
6289 p = curbuf->b_p_cm;
6290 else
6291 p = p_cm;
6292 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6293 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006294 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006295 errmsg = e_invarg;
6296 else
6297 {
6298 /* When setting the global value to empty, make it "zip". */
6299 if (*p_cm == NUL)
6300 {
6301 if (new_value_alloced)
6302 free_string_option(p_cm);
6303 p_cm = vim_strsave((char_u *)"zip");
6304 new_value_alloced = TRUE;
6305 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006306 /* When using ":set cm=name" the local value is going to be empty.
6307 * Do that here, otherwise the crypt functions will still use the
6308 * local value. */
6309 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6310 {
6311 free_string_option(curbuf->b_p_cm);
6312 curbuf->b_p_cm = empty_option;
6313 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006314
6315 /* Need to update the swapfile when the effective method changed.
6316 * Set "s" to the effective old value, "p" to the effective new
6317 * method and compare. */
6318 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6319 s = p_cm; /* was previously using the global value */
6320 else
6321 s = oldval;
6322 if (*curbuf->b_p_cm == NUL)
6323 p = p_cm; /* is now using the global value */
6324 else
6325 p = curbuf->b_p_cm;
6326 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006327 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006328
6329 /* If the global value changes need to update the swapfile for all
6330 * buffers using that value. */
6331 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6332 {
6333 buf_T *buf;
6334
6335 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6336 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006337 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006338 }
6339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006340 }
6341#endif
6342
6343 /* 'matchpairs' */
6344 else if (gvarp == &p_mps)
6345 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006346#ifdef FEAT_MBYTE
6347 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006349 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006351 int x2 = -1;
6352 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006353
6354 if (*p != NUL)
6355 p += mb_ptr2len(p);
6356 if (*p != NUL)
6357 x2 = *p++;
6358 if (*p != NUL)
6359 {
6360 x3 = mb_ptr2char(p);
6361 p += mb_ptr2len(p);
6362 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006363 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006364 {
6365 errmsg = e_invarg;
6366 break;
6367 }
6368 if (*p == NUL)
6369 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006370 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006371 }
6372 else
6373#endif
6374 {
6375 /* Check for "x:y,x:y" */
6376 for (p = *varp; *p != NUL; p += 4)
6377 {
6378 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6379 {
6380 errmsg = e_invarg;
6381 break;
6382 }
6383 if (p[3] == NUL)
6384 break;
6385 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 }
6387 }
6388
6389#ifdef FEAT_COMMENTS
6390 /* 'comments' */
6391 else if (gvarp == &p_com)
6392 {
6393 for (s = *varp; *s; )
6394 {
6395 while (*s && *s != ':')
6396 {
6397 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6398 && !VIM_ISDIGIT(*s) && *s != '-')
6399 {
6400 errmsg = illegal_char(errbuf, *s);
6401 break;
6402 }
6403 ++s;
6404 }
6405 if (*s++ == NUL)
6406 errmsg = (char_u *)N_("E524: Missing colon");
6407 else if (*s == ',' || *s == NUL)
6408 errmsg = (char_u *)N_("E525: Zero length string");
6409 if (errmsg != NULL)
6410 break;
6411 while (*s && *s != ',')
6412 {
6413 if (*s == '\\' && s[1] != NUL)
6414 ++s;
6415 ++s;
6416 }
6417 s = skip_to_option_part(s);
6418 }
6419 }
6420#endif
6421
6422 /* 'listchars' */
6423 else if (varp == &p_lcs)
6424 {
6425 errmsg = set_chars_option(varp);
6426 }
6427
6428#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6429 /* 'fillchars' */
6430 else if (varp == &p_fcs)
6431 {
6432 errmsg = set_chars_option(varp);
6433 }
6434#endif
6435
6436#ifdef FEAT_CMDWIN
6437 /* 'cedit' */
6438 else if (varp == &p_cedit)
6439 {
6440 errmsg = check_cedit();
6441 }
6442#endif
6443
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006444 /* 'verbosefile' */
6445 else if (varp == &p_vfile)
6446 {
6447 verbose_stop();
6448 if (*p_vfile != NUL && verbose_open() == FAIL)
6449 errmsg = e_invarg;
6450 }
6451
Bram Moolenaar071d4272004-06-13 20:20:40 +00006452#ifdef FEAT_VIMINFO
6453 /* 'viminfo' */
6454 else if (varp == &p_viminfo)
6455 {
6456 for (s = p_viminfo; *s;)
6457 {
6458 /* Check it's a valid character */
6459 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6460 {
6461 errmsg = illegal_char(errbuf, *s);
6462 break;
6463 }
6464 if (*s == 'n') /* name is always last one */
6465 {
6466 break;
6467 }
6468 else if (*s == 'r') /* skip until next ',' */
6469 {
6470 while (*++s && *s != ',')
6471 ;
6472 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006473 else if (*s == '%')
6474 {
6475 /* optional number */
6476 while (vim_isdigit(*++s))
6477 ;
6478 }
6479 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480 ++s; /* no extra chars */
6481 else /* must have a number */
6482 {
6483 while (vim_isdigit(*++s))
6484 ;
6485
6486 if (!VIM_ISDIGIT(*(s - 1)))
6487 {
6488 if (errbuf != NULL)
6489 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006490 sprintf((char *)errbuf,
6491 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492 transchar_byte(*(s - 1)));
6493 errmsg = errbuf;
6494 }
6495 else
6496 errmsg = (char_u *)"";
6497 break;
6498 }
6499 }
6500 if (*s == ',')
6501 ++s;
6502 else if (*s)
6503 {
6504 if (errbuf != NULL)
6505 errmsg = (char_u *)N_("E527: Missing comma");
6506 else
6507 errmsg = (char_u *)"";
6508 break;
6509 }
6510 }
6511 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6512 errmsg = (char_u *)N_("E528: Must specify a ' value");
6513 }
6514#endif /* FEAT_VIMINFO */
6515
6516 /* terminal options */
6517 else if (istermoption(&options[opt_idx]) && full_screen)
6518 {
6519 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6520 if (varp == &T_CCO)
6521 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006522 int colors = atoi((char *)T_CCO);
6523
6524 /* Only reinitialize colors if t_Co value has really changed to
6525 * avoid expensive reload of colorscheme if t_Co is set to the
6526 * same value multiple times. */
6527 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006528 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006529 t_colors = colors;
6530 if (t_colors <= 1)
6531 {
6532 if (new_value_alloced)
6533 vim_free(T_CCO);
6534 T_CCO = empty_option;
6535 }
6536 /* We now have a different color setup, initialize it again. */
6537 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006538 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006539 }
6540 ttest(FALSE);
6541 if (varp == &T_ME)
6542 {
6543 out_str(T_ME);
6544 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006545#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006546 /* Since t_me has been set, this probably means that the user
6547 * wants to use this as default colors. Need to reset default
6548 * background/foreground colors. */
6549 mch_set_normal_colors();
6550#endif
6551 }
6552 }
6553
6554#ifdef FEAT_LINEBREAK
6555 /* 'showbreak' */
6556 else if (varp == &p_sbr)
6557 {
6558 for (s = p_sbr; *s; )
6559 {
6560 if (ptr2cells(s) != 1)
6561 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006562 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563 }
6564 }
6565#endif
6566
6567#ifdef FEAT_GUI
6568 /* 'guifont' */
6569 else if (varp == &p_guifont)
6570 {
6571 if (gui.in_use)
6572 {
6573 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006574# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006575 /*
6576 * Put up a font dialog and let the user select a new value.
6577 * If this is cancelled go back to the old value but don't
6578 * give an error message.
6579 */
6580 if (STRCMP(p, "*") == 0)
6581 {
6582 p = gui_mch_font_dialog(oldval);
6583
6584 if (new_value_alloced)
6585 free_string_option(p_guifont);
6586
6587 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6588 new_value_alloced = TRUE;
6589 }
6590# endif
6591 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6592 {
6593# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6594 if (STRCMP(p_guifont, "*") == 0)
6595 {
6596 /* Dialog was cancelled: Keep the old value without giving
6597 * an error message. */
6598 if (new_value_alloced)
6599 free_string_option(p_guifont);
6600 p_guifont = vim_strsave(oldval);
6601 new_value_alloced = TRUE;
6602 }
6603 else
6604# endif
6605 errmsg = (char_u *)N_("E596: Invalid font(s)");
6606 }
6607 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006608 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006609 }
6610# ifdef FEAT_XFONTSET
6611 else if (varp == &p_guifontset)
6612 {
6613 if (STRCMP(p_guifontset, "*") == 0)
6614 errmsg = (char_u *)N_("E597: can't select fontset");
6615 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6616 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006617 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 }
6619# endif
6620# ifdef FEAT_MBYTE
6621 else if (varp == &p_guifontwide)
6622 {
6623 if (STRCMP(p_guifontwide, "*") == 0)
6624 errmsg = (char_u *)N_("E533: can't select wide font");
6625 else if (gui_get_wide_font() == FAIL)
6626 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006627 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006628 }
6629# endif
6630#endif
6631
6632#ifdef CURSOR_SHAPE
6633 /* 'guicursor' */
6634 else if (varp == &p_guicursor)
6635 errmsg = parse_shape_opt(SHAPE_CURSOR);
6636#endif
6637
6638#ifdef FEAT_MOUSESHAPE
6639 /* 'mouseshape' */
6640 else if (varp == &p_mouseshape)
6641 {
6642 errmsg = parse_shape_opt(SHAPE_MOUSE);
6643 update_mouseshape(-1);
6644 }
6645#endif
6646
6647#ifdef FEAT_PRINTER
6648 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006649 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006650# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006651 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006652 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006653# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654#endif
6655
6656#ifdef FEAT_LANGMAP
6657 /* 'langmap' */
6658 else if (varp == &p_langmap)
6659 langmap_set();
6660#endif
6661
6662#ifdef FEAT_LINEBREAK
6663 /* 'breakat' */
6664 else if (varp == &p_breakat)
6665 fill_breakat_flags();
6666#endif
6667
6668#ifdef FEAT_TITLE
6669 /* 'titlestring' and 'iconstring' */
6670 else if (varp == &p_titlestring || varp == &p_iconstring)
6671 {
6672# ifdef FEAT_STL_OPT
6673 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6674
6675 /* NULL => statusline syntax */
6676 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6677 stl_syntax |= flagval;
6678 else
6679 stl_syntax &= ~flagval;
6680# endif
6681 did_set_title(varp == &p_iconstring);
6682
6683 }
6684#endif
6685
6686#ifdef FEAT_GUI
6687 /* 'guioptions' */
6688 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006689 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006690 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006691 redraw_gui_only = TRUE;
6692 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006693#endif
6694
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006695#if defined(FEAT_GUI_TABLINE)
6696 /* 'guitablabel' */
6697 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006698 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006699 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006700 redraw_gui_only = TRUE;
6701 }
6702 /* 'guitabtooltip' */
6703 else if (varp == &p_gtt)
6704 {
6705 redraw_gui_only = TRUE;
6706 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006707#endif
6708
Bram Moolenaar071d4272004-06-13 20:20:40 +00006709#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6710 /* 'ttymouse' */
6711 else if (varp == &p_ttym)
6712 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006713 /* Switch the mouse off before changing the escape sequences used for
6714 * that. */
6715 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006716 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6717 errmsg = e_invarg;
6718 else
6719 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006720 if (termcap_active)
6721 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722 }
6723#endif
6724
Bram Moolenaar071d4272004-06-13 20:20:40 +00006725 /* 'selection' */
6726 else if (varp == &p_sel)
6727 {
6728 if (*p_sel == NUL
6729 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6730 errmsg = e_invarg;
6731 }
6732
6733 /* 'selectmode' */
6734 else if (varp == &p_slm)
6735 {
6736 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6737 errmsg = e_invarg;
6738 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006739
6740#ifdef FEAT_BROWSE
6741 /* 'browsedir' */
6742 else if (varp == &p_bsdir)
6743 {
6744 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6745 && !mch_isdir(p_bsdir))
6746 errmsg = e_invarg;
6747 }
6748#endif
6749
Bram Moolenaar071d4272004-06-13 20:20:40 +00006750 /* 'keymodel' */
6751 else if (varp == &p_km)
6752 {
6753 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6754 errmsg = e_invarg;
6755 else
6756 {
6757 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6758 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6759 }
6760 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006761
6762 /* 'mousemodel' */
6763 else if (varp == &p_mousem)
6764 {
6765 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6766 errmsg = e_invarg;
6767#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6768 else if (*p_mousem != *oldval)
6769 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6770 * to create or delete the popup menus. */
6771 gui_motif_update_mousemodel(root_menu);
6772#endif
6773 }
6774
6775 /* 'switchbuf' */
6776 else if (varp == &p_swb)
6777 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006778 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779 errmsg = e_invarg;
6780 }
6781
6782 /* 'debug' */
6783 else if (varp == &p_debug)
6784 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006785 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 errmsg = e_invarg;
6787 }
6788
6789 /* 'display' */
6790 else if (varp == &p_dy)
6791 {
6792 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6793 errmsg = e_invarg;
6794 else
6795 (void)init_chartab();
6796
6797 }
6798
6799#ifdef FEAT_VERTSPLIT
6800 /* 'eadirection' */
6801 else if (varp == &p_ead)
6802 {
6803 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6804 errmsg = e_invarg;
6805 }
6806#endif
6807
6808#ifdef FEAT_CLIPBOARD
6809 /* 'clipboard' */
6810 else if (varp == &p_cb)
6811 errmsg = check_clipboard_option();
6812#endif
6813
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006814#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006815 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6816 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006817 else if (varp == &(curwin->w_s->b_p_spl)
6818 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006819 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006820 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006821 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006822 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006823 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006824 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006825 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006826 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006827 /* 'spellsuggest' */
6828 else if (varp == &p_sps)
6829 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006830 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006831 errmsg = e_invarg;
6832 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006833 /* 'mkspellmem' */
6834 else if (varp == &p_msm)
6835 {
6836 if (spell_check_msm() != OK)
6837 errmsg = e_invarg;
6838 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006839#endif
6840
Bram Moolenaar071d4272004-06-13 20:20:40 +00006841#ifdef FEAT_QUICKFIX
6842 /* When 'bufhidden' is set, check for valid value. */
6843 else if (gvarp == &p_bh)
6844 {
6845 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6846 errmsg = e_invarg;
6847 }
6848
6849 /* When 'buftype' is set, check for valid value. */
6850 else if (gvarp == &p_bt)
6851 {
6852 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6853 errmsg = e_invarg;
6854 else
6855 {
6856# ifdef FEAT_WINDOWS
6857 if (curwin->w_status_height)
6858 {
6859 curwin->w_redr_status = TRUE;
6860 redraw_later(VALID);
6861 }
6862# endif
6863 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006864# ifdef FEAT_TITLE
6865 redraw_titles();
6866# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006867 }
6868 }
6869#endif
6870
6871#ifdef FEAT_STL_OPT
6872 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006873 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006874 {
6875 int wid;
6876
6877 if (varp == &p_ruf) /* reset ru_wid first */
6878 ru_wid = 0;
6879 s = *varp;
6880 if (varp == &p_ruf && *s == '%')
6881 {
6882 /* set ru_wid if 'ruf' starts with "%99(" */
6883 if (*++s == '-') /* ignore a '-' */
6884 s++;
6885 wid = getdigits(&s);
6886 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6887 ru_wid = wid;
6888 else
6889 errmsg = check_stl_option(p_ruf);
6890 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006891 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006892 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006894 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006895 comp_col();
6896 }
6897#endif
6898
6899#ifdef FEAT_INS_EXPAND
6900 /* check if it is a valid value for 'complete' -- Acevedo */
6901 else if (gvarp == &p_cpt)
6902 {
6903 for (s = *varp; *s;)
6904 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006905 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 s++;
6907 if (!*s)
6908 break;
6909 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6910 {
6911 errmsg = illegal_char(errbuf, *s);
6912 break;
6913 }
6914 if (*++s != NUL && *s != ',' && *s != ' ')
6915 {
6916 if (s[-1] == 'k' || s[-1] == 's')
6917 {
6918 /* skip optional filename after 'k' and 's' */
6919 while (*s && *s != ',' && *s != ' ')
6920 {
6921 if (*s == '\\')
6922 ++s;
6923 ++s;
6924 }
6925 }
6926 else
6927 {
6928 if (errbuf != NULL)
6929 {
6930 sprintf((char *)errbuf,
6931 _("E535: Illegal character after <%c>"),
6932 *--s);
6933 errmsg = errbuf;
6934 }
6935 else
6936 errmsg = (char_u *)"";
6937 break;
6938 }
6939 }
6940 }
6941 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006942
6943 /* 'completeopt' */
6944 else if (varp == &p_cot)
6945 {
6946 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6947 errmsg = e_invarg;
6948 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006949#endif /* FEAT_INS_EXPAND */
6950
6951
6952#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6953 else if (varp == &p_toolbar)
6954 {
6955 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6956 &toolbar_flags, TRUE) != OK)
6957 errmsg = e_invarg;
6958 else
6959 {
6960 out_flush();
6961 gui_mch_show_toolbar((toolbar_flags &
6962 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6963 }
6964 }
6965#endif
6966
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006967#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006968 /* 'toolbariconsize': GTK+ 2 only */
6969 else if (varp == &p_tbis)
6970 {
6971 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6972 errmsg = e_invarg;
6973 else
6974 {
6975 out_flush();
6976 gui_mch_show_toolbar((toolbar_flags &
6977 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6978 }
6979 }
6980#endif
6981
6982 /* 'pastetoggle': translate key codes like in a mapping */
6983 else if (varp == &p_pt)
6984 {
6985 if (*p_pt)
6986 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006987 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006988 if (p != NULL)
6989 {
6990 if (new_value_alloced)
6991 free_string_option(p_pt);
6992 p_pt = p;
6993 new_value_alloced = TRUE;
6994 }
6995 }
6996 }
6997
6998 /* 'backspace' */
6999 else if (varp == &p_bs)
7000 {
7001 if (VIM_ISDIGIT(*p_bs))
7002 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007003 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007004 errmsg = e_invarg;
7005 }
7006 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7007 errmsg = e_invarg;
7008 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007009 else if (varp == &p_bo)
7010 {
7011 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7012 errmsg = e_invarg;
7013 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007015 /* 'tagcase' */
7016 else if (gvarp == &p_tc)
7017 {
7018 unsigned int *flags;
7019
7020 if (opt_flags & OPT_LOCAL)
7021 {
7022 p = curbuf->b_p_tc;
7023 flags = &curbuf->b_tc_flags;
7024 }
7025 else
7026 {
7027 p = p_tc;
7028 flags = &tc_flags;
7029 }
7030
7031 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7032 /* make the local value empty: use the global value */
7033 *flags = 0;
7034 else if (*p == NUL
7035 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7036 errmsg = e_invarg;
7037 }
7038
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007039#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007040 /* 'casemap' */
7041 else if (varp == &p_cmp)
7042 {
7043 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7044 errmsg = e_invarg;
7045 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007046#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007047
7048#ifdef FEAT_DIFF
7049 /* 'diffopt' */
7050 else if (varp == &p_dip)
7051 {
7052 if (diffopt_changed() == FAIL)
7053 errmsg = e_invarg;
7054 }
7055#endif
7056
7057#ifdef FEAT_FOLDING
7058 /* 'foldmethod' */
7059 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7060 {
7061 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7062 || *curwin->w_p_fdm == NUL)
7063 errmsg = e_invarg;
7064 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007065 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007066 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007067 if (foldmethodIsDiff(curwin))
7068 newFoldLevel();
7069 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 }
7071# ifdef FEAT_EVAL
7072 /* 'foldexpr' */
7073 else if (varp == &curwin->w_p_fde)
7074 {
7075 if (foldmethodIsExpr(curwin))
7076 foldUpdateAll(curwin);
7077 }
7078# endif
7079 /* 'foldmarker' */
7080 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7081 {
7082 p = vim_strchr(*varp, ',');
7083 if (p == NULL)
7084 errmsg = (char_u *)N_("E536: comma required");
7085 else if (p == *varp || p[1] == NUL)
7086 errmsg = e_invarg;
7087 else if (foldmethodIsMarker(curwin))
7088 foldUpdateAll(curwin);
7089 }
7090 /* 'commentstring' */
7091 else if (gvarp == &p_cms)
7092 {
7093 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7094 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7095 }
7096 /* 'foldopen' */
7097 else if (varp == &p_fdo)
7098 {
7099 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7100 errmsg = e_invarg;
7101 }
7102 /* 'foldclose' */
7103 else if (varp == &p_fcl)
7104 {
7105 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7106 errmsg = e_invarg;
7107 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007108 /* 'foldignore' */
7109 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7110 {
7111 if (foldmethodIsIndent(curwin))
7112 foldUpdateAll(curwin);
7113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007114#endif
7115
7116#ifdef FEAT_VIRTUALEDIT
7117 /* 'virtualedit' */
7118 else if (varp == &p_ve)
7119 {
7120 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7121 errmsg = e_invarg;
7122 else if (STRCMP(p_ve, oldval) != 0)
7123 {
7124 /* Recompute cursor position in case the new 've' setting
7125 * changes something. */
7126 validate_virtcol();
7127 coladvance(curwin->w_virtcol);
7128 }
7129 }
7130#endif
7131
7132#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7133 else if (varp == &p_csqf)
7134 {
7135 if (p_csqf != NULL)
7136 {
7137 p = p_csqf;
7138 while (*p != NUL)
7139 {
7140 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7141 || p[1] == NUL
7142 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7143 || (p[2] != NUL && p[2] != ','))
7144 {
7145 errmsg = e_invarg;
7146 break;
7147 }
7148 else if (p[2] == NUL)
7149 break;
7150 else
7151 p += 3;
7152 }
7153 }
7154 }
7155#endif
7156
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007157#ifdef FEAT_CINDENT
7158 /* 'cinoptions' */
7159 else if (gvarp == &p_cino)
7160 {
7161 /* TODO: recognize errors */
7162 parse_cino(curbuf);
7163 }
7164#endif
7165
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007166#if defined(FEAT_RENDER_OPTIONS)
7167 else if (varp == &p_rop && gui.in_use)
7168 {
7169 if (!gui_mch_set_rendering_options(p_rop))
7170 errmsg = e_invarg;
7171 }
7172#endif
7173
Bram Moolenaar071d4272004-06-13 20:20:40 +00007174 /* Options that are a list of flags. */
7175 else
7176 {
7177 p = NULL;
7178 if (varp == &p_ww)
7179 p = (char_u *)WW_ALL;
7180 if (varp == &p_shm)
7181 p = (char_u *)SHM_ALL;
7182 else if (varp == &(p_cpo))
7183 p = (char_u *)CPO_ALL;
7184 else if (varp == &(curbuf->b_p_fo))
7185 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007186#ifdef FEAT_CONCEAL
7187 else if (varp == &curwin->w_p_cocu)
7188 p = (char_u *)COCU_ALL;
7189#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007190 else if (varp == &p_mouse)
7191 {
7192#ifdef FEAT_MOUSE
7193 p = (char_u *)MOUSE_ALL;
7194#else
7195 if (*p_mouse != NUL)
7196 errmsg = (char_u *)N_("E538: No mouse support");
7197#endif
7198 }
7199#if defined(FEAT_GUI)
7200 else if (varp == &p_go)
7201 p = (char_u *)GO_ALL;
7202#endif
7203 if (p != NULL)
7204 {
7205 for (s = *varp; *s; ++s)
7206 if (vim_strchr(p, *s) == NULL)
7207 {
7208 errmsg = illegal_char(errbuf, *s);
7209 break;
7210 }
7211 }
7212 }
7213
7214 /*
7215 * If error detected, restore the previous value.
7216 */
7217 if (errmsg != NULL)
7218 {
7219 if (new_value_alloced)
7220 free_string_option(*varp);
7221 *varp = oldval;
7222 /*
7223 * When resetting some values, need to act on it.
7224 */
7225 if (did_chartab)
7226 (void)init_chartab();
7227 if (varp == &p_hl)
7228 (void)highlight_changed();
7229 }
7230 else
7231 {
7232#ifdef FEAT_EVAL
7233 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007234 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007235#endif
7236 /*
7237 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007238 * Use "free_oldval", because recursiveness may change the flags under
7239 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007240 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007241 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242 free_string_option(oldval);
7243 if (new_value_alloced)
7244 options[opt_idx].flags |= P_ALLOCED;
7245 else
7246 options[opt_idx].flags &= ~P_ALLOCED;
7247
7248 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007249 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007250 {
7251 /* global option with local value set to use global value; free
7252 * the local value and make it empty */
7253 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7254 free_string_option(*(char_u **)p);
7255 *(char_u **)p = empty_option;
7256 }
7257
7258 /* May set global value for local option. */
7259 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7260 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007261
7262#ifdef FEAT_AUTOCMD
7263 /*
7264 * Trigger the autocommand only after setting the flags.
7265 */
7266# ifdef FEAT_SYN_HL
7267 /* When 'syntax' is set, load the syntax of that name */
7268 if (varp == &(curbuf->b_p_syn))
7269 {
7270 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7271 curbuf->b_fname, TRUE, curbuf);
7272 }
7273# endif
7274 else if (varp == &(curbuf->b_p_ft))
7275 {
7276 /* 'filetype' is set, trigger the FileType autocommand */
7277 did_filetype = TRUE;
7278 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7279 curbuf->b_fname, TRUE, curbuf);
7280 }
7281#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007282#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007283 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007284 {
7285 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007286 char_u *q = curwin->w_s->b_p_spl;
7287
7288 /* Skip the first name if it is "cjk". */
7289 if (STRNCMP(q, "cjk,", 4) == 0)
7290 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007291
7292 /*
7293 * Source the spell/LANG.vim in 'runtimepath'.
7294 * They could set 'spellcapcheck' depending on the language.
7295 * Use the first name in 'spelllang' up to '_region' or
7296 * '.encoding'.
7297 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007298 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007299 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7300 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007301 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007302 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007303 }
7304#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007305 }
7306
7307#ifdef FEAT_MOUSE
7308 if (varp == &p_mouse)
7309 {
7310# ifdef FEAT_MOUSE_TTY
7311 if (*p_mouse == NUL)
7312 mch_setmouse(FALSE); /* switch mouse off */
7313 else
7314# endif
7315 setmouse(); /* in case 'mouse' changed */
7316 }
7317#endif
7318
Bram Moolenaar913077c2012-03-28 19:59:04 +02007319 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007320 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007321 curwin->w_set_curswant = TRUE;
7322
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007323#ifdef FEAT_GUI
7324 /* check redraw when it's not a GUI option or the GUI is active. */
7325 if (!redraw_gui_only || gui.in_use)
7326#endif
7327 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007328
7329 return errmsg;
7330}
7331
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007332#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007333/*
7334 * Simple int comparison function for use with qsort()
7335 */
7336 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007337int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007338{
7339 return *(const int *)a - *(const int *)b;
7340}
7341
7342/*
7343 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7344 * Returns error message, NULL if it's OK.
7345 */
7346 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007347check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007348{
7349 char_u *s;
7350 int col;
7351 int count = 0;
7352 int color_cols[256];
7353 int i;
7354 int j = 0;
7355
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007356 if (wp->w_buffer == NULL)
7357 return NULL; /* buffer was closed */
7358
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007359 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007360 {
7361 if (*s == '-' || *s == '+')
7362 {
7363 /* -N and +N: add to 'textwidth' */
7364 col = (*s == '-') ? -1 : 1;
7365 ++s;
7366 if (!VIM_ISDIGIT(*s))
7367 return e_invarg;
7368 col = col * getdigits(&s);
7369 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007370 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007371 col += wp->w_buffer->b_p_tw;
7372 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007373 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007374 }
7375 else if (VIM_ISDIGIT(*s))
7376 col = getdigits(&s);
7377 else
7378 return e_invarg;
7379 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007380skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007381 if (*s == NUL)
7382 break;
7383 if (*s != ',')
7384 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007385 if (*++s == NUL)
7386 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007387 }
7388
7389 vim_free(wp->w_p_cc_cols);
7390 if (count == 0)
7391 wp->w_p_cc_cols = NULL;
7392 else
7393 {
7394 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7395 if (wp->w_p_cc_cols != NULL)
7396 {
7397 /* sort the columns for faster usage on screen redraw inside
7398 * win_line() */
7399 qsort(color_cols, count, sizeof(int), int_cmp);
7400
7401 for (i = 0; i < count; ++i)
7402 /* skip duplicates */
7403 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7404 wp->w_p_cc_cols[j++] = color_cols[i];
7405 wp->w_p_cc_cols[j] = -1; /* end marker */
7406 }
7407 }
7408
7409 return NULL; /* no error */
7410}
7411#endif
7412
Bram Moolenaar071d4272004-06-13 20:20:40 +00007413/*
7414 * Handle setting 'listchars' or 'fillchars'.
7415 * Returns error message, NULL if it's OK.
7416 */
7417 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007418set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007419{
7420 int round, i, len, entries;
7421 char_u *p, *s;
7422 int c1, c2 = 0;
7423 struct charstab
7424 {
7425 int *cp;
7426 char *name;
7427 };
7428#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7429 static struct charstab filltab[] =
7430 {
7431 {&fill_stl, "stl"},
7432 {&fill_stlnc, "stlnc"},
7433 {&fill_vert, "vert"},
7434 {&fill_fold, "fold"},
7435 {&fill_diff, "diff"},
7436 };
7437#endif
7438 static struct charstab lcstab[] =
7439 {
7440 {&lcs_eol, "eol"},
7441 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007442 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007444 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007445 {&lcs_tab2, "tab"},
7446 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007447#ifdef FEAT_CONCEAL
7448 {&lcs_conceal, "conceal"},
7449#else
7450 {NULL, "conceal"},
7451#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007452 };
7453 struct charstab *tab;
7454
7455#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7456 if (varp == &p_lcs)
7457#endif
7458 {
7459 tab = lcstab;
7460 entries = sizeof(lcstab) / sizeof(struct charstab);
7461 }
7462#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7463 else
7464 {
7465 tab = filltab;
7466 entries = sizeof(filltab) / sizeof(struct charstab);
7467 }
7468#endif
7469
7470 /* first round: check for valid value, second round: assign values */
7471 for (round = 0; round <= 1; ++round)
7472 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007473 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007474 {
7475 /* After checking that the value is valid: set defaults: space for
7476 * 'fillchars', NUL for 'listchars' */
7477 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007478 if (tab[i].cp != NULL)
7479 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007480 if (varp == &p_lcs)
7481 lcs_tab1 = NUL;
7482#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7483 else
7484 fill_diff = '-';
7485#endif
7486 }
7487 p = *varp;
7488 while (*p)
7489 {
7490 for (i = 0; i < entries; ++i)
7491 {
7492 len = (int)STRLEN(tab[i].name);
7493 if (STRNCMP(p, tab[i].name, len) == 0
7494 && p[len] == ':'
7495 && p[len + 1] != NUL)
7496 {
7497 s = p + len + 1;
7498#ifdef FEAT_MBYTE
7499 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007500 if (mb_char2cells(c1) > 1)
7501 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007502#else
7503 c1 = *s++;
7504#endif
7505 if (tab[i].cp == &lcs_tab2)
7506 {
7507 if (*s == NUL)
7508 continue;
7509#ifdef FEAT_MBYTE
7510 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007511 if (mb_char2cells(c2) > 1)
7512 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513#else
7514 c2 = *s++;
7515#endif
7516 }
7517 if (*s == ',' || *s == NUL)
7518 {
7519 if (round)
7520 {
7521 if (tab[i].cp == &lcs_tab2)
7522 {
7523 lcs_tab1 = c1;
7524 lcs_tab2 = c2;
7525 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007526 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 *(tab[i].cp) = c1;
7528
7529 }
7530 p = s;
7531 break;
7532 }
7533 }
7534 }
7535
7536 if (i == entries)
7537 return e_invarg;
7538 if (*p == ',')
7539 ++p;
7540 }
7541 }
7542
7543 return NULL; /* no error */
7544}
7545
7546#ifdef FEAT_STL_OPT
7547/*
7548 * Check validity of options with the 'statusline' format.
7549 * Return error message or NULL.
7550 */
7551 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007552check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007553{
7554 int itemcnt = 0;
7555 int groupdepth = 0;
7556 static char_u errbuf[80];
7557
7558 while (*s && itemcnt < STL_MAX_ITEM)
7559 {
7560 /* Check for valid keys after % sequences */
7561 while (*s && *s != '%')
7562 s++;
7563 if (!*s)
7564 break;
7565 s++;
7566 if (*s != '%' && *s != ')')
7567 ++itemcnt;
7568 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7569 {
7570 s++;
7571 continue;
7572 }
7573 if (*s == ')')
7574 {
7575 s++;
7576 if (--groupdepth < 0)
7577 break;
7578 continue;
7579 }
7580 if (*s == '-')
7581 s++;
7582 while (VIM_ISDIGIT(*s))
7583 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007584 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007585 continue;
7586 if (*s == '.')
7587 {
7588 s++;
7589 while (*s && VIM_ISDIGIT(*s))
7590 s++;
7591 }
7592 if (*s == '(')
7593 {
7594 groupdepth++;
7595 continue;
7596 }
7597 if (vim_strchr(STL_ALL, *s) == NULL)
7598 {
7599 return illegal_char(errbuf, *s);
7600 }
7601 if (*s == '{')
7602 {
7603 s++;
7604 while (*s != '}' && *s)
7605 s++;
7606 if (*s != '}')
7607 return (char_u *)N_("E540: Unclosed expression sequence");
7608 }
7609 }
7610 if (itemcnt >= STL_MAX_ITEM)
7611 return (char_u *)N_("E541: too many items");
7612 if (groupdepth != 0)
7613 return (char_u *)N_("E542: unbalanced groups");
7614 return NULL;
7615}
7616#endif
7617
7618#ifdef FEAT_CLIPBOARD
7619/*
7620 * Extract the items in the 'clipboard' option and set global values.
7621 */
7622 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007623check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007624{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007625 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007626 int new_autoselect_star = FALSE;
7627 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007628 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007629 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007630 regprog_T *new_exclude_prog = NULL;
7631 char_u *errmsg = NULL;
7632 char_u *p;
7633
7634 for (p = p_cb; *p != NUL; )
7635 {
7636 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7637 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007638 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007639 p += 7;
7640 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007641 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007642 && (p[11] == ',' || p[11] == NUL))
7643 {
7644 new_unnamed |= CLIP_UNNAMED_PLUS;
7645 p += 11;
7646 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007648 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007649 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007650 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007651 p += 10;
7652 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007653 else if (STRNCMP(p, "autoselectplus", 14) == 0
7654 && (p[14] == ',' || p[14] == NUL))
7655 {
7656 new_autoselect_plus = TRUE;
7657 p += 14;
7658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007660 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 {
7662 new_autoselectml = TRUE;
7663 p += 12;
7664 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007665 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7666 {
7667 new_html = TRUE;
7668 p += 4;
7669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7671 {
7672 p += 8;
7673 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7674 if (new_exclude_prog == NULL)
7675 errmsg = e_invarg;
7676 break;
7677 }
7678 else
7679 {
7680 errmsg = e_invarg;
7681 break;
7682 }
7683 if (*p == ',')
7684 ++p;
7685 }
7686 if (errmsg == NULL)
7687 {
7688 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007689 clip_autoselect_star = new_autoselect_star;
7690 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007692 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007693 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007694 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007695#ifdef FEAT_GUI_GTK
7696 if (gui.in_use)
7697 {
7698 gui_gtk_set_selection_targets();
7699 gui_gtk_set_dnd_targets();
7700 }
7701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007702 }
7703 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007704 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705
7706 return errmsg;
7707}
7708#endif
7709
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007710#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007711 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007712did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007713{
7714 char_u *errmsg = NULL;
7715 win_T *wp;
7716 int l;
7717
7718 if (is_spellfile)
7719 {
7720 l = (int)STRLEN(curwin->w_s->b_p_spf);
7721 if (l > 0 && (l < 4
7722 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7723 errmsg = e_invarg;
7724 }
7725
7726 if (errmsg == NULL)
7727 {
7728 FOR_ALL_WINDOWS(wp)
7729 if (wp->w_buffer == curbuf && wp->w_p_spell)
7730 {
7731 errmsg = did_set_spelllang(wp);
7732# ifdef FEAT_WINDOWS
7733 break;
7734# endif
7735 }
7736 }
7737 return errmsg;
7738}
7739
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007740/*
7741 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7742 * Return error message when failed, NULL when OK.
7743 */
7744 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007745compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007746{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007747 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007748 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007749
Bram Moolenaar860cae12010-06-05 23:22:07 +02007750 if (*synblock->b_p_spc == NUL)
7751 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007752 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007753 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007754 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007755 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007756 if (re != NULL)
7757 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007758 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007759 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007760 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007761 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007762 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007763 return e_invarg;
7764 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007765 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007766 }
7767
Bram Moolenaar473de612013-06-08 18:19:48 +02007768 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007769 return NULL;
7770}
7771#endif
7772
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007773#if defined(FEAT_EVAL) || defined(PROTO)
7774/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007775 * Set the scriptID for an option, taking care of setting the buffer- or
7776 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007777 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007778 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007779set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007780{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007781 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7782 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007783
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007784 /* Remember where the option was set. For local options need to do that
7785 * in the buffer or window structure. */
7786 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007787 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007788 if (both || (opt_flags & OPT_LOCAL))
7789 {
7790 if (indir & PV_BUF)
7791 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7792 else if (indir & PV_WIN)
7793 curwin->w_p_scriptID[indir & PV_MASK] = id;
7794 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007795}
7796#endif
7797
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798/*
7799 * Set the value of a boolean option, and take care of side effects.
7800 * Returns NULL for success, or an error message for an error.
7801 */
7802 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007803set_bool_option(
7804 int opt_idx, /* index in options[] table */
7805 char_u *varp, /* pointer to the option variable */
7806 int value, /* new value */
7807 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007808{
7809 int old_value = *(int *)varp;
7810
Bram Moolenaar071d4272004-06-13 20:20:40 +00007811 /* Disallow changing some options from secure mode */
7812 if ((secure
7813#ifdef HAVE_SANDBOX
7814 || sandbox != 0
7815#endif
7816 ) && (options[opt_idx].flags & P_SECURE))
7817 return e_secure;
7818
7819 *(int *)varp = value; /* set the new value */
7820#ifdef FEAT_EVAL
7821 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007822 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007823#endif
7824
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007825#ifdef FEAT_GUI
7826 need_mouse_correct = TRUE;
7827#endif
7828
Bram Moolenaar071d4272004-06-13 20:20:40 +00007829 /* May set global value for local option. */
7830 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7831 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7832
7833 /*
7834 * Handle side effects of changing a bool option.
7835 */
7836
7837 /* 'compatible' */
7838 if ((int *)varp == &p_cp)
7839 {
7840 compatible_set();
7841 }
7842
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007843#ifdef FEAT_PERSISTENT_UNDO
7844 /* 'undofile' */
7845 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7846 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007847 /* Only take action when the option was set. When reset we do not
7848 * delete the undo file, the option may be set again without making
7849 * any changes in between. */
7850 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007851 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007852 char_u hash[UNDO_HASH_SIZE];
7853 buf_T *save_curbuf = curbuf;
7854
7855 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007856 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007857 /* When 'undofile' is set globally: for every buffer, otherwise
7858 * only for the current buffer: Try to read in the undofile,
7859 * if one exists, the buffer wasn't changed and the buffer was
7860 * loaded */
7861 if ((curbuf == save_curbuf
7862 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7863 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7864 {
7865 u_compute_hash(hash);
7866 u_read_undo(NULL, hash, curbuf->b_fname);
7867 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007868 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007869 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007870 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007871 }
7872#endif
7873
Bram Moolenaar071d4272004-06-13 20:20:40 +00007874 else if ((int *)varp == &curbuf->b_p_ro)
7875 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007876 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7878 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007879
7880 /* when 'readonly' is set may give W10 again */
7881 if (curbuf->b_p_ro)
7882 curbuf->b_did_warn = FALSE;
7883
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007885 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886#endif
7887 }
7888
Bram Moolenaar9c449722010-07-20 18:44:27 +02007889#ifdef FEAT_GUI
7890 else if ((int *)varp == &p_mh)
7891 {
7892 if (!p_mh)
7893 gui_mch_mousehide(FALSE);
7894 }
7895#endif
7896
Bram Moolenaara539df02010-08-01 14:35:05 +02007897#ifdef FEAT_TITLE
7898 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007900 {
7901 redraw_titles();
7902 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 /* when 'endofline' is changed, redraw the window title */
7904 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007905 {
7906 redraw_titles();
7907 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007908 /* when 'fixeol' is changed, redraw the window title */
7909 else if ((int *)varp == &curbuf->b_p_fixeol)
7910 {
7911 redraw_titles();
7912 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007913# ifdef FEAT_MBYTE
7914 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007915 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007916 {
7917 redraw_titles();
7918 }
7919# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007920#endif
7921
7922 /* when 'bin' is set also set some other options */
7923 else if ((int *)varp == &curbuf->b_p_bin)
7924 {
7925 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7926#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007927 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928#endif
7929 }
7930
7931#ifdef FEAT_AUTOCMD
7932 /* when 'buflisted' changes, trigger autocommands */
7933 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7934 {
7935 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7936 NULL, NULL, TRUE, curbuf);
7937 }
7938#endif
7939
7940 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7941 else if ((int *)varp == &curbuf->b_p_swf)
7942 {
7943 if (curbuf->b_p_swf && p_uc)
7944 ml_open_file(curbuf); /* create the swap file */
7945 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007946 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7947 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007948 mf_close_file(curbuf, TRUE); /* remove the swap file */
7949 }
7950
7951 /* when 'terse' is set change 'shortmess' */
7952 else if ((int *)varp == &p_terse)
7953 {
7954 char_u *p;
7955
7956 p = vim_strchr(p_shm, SHM_SEARCH);
7957
7958 /* insert 's' in p_shm */
7959 if (p_terse && p == NULL)
7960 {
7961 STRCPY(IObuff, p_shm);
7962 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007963 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 }
7965 /* remove 's' from p_shm */
7966 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007967 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 }
7969
7970 /* when 'paste' is set or reset also change other options */
7971 else if ((int *)varp == &p_paste)
7972 {
7973 paste_option_changed();
7974 }
7975
7976 /* when 'insertmode' is set from an autocommand need to do work here */
7977 else if ((int *)varp == &p_im)
7978 {
7979 if (p_im)
7980 {
7981 if ((State & INSERT) == 0)
7982 need_start_insertmode = TRUE;
7983 stop_insert_mode = FALSE;
7984 }
7985 else
7986 {
7987 need_start_insertmode = FALSE;
7988 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007989 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990 clear_cmdline = TRUE; /* remove "(insert)" */
7991 restart_edit = 0;
7992 }
7993 }
7994
7995 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7996 else if ((int *)varp == &p_ic && p_hls)
7997 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007998 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 }
8000
8001#ifdef FEAT_SEARCH_EXTRA
8002 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8003 else if ((int *)varp == &p_hls)
8004 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008005 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008006 }
8007#endif
8008
8009#ifdef FEAT_SCROLLBIND
8010 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8011 * at the end of normal_cmd() */
8012 else if ((int *)varp == &curwin->w_p_scb)
8013 {
8014 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008015 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008017 curwin->w_scbind_pos = curwin->w_topline;
8018 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008019 }
8020#endif
8021
8022#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8023 /* There can be only one window with 'previewwindow' set. */
8024 else if ((int *)varp == &curwin->w_p_pvw)
8025 {
8026 if (curwin->w_p_pvw)
8027 {
8028 win_T *win;
8029
8030 for (win = firstwin; win != NULL; win = win->w_next)
8031 if (win->w_p_pvw && win != curwin)
8032 {
8033 curwin->w_p_pvw = FALSE;
8034 return (char_u *)N_("E590: A preview window already exists");
8035 }
8036 }
8037 }
8038#endif
8039
8040 /* when 'textmode' is set or reset also change 'fileformat' */
8041 else if ((int *)varp == &curbuf->b_p_tx)
8042 {
8043 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8044 }
8045
8046 /* when 'textauto' is set or reset also change 'fileformats' */
8047 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008048 set_string_option_direct((char_u *)"ffs", -1,
8049 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008050 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008051
8052 /*
8053 * When 'lisp' option changes include/exclude '-' in
8054 * keyword characters.
8055 */
8056#ifdef FEAT_LISP
8057 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8058 {
8059 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8060 }
8061#endif
8062
8063#ifdef FEAT_TITLE
8064 /* when 'title' changed, may need to change the title; same for 'icon' */
8065 else if ((int *)varp == &p_title)
8066 {
8067 did_set_title(FALSE);
8068 }
8069
8070 else if ((int *)varp == &p_icon)
8071 {
8072 did_set_title(TRUE);
8073 }
8074#endif
8075
8076 else if ((int *)varp == &curbuf->b_changed)
8077 {
8078 if (!value)
8079 save_file_ff(curbuf); /* Buffer is unchanged */
8080#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008081 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008082#endif
8083#ifdef FEAT_AUTOCMD
8084 modified_was_set = value;
8085#endif
8086 }
8087
8088#ifdef BACKSLASH_IN_FILENAME
8089 else if ((int *)varp == &p_ssl)
8090 {
8091 if (p_ssl)
8092 {
8093 psepc = '/';
8094 psepcN = '\\';
8095 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008096 }
8097 else
8098 {
8099 psepc = '\\';
8100 psepcN = '/';
8101 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008102 }
8103
8104 /* need to adjust the file name arguments and buffer names. */
8105 buflist_slash_adjust();
8106 alist_slash_adjust();
8107# ifdef FEAT_EVAL
8108 scriptnames_slash_adjust();
8109# endif
8110 }
8111#endif
8112
8113 /* If 'wrap' is set, set w_leftcol to zero. */
8114 else if ((int *)varp == &curwin->w_p_wrap)
8115 {
8116 if (curwin->w_p_wrap)
8117 curwin->w_leftcol = 0;
8118 }
8119
8120#ifdef FEAT_WINDOWS
8121 else if ((int *)varp == &p_ea)
8122 {
8123 if (p_ea && !old_value)
8124 win_equal(curwin, FALSE, 0);
8125 }
8126#endif
8127
8128 else if ((int *)varp == &p_wiv)
8129 {
8130 /*
8131 * When 'weirdinvert' changed, set/reset 't_xs'.
8132 * Then set 'weirdinvert' according to value of 't_xs'.
8133 */
8134 if (p_wiv && !old_value)
8135 T_XS = (char_u *)"y";
8136 else if (!p_wiv && old_value)
8137 T_XS = empty_option;
8138 p_wiv = (*T_XS != NUL);
8139 }
8140
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008141#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142 else if ((int *)varp == &p_beval)
8143 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008144 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008146 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 gui_mch_disable_beval_area(balloonEval);
8148 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008149#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008151#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008152 else if ((int *)varp == &p_acd)
8153 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008154 /* Change directories when the 'acd' option is set now. */
8155 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156 }
8157#endif
8158
8159#ifdef FEAT_DIFF
8160 /* 'diff' */
8161 else if ((int *)varp == &curwin->w_p_diff)
8162 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008163 /* May add or remove the buffer from the list of diff buffers. */
8164 diff_buf_adjust(curwin);
8165# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008166 if (foldmethodIsDiff(curwin))
8167 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008168# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 }
8170#endif
8171
8172#ifdef USE_IM_CONTROL
8173 /* 'imdisable' */
8174 else if ((int *)varp == &p_imdisable)
8175 {
8176 /* Only de-activate it here, it will be enabled when changing mode. */
8177 if (p_imdisable)
8178 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008179 else if (State & INSERT)
8180 /* When the option is set from an autocommand, it may need to take
8181 * effect right away. */
8182 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008183 }
8184#endif
8185
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008186#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008187 /* 'spell' */
8188 else if ((int *)varp == &curwin->w_p_spell)
8189 {
8190 if (curwin->w_p_spell)
8191 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008192 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008193 if (errmsg != NULL)
8194 EMSG(_(errmsg));
8195 }
8196 }
8197#endif
8198
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199#ifdef FEAT_FKMAP
8200 else if ((int *)varp == &p_altkeymap)
8201 {
8202 if (old_value != p_altkeymap)
8203 {
8204 if (!p_altkeymap)
8205 {
8206 p_hkmap = p_fkmap;
8207 p_fkmap = 0;
8208 }
8209 else
8210 {
8211 p_fkmap = p_hkmap;
8212 p_hkmap = 0;
8213 }
8214 (void)init_chartab();
8215 }
8216 }
8217
8218 /*
8219 * In case some second language keymapping options have changed, check
8220 * and correct the setting in a consistent way.
8221 */
8222
8223 /*
8224 * If hkmap or fkmap are set, reset Arabic keymapping.
8225 */
8226 if ((p_hkmap || p_fkmap) && p_altkeymap)
8227 {
8228 p_altkeymap = p_fkmap;
8229# ifdef FEAT_ARABIC
8230 curwin->w_p_arab = FALSE;
8231# endif
8232 (void)init_chartab();
8233 }
8234
8235 /*
8236 * If hkmap set, reset Farsi keymapping.
8237 */
8238 if (p_hkmap && p_altkeymap)
8239 {
8240 p_altkeymap = 0;
8241 p_fkmap = 0;
8242# ifdef FEAT_ARABIC
8243 curwin->w_p_arab = FALSE;
8244# endif
8245 (void)init_chartab();
8246 }
8247
8248 /*
8249 * If fkmap set, reset Hebrew keymapping.
8250 */
8251 if (p_fkmap && !p_altkeymap)
8252 {
8253 p_altkeymap = 1;
8254 p_hkmap = 0;
8255# ifdef FEAT_ARABIC
8256 curwin->w_p_arab = FALSE;
8257# endif
8258 (void)init_chartab();
8259 }
8260#endif
8261
8262#ifdef FEAT_ARABIC
8263 if ((int *)varp == &curwin->w_p_arab)
8264 {
8265 if (curwin->w_p_arab)
8266 {
8267 /*
8268 * 'arabic' is set, handle various sub-settings.
8269 */
8270 if (!p_tbidi)
8271 {
8272 /* set rightleft mode */
8273 if (!curwin->w_p_rl)
8274 {
8275 curwin->w_p_rl = TRUE;
8276 changed_window_setting();
8277 }
8278
8279 /* Enable Arabic shaping (major part of what Arabic requires) */
8280 if (!p_arshape)
8281 {
8282 p_arshape = TRUE;
8283 redraw_later_clear();
8284 }
8285 }
8286
8287 /* Arabic requires a utf-8 encoding, inform the user if its not
8288 * set. */
8289 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008290 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008291 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8292
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008293 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008294 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8295#ifdef FEAT_EVAL
8296 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8297#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008298 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008299
8300# ifdef FEAT_MBYTE
8301 /* set 'delcombine' */
8302 p_deco = TRUE;
8303# endif
8304
8305# ifdef FEAT_KEYMAP
8306 /* Force-set the necessary keymap for arabic */
8307 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8308 OPT_LOCAL);
8309# endif
8310# ifdef FEAT_FKMAP
8311 p_altkeymap = 0;
8312 p_hkmap = 0;
8313 p_fkmap = 0;
8314 (void)init_chartab();
8315# endif
8316 }
8317 else
8318 {
8319 /*
8320 * 'arabic' is reset, handle various sub-settings.
8321 */
8322 if (!p_tbidi)
8323 {
8324 /* reset rightleft mode */
8325 if (curwin->w_p_rl)
8326 {
8327 curwin->w_p_rl = FALSE;
8328 changed_window_setting();
8329 }
8330
8331 /* 'arabicshape' isn't reset, it is a global option and
8332 * another window may still need it "on". */
8333 }
8334
8335 /* 'delcombine' isn't reset, it is a global option and another
8336 * window may still want it "on". */
8337
8338# ifdef FEAT_KEYMAP
8339 /* Revert to the default keymap */
8340 curbuf->b_p_iminsert = B_IMODE_NONE;
8341 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8342# endif
8343 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008344 }
8345
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008346#endif
8347
Bram Moolenaar071d4272004-06-13 20:20:40 +00008348 /*
8349 * End of handling side effects for bool options.
8350 */
8351
Bram Moolenaar53744302015-07-17 17:38:22 +02008352 /* after handling side effects, call autocommand */
8353
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354 options[opt_idx].flags |= P_WAS_SET;
8355
Bram Moolenaar53744302015-07-17 17:38:22 +02008356#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8357 if (!starting)
8358 {
8359 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008360 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8361 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8362 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008363 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8364 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8365 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8366 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8367 reset_v_option_vars();
8368 }
8369#endif
8370
Bram Moolenaar071d4272004-06-13 20:20:40 +00008371 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008372 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008373 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008374 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375 check_redraw(options[opt_idx].flags);
8376
8377 return NULL;
8378}
8379
8380/*
8381 * Set the value of a number option, and take care of side effects.
8382 * Returns NULL for success, or an error message for an error.
8383 */
8384 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008385set_num_option(
8386 int opt_idx, /* index in options[] table */
8387 char_u *varp, /* pointer to the option variable */
8388 long value, /* new value */
8389 char_u *errbuf, /* buffer for error messages */
8390 size_t errbuflen, /* length of "errbuf" */
8391 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008392 OPT_MODELINE */
8393{
8394 char_u *errmsg = NULL;
8395 long old_value = *(long *)varp;
8396 long old_Rows = Rows; /* remember old Rows */
8397 long old_Columns = Columns; /* remember old Columns */
8398 long *pp = (long *)varp;
8399
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008400 /* Disallow changing some options from secure mode. */
8401 if ((secure
8402#ifdef HAVE_SANDBOX
8403 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008405 ) && (options[opt_idx].flags & P_SECURE))
8406 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407
8408 *pp = value;
8409#ifdef FEAT_EVAL
8410 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008411 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008413#ifdef FEAT_GUI
8414 need_mouse_correct = TRUE;
8415#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416
Bram Moolenaar14f24742012-08-08 18:01:05 +02008417 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418 {
8419 errmsg = e_positive;
8420 curbuf->b_p_sw = curbuf->b_p_ts;
8421 }
8422
8423 /*
8424 * Number options that need some action when changed
8425 */
8426#ifdef FEAT_WINDOWS
8427 if (pp == &p_wh || pp == &p_hh)
8428 {
8429 if (p_wh < 1)
8430 {
8431 errmsg = e_positive;
8432 p_wh = 1;
8433 }
8434 if (p_wmh > p_wh)
8435 {
8436 errmsg = e_winheight;
8437 p_wh = p_wmh;
8438 }
8439 if (p_hh < 0)
8440 {
8441 errmsg = e_positive;
8442 p_hh = 0;
8443 }
8444
8445 /* Change window height NOW */
8446 if (lastwin != firstwin)
8447 {
8448 if (pp == &p_wh && curwin->w_height < p_wh)
8449 win_setheight((int)p_wh);
8450 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8451 win_setheight((int)p_hh);
8452 }
8453 }
8454
8455 /* 'winminheight' */
8456 else if (pp == &p_wmh)
8457 {
8458 if (p_wmh < 0)
8459 {
8460 errmsg = e_positive;
8461 p_wmh = 0;
8462 }
8463 if (p_wmh > p_wh)
8464 {
8465 errmsg = e_winheight;
8466 p_wmh = p_wh;
8467 }
8468 win_setminheight();
8469 }
8470
8471# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008472 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 {
8474 if (p_wiw < 1)
8475 {
8476 errmsg = e_positive;
8477 p_wiw = 1;
8478 }
8479 if (p_wmw > p_wiw)
8480 {
8481 errmsg = e_winwidth;
8482 p_wiw = p_wmw;
8483 }
8484
8485 /* Change window width NOW */
8486 if (lastwin != firstwin && curwin->w_width < p_wiw)
8487 win_setwidth((int)p_wiw);
8488 }
8489
8490 /* 'winminwidth' */
8491 else if (pp == &p_wmw)
8492 {
8493 if (p_wmw < 0)
8494 {
8495 errmsg = e_positive;
8496 p_wmw = 0;
8497 }
8498 if (p_wmw > p_wiw)
8499 {
8500 errmsg = e_winwidth;
8501 p_wmw = p_wiw;
8502 }
8503 win_setminheight();
8504 }
8505# endif
8506
8507#endif
8508
8509#ifdef FEAT_WINDOWS
8510 /* (re)set last window status line */
8511 else if (pp == &p_ls)
8512 {
8513 last_status(FALSE);
8514 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008515
8516 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008517 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008518 {
8519 shell_new_rows(); /* recompute window positions and heights */
8520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521#endif
8522
8523#ifdef FEAT_GUI
8524 else if (pp == &p_linespace)
8525 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008526 /* Recompute gui.char_height and resize the Vim window to keep the
8527 * same number of lines. */
8528 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008529 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008530 }
8531#endif
8532
8533#ifdef FEAT_FOLDING
8534 /* 'foldlevel' */
8535 else if (pp == &curwin->w_p_fdl)
8536 {
8537 if (curwin->w_p_fdl < 0)
8538 curwin->w_p_fdl = 0;
8539 newFoldLevel();
8540 }
8541
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008542 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008543 else if (pp == &curwin->w_p_fml)
8544 {
8545 foldUpdateAll(curwin);
8546 }
8547
8548 /* 'foldnestmax' */
8549 else if (pp == &curwin->w_p_fdn)
8550 {
8551 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8552 foldUpdateAll(curwin);
8553 }
8554
8555 /* 'foldcolumn' */
8556 else if (pp == &curwin->w_p_fdc)
8557 {
8558 if (curwin->w_p_fdc < 0)
8559 {
8560 errmsg = e_positive;
8561 curwin->w_p_fdc = 0;
8562 }
8563 else if (curwin->w_p_fdc > 12)
8564 {
8565 errmsg = e_invarg;
8566 curwin->w_p_fdc = 12;
8567 }
8568 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008569#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008570
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008571#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008572 /* 'shiftwidth' or 'tabstop' */
8573 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8574 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008575# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576 if (foldmethodIsIndent(curwin))
8577 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008578# endif
8579# ifdef FEAT_CINDENT
8580 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8581 * parse 'cinoptions'. */
8582 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8583 parse_cino(curbuf);
8584# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008585 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008588#ifdef FEAT_MBYTE
8589 /* 'maxcombine' */
8590 else if (pp == &p_mco)
8591 {
8592 if (p_mco > MAX_MCO)
8593 p_mco = MAX_MCO;
8594 else if (p_mco < 0)
8595 p_mco = 0;
8596 screenclear(); /* will re-allocate the screen */
8597 }
8598#endif
8599
Bram Moolenaar071d4272004-06-13 20:20:40 +00008600 else if (pp == &curbuf->b_p_iminsert)
8601 {
8602 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8603 {
8604 errmsg = e_invarg;
8605 curbuf->b_p_iminsert = B_IMODE_NONE;
8606 }
8607 p_iminsert = curbuf->b_p_iminsert;
8608 if (termcap_active) /* don't do this in the alternate screen */
8609 showmode();
8610#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8611 /* Show/unshow value of 'keymap' in status lines. */
8612 status_redraw_curbuf();
8613#endif
8614 }
8615
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008616 else if (pp == &p_window)
8617 {
8618 if (p_window < 1)
8619 p_window = 1;
8620 else if (p_window >= Rows)
8621 p_window = Rows - 1;
8622 }
8623
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624 else if (pp == &curbuf->b_p_imsearch)
8625 {
8626 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8627 {
8628 errmsg = e_invarg;
8629 curbuf->b_p_imsearch = B_IMODE_NONE;
8630 }
8631 p_imsearch = curbuf->b_p_imsearch;
8632 }
8633
8634#ifdef FEAT_TITLE
8635 /* if 'titlelen' has changed, redraw the title */
8636 else if (pp == &p_titlelen)
8637 {
8638 if (p_titlelen < 0)
8639 {
8640 errmsg = e_positive;
8641 p_titlelen = 85;
8642 }
8643 if (starting != NO_SCREEN && old_value != p_titlelen)
8644 need_maketitle = TRUE;
8645 }
8646#endif
8647
8648 /* if p_ch changed value, change the command line height */
8649 else if (pp == &p_ch)
8650 {
8651 if (p_ch < 1)
8652 {
8653 errmsg = e_positive;
8654 p_ch = 1;
8655 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008656 if (p_ch > Rows - min_rows() + 1)
8657 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008658
8659 /* Only compute the new window layout when startup has been
8660 * completed. Otherwise the frame sizes may be wrong. */
8661 if (p_ch != old_value && full_screen
8662#ifdef FEAT_GUI
8663 && !gui.starting
8664#endif
8665 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008666 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008667 }
8668
8669 /* when 'updatecount' changes from zero to non-zero, open swap files */
8670 else if (pp == &p_uc)
8671 {
8672 if (p_uc < 0)
8673 {
8674 errmsg = e_positive;
8675 p_uc = 100;
8676 }
8677 if (p_uc && !old_value)
8678 ml_open_files();
8679 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008680#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008681 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008682 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008683 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008684 {
8685 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008686 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008687 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008688 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008689 {
8690 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008691 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008692 }
8693 }
8694#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008695#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008696 else if (pp == &p_mzq)
8697 mzvim_reset_timer();
8698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699
8700 /* sync undo before 'undolevels' changes */
8701 else if (pp == &p_ul)
8702 {
8703 /* use the old value, otherwise u_sync() may not work properly */
8704 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008705 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706 p_ul = value;
8707 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008708 else if (pp == &curbuf->b_p_ul)
8709 {
8710 /* use the old value, otherwise u_sync() may not work properly */
8711 curbuf->b_p_ul = old_value;
8712 u_sync(TRUE);
8713 curbuf->b_p_ul = value;
8714 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008715
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008716#ifdef FEAT_LINEBREAK
8717 /* 'numberwidth' must be positive */
8718 else if (pp == &curwin->w_p_nuw)
8719 {
8720 if (curwin->w_p_nuw < 1)
8721 {
8722 errmsg = e_positive;
8723 curwin->w_p_nuw = 1;
8724 }
8725 if (curwin->w_p_nuw > 10)
8726 {
8727 errmsg = e_invarg;
8728 curwin->w_p_nuw = 10;
8729 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008730 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008731 }
8732#endif
8733
Bram Moolenaar1a384422010-07-14 19:53:30 +02008734 else if (pp == &curbuf->b_p_tw)
8735 {
8736 if (curbuf->b_p_tw < 0)
8737 {
8738 errmsg = e_positive;
8739 curbuf->b_p_tw = 0;
8740 }
8741#ifdef FEAT_SYN_HL
8742# ifdef FEAT_WINDOWS
8743 {
8744 win_T *wp;
8745 tabpage_T *tp;
8746
8747 FOR_ALL_TAB_WINDOWS(tp, wp)
8748 check_colorcolumn(wp);
8749 }
8750# else
8751 check_colorcolumn(curwin);
8752# endif
8753#endif
8754 }
8755
Bram Moolenaar071d4272004-06-13 20:20:40 +00008756 /*
8757 * Check the bounds for numeric options here
8758 */
8759 if (Rows < min_rows() && full_screen)
8760 {
8761 if (errbuf != NULL)
8762 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008763 vim_snprintf((char *)errbuf, errbuflen,
8764 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765 errmsg = errbuf;
8766 }
8767 Rows = min_rows();
8768 }
8769 if (Columns < MIN_COLUMNS && full_screen)
8770 {
8771 if (errbuf != NULL)
8772 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008773 vim_snprintf((char *)errbuf, errbuflen,
8774 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008775 errmsg = errbuf;
8776 }
8777 Columns = MIN_COLUMNS;
8778 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008779 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781 /*
8782 * If the screen (shell) height has been changed, assume it is the
8783 * physical screenheight.
8784 */
8785 if (old_Rows != Rows || old_Columns != Columns)
8786 {
8787 /* Changing the screen size is not allowed while updating the screen. */
8788 if (updating_screen)
8789 *pp = old_value;
8790 else if (full_screen
8791#ifdef FEAT_GUI
8792 && !gui.starting
8793#endif
8794 )
8795 set_shellsize((int)Columns, (int)Rows, TRUE);
8796 else
8797 {
8798 /* Postpone the resizing; check the size and cmdline position for
8799 * messages. */
8800 check_shellsize();
8801 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8802 cmdline_row = Rows - p_ch;
8803 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008804 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008805 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806 }
8807
Bram Moolenaar071d4272004-06-13 20:20:40 +00008808 if (curbuf->b_p_ts <= 0)
8809 {
8810 errmsg = e_positive;
8811 curbuf->b_p_ts = 8;
8812 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813 if (p_tm < 0)
8814 {
8815 errmsg = e_positive;
8816 p_tm = 0;
8817 }
8818 if ((curwin->w_p_scr <= 0
8819 || (curwin->w_p_scr > curwin->w_height
8820 && curwin->w_height > 0))
8821 && full_screen)
8822 {
8823 if (pp == &(curwin->w_p_scr))
8824 {
8825 if (curwin->w_p_scr != 0)
8826 errmsg = e_scroll;
8827 win_comp_scroll(curwin);
8828 }
8829 /* If 'scroll' became invalid because of a side effect silently adjust
8830 * it. */
8831 else if (curwin->w_p_scr <= 0)
8832 curwin->w_p_scr = 1;
8833 else /* curwin->w_p_scr > curwin->w_height */
8834 curwin->w_p_scr = curwin->w_height;
8835 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008836 if (p_hi < 0)
8837 {
8838 errmsg = e_positive;
8839 p_hi = 0;
8840 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008841 else if (p_hi > 10000)
8842 {
8843 errmsg = e_invarg;
8844 p_hi = 10000;
8845 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008846 if (p_re < 0 || p_re > 2)
8847 {
8848 errmsg = e_invarg;
8849 p_re = 0;
8850 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 if (p_report < 0)
8852 {
8853 errmsg = e_positive;
8854 p_report = 1;
8855 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008856 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 {
8858 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8859 p_sj = Rows / 2;
8860 else
8861 {
8862 errmsg = e_scroll;
8863 p_sj = 1;
8864 }
8865 }
8866 if (p_so < 0 && full_screen)
8867 {
8868 errmsg = e_scroll;
8869 p_so = 0;
8870 }
8871 if (p_siso < 0 && full_screen)
8872 {
8873 errmsg = e_positive;
8874 p_siso = 0;
8875 }
8876#ifdef FEAT_CMDWIN
8877 if (p_cwh < 1)
8878 {
8879 errmsg = e_positive;
8880 p_cwh = 1;
8881 }
8882#endif
8883 if (p_ut < 0)
8884 {
8885 errmsg = e_positive;
8886 p_ut = 2000;
8887 }
8888 if (p_ss < 0)
8889 {
8890 errmsg = e_positive;
8891 p_ss = 0;
8892 }
8893
8894 /* May set global value for local option. */
8895 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8896 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8897
8898 options[opt_idx].flags |= P_WAS_SET;
8899
Bram Moolenaar53744302015-07-17 17:38:22 +02008900#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8901 if (!starting && errmsg == NULL)
8902 {
8903 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008904 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8905 vim_snprintf((char *)buf_new, 10, "%ld", value);
8906 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008907 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8908 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8909 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8910 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8911 reset_v_option_vars();
8912 }
8913#endif
8914
Bram Moolenaar071d4272004-06-13 20:20:40 +00008915 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008916 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008917 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008918 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919 check_redraw(options[opt_idx].flags);
8920
8921 return errmsg;
8922}
8923
8924/*
8925 * Called after an option changed: check if something needs to be redrawn.
8926 */
8927 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008928check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929{
8930 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008931 int doclear = (flags & P_RCLR) == P_RCLR;
8932 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008933
8934#ifdef FEAT_WINDOWS
8935 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8936 status_redraw_all();
8937#endif
8938
8939 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8940 changed_window_setting();
8941 if (flags & P_RBUF)
8942 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008943 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944 redraw_all_later(CLEAR);
8945 else if (all)
8946 redraw_all_later(NOT_VALID);
8947}
8948
8949/*
8950 * Find index for option 'arg'.
8951 * Return -1 if not found.
8952 */
8953 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008954findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008955{
8956 int opt_idx;
8957 char *s, *p;
8958 static short quick_tab[27] = {0, 0}; /* quick access table */
8959 int is_term_opt;
8960
8961 /*
8962 * For first call: Initialize the quick-access table.
8963 * It contains the index for the first option that starts with a certain
8964 * letter. There are 26 letters, plus the first "t_" option.
8965 */
8966 if (quick_tab[1] == 0)
8967 {
8968 p = options[0].fullname;
8969 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8970 {
8971 if (s[0] != p[0])
8972 {
8973 if (s[0] == 't' && s[1] == '_')
8974 quick_tab[26] = opt_idx;
8975 else
8976 quick_tab[CharOrdLow(s[0])] = opt_idx;
8977 }
8978 p = s;
8979 }
8980 }
8981
8982 /*
8983 * Check for name starting with an illegal character.
8984 */
8985#ifdef EBCDIC
8986 if (!islower(arg[0]))
8987#else
8988 if (arg[0] < 'a' || arg[0] > 'z')
8989#endif
8990 return -1;
8991
8992 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8993 if (is_term_opt)
8994 opt_idx = quick_tab[26];
8995 else
8996 opt_idx = quick_tab[CharOrdLow(arg[0])];
8997 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8998 {
8999 if (STRCMP(arg, s) == 0) /* match full name */
9000 break;
9001 }
9002 if (s == NULL && !is_term_opt)
9003 {
9004 opt_idx = quick_tab[CharOrdLow(arg[0])];
9005 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9006 {
9007 s = options[opt_idx].shortname;
9008 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9009 break;
9010 s = NULL;
9011 }
9012 }
9013 if (s == NULL)
9014 opt_idx = -1;
9015 return opt_idx;
9016}
9017
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009018#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009019/*
9020 * Get the value for an option.
9021 *
9022 * Returns:
9023 * Number or Toggle option: 1, *numval gets value.
9024 * String option: 0, *stringval gets allocated string.
9025 * Hidden Number or Toggle option: -1.
9026 * hidden String option: -2.
9027 * unknown option: -3.
9028 */
9029 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009030get_option_value(
9031 char_u *name,
9032 long *numval,
9033 char_u **stringval, /* NULL when only checking existence */
9034 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009035{
9036 int opt_idx;
9037 char_u *varp;
9038
9039 opt_idx = findoption(name);
9040 if (opt_idx < 0) /* unknown option */
9041 return -3;
9042
9043 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9044
9045 if (options[opt_idx].flags & P_STRING)
9046 {
9047 if (varp == NULL) /* hidden option */
9048 return -2;
9049 if (stringval != NULL)
9050 {
9051#ifdef FEAT_CRYPT
9052 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009053 if ((char_u **)varp == &curbuf->b_p_key
9054 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009055 *stringval = vim_strsave((char_u *)"*****");
9056 else
9057#endif
9058 *stringval = vim_strsave(*(char_u **)(varp));
9059 }
9060 return 0;
9061 }
9062
9063 if (varp == NULL) /* hidden option */
9064 return -1;
9065 if (options[opt_idx].flags & P_NUM)
9066 *numval = *(long *)varp;
9067 else
9068 {
9069 /* Special case: 'modified' is b_changed, but we also want to consider
9070 * it set when 'ff' or 'fenc' changed. */
9071 if ((int *)varp == &curbuf->b_changed)
9072 *numval = curbufIsChanged();
9073 else
9074 *numval = *(int *)varp;
9075 }
9076 return 1;
9077}
9078#endif
9079
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009080#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009081/*
9082 * Returns the option attributes and its value. Unlike the above function it
9083 * will return either global value or local value of the option depending on
9084 * what was requested, but it will never return global value if it was
9085 * requested to return local one and vice versa. Neither it will return
9086 * buffer-local value if it was requested to return window-local one.
9087 *
9088 * Pretends that option is absent if it is not present in the requested scope
9089 * (i.e. has no global, window-local or buffer-local value depending on
9090 * opt_type). Uses
9091 *
9092 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009093 * 0 hidden or unknown option, also option that does not have requested
9094 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009095 * see SOPT_* in vim.h for other flags
9096 *
9097 * Possible opt_type values: see SREQ_* in vim.h
9098 */
9099 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009100get_option_value_strict(
9101 char_u *name,
9102 long *numval,
9103 char_u **stringval, /* NULL when only obtaining attributes */
9104 int opt_type,
9105 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009106{
9107 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009108 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009109 struct vimoption *p;
9110 int r = 0;
9111
9112 opt_idx = findoption(name);
9113 if (opt_idx < 0)
9114 return 0;
9115
9116 p = &(options[opt_idx]);
9117
9118 /* Hidden option */
9119 if (p->var == NULL)
9120 return 0;
9121
9122 if (p->flags & P_BOOL)
9123 r |= SOPT_BOOL;
9124 else if (p->flags & P_NUM)
9125 r |= SOPT_NUM;
9126 else if (p->flags & P_STRING)
9127 r |= SOPT_STRING;
9128
9129 if (p->indir == PV_NONE)
9130 {
9131 if (opt_type == SREQ_GLOBAL)
9132 r |= SOPT_GLOBAL;
9133 else
9134 return 0; /* Did not request global-only option */
9135 }
9136 else
9137 {
9138 if (p->indir & PV_BOTH)
9139 r |= SOPT_GLOBAL;
9140 else if (opt_type == SREQ_GLOBAL)
9141 return 0; /* Requested global option */
9142
9143 if (p->indir & PV_WIN)
9144 {
9145 if (opt_type == SREQ_BUF)
9146 return 0; /* Did not request window-local option */
9147 else
9148 r |= SOPT_WIN;
9149 }
9150 else if (p->indir & PV_BUF)
9151 {
9152 if (opt_type == SREQ_WIN)
9153 return 0; /* Did not request buffer-local option */
9154 else
9155 r |= SOPT_BUF;
9156 }
9157 }
9158
9159 if (stringval == NULL)
9160 return r;
9161
9162 if (opt_type == SREQ_GLOBAL)
9163 varp = p->var;
9164 else
9165 {
9166 if (opt_type == SREQ_BUF)
9167 {
9168 /* Special case: 'modified' is b_changed, but we also want to
9169 * consider it set when 'ff' or 'fenc' changed. */
9170 if (p->indir == PV_MOD)
9171 {
9172 *numval = bufIsChanged((buf_T *) from);
9173 varp = NULL;
9174 }
9175#ifdef FEAT_CRYPT
9176 else if (p->indir == PV_KEY)
9177 {
9178 /* never return the value of the crypt key */
9179 *stringval = NULL;
9180 varp = NULL;
9181 }
9182#endif
9183 else
9184 {
9185 aco_save_T aco;
9186 aucmd_prepbuf(&aco, (buf_T *) from);
9187 varp = get_varp(p);
9188 aucmd_restbuf(&aco);
9189 }
9190 }
9191 else if (opt_type == SREQ_WIN)
9192 {
9193 win_T *save_curwin;
9194 save_curwin = curwin;
9195 curwin = (win_T *) from;
9196 curbuf = curwin->w_buffer;
9197 varp = get_varp(p);
9198 curwin = save_curwin;
9199 curbuf = curwin->w_buffer;
9200 }
9201 if (varp == p->var)
9202 return (r | SOPT_UNSET);
9203 }
9204
9205 if (varp != NULL)
9206 {
9207 if (p->flags & P_STRING)
9208 *stringval = vim_strsave(*(char_u **)(varp));
9209 else if (p->flags & P_NUM)
9210 *numval = *(long *) varp;
9211 else
9212 *numval = *(int *)varp;
9213 }
9214
9215 return r;
9216}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009217
9218/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009219 * Iterate over options. First argument is a pointer to a pointer to a
9220 * structure inside options[] array, second is option type like in the above
9221 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009222 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009223 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009224 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009225 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009226 * first argument to NULL.
9227 *
9228 * Returns full option name for current option on each call.
9229 */
9230 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009231option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009232{
9233 struct vimoption *ret = NULL;
9234 do
9235 {
9236 if (*option == NULL)
9237 *option = (void *) options;
9238 else if (((struct vimoption *) (*option))->fullname == NULL)
9239 {
9240 *option = NULL;
9241 return NULL;
9242 }
9243 else
9244 *option = (void *) (((struct vimoption *) (*option)) + 1);
9245
9246 ret = ((struct vimoption *) (*option));
9247
9248 /* Hidden option */
9249 if (ret->var == NULL)
9250 {
9251 ret = NULL;
9252 continue;
9253 }
9254
9255 switch (opt_type)
9256 {
9257 case SREQ_GLOBAL:
9258 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9259 ret = NULL;
9260 break;
9261 case SREQ_BUF:
9262 if (!(ret->indir & PV_BUF))
9263 ret = NULL;
9264 break;
9265 case SREQ_WIN:
9266 if (!(ret->indir & PV_WIN))
9267 ret = NULL;
9268 break;
9269 default:
9270 EMSG2(_(e_intern2), "option_iter_next()");
9271 return NULL;
9272 }
9273 }
9274 while (ret == NULL);
9275
9276 return (char_u *)ret->fullname;
9277}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009278#endif
9279
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280/*
9281 * Set the value of option "name".
9282 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009283 *
9284 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009285 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009286 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009287set_option_value(
9288 char_u *name,
9289 long number,
9290 char_u *string,
9291 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009292{
9293 int opt_idx;
9294 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009295 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009296
9297 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009298 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009299 EMSG2(_("E355: Unknown option: %s"), name);
9300 else
9301 {
9302 flags = options[opt_idx].flags;
9303#ifdef HAVE_SANDBOX
9304 /* Disallow changing some options in the sandbox */
9305 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009306 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009308 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009309 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009310#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009311 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009312 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009313 else
9314 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009315 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009316 if (varp != NULL) /* hidden option is not changed */
9317 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009318 if (number == 0 && string != NULL)
9319 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009320 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009321
9322 /* Either we are given a string or we are setting option
9323 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009324 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009325 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009326 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009327 {
9328 /* There's another character after zeros or the string
9329 * is empty. In both cases, we are trying to set a
9330 * num option using a string. */
9331 EMSG3(_("E521: Number required: &%s = '%s'"),
9332 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009333 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009334
9335 }
9336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009338 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009339 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009340 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009341 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009342 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343 }
9344 }
9345 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009346 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347}
9348
9349/*
9350 * Get the terminal code for a terminal option.
9351 * Returns NULL when not found.
9352 */
9353 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009354get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355{
9356 int opt_idx;
9357 char_u *varp;
9358
9359 if (tname[0] != 't' || tname[1] != '_' ||
9360 tname[2] == NUL || tname[3] == NUL)
9361 return NULL;
9362 if ((opt_idx = findoption(tname)) >= 0)
9363 {
9364 varp = get_varp(&(options[opt_idx]));
9365 if (varp != NULL)
9366 varp = *(char_u **)(varp);
9367 return varp;
9368 }
9369 return find_termcode(tname + 2);
9370}
9371
9372 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009373get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009374{
9375 int i;
9376
9377 i = findoption((char_u *)"hl");
9378 if (i >= 0)
9379 return options[i].def_val[VI_DEFAULT];
9380 return (char_u *)NULL;
9381}
9382
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009383#if defined(FEAT_MBYTE) || defined(PROTO)
9384 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009385get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009386{
9387 int i;
9388
9389 i = findoption((char_u *)"enc");
9390 if (i >= 0)
9391 return options[i].def_val[VI_DEFAULT];
9392 return (char_u *)NULL;
9393}
9394#endif
9395
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396/*
9397 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9398 */
9399 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009400find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009401{
9402 int key;
9403 int modifiers;
9404
9405 /*
9406 * Don't use get_special_key_code() for t_xx, we don't want it to call
9407 * add_termcap_entry().
9408 */
9409 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9410 key = TERMCAP2KEY(arg[2], arg[3]);
9411 else
9412 {
9413 --arg; /* put arg at the '<' */
9414 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009415 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416 if (modifiers) /* can't handle modifiers here */
9417 key = 0;
9418 }
9419 return key;
9420}
9421
9422/*
9423 * if 'all' == 0: show changed options
9424 * if 'all' == 1: show all normal options
9425 * if 'all' == 2: show all terminal options
9426 */
9427 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009428showoptions(
9429 int all,
9430 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009431{
9432 struct vimoption *p;
9433 int col;
9434 int isterm;
9435 char_u *varp;
9436 struct vimoption **items;
9437 int item_count;
9438 int run;
9439 int row, rows;
9440 int cols;
9441 int i;
9442 int len;
9443
9444#define INC 20
9445#define GAP 3
9446
9447 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9448 PARAM_COUNT));
9449 if (items == NULL)
9450 return;
9451
9452 /* Highlight title */
9453 if (all == 2)
9454 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9455 else if (opt_flags & OPT_GLOBAL)
9456 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9457 else if (opt_flags & OPT_LOCAL)
9458 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9459 else
9460 MSG_PUTS_TITLE(_("\n--- Options ---"));
9461
9462 /*
9463 * do the loop two times:
9464 * 1. display the short items
9465 * 2. display the long items (only strings and numbers)
9466 */
9467 for (run = 1; run <= 2 && !got_int; ++run)
9468 {
9469 /*
9470 * collect the items in items[]
9471 */
9472 item_count = 0;
9473 for (p = &options[0]; p->fullname != NULL; p++)
9474 {
9475 varp = NULL;
9476 isterm = istermoption(p);
9477 if (opt_flags != 0)
9478 {
9479 if (p->indir != PV_NONE && !isterm)
9480 varp = get_varp_scope(p, opt_flags);
9481 }
9482 else
9483 varp = get_varp(p);
9484 if (varp != NULL
9485 && ((all == 2 && isterm)
9486 || (all == 1 && !isterm)
9487 || (all == 0 && !optval_default(p, varp))))
9488 {
9489 if (p->flags & P_BOOL)
9490 len = 1; /* a toggle option fits always */
9491 else
9492 {
9493 option_value2string(p, opt_flags);
9494 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9495 }
9496 if ((len <= INC - GAP && run == 1) ||
9497 (len > INC - GAP && run == 2))
9498 items[item_count++] = p;
9499 }
9500 }
9501
9502 /*
9503 * display the items
9504 */
9505 if (run == 1)
9506 {
9507 cols = (Columns + GAP - 3) / INC;
9508 if (cols == 0)
9509 cols = 1;
9510 rows = (item_count + cols - 1) / cols;
9511 }
9512 else /* run == 2 */
9513 rows = item_count;
9514 for (row = 0; row < rows && !got_int; ++row)
9515 {
9516 msg_putchar('\n'); /* go to next line */
9517 if (got_int) /* 'q' typed in more */
9518 break;
9519 col = 0;
9520 for (i = row; i < item_count; i += rows)
9521 {
9522 msg_col = col; /* make columns */
9523 showoneopt(items[i], opt_flags);
9524 col += INC;
9525 }
9526 out_flush();
9527 ui_breakcheck();
9528 }
9529 }
9530 vim_free(items);
9531}
9532
9533/*
9534 * Return TRUE if option "p" has its default value.
9535 */
9536 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009537optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009538{
9539 int dvi;
9540
9541 if (varp == NULL)
9542 return TRUE; /* hidden option is always at default */
9543 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9544 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009545 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009546 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009547 /* the cast to long is required for Manx C, long_i is
9548 * needed for MSVC */
9549 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009550 /* P_STRING */
9551 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9552}
9553
9554/*
9555 * showoneopt: show the value of one option
9556 * must not be called with a hidden option!
9557 */
9558 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009559showoneopt(
9560 struct vimoption *p,
9561 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009562{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009563 char_u *varp;
9564 int save_silent = silent_mode;
9565
9566 silent_mode = FALSE;
9567 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568
9569 varp = get_varp_scope(p, opt_flags);
9570
9571 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9572 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9573 ? !curbufIsChanged() : !*(int *)varp))
9574 MSG_PUTS("no");
9575 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9576 MSG_PUTS("--");
9577 else
9578 MSG_PUTS(" ");
9579 MSG_PUTS(p->fullname);
9580 if (!(p->flags & P_BOOL))
9581 {
9582 msg_putchar('=');
9583 /* put value string in NameBuff */
9584 option_value2string(p, opt_flags);
9585 msg_outtrans(NameBuff);
9586 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009587
9588 silent_mode = save_silent;
9589 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590}
9591
9592/*
9593 * Write modified options as ":set" commands to a file.
9594 *
9595 * There are three values for "opt_flags":
9596 * OPT_GLOBAL: Write global option values and fresh values of
9597 * buffer-local options (used for start of a session
9598 * file).
9599 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9600 * curwin (used for a vimrc file).
9601 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9602 * and local values for window-local options of
9603 * curwin. Local values are also written when at the
9604 * default value, because a modeline or autocommand
9605 * may have set them when doing ":edit file" and the
9606 * user has set them back at the default or fresh
9607 * value.
9608 * When "local_only" is TRUE, don't write fresh
9609 * values, only local values (for ":mkview").
9610 * (fresh value = value used for a new buffer or window for a local option).
9611 *
9612 * Return FAIL on error, OK otherwise.
9613 */
9614 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009615makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009616{
9617 struct vimoption *p;
9618 char_u *varp; /* currently used value */
9619 char_u *varp_fresh; /* local value */
9620 char_u *varp_local = NULL; /* fresh value */
9621 char *cmd;
9622 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009623 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009624
9625 /*
9626 * The options that don't have a default (terminal name, columns, lines)
9627 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009628 * Do the loop over "options[]" twice: once for options with the
9629 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009630 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009631 for (pri = 1; pri >= 0; --pri)
9632 {
9633 for (p = &options[0]; !istermoption(p); p++)
9634 if (!(p->flags & P_NO_MKRC)
9635 && !istermoption(p)
9636 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009637 {
9638 /* skip global option when only doing locals */
9639 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9640 continue;
9641
9642 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9643 * file, they are always buffer-specific. */
9644 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9645 continue;
9646
9647 /* Global values are only written when not at the default value. */
9648 varp = get_varp_scope(p, opt_flags);
9649 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9650 continue;
9651
9652 round = 2;
9653 if (p->indir != PV_NONE)
9654 {
9655 if (p->var == VAR_WIN)
9656 {
9657 /* skip window-local option when only doing globals */
9658 if (!(opt_flags & OPT_LOCAL))
9659 continue;
9660 /* When fresh value of window-local option is not at the
9661 * default, need to write it too. */
9662 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9663 {
9664 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9665 if (!optval_default(p, varp_fresh))
9666 {
9667 round = 1;
9668 varp_local = varp;
9669 varp = varp_fresh;
9670 }
9671 }
9672 }
9673 }
9674
9675 /* Round 1: fresh value for window-local options.
9676 * Round 2: other values */
9677 for ( ; round <= 2; varp = varp_local, ++round)
9678 {
9679 if (round == 1 || (opt_flags & OPT_GLOBAL))
9680 cmd = "set";
9681 else
9682 cmd = "setlocal";
9683
9684 if (p->flags & P_BOOL)
9685 {
9686 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9687 return FAIL;
9688 }
9689 else if (p->flags & P_NUM)
9690 {
9691 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9692 return FAIL;
9693 }
9694 else /* P_STRING */
9695 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009696#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9697 int do_endif = FALSE;
9698
Bram Moolenaar071d4272004-06-13 20:20:40 +00009699 /* Don't set 'syntax' and 'filetype' again if the value is
9700 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009701 if (
9702# if defined(FEAT_SYN_HL)
9703 p->indir == PV_SYN
9704# if defined(FEAT_AUTOCMD)
9705 ||
9706# endif
9707# endif
9708# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009709 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009710# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009711 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009712 {
9713 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9714 *(char_u **)(varp)) < 0
9715 || put_eol(fd) < 0)
9716 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009717 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009718 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009720 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9721 (p->flags & P_EXPAND) != 0) == FAIL)
9722 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009723#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9724 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725 {
9726 if (put_line(fd, "endif") == FAIL)
9727 return FAIL;
9728 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009729#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009730 }
9731 }
9732 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009733 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 return OK;
9735}
9736
9737#if defined(FEAT_FOLDING) || defined(PROTO)
9738/*
9739 * Generate set commands for the local fold options only. Used when
9740 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9741 */
9742 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009743makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009744{
9745 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9746# ifdef FEAT_EVAL
9747 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9748 == FAIL
9749# endif
9750 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9751 == FAIL
9752 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9753 == FAIL
9754 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9755 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9756 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9757 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9758 )
9759 return FAIL;
9760
9761 return OK;
9762}
9763#endif
9764
9765 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009766put_setstring(
9767 FILE *fd,
9768 char *cmd,
9769 char *name,
9770 char_u **valuep,
9771 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009772{
9773 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009774 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009775
9776 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9777 return FAIL;
9778 if (*valuep != NULL)
9779 {
9780 /* Output 'pastetoggle' as key names. For other
9781 * options some characters have to be escaped with
9782 * CTRL-V or backslash */
9783 if (valuep == &p_pt)
9784 {
9785 s = *valuep;
9786 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009787 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009788 return FAIL;
9789 }
9790 else if (expand)
9791 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009792 buf = alloc(MAXPATHL);
9793 if (buf == NULL)
9794 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9796 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009797 {
9798 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009799 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009800 }
9801 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009802 }
9803 else if (put_escstr(fd, *valuep, 2) == FAIL)
9804 return FAIL;
9805 }
9806 if (put_eol(fd) < 0)
9807 return FAIL;
9808 return OK;
9809}
9810
9811 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009812put_setnum(
9813 FILE *fd,
9814 char *cmd,
9815 char *name,
9816 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009817{
9818 long wc;
9819
9820 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9821 return FAIL;
9822 if (wc_use_keyname((char_u *)valuep, &wc))
9823 {
9824 /* print 'wildchar' and 'wildcharm' as a key name */
9825 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9826 return FAIL;
9827 }
9828 else if (fprintf(fd, "%ld", *valuep) < 0)
9829 return FAIL;
9830 if (put_eol(fd) < 0)
9831 return FAIL;
9832 return OK;
9833}
9834
9835 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009836put_setbool(
9837 FILE *fd,
9838 char *cmd,
9839 char *name,
9840 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009841{
Bram Moolenaar893de922007-10-02 18:40:57 +00009842 if (value < 0) /* global/local option using global value */
9843 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009844 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9845 || put_eol(fd) < 0)
9846 return FAIL;
9847 return OK;
9848}
9849
9850/*
9851 * Clear all the terminal options.
9852 * If the option has been allocated, free the memory.
9853 * Terminal options are never hidden or indirect.
9854 */
9855 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009856clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009857{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009858 /*
9859 * Reset a few things before clearing the old options. This may cause
9860 * outputting a few things that the terminal doesn't understand, but the
9861 * screen will be cleared later, so this is OK.
9862 */
9863#ifdef FEAT_MOUSE_TTY
9864 mch_setmouse(FALSE); /* switch mouse off */
9865#endif
9866#ifdef FEAT_TITLE
9867 mch_restore_title(3); /* restore window titles */
9868#endif
9869#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9870 /* When starting the GUI close the display opened for the clipboard.
9871 * After restoring the title, because that will need the display. */
9872 if (gui.starting)
9873 clear_xterm_clip();
9874#endif
9875#ifdef WIN3264
9876 /*
9877 * Check if this is allowed now.
9878 */
9879 if (can_end_termcap_mode(FALSE) == TRUE)
9880#endif
9881 stoptermcap(); /* stop termcap mode */
9882
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009883 free_termoptions();
9884}
9885
9886 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009887free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009888{
9889 struct vimoption *p;
9890
Bram Moolenaar071d4272004-06-13 20:20:40 +00009891 for (p = &options[0]; p->fullname != NULL; p++)
9892 if (istermoption(p))
9893 {
9894 if (p->flags & P_ALLOCED)
9895 free_string_option(*(char_u **)(p->var));
9896 if (p->flags & P_DEF_ALLOCED)
9897 free_string_option(p->def_val[VI_DEFAULT]);
9898 *(char_u **)(p->var) = empty_option;
9899 p->def_val[VI_DEFAULT] = empty_option;
9900 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9901 }
9902 clear_termcodes();
9903}
9904
9905/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009906 * Free the string for one term option, if it was allocated.
9907 * Set the string to empty_option and clear allocated flag.
9908 * "var" points to the option value.
9909 */
9910 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009911free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009912{
9913 struct vimoption *p;
9914
9915 for (p = &options[0]; p->fullname != NULL; p++)
9916 if (p->var == var)
9917 {
9918 if (p->flags & P_ALLOCED)
9919 free_string_option(*(char_u **)(p->var));
9920 *(char_u **)(p->var) = empty_option;
9921 p->flags &= ~P_ALLOCED;
9922 break;
9923 }
9924}
9925
9926/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009927 * Set the terminal option defaults to the current value.
9928 * Used after setting the terminal name.
9929 */
9930 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009931set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932{
9933 struct vimoption *p;
9934
9935 for (p = &options[0]; p->fullname != NULL; p++)
9936 {
9937 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9938 {
9939 if (p->flags & P_DEF_ALLOCED)
9940 {
9941 free_string_option(p->def_val[VI_DEFAULT]);
9942 p->flags &= ~P_DEF_ALLOCED;
9943 }
9944 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9945 if (p->flags & P_ALLOCED)
9946 {
9947 p->flags |= P_DEF_ALLOCED;
9948 p->flags &= ~P_ALLOCED; /* don't free the value now */
9949 }
9950 }
9951 }
9952}
9953
9954/*
9955 * return TRUE if 'p' starts with 't_'
9956 */
9957 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009958istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959{
9960 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9961}
9962
9963/*
9964 * Compute columns for ruler and shown command. 'sc_col' is also used to
9965 * decide what the maximum length of a message on the status line can be.
9966 * If there is a status line for the last window, 'sc_col' is independent
9967 * of 'ru_col'.
9968 */
9969
9970#define COL_RULER 17 /* columns needed by standard ruler */
9971
9972 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009973comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974{
9975#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9976 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9977
9978 sc_col = 0;
9979 ru_col = 0;
9980 if (p_ru)
9981 {
9982#ifdef FEAT_STL_OPT
9983 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9984#else
9985 ru_col = COL_RULER + 1;
9986#endif
9987 /* no last status line, adjust sc_col */
9988 if (!last_has_status)
9989 sc_col = ru_col;
9990 }
9991 if (p_sc)
9992 {
9993 sc_col += SHOWCMD_COLS;
9994 if (!p_ru || last_has_status) /* no need for separating space */
9995 ++sc_col;
9996 }
9997 sc_col = Columns - sc_col;
9998 ru_col = Columns - ru_col;
9999 if (sc_col <= 0) /* screen too narrow, will become a mess */
10000 sc_col = 1;
10001 if (ru_col <= 0)
10002 ru_col = 1;
10003#else
10004 sc_col = Columns;
10005 ru_col = Columns;
10006#endif
10007}
10008
10009/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010010 * Unset local option value, similar to ":set opt<".
10011 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010012 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010013unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010014{
10015 struct vimoption *p;
10016 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010017 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010018
10019 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010020 if (opt_idx < 0)
10021 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010022 p = &(options[opt_idx]);
10023
10024 switch ((int)p->indir)
10025 {
10026 /* global option with local value: use local value if it's been set */
10027 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010028 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010029 break;
10030 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010031 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010032 break;
10033 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010034 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010035 break;
10036 case PV_AR:
10037 buf->b_p_ar = -1;
10038 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010039 case PV_BKC:
10040 clear_string_option(&buf->b_p_bkc);
10041 buf->b_bkc_flags = 0;
10042 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010043 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010044 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010045 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010046 case PV_TC:
10047 clear_string_option(&buf->b_p_tc);
10048 buf->b_tc_flags = 0;
10049 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010050#ifdef FEAT_FIND_ID
10051 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010052 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010053 break;
10054 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010055 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010056 break;
10057#endif
10058#ifdef FEAT_INS_EXPAND
10059 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010060 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010061 break;
10062 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010063 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010064 break;
10065#endif
10066#ifdef FEAT_QUICKFIX
10067 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010068 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010069 break;
10070 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010071 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010072 break;
10073 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010074 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010075 break;
10076#endif
10077#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10078 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010079 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080 break;
10081#endif
10082#if defined(FEAT_CRYPT)
10083 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010084 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010085 break;
10086#endif
10087#ifdef FEAT_STL_OPT
10088 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010089 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010090 break;
10091#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010092 case PV_UL:
10093 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10094 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010095#ifdef FEAT_LISP
10096 case PV_LW:
10097 clear_string_option(&buf->b_p_lw);
10098 break;
10099#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010100 }
10101}
10102
10103/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010104 * Get pointer to option variable, depending on local or global scope.
10105 */
10106 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010107get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010108{
10109 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10110 {
10111 if (p->var == VAR_WIN)
10112 return (char_u *)GLOBAL_WO(get_varp(p));
10113 return p->var;
10114 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010115 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116 {
10117 switch ((int)p->indir)
10118 {
10119#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010120 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10121 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10122 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010123#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010124 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10125 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10126 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010127 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010128 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010129 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010130#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010131 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10132 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133#endif
10134#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010135 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10136 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010138#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10139 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10140#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010141#if defined(FEAT_CRYPT)
10142 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10143#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010144#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010145 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010146#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010147 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010148#ifdef FEAT_LISP
10149 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10150#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010151 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010152 }
10153 return NULL; /* "cannot happen" */
10154 }
10155 return get_varp(p);
10156}
10157
10158/*
10159 * Get pointer to option variable.
10160 */
10161 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010162get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010163{
10164 /* hidden option, always return NULL */
10165 if (p->var == NULL)
10166 return NULL;
10167
10168 switch ((int)p->indir)
10169 {
10170 case PV_NONE: return p->var;
10171
10172 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010173 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010175 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010176 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010177 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010179 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010181 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010183 case PV_TC: return *curbuf->b_p_tc != NUL
10184 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010185 case PV_BKC: return *curbuf->b_p_bkc != NUL
10186 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010187#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010188 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010190 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10192#endif
10193#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010194 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010196 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10198#endif
10199#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010200 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010201 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010202 case PV_GP: return *curbuf->b_p_gp != NUL
10203 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10204 case PV_MP: return *curbuf->b_p_mp != NUL
10205 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010207#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10208 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10209 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10210#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010211#if defined(FEAT_CRYPT)
10212 case PV_CM: return *curbuf->b_p_cm != NUL
10213 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10214#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010215#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010216 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010217 ? (char_u *)&(curwin->w_p_stl) : p->var;
10218#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010219 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10220 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010221#ifdef FEAT_LISP
10222 case PV_LW: return *curbuf->b_p_lw != NUL
10223 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010225
10226#ifdef FEAT_ARABIC
10227 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10228#endif
10229 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010230#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010231 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10232#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010233#ifdef FEAT_SYN_HL
10234 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10235 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010236 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010237#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010238#ifdef FEAT_DIFF
10239 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10240#endif
10241#ifdef FEAT_FOLDING
10242 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10243 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10244 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10245 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10246 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10247 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10248 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10249# ifdef FEAT_EVAL
10250 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10251 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10252# endif
10253 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10254#endif
10255 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010256 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010257#ifdef FEAT_LINEBREAK
10258 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010260#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10262#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010263#ifdef FEAT_VERTSPLIT
10264 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10265#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10267 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10268#endif
10269#ifdef FEAT_RIGHTLEFT
10270 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10271 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10272#endif
10273 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10274 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10275#ifdef FEAT_LINEBREAK
10276 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010277 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10278 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279#endif
10280#ifdef FEAT_SCROLLBIND
10281 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10282#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010283#ifdef FEAT_CURSORBIND
10284 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10285#endif
10286#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010287 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10288 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290
10291 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10292 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10293#ifdef FEAT_MBYTE
10294 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10295#endif
10296#if defined(FEAT_QUICKFIX)
10297 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10298 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10299#endif
10300 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10301 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10302#ifdef FEAT_CINDENT
10303 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10304 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10305 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10306#endif
10307#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10308 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10309#endif
10310#ifdef FEAT_COMMENTS
10311 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10312#endif
10313#ifdef FEAT_FOLDING
10314 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10315#endif
10316#ifdef FEAT_INS_EXPAND
10317 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10318#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010319#ifdef FEAT_COMPL_FUNC
10320 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010321 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010322#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010324 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010325 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10326#ifdef FEAT_MBYTE
10327 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10328#endif
10329 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10330#ifdef FEAT_AUTOCMD
10331 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10332#endif
10333 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010334 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010335 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10336 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10337 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10338 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10339#ifdef FEAT_FIND_ID
10340# ifdef FEAT_EVAL
10341 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10342# endif
10343#endif
10344#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10345 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10346 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10347#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010348#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010349 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351#ifdef FEAT_CRYPT
10352 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10353#endif
10354#ifdef FEAT_LISP
10355 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10356#endif
10357 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10358 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10359 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10360 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10361 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010362 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010363#ifdef FEAT_TEXTOBJ
10364 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10365#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010366 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10367#ifdef FEAT_SMARTINDENT
10368 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10372#ifdef FEAT_SEARCHPATH
10373 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10374#endif
10375 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10376#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010377 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010378 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10379#endif
10380#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010381 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10382 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10383 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384#endif
10385 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10386 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10387 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10388 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010389#ifdef FEAT_PERSISTENT_UNDO
10390 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10391#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010392 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10393#ifdef FEAT_KEYMAP
10394 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10395#endif
10396 default: EMSG(_("E356: get_varp ERROR"));
10397 }
10398 /* always return a valid pointer to avoid a crash! */
10399 return (char_u *)&(curbuf->b_p_wm);
10400}
10401
10402/*
10403 * Get the value of 'equalprg', either the buffer-local one or the global one.
10404 */
10405 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010406get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407{
10408 if (*curbuf->b_p_ep == NUL)
10409 return p_ep;
10410 return curbuf->b_p_ep;
10411}
10412
10413#if defined(FEAT_WINDOWS) || defined(PROTO)
10414/*
10415 * Copy options from one window to another.
10416 * Used when splitting a window.
10417 */
10418 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010419win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420{
10421 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10422 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10423# ifdef FEAT_RIGHTLEFT
10424# ifdef FEAT_FKMAP
10425 /* Is this right? */
10426 wp_to->w_farsi = wp_from->w_farsi;
10427# endif
10428# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010429#if defined(FEAT_LINEBREAK)
10430 briopt_check(wp_to);
10431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432}
10433#endif
10434
10435/*
10436 * Copy the options from one winopt_T to another.
10437 * Doesn't free the old option values in "to", use clear_winopt() for that.
10438 * The 'scroll' option is not copied, because it depends on the window height.
10439 * The 'previewwindow' option is reset, there can be only one preview window.
10440 */
10441 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010442copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010443{
10444#ifdef FEAT_ARABIC
10445 to->wo_arab = from->wo_arab;
10446#endif
10447 to->wo_list = from->wo_list;
10448 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010449 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010450#ifdef FEAT_LINEBREAK
10451 to->wo_nuw = from->wo_nuw;
10452#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010453#ifdef FEAT_RIGHTLEFT
10454 to->wo_rl = from->wo_rl;
10455 to->wo_rlc = vim_strsave(from->wo_rlc);
10456#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010457#ifdef FEAT_STL_OPT
10458 to->wo_stl = vim_strsave(from->wo_stl);
10459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010460 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010461#ifdef FEAT_DIFF
10462 to->wo_wrap_save = from->wo_wrap_save;
10463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010464#ifdef FEAT_LINEBREAK
10465 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010466 to->wo_bri = from->wo_bri;
10467 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010468#endif
10469#ifdef FEAT_SCROLLBIND
10470 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010471 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010473#ifdef FEAT_CURSORBIND
10474 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010475 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010476#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010477#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010478 to->wo_spell = from->wo_spell;
10479#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010480#ifdef FEAT_SYN_HL
10481 to->wo_cuc = from->wo_cuc;
10482 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010483 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010484#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010485#ifdef FEAT_DIFF
10486 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010487 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010488#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010489#ifdef FEAT_CONCEAL
10490 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010491 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010492#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493#ifdef FEAT_FOLDING
10494 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010495 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010496 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010497 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010498 to->wo_fdi = vim_strsave(from->wo_fdi);
10499 to->wo_fml = from->wo_fml;
10500 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010501 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010503 to->wo_fdm_save = from->wo_diff_saved
10504 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010505 to->wo_fdn = from->wo_fdn;
10506# ifdef FEAT_EVAL
10507 to->wo_fde = vim_strsave(from->wo_fde);
10508 to->wo_fdt = vim_strsave(from->wo_fdt);
10509# endif
10510 to->wo_fmr = vim_strsave(from->wo_fmr);
10511#endif
10512 check_winopt(to); /* don't want NULL pointers */
10513}
10514
10515/*
10516 * Check string options in a window for a NULL value.
10517 */
10518 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010519check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520{
10521 check_winopt(&win->w_onebuf_opt);
10522 check_winopt(&win->w_allbuf_opt);
10523}
10524
10525/*
10526 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10527 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010528 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010529check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530{
10531#ifdef FEAT_FOLDING
10532 check_string_option(&wop->wo_fdi);
10533 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010534 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535# ifdef FEAT_EVAL
10536 check_string_option(&wop->wo_fde);
10537 check_string_option(&wop->wo_fdt);
10538# endif
10539 check_string_option(&wop->wo_fmr);
10540#endif
10541#ifdef FEAT_RIGHTLEFT
10542 check_string_option(&wop->wo_rlc);
10543#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010544#ifdef FEAT_STL_OPT
10545 check_string_option(&wop->wo_stl);
10546#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010547#ifdef FEAT_SYN_HL
10548 check_string_option(&wop->wo_cc);
10549#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010550#ifdef FEAT_CONCEAL
10551 check_string_option(&wop->wo_cocu);
10552#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010553#ifdef FEAT_LINEBREAK
10554 check_string_option(&wop->wo_briopt);
10555#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556}
10557
10558/*
10559 * Free the allocated memory inside a winopt_T.
10560 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010562clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563{
10564#ifdef FEAT_FOLDING
10565 clear_string_option(&wop->wo_fdi);
10566 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010567 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568# ifdef FEAT_EVAL
10569 clear_string_option(&wop->wo_fde);
10570 clear_string_option(&wop->wo_fdt);
10571# endif
10572 clear_string_option(&wop->wo_fmr);
10573#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010574#ifdef FEAT_LINEBREAK
10575 clear_string_option(&wop->wo_briopt);
10576#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577#ifdef FEAT_RIGHTLEFT
10578 clear_string_option(&wop->wo_rlc);
10579#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010580#ifdef FEAT_STL_OPT
10581 clear_string_option(&wop->wo_stl);
10582#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010583#ifdef FEAT_SYN_HL
10584 clear_string_option(&wop->wo_cc);
10585#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010586#ifdef FEAT_CONCEAL
10587 clear_string_option(&wop->wo_cocu);
10588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589}
10590
10591/*
10592 * Copy global option values to local options for one buffer.
10593 * Used when creating a new buffer and sometimes when entering a buffer.
10594 * flags:
10595 * BCO_ENTER We will enter the buf buffer.
10596 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10597 * appropriate.
10598 * BCO_NOHELP Don't copy the values to a help buffer.
10599 */
10600 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010601buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602{
10603 int should_copy = TRUE;
10604 char_u *save_p_isk = NULL; /* init for GCC */
10605 int dont_do_help;
10606 int did_isk = FALSE;
10607
10608 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010609 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610 */
10611 if (buf == NULL || !buf_valid(buf))
10612 return;
10613
10614 /*
10615 * Skip this when the option defaults have not been set yet. Happens when
10616 * main() allocates the first buffer.
10617 */
10618 if (p_cpo != NULL)
10619 {
10620 /*
10621 * Always copy when entering and 'cpo' contains 'S'.
10622 * Don't copy when already initialized.
10623 * Don't copy when 'cpo' contains 's' and not entering.
10624 * 'S' BCO_ENTER initialized 's' should_copy
10625 * yes yes X X TRUE
10626 * yes no yes X FALSE
10627 * no X yes X FALSE
10628 * X no no yes FALSE
10629 * X no no no TRUE
10630 * no yes no X TRUE
10631 */
10632 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10633 && (buf->b_p_initialized
10634 || (!(flags & BCO_ENTER)
10635 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10636 should_copy = FALSE;
10637
10638 if (should_copy || (flags & BCO_ALWAYS))
10639 {
10640 /* Don't copy the options specific to a help buffer when
10641 * BCO_NOHELP is given or the options were initialized already
10642 * (jumping back to a help file with CTRL-T or CTRL-O) */
10643 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10644 || buf->b_p_initialized;
10645 if (dont_do_help) /* don't free b_p_isk */
10646 {
10647 save_p_isk = buf->b_p_isk;
10648 buf->b_p_isk = NULL;
10649 }
10650 /*
10651 * Always free the allocated strings.
10652 * If not already initialized, set 'readonly' and copy 'fileformat'.
10653 */
10654 if (!buf->b_p_initialized)
10655 {
10656 free_buf_options(buf, TRUE);
10657 buf->b_p_ro = FALSE; /* don't copy readonly */
10658 buf->b_p_tx = p_tx;
10659#ifdef FEAT_MBYTE
10660 buf->b_p_fenc = vim_strsave(p_fenc);
10661#endif
10662 buf->b_p_ff = vim_strsave(p_ff);
10663#if defined(FEAT_QUICKFIX)
10664 buf->b_p_bh = empty_option;
10665 buf->b_p_bt = empty_option;
10666#endif
10667 }
10668 else
10669 free_buf_options(buf, FALSE);
10670
10671 buf->b_p_ai = p_ai;
10672 buf->b_p_ai_nopaste = p_ai_nopaste;
10673 buf->b_p_sw = p_sw;
10674 buf->b_p_tw = p_tw;
10675 buf->b_p_tw_nopaste = p_tw_nopaste;
10676 buf->b_p_tw_nobin = p_tw_nobin;
10677 buf->b_p_wm = p_wm;
10678 buf->b_p_wm_nopaste = p_wm_nopaste;
10679 buf->b_p_wm_nobin = p_wm_nobin;
10680 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010681#ifdef FEAT_MBYTE
10682 buf->b_p_bomb = p_bomb;
10683#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010684 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685 buf->b_p_et = p_et;
10686 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010687 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688 buf->b_p_ml = p_ml;
10689 buf->b_p_ml_nobin = p_ml_nobin;
10690 buf->b_p_inf = p_inf;
10691 buf->b_p_swf = p_swf;
10692#ifdef FEAT_INS_EXPAND
10693 buf->b_p_cpt = vim_strsave(p_cpt);
10694#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010695#ifdef FEAT_COMPL_FUNC
10696 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010697 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 buf->b_p_sts = p_sts;
10700 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010701 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010702#ifdef FEAT_COMMENTS
10703 buf->b_p_com = vim_strsave(p_com);
10704#endif
10705#ifdef FEAT_FOLDING
10706 buf->b_p_cms = vim_strsave(p_cms);
10707#endif
10708 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010709 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010710 buf->b_p_nf = vim_strsave(p_nf);
10711 buf->b_p_mps = vim_strsave(p_mps);
10712#ifdef FEAT_SMARTINDENT
10713 buf->b_p_si = p_si;
10714#endif
10715 buf->b_p_ci = p_ci;
10716#ifdef FEAT_CINDENT
10717 buf->b_p_cin = p_cin;
10718 buf->b_p_cink = vim_strsave(p_cink);
10719 buf->b_p_cino = vim_strsave(p_cino);
10720#endif
10721#ifdef FEAT_AUTOCMD
10722 /* Don't copy 'filetype', it must be detected */
10723 buf->b_p_ft = empty_option;
10724#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010725 buf->b_p_pi = p_pi;
10726#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10727 buf->b_p_cinw = vim_strsave(p_cinw);
10728#endif
10729#ifdef FEAT_LISP
10730 buf->b_p_lisp = p_lisp;
10731#endif
10732#ifdef FEAT_SYN_HL
10733 /* Don't copy 'syntax', it must be set */
10734 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010735 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010736 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010737#endif
10738#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010739 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010740 (void)compile_cap_prog(&buf->b_s);
10741 buf->b_s.b_p_spf = vim_strsave(p_spf);
10742 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743#endif
10744#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10745 buf->b_p_inde = vim_strsave(p_inde);
10746 buf->b_p_indk = vim_strsave(p_indk);
10747#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010748#if defined(FEAT_EVAL)
10749 buf->b_p_fex = vim_strsave(p_fex);
10750#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751#ifdef FEAT_CRYPT
10752 buf->b_p_key = vim_strsave(p_key);
10753#endif
10754#ifdef FEAT_SEARCHPATH
10755 buf->b_p_sua = vim_strsave(p_sua);
10756#endif
10757#ifdef FEAT_KEYMAP
10758 buf->b_p_keymap = vim_strsave(p_keymap);
10759 buf->b_kmap_state |= KEYMAP_INIT;
10760#endif
10761 /* This isn't really an option, but copying the langmap and IME
10762 * state from the current buffer is better than resetting it. */
10763 buf->b_p_iminsert = p_iminsert;
10764 buf->b_p_imsearch = p_imsearch;
10765
10766 /* options that are normally global but also have a local value
10767 * are not copied, start using the global value */
10768 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010769 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010770 buf->b_p_bkc = empty_option;
10771 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772#ifdef FEAT_QUICKFIX
10773 buf->b_p_gp = empty_option;
10774 buf->b_p_mp = empty_option;
10775 buf->b_p_efm = empty_option;
10776#endif
10777 buf->b_p_ep = empty_option;
10778 buf->b_p_kp = empty_option;
10779 buf->b_p_path = empty_option;
10780 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010781 buf->b_p_tc = empty_option;
10782 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783#ifdef FEAT_FIND_ID
10784 buf->b_p_def = empty_option;
10785 buf->b_p_inc = empty_option;
10786# ifdef FEAT_EVAL
10787 buf->b_p_inex = vim_strsave(p_inex);
10788# endif
10789#endif
10790#ifdef FEAT_INS_EXPAND
10791 buf->b_p_dict = empty_option;
10792 buf->b_p_tsr = empty_option;
10793#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010794#ifdef FEAT_TEXTOBJ
10795 buf->b_p_qe = vim_strsave(p_qe);
10796#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010797#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10798 buf->b_p_bexpr = empty_option;
10799#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010800#if defined(FEAT_CRYPT)
10801 buf->b_p_cm = empty_option;
10802#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010803#ifdef FEAT_PERSISTENT_UNDO
10804 buf->b_p_udf = p_udf;
10805#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010806#ifdef FEAT_LISP
10807 buf->b_p_lw = empty_option;
10808#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010809
10810 /*
10811 * Don't copy the options set by ex_help(), use the saved values,
10812 * when going from a help buffer to a non-help buffer.
10813 * Don't touch these at all when BCO_NOHELP is used and going from
10814 * or to a help buffer.
10815 */
10816 if (dont_do_help)
10817 buf->b_p_isk = save_p_isk;
10818 else
10819 {
10820 buf->b_p_isk = vim_strsave(p_isk);
10821 did_isk = TRUE;
10822 buf->b_p_ts = p_ts;
10823 buf->b_help = FALSE;
10824#ifdef FEAT_QUICKFIX
10825 if (buf->b_p_bt[0] == 'h')
10826 clear_string_option(&buf->b_p_bt);
10827#endif
10828 buf->b_p_ma = p_ma;
10829 }
10830 }
10831
10832 /*
10833 * When the options should be copied (ignoring BCO_ALWAYS), set the
10834 * flag that indicates that the options have been initialized.
10835 */
10836 if (should_copy)
10837 buf->b_p_initialized = TRUE;
10838 }
10839
10840 check_buf_options(buf); /* make sure we don't have NULLs */
10841 if (did_isk)
10842 (void)buf_init_chartab(buf, FALSE);
10843}
10844
10845/*
10846 * Reset the 'modifiable' option and its default value.
10847 */
10848 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010849reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850{
10851 int opt_idx;
10852
10853 curbuf->b_p_ma = FALSE;
10854 p_ma = FALSE;
10855 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010856 if (opt_idx >= 0)
10857 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858}
10859
10860/*
10861 * Set the global value for 'iminsert' to the local value.
10862 */
10863 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010864set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865{
10866 p_iminsert = curbuf->b_p_iminsert;
10867}
10868
10869/*
10870 * Set the global value for 'imsearch' to the local value.
10871 */
10872 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010873set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874{
10875 p_imsearch = curbuf->b_p_imsearch;
10876}
10877
10878#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10879static int expand_option_idx = -1;
10880static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10881static int expand_option_flags = 0;
10882
10883 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010884set_context_in_set_cmd(
10885 expand_T *xp,
10886 char_u *arg,
10887 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010888{
10889 int nextchar;
10890 long_u flags = 0; /* init for GCC */
10891 int opt_idx = 0; /* init for GCC */
10892 char_u *p;
10893 char_u *s;
10894 int is_term_option = FALSE;
10895 int key;
10896
10897 expand_option_flags = opt_flags;
10898
10899 xp->xp_context = EXPAND_SETTINGS;
10900 if (*arg == NUL)
10901 {
10902 xp->xp_pattern = arg;
10903 return;
10904 }
10905 p = arg + STRLEN(arg) - 1;
10906 if (*p == ' ' && *(p - 1) != '\\')
10907 {
10908 xp->xp_pattern = p + 1;
10909 return;
10910 }
10911 while (p > arg)
10912 {
10913 s = p;
10914 /* count number of backslashes before ' ' or ',' */
10915 if (*p == ' ' || *p == ',')
10916 {
10917 while (s > arg && *(s - 1) == '\\')
10918 --s;
10919 }
10920 /* break at a space with an even number of backslashes */
10921 if (*p == ' ' && ((p - s) & 1) == 0)
10922 {
10923 ++p;
10924 break;
10925 }
10926 --p;
10927 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010928 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929 {
10930 xp->xp_context = EXPAND_BOOL_SETTINGS;
10931 p += 2;
10932 }
10933 if (STRNCMP(p, "inv", 3) == 0)
10934 {
10935 xp->xp_context = EXPAND_BOOL_SETTINGS;
10936 p += 3;
10937 }
10938 xp->xp_pattern = arg = p;
10939 if (*arg == '<')
10940 {
10941 while (*p != '>')
10942 if (*p++ == NUL) /* expand terminal option name */
10943 return;
10944 key = get_special_key_code(arg + 1);
10945 if (key == 0) /* unknown name */
10946 {
10947 xp->xp_context = EXPAND_NOTHING;
10948 return;
10949 }
10950 nextchar = *++p;
10951 is_term_option = TRUE;
10952 expand_option_name[2] = KEY2TERMCAP0(key);
10953 expand_option_name[3] = KEY2TERMCAP1(key);
10954 }
10955 else
10956 {
10957 if (p[0] == 't' && p[1] == '_')
10958 {
10959 p += 2;
10960 if (*p != NUL)
10961 ++p;
10962 if (*p == NUL)
10963 return; /* expand option name */
10964 nextchar = *++p;
10965 is_term_option = TRUE;
10966 expand_option_name[2] = p[-2];
10967 expand_option_name[3] = p[-1];
10968 }
10969 else
10970 {
10971 /* Allow * wildcard */
10972 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10973 p++;
10974 if (*p == NUL)
10975 return;
10976 nextchar = *p;
10977 *p = NUL;
10978 opt_idx = findoption(arg);
10979 *p = nextchar;
10980 if (opt_idx == -1 || options[opt_idx].var == NULL)
10981 {
10982 xp->xp_context = EXPAND_NOTHING;
10983 return;
10984 }
10985 flags = options[opt_idx].flags;
10986 if (flags & P_BOOL)
10987 {
10988 xp->xp_context = EXPAND_NOTHING;
10989 return;
10990 }
10991 }
10992 }
10993 /* handle "-=" and "+=" */
10994 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10995 {
10996 ++p;
10997 nextchar = '=';
10998 }
10999 if ((nextchar != '=' && nextchar != ':')
11000 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11001 {
11002 xp->xp_context = EXPAND_UNSUCCESSFUL;
11003 return;
11004 }
11005 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11006 {
11007 xp->xp_context = EXPAND_OLD_SETTING;
11008 if (is_term_option)
11009 expand_option_idx = -1;
11010 else
11011 expand_option_idx = opt_idx;
11012 xp->xp_pattern = p + 1;
11013 return;
11014 }
11015 xp->xp_context = EXPAND_NOTHING;
11016 if (is_term_option || (flags & P_NUM))
11017 return;
11018
11019 xp->xp_pattern = p + 1;
11020
11021 if (flags & P_EXPAND)
11022 {
11023 p = options[opt_idx].var;
11024 if (p == (char_u *)&p_bdir
11025 || p == (char_u *)&p_dir
11026 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011027 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011028 || p == (char_u *)&p_rtp
11029#ifdef FEAT_SEARCHPATH
11030 || p == (char_u *)&p_cdpath
11031#endif
11032#ifdef FEAT_SESSION
11033 || p == (char_u *)&p_vdir
11034#endif
11035 )
11036 {
11037 xp->xp_context = EXPAND_DIRECTORIES;
11038 if (p == (char_u *)&p_path
11039#ifdef FEAT_SEARCHPATH
11040 || p == (char_u *)&p_cdpath
11041#endif
11042 )
11043 xp->xp_backslash = XP_BS_THREE;
11044 else
11045 xp->xp_backslash = XP_BS_ONE;
11046 }
11047 else
11048 {
11049 xp->xp_context = EXPAND_FILES;
11050 /* for 'tags' need three backslashes for a space */
11051 if (p == (char_u *)&p_tags)
11052 xp->xp_backslash = XP_BS_THREE;
11053 else
11054 xp->xp_backslash = XP_BS_ONE;
11055 }
11056 }
11057
11058 /* For an option that is a list of file names, find the start of the
11059 * last file name. */
11060 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11061 {
11062 /* count number of backslashes before ' ' or ',' */
11063 if (*p == ' ' || *p == ',')
11064 {
11065 s = p;
11066 while (s > xp->xp_pattern && *(s - 1) == '\\')
11067 --s;
11068 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11069 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11070 {
11071 xp->xp_pattern = p + 1;
11072 break;
11073 }
11074 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011075
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011076#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011077 /* for 'spellsuggest' start at "file:" */
11078 if (options[opt_idx].var == (char_u *)&p_sps
11079 && STRNCMP(p, "file:", 5) == 0)
11080 {
11081 xp->xp_pattern = p + 5;
11082 break;
11083 }
11084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085 }
11086
11087 return;
11088}
11089
11090 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011091ExpandSettings(
11092 expand_T *xp,
11093 regmatch_T *regmatch,
11094 int *num_file,
11095 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096{
11097 int num_normal = 0; /* Nr of matching non-term-code settings */
11098 int num_term = 0; /* Nr of matching terminal code settings */
11099 int opt_idx;
11100 int match;
11101 int count = 0;
11102 char_u *str;
11103 int loop;
11104 int is_term_opt;
11105 char_u name_buf[MAX_KEY_NAME_LEN];
11106 static char *(names[]) = {"all", "termcap"};
11107 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11108
11109 /* do this loop twice:
11110 * loop == 0: count the number of matching options
11111 * loop == 1: copy the matching options into allocated memory
11112 */
11113 for (loop = 0; loop <= 1; ++loop)
11114 {
11115 regmatch->rm_ic = ic;
11116 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11117 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011118 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11119 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11121 {
11122 if (loop == 0)
11123 num_normal++;
11124 else
11125 (*file)[count++] = vim_strsave((char_u *)names[match]);
11126 }
11127 }
11128 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11129 opt_idx++)
11130 {
11131 if (options[opt_idx].var == NULL)
11132 continue;
11133 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11134 && !(options[opt_idx].flags & P_BOOL))
11135 continue;
11136 is_term_opt = istermoption(&options[opt_idx]);
11137 if (is_term_opt && num_normal > 0)
11138 continue;
11139 match = FALSE;
11140 if (vim_regexec(regmatch, str, (colnr_T)0)
11141 || (options[opt_idx].shortname != NULL
11142 && vim_regexec(regmatch,
11143 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11144 match = TRUE;
11145 else if (is_term_opt)
11146 {
11147 name_buf[0] = '<';
11148 name_buf[1] = 't';
11149 name_buf[2] = '_';
11150 name_buf[3] = str[2];
11151 name_buf[4] = str[3];
11152 name_buf[5] = '>';
11153 name_buf[6] = NUL;
11154 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11155 {
11156 match = TRUE;
11157 str = name_buf;
11158 }
11159 }
11160 if (match)
11161 {
11162 if (loop == 0)
11163 {
11164 if (is_term_opt)
11165 num_term++;
11166 else
11167 num_normal++;
11168 }
11169 else
11170 (*file)[count++] = vim_strsave(str);
11171 }
11172 }
11173 /*
11174 * Check terminal key codes, these are not in the option table
11175 */
11176 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11177 {
11178 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11179 {
11180 if (!isprint(str[0]) || !isprint(str[1]))
11181 continue;
11182
11183 name_buf[0] = 't';
11184 name_buf[1] = '_';
11185 name_buf[2] = str[0];
11186 name_buf[3] = str[1];
11187 name_buf[4] = NUL;
11188
11189 match = FALSE;
11190 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11191 match = TRUE;
11192 else
11193 {
11194 name_buf[0] = '<';
11195 name_buf[1] = 't';
11196 name_buf[2] = '_';
11197 name_buf[3] = str[0];
11198 name_buf[4] = str[1];
11199 name_buf[5] = '>';
11200 name_buf[6] = NUL;
11201
11202 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11203 match = TRUE;
11204 }
11205 if (match)
11206 {
11207 if (loop == 0)
11208 num_term++;
11209 else
11210 (*file)[count++] = vim_strsave(name_buf);
11211 }
11212 }
11213
11214 /*
11215 * Check special key names.
11216 */
11217 regmatch->rm_ic = TRUE; /* ignore case here */
11218 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11219 {
11220 name_buf[0] = '<';
11221 STRCPY(name_buf + 1, str);
11222 STRCAT(name_buf, ">");
11223
11224 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11225 {
11226 if (loop == 0)
11227 num_term++;
11228 else
11229 (*file)[count++] = vim_strsave(name_buf);
11230 }
11231 }
11232 }
11233 if (loop == 0)
11234 {
11235 if (num_normal > 0)
11236 *num_file = num_normal;
11237 else if (num_term > 0)
11238 *num_file = num_term;
11239 else
11240 return OK;
11241 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11242 if (*file == NULL)
11243 {
11244 *file = (char_u **)"";
11245 return FAIL;
11246 }
11247 }
11248 }
11249 return OK;
11250}
11251
11252 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011253ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011254{
11255 char_u *var = NULL; /* init for GCC */
11256 char_u *buf;
11257
11258 *num_file = 0;
11259 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11260 if (*file == NULL)
11261 return FAIL;
11262
11263 /*
11264 * For a terminal key code expand_option_idx is < 0.
11265 */
11266 if (expand_option_idx < 0)
11267 {
11268 var = find_termcode(expand_option_name + 2);
11269 if (var == NULL)
11270 expand_option_idx = findoption(expand_option_name);
11271 }
11272
11273 if (expand_option_idx >= 0)
11274 {
11275 /* put string of option value in NameBuff */
11276 option_value2string(&options[expand_option_idx], expand_option_flags);
11277 var = NameBuff;
11278 }
11279 else if (var == NULL)
11280 var = (char_u *)"";
11281
11282 /* A backslash is required before some characters. This is the reverse of
11283 * what happens in do_set(). */
11284 buf = vim_strsave_escaped(var, escape_chars);
11285
11286 if (buf == NULL)
11287 {
11288 vim_free(*file);
11289 *file = NULL;
11290 return FAIL;
11291 }
11292
11293#ifdef BACKSLASH_IN_FILENAME
11294 /* For MS-Windows et al. we don't double backslashes at the start and
11295 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011296 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011297 if (var[0] == '\\' && var[1] == '\\'
11298 && expand_option_idx >= 0
11299 && (options[expand_option_idx].flags & P_EXPAND)
11300 && vim_isfilec(var[2])
11301 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011302 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011303#endif
11304
11305 *file[0] = buf;
11306 *num_file = 1;
11307 return OK;
11308}
11309#endif
11310
11311/*
11312 * Get the value for the numeric or string option *opp in a nice format into
11313 * NameBuff[]. Must not be called with a hidden option!
11314 */
11315 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011316option_value2string(
11317 struct vimoption *opp,
11318 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319{
11320 char_u *varp;
11321
11322 varp = get_varp_scope(opp, opt_flags);
11323
11324 if (opp->flags & P_NUM)
11325 {
11326 long wc = 0;
11327
11328 if (wc_use_keyname(varp, &wc))
11329 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11330 else if (wc != 0)
11331 STRCPY(NameBuff, transchar((int)wc));
11332 else
11333 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11334 }
11335 else /* P_STRING */
11336 {
11337 varp = *(char_u **)(varp);
11338 if (varp == NULL) /* just in case */
11339 NameBuff[0] = NUL;
11340#ifdef FEAT_CRYPT
11341 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011342 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011343 STRCPY(NameBuff, "*****");
11344#endif
11345 else if (opp->flags & P_EXPAND)
11346 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11347 /* Translate 'pastetoggle' into special key names */
11348 else if ((char_u **)opp->var == &p_pt)
11349 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11350 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011351 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011352 }
11353}
11354
11355/*
11356 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11357 * printed as a keyname.
11358 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11359 */
11360 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011361wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011362{
11363 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11364 {
11365 *wcp = *(long *)varp;
11366 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11367 return TRUE;
11368 }
11369 return FALSE;
11370}
11371
Bram Moolenaar01615492015-02-03 13:00:38 +010011372#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011373/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011374 * Any character has an equivalent 'langmap' character. This is used for
11375 * keyboards that have a special language mode that sends characters above
11376 * 128 (although other characters can be translated too). The "to" field is a
11377 * Vim command character. This avoids having to switch the keyboard back to
11378 * ASCII mode when leaving Insert mode.
11379 *
11380 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11381 * commands.
11382 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11383 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11384 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011385 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011386# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011387/*
11388 * With multi-byte support use growarray for 'langmap' chars >= 256
11389 */
11390typedef struct
11391{
11392 int from;
11393 int to;
11394} langmap_entry_T;
11395
11396static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011397static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011398
11399/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011400 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11401 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011402 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011403 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011404langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011405{
11406 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011407 int a = 0;
11408 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011409
11410 /* Do a binary search for an existing entry. */
11411 while (a != b)
11412 {
11413 int i = (a + b) / 2;
11414 int d = entries[i].from - from;
11415
11416 if (d == 0)
11417 {
11418 entries[i].to = to;
11419 return;
11420 }
11421 if (d < 0)
11422 a = i + 1;
11423 else
11424 b = i;
11425 }
11426
11427 if (ga_grow(&langmap_mapga, 1) != OK)
11428 return; /* out of memory */
11429
11430 /* insert new entry at position "a" */
11431 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11432 mch_memmove(entries + 1, entries,
11433 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11434 ++langmap_mapga.ga_len;
11435 entries[0].from = from;
11436 entries[0].to = to;
11437}
11438
11439/*
11440 * Apply 'langmap' to multi-byte character "c" and return the result.
11441 */
11442 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011443langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011444{
11445 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11446 int a = 0;
11447 int b = langmap_mapga.ga_len;
11448
11449 while (a != b)
11450 {
11451 int i = (a + b) / 2;
11452 int d = entries[i].from - c;
11453
11454 if (d == 0)
11455 return entries[i].to; /* found matching entry */
11456 if (d < 0)
11457 a = i + 1;
11458 else
11459 b = i;
11460 }
11461 return c; /* no entry found, return "c" unmodified */
11462}
11463# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011464
11465 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011466langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011467{
11468 int i;
11469
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011470 for (i = 0; i < 256; i++)
11471 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11472# ifdef FEAT_MBYTE
11473 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11474# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011475}
11476
11477/*
11478 * Called when langmap option is set; the language map can be
11479 * changed at any time!
11480 */
11481 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011482langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011483{
11484 char_u *p;
11485 char_u *p2;
11486 int from, to;
11487
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011488#ifdef FEAT_MBYTE
11489 ga_clear(&langmap_mapga); /* clear the previous map first */
11490#endif
11491 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011492
11493 for (p = p_langmap; p[0] != NUL; )
11494 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011495 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11496 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011497 {
11498 if (p2[0] == '\\' && p2[1] != NUL)
11499 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011500 }
11501 if (p2[0] == ';')
11502 ++p2; /* abcd;ABCD form, p2 points to A */
11503 else
11504 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11505 while (p[0])
11506 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011507 if (p[0] == ',')
11508 {
11509 ++p;
11510 break;
11511 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011512 if (p[0] == '\\' && p[1] != NUL)
11513 ++p;
11514#ifdef FEAT_MBYTE
11515 from = (*mb_ptr2char)(p);
11516#else
11517 from = p[0];
11518#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011519 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011520 if (p2 == NULL)
11521 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011522 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011523 if (p[0] != ',')
11524 {
11525 if (p[0] == '\\')
11526 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011527#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011528 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011529#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011530 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011532 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533 }
11534 else
11535 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011536 if (p2[0] != ',')
11537 {
11538 if (p2[0] == '\\')
11539 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011540#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011541 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011542#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011543 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011544#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011545 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546 }
11547 if (to == NUL)
11548 {
11549 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11550 transchar(from));
11551 return;
11552 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011553
11554#ifdef FEAT_MBYTE
11555 if (from >= 256)
11556 langmap_set_entry(from, to);
11557 else
11558#endif
11559 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011560
11561 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011562 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011563 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011564 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011565 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566 if (*p == ';')
11567 {
11568 p = p2;
11569 if (p[0] != NUL)
11570 {
11571 if (p[0] != ',')
11572 {
11573 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11574 return;
11575 }
11576 ++p;
11577 }
11578 break;
11579 }
11580 }
11581 }
11582 }
11583}
11584#endif
11585
11586/*
11587 * Return TRUE if format option 'x' is in effect.
11588 * Take care of no formatting when 'paste' is set.
11589 */
11590 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011591has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011592{
11593 if (p_paste)
11594 return FALSE;
11595 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11596}
11597
11598/*
11599 * Return TRUE if "x" is present in 'shortmess' option, or
11600 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11601 */
11602 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011603shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011604{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011605 return p_shm != NULL &&
11606 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011607 || (vim_strchr(p_shm, 'a') != NULL
11608 && vim_strchr((char_u *)SHM_A, x) != NULL));
11609}
11610
11611/*
11612 * paste_option_changed() - Called after p_paste was set or reset.
11613 */
11614 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011615paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616{
11617 static int old_p_paste = FALSE;
11618 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011619 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011620#ifdef FEAT_CMDL_INFO
11621 static int save_ru = 0;
11622#endif
11623#ifdef FEAT_RIGHTLEFT
11624 static int save_ri = 0;
11625 static int save_hkmap = 0;
11626#endif
11627 buf_T *buf;
11628
11629 if (p_paste)
11630 {
11631 /*
11632 * Paste switched from off to on.
11633 * Save the current values, so they can be restored later.
11634 */
11635 if (!old_p_paste)
11636 {
11637 /* save options for each buffer */
11638 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11639 {
11640 buf->b_p_tw_nopaste = buf->b_p_tw;
11641 buf->b_p_wm_nopaste = buf->b_p_wm;
11642 buf->b_p_sts_nopaste = buf->b_p_sts;
11643 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011644 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011645 }
11646
11647 /* save global options */
11648 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011649 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011650#ifdef FEAT_CMDL_INFO
11651 save_ru = p_ru;
11652#endif
11653#ifdef FEAT_RIGHTLEFT
11654 save_ri = p_ri;
11655 save_hkmap = p_hkmap;
11656#endif
11657 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011658 p_ai_nopaste = p_ai;
11659 p_et_nopaste = p_et;
11660 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011661 p_tw_nopaste = p_tw;
11662 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011663 }
11664
11665 /*
11666 * Always set the option values, also when 'paste' is set when it is
11667 * already on.
11668 */
11669 /* set options for each buffer */
11670 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11671 {
11672 buf->b_p_tw = 0; /* textwidth is 0 */
11673 buf->b_p_wm = 0; /* wrapmargin is 0 */
11674 buf->b_p_sts = 0; /* softtabstop is 0 */
11675 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011676 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011677 }
11678
11679 /* set global options */
11680 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011681 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011682#ifdef FEAT_CMDL_INFO
11683# ifdef FEAT_WINDOWS
11684 if (p_ru)
11685 status_redraw_all(); /* redraw to remove the ruler */
11686# endif
11687 p_ru = 0; /* no ruler */
11688#endif
11689#ifdef FEAT_RIGHTLEFT
11690 p_ri = 0; /* no reverse insert */
11691 p_hkmap = 0; /* no Hebrew keyboard */
11692#endif
11693 /* set global values for local buffer options */
11694 p_tw = 0;
11695 p_wm = 0;
11696 p_sts = 0;
11697 p_ai = 0;
11698 }
11699
11700 /*
11701 * Paste switched from on to off: Restore saved values.
11702 */
11703 else if (old_p_paste)
11704 {
11705 /* restore options for each buffer */
11706 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11707 {
11708 buf->b_p_tw = buf->b_p_tw_nopaste;
11709 buf->b_p_wm = buf->b_p_wm_nopaste;
11710 buf->b_p_sts = buf->b_p_sts_nopaste;
11711 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011712 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011713 }
11714
11715 /* restore global options */
11716 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011717 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011718#ifdef FEAT_CMDL_INFO
11719# ifdef FEAT_WINDOWS
11720 if (p_ru != save_ru)
11721 status_redraw_all(); /* redraw to draw the ruler */
11722# endif
11723 p_ru = save_ru;
11724#endif
11725#ifdef FEAT_RIGHTLEFT
11726 p_ri = save_ri;
11727 p_hkmap = save_hkmap;
11728#endif
11729 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011730 p_ai = p_ai_nopaste;
11731 p_et = p_et_nopaste;
11732 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011733 p_tw = p_tw_nopaste;
11734 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735 }
11736
11737 old_p_paste = p_paste;
11738}
11739
11740/*
11741 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11742 *
11743 * Reset 'compatible' and set the values for options that didn't get set yet
11744 * to the Vim defaults.
11745 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011746 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011747 */
11748 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011749vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011750{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011751 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011752 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011753 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011754
11755 if (!option_was_set((char_u *)"cp"))
11756 {
11757 p_cp = FALSE;
11758 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11759 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11760 set_option_default(opt_idx, OPT_FREE, FALSE);
11761 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011762 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011763 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011764
11765 if (fname != NULL)
11766 {
11767 p = vim_getenv(envname, &dofree);
11768 if (p == NULL)
11769 {
11770 /* Set $MYVIMRC to the first vimrc file found. */
11771 p = FullName_save(fname, FALSE);
11772 if (p != NULL)
11773 {
11774 vim_setenv(envname, p);
11775 vim_free(p);
11776 }
11777 }
11778 else if (dofree)
11779 vim_free(p);
11780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781}
11782
11783/*
11784 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11785 */
11786 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011787change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011788{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011789 int opt_idx;
11790
Bram Moolenaar071d4272004-06-13 20:20:40 +000011791 if (p_cp != on)
11792 {
11793 p_cp = on;
11794 compatible_set();
11795 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011796 opt_idx = findoption((char_u *)"cp");
11797 if (opt_idx >= 0)
11798 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799}
11800
11801/*
11802 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011803 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011804 */
11805 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011806option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807{
11808 int idx;
11809
11810 idx = findoption(name);
11811 if (idx < 0) /* unknown option */
11812 return FALSE;
11813 if (options[idx].flags & P_WAS_SET)
11814 return TRUE;
11815 return FALSE;
11816}
11817
11818/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011819 * Reset the flag indicating option "name" was set.
11820 */
11821 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011822reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011823{
11824 int idx = findoption(name);
11825
11826 if (idx >= 0)
11827 options[idx].flags &= ~P_WAS_SET;
11828}
11829
11830/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831 * compatible_set() - Called when 'compatible' has been set or unset.
11832 *
11833 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11834 * flag) to a Vi compatible value.
11835 * When 'compatible' is unset: Set all options that have a different default
11836 * for Vim (without the P_VI_DEF flag) to that default.
11837 */
11838 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011839compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840{
11841 int opt_idx;
11842
11843 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11844 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11845 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11846 set_option_default(opt_idx, OPT_FREE, p_cp);
11847 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011848 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011849}
11850
11851#ifdef FEAT_LINEBREAK
11852
11853# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11854 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011855 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856# endif
11857
11858/*
11859 * fill_breakat_flags() -- called when 'breakat' changes value.
11860 */
11861 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011862fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011863{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011864 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011865 int i;
11866
11867 for (i = 0; i < 256; i++)
11868 breakat_flags[i] = FALSE;
11869
11870 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011871 for (p = p_breakat; *p; p++)
11872 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011873}
11874
11875# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011876 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877# endif
11878
11879#endif
11880
11881/*
11882 * Check an option that can be a range of string values.
11883 *
11884 * Return OK for correct value, FAIL otherwise.
11885 * Empty is always OK.
11886 */
11887 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011888check_opt_strings(
11889 char_u *val,
11890 char **values,
11891 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011892{
11893 return opt_strings_flags(val, values, NULL, list);
11894}
11895
11896/*
11897 * Handle an option that can be a range of string values.
11898 * Set a flag in "*flagp" for each string present.
11899 *
11900 * Return OK for correct value, FAIL otherwise.
11901 * Empty is always OK.
11902 */
11903 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011904opt_strings_flags(
11905 char_u *val, /* new value */
11906 char **values, /* array of valid string values */
11907 unsigned *flagp,
11908 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011909{
11910 int i;
11911 int len;
11912 unsigned new_flags = 0;
11913
11914 while (*val)
11915 {
11916 for (i = 0; ; ++i)
11917 {
11918 if (values[i] == NULL) /* val not found in values[] */
11919 return FAIL;
11920
11921 len = (int)STRLEN(values[i]);
11922 if (STRNCMP(values[i], val, len) == 0
11923 && ((list && val[len] == ',') || val[len] == NUL))
11924 {
11925 val += len + (val[len] == ',');
11926 new_flags |= (1 << i);
11927 break; /* check next item in val list */
11928 }
11929 }
11930 }
11931 if (flagp != NULL)
11932 *flagp = new_flags;
11933
11934 return OK;
11935}
11936
11937/*
11938 * Read the 'wildmode' option, fill wim_flags[].
11939 */
11940 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011941check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011942{
11943 char_u new_wim_flags[4];
11944 char_u *p;
11945 int i;
11946 int idx = 0;
11947
11948 for (i = 0; i < 4; ++i)
11949 new_wim_flags[i] = 0;
11950
11951 for (p = p_wim; *p; ++p)
11952 {
11953 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11954 ;
11955 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11956 return FAIL;
11957 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11958 new_wim_flags[idx] |= WIM_LONGEST;
11959 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11960 new_wim_flags[idx] |= WIM_FULL;
11961 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11962 new_wim_flags[idx] |= WIM_LIST;
11963 else
11964 return FAIL;
11965 p += i;
11966 if (*p == NUL)
11967 break;
11968 if (*p == ',')
11969 {
11970 if (idx == 3)
11971 return FAIL;
11972 ++idx;
11973 }
11974 }
11975
11976 /* fill remaining entries with last flag */
11977 while (idx < 3)
11978 {
11979 new_wim_flags[idx + 1] = new_wim_flags[idx];
11980 ++idx;
11981 }
11982
11983 /* only when there are no errors, wim_flags[] is changed */
11984 for (i = 0; i < 4; ++i)
11985 wim_flags[i] = new_wim_flags[i];
11986 return OK;
11987}
11988
11989/*
11990 * Check if backspacing over something is allowed.
11991 */
11992 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011993can_bs(
11994 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011995{
11996 switch (*p_bs)
11997 {
11998 case '2': return TRUE;
11999 case '1': return (what != BS_START);
12000 case '0': return FALSE;
12001 }
12002 return vim_strchr(p_bs, what) != NULL;
12003}
12004
12005/*
12006 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12007 * the file must be considered changed when the value is different.
12008 */
12009 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012010save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012011{
12012 buf->b_start_ffc = *buf->b_p_ff;
12013 buf->b_start_eol = buf->b_p_eol;
12014#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012015 buf->b_start_bomb = buf->b_p_bomb;
12016
Bram Moolenaar071d4272004-06-13 20:20:40 +000012017 /* Only use free/alloc when necessary, they take time. */
12018 if (buf->b_start_fenc == NULL
12019 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12020 {
12021 vim_free(buf->b_start_fenc);
12022 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12023 }
12024#endif
12025}
12026
12027/*
12028 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12029 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012030 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12031 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012032 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012033 * When "ignore_empty" is true don't consider a new, empty buffer to be
12034 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012035 */
12036 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012037file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012038{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012039 /* In a buffer that was never loaded the options are not valid. */
12040 if (buf->b_flags & BF_NEVERLOADED)
12041 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012042 if (ignore_empty
12043 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012044 && buf->b_ml.ml_line_count == 1
12045 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12046 return FALSE;
12047 if (buf->b_start_ffc != *buf->b_p_ff)
12048 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012049 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 return TRUE;
12051#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012052 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12053 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012054 if (buf->b_start_fenc == NULL)
12055 return (*buf->b_p_fenc != NUL);
12056 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12057#else
12058 return FALSE;
12059#endif
12060}
12061
12062/*
12063 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12064 */
12065 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012066check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012067{
12068 return check_opt_strings(p, p_ff_values, FALSE);
12069}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012070
12071/*
12072 * Return the effective shiftwidth value for current buffer, using the
12073 * 'tabstop' value when 'shiftwidth' is zero.
12074 */
12075 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012076get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012077{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012078 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012079}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012080
12081/*
12082 * Return the effective softtabstop value for the current buffer, using the
12083 * 'tabstop' value when 'softtabstop' is negative.
12084 */
12085 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012086get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012087{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012088 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012089}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012090
12091/*
12092 * Check matchpairs option for "*initc".
12093 * If there is a match set "*initc" to the matching character and "*findc" to
12094 * the opposite character. Set "*backwards" to the direction.
12095 * When "switchit" is TRUE swap the direction.
12096 */
12097 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012098find_mps_values(
12099 int *initc,
12100 int *findc,
12101 int *backwards,
12102 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012103{
12104 char_u *ptr;
12105
12106 ptr = curbuf->b_p_mps;
12107 while (*ptr != NUL)
12108 {
12109#ifdef FEAT_MBYTE
12110 if (has_mbyte)
12111 {
12112 char_u *prev;
12113
12114 if (mb_ptr2char(ptr) == *initc)
12115 {
12116 if (switchit)
12117 {
12118 *findc = *initc;
12119 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12120 *backwards = TRUE;
12121 }
12122 else
12123 {
12124 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12125 *backwards = FALSE;
12126 }
12127 return;
12128 }
12129 prev = ptr;
12130 ptr += mb_ptr2len(ptr) + 1;
12131 if (mb_ptr2char(ptr) == *initc)
12132 {
12133 if (switchit)
12134 {
12135 *findc = *initc;
12136 *initc = mb_ptr2char(prev);
12137 *backwards = FALSE;
12138 }
12139 else
12140 {
12141 *findc = mb_ptr2char(prev);
12142 *backwards = TRUE;
12143 }
12144 return;
12145 }
12146 ptr += mb_ptr2len(ptr);
12147 }
12148 else
12149#endif
12150 {
12151 if (*ptr == *initc)
12152 {
12153 if (switchit)
12154 {
12155 *backwards = TRUE;
12156 *findc = *initc;
12157 *initc = ptr[2];
12158 }
12159 else
12160 {
12161 *backwards = FALSE;
12162 *findc = ptr[2];
12163 }
12164 return;
12165 }
12166 ptr += 2;
12167 if (*ptr == *initc)
12168 {
12169 if (switchit)
12170 {
12171 *backwards = FALSE;
12172 *findc = *initc;
12173 *initc = ptr[-2];
12174 }
12175 else
12176 {
12177 *backwards = TRUE;
12178 *findc = ptr[-2];
12179 }
12180 return;
12181 }
12182 ++ptr;
12183 }
12184 if (*ptr == ',')
12185 ++ptr;
12186 }
12187}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012188
12189#if defined(FEAT_LINEBREAK) || defined(PROTO)
12190/*
12191 * This is called when 'breakindentopt' is changed and when a window is
12192 * initialized.
12193 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012194 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012195briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012196{
12197 char_u *p;
12198 int bri_shift = 0;
12199 long bri_min = 20;
12200 int bri_sbr = FALSE;
12201
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012202 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012203 while (*p != NUL)
12204 {
12205 if (STRNCMP(p, "shift:", 6) == 0
12206 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12207 {
12208 p += 6;
12209 bri_shift = getdigits(&p);
12210 }
12211 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12212 {
12213 p += 4;
12214 bri_min = getdigits(&p);
12215 }
12216 else if (STRNCMP(p, "sbr", 3) == 0)
12217 {
12218 p += 3;
12219 bri_sbr = TRUE;
12220 }
12221 if (*p != ',' && *p != NUL)
12222 return FAIL;
12223 if (*p == ',')
12224 ++p;
12225 }
12226
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012227 wp->w_p_brishift = bri_shift;
12228 wp->w_p_brimin = bri_min;
12229 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012230
12231 return OK;
12232}
12233#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012234
12235/*
12236 * Get the local or global value of 'backupcopy'.
12237 */
12238 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012239get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012240{
12241 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12242}