blob: 648919dc74e18f97dc14320b630bcd29e3852ab3 [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 Moolenaar865242e2010-07-14 21:12:05 +02001054 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055#ifdef FEAT_MBYTE
1056 (char_u *)&p_enc, PV_NONE,
1057 {(char_u *)ENC_DFLT, (char_u *)0L}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)0L, (char_u *)0L}
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1064 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001065 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1067 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001070 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1073 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1076#ifdef FEAT_QUICKFIX
1077 (char_u *)&p_ef, PV_NONE,
1078 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1079#else
1080 (char_u *)NULL, PV_NONE,
1081 {(char_u *)NULL, (char_u *)0L}
1082#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001084 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001086 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088#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 Moolenaar071d4272004-06-13 20:20:40 +00001093 {"esckeys", "ek", P_BOOL|P_VIM,
1094 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001095 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001096 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097#ifdef FEAT_AUTOCMD
1098 (char_u *)&p_ei, PV_NONE,
1099#else
1100 (char_u *)NULL, PV_NONE,
1101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1104 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1107 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001109 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1110 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111#ifdef FEAT_MBYTE
1112 (char_u *)&p_fenc, PV_FENC,
1113 {(char_u *)"", (char_u *)0L}
1114#else
1115 (char_u *)NULL, PV_NONE,
1116 {(char_u *)0L, (char_u *)0L}
1117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001119 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120#ifdef FEAT_MBYTE
1121 (char_u *)&p_fencs, PV_NONE,
1122 {(char_u *)"ucs-bom", (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 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1129 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001132 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001134 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1135 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001136 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1137 (char_u *)&p_fic, PV_NONE,
1138 {
1139#ifdef CASE_INSENSITIVE_FILENAME
1140 (char_u *)TRUE,
1141#else
1142 (char_u *)FALSE,
1143#endif
1144 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001145 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146#ifdef FEAT_AUTOCMD
1147 (char_u *)&p_ft, PV_FT,
1148 {(char_u *)"", (char_u *)0L}
1149#else
1150 (char_u *)NULL, PV_NONE,
1151 {(char_u *)0L, (char_u *)0L}
1152#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001154 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1156 (char_u *)&p_fcs, PV_NONE,
1157 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)"", (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001163 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1164 (char_u *)&p_fixeol, PV_FIXEOL,
1165 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001166 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1167#ifdef FEAT_FKMAP
1168 (char_u *)&p_fkmap, PV_NONE,
1169#else
1170 (char_u *)NULL, PV_NONE,
1171#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173 {"flash", "fl", P_BOOL|P_VI_DEF,
1174 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001177 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001180 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1181 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001182 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1184 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1187# ifdef FEAT_EVAL
1188 (char_u *)VAR_WIN, PV_FDE,
1189 {(char_u *)"0", (char_u *)NULL}
1190# else
1191 (char_u *)NULL, PV_NONE,
1192 {(char_u *)NULL, (char_u *)0L}
1193# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1196 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1199 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001201 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001202 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001205 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001206 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001207 {(char_u *)"{{{,}}}", (char_u *)NULL}
1208 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1210 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001211 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1213 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001214 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1216 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001218 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)&p_fdo, PV_NONE,
1220 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1223# ifdef FEAT_EVAL
1224 (char_u *)VAR_WIN, PV_FDT,
1225 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001226# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 (char_u *)NULL, PV_NONE,
1228 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001229# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001232 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001233#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001234 (char_u *)&p_fex, PV_FEX,
1235 {(char_u *)"", (char_u *)0L}
1236#else
1237 (char_u *)NULL, PV_NONE,
1238 {(char_u *)0L, (char_u *)0L}
1239#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001240 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1242 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001243 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1244 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001245 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1246 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001247 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1248 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1250 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001251 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001252 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1253#ifdef HAVE_FSYNC
1254 (char_u *)&p_fs, PV_NONE,
1255 {(char_u *)TRUE, (char_u *)0L}
1256#else
1257 (char_u *)NULL, PV_NONE,
1258 {(char_u *)FALSE, (char_u *)0L}
1259#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1262 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 {"graphic", "gr", P_BOOL|P_VI_DEF,
1265 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001267 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268#ifdef FEAT_QUICKFIX
1269 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001270 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)NULL, (char_u *)0L}
1274#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1277#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001278 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001279 {
1280# ifdef WIN3264
1281 /* may be changed to "grep -n" in os_win32.c */
1282 (char_u *)"findstr /n",
1283# else
1284# ifdef UNIX
1285 /* Add an extra file name so that grep will always
1286 * insert a file name in the match line. */
1287 (char_u *)"grep -n $* /dev/null",
1288# else
1289# ifdef VMS
1290 (char_u *)"SEARCH/NUMBERS ",
1291# else
1292 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001293# endif
1294# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001296 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)NULL, (char_u *)0L}
1300#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001301 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001302 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303#ifdef CURSOR_SHAPE
1304 (char_u *)&p_guicursor, PV_NONE,
1305 {
1306# ifdef FEAT_GUI
1307 (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 +01001308# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1310# endif
1311 (char_u *)0L}
1312#else
1313 (char_u *)NULL, PV_NONE,
1314 {(char_u *)NULL, (char_u *)0L}
1315#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001316 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001317 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318#ifdef FEAT_GUI
1319 (char_u *)&p_guifont, PV_NONE,
1320 {(char_u *)"", (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 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1328 (char_u *)&p_guifontset, 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 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1337 (char_u *)&p_guifontwide, 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 Moolenaar071d4272004-06-13 20:20:40 +00001344 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001345#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001346 (char_u *)&p_ghr, PV_NONE,
1347#else
1348 (char_u *)NULL, PV_NONE,
1349#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001352#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 (char_u *)&p_go, PV_NONE,
1354# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001355 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001357 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358# endif
1359#else
1360 (char_u *)NULL, PV_NONE,
1361 {(char_u *)NULL, (char_u *)0L}
1362#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001363 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364 {"guipty", NULL, P_BOOL|P_VI_DEF,
1365#if defined(FEAT_GUI)
1366 (char_u *)&p_guipty, PV_NONE,
1367#else
1368 (char_u *)NULL, PV_NONE,
1369#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001370 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001371 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001372#if defined(FEAT_GUI_TABLINE)
1373 (char_u *)&p_gtl, PV_NONE,
1374 {(char_u *)"", (char_u *)0L}
1375#else
1376 (char_u *)NULL, PV_NONE,
1377 {(char_u *)NULL, (char_u *)0L}
1378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001380 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001381#if defined(FEAT_GUI_TABLINE)
1382 (char_u *)&p_gtt, 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 Moolenaar071d4272004-06-13 20:20:40 +00001389 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1390 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1393 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1395 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 {"helpheight", "hh", P_NUM|P_VI_DEF,
1397#ifdef FEAT_WINDOWS
1398 (char_u *)&p_hh, PV_NONE,
1399#else
1400 (char_u *)NULL, PV_NONE,
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001403 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#ifdef FEAT_MULTI_LANG
1405 (char_u *)&p_hlg, PV_NONE,
1406 {(char_u *)"", (char_u *)0L}
1407#else
1408 (char_u *)NULL, PV_NONE,
1409 {(char_u *)0L, (char_u *)0L}
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"hidden", "hid", P_BOOL|P_VI_DEF,
1413 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1418 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 {"history", "hi", P_NUM|P_VIM,
1420 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001421 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001422 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1423#ifdef FEAT_RIGHTLEFT
1424 (char_u *)&p_hkmap, PV_NONE,
1425#else
1426 (char_u *)NULL, PV_NONE,
1427#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001428 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1430#ifdef FEAT_RIGHTLEFT
1431 (char_u *)&p_hkmapp, PV_NONE,
1432#else
1433 (char_u *)NULL, PV_NONE,
1434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1437 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001438 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001439 {"icon", NULL, P_BOOL|P_VI_DEF,
1440#ifdef FEAT_TITLE
1441 (char_u *)&p_icon, PV_NONE,
1442#else
1443 (char_u *)NULL, PV_NONE,
1444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001445 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001446 {"iconstring", NULL, P_STRING|P_VI_DEF,
1447#ifdef FEAT_TITLE
1448 (char_u *)&p_iconstring, PV_NONE,
1449#else
1450 (char_u *)NULL, PV_NONE,
1451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1454 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001455 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001456 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1457# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1458 (char_u *)&p_imaf, PV_NONE,
1459 {(char_u *)"", (char_u *)NULL}
1460# else
1461 (char_u *)NULL, PV_NONE,
1462 {(char_u *)NULL, (char_u *)0L}
1463# endif
1464 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001466#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467 (char_u *)&p_imak, PV_NONE,
1468#else
1469 (char_u *)NULL, PV_NONE,
1470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1473#ifdef USE_IM_CONTROL
1474 (char_u *)&p_imcmdline, PV_NONE,
1475#else
1476 (char_u *)NULL, PV_NONE,
1477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1480#ifdef USE_IM_CONTROL
1481 (char_u *)&p_imdisable, PV_NONE,
1482#else
1483 (char_u *)NULL, PV_NONE,
1484#endif
1485#ifdef __sgi
1486 {(char_u *)TRUE, (char_u *)0L}
1487#else
1488 {(char_u *)FALSE, (char_u *)0L}
1489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"iminsert", "imi", P_NUM|P_VI_DEF,
1492 (char_u *)&p_iminsert, PV_IMI,
1493#ifdef B_IMODE_IM
1494 {(char_u *)B_IMODE_IM, (char_u *)0L}
1495#else
1496 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001498 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"imsearch", "ims", P_NUM|P_VI_DEF,
1500 (char_u *)&p_imsearch, PV_IMS,
1501#ifdef B_IMODE_IM
1502 {(char_u *)B_IMODE_IM, (char_u *)0L}
1503#else
1504 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001506 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001507 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001508# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1509 (char_u *)&p_imsf, PV_NONE,
1510 {(char_u *)"", (char_u *)NULL}
1511# else
1512 (char_u *)NULL, PV_NONE,
1513 {(char_u *)NULL, (char_u *)0L}
1514# endif
1515 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1517#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001518 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1520#else
1521 (char_u *)NULL, PV_NONE,
1522 {(char_u *)0L, (char_u *)0L}
1523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001524 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1526#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1527 (char_u *)&p_inex, PV_INEX,
1528 {(char_u *)"", (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 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1535 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1538#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1539 (char_u *)&p_inde, PV_INDE,
1540 {(char_u *)"", (char_u *)0L}
1541#else
1542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)0L, (char_u *)0L}
1544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001546 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1548 (char_u *)&p_indk, PV_INDK,
1549 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (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 Moolenaar071d4272004-06-13 20:20:40 +00001555 {"infercase", "inf", P_BOOL|P_VI_DEF,
1556 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1559 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1562 (char_u *)&p_isf, PV_NONE,
1563 {
1564#ifdef BACKSLASH_IN_FILENAME
1565 /* Excluded are: & and ^ are special in cmd.exe
1566 * ( and ) are used in text separating fnames */
1567 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1568#else
1569# ifdef AMIGA
1570 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1571# else
1572# ifdef VMS
1573 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1574# else /* UNIX et al. */
1575# ifdef EBCDIC
1576 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1577# else
1578 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1579# endif
1580# endif
1581# endif
1582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001583 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1585 (char_u *)&p_isi, PV_NONE,
1586 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001587#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588 (char_u *)"@,48-57,_,128-167,224-235",
1589#else
1590# ifdef EBCDIC
1591 /* TODO: EBCDIC Check this! @ == isalpha()*/
1592 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1593 "112-120,128,140-142,156,158,172,"
1594 "174,186,191,203-207,219-225,235-239,"
1595 "251-254",
1596# else
1597 (char_u *)"@,48-57,_,192-255",
1598# endif
1599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001600 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001601 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1602 (char_u *)&p_isk, PV_ISK,
1603 {
1604#ifdef EBCDIC
1605 (char_u *)"@,240-249,_",
1606 /* TODO: EBCDIC Check this! @ == isalpha()*/
1607 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1608 "112-120,128,140-142,156,158,172,"
1609 "174,186,191,203-207,219-225,235-239,"
1610 "251-254",
1611#else
1612 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001613# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614 (char_u *)"@,48-57,_,128-167,224-235"
1615# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001616 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617# endif
1618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001619 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1621 (char_u *)&p_isp, PV_NONE,
1622 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001623#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624 || defined(VMS)
1625 (char_u *)"@,~-255",
1626#else
1627# ifdef EBCDIC
1628 /* all chars above 63 are printable */
1629 (char_u *)"63-255",
1630# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001631 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632# endif
1633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1636 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1639#ifdef FEAT_CRYPT
1640 (char_u *)&p_key, PV_KEY,
1641 {(char_u *)"", (char_u *)0L}
1642#else
1643 (char_u *)NULL, PV_NONE,
1644 {(char_u *)0L, (char_u *)0L}
1645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001647 {"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 +00001648#ifdef FEAT_KEYMAP
1649 (char_u *)&p_keymap, PV_KMAP,
1650 {(char_u *)"", (char_u *)0L}
1651#else
1652 (char_u *)NULL, PV_NONE,
1653 {(char_u *)"", (char_u *)0L}
1654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001656 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001660 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001662#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 (char_u *)":help",
1664#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001665# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001667# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001668# ifdef USEMAN_S
1669 (char_u *)"man -s",
1670# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001672# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673# endif
1674#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001675 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001676 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677#ifdef FEAT_LANGMAP
1678 (char_u *)&p_langmap, PV_NONE,
1679 {(char_u *)"", /* unmatched } */
1680#else
1681 (char_u *)NULL, PV_NONE,
1682 {(char_u *)NULL,
1683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001684 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001685 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1687 (char_u *)&p_lm, PV_NONE,
1688#else
1689 (char_u *)NULL, PV_NONE,
1690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001691 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001692 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1693#ifdef FEAT_LANGMAP
1694 (char_u *)&p_lnr, PV_NONE,
1695#else
1696 (char_u *)NULL, PV_NONE,
1697#endif
1698 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1700#ifdef FEAT_WINDOWS
1701 (char_u *)&p_ls, PV_NONE,
1702#else
1703 (char_u *)NULL, PV_NONE,
1704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1707 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001708 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1710#ifdef FEAT_LINEBREAK
1711 (char_u *)VAR_WIN, PV_LBR,
1712#else
1713 (char_u *)NULL, PV_NONE,
1714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001715 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1717 (char_u *)&Rows, PV_NONE,
1718 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001719#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 (char_u *)25L,
1721#else
1722 (char_u *)24L,
1723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1726#ifdef FEAT_GUI
1727 (char_u *)&p_linespace, PV_NONE,
1728#else
1729 (char_u *)NULL, PV_NONE,
1730#endif
1731#ifdef FEAT_GUI_W32
1732 {(char_u *)1L, (char_u *)0L}
1733#else
1734 {(char_u *)0L, (char_u *)0L}
1735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001736 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {"lisp", NULL, P_BOOL|P_VI_DEF,
1738#ifdef FEAT_LISP
1739 (char_u *)&p_lisp, PV_LISP,
1740#else
1741 (char_u *)NULL, PV_NONE,
1742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001744 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001746 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1748#else
1749 (char_u *)NULL, PV_NONE,
1750 {(char_u *)"", (char_u *)0L}
1751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1754 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001755 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001756 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001758 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1760 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001761 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001762#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001763 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1764 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001765 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1766 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001767#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001768#ifdef FEAT_GUI_MAC
1769 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1770 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001772#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {"magic", NULL, P_BOOL|P_VI_DEF,
1774 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001775 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001776 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777#ifdef FEAT_QUICKFIX
1778 (char_u *)&p_mef, PV_NONE,
1779 {(char_u *)"", (char_u *)0L}
1780#else
1781 (char_u *)NULL, PV_NONE,
1782 {(char_u *)NULL, (char_u *)0L}
1783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1786#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001787 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788# ifdef VMS
1789 {(char_u *)"MMS", (char_u *)0L}
1790# else
1791 {(char_u *)"make", (char_u *)0L}
1792# endif
1793#else
1794 (char_u *)NULL, PV_NONE,
1795 {(char_u *)NULL, (char_u *)0L}
1796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001797 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001798 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001800 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1801 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001802 {"matchtime", "mat", P_NUM|P_VI_DEF,
1803 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001804 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001805 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001806#ifdef FEAT_MBYTE
1807 (char_u *)&p_mco, PV_NONE,
1808#else
1809 (char_u *)NULL, PV_NONE,
1810#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001811 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1813#ifdef FEAT_EVAL
1814 (char_u *)&p_mfd, PV_NONE,
1815#else
1816 (char_u *)NULL, PV_NONE,
1817#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001818 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1820 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {"maxmem", "mm", P_NUM|P_VI_DEF,
1823 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1825 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001826 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1827 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001828 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1830 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1832 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"menuitems", "mis", P_NUM|P_VI_DEF,
1834#ifdef FEAT_MENU
1835 (char_u *)&p_mis, PV_NONE,
1836#else
1837 (char_u *)NULL, PV_NONE,
1838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001839 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840 {"mesg", NULL, P_BOOL|P_VI_DEF,
1841 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001843 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001844#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001845 (char_u *)&p_msm, PV_NONE,
1846 {(char_u *)"460000,2000,500", (char_u *)0L}
1847#else
1848 (char_u *)NULL, PV_NONE,
1849 {(char_u *)0L, (char_u *)0L}
1850#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"modeline", "ml", P_BOOL|P_VIM,
1853 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001854 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 {"modelines", "mls", P_NUM|P_VI_DEF,
1856 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001857 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1859 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1862 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"more", NULL, P_BOOL|P_VIM,
1865 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1868 (char_u *)&p_mouse, PV_NONE,
1869 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001870#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 (char_u *)"a",
1872#else
1873 (char_u *)"",
1874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1877#ifdef FEAT_GUI
1878 (char_u *)&p_mousef, PV_NONE,
1879#else
1880 (char_u *)NULL, PV_NONE,
1881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1884#ifdef FEAT_GUI
1885 (char_u *)&p_mh, PV_NONE,
1886#else
1887 (char_u *)NULL, PV_NONE,
1888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001889 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1891 (char_u *)&p_mousem, PV_NONE,
1892 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001893#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 (char_u *)"popup",
1895#else
1896# if defined(MACOS)
1897 (char_u *)"popup_setpos",
1898# else
1899 (char_u *)"extend",
1900# endif
1901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001903 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001904#ifdef FEAT_MOUSESHAPE
1905 (char_u *)&p_mouseshape, PV_NONE,
1906 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1907#else
1908 (char_u *)NULL, PV_NONE,
1909 {(char_u *)NULL, (char_u *)0L}
1910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1913 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001914 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001915 {"mzquantum", "mzq", P_NUM,
1916#ifdef FEAT_MZSCHEME
1917 (char_u *)&p_mzq, PV_NONE,
1918#else
1919 (char_u *)NULL, PV_NONE,
1920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001921 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 {"novice", NULL, P_BOOL|P_VI_DEF,
1923 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001925 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001927 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1930 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001931 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001932 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1933#ifdef FEAT_LINEBREAK
1934 (char_u *)VAR_WIN, PV_NUW,
1935#else
1936 (char_u *)NULL, PV_NONE,
1937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001939 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001940#ifdef FEAT_COMPL_FUNC
1941 (char_u *)&p_ofu, PV_OFU,
1942 {(char_u *)"", (char_u *)0L}
1943#else
1944 (char_u *)NULL, PV_NONE,
1945 {(char_u *)0L, (char_u *)0L}
1946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"open", NULL, P_BOOL|P_VI_DEF,
1949 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001950 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001951 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001952#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001953 (char_u *)&p_odev, PV_NONE,
1954#else
1955 (char_u *)NULL, PV_NONE,
1956#endif
1957 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001959 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1960 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"optimize", "opt", P_BOOL|P_VI_DEF,
1963 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001967 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001968 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1969 |P_SECURE,
1970 (char_u *)&p_pp, PV_NONE,
1971 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
1972 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"paragraphs", "para", P_STRING|P_VI_DEF,
1974 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001975 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001976 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001977 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1981 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1984#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1985 (char_u *)&p_pex, PV_NONE,
1986 {(char_u *)"", (char_u *)0L}
1987#else
1988 (char_u *)NULL, PV_NONE,
1989 {(char_u *)0L, (char_u *)0L}
1990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001992 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001993 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001996 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001998#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 (char_u *)".,,",
2000#else
2001# if defined(__EMX__)
2002 (char_u *)".,/emx/include,,",
2003# else /* Unix, probably */
2004 (char_u *)".,/usr/include,,",
2005# endif
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002008#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002009 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2010 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002011 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2012 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002013#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002014 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2015 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002016 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002017 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2019 (char_u *)&p_pvh, PV_NONE,
2020#else
2021 (char_u *)NULL, PV_NONE,
2022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002023 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2025#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2026 (char_u *)VAR_WIN, PV_PVW,
2027#else
2028 (char_u *)NULL, PV_NONE,
2029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002030 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002031 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032#ifdef FEAT_PRINTER
2033 (char_u *)&p_pdev, PV_NONE,
2034 {(char_u *)"", (char_u *)0L}
2035#else
2036 (char_u *)NULL, PV_NONE,
2037 {(char_u *)NULL, (char_u *)0L}
2038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002039 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 {"printencoding", "penc", P_STRING|P_VI_DEF,
2041#ifdef FEAT_POSTSCRIPT
2042 (char_u *)&p_penc, 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 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2050#ifdef FEAT_POSTSCRIPT
2051 (char_u *)&p_pexpr, 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 {"printfont", "pfn", P_STRING|P_VI_DEF,
2059#ifdef FEAT_PRINTER
2060 (char_u *)&p_pfn, PV_NONE,
2061 {
2062# ifdef MSWIN
2063 (char_u *)"Courier_New:h10",
2064# else
2065 (char_u *)"courier",
2066# endif
2067 (char_u *)0L}
2068#else
2069 (char_u *)NULL, PV_NONE,
2070 {(char_u *)NULL, (char_u *)0L}
2071#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2074#ifdef FEAT_PRINTER
2075 (char_u *)&p_header, PV_NONE,
2076 {(char_u *)N_("%<%f%h%m%=Page %N"), (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 Moolenaar8299df92004-07-10 09:47:34 +00002082 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2083#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2084 (char_u *)&p_pmcs, PV_NONE,
2085 {(char_u *)"", (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 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2092#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2093 (char_u *)&p_pmfn, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002100 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002101#ifdef FEAT_PRINTER
2102 (char_u *)&p_popt, 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 Moolenaar071d4272004-06-13 20:20:40 +00002109 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002110 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002112 {"pumheight", "ph", P_NUM|P_VI_DEF,
2113#ifdef FEAT_INS_EXPAND
2114 (char_u *)&p_ph, PV_NONE,
2115#else
2116 (char_u *)NULL, PV_NONE,
2117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002118 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002119#if defined(DYNAMIC_PYTHON3)
Bram Moolenaar0796c062015-11-10 19:41:37 +01002120 {"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002121 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002122 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2123 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002124#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002125#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002126 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2127 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002128 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2129 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002130#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002131 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2132#ifdef FEAT_TEXTOBJ
2133 (char_u *)&p_qe, PV_QE,
2134 {(char_u *)"\\", (char_u *)0L}
2135#else
2136 (char_u *)NULL, PV_NONE,
2137 {(char_u *)NULL, (char_u *)0L}
2138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002139 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2141 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002142 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143 {"redraw", NULL, P_BOOL|P_VI_DEF,
2144 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002146 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2147#ifdef FEAT_RELTIME
2148 (char_u *)&p_rdt, PV_NONE,
2149#else
2150 (char_u *)NULL, PV_NONE,
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002153 {"regexpengine", "re", P_NUM|P_VI_DEF,
2154 (char_u *)&p_re, PV_NONE,
2155 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002156 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2157 (char_u *)VAR_WIN, PV_RNU,
2158 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002159 {"remap", NULL, P_BOOL|P_VI_DEF,
2160 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002161 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002162 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002163#ifdef FEAT_RENDER_OPTIONS
2164 (char_u *)&p_rop, PV_NONE,
2165 {(char_u *)"", (char_u *)0L}
2166#else
2167 (char_u *)NULL, PV_NONE,
2168 {(char_u *)NULL, (char_u *)0L}
2169#endif
2170 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 {"report", NULL, P_NUM|P_VI_DEF,
2172 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002173 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2175#ifdef WIN3264
2176 (char_u *)&p_rs, PV_NONE,
2177#else
2178 (char_u *)NULL, PV_NONE,
2179#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002180 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2182#ifdef FEAT_RIGHTLEFT
2183 (char_u *)&p_ri, PV_NONE,
2184#else
2185 (char_u *)NULL, PV_NONE,
2186#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2189#ifdef FEAT_RIGHTLEFT
2190 (char_u *)VAR_WIN, PV_RL,
2191#else
2192 (char_u *)NULL, PV_NONE,
2193#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002194 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002195 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2196#ifdef FEAT_RIGHTLEFT
2197 (char_u *)VAR_WIN, PV_RLC,
2198 {(char_u *)"search", (char_u *)NULL}
2199#else
2200 (char_u *)NULL, PV_NONE,
2201 {(char_u *)NULL, (char_u *)0L}
2202#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002203 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002204#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002205 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2206 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002207 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2208 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002209#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002210 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2211#ifdef FEAT_CMDL_INFO
2212 (char_u *)&p_ru, PV_NONE,
2213#else
2214 (char_u *)NULL, PV_NONE,
2215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2218#ifdef FEAT_STL_OPT
2219 (char_u *)&p_ruf, PV_NONE,
2220#else
2221 (char_u *)NULL, PV_NONE,
2222#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002223 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002224 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2225 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002227 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2228 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2230 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002231 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2233#ifdef FEAT_SCROLLBIND
2234 (char_u *)VAR_WIN, PV_SCBIND,
2235#else
2236 (char_u *)NULL, PV_NONE,
2237#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002238 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2240 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2243 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002244 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002245 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002246#ifdef FEAT_SCROLLBIND
2247 (char_u *)&p_sbo, PV_NONE,
2248 {(char_u *)"ver,jump", (char_u *)0L}
2249#else
2250 (char_u *)NULL, PV_NONE,
2251 {(char_u *)0L, (char_u *)0L}
2252#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 {"sections", "sect", P_STRING|P_VI_DEF,
2255 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002256 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2257 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2259 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002260 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002261 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002263 {(char_u *)"inclusive", (char_u *)0L}
2264 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002265 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002267 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002268 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269#ifdef FEAT_SESSION
2270 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002271 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 (char_u *)0L}
2273#else
2274 (char_u *)NULL, PV_NONE,
2275 {(char_u *)0L, (char_u *)0L}
2276#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002277 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2279 (char_u *)&p_sh, PV_NONE,
2280 {
2281#ifdef VMS
2282 (char_u *)"-",
2283#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002284# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002286# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288# endif
2289#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2292 (char_u *)&p_shcf, PV_NONE,
2293 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002294#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 (char_u *)"/c",
2296#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002299 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2301#ifdef FEAT_QUICKFIX
2302 (char_u *)&p_sp, PV_NONE,
2303 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002304#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306#else
2307 (char_u *)">",
2308#endif
2309 (char_u *)0L}
2310#else
2311 (char_u *)NULL, PV_NONE,
2312 {(char_u *)0L, (char_u *)0L}
2313#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2316 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2319 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2322#ifdef BACKSLASH_IN_FILENAME
2323 (char_u *)&p_ssl, PV_NONE,
2324#else
2325 (char_u *)NULL, PV_NONE,
2326#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002328 {"shelltemp", "stmp", P_BOOL,
2329 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"shelltype", "st", P_NUM|P_VI_DEF,
2332#ifdef AMIGA
2333 (char_u *)&p_st, PV_NONE,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2339 (char_u *)&p_sxq, PV_NONE,
2340 {
2341#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2342 (char_u *)"\"",
2343#else
2344 (char_u *)"",
2345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002347 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2348 (char_u *)&p_sxe, PV_NONE,
2349 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002350#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002351 (char_u *)"\"&|<>()@^",
2352#else
2353 (char_u *)"",
2354#endif
2355 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2357 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2360 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2363 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)"", (char_u *)"filnxtToO"}
2365 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2370#ifdef FEAT_LINEBREAK
2371 (char_u *)&p_sbr, PV_NONE,
2372#else
2373 (char_u *)NULL, PV_NONE,
2374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"showcmd", "sc", P_BOOL|P_VIM,
2377#ifdef FEAT_CMDL_INFO
2378 (char_u *)&p_sc, PV_NONE,
2379#else
2380 (char_u *)NULL, PV_NONE,
2381#endif
2382 {(char_u *)FALSE,
2383#ifdef UNIX
2384 (char_u *)FALSE
2385#else
2386 (char_u *)TRUE
2387#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2390 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2393 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"showmode", "smd", P_BOOL|P_VIM,
2396 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002397 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002398 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2399#ifdef FEAT_WINDOWS
2400 (char_u *)&p_stal, PV_NONE,
2401#else
2402 (char_u *)NULL, PV_NONE,
2403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2406 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2409 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2412 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2415 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2418#ifdef FEAT_SMARTINDENT
2419 (char_u *)&p_si, PV_SI,
2420#else
2421 (char_u *)NULL, PV_NONE,
2422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2425 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2428 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2431 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002433 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002434#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002435 (char_u *)VAR_WIN, PV_SPELL,
2436#else
2437 (char_u *)NULL, PV_NONE,
2438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002440 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002441#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002442 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002443 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002444#else
2445 (char_u *)NULL, PV_NONE,
2446 {(char_u *)0L, (char_u *)0L}
2447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002449 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2450 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002451#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002452 (char_u *)&p_spf, PV_SPF,
2453 {(char_u *)"", (char_u *)0L}
2454#else
2455 (char_u *)NULL, PV_NONE,
2456 {(char_u *)0L, (char_u *)0L}
2457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002459 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2460 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002461#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002462 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002463 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002464#else
2465 (char_u *)NULL, PV_NONE,
2466 {(char_u *)0L, (char_u *)0L}
2467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002469 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002470#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002471 (char_u *)&p_sps, PV_NONE,
2472 {(char_u *)"best", (char_u *)0L}
2473#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 Moolenaar071d4272004-06-13 20:20:40 +00002478 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2479#ifdef FEAT_WINDOWS
2480 (char_u *)&p_sb, PV_NONE,
2481#else
2482 (char_u *)NULL, PV_NONE,
2483#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002484 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 {"splitright", "spr", P_BOOL|P_VI_DEF,
2486#ifdef FEAT_VERTSPLIT
2487 (char_u *)&p_spr, PV_NONE,
2488#else
2489 (char_u *)NULL, PV_NONE,
2490#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002491 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2493 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002494 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2496#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002497 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498#else
2499 (char_u *)NULL, PV_NONE,
2500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002502 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 (char_u *)&p_su, PV_NONE,
2504 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002506 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002507#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 (char_u *)&p_sua, PV_SUA,
2509 {(char_u *)"", (char_u *)0L}
2510#else
2511 (char_u *)NULL, PV_NONE,
2512 {(char_u *)0L, (char_u *)0L}
2513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2516 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002517 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 {"swapsync", "sws", P_STRING|P_VI_DEF,
2519 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002521 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002524 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2525#ifdef FEAT_SYN_HL
2526 (char_u *)&p_smc, PV_SMC,
2527 {(char_u *)3000L, (char_u *)0L}
2528#else
2529 (char_u *)NULL, PV_NONE,
2530 {(char_u *)0L, (char_u *)0L}
2531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002533 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534#ifdef FEAT_SYN_HL
2535 (char_u *)&p_syn, PV_SYN,
2536 {(char_u *)"", (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 Moolenaarfaa959a2006-02-20 21:37:40 +00002542 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2543#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002544 (char_u *)&p_tal, PV_NONE,
2545#else
2546 (char_u *)NULL, PV_NONE,
2547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002548 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002549 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2550#ifdef FEAT_WINDOWS
2551 (char_u *)&p_tpm, PV_NONE,
2552#else
2553 (char_u *)NULL, PV_NONE,
2554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2557 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2560 (char_u *)&p_tbs, PV_NONE,
2561#ifdef VMS /* binary searching doesn't appear to work on VMS */
2562 {(char_u *)0L, (char_u *)0L}
2563#else
2564 {(char_u *)TRUE, (char_u *)0L}
2565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002567 {"tagcase", "tc", P_STRING|P_VIM,
2568 (char_u *)&p_tc, PV_TC,
2569 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"taglength", "tl", P_NUM|P_VI_DEF,
2571 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"tagrelative", "tr", P_BOOL|P_VIM,
2574 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002576 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002577 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 {
2579#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2580 (char_u *)"./tags,./TAGS,tags,TAGS",
2581#else
2582 (char_u *)"./tags,tags",
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2586 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002588#if defined(DYNAMIC_TCL)
2589 {"tcldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2590 (char_u *)&p_tcldll, PV_NONE,
2591 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2592 SCRIPTID_INIT},
2593#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2595 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2598#ifdef FEAT_ARABIC
2599 (char_u *)&p_tbidi, PV_NONE,
2600#else
2601 (char_u *)NULL, PV_NONE,
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2605#ifdef FEAT_MBYTE
2606 (char_u *)&p_tenc, PV_NONE,
2607 {(char_u *)"", (char_u *)0L}
2608#else
2609 (char_u *)NULL, PV_NONE,
2610 {(char_u *)0L, (char_u *)0L}
2611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002612 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 {"terse", NULL, P_BOOL|P_VI_DEF,
2614 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002615 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 {"textauto", "ta", P_BOOL|P_VIM,
2617 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2621 (char_u *)&p_tx, PV_TX,
2622 {
2623#ifdef USE_CRNL
2624 (char_u *)TRUE,
2625#else
2626 (char_u *)FALSE,
2627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002629 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002632 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002634 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635#else
2636 (char_u *)NULL, PV_NONE,
2637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002638 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2640 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002641 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"timeout", "to", P_BOOL|P_VI_DEF,
2643 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2646 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"title", NULL, P_BOOL|P_VI_DEF,
2649#ifdef FEAT_TITLE
2650 (char_u *)&p_title, PV_NONE,
2651#else
2652 (char_u *)NULL, PV_NONE,
2653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"titlelen", NULL, P_NUM|P_VI_DEF,
2656#ifdef FEAT_TITLE
2657 (char_u *)&p_titlelen, PV_NONE,
2658#else
2659 (char_u *)NULL, PV_NONE,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002662 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663#ifdef FEAT_TITLE
2664 (char_u *)&p_titleold, PV_NONE,
2665 {(char_u *)N_("Thanks for flying Vim"),
2666 (char_u *)0L}
2667#else
2668 (char_u *)NULL, PV_NONE,
2669 {(char_u *)0L, (char_u *)0L}
2670#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"titlestring", NULL, P_STRING|P_VI_DEF,
2673#ifdef FEAT_TITLE
2674 (char_u *)&p_titlestring, PV_NONE,
2675#else
2676 (char_u *)NULL, PV_NONE,
2677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002680 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)"icons,tooltips", (char_u *)0L}
2683 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002685#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2687 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002688 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689#endif
2690 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2691 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002692 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2694 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2697 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2700 (char_u *)&p_tf, 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 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2703#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2704 (char_u *)&p_ttym, PV_NONE,
2705#else
2706 (char_u *)NULL, PV_NONE,
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2710 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2713 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002715 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2716 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002717#ifdef FEAT_PERSISTENT_UNDO
2718 (char_u *)&p_udir, PV_NONE,
2719 {(char_u *)".", (char_u *)0L}
2720#else
2721 (char_u *)NULL, PV_NONE,
2722 {(char_u *)0L, (char_u *)0L}
2723#endif
2724 SCRIPTID_INIT},
2725 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2726#ifdef FEAT_PERSISTENT_UNDO
2727 (char_u *)&p_udf, PV_UDF,
2728#else
2729 (char_u *)NULL, PV_NONE,
2730#endif
2731 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002733 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002735#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 (char_u *)1000L,
2737#else
2738 (char_u *)100L,
2739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002741 {"undoreload", "ur", P_NUM|P_VI_DEF,
2742 (char_u *)&p_ur, PV_NONE,
2743 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744 {"updatecount", "uc", P_NUM|P_VI_DEF,
2745 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"updatetime", "ut", P_NUM|P_VI_DEF,
2748 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"verbose", "vbs", P_NUM|P_VI_DEF,
2751 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002752 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002753 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2754 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2757#ifdef FEAT_SESSION
2758 (char_u *)&p_vdir, PV_NONE,
2759 {(char_u *)DFLT_VDIR, (char_u *)0L}
2760#else
2761 (char_u *)NULL, PV_NONE,
2762 {(char_u *)0L, (char_u *)0L}
2763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002765 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766#ifdef FEAT_SESSION
2767 (char_u *)&p_vop, PV_NONE,
2768 {(char_u *)"folds,options,cursor", (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 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775#ifdef FEAT_VIMINFO
2776 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002777#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002778 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779#else
2780# ifdef AMIGA
2781 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002782 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002784 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785# endif
2786#endif
2787#else
2788 (char_u *)NULL, PV_NONE,
2789 {(char_u *)0L, (char_u *)0L}
2790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002792 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2793 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794#ifdef FEAT_VIRTUALEDIT
2795 (char_u *)&p_ve, PV_NONE,
2796 {(char_u *)"", (char_u *)""}
2797#else
2798 (char_u *)NULL, PV_NONE,
2799 {(char_u *)0L, (char_u *)0L}
2800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002801 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2803 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"w300", NULL, P_NUM|P_VI_DEF,
2806 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"w1200", NULL, P_NUM|P_VI_DEF,
2809 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"w9600", NULL, P_NUM|P_VI_DEF,
2812 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"warn", NULL, P_BOOL|P_VI_DEF,
2815 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2818 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002820 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"wildchar", "wc", P_NUM|P_VIM,
2824 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2826 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002827 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002830 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831#ifdef FEAT_WILDIGN
2832 (char_u *)&p_wig, PV_NONE,
2833#else
2834 (char_u *)NULL, PV_NONE,
2835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002837 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2838 (char_u *)&p_wic, PV_NONE,
2839 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2841#ifdef FEAT_WILDMENU
2842 (char_u *)&p_wmnu, PV_NONE,
2843#else
2844 (char_u *)NULL, PV_NONE,
2845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002847 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002850 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2851#ifdef FEAT_CMDL_COMPL
2852 (char_u *)&p_wop, PV_NONE,
2853 {(char_u *)"", (char_u *)0L}
2854#else
2855 (char_u *)NULL, PV_NONE,
2856 {(char_u *)NULL, (char_u *)0L}
2857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2860#ifdef FEAT_WAK
2861 (char_u *)&p_wak, PV_NONE,
2862 {(char_u *)"menu", (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 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002869 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"winheight", "wh", P_NUM|P_VI_DEF,
2872#ifdef FEAT_WINDOWS
2873 (char_u *)&p_wh, PV_NONE,
2874#else
2875 (char_u *)NULL, PV_NONE,
2876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002877 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002879#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 (char_u *)VAR_WIN, PV_WFH,
2881#else
2882 (char_u *)NULL, PV_NONE,
2883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002884 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002885 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2886#ifdef FEAT_VERTSPLIT
2887 (char_u *)VAR_WIN, PV_WFW,
2888#else
2889 (char_u *)NULL, PV_NONE,
2890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2893#ifdef FEAT_WINDOWS
2894 (char_u *)&p_wmh, PV_NONE,
2895#else
2896 (char_u *)NULL, PV_NONE,
2897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2900#ifdef FEAT_VERTSPLIT
2901 (char_u *)&p_wmw, PV_NONE,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2907#ifdef FEAT_VERTSPLIT
2908 (char_u *)&p_wiw, PV_NONE,
2909#else
2910 (char_u *)NULL, PV_NONE,
2911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002912 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2914 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002915 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2917 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002918 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2920 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"write", NULL, P_BOOL|P_VI_DEF,
2923 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"writeany", "wa", P_BOOL|P_VI_DEF,
2926 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2929 (char_u *)&p_wb, PV_NONE,
2930 {
2931#ifdef FEAT_WRITEBACKUP
2932 (char_u *)TRUE,
2933#else
2934 (char_u *)FALSE,
2935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937 {"writedelay", "wd", P_NUM|P_VI_DEF,
2938 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940
2941/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002942#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002944 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945
2946 p_term("t_AB", T_CAB)
2947 p_term("t_AF", T_CAF)
2948 p_term("t_AL", T_CAL)
2949 p_term("t_al", T_AL)
2950 p_term("t_bc", T_BC)
2951 p_term("t_cd", T_CD)
2952 p_term("t_ce", T_CE)
2953 p_term("t_cl", T_CL)
2954 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002955 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 p_term("t_Co", T_CCO)
2957 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002958 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959 p_term("t_cs", T_CS)
2960#ifdef FEAT_VERTSPLIT
2961 p_term("t_CV", T_CSV)
2962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 p_term("t_da", T_DA)
2964 p_term("t_db", T_DB)
2965 p_term("t_DL", T_CDL)
2966 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002967 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968 p_term("t_fs", T_FS)
2969 p_term("t_IE", T_CIE)
2970 p_term("t_IS", T_CIS)
2971 p_term("t_ke", T_KE)
2972 p_term("t_ks", T_KS)
2973 p_term("t_le", T_LE)
2974 p_term("t_mb", T_MB)
2975 p_term("t_md", T_MD)
2976 p_term("t_me", T_ME)
2977 p_term("t_mr", T_MR)
2978 p_term("t_ms", T_MS)
2979 p_term("t_nd", T_ND)
2980 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002981 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 p_term("t_RI", T_CRI)
2983 p_term("t_RV", T_CRV)
2984 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002986 p_term("t_Sf", T_CSF)
2987 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02002989 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 p_term("t_te", T_TE)
2992 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02002993 p_term("t_ts", T_TS)
2994 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 p_term("t_ue", T_UE)
2996 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02002997 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 p_term("t_vb", T_VB)
2999 p_term("t_ve", T_VE)
3000 p_term("t_vi", T_VI)
3001 p_term("t_vs", T_VS)
3002 p_term("t_WP", T_CWP)
3003 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003004 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 p_term("t_xs", T_XS)
3006 p_term("t_ZH", T_CZH)
3007 p_term("t_ZR", T_CZR)
3008
3009/* terminal key codes are not in here */
3010
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 /* end marker */
3012 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013};
3014
3015#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3016
3017#ifdef FEAT_MBYTE
3018static char *(p_ambw_values[]) = {"single", "double", NULL};
3019#endif
3020static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003021static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003023#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003024static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003025#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003026#ifdef FEAT_CMDL_COMPL
3027static char *(p_wop_values[]) = {"tagfile", NULL};
3028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029#ifdef FEAT_WAK
3030static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3031#endif
3032static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3034static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036#ifdef FEAT_BROWSE
3037static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3038#endif
3039#ifdef FEAT_SCROLLBIND
3040static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3041#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003042static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043#ifdef FEAT_VERTSPLIT
3044static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3045#endif
3046#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003047# ifdef FEAT_AUTOCMD
3048static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3049# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003051# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3053#endif
3054static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3055#ifdef FEAT_FOLDING
3056static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003057# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003059# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 NULL};
3061static char *(p_fcl_values[]) = {"all", NULL};
3062#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003063#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003064static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003065#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003067static void set_option_default(int, int opt_flags, int compatible);
3068static void set_options_default(int opt_flags);
3069static char_u *term_bg_default(void);
3070static void did_set_option(int opt_idx, int opt_flags, int new_value);
3071static char_u *illegal_char(char_u *, int);
3072static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003074static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075#endif
3076#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003077static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003079static char_u *option_expand(int opt_idx, char_u *val);
3080static void didset_options(void);
3081static void didset_options2(void);
3082static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003083#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003084static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003085#else
3086# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3087#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003088static void set_string_option_global(int opt_idx, char_u **varp);
3089static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3090static 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);
3091static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003092#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003093static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003094#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003096static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003098#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003099static char_u *did_set_spell_option(int is_spellfile);
3100static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003101#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003102#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003103static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003104#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003105static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3106static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3107static void check_redraw(long_u flags);
3108static int findoption(char_u *);
3109static int find_key_option(char_u *);
3110static void showoptions(int all, int opt_flags);
3111static int optval_default(struct vimoption *, char_u *varp);
3112static void showoneopt(struct vimoption *, int opt_flags);
3113static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3114static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3115static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3116static int istermoption(struct vimoption *);
3117static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3118static char_u *get_varp(struct vimoption *);
3119static void option_value2string(struct vimoption *, int opt_flags);
3120static void check_winopt(winopt_T *wop);
3121static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003123static void langmap_init(void);
3124static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003126static void paste_option_changed(void);
3127static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003129static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003131static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3132static int check_opt_strings(char_u *val, char **values, int);
3133static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003134#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003135static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003136#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137
3138/*
3139 * Initialize the options, first part.
3140 *
3141 * Called only once from main(), just after creating the first buffer.
3142 */
3143 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003144set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145{
3146 char_u *p;
3147 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003148 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149
3150#ifdef FEAT_LANGMAP
3151 langmap_init();
3152#endif
3153
3154 /* Be Vi compatible by default */
3155 p_cp = TRUE;
3156
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003157 /* Use POSIX compatibility when $VIM_POSIX is set. */
3158 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003159 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003160 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003161 set_string_default("shm", (char_u *)"A");
3162 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003163
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 /*
3165 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003166 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003168 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003169#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003171 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003173 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003175 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176# endif
3177#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003178 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 set_string_default("sh", p);
3180
3181#ifdef FEAT_WILDIGN
3182 /*
3183 * Set the default for 'backupskip' to include environment variables for
3184 * temp files.
3185 */
3186 {
3187# ifdef UNIX
3188 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3189# else
3190 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3191# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003192 int len;
3193 garray_T ga;
3194 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195
3196 ga_init2(&ga, 1, 100);
3197 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3198 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003199 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200# ifdef UNIX
3201 if (*names[n] == NUL)
3202 p = (char_u *)"/tmp";
3203 else
3204# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003205 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206 if (p != NULL && *p != NUL)
3207 {
3208 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003209 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210 if (ga_grow(&ga, len) == OK)
3211 {
3212 if (ga.ga_len > 0)
3213 STRCAT(ga.ga_data, ",");
3214 STRCAT(ga.ga_data, p);
3215 add_pathsep(ga.ga_data);
3216 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217 ga.ga_len += len;
3218 }
3219 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003220 if (mustfree)
3221 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222 }
3223 if (ga.ga_data != NULL)
3224 {
3225 set_string_default("bsk", ga.ga_data);
3226 vim_free(ga.ga_data);
3227 }
3228 }
3229#endif
3230
3231 /*
3232 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3233 */
3234 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003235 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003237#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3238 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3239#endif
3240 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003242 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003243 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244#else
3245# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003246 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003247 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003249 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250# endif
3251#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003253 opt_idx = findoption((char_u *)"maxmem");
3254 if (opt_idx >= 0)
3255 {
3256#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003257 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3258 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259#endif
3260 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3261 }
3262 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263 }
3264
3265#ifdef FEAT_GUI_W32
3266 /* force 'shortname' for Win32s */
3267 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003268 {
3269 opt_idx = findoption((char_u *)"shortname");
3270 if (opt_idx >= 0)
3271 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3272 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273#endif
3274
3275#ifdef FEAT_SEARCHPATH
3276 {
3277 char_u *cdpath;
3278 char_u *buf;
3279 int i;
3280 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003281 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282
3283 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003284 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285 if (cdpath != NULL)
3286 {
3287 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3288 if (buf != NULL)
3289 {
3290 buf[0] = ','; /* start with ",", current dir first */
3291 j = 1;
3292 for (i = 0; cdpath[i] != NUL; ++i)
3293 {
3294 if (vim_ispathlistsep(cdpath[i]))
3295 buf[j++] = ',';
3296 else
3297 {
3298 if (cdpath[i] == ' ' || cdpath[i] == ',')
3299 buf[j++] = '\\';
3300 buf[j++] = cdpath[i];
3301 }
3302 }
3303 buf[j] = NUL;
3304 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003305 if (opt_idx >= 0)
3306 {
3307 options[opt_idx].def_val[VI_DEFAULT] = buf;
3308 options[opt_idx].flags |= P_DEF_ALLOCED;
3309 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003310 else
3311 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003312 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003313 if (mustfree)
3314 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315 }
3316 }
3317#endif
3318
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003319#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320 /* Set print encoding on platforms that don't default to latin1 */
3321 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003322# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323 (char_u *)"cp1252"
3324# else
3325# ifdef VMS
3326 (char_u *)"dec-mcs"
3327# else
3328# ifdef EBCDIC
3329 (char_u *)"ebcdic-uk"
3330# else
3331# ifdef MAC
3332 (char_u *)"mac-roman"
3333# else /* HPUX */
3334 (char_u *)"hp-roman8"
3335# endif
3336# endif
3337# endif
3338# endif
3339 );
3340#endif
3341
3342#ifdef FEAT_POSTSCRIPT
3343 /* 'printexpr' must be allocated to be able to evaluate it. */
3344 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003345# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003346 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347# else
3348# ifdef VMS
3349 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3350
3351# else
3352 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3353# endif
3354# endif
3355 );
3356#endif
3357
3358 /*
3359 * Set all the options (except the terminal options) to their default
3360 * value. Also set the global value for local options.
3361 */
3362 set_options_default(0);
3363
3364#ifdef FEAT_GUI
3365 if (found_reverse_arg)
3366 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3367#endif
3368
3369 curbuf->b_p_initialized = TRUE;
3370 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003371 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372 check_buf_options(curbuf);
3373 check_win_options(curwin);
3374 check_options();
3375
3376 /* Must be before option_expand(), because that one needs vim_isIDc() */
3377 didset_options();
3378
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003379#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003380 /* Use the current chartab for the generic chartab. This is not in
3381 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003382 init_spell_chartab();
3383#endif
3384
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385 /*
3386 * Expand environment variables and things like "~" for the defaults.
3387 * If option_expand() returns non-NULL the variable is expanded. This can
3388 * only happen for non-indirect options.
3389 * Also set the default to the expanded value, so ":set" does not list
3390 * them.
3391 * Don't set the P_ALLOCED flag, because we don't want to free the
3392 * default.
3393 */
3394 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3395 {
3396 if ((options[opt_idx].flags & P_GETTEXT)
3397 && options[opt_idx].var != NULL)
3398 p = (char_u *)_(*(char **)options[opt_idx].var);
3399 else
3400 p = option_expand(opt_idx, NULL);
3401 if (p != NULL && (p = vim_strsave(p)) != NULL)
3402 {
3403 *(char_u **)options[opt_idx].var = p;
3404 /* VIMEXP
3405 * Defaults for all expanded options are currently the same for Vi
3406 * and Vim. When this changes, add some code here! Also need to
3407 * split P_DEF_ALLOCED in two.
3408 */
3409 if (options[opt_idx].flags & P_DEF_ALLOCED)
3410 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3411 options[opt_idx].def_val[VI_DEFAULT] = p;
3412 options[opt_idx].flags |= P_DEF_ALLOCED;
3413 }
3414 }
3415
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416 save_file_ff(curbuf); /* Buffer is unchanged */
3417
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418#if defined(FEAT_ARABIC)
3419 /* Detect use of mlterm.
3420 * Mlterm is a terminal emulator akin to xterm that has some special
3421 * abilities (bidi namely).
3422 * NOTE: mlterm's author is being asked to 'set' a variable
3423 * instead of an environment variable due to inheritance.
3424 */
3425 if (mch_getenv((char_u *)"MLTERM") != NULL)
3426 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3427#endif
3428
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003429 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430
3431#ifdef FEAT_MBYTE
3432# if defined(WIN3264) && defined(FEAT_GETTEXT)
3433 /*
3434 * If $LANG isn't set, try to get a good value for it. This makes the
3435 * right language be used automatically. Don't do this for English.
3436 */
3437 if (mch_getenv((char_u *)"LANG") == NULL)
3438 {
3439 char buf[20];
3440
3441 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3442 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3443 * only the first two. */
3444 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3445 (LPTSTR)buf, 20);
3446 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3447 {
3448 /* There are a few exceptions (probably more) */
3449 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3450 STRCPY(buf, "zh_TW");
3451 else if (STRNICMP(buf, "chs", 3) == 0
3452 || STRNICMP(buf, "zhc", 3) == 0)
3453 STRCPY(buf, "zh_CN");
3454 else if (STRNICMP(buf, "jp", 2) == 0)
3455 STRCPY(buf, "ja");
3456 else
3457 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003458 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459 }
3460 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003461# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003462# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003463 /* Moved to os_mac_conv.c to avoid dependency problems. */
3464 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003465# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466# endif
3467
3468 /* enc_locale() will try to find the encoding of the current locale. */
3469 p = enc_locale();
3470 if (p != NULL)
3471 {
3472 char_u *save_enc;
3473
3474 /* Try setting 'encoding' and check if the value is valid.
3475 * If not, go back to the default "latin1". */
3476 save_enc = p_enc;
3477 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003478 if (STRCMP(p_enc, "gb18030") == 0)
3479 {
3480 /* We don't support "gb18030", but "cp936" is a good substitute
3481 * for practical purposes, thus use that. It's not an alias to
3482 * still support conversion between gb18030 and utf-8. */
3483 p_enc = vim_strsave((char_u *)"cp936");
3484 vim_free(p);
3485 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 if (mb_init() == NULL)
3487 {
3488 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003489 if (opt_idx >= 0)
3490 {
3491 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3492 options[opt_idx].flags |= P_DEF_ALLOCED;
3493 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003495#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003496 if (STRCMP(p_enc, "latin1") == 0
3497# ifdef FEAT_MBYTE
3498 || enc_utf8
3499# endif
3500 )
3501 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003502 /* Adjust the default for 'isprint' and 'iskeyword' to match
3503 * latin1. Also set the defaults for when 'nocompatible' is
3504 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003505 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003506 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003507 set_string_option_direct((char_u *)"isk", -1,
3508 ISK_LATIN1, OPT_FREE, SID_NONE);
3509 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003510 if (opt_idx >= 0)
3511 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003512 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003513 if (opt_idx >= 0)
3514 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003515 (void)init_chartab();
3516 }
3517#endif
3518
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519# if defined(WIN3264) && !defined(FEAT_GUI)
3520 /* Win32 console: When GetACP() returns a different value from
3521 * GetConsoleCP() set 'termencoding'. */
3522 if (GetACP() != GetConsoleCP())
3523 {
3524 char buf[50];
3525
3526 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3527 p_tenc = vim_strsave((char_u *)buf);
3528 if (p_tenc != NULL)
3529 {
3530 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003531 if (opt_idx >= 0)
3532 {
3533 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3534 options[opt_idx].flags |= P_DEF_ALLOCED;
3535 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003536 convert_setup(&input_conv, p_tenc, p_enc);
3537 convert_setup(&output_conv, p_enc, p_tenc);
3538 }
3539 else
3540 p_tenc = empty_option;
3541 }
3542# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003543# if defined(WIN3264) && defined(FEAT_MBYTE)
3544 /* $HOME may have characters in active code page. */
3545 init_homedir();
3546# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003547 }
3548 else
3549 {
3550 vim_free(p_enc);
3551 p_enc = save_enc;
3552 }
3553 }
3554#endif
3555
3556#ifdef FEAT_MULTI_LANG
3557 /* Set the default for 'helplang'. */
3558 set_helplang_default(get_mess_lang());
3559#endif
3560}
3561
3562/*
3563 * Set an option to its default value.
3564 * This does not take care of side effects!
3565 */
3566 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003567set_option_default(
3568 int opt_idx,
3569 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3570 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571{
3572 char_u *varp; /* pointer to variable for current option */
3573 int dvi; /* index in def_val[] */
3574 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003575 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3577
3578 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3579 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003580 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003581 {
3582 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3583 if (flags & P_STRING)
3584 {
3585 /* Use set_string_option_direct() for local options to handle
3586 * freeing and allocating the value. */
3587 if (options[opt_idx].indir != PV_NONE)
3588 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003589 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003590 else
3591 {
3592 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3593 free_string_option(*(char_u **)(varp));
3594 *(char_u **)varp = options[opt_idx].def_val[dvi];
3595 options[opt_idx].flags &= ~P_ALLOCED;
3596 }
3597 }
3598 else if (flags & P_NUM)
3599 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003600 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 win_comp_scroll(curwin);
3602 else
3603 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003604 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605 /* May also set global value for local option. */
3606 if (both)
3607 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3608 *(long *)varp;
3609 }
3610 }
3611 else /* P_BOOL */
3612 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003613 /* the cast to long is required for Manx C, long_i is needed for
3614 * MSVC */
3615 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003616#ifdef UNIX
3617 /* 'modeline' defaults to off for root */
3618 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3619 *(int *)varp = FALSE;
3620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003621 /* May also set global value for local option. */
3622 if (both)
3623 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3624 *(int *)varp;
3625 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003626
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003627 /* The default value is not insecure. */
3628 flagsp = insecure_flag(opt_idx, opt_flags);
3629 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630 }
3631
3632#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003633 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634#endif
3635}
3636
3637/*
3638 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003639 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640 */
3641 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003642set_options_default(
3643 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644{
3645 int i;
3646#ifdef FEAT_WINDOWS
3647 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003648 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649#endif
3650
3651 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003652 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003653#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003654 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003655 || (TRUE
3656# if defined(FEAT_MBYTE)
3657 && options[i].var != (char_u *)&p_enc
3658# endif
3659# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003660 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003661 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003662# endif
3663 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003664#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003665 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003666 set_option_default(i, opt_flags, p_cp);
3667
3668#ifdef FEAT_WINDOWS
3669 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003670 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671 win_comp_scroll(wp);
3672#else
3673 win_comp_scroll(curwin);
3674#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003675#ifdef FEAT_CINDENT
3676 parse_cino(curbuf);
3677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678}
3679
3680/*
3681 * Set the Vi-default value of a string option.
3682 * Used for 'sh', 'backupskip' and 'term'.
3683 */
3684 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003685set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686{
3687 char_u *p;
3688 int opt_idx;
3689
3690 p = vim_strsave(val);
3691 if (p != NULL) /* we don't want a NULL */
3692 {
3693 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003694 if (opt_idx >= 0)
3695 {
3696 if (options[opt_idx].flags & P_DEF_ALLOCED)
3697 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3698 options[opt_idx].def_val[VI_DEFAULT] = p;
3699 options[opt_idx].flags |= P_DEF_ALLOCED;
3700 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003701 }
3702}
3703
3704/*
3705 * Set the Vi-default value of a number option.
3706 * Used for 'lines' and 'columns'.
3707 */
3708 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003709set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003711 int opt_idx;
3712
3713 opt_idx = findoption((char_u *)name);
3714 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003715 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716}
3717
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003718#if defined(EXITFREE) || defined(PROTO)
3719/*
3720 * Free all options.
3721 */
3722 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003723free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003724{
3725 int i;
3726
3727 for (i = 0; !istermoption(&options[i]); i++)
3728 {
3729 if (options[i].indir == PV_NONE)
3730 {
3731 /* global option: free value and default value. */
3732 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3733 free_string_option(*(char_u **)options[i].var);
3734 if (options[i].flags & P_DEF_ALLOCED)
3735 free_string_option(options[i].def_val[VI_DEFAULT]);
3736 }
3737 else if (options[i].var != VAR_WIN
3738 && (options[i].flags & P_STRING))
3739 /* buffer-local option: free global value */
3740 free_string_option(*(char_u **)options[i].var);
3741 }
3742}
3743#endif
3744
3745
Bram Moolenaar071d4272004-06-13 20:20:40 +00003746/*
3747 * Initialize the options, part two: After getting Rows and Columns and
3748 * setting 'term'.
3749 */
3750 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003751set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003753 int idx;
3754
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755 /*
3756 * 'scroll' defaults to half the window height. Note that this default is
3757 * wrong when the window height changes.
3758 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003759 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003760 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003761 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003762 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763 comp_col();
3764
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003765 /*
3766 * 'window' is only for backwards compatibility with Vi.
3767 * Default is Rows - 1.
3768 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003769 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003770 p_window = Rows - 1;
3771 set_number_default("window", Rows - 1);
3772
Bram Moolenaarf740b292006-02-16 22:11:02 +00003773 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003774#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003775 /*
3776 * If 'background' wasn't set by the user, try guessing the value,
3777 * depending on the terminal name. Only need to check for terminals
3778 * with a dark background, that can handle color.
3779 */
3780 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003781 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3782 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003784 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003785 /* don't mark it as set, when starting the GUI it may be
3786 * changed again */
3787 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 }
3789#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003790
3791#ifdef CURSOR_SHAPE
3792 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3793#endif
3794#ifdef FEAT_MOUSESHAPE
3795 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3796#endif
3797#ifdef FEAT_PRINTER
3798 (void)parse_printoptions(); /* parse 'printoptions' default value */
3799#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800}
3801
3802/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003803 * Return "dark" or "light" depending on the kind of terminal.
3804 * This is just guessing! Recognized are:
3805 * "linux" Linux console
3806 * "screen.linux" Linux console with screen
3807 * "cygwin" Cygwin shell
3808 * "putty" Putty program
3809 * We also check the COLORFGBG environment variable, which is set by
3810 * rxvt and derivatives. This variable contains either two or three
3811 * values separated by semicolons; we want the last value in either
3812 * case. If this value is 0-6 or 8, our background is dark.
3813 */
3814 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003815term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003816{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003817#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003818 /* DOS console nearly always black */
3819 return (char_u *)"dark";
3820#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003821 char_u *p;
3822
Bram Moolenaarf740b292006-02-16 22:11:02 +00003823 if (STRCMP(T_NAME, "linux") == 0
3824 || STRCMP(T_NAME, "screen.linux") == 0
3825 || STRCMP(T_NAME, "cygwin") == 0
3826 || STRCMP(T_NAME, "putty") == 0
3827 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3828 && (p = vim_strrchr(p, ';')) != NULL
3829 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3830 && p[2] == NUL))
3831 return (char_u *)"dark";
3832 return (char_u *)"light";
3833#endif
3834}
3835
3836/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837 * Initialize the options, part three: After reading the .vimrc
3838 */
3839 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003840set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003842#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843/*
3844 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3845 * This is done after other initializations, where 'shell' might have been
3846 * set, but only if they have not been set before.
3847 */
3848 char_u *p;
3849 int idx_srr;
3850 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003851# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 int idx_sp;
3853 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003854# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855
3856 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003857 if (idx_srr < 0)
3858 do_srr = FALSE;
3859 else
3860 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003861# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003863 if (idx_sp < 0)
3864 do_sp = FALSE;
3865 else
3866 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003867# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003868 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 if (p != NULL)
3870 {
3871 /*
3872 * Default for p_sp is "| tee", for p_srr is ">".
3873 * For known shells it is changed here to include stderr.
3874 */
3875 if ( fnamecmp(p, "csh") == 0
3876 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003877# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878 || fnamecmp(p, "csh.exe") == 0
3879 || fnamecmp(p, "tcsh.exe") == 0
3880# endif
3881 )
3882 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003883# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 if (do_sp)
3885 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003886# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003888# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003890# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3892 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003893# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 if (do_srr)
3895 {
3896 p_srr = (char_u *)">&";
3897 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3898 }
3899 }
3900 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003901 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902 if ( fnamecmp(p, "sh") == 0
3903 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003904 || fnamecmp(p, "mksh") == 0
3905 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003907 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003909 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003910# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 || fnamecmp(p, "cmd") == 0
3912 || fnamecmp(p, "sh.exe") == 0
3913 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003914 || fnamecmp(p, "mksh.exe") == 0
3915 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003917 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 || fnamecmp(p, "bash.exe") == 0
3919 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003921 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003923# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 if (do_sp)
3925 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003926# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003928# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003930# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3932 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003933# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 if (do_srr)
3935 {
3936 p_srr = (char_u *)">%s 2>&1";
3937 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3938 }
3939 }
3940 vim_free(p);
3941 }
3942#endif
3943
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003944#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003946 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3947 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 * This is done after other initializations, where 'shell' might have been
3949 * set, but only if they have not been set before. Default for p_shcf is
3950 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003951 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003953 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 {
3955 int idx3;
3956
3957 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003958 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959 {
3960 p_shcf = (char_u *)"-c";
3961 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3962 }
3963
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003964# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965 /* Somehow Win32 requires the quotes around the redirection too */
3966 idx3 = findoption((char_u *)"sxq");
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_sxq = (char_u *)"\"";
3970 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3971 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003972# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003974 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 {
3976 p_shq = (char_u *)"\"";
3977 options[idx3].def_val[VI_DEFAULT] = p_shq;
3978 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979# endif
3980 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003981 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3982 {
3983 int idx3;
3984
3985 /*
3986 * cmd.exe on Windows will strip the first and last double quote given
3987 * on the command line, e.g. most of the time things like:
3988 * cmd /c "my path/to/echo" "my args to echo"
3989 * become:
3990 * my path/to/echo" "my args to echo
3991 * when executed.
3992 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003993 * To avoid this, set shellxquote to surround the command in
3994 * parenthesis. This appears to make most commands work, without
3995 * breaking commands that worked previously, such as
3996 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003997 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003998 idx3 = findoption((char_u *)"sxq");
3999 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4000 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004001 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004002 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4003 }
4004
Bram Moolenaara64ba222012-02-12 23:23:31 +01004005 idx3 = findoption((char_u *)"shcf");
4006 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4007 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004008 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004009 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4010 }
4011 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012#endif
4013
4014#ifdef FEAT_TITLE
4015 set_title_defaults();
4016#endif
4017}
4018
4019#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4020/*
4021 * When 'helplang' is still at its default value, set it to "lang".
4022 * Only the first two characters of "lang" are used.
4023 */
4024 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004025set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026{
4027 int idx;
4028
4029 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4030 return;
4031 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004032 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033 {
4034 if (options[idx].flags & P_ALLOCED)
4035 free_string_option(p_hlg);
4036 p_hlg = vim_strsave(lang);
4037 if (p_hlg == NULL)
4038 p_hlg = empty_option;
4039 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004040 {
4041 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4042 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4043 {
4044 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4045 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4046 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004048 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049 options[idx].flags |= P_ALLOCED;
4050 }
4051}
4052#endif
4053
4054#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004055static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056
4057 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004058gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059{
4060 if (gui_get_lightness(gui.back_pixel) < 127)
4061 return (char_u *)"dark";
4062 return (char_u *)"light";
4063}
4064
4065/*
4066 * Option initializations that can only be done after opening the GUI window.
4067 */
4068 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004069init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070{
4071 /* Set the 'background' option according to the lightness of the
4072 * background color, unless the user has set it already. */
4073 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4074 {
4075 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4076 highlight_changed();
4077 }
4078}
4079#endif
4080
4081#ifdef FEAT_TITLE
4082/*
4083 * 'title' and 'icon' only default to true if they have not been set or reset
4084 * in .vimrc and we can read the old value.
4085 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4086 * they can be reset. This reduces startup time when using X on a remote
4087 * machine.
4088 */
4089 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004090set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091{
4092 int idx1;
4093 long val;
4094
4095 /*
4096 * If GUI is (going to be) used, we can always set the window title and
4097 * icon name. Saves a bit of time, because the X11 display server does
4098 * not need to be contacted.
4099 */
4100 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004101 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 {
4103#ifdef FEAT_GUI
4104 if (gui.starting || gui.in_use)
4105 val = TRUE;
4106 else
4107#endif
4108 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004109 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 p_title = val;
4111 }
4112 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004113 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 {
4115#ifdef FEAT_GUI
4116 if (gui.starting || gui.in_use)
4117 val = TRUE;
4118 else
4119#endif
4120 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004121 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 p_icon = val;
4123 }
4124}
4125#endif
4126
4127/*
4128 * Parse 'arg' for option settings.
4129 *
4130 * 'arg' may be IObuff, but only when no errors can be present and option
4131 * does not need to be expanded with option_expand().
4132 * "opt_flags":
4133 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004134 * OPT_GLOBAL for ":setglobal"
4135 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004137 * OPT_WINONLY to only set window-local options
4138 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 *
4140 * returns FAIL if an error is detected, OK otherwise
4141 */
4142 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004143do_set(
4144 char_u *arg, /* option string (may be written to!) */
4145 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146{
4147 int opt_idx;
4148 char_u *errmsg;
4149 char_u errbuf[80];
4150 char_u *startarg;
4151 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4152 int nextchar; /* next non-white char after option name */
4153 int afterchar; /* character just after option name */
4154 int len;
4155 int i;
4156 long value;
4157 int key;
4158 long_u flags; /* flags for current option */
4159 char_u *varp = NULL; /* pointer to variable for current option */
4160 int did_show = FALSE; /* already showed one value */
4161 int adding; /* "opt+=arg" */
4162 int prepending; /* "opt^=arg" */
4163 int removing; /* "opt-=arg" */
4164 int cp_val = 0;
4165 char_u key_name[2];
4166
4167 if (*arg == NUL)
4168 {
4169 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004170 did_show = TRUE;
4171 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 }
4173
4174 while (*arg != NUL) /* loop to process all options */
4175 {
4176 errmsg = NULL;
4177 startarg = arg; /* remember for error message */
4178
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004179 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4180 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004181 {
4182 /*
4183 * ":set all" show all options.
4184 * ":set all&" set all options to their default value.
4185 */
4186 arg += 3;
4187 if (*arg == '&')
4188 {
4189 ++arg;
4190 /* Only for :set command set global value of local options. */
4191 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004192 didset_options();
4193 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004194 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004195 }
4196 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004197 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004198 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004199 did_show = TRUE;
4200 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004202 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203 {
4204 showoptions(2, opt_flags);
4205 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004206 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 arg += 7;
4208 }
4209 else
4210 {
4211 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004212 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004213 {
4214 prefix = 0;
4215 arg += 2;
4216 }
4217 else if (STRNCMP(arg, "inv", 3) == 0)
4218 {
4219 prefix = 2;
4220 arg += 3;
4221 }
4222
4223 /* find end of name */
4224 key = 0;
4225 if (*arg == '<')
4226 {
4227 nextchar = 0;
4228 opt_idx = -1;
4229 /* look out for <t_>;> */
4230 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4231 len = 5;
4232 else
4233 {
4234 len = 1;
4235 while (arg[len] != NUL && arg[len] != '>')
4236 ++len;
4237 }
4238 if (arg[len] != '>')
4239 {
4240 errmsg = e_invarg;
4241 goto skip;
4242 }
4243 arg[len] = NUL; /* put NUL after name */
4244 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4245 opt_idx = findoption(arg + 1);
4246 arg[len++] = '>'; /* restore '>' */
4247 if (opt_idx == -1)
4248 key = find_key_option(arg + 1);
4249 }
4250 else
4251 {
4252 len = 0;
4253 /*
4254 * The two characters after "t_" may not be alphanumeric.
4255 */
4256 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4257 len = 4;
4258 else
4259 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4260 ++len;
4261 nextchar = arg[len];
4262 arg[len] = NUL; /* put NUL after name */
4263 opt_idx = findoption(arg);
4264 arg[len] = nextchar; /* restore nextchar */
4265 if (opt_idx == -1)
4266 key = find_key_option(arg);
4267 }
4268
4269 /* remember character after option name */
4270 afterchar = arg[len];
4271
4272 /* skip white space, allow ":set ai ?" */
4273 while (vim_iswhite(arg[len]))
4274 ++len;
4275
4276 adding = FALSE;
4277 prepending = FALSE;
4278 removing = FALSE;
4279 if (arg[len] != NUL && arg[len + 1] == '=')
4280 {
4281 if (arg[len] == '+')
4282 {
4283 adding = TRUE; /* "+=" */
4284 ++len;
4285 }
4286 else if (arg[len] == '^')
4287 {
4288 prepending = TRUE; /* "^=" */
4289 ++len;
4290 }
4291 else if (arg[len] == '-')
4292 {
4293 removing = TRUE; /* "-=" */
4294 ++len;
4295 }
4296 }
4297 nextchar = arg[len];
4298
4299 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4300 {
4301 errmsg = (char_u *)N_("E518: Unknown option");
4302 goto skip;
4303 }
4304
4305 if (opt_idx >= 0)
4306 {
4307 if (options[opt_idx].var == NULL) /* hidden option: skip */
4308 {
4309 /* Only give an error message when requesting the value of
4310 * a hidden option, ignore setting it. */
4311 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4312 && (!(options[opt_idx].flags & P_BOOL)
4313 || nextchar == '?'))
4314 errmsg = (char_u *)N_("E519: Option not supported");
4315 goto skip;
4316 }
4317
4318 flags = options[opt_idx].flags;
4319 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4320 }
4321 else
4322 {
4323 flags = P_STRING;
4324 if (key < 0)
4325 {
4326 key_name[0] = KEY2TERMCAP0(key);
4327 key_name[1] = KEY2TERMCAP1(key);
4328 }
4329 else
4330 {
4331 key_name[0] = KS_KEY;
4332 key_name[1] = (key & 0xff);
4333 }
4334 }
4335
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004336 /* Skip all options that are not window-local (used when showing
4337 * an already loaded buffer in a window). */
4338 if ((opt_flags & OPT_WINONLY)
4339 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4340 goto skip;
4341
Bram Moolenaara3227e22006-03-08 21:32:40 +00004342 /* Skip all options that are window-local (used for :vimgrep). */
4343 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4344 && options[opt_idx].var == VAR_WIN)
4345 goto skip;
4346
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004347 /* Disallow changing some options from modelines. */
4348 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004350 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004351 {
4352 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4353 goto skip;
4354 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004355#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004356 /* In diff mode some options are overruled. This avoids that
4357 * 'foldmethod' becomes "marker" instead of "diff" and that
4358 * "wrap" gets set. */
4359 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004360 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004361 && (options[opt_idx].indir == PV_FDM
4362 || options[opt_idx].indir == PV_WRAP))
4363 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004365 }
4366
4367#ifdef HAVE_SANDBOX
4368 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004369 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004370 {
4371 errmsg = (char_u *)_(e_sandbox);
4372 goto skip;
4373 }
4374#endif
4375
4376 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4377 {
4378 arg += len;
4379 cp_val = p_cp;
4380 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4381 {
4382 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4383 {
4384 cp_val = FALSE;
4385 arg += 3;
4386 }
4387 else /* "opt&vi": set to Vi default */
4388 {
4389 cp_val = TRUE;
4390 arg += 2;
4391 }
4392 }
4393 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4394 && arg[1] != NUL && !vim_iswhite(arg[1]))
4395 {
4396 errmsg = e_trailing;
4397 goto skip;
4398 }
4399 }
4400
4401 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004402 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4403 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 */
4405 if (nextchar == '?'
4406 || (prefix == 1
4407 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4408 && !(flags & P_BOOL)))
4409 {
4410 /*
4411 * print value
4412 */
4413 if (did_show)
4414 msg_putchar('\n'); /* cursor below last one */
4415 else
4416 {
4417 gotocmdline(TRUE); /* cursor at status line */
4418 did_show = TRUE; /* remember that we did a line */
4419 }
4420 if (opt_idx >= 0)
4421 {
4422 showoneopt(&options[opt_idx], opt_flags);
4423#ifdef FEAT_EVAL
4424 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004425 {
4426 /* Mention where the option was last set. */
4427 if (varp == options[opt_idx].var)
4428 last_set_msg(options[opt_idx].scriptID);
4429 else if ((int)options[opt_idx].indir & PV_WIN)
4430 last_set_msg(curwin->w_p_scriptID[
4431 (int)options[opt_idx].indir & PV_MASK]);
4432 else if ((int)options[opt_idx].indir & PV_BUF)
4433 last_set_msg(curbuf->b_p_scriptID[
4434 (int)options[opt_idx].indir & PV_MASK]);
4435 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004436#endif
4437 }
4438 else
4439 {
4440 char_u *p;
4441
4442 p = find_termcode(key_name);
4443 if (p == NULL)
4444 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004445 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004446 goto skip;
4447 }
4448 else
4449 (void)show_one_termcode(key_name, p, TRUE);
4450 }
4451 if (nextchar != '?'
4452 && nextchar != NUL && !vim_iswhite(afterchar))
4453 errmsg = e_trailing;
4454 }
4455 else
4456 {
4457 if (flags & P_BOOL) /* boolean */
4458 {
4459 if (nextchar == '=' || nextchar == ':')
4460 {
4461 errmsg = e_invarg;
4462 goto skip;
4463 }
4464
4465 /*
4466 * ":set opt!": invert
4467 * ":set opt&": reset to default value
4468 * ":set opt<": reset to global value
4469 */
4470 if (nextchar == '!')
4471 value = *(int *)(varp) ^ 1;
4472 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004473 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004474 ((flags & P_VI_DEF) || cp_val)
4475 ? VI_DEFAULT : VIM_DEFAULT];
4476 else if (nextchar == '<')
4477 {
4478 /* For 'autoread' -1 means to use global value. */
4479 if ((int *)varp == &curbuf->b_p_ar
4480 && opt_flags == OPT_LOCAL)
4481 value = -1;
4482 else
4483 value = *(int *)get_varp_scope(&(options[opt_idx]),
4484 OPT_GLOBAL);
4485 }
4486 else
4487 {
4488 /*
4489 * ":set invopt": invert
4490 * ":set opt" or ":set noopt": set or reset
4491 */
4492 if (nextchar != NUL && !vim_iswhite(afterchar))
4493 {
4494 errmsg = e_trailing;
4495 goto skip;
4496 }
4497 if (prefix == 2) /* inv */
4498 value = *(int *)(varp) ^ 1;
4499 else
4500 value = prefix;
4501 }
4502
4503 errmsg = set_bool_option(opt_idx, varp, (int)value,
4504 opt_flags);
4505 }
4506 else /* numeric or string */
4507 {
4508 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4509 || prefix != 1)
4510 {
4511 errmsg = e_invarg;
4512 goto skip;
4513 }
4514
4515 if (flags & P_NUM) /* numeric */
4516 {
4517 /*
4518 * Different ways to set a number option:
4519 * & set to default value
4520 * < set to global value
4521 * <xx> accept special key codes for 'wildchar'
4522 * c accept any non-digit for 'wildchar'
4523 * [-]0-9 set number
4524 * other error
4525 */
4526 ++arg;
4527 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004528 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004529 ((flags & P_VI_DEF) || cp_val)
4530 ? VI_DEFAULT : VIM_DEFAULT];
4531 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004532 {
4533 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4534 * use the global value. */
4535 if ((long *)varp == &curbuf->b_p_ul
4536 && opt_flags == OPT_LOCAL)
4537 value = NO_LOCAL_UNDOLEVEL;
4538 else
4539 value = *(long *)get_varp_scope(
4540 &(options[opt_idx]), OPT_GLOBAL);
4541 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004542 else if (((long *)varp == &p_wc
4543 || (long *)varp == &p_wcm)
4544 && (*arg == '<'
4545 || *arg == '^'
4546 || ((!arg[1] || vim_iswhite(arg[1]))
4547 && !VIM_ISDIGIT(*arg))))
4548 {
4549 value = string_to_key(arg);
4550 if (value == 0 && (long *)varp != &p_wcm)
4551 {
4552 errmsg = e_invarg;
4553 goto skip;
4554 }
4555 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004556 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4557 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004558 /* Allow negative (for 'undolevels'), octal and
4559 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004560 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4561 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4563 {
4564 errmsg = e_invarg;
4565 goto skip;
4566 }
4567 }
4568 else
4569 {
4570 errmsg = (char_u *)N_("E521: Number required after =");
4571 goto skip;
4572 }
4573
4574 if (adding)
4575 value = *(long *)varp + value;
4576 if (prepending)
4577 value = *(long *)varp * value;
4578 if (removing)
4579 value = *(long *)varp - value;
4580 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004581 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004582 }
4583 else if (opt_idx >= 0) /* string */
4584 {
4585 char_u *save_arg = NULL;
4586 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004587 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004588 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004589 char_u *origval = NULL;
4590#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4591 char_u *saved_origval = NULL;
4592#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004593 unsigned newlen;
4594 int comma;
4595 int bs;
4596 int new_value_alloced; /* new string option
4597 was allocated */
4598
4599 /* When using ":set opt=val" for a global option
4600 * with a local value the local value will be
4601 * reset, use the global value here. */
4602 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004603 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004604 varp = options[opt_idx].var;
4605
4606 /* The old value is kept until we are sure that the
4607 * new value is valid. */
4608 oldval = *(char_u **)varp;
4609 if (nextchar == '&') /* set to default val */
4610 {
4611 newval = options[opt_idx].def_val[
4612 ((flags & P_VI_DEF) || cp_val)
4613 ? VI_DEFAULT : VIM_DEFAULT];
4614 if ((char_u **)varp == &p_bg)
4615 {
4616 /* guess the value of 'background' */
4617#ifdef FEAT_GUI
4618 if (gui.in_use)
4619 newval = gui_bg_default();
4620 else
4621#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004622 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623 }
4624
4625 /* expand environment variables and ~ (since the
4626 * default value was already expanded, only
4627 * required when an environment variable was set
4628 * later */
4629 if (newval == NULL)
4630 newval = empty_option;
4631 else
4632 {
4633 s = option_expand(opt_idx, newval);
4634 if (s == NULL)
4635 s = newval;
4636 newval = vim_strsave(s);
4637 }
4638 new_value_alloced = TRUE;
4639 }
4640 else if (nextchar == '<') /* set to global val */
4641 {
4642 newval = vim_strsave(*(char_u **)get_varp_scope(
4643 &(options[opt_idx]), OPT_GLOBAL));
4644 new_value_alloced = TRUE;
4645 }
4646 else
4647 {
4648 ++arg; /* jump to after the '=' or ':' */
4649
4650 /*
4651 * Set 'keywordprg' to ":help" if an empty
4652 * value was passed to :set by the user.
4653 * Misuse errbuf[] for the resulting string.
4654 */
4655 if (varp == (char_u *)&p_kp
4656 && (*arg == NUL || *arg == ' '))
4657 {
4658 STRCPY(errbuf, ":help");
4659 save_arg = arg;
4660 arg = errbuf;
4661 }
4662 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004663 * Convert 'backspace' number to string, for
4664 * adding, prepending and removing string.
4665 */
4666 else if (varp == (char_u *)&p_bs
4667 && VIM_ISDIGIT(**(char_u **)varp))
4668 {
4669 i = getdigits((char_u **)varp);
4670 switch (i)
4671 {
4672 case 0:
4673 *(char_u **)varp = empty_option;
4674 break;
4675 case 1:
4676 *(char_u **)varp = vim_strsave(
4677 (char_u *)"indent,eol");
4678 break;
4679 case 2:
4680 *(char_u **)varp = vim_strsave(
4681 (char_u *)"indent,eol,start");
4682 break;
4683 }
4684 vim_free(oldval);
4685 oldval = *(char_u **)varp;
4686 }
4687 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004688 * Convert 'whichwrap' number to string, for
4689 * backwards compatibility with Vim 3.0.
4690 * Misuse errbuf[] for the resulting string.
4691 */
4692 else if (varp == (char_u *)&p_ww
4693 && VIM_ISDIGIT(*arg))
4694 {
4695 *errbuf = NUL;
4696 i = getdigits(&arg);
4697 if (i & 1)
4698 STRCAT(errbuf, "b,");
4699 if (i & 2)
4700 STRCAT(errbuf, "s,");
4701 if (i & 4)
4702 STRCAT(errbuf, "h,l,");
4703 if (i & 8)
4704 STRCAT(errbuf, "<,>,");
4705 if (i & 16)
4706 STRCAT(errbuf, "[,],");
4707 if (*errbuf != NUL) /* remove trailing , */
4708 errbuf[STRLEN(errbuf) - 1] = NUL;
4709 save_arg = arg;
4710 arg = errbuf;
4711 }
4712 /*
4713 * Remove '>' before 'dir' and 'bdir', for
4714 * backwards compatibility with version 3.0
4715 */
4716 else if ( *arg == '>'
4717 && (varp == (char_u *)&p_dir
4718 || varp == (char_u *)&p_bdir))
4719 {
4720 ++arg;
4721 }
4722
4723 /* When setting the local value of a global
4724 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004725 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004726 && (opt_flags & OPT_LOCAL))
4727 origval = *(char_u **)get_varp(
4728 &options[opt_idx]);
4729 else
4730 origval = oldval;
4731
4732 /*
4733 * Copy the new string into allocated memory.
4734 * Can't use set_string_option_direct(), because
4735 * we need to remove the backslashes.
4736 */
4737 /* get a bit too much */
4738 newlen = (unsigned)STRLEN(arg) + 1;
4739 if (adding || prepending || removing)
4740 newlen += (unsigned)STRLEN(origval) + 1;
4741 newval = alloc(newlen);
4742 if (newval == NULL) /* out of mem, don't change */
4743 break;
4744 s = newval;
4745
4746 /*
4747 * Copy the string, skip over escaped chars.
4748 * For MS-DOS and WIN32 backslashes before normal
4749 * file name characters are not removed, and keep
4750 * backslash at start, for "\\machine\path", but
4751 * do remove it for "\\\\machine\\path".
4752 * The reverse is found in ExpandOldSetting().
4753 */
4754 while (*arg && !vim_iswhite(*arg))
4755 {
4756 if (*arg == '\\' && arg[1] != NUL
4757#ifdef BACKSLASH_IN_FILENAME
4758 && !((flags & P_EXPAND)
4759 && vim_isfilec(arg[1])
4760 && (arg[1] != '\\'
4761 || (s == newval
4762 && arg[2] != '\\')))
4763#endif
4764 )
4765 ++arg; /* remove backslash */
4766#ifdef FEAT_MBYTE
4767 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004768 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769 {
4770 /* copy multibyte char */
4771 mch_memmove(s, arg, (size_t)i);
4772 arg += i;
4773 s += i;
4774 }
4775 else
4776#endif
4777 *s++ = *arg++;
4778 }
4779 *s = NUL;
4780
4781 /*
4782 * Expand environment variables and ~.
4783 * Don't do it when adding without inserting a
4784 * comma.
4785 */
4786 if (!(adding || prepending || removing)
4787 || (flags & P_COMMA))
4788 {
4789 s = option_expand(opt_idx, newval);
4790 if (s != NULL)
4791 {
4792 vim_free(newval);
4793 newlen = (unsigned)STRLEN(s) + 1;
4794 if (adding || prepending || removing)
4795 newlen += (unsigned)STRLEN(origval) + 1;
4796 newval = alloc(newlen);
4797 if (newval == NULL)
4798 break;
4799 STRCPY(newval, s);
4800 }
4801 }
4802
4803 /* locate newval[] in origval[] when removing it
4804 * and when adding to avoid duplicates */
4805 i = 0; /* init for GCC */
4806 if (removing || (flags & P_NODUP))
4807 {
4808 i = (int)STRLEN(newval);
4809 bs = 0;
4810 for (s = origval; *s; ++s)
4811 {
4812 if ((!(flags & P_COMMA)
4813 || s == origval
4814 || (s[-1] == ',' && !(bs & 1)))
4815 && STRNCMP(s, newval, i) == 0
4816 && (!(flags & P_COMMA)
4817 || s[i] == ','
4818 || s[i] == NUL))
4819 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004820 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004821 * even number of backslashes or a single
4822 * backslash preceded by a comma before it
4823 * is recognized as a separator */
4824 if ((s > origval + 1
4825 && s[-1] == '\\'
4826 && s[-2] != ',')
4827 || (s == origval + 1
4828 && s[-1] == '\\'))
4829
Bram Moolenaar071d4272004-06-13 20:20:40 +00004830 ++bs;
4831 else
4832 bs = 0;
4833 }
4834
4835 /* do not add if already there */
4836 if ((adding || prepending) && *s)
4837 {
4838 prepending = FALSE;
4839 adding = FALSE;
4840 STRCPY(newval, origval);
4841 }
4842 }
4843
4844 /* concatenate the two strings; add a ',' if
4845 * needed */
4846 if (adding || prepending)
4847 {
4848 comma = ((flags & P_COMMA) && *origval != NUL
4849 && *newval != NUL);
4850 if (adding)
4851 {
4852 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004853 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004854 if (comma && i > 1
4855 && (flags & P_ONECOMMA) == P_ONECOMMA
4856 && origval[i - 1] == ','
4857 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004858 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004859 mch_memmove(newval + i + comma, newval,
4860 STRLEN(newval) + 1);
4861 mch_memmove(newval, origval, (size_t)i);
4862 }
4863 else
4864 {
4865 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004866 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004867 }
4868 if (comma)
4869 newval[i] = ',';
4870 }
4871
4872 /* Remove newval[] from origval[]. (Note: "i" has
4873 * been set above and is used here). */
4874 if (removing)
4875 {
4876 STRCPY(newval, origval);
4877 if (*s)
4878 {
4879 /* may need to remove a comma */
4880 if (flags & P_COMMA)
4881 {
4882 if (s == origval)
4883 {
4884 /* include comma after string */
4885 if (s[i] == ',')
4886 ++i;
4887 }
4888 else
4889 {
4890 /* include comma before string */
4891 --s;
4892 ++i;
4893 }
4894 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004895 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004896 }
4897 }
4898
4899 if (flags & P_FLAGLIST)
4900 {
4901 /* Remove flags that appear twice. */
4902 for (s = newval; *s; ++s)
4903 if ((!(flags & P_COMMA) || *s != ',')
4904 && vim_strchr(s + 1, *s) != NULL)
4905 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004906 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004907 --s;
4908 }
4909 }
4910
4911 if (save_arg != NULL) /* number for 'whichwrap' */
4912 arg = save_arg;
4913 new_value_alloced = TRUE;
4914 }
4915
4916 /* Set the new value. */
4917 *(char_u **)(varp) = newval;
4918
Bram Moolenaar53744302015-07-17 17:38:22 +02004919#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004920 if (!starting
4921# ifdef FEAT_CRYPT
4922 && options[opt_idx].indir != PV_KEY
4923# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004924 && origval != NULL)
4925 /* origval may be freed by
4926 * did_set_string_option(), make a copy. */
4927 saved_origval = vim_strsave(origval);
4928#endif
4929
Bram Moolenaar071d4272004-06-13 20:20:40 +00004930 /* Handle side effects, and set the global value for
4931 * ":set" on local options. */
4932 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4933 new_value_alloced, oldval, errbuf, opt_flags);
4934
4935 /* If error detected, print the error message. */
4936 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004937 {
4938#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4939 vim_free(saved_origval);
4940#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004941 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004942 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004943#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4944 if (saved_origval != NULL)
4945 {
4946 char_u buf_type[7];
4947
4948 sprintf((char *)buf_type, "%s",
4949 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004950 set_vim_var_string(VV_OPTION_NEW,
4951 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004952 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4953 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4954 apply_autocmds(EVENT_OPTIONSET,
4955 (char_u *)options[opt_idx].fullname,
4956 NULL, FALSE, NULL);
4957 reset_v_option_vars();
4958 vim_free(saved_origval);
4959 }
4960#endif
4961
Bram Moolenaar071d4272004-06-13 20:20:40 +00004962 }
4963 else /* key code option */
4964 {
4965 char_u *p;
4966
4967 if (nextchar == '&')
4968 {
4969 if (add_termcap_entry(key_name, TRUE) == FAIL)
4970 errmsg = (char_u *)N_("E522: Not found in termcap");
4971 }
4972 else
4973 {
4974 ++arg; /* jump to after the '=' or ':' */
4975 for (p = arg; *p && !vim_iswhite(*p); ++p)
4976 if (*p == '\\' && p[1] != NUL)
4977 ++p;
4978 nextchar = *p;
4979 *p = NUL;
4980 add_termcode(key_name, arg, FALSE);
4981 *p = nextchar;
4982 }
4983 if (full_screen)
4984 ttest(FALSE);
4985 redraw_all_later(CLEAR);
4986 }
4987 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004988
Bram Moolenaar071d4272004-06-13 20:20:40 +00004989 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004990 did_set_option(opt_idx, opt_flags,
4991 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004992 }
4993
4994skip:
4995 /*
4996 * Advance to next argument.
4997 * - skip until a blank found, taking care of backslashes
4998 * - skip blanks
4999 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5000 */
5001 for (i = 0; i < 2 ; ++i)
5002 {
5003 while (*arg != NUL && !vim_iswhite(*arg))
5004 if (*arg++ == '\\' && *arg != NUL)
5005 ++arg;
5006 arg = skipwhite(arg);
5007 if (*arg != '=')
5008 break;
5009 }
5010 }
5011
5012 if (errmsg != NULL)
5013 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005014 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005015 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016 if (i + (arg - startarg) < IOSIZE)
5017 {
5018 /* append the argument with the error */
5019 STRCAT(IObuff, ": ");
5020 mch_memmove(IObuff + i, startarg, (arg - startarg));
5021 IObuff[i + (arg - startarg)] = NUL;
5022 }
5023 /* make sure all characters are printable */
5024 trans_characters(IObuff, IOSIZE);
5025
5026 ++no_wait_return; /* wait_return done later */
5027 emsg(IObuff); /* show error highlighted */
5028 --no_wait_return;
5029
5030 return FAIL;
5031 }
5032
5033 arg = skipwhite(arg);
5034 }
5035
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005036theend:
5037 if (silent_mode && did_show)
5038 {
5039 /* After displaying option values in silent mode. */
5040 silent_mode = FALSE;
5041 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5042 msg_putchar('\n');
5043 cursor_on(); /* msg_start() switches it off */
5044 out_flush();
5045 silent_mode = TRUE;
5046 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5047 }
5048
Bram Moolenaar071d4272004-06-13 20:20:40 +00005049 return OK;
5050}
5051
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005052/*
5053 * Call this when an option has been given a new value through a user command.
5054 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5055 */
5056 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005057did_set_option(
5058 int opt_idx,
5059 int opt_flags, /* possibly with OPT_MODELINE */
5060 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005061{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005062 long_u *p;
5063
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005064 options[opt_idx].flags |= P_WAS_SET;
5065
5066 /* When an option is set in the sandbox, from a modeline or in secure mode
5067 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005068 * flag. */
5069 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005070 if (secure
5071#ifdef HAVE_SANDBOX
5072 || sandbox != 0
5073#endif
5074 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005075 *p = *p | P_INSECURE;
5076 else if (new_value)
5077 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005078}
5079
Bram Moolenaar071d4272004-06-13 20:20:40 +00005080 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005081illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005082{
5083 if (errbuf == NULL)
5084 return (char_u *)"";
5085 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005086 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005087 return errbuf;
5088}
5089
5090/*
5091 * Convert a key name or string into a key value.
5092 * Used for 'wildchar' and 'cedit' options.
5093 */
5094 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005095string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005096{
5097 if (*arg == '<')
5098 return find_key_option(arg + 1);
5099 if (*arg == '^')
5100 return Ctrl_chr(arg[1]);
5101 return *arg;
5102}
5103
5104#ifdef FEAT_CMDWIN
5105/*
5106 * Check value of 'cedit' and set cedit_key.
5107 * Returns NULL if value is OK, error message otherwise.
5108 */
5109 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005110check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111{
5112 int n;
5113
5114 if (*p_cedit == NUL)
5115 cedit_key = -1;
5116 else
5117 {
5118 n = string_to_key(p_cedit);
5119 if (vim_isprintc(n))
5120 return e_invarg;
5121 cedit_key = n;
5122 }
5123 return NULL;
5124}
5125#endif
5126
5127#ifdef FEAT_TITLE
5128/*
5129 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5130 * maketitle() to create and display it.
5131 * When switching the title or icon off, call mch_restore_title() to get
5132 * the old value back.
5133 */
5134 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005135did_set_title(
5136 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005137{
5138 if (starting != NO_SCREEN
5139#ifdef FEAT_GUI
5140 && !gui.starting
5141#endif
5142 )
5143 {
5144 maketitle();
5145 if (icon)
5146 {
5147 if (!p_icon)
5148 mch_restore_title(2);
5149 }
5150 else
5151 {
5152 if (!p_title)
5153 mch_restore_title(1);
5154 }
5155 }
5156}
5157#endif
5158
5159/*
5160 * set_options_bin - called when 'bin' changes value.
5161 */
5162 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005163set_options_bin(
5164 int oldval,
5165 int newval,
5166 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005167{
5168 /*
5169 * The option values that are changed when 'bin' changes are
5170 * copied when 'bin is set and restored when 'bin' is reset.
5171 */
5172 if (newval)
5173 {
5174 if (!oldval) /* switched on */
5175 {
5176 if (!(opt_flags & OPT_GLOBAL))
5177 {
5178 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5179 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5180 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5181 curbuf->b_p_et_nobin = curbuf->b_p_et;
5182 }
5183 if (!(opt_flags & OPT_LOCAL))
5184 {
5185 p_tw_nobin = p_tw;
5186 p_wm_nobin = p_wm;
5187 p_ml_nobin = p_ml;
5188 p_et_nobin = p_et;
5189 }
5190 }
5191
5192 if (!(opt_flags & OPT_GLOBAL))
5193 {
5194 curbuf->b_p_tw = 0; /* no automatic line wrap */
5195 curbuf->b_p_wm = 0; /* no automatic line wrap */
5196 curbuf->b_p_ml = 0; /* no modelines */
5197 curbuf->b_p_et = 0; /* no expandtab */
5198 }
5199 if (!(opt_flags & OPT_LOCAL))
5200 {
5201 p_tw = 0;
5202 p_wm = 0;
5203 p_ml = FALSE;
5204 p_et = FALSE;
5205 p_bin = TRUE; /* needed when called for the "-b" argument */
5206 }
5207 }
5208 else if (oldval) /* switched off */
5209 {
5210 if (!(opt_flags & OPT_GLOBAL))
5211 {
5212 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5213 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5214 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5215 curbuf->b_p_et = curbuf->b_p_et_nobin;
5216 }
5217 if (!(opt_flags & OPT_LOCAL))
5218 {
5219 p_tw = p_tw_nobin;
5220 p_wm = p_wm_nobin;
5221 p_ml = p_ml_nobin;
5222 p_et = p_et_nobin;
5223 }
5224 }
5225}
5226
5227#ifdef FEAT_VIMINFO
5228/*
5229 * Find the parameter represented by the given character (eg ', :, ", or /),
5230 * and return its associated value in the 'viminfo' string.
5231 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005232 * If the parameter is not specified in the string or there is no following
5233 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234 */
5235 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005236get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005237{
5238 char_u *p;
5239
5240 p = find_viminfo_parameter(type);
5241 if (p != NULL && VIM_ISDIGIT(*p))
5242 return atoi((char *)p);
5243 return -1;
5244}
5245
5246/*
5247 * Find the parameter represented by the given character (eg ''', ':', '"', or
5248 * '/') in the 'viminfo' option and return a pointer to the string after it.
5249 * Return NULL if the parameter is not specified in the string.
5250 */
5251 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005252find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005253{
5254 char_u *p;
5255
5256 for (p = p_viminfo; *p; ++p)
5257 {
5258 if (*p == type)
5259 return p + 1;
5260 if (*p == 'n') /* 'n' is always the last one */
5261 break;
5262 p = vim_strchr(p, ','); /* skip until next ',' */
5263 if (p == NULL) /* hit the end without finding parameter */
5264 break;
5265 }
5266 return NULL;
5267}
5268#endif
5269
5270/*
5271 * Expand environment variables for some string options.
5272 * These string options cannot be indirect!
5273 * If "val" is NULL expand the current value of the option.
5274 * Return pointer to NameBuff, or NULL when not expanded.
5275 */
5276 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005277option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005278{
5279 /* if option doesn't need expansion nothing to do */
5280 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5281 return NULL;
5282
5283 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5284 * expand_env() would truncate the string. */
5285 if (val != NULL && STRLEN(val) > MAXPATHL)
5286 return NULL;
5287
5288 if (val == NULL)
5289 val = *(char_u **)options[opt_idx].var;
5290
5291 /*
5292 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5293 * Escape spaces when expanding 'tags', they are used to separate file
5294 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005295 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005296 */
5297 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005298 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005299#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005300 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5301#endif
5302 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005303 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5304 return NULL;
5305
5306 return NameBuff;
5307}
5308
5309/*
5310 * After setting various option values: recompute variables that depend on
5311 * option values.
5312 */
5313 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005314didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005315{
5316 /* initialize the table for 'iskeyword' et.al. */
5317 (void)init_chartab();
5318
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005319#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005321#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005323 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005324#ifdef FEAT_SESSION
5325 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5326 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5327#endif
5328#ifdef FEAT_FOLDING
5329 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5330#endif
5331 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005332 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333#ifdef FEAT_VIRTUALEDIT
5334 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5335#endif
5336#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5337 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5338#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005339#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005340 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005341 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005342 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005343 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005345#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5346 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5347#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005348#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5350#endif
5351#ifdef FEAT_CMDWIN
5352 /* set cedit_key */
5353 (void)check_cedit();
5354#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005355#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005356 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005357#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005358#ifdef FEAT_LINEBREAK
5359 /* initialize the table for 'breakat'. */
5360 fill_breakat_flags();
5361#endif
5362
5363}
5364
5365/*
5366 * More side effects of setting options.
5367 */
5368 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005369didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005370{
5371 /* Initialize the highlight_attr[] table. */
5372 (void)highlight_changed();
5373
5374 /* Parse default for 'wildmode' */
5375 check_opt_wim();
5376
5377 (void)set_chars_option(&p_lcs);
5378#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5379 /* Parse default for 'fillchars'. */
5380 (void)set_chars_option(&p_fcs);
5381#endif
5382
5383#ifdef FEAT_CLIPBOARD
5384 /* Parse default for 'clipboard' */
5385 (void)check_clipboard_option();
5386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387}
5388
5389/*
5390 * Check for string options that are NULL (normally only termcap options).
5391 */
5392 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005393check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005394{
5395 int opt_idx;
5396
5397 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5398 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5399 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5400}
5401
5402/*
5403 * Check string options in a buffer for NULL value.
5404 */
5405 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005406check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005407{
5408#if defined(FEAT_QUICKFIX)
5409 check_string_option(&buf->b_p_bh);
5410 check_string_option(&buf->b_p_bt);
5411#endif
5412#ifdef FEAT_MBYTE
5413 check_string_option(&buf->b_p_fenc);
5414#endif
5415 check_string_option(&buf->b_p_ff);
5416#ifdef FEAT_FIND_ID
5417 check_string_option(&buf->b_p_def);
5418 check_string_option(&buf->b_p_inc);
5419# ifdef FEAT_EVAL
5420 check_string_option(&buf->b_p_inex);
5421# endif
5422#endif
5423#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5424 check_string_option(&buf->b_p_inde);
5425 check_string_option(&buf->b_p_indk);
5426#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005427#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5428 check_string_option(&buf->b_p_bexpr);
5429#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005430#if defined(FEAT_CRYPT)
5431 check_string_option(&buf->b_p_cm);
5432#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005433#if defined(FEAT_EVAL)
5434 check_string_option(&buf->b_p_fex);
5435#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005436#ifdef FEAT_CRYPT
5437 check_string_option(&buf->b_p_key);
5438#endif
5439 check_string_option(&buf->b_p_kp);
5440 check_string_option(&buf->b_p_mps);
5441 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005442 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005443 check_string_option(&buf->b_p_isk);
5444#ifdef FEAT_COMMENTS
5445 check_string_option(&buf->b_p_com);
5446#endif
5447#ifdef FEAT_FOLDING
5448 check_string_option(&buf->b_p_cms);
5449#endif
5450 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005451#ifdef FEAT_TEXTOBJ
5452 check_string_option(&buf->b_p_qe);
5453#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005454#ifdef FEAT_SYN_HL
5455 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005456 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005457#endif
5458#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005459 check_string_option(&buf->b_s.b_p_spc);
5460 check_string_option(&buf->b_s.b_p_spf);
5461 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462#endif
5463#ifdef FEAT_SEARCHPATH
5464 check_string_option(&buf->b_p_sua);
5465#endif
5466#ifdef FEAT_CINDENT
5467 check_string_option(&buf->b_p_cink);
5468 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005469 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005470#endif
5471#ifdef FEAT_AUTOCMD
5472 check_string_option(&buf->b_p_ft);
5473#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005474#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5475 check_string_option(&buf->b_p_cinw);
5476#endif
5477#ifdef FEAT_INS_EXPAND
5478 check_string_option(&buf->b_p_cpt);
5479#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005480#ifdef FEAT_COMPL_FUNC
5481 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005482 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005484#ifdef FEAT_KEYMAP
5485 check_string_option(&buf->b_p_keymap);
5486#endif
5487#ifdef FEAT_QUICKFIX
5488 check_string_option(&buf->b_p_gp);
5489 check_string_option(&buf->b_p_mp);
5490 check_string_option(&buf->b_p_efm);
5491#endif
5492 check_string_option(&buf->b_p_ep);
5493 check_string_option(&buf->b_p_path);
5494 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005495 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496#ifdef FEAT_INS_EXPAND
5497 check_string_option(&buf->b_p_dict);
5498 check_string_option(&buf->b_p_tsr);
5499#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005500#ifdef FEAT_LISP
5501 check_string_option(&buf->b_p_lw);
5502#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005503 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504}
5505
5506/*
5507 * Free the string allocated for an option.
5508 * Checks for the string being empty_option. This may happen if we're out of
5509 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5510 * check_options().
5511 * Does NOT check for P_ALLOCED flag!
5512 */
5513 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005514free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005515{
5516 if (p != empty_option)
5517 vim_free(p);
5518}
5519
5520 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005521clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522{
5523 if (*pp != empty_option)
5524 vim_free(*pp);
5525 *pp = empty_option;
5526}
5527
5528 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005529check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005530{
5531 if (*pp == NULL)
5532 *pp = empty_option;
5533}
5534
5535/*
5536 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5537 */
5538 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005539set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540{
5541 int opt_idx;
5542
5543 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5544 if (options[opt_idx].var == (char_u *)p)
5545 {
5546 options[opt_idx].flags |= P_ALLOCED;
5547 return;
5548 }
5549 return; /* cannot happen: didn't find it! */
5550}
5551
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005552#if defined(FEAT_EVAL) || defined(PROTO)
5553/*
5554 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5555 * Return FALSE when it wasn't.
5556 * Return -1 for an unknown option.
5557 */
5558 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005559was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005560{
5561 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005562 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005563
5564 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005565 {
5566 flagp = insecure_flag(idx, opt_flags);
5567 return (*flagp & P_INSECURE) != 0;
5568 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005569 EMSG2(_(e_intern2), "was_set_insecurely()");
5570 return -1;
5571}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005572
5573/*
5574 * Get a pointer to the flags used for the P_INSECURE flag of option
5575 * "opt_idx". For some local options a local flags field is used.
5576 */
5577 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005578insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005579{
5580 if (opt_flags & OPT_LOCAL)
5581 switch ((int)options[opt_idx].indir)
5582 {
5583#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005584 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005585#endif
5586#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005587# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005588 case PV_FDE: return &curwin->w_p_fde_flags;
5589 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005590# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005591# ifdef FEAT_BEVAL
5592 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5593# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005594# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005595 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005596# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005597 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005598# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005599 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005600# endif
5601#endif
5602 }
5603
5604 /* Nothing special, return global flags field. */
5605 return &options[opt_idx].flags;
5606}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005607#endif
5608
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005609#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005610static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005611
5612/*
5613 * Redraw the window title and/or tab page text later.
5614 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005615static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005616{
5617 need_maketitle = TRUE;
5618# ifdef FEAT_WINDOWS
5619 redraw_tabline = TRUE;
5620# endif
5621}
5622#endif
5623
Bram Moolenaar071d4272004-06-13 20:20:40 +00005624/*
5625 * Set a string option to a new value (without checking the effect).
5626 * The string is copied into allocated memory.
5627 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005628 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005629 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630 */
5631 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005632set_string_option_direct(
5633 char_u *name,
5634 int opt_idx,
5635 char_u *val,
5636 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5637 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638{
5639 char_u *s;
5640 char_u **varp;
5641 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005642 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643
Bram Moolenaar89d40322006-08-29 15:30:07 +00005644 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005646 idx = findoption(name);
5647 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005648 {
5649 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005650 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005651 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005652 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005653 }
5654
Bram Moolenaar89d40322006-08-29 15:30:07 +00005655 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656 return;
5657
5658 s = vim_strsave(val);
5659 if (s != NULL)
5660 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005661 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005663 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664 free_string_option(*varp);
5665 *varp = s;
5666
5667 /* For buffer/window local option may also set the global value. */
5668 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005669 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670
Bram Moolenaar89d40322006-08-29 15:30:07 +00005671 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672
5673 /* When setting both values of a global option with a local value,
5674 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005675 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676 {
5677 free_string_option(*varp);
5678 *varp = empty_option;
5679 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005680# ifdef FEAT_EVAL
5681 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005682 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005683 set_sid == 0 ? current_SID : set_sid);
5684# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685 }
5686}
5687
5688/*
5689 * Set global value for string option when it's a local option.
5690 */
5691 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005692set_string_option_global(
5693 int opt_idx, /* option index */
5694 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695{
5696 char_u **p, *s;
5697
5698 /* the global value is always allocated */
5699 if (options[opt_idx].var == VAR_WIN)
5700 p = (char_u **)GLOBAL_WO(varp);
5701 else
5702 p = (char_u **)options[opt_idx].var;
5703 if (options[opt_idx].indir != PV_NONE
5704 && p != varp
5705 && (s = vim_strsave(*varp)) != NULL)
5706 {
5707 free_string_option(*p);
5708 *p = s;
5709 }
5710}
5711
5712/*
5713 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005714 *
5715 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005717 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005718set_string_option(
5719 int opt_idx,
5720 char_u *value,
5721 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722{
5723 char_u *s;
5724 char_u **varp;
5725 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005726#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5727 char_u *saved_oldval = NULL;
5728#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005729 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005730
5731 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005732 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005733
5734 s = vim_strsave(value);
5735 if (s != NULL)
5736 {
5737 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5738 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005739 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005740 ? OPT_GLOBAL : OPT_LOCAL)
5741 : opt_flags);
5742 oldval = *varp;
5743 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005744
5745#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005746 if (!starting
5747# ifdef FEAT_CRYPT
5748 && options[opt_idx].indir != PV_KEY
5749# endif
5750 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005751 saved_oldval = vim_strsave(oldval);
5752#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005753 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5754 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005755 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005756
5757 /* call autocomamnd after handling side effects */
5758#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5759 if (saved_oldval != NULL)
5760 {
5761 char_u buf_type[7];
5762 sprintf((char *)buf_type, "%s",
5763 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005764 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5765 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005766 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5767 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5768 reset_v_option_vars();
5769 vim_free(saved_oldval);
5770 }
5771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005773 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005774}
5775
5776/*
5777 * Handle string options that need some action to perform when changed.
5778 * Returns NULL for success, or an error message for an error.
5779 */
5780 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005781did_set_string_option(
5782 int opt_idx, /* index in options[] table */
5783 char_u **varp, /* pointer to the option variable */
5784 int new_value_alloced, /* new value was allocated */
5785 char_u *oldval, /* previous value of the option */
5786 char_u *errbuf, /* buffer for errors, or NULL */
5787 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005788{
5789 char_u *errmsg = NULL;
5790 char_u *s, *p;
5791 int did_chartab = FALSE;
5792 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005793 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005794#ifdef FEAT_GUI
5795 /* set when changing an option that only requires a redraw in the GUI */
5796 int redraw_gui_only = FALSE;
5797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798
5799 /* Get the global option to compare with, otherwise we would have to check
5800 * two values for all local options. */
5801 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5802
5803 /* Disallow changing some options from secure mode */
5804 if ((secure
5805#ifdef HAVE_SANDBOX
5806 || sandbox != 0
5807#endif
5808 ) && (options[opt_idx].flags & P_SECURE))
5809 {
5810 errmsg = e_secure;
5811 }
5812
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005813 /* Check for a "normal" file name in some options. Disallow a path
5814 * separator (slash and/or backslash), wildcards and characters that are
5815 * often illegal in a file name. */
5816 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005817 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005818 {
5819 errmsg = e_invarg;
5820 }
5821
Bram Moolenaar071d4272004-06-13 20:20:40 +00005822 /* 'term' */
5823 else if (varp == &T_NAME)
5824 {
5825 if (T_NAME[0] == NUL)
5826 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5827#ifdef FEAT_GUI
5828 if (gui.in_use)
5829 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5830 else if (term_is_gui(T_NAME))
5831 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5832#endif
5833 else if (set_termname(T_NAME) == FAIL)
5834 errmsg = (char_u *)N_("E522: Not found in termcap");
5835 else
5836 /* Screen colors may have changed. */
5837 redraw_later_clear();
5838 }
5839
5840 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005841 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005842 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005843 char_u *bkc = p_bkc;
5844 unsigned int *flags = &bkc_flags;
5845
5846 if (opt_flags & OPT_LOCAL)
5847 {
5848 bkc = curbuf->b_p_bkc;
5849 flags = &curbuf->b_bkc_flags;
5850 }
5851
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005852 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5853 /* make the local value empty: use the global value */
5854 *flags = 0;
5855 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005857 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5858 errmsg = e_invarg;
5859 if ((((int)*flags & BKC_AUTO) != 0)
5860 + (((int)*flags & BKC_YES) != 0)
5861 + (((int)*flags & BKC_NO) != 0) != 1)
5862 {
5863 /* Must have exactly one of "auto", "yes" and "no". */
5864 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5865 errmsg = e_invarg;
5866 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867 }
5868 }
5869
5870 /* 'backupext' and 'patchmode' */
5871 else if (varp == &p_bex || varp == &p_pm)
5872 {
5873 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5874 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5875 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5876 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005877#ifdef FEAT_LINEBREAK
5878 /* 'breakindentopt' */
5879 else if (varp == &curwin->w_p_briopt)
5880 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005881 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005882 errmsg = e_invarg;
5883 }
5884#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885
5886 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005887 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005888 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005889 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890 */
5891 else if ( varp == &p_isi
5892 || varp == &(curbuf->b_p_isk)
5893 || varp == &p_isp
5894 || varp == &p_isf)
5895 {
5896 if (init_chartab() == FAIL)
5897 {
5898 did_chartab = TRUE; /* need to restore it below */
5899 errmsg = e_invarg; /* error in value */
5900 }
5901 }
5902
5903 /* 'helpfile' */
5904 else if (varp == &p_hf)
5905 {
5906 /* May compute new values for $VIM and $VIMRUNTIME */
5907 if (didset_vim)
5908 {
5909 vim_setenv((char_u *)"VIM", (char_u *)"");
5910 didset_vim = FALSE;
5911 }
5912 if (didset_vimruntime)
5913 {
5914 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5915 didset_vimruntime = FALSE;
5916 }
5917 }
5918
Bram Moolenaar1a384422010-07-14 19:53:30 +02005919#ifdef FEAT_SYN_HL
5920 /* 'colorcolumn' */
5921 else if (varp == &curwin->w_p_cc)
5922 errmsg = check_colorcolumn(curwin);
5923#endif
5924
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925#ifdef FEAT_MULTI_LANG
5926 /* 'helplang' */
5927 else if (varp == &p_hlg)
5928 {
5929 /* Check for "", "ab", "ab,cd", etc. */
5930 for (s = p_hlg; *s != NUL; s += 3)
5931 {
5932 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5933 {
5934 errmsg = e_invarg;
5935 break;
5936 }
5937 if (s[2] == NUL)
5938 break;
5939 }
5940 }
5941#endif
5942
5943 /* 'highlight' */
5944 else if (varp == &p_hl)
5945 {
5946 if (highlight_changed() == FAIL)
5947 errmsg = e_invarg; /* invalid flags */
5948 }
5949
5950 /* 'nrformats' */
5951 else if (gvarp == &p_nf)
5952 {
5953 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5954 errmsg = e_invarg;
5955 }
5956
5957#ifdef FEAT_SESSION
5958 /* 'sessionoptions' */
5959 else if (varp == &p_ssop)
5960 {
5961 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5962 errmsg = e_invarg;
5963 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5964 {
5965 /* Don't allow both "sesdir" and "curdir". */
5966 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5967 errmsg = e_invarg;
5968 }
5969 }
5970 /* 'viewoptions' */
5971 else if (varp == &p_vop)
5972 {
5973 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5974 errmsg = e_invarg;
5975 }
5976#endif
5977
5978 /* 'scrollopt' */
5979#ifdef FEAT_SCROLLBIND
5980 else if (varp == &p_sbo)
5981 {
5982 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5983 errmsg = e_invarg;
5984 }
5985#endif
5986
5987 /* 'ambiwidth' */
5988#ifdef FEAT_MBYTE
5989 else if (varp == &p_ambw)
5990 {
5991 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5992 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005993 else if (set_chars_option(&p_lcs) != NULL)
5994 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5995# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5996 else if (set_chars_option(&p_fcs) != NULL)
5997 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5998# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999 }
6000#endif
6001
6002 /* 'background' */
6003 else if (varp == &p_bg)
6004 {
6005 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6006 {
6007#ifdef FEAT_EVAL
6008 int dark = (*p_bg == 'd');
6009#endif
6010
6011 init_highlight(FALSE, FALSE);
6012
6013#ifdef FEAT_EVAL
6014 if (dark != (*p_bg == 'd')
6015 && get_var_value((char_u *)"g:colors_name") != NULL)
6016 {
6017 /* The color scheme must have set 'background' back to another
6018 * value, that's not what we want here. Disable the color
6019 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006020 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006021 free_string_option(p_bg);
6022 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6023 check_string_option(&p_bg);
6024 init_highlight(FALSE, FALSE);
6025 }
6026#endif
6027 }
6028 else
6029 errmsg = e_invarg;
6030 }
6031
6032 /* 'wildmode' */
6033 else if (varp == &p_wim)
6034 {
6035 if (check_opt_wim() == FAIL)
6036 errmsg = e_invarg;
6037 }
6038
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006039#ifdef FEAT_CMDL_COMPL
6040 /* 'wildoptions' */
6041 else if (varp == &p_wop)
6042 {
6043 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6044 errmsg = e_invarg;
6045 }
6046#endif
6047
Bram Moolenaar071d4272004-06-13 20:20:40 +00006048#ifdef FEAT_WAK
6049 /* 'winaltkeys' */
6050 else if (varp == &p_wak)
6051 {
6052 if (*p_wak == NUL
6053 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6054 errmsg = e_invarg;
6055# ifdef FEAT_MENU
6056# ifdef FEAT_GUI_MOTIF
6057 else if (gui.in_use)
6058 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6059# else
6060# ifdef FEAT_GUI_GTK
6061 else if (gui.in_use)
6062 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6063# endif
6064# endif
6065# endif
6066 }
6067#endif
6068
6069#ifdef FEAT_AUTOCMD
6070 /* 'eventignore' */
6071 else if (varp == &p_ei)
6072 {
6073 if (check_ei() == FAIL)
6074 errmsg = e_invarg;
6075 }
6076#endif
6077
6078#ifdef FEAT_MBYTE
6079 /* 'encoding' and 'fileencoding' */
6080 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6081 {
6082 if (gvarp == &p_fenc)
6083 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006084 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006085 errmsg = e_modifiable;
6086 else if (vim_strchr(*varp, ',') != NULL)
6087 /* No comma allowed in 'fileencoding'; catches confusing it
6088 * with 'fileencodings'. */
6089 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006091 {
6092# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006093 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006094 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006096 /* Add 'fileencoding' to the swap file. */
6097 ml_setflags(curbuf);
6098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 }
6100 if (errmsg == NULL)
6101 {
6102 /* canonize the value, so that STRCMP() can be used on it */
6103 p = enc_canonize(*varp);
6104 if (p != NULL)
6105 {
6106 vim_free(*varp);
6107 *varp = p;
6108 }
6109 if (varp == &p_enc)
6110 {
6111 errmsg = mb_init();
6112# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006113 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114# endif
6115 }
6116 }
6117
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006118# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6120 {
6121 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6122 if (STRCMP(p_tenc, "utf-8") != 0)
6123 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6124 }
6125# endif
6126
6127 if (errmsg == NULL)
6128 {
6129# ifdef FEAT_KEYMAP
6130 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6131 * (with another encoding). */
6132 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6133 (void)keymap_init();
6134# endif
6135
6136 /* When 'termencoding' is not empty and 'encoding' changes or when
6137 * 'termencoding' changes, need to setup for keyboard input and
6138 * display output conversion. */
6139 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6140 {
6141 convert_setup(&input_conv, p_tenc, p_enc);
6142 convert_setup(&output_conv, p_enc, p_tenc);
6143 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006144
6145# if defined(WIN3264) && defined(FEAT_MBYTE)
6146 /* $HOME may have characters in active code page. */
6147 if (varp == &p_enc)
6148 init_homedir();
6149# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150 }
6151 }
6152#endif
6153
6154#if defined(FEAT_POSTSCRIPT)
6155 else if (varp == &p_penc)
6156 {
6157 /* Canonize printencoding if VIM standard one */
6158 p = enc_canonize(p_penc);
6159 if (p != NULL)
6160 {
6161 vim_free(p_penc);
6162 p_penc = p;
6163 }
6164 else
6165 {
6166 /* Ensure lower case and '-' for '_' */
6167 for (s = p_penc; *s != NUL; s++)
6168 {
6169 if (*s == '_')
6170 *s = '-';
6171 else
6172 *s = TOLOWER_ASC(*s);
6173 }
6174 }
6175 }
6176#endif
6177
Bram Moolenaar9372a112005-12-06 19:59:18 +00006178#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179 else if (varp == &p_imak)
6180 {
6181 if (gui.in_use && !im_xim_isvalid_imactivate())
6182 errmsg = e_invarg;
6183 }
6184#endif
6185
6186#ifdef FEAT_KEYMAP
6187 else if (varp == &curbuf->b_p_keymap)
6188 {
6189 /* load or unload key mapping tables */
6190 errmsg = keymap_init();
6191
Bram Moolenaarfab06232009-03-04 03:13:35 +00006192 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006193 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006194 if (*curbuf->b_p_keymap != NUL)
6195 {
6196 /* Installed a new keymap, switch on using it. */
6197 curbuf->b_p_iminsert = B_IMODE_LMAP;
6198 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6199 curbuf->b_p_imsearch = B_IMODE_LMAP;
6200 }
6201 else
6202 {
6203 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6204 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6205 curbuf->b_p_iminsert = B_IMODE_NONE;
6206 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6207 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6208 }
6209 if ((opt_flags & OPT_LOCAL) == 0)
6210 {
6211 set_iminsert_global();
6212 set_imsearch_global();
6213 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006214# ifdef FEAT_WINDOWS
6215 status_redraw_curbuf();
6216# endif
6217 }
6218 }
6219#endif
6220
6221 /* 'fileformat' */
6222 else if (gvarp == &p_ff)
6223 {
6224 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6225 errmsg = e_modifiable;
6226 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6227 errmsg = e_invarg;
6228 else
6229 {
6230 /* may also change 'textmode' */
6231 if (get_fileformat(curbuf) == EOL_DOS)
6232 curbuf->b_p_tx = TRUE;
6233 else
6234 curbuf->b_p_tx = FALSE;
6235#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006236 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006238 /* update flag in swap file */
6239 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006240 /* Redraw needed when switching to/from "mac": a CR in the text
6241 * will be displayed differently. */
6242 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6243 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006244 }
6245 }
6246
6247 /* 'fileformats' */
6248 else if (varp == &p_ffs)
6249 {
6250 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6251 errmsg = e_invarg;
6252 else
6253 {
6254 /* also change 'textauto' */
6255 if (*p_ffs == NUL)
6256 p_ta = FALSE;
6257 else
6258 p_ta = TRUE;
6259 }
6260 }
6261
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006262#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263 /* 'cryptkey' */
6264 else if (gvarp == &p_key)
6265 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006266# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006267 /* Make sure the ":set" command doesn't show the new value in the
6268 * history. */
6269 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006270# endif
6271 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6272 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006273 ml_set_crypt_key(curbuf, oldval,
6274 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006275 }
6276
6277 else if (gvarp == &p_cm)
6278 {
6279 if (opt_flags & OPT_LOCAL)
6280 p = curbuf->b_p_cm;
6281 else
6282 p = p_cm;
6283 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6284 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006285 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006286 errmsg = e_invarg;
6287 else
6288 {
6289 /* When setting the global value to empty, make it "zip". */
6290 if (*p_cm == NUL)
6291 {
6292 if (new_value_alloced)
6293 free_string_option(p_cm);
6294 p_cm = vim_strsave((char_u *)"zip");
6295 new_value_alloced = TRUE;
6296 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006297 /* When using ":set cm=name" the local value is going to be empty.
6298 * Do that here, otherwise the crypt functions will still use the
6299 * local value. */
6300 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6301 {
6302 free_string_option(curbuf->b_p_cm);
6303 curbuf->b_p_cm = empty_option;
6304 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006305
6306 /* Need to update the swapfile when the effective method changed.
6307 * Set "s" to the effective old value, "p" to the effective new
6308 * method and compare. */
6309 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6310 s = p_cm; /* was previously using the global value */
6311 else
6312 s = oldval;
6313 if (*curbuf->b_p_cm == NUL)
6314 p = p_cm; /* is now using the global value */
6315 else
6316 p = curbuf->b_p_cm;
6317 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006318 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006319
6320 /* If the global value changes need to update the swapfile for all
6321 * buffers using that value. */
6322 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6323 {
6324 buf_T *buf;
6325
6326 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6327 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006328 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006329 }
6330 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331 }
6332#endif
6333
6334 /* 'matchpairs' */
6335 else if (gvarp == &p_mps)
6336 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006337#ifdef FEAT_MBYTE
6338 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006340 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006341 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006342 int x2 = -1;
6343 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006344
6345 if (*p != NUL)
6346 p += mb_ptr2len(p);
6347 if (*p != NUL)
6348 x2 = *p++;
6349 if (*p != NUL)
6350 {
6351 x3 = mb_ptr2char(p);
6352 p += mb_ptr2len(p);
6353 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006354 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006355 {
6356 errmsg = e_invarg;
6357 break;
6358 }
6359 if (*p == NUL)
6360 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006361 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006362 }
6363 else
6364#endif
6365 {
6366 /* Check for "x:y,x:y" */
6367 for (p = *varp; *p != NUL; p += 4)
6368 {
6369 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6370 {
6371 errmsg = e_invarg;
6372 break;
6373 }
6374 if (p[3] == NUL)
6375 break;
6376 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 }
6378 }
6379
6380#ifdef FEAT_COMMENTS
6381 /* 'comments' */
6382 else if (gvarp == &p_com)
6383 {
6384 for (s = *varp; *s; )
6385 {
6386 while (*s && *s != ':')
6387 {
6388 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6389 && !VIM_ISDIGIT(*s) && *s != '-')
6390 {
6391 errmsg = illegal_char(errbuf, *s);
6392 break;
6393 }
6394 ++s;
6395 }
6396 if (*s++ == NUL)
6397 errmsg = (char_u *)N_("E524: Missing colon");
6398 else if (*s == ',' || *s == NUL)
6399 errmsg = (char_u *)N_("E525: Zero length string");
6400 if (errmsg != NULL)
6401 break;
6402 while (*s && *s != ',')
6403 {
6404 if (*s == '\\' && s[1] != NUL)
6405 ++s;
6406 ++s;
6407 }
6408 s = skip_to_option_part(s);
6409 }
6410 }
6411#endif
6412
6413 /* 'listchars' */
6414 else if (varp == &p_lcs)
6415 {
6416 errmsg = set_chars_option(varp);
6417 }
6418
6419#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6420 /* 'fillchars' */
6421 else if (varp == &p_fcs)
6422 {
6423 errmsg = set_chars_option(varp);
6424 }
6425#endif
6426
6427#ifdef FEAT_CMDWIN
6428 /* 'cedit' */
6429 else if (varp == &p_cedit)
6430 {
6431 errmsg = check_cedit();
6432 }
6433#endif
6434
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006435 /* 'verbosefile' */
6436 else if (varp == &p_vfile)
6437 {
6438 verbose_stop();
6439 if (*p_vfile != NUL && verbose_open() == FAIL)
6440 errmsg = e_invarg;
6441 }
6442
Bram Moolenaar071d4272004-06-13 20:20:40 +00006443#ifdef FEAT_VIMINFO
6444 /* 'viminfo' */
6445 else if (varp == &p_viminfo)
6446 {
6447 for (s = p_viminfo; *s;)
6448 {
6449 /* Check it's a valid character */
6450 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6451 {
6452 errmsg = illegal_char(errbuf, *s);
6453 break;
6454 }
6455 if (*s == 'n') /* name is always last one */
6456 {
6457 break;
6458 }
6459 else if (*s == 'r') /* skip until next ',' */
6460 {
6461 while (*++s && *s != ',')
6462 ;
6463 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006464 else if (*s == '%')
6465 {
6466 /* optional number */
6467 while (vim_isdigit(*++s))
6468 ;
6469 }
6470 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006471 ++s; /* no extra chars */
6472 else /* must have a number */
6473 {
6474 while (vim_isdigit(*++s))
6475 ;
6476
6477 if (!VIM_ISDIGIT(*(s - 1)))
6478 {
6479 if (errbuf != NULL)
6480 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006481 sprintf((char *)errbuf,
6482 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 transchar_byte(*(s - 1)));
6484 errmsg = errbuf;
6485 }
6486 else
6487 errmsg = (char_u *)"";
6488 break;
6489 }
6490 }
6491 if (*s == ',')
6492 ++s;
6493 else if (*s)
6494 {
6495 if (errbuf != NULL)
6496 errmsg = (char_u *)N_("E527: Missing comma");
6497 else
6498 errmsg = (char_u *)"";
6499 break;
6500 }
6501 }
6502 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6503 errmsg = (char_u *)N_("E528: Must specify a ' value");
6504 }
6505#endif /* FEAT_VIMINFO */
6506
6507 /* terminal options */
6508 else if (istermoption(&options[opt_idx]) && full_screen)
6509 {
6510 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6511 if (varp == &T_CCO)
6512 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006513 int colors = atoi((char *)T_CCO);
6514
6515 /* Only reinitialize colors if t_Co value has really changed to
6516 * avoid expensive reload of colorscheme if t_Co is set to the
6517 * same value multiple times. */
6518 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006519 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006520 t_colors = colors;
6521 if (t_colors <= 1)
6522 {
6523 if (new_value_alloced)
6524 vim_free(T_CCO);
6525 T_CCO = empty_option;
6526 }
6527 /* We now have a different color setup, initialize it again. */
6528 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006530 }
6531 ttest(FALSE);
6532 if (varp == &T_ME)
6533 {
6534 out_str(T_ME);
6535 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006536#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006537 /* Since t_me has been set, this probably means that the user
6538 * wants to use this as default colors. Need to reset default
6539 * background/foreground colors. */
6540 mch_set_normal_colors();
6541#endif
6542 }
6543 }
6544
6545#ifdef FEAT_LINEBREAK
6546 /* 'showbreak' */
6547 else if (varp == &p_sbr)
6548 {
6549 for (s = p_sbr; *s; )
6550 {
6551 if (ptr2cells(s) != 1)
6552 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006553 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554 }
6555 }
6556#endif
6557
6558#ifdef FEAT_GUI
6559 /* 'guifont' */
6560 else if (varp == &p_guifont)
6561 {
6562 if (gui.in_use)
6563 {
6564 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006565# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 /*
6567 * Put up a font dialog and let the user select a new value.
6568 * If this is cancelled go back to the old value but don't
6569 * give an error message.
6570 */
6571 if (STRCMP(p, "*") == 0)
6572 {
6573 p = gui_mch_font_dialog(oldval);
6574
6575 if (new_value_alloced)
6576 free_string_option(p_guifont);
6577
6578 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6579 new_value_alloced = TRUE;
6580 }
6581# endif
6582 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6583 {
6584# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6585 if (STRCMP(p_guifont, "*") == 0)
6586 {
6587 /* Dialog was cancelled: Keep the old value without giving
6588 * an error message. */
6589 if (new_value_alloced)
6590 free_string_option(p_guifont);
6591 p_guifont = vim_strsave(oldval);
6592 new_value_alloced = TRUE;
6593 }
6594 else
6595# endif
6596 errmsg = (char_u *)N_("E596: Invalid font(s)");
6597 }
6598 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006599 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006600 }
6601# ifdef FEAT_XFONTSET
6602 else if (varp == &p_guifontset)
6603 {
6604 if (STRCMP(p_guifontset, "*") == 0)
6605 errmsg = (char_u *)N_("E597: can't select fontset");
6606 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6607 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006608 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006609 }
6610# endif
6611# ifdef FEAT_MBYTE
6612 else if (varp == &p_guifontwide)
6613 {
6614 if (STRCMP(p_guifontwide, "*") == 0)
6615 errmsg = (char_u *)N_("E533: can't select wide font");
6616 else if (gui_get_wide_font() == FAIL)
6617 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006618 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006619 }
6620# endif
6621#endif
6622
6623#ifdef CURSOR_SHAPE
6624 /* 'guicursor' */
6625 else if (varp == &p_guicursor)
6626 errmsg = parse_shape_opt(SHAPE_CURSOR);
6627#endif
6628
6629#ifdef FEAT_MOUSESHAPE
6630 /* 'mouseshape' */
6631 else if (varp == &p_mouseshape)
6632 {
6633 errmsg = parse_shape_opt(SHAPE_MOUSE);
6634 update_mouseshape(-1);
6635 }
6636#endif
6637
6638#ifdef FEAT_PRINTER
6639 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006640 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006641# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006642 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006643 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006644# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006645#endif
6646
6647#ifdef FEAT_LANGMAP
6648 /* 'langmap' */
6649 else if (varp == &p_langmap)
6650 langmap_set();
6651#endif
6652
6653#ifdef FEAT_LINEBREAK
6654 /* 'breakat' */
6655 else if (varp == &p_breakat)
6656 fill_breakat_flags();
6657#endif
6658
6659#ifdef FEAT_TITLE
6660 /* 'titlestring' and 'iconstring' */
6661 else if (varp == &p_titlestring || varp == &p_iconstring)
6662 {
6663# ifdef FEAT_STL_OPT
6664 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6665
6666 /* NULL => statusline syntax */
6667 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6668 stl_syntax |= flagval;
6669 else
6670 stl_syntax &= ~flagval;
6671# endif
6672 did_set_title(varp == &p_iconstring);
6673
6674 }
6675#endif
6676
6677#ifdef FEAT_GUI
6678 /* 'guioptions' */
6679 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006680 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006681 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006682 redraw_gui_only = TRUE;
6683 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006684#endif
6685
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006686#if defined(FEAT_GUI_TABLINE)
6687 /* 'guitablabel' */
6688 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006689 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006690 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006691 redraw_gui_only = TRUE;
6692 }
6693 /* 'guitabtooltip' */
6694 else if (varp == &p_gtt)
6695 {
6696 redraw_gui_only = TRUE;
6697 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006698#endif
6699
Bram Moolenaar071d4272004-06-13 20:20:40 +00006700#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6701 /* 'ttymouse' */
6702 else if (varp == &p_ttym)
6703 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006704 /* Switch the mouse off before changing the escape sequences used for
6705 * that. */
6706 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006707 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6708 errmsg = e_invarg;
6709 else
6710 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006711 if (termcap_active)
6712 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006713 }
6714#endif
6715
Bram Moolenaar071d4272004-06-13 20:20:40 +00006716 /* 'selection' */
6717 else if (varp == &p_sel)
6718 {
6719 if (*p_sel == NUL
6720 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6721 errmsg = e_invarg;
6722 }
6723
6724 /* 'selectmode' */
6725 else if (varp == &p_slm)
6726 {
6727 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6728 errmsg = e_invarg;
6729 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006730
6731#ifdef FEAT_BROWSE
6732 /* 'browsedir' */
6733 else if (varp == &p_bsdir)
6734 {
6735 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6736 && !mch_isdir(p_bsdir))
6737 errmsg = e_invarg;
6738 }
6739#endif
6740
Bram Moolenaar071d4272004-06-13 20:20:40 +00006741 /* 'keymodel' */
6742 else if (varp == &p_km)
6743 {
6744 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6745 errmsg = e_invarg;
6746 else
6747 {
6748 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6749 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6750 }
6751 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006752
6753 /* 'mousemodel' */
6754 else if (varp == &p_mousem)
6755 {
6756 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6757 errmsg = e_invarg;
6758#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6759 else if (*p_mousem != *oldval)
6760 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6761 * to create or delete the popup menus. */
6762 gui_motif_update_mousemodel(root_menu);
6763#endif
6764 }
6765
6766 /* 'switchbuf' */
6767 else if (varp == &p_swb)
6768 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006769 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006770 errmsg = e_invarg;
6771 }
6772
6773 /* 'debug' */
6774 else if (varp == &p_debug)
6775 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006776 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777 errmsg = e_invarg;
6778 }
6779
6780 /* 'display' */
6781 else if (varp == &p_dy)
6782 {
6783 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6784 errmsg = e_invarg;
6785 else
6786 (void)init_chartab();
6787
6788 }
6789
6790#ifdef FEAT_VERTSPLIT
6791 /* 'eadirection' */
6792 else if (varp == &p_ead)
6793 {
6794 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6795 errmsg = e_invarg;
6796 }
6797#endif
6798
6799#ifdef FEAT_CLIPBOARD
6800 /* 'clipboard' */
6801 else if (varp == &p_cb)
6802 errmsg = check_clipboard_option();
6803#endif
6804
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006805#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006806 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6807 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006808 else if (varp == &(curwin->w_s->b_p_spl)
6809 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006810 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006811 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006812 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006813 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006814 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006815 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006816 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006817 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006818 /* 'spellsuggest' */
6819 else if (varp == &p_sps)
6820 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006821 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006822 errmsg = e_invarg;
6823 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006824 /* 'mkspellmem' */
6825 else if (varp == &p_msm)
6826 {
6827 if (spell_check_msm() != OK)
6828 errmsg = e_invarg;
6829 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006830#endif
6831
Bram Moolenaar071d4272004-06-13 20:20:40 +00006832#ifdef FEAT_QUICKFIX
6833 /* When 'bufhidden' is set, check for valid value. */
6834 else if (gvarp == &p_bh)
6835 {
6836 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6837 errmsg = e_invarg;
6838 }
6839
6840 /* When 'buftype' is set, check for valid value. */
6841 else if (gvarp == &p_bt)
6842 {
6843 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6844 errmsg = e_invarg;
6845 else
6846 {
6847# ifdef FEAT_WINDOWS
6848 if (curwin->w_status_height)
6849 {
6850 curwin->w_redr_status = TRUE;
6851 redraw_later(VALID);
6852 }
6853# endif
6854 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006855# ifdef FEAT_TITLE
6856 redraw_titles();
6857# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006858 }
6859 }
6860#endif
6861
6862#ifdef FEAT_STL_OPT
6863 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006864 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006865 {
6866 int wid;
6867
6868 if (varp == &p_ruf) /* reset ru_wid first */
6869 ru_wid = 0;
6870 s = *varp;
6871 if (varp == &p_ruf && *s == '%')
6872 {
6873 /* set ru_wid if 'ruf' starts with "%99(" */
6874 if (*++s == '-') /* ignore a '-' */
6875 s++;
6876 wid = getdigits(&s);
6877 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6878 ru_wid = wid;
6879 else
6880 errmsg = check_stl_option(p_ruf);
6881 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006882 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006883 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006885 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006886 comp_col();
6887 }
6888#endif
6889
6890#ifdef FEAT_INS_EXPAND
6891 /* check if it is a valid value for 'complete' -- Acevedo */
6892 else if (gvarp == &p_cpt)
6893 {
6894 for (s = *varp; *s;)
6895 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006896 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006897 s++;
6898 if (!*s)
6899 break;
6900 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6901 {
6902 errmsg = illegal_char(errbuf, *s);
6903 break;
6904 }
6905 if (*++s != NUL && *s != ',' && *s != ' ')
6906 {
6907 if (s[-1] == 'k' || s[-1] == 's')
6908 {
6909 /* skip optional filename after 'k' and 's' */
6910 while (*s && *s != ',' && *s != ' ')
6911 {
6912 if (*s == '\\')
6913 ++s;
6914 ++s;
6915 }
6916 }
6917 else
6918 {
6919 if (errbuf != NULL)
6920 {
6921 sprintf((char *)errbuf,
6922 _("E535: Illegal character after <%c>"),
6923 *--s);
6924 errmsg = errbuf;
6925 }
6926 else
6927 errmsg = (char_u *)"";
6928 break;
6929 }
6930 }
6931 }
6932 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006933
6934 /* 'completeopt' */
6935 else if (varp == &p_cot)
6936 {
6937 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6938 errmsg = e_invarg;
6939 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006940#endif /* FEAT_INS_EXPAND */
6941
6942
6943#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6944 else if (varp == &p_toolbar)
6945 {
6946 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6947 &toolbar_flags, TRUE) != OK)
6948 errmsg = e_invarg;
6949 else
6950 {
6951 out_flush();
6952 gui_mch_show_toolbar((toolbar_flags &
6953 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6954 }
6955 }
6956#endif
6957
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006958#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006959 /* 'toolbariconsize': GTK+ 2 only */
6960 else if (varp == &p_tbis)
6961 {
6962 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6963 errmsg = e_invarg;
6964 else
6965 {
6966 out_flush();
6967 gui_mch_show_toolbar((toolbar_flags &
6968 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6969 }
6970 }
6971#endif
6972
6973 /* 'pastetoggle': translate key codes like in a mapping */
6974 else if (varp == &p_pt)
6975 {
6976 if (*p_pt)
6977 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006978 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 if (p != NULL)
6980 {
6981 if (new_value_alloced)
6982 free_string_option(p_pt);
6983 p_pt = p;
6984 new_value_alloced = TRUE;
6985 }
6986 }
6987 }
6988
6989 /* 'backspace' */
6990 else if (varp == &p_bs)
6991 {
6992 if (VIM_ISDIGIT(*p_bs))
6993 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01006994 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006995 errmsg = e_invarg;
6996 }
6997 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6998 errmsg = e_invarg;
6999 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007000 else if (varp == &p_bo)
7001 {
7002 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7003 errmsg = e_invarg;
7004 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007005
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007006 /* 'tagcase' */
7007 else if (gvarp == &p_tc)
7008 {
7009 unsigned int *flags;
7010
7011 if (opt_flags & OPT_LOCAL)
7012 {
7013 p = curbuf->b_p_tc;
7014 flags = &curbuf->b_tc_flags;
7015 }
7016 else
7017 {
7018 p = p_tc;
7019 flags = &tc_flags;
7020 }
7021
7022 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7023 /* make the local value empty: use the global value */
7024 *flags = 0;
7025 else if (*p == NUL
7026 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7027 errmsg = e_invarg;
7028 }
7029
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007030#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007031 /* 'casemap' */
7032 else if (varp == &p_cmp)
7033 {
7034 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7035 errmsg = e_invarg;
7036 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007037#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007038
7039#ifdef FEAT_DIFF
7040 /* 'diffopt' */
7041 else if (varp == &p_dip)
7042 {
7043 if (diffopt_changed() == FAIL)
7044 errmsg = e_invarg;
7045 }
7046#endif
7047
7048#ifdef FEAT_FOLDING
7049 /* 'foldmethod' */
7050 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7051 {
7052 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7053 || *curwin->w_p_fdm == NUL)
7054 errmsg = e_invarg;
7055 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007056 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007057 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007058 if (foldmethodIsDiff(curwin))
7059 newFoldLevel();
7060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007061 }
7062# ifdef FEAT_EVAL
7063 /* 'foldexpr' */
7064 else if (varp == &curwin->w_p_fde)
7065 {
7066 if (foldmethodIsExpr(curwin))
7067 foldUpdateAll(curwin);
7068 }
7069# endif
7070 /* 'foldmarker' */
7071 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7072 {
7073 p = vim_strchr(*varp, ',');
7074 if (p == NULL)
7075 errmsg = (char_u *)N_("E536: comma required");
7076 else if (p == *varp || p[1] == NUL)
7077 errmsg = e_invarg;
7078 else if (foldmethodIsMarker(curwin))
7079 foldUpdateAll(curwin);
7080 }
7081 /* 'commentstring' */
7082 else if (gvarp == &p_cms)
7083 {
7084 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7085 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7086 }
7087 /* 'foldopen' */
7088 else if (varp == &p_fdo)
7089 {
7090 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7091 errmsg = e_invarg;
7092 }
7093 /* 'foldclose' */
7094 else if (varp == &p_fcl)
7095 {
7096 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7097 errmsg = e_invarg;
7098 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007099 /* 'foldignore' */
7100 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7101 {
7102 if (foldmethodIsIndent(curwin))
7103 foldUpdateAll(curwin);
7104 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007105#endif
7106
7107#ifdef FEAT_VIRTUALEDIT
7108 /* 'virtualedit' */
7109 else if (varp == &p_ve)
7110 {
7111 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7112 errmsg = e_invarg;
7113 else if (STRCMP(p_ve, oldval) != 0)
7114 {
7115 /* Recompute cursor position in case the new 've' setting
7116 * changes something. */
7117 validate_virtcol();
7118 coladvance(curwin->w_virtcol);
7119 }
7120 }
7121#endif
7122
7123#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7124 else if (varp == &p_csqf)
7125 {
7126 if (p_csqf != NULL)
7127 {
7128 p = p_csqf;
7129 while (*p != NUL)
7130 {
7131 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7132 || p[1] == NUL
7133 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7134 || (p[2] != NUL && p[2] != ','))
7135 {
7136 errmsg = e_invarg;
7137 break;
7138 }
7139 else if (p[2] == NUL)
7140 break;
7141 else
7142 p += 3;
7143 }
7144 }
7145 }
7146#endif
7147
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007148#ifdef FEAT_CINDENT
7149 /* 'cinoptions' */
7150 else if (gvarp == &p_cino)
7151 {
7152 /* TODO: recognize errors */
7153 parse_cino(curbuf);
7154 }
7155#endif
7156
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007157#if defined(FEAT_RENDER_OPTIONS)
7158 else if (varp == &p_rop && gui.in_use)
7159 {
7160 if (!gui_mch_set_rendering_options(p_rop))
7161 errmsg = e_invarg;
7162 }
7163#endif
7164
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 /* Options that are a list of flags. */
7166 else
7167 {
7168 p = NULL;
7169 if (varp == &p_ww)
7170 p = (char_u *)WW_ALL;
7171 if (varp == &p_shm)
7172 p = (char_u *)SHM_ALL;
7173 else if (varp == &(p_cpo))
7174 p = (char_u *)CPO_ALL;
7175 else if (varp == &(curbuf->b_p_fo))
7176 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007177#ifdef FEAT_CONCEAL
7178 else if (varp == &curwin->w_p_cocu)
7179 p = (char_u *)COCU_ALL;
7180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 else if (varp == &p_mouse)
7182 {
7183#ifdef FEAT_MOUSE
7184 p = (char_u *)MOUSE_ALL;
7185#else
7186 if (*p_mouse != NUL)
7187 errmsg = (char_u *)N_("E538: No mouse support");
7188#endif
7189 }
7190#if defined(FEAT_GUI)
7191 else if (varp == &p_go)
7192 p = (char_u *)GO_ALL;
7193#endif
7194 if (p != NULL)
7195 {
7196 for (s = *varp; *s; ++s)
7197 if (vim_strchr(p, *s) == NULL)
7198 {
7199 errmsg = illegal_char(errbuf, *s);
7200 break;
7201 }
7202 }
7203 }
7204
7205 /*
7206 * If error detected, restore the previous value.
7207 */
7208 if (errmsg != NULL)
7209 {
7210 if (new_value_alloced)
7211 free_string_option(*varp);
7212 *varp = oldval;
7213 /*
7214 * When resetting some values, need to act on it.
7215 */
7216 if (did_chartab)
7217 (void)init_chartab();
7218 if (varp == &p_hl)
7219 (void)highlight_changed();
7220 }
7221 else
7222 {
7223#ifdef FEAT_EVAL
7224 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007225 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007226#endif
7227 /*
7228 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007229 * Use "free_oldval", because recursiveness may change the flags under
7230 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007231 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007232 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007233 free_string_option(oldval);
7234 if (new_value_alloced)
7235 options[opt_idx].flags |= P_ALLOCED;
7236 else
7237 options[opt_idx].flags &= ~P_ALLOCED;
7238
7239 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007240 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007241 {
7242 /* global option with local value set to use global value; free
7243 * the local value and make it empty */
7244 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7245 free_string_option(*(char_u **)p);
7246 *(char_u **)p = empty_option;
7247 }
7248
7249 /* May set global value for local option. */
7250 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7251 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007252
7253#ifdef FEAT_AUTOCMD
7254 /*
7255 * Trigger the autocommand only after setting the flags.
7256 */
7257# ifdef FEAT_SYN_HL
7258 /* When 'syntax' is set, load the syntax of that name */
7259 if (varp == &(curbuf->b_p_syn))
7260 {
7261 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7262 curbuf->b_fname, TRUE, curbuf);
7263 }
7264# endif
7265 else if (varp == &(curbuf->b_p_ft))
7266 {
7267 /* 'filetype' is set, trigger the FileType autocommand */
7268 did_filetype = TRUE;
7269 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7270 curbuf->b_fname, TRUE, curbuf);
7271 }
7272#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007273#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007274 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007275 {
7276 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007277 char_u *q = curwin->w_s->b_p_spl;
7278
7279 /* Skip the first name if it is "cjk". */
7280 if (STRNCMP(q, "cjk,", 4) == 0)
7281 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007282
7283 /*
7284 * Source the spell/LANG.vim in 'runtimepath'.
7285 * They could set 'spellcapcheck' depending on the language.
7286 * Use the first name in 'spelllang' up to '_region' or
7287 * '.encoding'.
7288 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007289 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007290 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7291 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007292 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007293 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007294 }
7295#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007296 }
7297
7298#ifdef FEAT_MOUSE
7299 if (varp == &p_mouse)
7300 {
7301# ifdef FEAT_MOUSE_TTY
7302 if (*p_mouse == NUL)
7303 mch_setmouse(FALSE); /* switch mouse off */
7304 else
7305# endif
7306 setmouse(); /* in case 'mouse' changed */
7307 }
7308#endif
7309
Bram Moolenaar913077c2012-03-28 19:59:04 +02007310 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007311 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007312 curwin->w_set_curswant = TRUE;
7313
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007314#ifdef FEAT_GUI
7315 /* check redraw when it's not a GUI option or the GUI is active. */
7316 if (!redraw_gui_only || gui.in_use)
7317#endif
7318 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007319
7320 return errmsg;
7321}
7322
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007323#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007324/*
7325 * Simple int comparison function for use with qsort()
7326 */
7327 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007328int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007329{
7330 return *(const int *)a - *(const int *)b;
7331}
7332
7333/*
7334 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7335 * Returns error message, NULL if it's OK.
7336 */
7337 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007338check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007339{
7340 char_u *s;
7341 int col;
7342 int count = 0;
7343 int color_cols[256];
7344 int i;
7345 int j = 0;
7346
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007347 if (wp->w_buffer == NULL)
7348 return NULL; /* buffer was closed */
7349
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007350 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007351 {
7352 if (*s == '-' || *s == '+')
7353 {
7354 /* -N and +N: add to 'textwidth' */
7355 col = (*s == '-') ? -1 : 1;
7356 ++s;
7357 if (!VIM_ISDIGIT(*s))
7358 return e_invarg;
7359 col = col * getdigits(&s);
7360 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007361 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007362 col += wp->w_buffer->b_p_tw;
7363 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007364 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007365 }
7366 else if (VIM_ISDIGIT(*s))
7367 col = getdigits(&s);
7368 else
7369 return e_invarg;
7370 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007371skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007372 if (*s == NUL)
7373 break;
7374 if (*s != ',')
7375 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007376 if (*++s == NUL)
7377 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007378 }
7379
7380 vim_free(wp->w_p_cc_cols);
7381 if (count == 0)
7382 wp->w_p_cc_cols = NULL;
7383 else
7384 {
7385 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7386 if (wp->w_p_cc_cols != NULL)
7387 {
7388 /* sort the columns for faster usage on screen redraw inside
7389 * win_line() */
7390 qsort(color_cols, count, sizeof(int), int_cmp);
7391
7392 for (i = 0; i < count; ++i)
7393 /* skip duplicates */
7394 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7395 wp->w_p_cc_cols[j++] = color_cols[i];
7396 wp->w_p_cc_cols[j] = -1; /* end marker */
7397 }
7398 }
7399
7400 return NULL; /* no error */
7401}
7402#endif
7403
Bram Moolenaar071d4272004-06-13 20:20:40 +00007404/*
7405 * Handle setting 'listchars' or 'fillchars'.
7406 * Returns error message, NULL if it's OK.
7407 */
7408 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007409set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007410{
7411 int round, i, len, entries;
7412 char_u *p, *s;
7413 int c1, c2 = 0;
7414 struct charstab
7415 {
7416 int *cp;
7417 char *name;
7418 };
7419#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7420 static struct charstab filltab[] =
7421 {
7422 {&fill_stl, "stl"},
7423 {&fill_stlnc, "stlnc"},
7424 {&fill_vert, "vert"},
7425 {&fill_fold, "fold"},
7426 {&fill_diff, "diff"},
7427 };
7428#endif
7429 static struct charstab lcstab[] =
7430 {
7431 {&lcs_eol, "eol"},
7432 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007433 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007434 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007435 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007436 {&lcs_tab2, "tab"},
7437 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007438#ifdef FEAT_CONCEAL
7439 {&lcs_conceal, "conceal"},
7440#else
7441 {NULL, "conceal"},
7442#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443 };
7444 struct charstab *tab;
7445
7446#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7447 if (varp == &p_lcs)
7448#endif
7449 {
7450 tab = lcstab;
7451 entries = sizeof(lcstab) / sizeof(struct charstab);
7452 }
7453#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7454 else
7455 {
7456 tab = filltab;
7457 entries = sizeof(filltab) / sizeof(struct charstab);
7458 }
7459#endif
7460
7461 /* first round: check for valid value, second round: assign values */
7462 for (round = 0; round <= 1; ++round)
7463 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007464 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007465 {
7466 /* After checking that the value is valid: set defaults: space for
7467 * 'fillchars', NUL for 'listchars' */
7468 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007469 if (tab[i].cp != NULL)
7470 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007471 if (varp == &p_lcs)
7472 lcs_tab1 = NUL;
7473#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7474 else
7475 fill_diff = '-';
7476#endif
7477 }
7478 p = *varp;
7479 while (*p)
7480 {
7481 for (i = 0; i < entries; ++i)
7482 {
7483 len = (int)STRLEN(tab[i].name);
7484 if (STRNCMP(p, tab[i].name, len) == 0
7485 && p[len] == ':'
7486 && p[len + 1] != NUL)
7487 {
7488 s = p + len + 1;
7489#ifdef FEAT_MBYTE
7490 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007491 if (mb_char2cells(c1) > 1)
7492 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007493#else
7494 c1 = *s++;
7495#endif
7496 if (tab[i].cp == &lcs_tab2)
7497 {
7498 if (*s == NUL)
7499 continue;
7500#ifdef FEAT_MBYTE
7501 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007502 if (mb_char2cells(c2) > 1)
7503 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504#else
7505 c2 = *s++;
7506#endif
7507 }
7508 if (*s == ',' || *s == NUL)
7509 {
7510 if (round)
7511 {
7512 if (tab[i].cp == &lcs_tab2)
7513 {
7514 lcs_tab1 = c1;
7515 lcs_tab2 = c2;
7516 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007517 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518 *(tab[i].cp) = c1;
7519
7520 }
7521 p = s;
7522 break;
7523 }
7524 }
7525 }
7526
7527 if (i == entries)
7528 return e_invarg;
7529 if (*p == ',')
7530 ++p;
7531 }
7532 }
7533
7534 return NULL; /* no error */
7535}
7536
7537#ifdef FEAT_STL_OPT
7538/*
7539 * Check validity of options with the 'statusline' format.
7540 * Return error message or NULL.
7541 */
7542 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007543check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007544{
7545 int itemcnt = 0;
7546 int groupdepth = 0;
7547 static char_u errbuf[80];
7548
7549 while (*s && itemcnt < STL_MAX_ITEM)
7550 {
7551 /* Check for valid keys after % sequences */
7552 while (*s && *s != '%')
7553 s++;
7554 if (!*s)
7555 break;
7556 s++;
7557 if (*s != '%' && *s != ')')
7558 ++itemcnt;
7559 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7560 {
7561 s++;
7562 continue;
7563 }
7564 if (*s == ')')
7565 {
7566 s++;
7567 if (--groupdepth < 0)
7568 break;
7569 continue;
7570 }
7571 if (*s == '-')
7572 s++;
7573 while (VIM_ISDIGIT(*s))
7574 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007575 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007576 continue;
7577 if (*s == '.')
7578 {
7579 s++;
7580 while (*s && VIM_ISDIGIT(*s))
7581 s++;
7582 }
7583 if (*s == '(')
7584 {
7585 groupdepth++;
7586 continue;
7587 }
7588 if (vim_strchr(STL_ALL, *s) == NULL)
7589 {
7590 return illegal_char(errbuf, *s);
7591 }
7592 if (*s == '{')
7593 {
7594 s++;
7595 while (*s != '}' && *s)
7596 s++;
7597 if (*s != '}')
7598 return (char_u *)N_("E540: Unclosed expression sequence");
7599 }
7600 }
7601 if (itemcnt >= STL_MAX_ITEM)
7602 return (char_u *)N_("E541: too many items");
7603 if (groupdepth != 0)
7604 return (char_u *)N_("E542: unbalanced groups");
7605 return NULL;
7606}
7607#endif
7608
7609#ifdef FEAT_CLIPBOARD
7610/*
7611 * Extract the items in the 'clipboard' option and set global values.
7612 */
7613 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007614check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007615{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007616 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007617 int new_autoselect_star = FALSE;
7618 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007619 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007620 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621 regprog_T *new_exclude_prog = NULL;
7622 char_u *errmsg = NULL;
7623 char_u *p;
7624
7625 for (p = p_cb; *p != NUL; )
7626 {
7627 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7628 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007629 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007630 p += 7;
7631 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007632 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007633 && (p[11] == ',' || p[11] == NUL))
7634 {
7635 new_unnamed |= CLIP_UNNAMED_PLUS;
7636 p += 11;
7637 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007638 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007639 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007640 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007641 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007642 p += 10;
7643 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007644 else if (STRNCMP(p, "autoselectplus", 14) == 0
7645 && (p[14] == ',' || p[14] == NUL))
7646 {
7647 new_autoselect_plus = TRUE;
7648 p += 14;
7649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007651 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007652 {
7653 new_autoselectml = TRUE;
7654 p += 12;
7655 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007656 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7657 {
7658 new_html = TRUE;
7659 p += 4;
7660 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7662 {
7663 p += 8;
7664 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7665 if (new_exclude_prog == NULL)
7666 errmsg = e_invarg;
7667 break;
7668 }
7669 else
7670 {
7671 errmsg = e_invarg;
7672 break;
7673 }
7674 if (*p == ',')
7675 ++p;
7676 }
7677 if (errmsg == NULL)
7678 {
7679 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007680 clip_autoselect_star = new_autoselect_star;
7681 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007683 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007684 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007685 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007686#ifdef FEAT_GUI_GTK
7687 if (gui.in_use)
7688 {
7689 gui_gtk_set_selection_targets();
7690 gui_gtk_set_dnd_targets();
7691 }
7692#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007693 }
7694 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007695 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007696
7697 return errmsg;
7698}
7699#endif
7700
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007701#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007702 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007703did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007704{
7705 char_u *errmsg = NULL;
7706 win_T *wp;
7707 int l;
7708
7709 if (is_spellfile)
7710 {
7711 l = (int)STRLEN(curwin->w_s->b_p_spf);
7712 if (l > 0 && (l < 4
7713 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7714 errmsg = e_invarg;
7715 }
7716
7717 if (errmsg == NULL)
7718 {
7719 FOR_ALL_WINDOWS(wp)
7720 if (wp->w_buffer == curbuf && wp->w_p_spell)
7721 {
7722 errmsg = did_set_spelllang(wp);
7723# ifdef FEAT_WINDOWS
7724 break;
7725# endif
7726 }
7727 }
7728 return errmsg;
7729}
7730
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007731/*
7732 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7733 * Return error message when failed, NULL when OK.
7734 */
7735 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007736compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007737{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007738 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007739 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007740
Bram Moolenaar860cae12010-06-05 23:22:07 +02007741 if (*synblock->b_p_spc == NUL)
7742 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007743 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007744 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007745 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007746 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007747 if (re != NULL)
7748 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007749 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007750 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007751 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007752 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007753 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007754 return e_invarg;
7755 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007756 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007757 }
7758
Bram Moolenaar473de612013-06-08 18:19:48 +02007759 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007760 return NULL;
7761}
7762#endif
7763
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007764#if defined(FEAT_EVAL) || defined(PROTO)
7765/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007766 * Set the scriptID for an option, taking care of setting the buffer- or
7767 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007768 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007769 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007770set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007771{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007772 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7773 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007774
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007775 /* Remember where the option was set. For local options need to do that
7776 * in the buffer or window structure. */
7777 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007778 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007779 if (both || (opt_flags & OPT_LOCAL))
7780 {
7781 if (indir & PV_BUF)
7782 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7783 else if (indir & PV_WIN)
7784 curwin->w_p_scriptID[indir & PV_MASK] = id;
7785 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007786}
7787#endif
7788
Bram Moolenaar071d4272004-06-13 20:20:40 +00007789/*
7790 * Set the value of a boolean option, and take care of side effects.
7791 * Returns NULL for success, or an error message for an error.
7792 */
7793 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007794set_bool_option(
7795 int opt_idx, /* index in options[] table */
7796 char_u *varp, /* pointer to the option variable */
7797 int value, /* new value */
7798 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799{
7800 int old_value = *(int *)varp;
7801
Bram Moolenaar071d4272004-06-13 20:20:40 +00007802 /* Disallow changing some options from secure mode */
7803 if ((secure
7804#ifdef HAVE_SANDBOX
7805 || sandbox != 0
7806#endif
7807 ) && (options[opt_idx].flags & P_SECURE))
7808 return e_secure;
7809
7810 *(int *)varp = value; /* set the new value */
7811#ifdef FEAT_EVAL
7812 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007813 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007814#endif
7815
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007816#ifdef FEAT_GUI
7817 need_mouse_correct = TRUE;
7818#endif
7819
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820 /* May set global value for local option. */
7821 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7822 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7823
7824 /*
7825 * Handle side effects of changing a bool option.
7826 */
7827
7828 /* 'compatible' */
7829 if ((int *)varp == &p_cp)
7830 {
7831 compatible_set();
7832 }
7833
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007834#ifdef FEAT_PERSISTENT_UNDO
7835 /* 'undofile' */
7836 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7837 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007838 /* Only take action when the option was set. When reset we do not
7839 * delete the undo file, the option may be set again without making
7840 * any changes in between. */
7841 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007842 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007843 char_u hash[UNDO_HASH_SIZE];
7844 buf_T *save_curbuf = curbuf;
7845
7846 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007847 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007848 /* When 'undofile' is set globally: for every buffer, otherwise
7849 * only for the current buffer: Try to read in the undofile,
7850 * if one exists, the buffer wasn't changed and the buffer was
7851 * loaded */
7852 if ((curbuf == save_curbuf
7853 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7854 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7855 {
7856 u_compute_hash(hash);
7857 u_read_undo(NULL, hash, curbuf->b_fname);
7858 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007859 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007860 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007861 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007862 }
7863#endif
7864
Bram Moolenaar071d4272004-06-13 20:20:40 +00007865 else if ((int *)varp == &curbuf->b_p_ro)
7866 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007867 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7869 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007870
7871 /* when 'readonly' is set may give W10 again */
7872 if (curbuf->b_p_ro)
7873 curbuf->b_did_warn = FALSE;
7874
Bram Moolenaar071d4272004-06-13 20:20:40 +00007875#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007876 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877#endif
7878 }
7879
Bram Moolenaar9c449722010-07-20 18:44:27 +02007880#ifdef FEAT_GUI
7881 else if ((int *)varp == &p_mh)
7882 {
7883 if (!p_mh)
7884 gui_mch_mousehide(FALSE);
7885 }
7886#endif
7887
Bram Moolenaara539df02010-08-01 14:35:05 +02007888#ifdef FEAT_TITLE
7889 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007891 {
7892 redraw_titles();
7893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 /* when 'endofline' is changed, redraw the window title */
7895 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007896 {
7897 redraw_titles();
7898 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007899 /* when 'fixeol' is changed, redraw the window title */
7900 else if ((int *)varp == &curbuf->b_p_fixeol)
7901 {
7902 redraw_titles();
7903 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007904# ifdef FEAT_MBYTE
7905 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007906 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007907 {
7908 redraw_titles();
7909 }
7910# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911#endif
7912
7913 /* when 'bin' is set also set some other options */
7914 else if ((int *)varp == &curbuf->b_p_bin)
7915 {
7916 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7917#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007918 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919#endif
7920 }
7921
7922#ifdef FEAT_AUTOCMD
7923 /* when 'buflisted' changes, trigger autocommands */
7924 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7925 {
7926 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7927 NULL, NULL, TRUE, curbuf);
7928 }
7929#endif
7930
7931 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7932 else if ((int *)varp == &curbuf->b_p_swf)
7933 {
7934 if (curbuf->b_p_swf && p_uc)
7935 ml_open_file(curbuf); /* create the swap file */
7936 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007937 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7938 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 mf_close_file(curbuf, TRUE); /* remove the swap file */
7940 }
7941
7942 /* when 'terse' is set change 'shortmess' */
7943 else if ((int *)varp == &p_terse)
7944 {
7945 char_u *p;
7946
7947 p = vim_strchr(p_shm, SHM_SEARCH);
7948
7949 /* insert 's' in p_shm */
7950 if (p_terse && p == NULL)
7951 {
7952 STRCPY(IObuff, p_shm);
7953 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007954 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007955 }
7956 /* remove 's' from p_shm */
7957 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007958 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959 }
7960
7961 /* when 'paste' is set or reset also change other options */
7962 else if ((int *)varp == &p_paste)
7963 {
7964 paste_option_changed();
7965 }
7966
7967 /* when 'insertmode' is set from an autocommand need to do work here */
7968 else if ((int *)varp == &p_im)
7969 {
7970 if (p_im)
7971 {
7972 if ((State & INSERT) == 0)
7973 need_start_insertmode = TRUE;
7974 stop_insert_mode = FALSE;
7975 }
7976 else
7977 {
7978 need_start_insertmode = FALSE;
7979 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007980 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981 clear_cmdline = TRUE; /* remove "(insert)" */
7982 restart_edit = 0;
7983 }
7984 }
7985
7986 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7987 else if ((int *)varp == &p_ic && p_hls)
7988 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007989 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990 }
7991
7992#ifdef FEAT_SEARCH_EXTRA
7993 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7994 else if ((int *)varp == &p_hls)
7995 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007996 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007997 }
7998#endif
7999
8000#ifdef FEAT_SCROLLBIND
8001 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8002 * at the end of normal_cmd() */
8003 else if ((int *)varp == &curwin->w_p_scb)
8004 {
8005 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008006 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008008 curwin->w_scbind_pos = curwin->w_topline;
8009 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 }
8011#endif
8012
8013#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8014 /* There can be only one window with 'previewwindow' set. */
8015 else if ((int *)varp == &curwin->w_p_pvw)
8016 {
8017 if (curwin->w_p_pvw)
8018 {
8019 win_T *win;
8020
8021 for (win = firstwin; win != NULL; win = win->w_next)
8022 if (win->w_p_pvw && win != curwin)
8023 {
8024 curwin->w_p_pvw = FALSE;
8025 return (char_u *)N_("E590: A preview window already exists");
8026 }
8027 }
8028 }
8029#endif
8030
8031 /* when 'textmode' is set or reset also change 'fileformat' */
8032 else if ((int *)varp == &curbuf->b_p_tx)
8033 {
8034 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8035 }
8036
8037 /* when 'textauto' is set or reset also change 'fileformats' */
8038 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008039 set_string_option_direct((char_u *)"ffs", -1,
8040 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008041 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042
8043 /*
8044 * When 'lisp' option changes include/exclude '-' in
8045 * keyword characters.
8046 */
8047#ifdef FEAT_LISP
8048 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8049 {
8050 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8051 }
8052#endif
8053
8054#ifdef FEAT_TITLE
8055 /* when 'title' changed, may need to change the title; same for 'icon' */
8056 else if ((int *)varp == &p_title)
8057 {
8058 did_set_title(FALSE);
8059 }
8060
8061 else if ((int *)varp == &p_icon)
8062 {
8063 did_set_title(TRUE);
8064 }
8065#endif
8066
8067 else if ((int *)varp == &curbuf->b_changed)
8068 {
8069 if (!value)
8070 save_file_ff(curbuf); /* Buffer is unchanged */
8071#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008072 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008073#endif
8074#ifdef FEAT_AUTOCMD
8075 modified_was_set = value;
8076#endif
8077 }
8078
8079#ifdef BACKSLASH_IN_FILENAME
8080 else if ((int *)varp == &p_ssl)
8081 {
8082 if (p_ssl)
8083 {
8084 psepc = '/';
8085 psepcN = '\\';
8086 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087 }
8088 else
8089 {
8090 psepc = '\\';
8091 psepcN = '/';
8092 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 }
8094
8095 /* need to adjust the file name arguments and buffer names. */
8096 buflist_slash_adjust();
8097 alist_slash_adjust();
8098# ifdef FEAT_EVAL
8099 scriptnames_slash_adjust();
8100# endif
8101 }
8102#endif
8103
8104 /* If 'wrap' is set, set w_leftcol to zero. */
8105 else if ((int *)varp == &curwin->w_p_wrap)
8106 {
8107 if (curwin->w_p_wrap)
8108 curwin->w_leftcol = 0;
8109 }
8110
8111#ifdef FEAT_WINDOWS
8112 else if ((int *)varp == &p_ea)
8113 {
8114 if (p_ea && !old_value)
8115 win_equal(curwin, FALSE, 0);
8116 }
8117#endif
8118
8119 else if ((int *)varp == &p_wiv)
8120 {
8121 /*
8122 * When 'weirdinvert' changed, set/reset 't_xs'.
8123 * Then set 'weirdinvert' according to value of 't_xs'.
8124 */
8125 if (p_wiv && !old_value)
8126 T_XS = (char_u *)"y";
8127 else if (!p_wiv && old_value)
8128 T_XS = empty_option;
8129 p_wiv = (*T_XS != NUL);
8130 }
8131
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008132#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008133 else if ((int *)varp == &p_beval)
8134 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008135 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008137 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008138 gui_mch_disable_beval_area(balloonEval);
8139 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008140#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008142#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 else if ((int *)varp == &p_acd)
8144 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008145 /* Change directories when the 'acd' option is set now. */
8146 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 }
8148#endif
8149
8150#ifdef FEAT_DIFF
8151 /* 'diff' */
8152 else if ((int *)varp == &curwin->w_p_diff)
8153 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008154 /* May add or remove the buffer from the list of diff buffers. */
8155 diff_buf_adjust(curwin);
8156# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 if (foldmethodIsDiff(curwin))
8158 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008159# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 }
8161#endif
8162
8163#ifdef USE_IM_CONTROL
8164 /* 'imdisable' */
8165 else if ((int *)varp == &p_imdisable)
8166 {
8167 /* Only de-activate it here, it will be enabled when changing mode. */
8168 if (p_imdisable)
8169 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008170 else if (State & INSERT)
8171 /* When the option is set from an autocommand, it may need to take
8172 * effect right away. */
8173 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008174 }
8175#endif
8176
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008177#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008178 /* 'spell' */
8179 else if ((int *)varp == &curwin->w_p_spell)
8180 {
8181 if (curwin->w_p_spell)
8182 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008183 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008184 if (errmsg != NULL)
8185 EMSG(_(errmsg));
8186 }
8187 }
8188#endif
8189
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190#ifdef FEAT_FKMAP
8191 else if ((int *)varp == &p_altkeymap)
8192 {
8193 if (old_value != p_altkeymap)
8194 {
8195 if (!p_altkeymap)
8196 {
8197 p_hkmap = p_fkmap;
8198 p_fkmap = 0;
8199 }
8200 else
8201 {
8202 p_fkmap = p_hkmap;
8203 p_hkmap = 0;
8204 }
8205 (void)init_chartab();
8206 }
8207 }
8208
8209 /*
8210 * In case some second language keymapping options have changed, check
8211 * and correct the setting in a consistent way.
8212 */
8213
8214 /*
8215 * If hkmap or fkmap are set, reset Arabic keymapping.
8216 */
8217 if ((p_hkmap || p_fkmap) && p_altkeymap)
8218 {
8219 p_altkeymap = p_fkmap;
8220# ifdef FEAT_ARABIC
8221 curwin->w_p_arab = FALSE;
8222# endif
8223 (void)init_chartab();
8224 }
8225
8226 /*
8227 * If hkmap set, reset Farsi keymapping.
8228 */
8229 if (p_hkmap && p_altkeymap)
8230 {
8231 p_altkeymap = 0;
8232 p_fkmap = 0;
8233# ifdef FEAT_ARABIC
8234 curwin->w_p_arab = FALSE;
8235# endif
8236 (void)init_chartab();
8237 }
8238
8239 /*
8240 * If fkmap set, reset Hebrew keymapping.
8241 */
8242 if (p_fkmap && !p_altkeymap)
8243 {
8244 p_altkeymap = 1;
8245 p_hkmap = 0;
8246# ifdef FEAT_ARABIC
8247 curwin->w_p_arab = FALSE;
8248# endif
8249 (void)init_chartab();
8250 }
8251#endif
8252
8253#ifdef FEAT_ARABIC
8254 if ((int *)varp == &curwin->w_p_arab)
8255 {
8256 if (curwin->w_p_arab)
8257 {
8258 /*
8259 * 'arabic' is set, handle various sub-settings.
8260 */
8261 if (!p_tbidi)
8262 {
8263 /* set rightleft mode */
8264 if (!curwin->w_p_rl)
8265 {
8266 curwin->w_p_rl = TRUE;
8267 changed_window_setting();
8268 }
8269
8270 /* Enable Arabic shaping (major part of what Arabic requires) */
8271 if (!p_arshape)
8272 {
8273 p_arshape = TRUE;
8274 redraw_later_clear();
8275 }
8276 }
8277
8278 /* Arabic requires a utf-8 encoding, inform the user if its not
8279 * set. */
8280 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008281 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008282 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8283
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008284 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008285 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8286#ifdef FEAT_EVAL
8287 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8288#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008289 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290
8291# ifdef FEAT_MBYTE
8292 /* set 'delcombine' */
8293 p_deco = TRUE;
8294# endif
8295
8296# ifdef FEAT_KEYMAP
8297 /* Force-set the necessary keymap for arabic */
8298 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8299 OPT_LOCAL);
8300# endif
8301# ifdef FEAT_FKMAP
8302 p_altkeymap = 0;
8303 p_hkmap = 0;
8304 p_fkmap = 0;
8305 (void)init_chartab();
8306# endif
8307 }
8308 else
8309 {
8310 /*
8311 * 'arabic' is reset, handle various sub-settings.
8312 */
8313 if (!p_tbidi)
8314 {
8315 /* reset rightleft mode */
8316 if (curwin->w_p_rl)
8317 {
8318 curwin->w_p_rl = FALSE;
8319 changed_window_setting();
8320 }
8321
8322 /* 'arabicshape' isn't reset, it is a global option and
8323 * another window may still need it "on". */
8324 }
8325
8326 /* 'delcombine' isn't reset, it is a global option and another
8327 * window may still want it "on". */
8328
8329# ifdef FEAT_KEYMAP
8330 /* Revert to the default keymap */
8331 curbuf->b_p_iminsert = B_IMODE_NONE;
8332 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8333# endif
8334 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008335 }
8336
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008337#endif
8338
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339 /*
8340 * End of handling side effects for bool options.
8341 */
8342
Bram Moolenaar53744302015-07-17 17:38:22 +02008343 /* after handling side effects, call autocommand */
8344
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 options[opt_idx].flags |= P_WAS_SET;
8346
Bram Moolenaar53744302015-07-17 17:38:22 +02008347#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8348 if (!starting)
8349 {
8350 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008351 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8352 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8353 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008354 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8355 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8356 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8357 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8358 reset_v_option_vars();
8359 }
8360#endif
8361
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008363 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008364 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008365 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008366 check_redraw(options[opt_idx].flags);
8367
8368 return NULL;
8369}
8370
8371/*
8372 * Set the value of a number option, and take care of side effects.
8373 * Returns NULL for success, or an error message for an error.
8374 */
8375 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008376set_num_option(
8377 int opt_idx, /* index in options[] table */
8378 char_u *varp, /* pointer to the option variable */
8379 long value, /* new value */
8380 char_u *errbuf, /* buffer for error messages */
8381 size_t errbuflen, /* length of "errbuf" */
8382 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 OPT_MODELINE */
8384{
8385 char_u *errmsg = NULL;
8386 long old_value = *(long *)varp;
8387 long old_Rows = Rows; /* remember old Rows */
8388 long old_Columns = Columns; /* remember old Columns */
8389 long *pp = (long *)varp;
8390
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008391 /* Disallow changing some options from secure mode. */
8392 if ((secure
8393#ifdef HAVE_SANDBOX
8394 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008395#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008396 ) && (options[opt_idx].flags & P_SECURE))
8397 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008398
8399 *pp = value;
8400#ifdef FEAT_EVAL
8401 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008402 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008404#ifdef FEAT_GUI
8405 need_mouse_correct = TRUE;
8406#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407
Bram Moolenaar14f24742012-08-08 18:01:05 +02008408 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409 {
8410 errmsg = e_positive;
8411 curbuf->b_p_sw = curbuf->b_p_ts;
8412 }
8413
8414 /*
8415 * Number options that need some action when changed
8416 */
8417#ifdef FEAT_WINDOWS
8418 if (pp == &p_wh || pp == &p_hh)
8419 {
8420 if (p_wh < 1)
8421 {
8422 errmsg = e_positive;
8423 p_wh = 1;
8424 }
8425 if (p_wmh > p_wh)
8426 {
8427 errmsg = e_winheight;
8428 p_wh = p_wmh;
8429 }
8430 if (p_hh < 0)
8431 {
8432 errmsg = e_positive;
8433 p_hh = 0;
8434 }
8435
8436 /* Change window height NOW */
8437 if (lastwin != firstwin)
8438 {
8439 if (pp == &p_wh && curwin->w_height < p_wh)
8440 win_setheight((int)p_wh);
8441 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8442 win_setheight((int)p_hh);
8443 }
8444 }
8445
8446 /* 'winminheight' */
8447 else if (pp == &p_wmh)
8448 {
8449 if (p_wmh < 0)
8450 {
8451 errmsg = e_positive;
8452 p_wmh = 0;
8453 }
8454 if (p_wmh > p_wh)
8455 {
8456 errmsg = e_winheight;
8457 p_wmh = p_wh;
8458 }
8459 win_setminheight();
8460 }
8461
8462# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008463 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 {
8465 if (p_wiw < 1)
8466 {
8467 errmsg = e_positive;
8468 p_wiw = 1;
8469 }
8470 if (p_wmw > p_wiw)
8471 {
8472 errmsg = e_winwidth;
8473 p_wiw = p_wmw;
8474 }
8475
8476 /* Change window width NOW */
8477 if (lastwin != firstwin && curwin->w_width < p_wiw)
8478 win_setwidth((int)p_wiw);
8479 }
8480
8481 /* 'winminwidth' */
8482 else if (pp == &p_wmw)
8483 {
8484 if (p_wmw < 0)
8485 {
8486 errmsg = e_positive;
8487 p_wmw = 0;
8488 }
8489 if (p_wmw > p_wiw)
8490 {
8491 errmsg = e_winwidth;
8492 p_wmw = p_wiw;
8493 }
8494 win_setminheight();
8495 }
8496# endif
8497
8498#endif
8499
8500#ifdef FEAT_WINDOWS
8501 /* (re)set last window status line */
8502 else if (pp == &p_ls)
8503 {
8504 last_status(FALSE);
8505 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008506
8507 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008508 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008509 {
8510 shell_new_rows(); /* recompute window positions and heights */
8511 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512#endif
8513
8514#ifdef FEAT_GUI
8515 else if (pp == &p_linespace)
8516 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008517 /* Recompute gui.char_height and resize the Vim window to keep the
8518 * same number of lines. */
8519 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008520 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 }
8522#endif
8523
8524#ifdef FEAT_FOLDING
8525 /* 'foldlevel' */
8526 else if (pp == &curwin->w_p_fdl)
8527 {
8528 if (curwin->w_p_fdl < 0)
8529 curwin->w_p_fdl = 0;
8530 newFoldLevel();
8531 }
8532
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008533 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008534 else if (pp == &curwin->w_p_fml)
8535 {
8536 foldUpdateAll(curwin);
8537 }
8538
8539 /* 'foldnestmax' */
8540 else if (pp == &curwin->w_p_fdn)
8541 {
8542 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8543 foldUpdateAll(curwin);
8544 }
8545
8546 /* 'foldcolumn' */
8547 else if (pp == &curwin->w_p_fdc)
8548 {
8549 if (curwin->w_p_fdc < 0)
8550 {
8551 errmsg = e_positive;
8552 curwin->w_p_fdc = 0;
8553 }
8554 else if (curwin->w_p_fdc > 12)
8555 {
8556 errmsg = e_invarg;
8557 curwin->w_p_fdc = 12;
8558 }
8559 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008560#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008562#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563 /* 'shiftwidth' or 'tabstop' */
8564 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8565 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008566# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567 if (foldmethodIsIndent(curwin))
8568 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008569# endif
8570# ifdef FEAT_CINDENT
8571 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8572 * parse 'cinoptions'. */
8573 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8574 parse_cino(curbuf);
8575# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008578
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008579#ifdef FEAT_MBYTE
8580 /* 'maxcombine' */
8581 else if (pp == &p_mco)
8582 {
8583 if (p_mco > MAX_MCO)
8584 p_mco = MAX_MCO;
8585 else if (p_mco < 0)
8586 p_mco = 0;
8587 screenclear(); /* will re-allocate the screen */
8588 }
8589#endif
8590
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 else if (pp == &curbuf->b_p_iminsert)
8592 {
8593 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8594 {
8595 errmsg = e_invarg;
8596 curbuf->b_p_iminsert = B_IMODE_NONE;
8597 }
8598 p_iminsert = curbuf->b_p_iminsert;
8599 if (termcap_active) /* don't do this in the alternate screen */
8600 showmode();
8601#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8602 /* Show/unshow value of 'keymap' in status lines. */
8603 status_redraw_curbuf();
8604#endif
8605 }
8606
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008607 else if (pp == &p_window)
8608 {
8609 if (p_window < 1)
8610 p_window = 1;
8611 else if (p_window >= Rows)
8612 p_window = Rows - 1;
8613 }
8614
Bram Moolenaar071d4272004-06-13 20:20:40 +00008615 else if (pp == &curbuf->b_p_imsearch)
8616 {
8617 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8618 {
8619 errmsg = e_invarg;
8620 curbuf->b_p_imsearch = B_IMODE_NONE;
8621 }
8622 p_imsearch = curbuf->b_p_imsearch;
8623 }
8624
8625#ifdef FEAT_TITLE
8626 /* if 'titlelen' has changed, redraw the title */
8627 else if (pp == &p_titlelen)
8628 {
8629 if (p_titlelen < 0)
8630 {
8631 errmsg = e_positive;
8632 p_titlelen = 85;
8633 }
8634 if (starting != NO_SCREEN && old_value != p_titlelen)
8635 need_maketitle = TRUE;
8636 }
8637#endif
8638
8639 /* if p_ch changed value, change the command line height */
8640 else if (pp == &p_ch)
8641 {
8642 if (p_ch < 1)
8643 {
8644 errmsg = e_positive;
8645 p_ch = 1;
8646 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008647 if (p_ch > Rows - min_rows() + 1)
8648 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008649
8650 /* Only compute the new window layout when startup has been
8651 * completed. Otherwise the frame sizes may be wrong. */
8652 if (p_ch != old_value && full_screen
8653#ifdef FEAT_GUI
8654 && !gui.starting
8655#endif
8656 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008657 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008658 }
8659
8660 /* when 'updatecount' changes from zero to non-zero, open swap files */
8661 else if (pp == &p_uc)
8662 {
8663 if (p_uc < 0)
8664 {
8665 errmsg = e_positive;
8666 p_uc = 100;
8667 }
8668 if (p_uc && !old_value)
8669 ml_open_files();
8670 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008671#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008672 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008673 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008674 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008675 {
8676 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008677 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008678 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008679 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008680 {
8681 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008682 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008683 }
8684 }
8685#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008686#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008687 else if (pp == &p_mzq)
8688 mzvim_reset_timer();
8689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008690
8691 /* sync undo before 'undolevels' changes */
8692 else if (pp == &p_ul)
8693 {
8694 /* use the old value, otherwise u_sync() may not work properly */
8695 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008696 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697 p_ul = value;
8698 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008699 else if (pp == &curbuf->b_p_ul)
8700 {
8701 /* use the old value, otherwise u_sync() may not work properly */
8702 curbuf->b_p_ul = old_value;
8703 u_sync(TRUE);
8704 curbuf->b_p_ul = value;
8705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008707#ifdef FEAT_LINEBREAK
8708 /* 'numberwidth' must be positive */
8709 else if (pp == &curwin->w_p_nuw)
8710 {
8711 if (curwin->w_p_nuw < 1)
8712 {
8713 errmsg = e_positive;
8714 curwin->w_p_nuw = 1;
8715 }
8716 if (curwin->w_p_nuw > 10)
8717 {
8718 errmsg = e_invarg;
8719 curwin->w_p_nuw = 10;
8720 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008721 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008722 }
8723#endif
8724
Bram Moolenaar1a384422010-07-14 19:53:30 +02008725 else if (pp == &curbuf->b_p_tw)
8726 {
8727 if (curbuf->b_p_tw < 0)
8728 {
8729 errmsg = e_positive;
8730 curbuf->b_p_tw = 0;
8731 }
8732#ifdef FEAT_SYN_HL
8733# ifdef FEAT_WINDOWS
8734 {
8735 win_T *wp;
8736 tabpage_T *tp;
8737
8738 FOR_ALL_TAB_WINDOWS(tp, wp)
8739 check_colorcolumn(wp);
8740 }
8741# else
8742 check_colorcolumn(curwin);
8743# endif
8744#endif
8745 }
8746
Bram Moolenaar071d4272004-06-13 20:20:40 +00008747 /*
8748 * Check the bounds for numeric options here
8749 */
8750 if (Rows < min_rows() && full_screen)
8751 {
8752 if (errbuf != NULL)
8753 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008754 vim_snprintf((char *)errbuf, errbuflen,
8755 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008756 errmsg = errbuf;
8757 }
8758 Rows = min_rows();
8759 }
8760 if (Columns < MIN_COLUMNS && full_screen)
8761 {
8762 if (errbuf != NULL)
8763 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008764 vim_snprintf((char *)errbuf, errbuflen,
8765 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008766 errmsg = errbuf;
8767 }
8768 Columns = MIN_COLUMNS;
8769 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008770 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 /*
8773 * If the screen (shell) height has been changed, assume it is the
8774 * physical screenheight.
8775 */
8776 if (old_Rows != Rows || old_Columns != Columns)
8777 {
8778 /* Changing the screen size is not allowed while updating the screen. */
8779 if (updating_screen)
8780 *pp = old_value;
8781 else if (full_screen
8782#ifdef FEAT_GUI
8783 && !gui.starting
8784#endif
8785 )
8786 set_shellsize((int)Columns, (int)Rows, TRUE);
8787 else
8788 {
8789 /* Postpone the resizing; check the size and cmdline position for
8790 * messages. */
8791 check_shellsize();
8792 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8793 cmdline_row = Rows - p_ch;
8794 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008795 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008796 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797 }
8798
Bram Moolenaar071d4272004-06-13 20:20:40 +00008799 if (curbuf->b_p_ts <= 0)
8800 {
8801 errmsg = e_positive;
8802 curbuf->b_p_ts = 8;
8803 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 if (p_tm < 0)
8805 {
8806 errmsg = e_positive;
8807 p_tm = 0;
8808 }
8809 if ((curwin->w_p_scr <= 0
8810 || (curwin->w_p_scr > curwin->w_height
8811 && curwin->w_height > 0))
8812 && full_screen)
8813 {
8814 if (pp == &(curwin->w_p_scr))
8815 {
8816 if (curwin->w_p_scr != 0)
8817 errmsg = e_scroll;
8818 win_comp_scroll(curwin);
8819 }
8820 /* If 'scroll' became invalid because of a side effect silently adjust
8821 * it. */
8822 else if (curwin->w_p_scr <= 0)
8823 curwin->w_p_scr = 1;
8824 else /* curwin->w_p_scr > curwin->w_height */
8825 curwin->w_p_scr = curwin->w_height;
8826 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008827 if (p_hi < 0)
8828 {
8829 errmsg = e_positive;
8830 p_hi = 0;
8831 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008832 else if (p_hi > 10000)
8833 {
8834 errmsg = e_invarg;
8835 p_hi = 10000;
8836 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008837 if (p_re < 0 || p_re > 2)
8838 {
8839 errmsg = e_invarg;
8840 p_re = 0;
8841 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008842 if (p_report < 0)
8843 {
8844 errmsg = e_positive;
8845 p_report = 1;
8846 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008847 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848 {
8849 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8850 p_sj = Rows / 2;
8851 else
8852 {
8853 errmsg = e_scroll;
8854 p_sj = 1;
8855 }
8856 }
8857 if (p_so < 0 && full_screen)
8858 {
8859 errmsg = e_scroll;
8860 p_so = 0;
8861 }
8862 if (p_siso < 0 && full_screen)
8863 {
8864 errmsg = e_positive;
8865 p_siso = 0;
8866 }
8867#ifdef FEAT_CMDWIN
8868 if (p_cwh < 1)
8869 {
8870 errmsg = e_positive;
8871 p_cwh = 1;
8872 }
8873#endif
8874 if (p_ut < 0)
8875 {
8876 errmsg = e_positive;
8877 p_ut = 2000;
8878 }
8879 if (p_ss < 0)
8880 {
8881 errmsg = e_positive;
8882 p_ss = 0;
8883 }
8884
8885 /* May set global value for local option. */
8886 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8887 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8888
8889 options[opt_idx].flags |= P_WAS_SET;
8890
Bram Moolenaar53744302015-07-17 17:38:22 +02008891#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8892 if (!starting && errmsg == NULL)
8893 {
8894 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008895 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8896 vim_snprintf((char *)buf_new, 10, "%ld", value);
8897 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008898 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8899 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8900 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8901 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8902 reset_v_option_vars();
8903 }
8904#endif
8905
Bram Moolenaar071d4272004-06-13 20:20:40 +00008906 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008907 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008908 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008909 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910 check_redraw(options[opt_idx].flags);
8911
8912 return errmsg;
8913}
8914
8915/*
8916 * Called after an option changed: check if something needs to be redrawn.
8917 */
8918 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008919check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008920{
8921 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008922 int doclear = (flags & P_RCLR) == P_RCLR;
8923 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924
8925#ifdef FEAT_WINDOWS
8926 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8927 status_redraw_all();
8928#endif
8929
8930 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8931 changed_window_setting();
8932 if (flags & P_RBUF)
8933 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008934 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935 redraw_all_later(CLEAR);
8936 else if (all)
8937 redraw_all_later(NOT_VALID);
8938}
8939
8940/*
8941 * Find index for option 'arg'.
8942 * Return -1 if not found.
8943 */
8944 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008945findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008946{
8947 int opt_idx;
8948 char *s, *p;
8949 static short quick_tab[27] = {0, 0}; /* quick access table */
8950 int is_term_opt;
8951
8952 /*
8953 * For first call: Initialize the quick-access table.
8954 * It contains the index for the first option that starts with a certain
8955 * letter. There are 26 letters, plus the first "t_" option.
8956 */
8957 if (quick_tab[1] == 0)
8958 {
8959 p = options[0].fullname;
8960 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8961 {
8962 if (s[0] != p[0])
8963 {
8964 if (s[0] == 't' && s[1] == '_')
8965 quick_tab[26] = opt_idx;
8966 else
8967 quick_tab[CharOrdLow(s[0])] = opt_idx;
8968 }
8969 p = s;
8970 }
8971 }
8972
8973 /*
8974 * Check for name starting with an illegal character.
8975 */
8976#ifdef EBCDIC
8977 if (!islower(arg[0]))
8978#else
8979 if (arg[0] < 'a' || arg[0] > 'z')
8980#endif
8981 return -1;
8982
8983 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8984 if (is_term_opt)
8985 opt_idx = quick_tab[26];
8986 else
8987 opt_idx = quick_tab[CharOrdLow(arg[0])];
8988 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8989 {
8990 if (STRCMP(arg, s) == 0) /* match full name */
8991 break;
8992 }
8993 if (s == NULL && !is_term_opt)
8994 {
8995 opt_idx = quick_tab[CharOrdLow(arg[0])];
8996 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8997 {
8998 s = options[opt_idx].shortname;
8999 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9000 break;
9001 s = NULL;
9002 }
9003 }
9004 if (s == NULL)
9005 opt_idx = -1;
9006 return opt_idx;
9007}
9008
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009009#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009010/*
9011 * Get the value for an option.
9012 *
9013 * Returns:
9014 * Number or Toggle option: 1, *numval gets value.
9015 * String option: 0, *stringval gets allocated string.
9016 * Hidden Number or Toggle option: -1.
9017 * hidden String option: -2.
9018 * unknown option: -3.
9019 */
9020 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009021get_option_value(
9022 char_u *name,
9023 long *numval,
9024 char_u **stringval, /* NULL when only checking existence */
9025 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009026{
9027 int opt_idx;
9028 char_u *varp;
9029
9030 opt_idx = findoption(name);
9031 if (opt_idx < 0) /* unknown option */
9032 return -3;
9033
9034 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9035
9036 if (options[opt_idx].flags & P_STRING)
9037 {
9038 if (varp == NULL) /* hidden option */
9039 return -2;
9040 if (stringval != NULL)
9041 {
9042#ifdef FEAT_CRYPT
9043 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009044 if ((char_u **)varp == &curbuf->b_p_key
9045 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009046 *stringval = vim_strsave((char_u *)"*****");
9047 else
9048#endif
9049 *stringval = vim_strsave(*(char_u **)(varp));
9050 }
9051 return 0;
9052 }
9053
9054 if (varp == NULL) /* hidden option */
9055 return -1;
9056 if (options[opt_idx].flags & P_NUM)
9057 *numval = *(long *)varp;
9058 else
9059 {
9060 /* Special case: 'modified' is b_changed, but we also want to consider
9061 * it set when 'ff' or 'fenc' changed. */
9062 if ((int *)varp == &curbuf->b_changed)
9063 *numval = curbufIsChanged();
9064 else
9065 *numval = *(int *)varp;
9066 }
9067 return 1;
9068}
9069#endif
9070
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009071#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009072/*
9073 * Returns the option attributes and its value. Unlike the above function it
9074 * will return either global value or local value of the option depending on
9075 * what was requested, but it will never return global value if it was
9076 * requested to return local one and vice versa. Neither it will return
9077 * buffer-local value if it was requested to return window-local one.
9078 *
9079 * Pretends that option is absent if it is not present in the requested scope
9080 * (i.e. has no global, window-local or buffer-local value depending on
9081 * opt_type). Uses
9082 *
9083 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009084 * 0 hidden or unknown option, also option that does not have requested
9085 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009086 * see SOPT_* in vim.h for other flags
9087 *
9088 * Possible opt_type values: see SREQ_* in vim.h
9089 */
9090 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009091get_option_value_strict(
9092 char_u *name,
9093 long *numval,
9094 char_u **stringval, /* NULL when only obtaining attributes */
9095 int opt_type,
9096 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009097{
9098 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009099 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009100 struct vimoption *p;
9101 int r = 0;
9102
9103 opt_idx = findoption(name);
9104 if (opt_idx < 0)
9105 return 0;
9106
9107 p = &(options[opt_idx]);
9108
9109 /* Hidden option */
9110 if (p->var == NULL)
9111 return 0;
9112
9113 if (p->flags & P_BOOL)
9114 r |= SOPT_BOOL;
9115 else if (p->flags & P_NUM)
9116 r |= SOPT_NUM;
9117 else if (p->flags & P_STRING)
9118 r |= SOPT_STRING;
9119
9120 if (p->indir == PV_NONE)
9121 {
9122 if (opt_type == SREQ_GLOBAL)
9123 r |= SOPT_GLOBAL;
9124 else
9125 return 0; /* Did not request global-only option */
9126 }
9127 else
9128 {
9129 if (p->indir & PV_BOTH)
9130 r |= SOPT_GLOBAL;
9131 else if (opt_type == SREQ_GLOBAL)
9132 return 0; /* Requested global option */
9133
9134 if (p->indir & PV_WIN)
9135 {
9136 if (opt_type == SREQ_BUF)
9137 return 0; /* Did not request window-local option */
9138 else
9139 r |= SOPT_WIN;
9140 }
9141 else if (p->indir & PV_BUF)
9142 {
9143 if (opt_type == SREQ_WIN)
9144 return 0; /* Did not request buffer-local option */
9145 else
9146 r |= SOPT_BUF;
9147 }
9148 }
9149
9150 if (stringval == NULL)
9151 return r;
9152
9153 if (opt_type == SREQ_GLOBAL)
9154 varp = p->var;
9155 else
9156 {
9157 if (opt_type == SREQ_BUF)
9158 {
9159 /* Special case: 'modified' is b_changed, but we also want to
9160 * consider it set when 'ff' or 'fenc' changed. */
9161 if (p->indir == PV_MOD)
9162 {
9163 *numval = bufIsChanged((buf_T *) from);
9164 varp = NULL;
9165 }
9166#ifdef FEAT_CRYPT
9167 else if (p->indir == PV_KEY)
9168 {
9169 /* never return the value of the crypt key */
9170 *stringval = NULL;
9171 varp = NULL;
9172 }
9173#endif
9174 else
9175 {
9176 aco_save_T aco;
9177 aucmd_prepbuf(&aco, (buf_T *) from);
9178 varp = get_varp(p);
9179 aucmd_restbuf(&aco);
9180 }
9181 }
9182 else if (opt_type == SREQ_WIN)
9183 {
9184 win_T *save_curwin;
9185 save_curwin = curwin;
9186 curwin = (win_T *) from;
9187 curbuf = curwin->w_buffer;
9188 varp = get_varp(p);
9189 curwin = save_curwin;
9190 curbuf = curwin->w_buffer;
9191 }
9192 if (varp == p->var)
9193 return (r | SOPT_UNSET);
9194 }
9195
9196 if (varp != NULL)
9197 {
9198 if (p->flags & P_STRING)
9199 *stringval = vim_strsave(*(char_u **)(varp));
9200 else if (p->flags & P_NUM)
9201 *numval = *(long *) varp;
9202 else
9203 *numval = *(int *)varp;
9204 }
9205
9206 return r;
9207}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009208
9209/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009210 * Iterate over options. First argument is a pointer to a pointer to a
9211 * structure inside options[] array, second is option type like in the above
9212 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009213 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009214 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009215 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009216 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009217 * first argument to NULL.
9218 *
9219 * Returns full option name for current option on each call.
9220 */
9221 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009222option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009223{
9224 struct vimoption *ret = NULL;
9225 do
9226 {
9227 if (*option == NULL)
9228 *option = (void *) options;
9229 else if (((struct vimoption *) (*option))->fullname == NULL)
9230 {
9231 *option = NULL;
9232 return NULL;
9233 }
9234 else
9235 *option = (void *) (((struct vimoption *) (*option)) + 1);
9236
9237 ret = ((struct vimoption *) (*option));
9238
9239 /* Hidden option */
9240 if (ret->var == NULL)
9241 {
9242 ret = NULL;
9243 continue;
9244 }
9245
9246 switch (opt_type)
9247 {
9248 case SREQ_GLOBAL:
9249 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9250 ret = NULL;
9251 break;
9252 case SREQ_BUF:
9253 if (!(ret->indir & PV_BUF))
9254 ret = NULL;
9255 break;
9256 case SREQ_WIN:
9257 if (!(ret->indir & PV_WIN))
9258 ret = NULL;
9259 break;
9260 default:
9261 EMSG2(_(e_intern2), "option_iter_next()");
9262 return NULL;
9263 }
9264 }
9265 while (ret == NULL);
9266
9267 return (char_u *)ret->fullname;
9268}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009269#endif
9270
Bram Moolenaar071d4272004-06-13 20:20:40 +00009271/*
9272 * Set the value of option "name".
9273 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009274 *
9275 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009276 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009277 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009278set_option_value(
9279 char_u *name,
9280 long number,
9281 char_u *string,
9282 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009283{
9284 int opt_idx;
9285 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009286 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009287
9288 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009289 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009290 EMSG2(_("E355: Unknown option: %s"), name);
9291 else
9292 {
9293 flags = options[opt_idx].flags;
9294#ifdef HAVE_SANDBOX
9295 /* Disallow changing some options in the sandbox */
9296 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009297 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009298 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009299 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009300 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009301#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009302 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009303 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304 else
9305 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009306 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 if (varp != NULL) /* hidden option is not changed */
9308 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009309 if (number == 0 && string != NULL)
9310 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009311 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009312
9313 /* Either we are given a string or we are setting option
9314 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009315 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009316 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009317 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009318 {
9319 /* There's another character after zeros or the string
9320 * is empty. In both cases, we are trying to set a
9321 * num option using a string. */
9322 EMSG3(_("E521: Number required: &%s = '%s'"),
9323 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009324 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009325
9326 }
9327 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009328 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009329 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009330 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009332 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009333 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334 }
9335 }
9336 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009337 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338}
9339
9340/*
9341 * Get the terminal code for a terminal option.
9342 * Returns NULL when not found.
9343 */
9344 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009345get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009346{
9347 int opt_idx;
9348 char_u *varp;
9349
9350 if (tname[0] != 't' || tname[1] != '_' ||
9351 tname[2] == NUL || tname[3] == NUL)
9352 return NULL;
9353 if ((opt_idx = findoption(tname)) >= 0)
9354 {
9355 varp = get_varp(&(options[opt_idx]));
9356 if (varp != NULL)
9357 varp = *(char_u **)(varp);
9358 return varp;
9359 }
9360 return find_termcode(tname + 2);
9361}
9362
9363 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009364get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365{
9366 int i;
9367
9368 i = findoption((char_u *)"hl");
9369 if (i >= 0)
9370 return options[i].def_val[VI_DEFAULT];
9371 return (char_u *)NULL;
9372}
9373
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009374#if defined(FEAT_MBYTE) || defined(PROTO)
9375 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009376get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009377{
9378 int i;
9379
9380 i = findoption((char_u *)"enc");
9381 if (i >= 0)
9382 return options[i].def_val[VI_DEFAULT];
9383 return (char_u *)NULL;
9384}
9385#endif
9386
Bram Moolenaar071d4272004-06-13 20:20:40 +00009387/*
9388 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9389 */
9390 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009391find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009392{
9393 int key;
9394 int modifiers;
9395
9396 /*
9397 * Don't use get_special_key_code() for t_xx, we don't want it to call
9398 * add_termcap_entry().
9399 */
9400 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9401 key = TERMCAP2KEY(arg[2], arg[3]);
9402 else
9403 {
9404 --arg; /* put arg at the '<' */
9405 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009406 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009407 if (modifiers) /* can't handle modifiers here */
9408 key = 0;
9409 }
9410 return key;
9411}
9412
9413/*
9414 * if 'all' == 0: show changed options
9415 * if 'all' == 1: show all normal options
9416 * if 'all' == 2: show all terminal options
9417 */
9418 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009419showoptions(
9420 int all,
9421 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009422{
9423 struct vimoption *p;
9424 int col;
9425 int isterm;
9426 char_u *varp;
9427 struct vimoption **items;
9428 int item_count;
9429 int run;
9430 int row, rows;
9431 int cols;
9432 int i;
9433 int len;
9434
9435#define INC 20
9436#define GAP 3
9437
9438 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9439 PARAM_COUNT));
9440 if (items == NULL)
9441 return;
9442
9443 /* Highlight title */
9444 if (all == 2)
9445 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9446 else if (opt_flags & OPT_GLOBAL)
9447 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9448 else if (opt_flags & OPT_LOCAL)
9449 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9450 else
9451 MSG_PUTS_TITLE(_("\n--- Options ---"));
9452
9453 /*
9454 * do the loop two times:
9455 * 1. display the short items
9456 * 2. display the long items (only strings and numbers)
9457 */
9458 for (run = 1; run <= 2 && !got_int; ++run)
9459 {
9460 /*
9461 * collect the items in items[]
9462 */
9463 item_count = 0;
9464 for (p = &options[0]; p->fullname != NULL; p++)
9465 {
9466 varp = NULL;
9467 isterm = istermoption(p);
9468 if (opt_flags != 0)
9469 {
9470 if (p->indir != PV_NONE && !isterm)
9471 varp = get_varp_scope(p, opt_flags);
9472 }
9473 else
9474 varp = get_varp(p);
9475 if (varp != NULL
9476 && ((all == 2 && isterm)
9477 || (all == 1 && !isterm)
9478 || (all == 0 && !optval_default(p, varp))))
9479 {
9480 if (p->flags & P_BOOL)
9481 len = 1; /* a toggle option fits always */
9482 else
9483 {
9484 option_value2string(p, opt_flags);
9485 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9486 }
9487 if ((len <= INC - GAP && run == 1) ||
9488 (len > INC - GAP && run == 2))
9489 items[item_count++] = p;
9490 }
9491 }
9492
9493 /*
9494 * display the items
9495 */
9496 if (run == 1)
9497 {
9498 cols = (Columns + GAP - 3) / INC;
9499 if (cols == 0)
9500 cols = 1;
9501 rows = (item_count + cols - 1) / cols;
9502 }
9503 else /* run == 2 */
9504 rows = item_count;
9505 for (row = 0; row < rows && !got_int; ++row)
9506 {
9507 msg_putchar('\n'); /* go to next line */
9508 if (got_int) /* 'q' typed in more */
9509 break;
9510 col = 0;
9511 for (i = row; i < item_count; i += rows)
9512 {
9513 msg_col = col; /* make columns */
9514 showoneopt(items[i], opt_flags);
9515 col += INC;
9516 }
9517 out_flush();
9518 ui_breakcheck();
9519 }
9520 }
9521 vim_free(items);
9522}
9523
9524/*
9525 * Return TRUE if option "p" has its default value.
9526 */
9527 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009528optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009529{
9530 int dvi;
9531
9532 if (varp == NULL)
9533 return TRUE; /* hidden option is always at default */
9534 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9535 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009536 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009538 /* the cast to long is required for Manx C, long_i is
9539 * needed for MSVC */
9540 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009541 /* P_STRING */
9542 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9543}
9544
9545/*
9546 * showoneopt: show the value of one option
9547 * must not be called with a hidden option!
9548 */
9549 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009550showoneopt(
9551 struct vimoption *p,
9552 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009553{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009554 char_u *varp;
9555 int save_silent = silent_mode;
9556
9557 silent_mode = FALSE;
9558 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009559
9560 varp = get_varp_scope(p, opt_flags);
9561
9562 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9563 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9564 ? !curbufIsChanged() : !*(int *)varp))
9565 MSG_PUTS("no");
9566 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9567 MSG_PUTS("--");
9568 else
9569 MSG_PUTS(" ");
9570 MSG_PUTS(p->fullname);
9571 if (!(p->flags & P_BOOL))
9572 {
9573 msg_putchar('=');
9574 /* put value string in NameBuff */
9575 option_value2string(p, opt_flags);
9576 msg_outtrans(NameBuff);
9577 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009578
9579 silent_mode = save_silent;
9580 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009581}
9582
9583/*
9584 * Write modified options as ":set" commands to a file.
9585 *
9586 * There are three values for "opt_flags":
9587 * OPT_GLOBAL: Write global option values and fresh values of
9588 * buffer-local options (used for start of a session
9589 * file).
9590 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9591 * curwin (used for a vimrc file).
9592 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9593 * and local values for window-local options of
9594 * curwin. Local values are also written when at the
9595 * default value, because a modeline or autocommand
9596 * may have set them when doing ":edit file" and the
9597 * user has set them back at the default or fresh
9598 * value.
9599 * When "local_only" is TRUE, don't write fresh
9600 * values, only local values (for ":mkview").
9601 * (fresh value = value used for a new buffer or window for a local option).
9602 *
9603 * Return FAIL on error, OK otherwise.
9604 */
9605 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009606makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009607{
9608 struct vimoption *p;
9609 char_u *varp; /* currently used value */
9610 char_u *varp_fresh; /* local value */
9611 char_u *varp_local = NULL; /* fresh value */
9612 char *cmd;
9613 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009614 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009615
9616 /*
9617 * The options that don't have a default (terminal name, columns, lines)
9618 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009619 * Do the loop over "options[]" twice: once for options with the
9620 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009622 for (pri = 1; pri >= 0; --pri)
9623 {
9624 for (p = &options[0]; !istermoption(p); p++)
9625 if (!(p->flags & P_NO_MKRC)
9626 && !istermoption(p)
9627 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009628 {
9629 /* skip global option when only doing locals */
9630 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9631 continue;
9632
9633 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9634 * file, they are always buffer-specific. */
9635 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9636 continue;
9637
9638 /* Global values are only written when not at the default value. */
9639 varp = get_varp_scope(p, opt_flags);
9640 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9641 continue;
9642
9643 round = 2;
9644 if (p->indir != PV_NONE)
9645 {
9646 if (p->var == VAR_WIN)
9647 {
9648 /* skip window-local option when only doing globals */
9649 if (!(opt_flags & OPT_LOCAL))
9650 continue;
9651 /* When fresh value of window-local option is not at the
9652 * default, need to write it too. */
9653 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9654 {
9655 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9656 if (!optval_default(p, varp_fresh))
9657 {
9658 round = 1;
9659 varp_local = varp;
9660 varp = varp_fresh;
9661 }
9662 }
9663 }
9664 }
9665
9666 /* Round 1: fresh value for window-local options.
9667 * Round 2: other values */
9668 for ( ; round <= 2; varp = varp_local, ++round)
9669 {
9670 if (round == 1 || (opt_flags & OPT_GLOBAL))
9671 cmd = "set";
9672 else
9673 cmd = "setlocal";
9674
9675 if (p->flags & P_BOOL)
9676 {
9677 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9678 return FAIL;
9679 }
9680 else if (p->flags & P_NUM)
9681 {
9682 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9683 return FAIL;
9684 }
9685 else /* P_STRING */
9686 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009687#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9688 int do_endif = FALSE;
9689
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690 /* Don't set 'syntax' and 'filetype' again if the value is
9691 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009692 if (
9693# if defined(FEAT_SYN_HL)
9694 p->indir == PV_SYN
9695# if defined(FEAT_AUTOCMD)
9696 ||
9697# endif
9698# endif
9699# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009700 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009701# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009702 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009703 {
9704 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9705 *(char_u **)(varp)) < 0
9706 || put_eol(fd) < 0)
9707 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009708 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009709 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009711 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9712 (p->flags & P_EXPAND) != 0) == FAIL)
9713 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009714#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9715 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716 {
9717 if (put_line(fd, "endif") == FAIL)
9718 return FAIL;
9719 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009720#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009721 }
9722 }
9723 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725 return OK;
9726}
9727
9728#if defined(FEAT_FOLDING) || defined(PROTO)
9729/*
9730 * Generate set commands for the local fold options only. Used when
9731 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9732 */
9733 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009734makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009735{
9736 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9737# ifdef FEAT_EVAL
9738 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9739 == FAIL
9740# endif
9741 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9742 == FAIL
9743 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9744 == FAIL
9745 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9746 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9747 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9748 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9749 )
9750 return FAIL;
9751
9752 return OK;
9753}
9754#endif
9755
9756 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009757put_setstring(
9758 FILE *fd,
9759 char *cmd,
9760 char *name,
9761 char_u **valuep,
9762 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009763{
9764 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009765 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009766
9767 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9768 return FAIL;
9769 if (*valuep != NULL)
9770 {
9771 /* Output 'pastetoggle' as key names. For other
9772 * options some characters have to be escaped with
9773 * CTRL-V or backslash */
9774 if (valuep == &p_pt)
9775 {
9776 s = *valuep;
9777 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009778 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009779 return FAIL;
9780 }
9781 else if (expand)
9782 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009783 buf = alloc(MAXPATHL);
9784 if (buf == NULL)
9785 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009786 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9787 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009788 {
9789 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009791 }
9792 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009793 }
9794 else if (put_escstr(fd, *valuep, 2) == FAIL)
9795 return FAIL;
9796 }
9797 if (put_eol(fd) < 0)
9798 return FAIL;
9799 return OK;
9800}
9801
9802 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009803put_setnum(
9804 FILE *fd,
9805 char *cmd,
9806 char *name,
9807 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009808{
9809 long wc;
9810
9811 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9812 return FAIL;
9813 if (wc_use_keyname((char_u *)valuep, &wc))
9814 {
9815 /* print 'wildchar' and 'wildcharm' as a key name */
9816 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9817 return FAIL;
9818 }
9819 else if (fprintf(fd, "%ld", *valuep) < 0)
9820 return FAIL;
9821 if (put_eol(fd) < 0)
9822 return FAIL;
9823 return OK;
9824}
9825
9826 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009827put_setbool(
9828 FILE *fd,
9829 char *cmd,
9830 char *name,
9831 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832{
Bram Moolenaar893de922007-10-02 18:40:57 +00009833 if (value < 0) /* global/local option using global value */
9834 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009835 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9836 || put_eol(fd) < 0)
9837 return FAIL;
9838 return OK;
9839}
9840
9841/*
9842 * Clear all the terminal options.
9843 * If the option has been allocated, free the memory.
9844 * Terminal options are never hidden or indirect.
9845 */
9846 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009847clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009848{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009849 /*
9850 * Reset a few things before clearing the old options. This may cause
9851 * outputting a few things that the terminal doesn't understand, but the
9852 * screen will be cleared later, so this is OK.
9853 */
9854#ifdef FEAT_MOUSE_TTY
9855 mch_setmouse(FALSE); /* switch mouse off */
9856#endif
9857#ifdef FEAT_TITLE
9858 mch_restore_title(3); /* restore window titles */
9859#endif
9860#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9861 /* When starting the GUI close the display opened for the clipboard.
9862 * After restoring the title, because that will need the display. */
9863 if (gui.starting)
9864 clear_xterm_clip();
9865#endif
9866#ifdef WIN3264
9867 /*
9868 * Check if this is allowed now.
9869 */
9870 if (can_end_termcap_mode(FALSE) == TRUE)
9871#endif
9872 stoptermcap(); /* stop termcap mode */
9873
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009874 free_termoptions();
9875}
9876
9877 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009878free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009879{
9880 struct vimoption *p;
9881
Bram Moolenaar071d4272004-06-13 20:20:40 +00009882 for (p = &options[0]; p->fullname != NULL; p++)
9883 if (istermoption(p))
9884 {
9885 if (p->flags & P_ALLOCED)
9886 free_string_option(*(char_u **)(p->var));
9887 if (p->flags & P_DEF_ALLOCED)
9888 free_string_option(p->def_val[VI_DEFAULT]);
9889 *(char_u **)(p->var) = empty_option;
9890 p->def_val[VI_DEFAULT] = empty_option;
9891 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9892 }
9893 clear_termcodes();
9894}
9895
9896/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009897 * Free the string for one term option, if it was allocated.
9898 * Set the string to empty_option and clear allocated flag.
9899 * "var" points to the option value.
9900 */
9901 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009902free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009903{
9904 struct vimoption *p;
9905
9906 for (p = &options[0]; p->fullname != NULL; p++)
9907 if (p->var == var)
9908 {
9909 if (p->flags & P_ALLOCED)
9910 free_string_option(*(char_u **)(p->var));
9911 *(char_u **)(p->var) = empty_option;
9912 p->flags &= ~P_ALLOCED;
9913 break;
9914 }
9915}
9916
9917/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009918 * Set the terminal option defaults to the current value.
9919 * Used after setting the terminal name.
9920 */
9921 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009922set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923{
9924 struct vimoption *p;
9925
9926 for (p = &options[0]; p->fullname != NULL; p++)
9927 {
9928 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9929 {
9930 if (p->flags & P_DEF_ALLOCED)
9931 {
9932 free_string_option(p->def_val[VI_DEFAULT]);
9933 p->flags &= ~P_DEF_ALLOCED;
9934 }
9935 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9936 if (p->flags & P_ALLOCED)
9937 {
9938 p->flags |= P_DEF_ALLOCED;
9939 p->flags &= ~P_ALLOCED; /* don't free the value now */
9940 }
9941 }
9942 }
9943}
9944
9945/*
9946 * return TRUE if 'p' starts with 't_'
9947 */
9948 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009949istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950{
9951 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9952}
9953
9954/*
9955 * Compute columns for ruler and shown command. 'sc_col' is also used to
9956 * decide what the maximum length of a message on the status line can be.
9957 * If there is a status line for the last window, 'sc_col' is independent
9958 * of 'ru_col'.
9959 */
9960
9961#define COL_RULER 17 /* columns needed by standard ruler */
9962
9963 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009964comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965{
9966#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9967 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9968
9969 sc_col = 0;
9970 ru_col = 0;
9971 if (p_ru)
9972 {
9973#ifdef FEAT_STL_OPT
9974 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9975#else
9976 ru_col = COL_RULER + 1;
9977#endif
9978 /* no last status line, adjust sc_col */
9979 if (!last_has_status)
9980 sc_col = ru_col;
9981 }
9982 if (p_sc)
9983 {
9984 sc_col += SHOWCMD_COLS;
9985 if (!p_ru || last_has_status) /* no need for separating space */
9986 ++sc_col;
9987 }
9988 sc_col = Columns - sc_col;
9989 ru_col = Columns - ru_col;
9990 if (sc_col <= 0) /* screen too narrow, will become a mess */
9991 sc_col = 1;
9992 if (ru_col <= 0)
9993 ru_col = 1;
9994#else
9995 sc_col = Columns;
9996 ru_col = Columns;
9997#endif
9998}
9999
10000/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010001 * Unset local option value, similar to ":set opt<".
10002 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010003 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010004unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010005{
10006 struct vimoption *p;
10007 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010008 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010009
10010 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010011 if (opt_idx < 0)
10012 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010013 p = &(options[opt_idx]);
10014
10015 switch ((int)p->indir)
10016 {
10017 /* global option with local value: use local value if it's been set */
10018 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010019 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010020 break;
10021 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010022 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010023 break;
10024 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010025 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010026 break;
10027 case PV_AR:
10028 buf->b_p_ar = -1;
10029 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010030 case PV_BKC:
10031 clear_string_option(&buf->b_p_bkc);
10032 buf->b_bkc_flags = 0;
10033 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010034 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010035 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010036 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010037 case PV_TC:
10038 clear_string_option(&buf->b_p_tc);
10039 buf->b_tc_flags = 0;
10040 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010041#ifdef FEAT_FIND_ID
10042 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010043 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010044 break;
10045 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010046 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010047 break;
10048#endif
10049#ifdef FEAT_INS_EXPAND
10050 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010051 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010052 break;
10053 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010054 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010055 break;
10056#endif
10057#ifdef FEAT_QUICKFIX
10058 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010059 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010060 break;
10061 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010062 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010063 break;
10064 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010065 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010066 break;
10067#endif
10068#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10069 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010070 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010071 break;
10072#endif
10073#if defined(FEAT_CRYPT)
10074 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010075 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010076 break;
10077#endif
10078#ifdef FEAT_STL_OPT
10079 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010080 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010081 break;
10082#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010083 case PV_UL:
10084 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10085 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010086#ifdef FEAT_LISP
10087 case PV_LW:
10088 clear_string_option(&buf->b_p_lw);
10089 break;
10090#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010091 }
10092}
10093
10094/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010095 * Get pointer to option variable, depending on local or global scope.
10096 */
10097 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010098get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099{
10100 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10101 {
10102 if (p->var == VAR_WIN)
10103 return (char_u *)GLOBAL_WO(get_varp(p));
10104 return p->var;
10105 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010106 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010107 {
10108 switch ((int)p->indir)
10109 {
10110#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010111 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10112 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10113 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010114#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010115 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10116 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10117 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010118 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010119 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010120 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010121#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010122 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10123 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124#endif
10125#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010126 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10127 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010129#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10130 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10131#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010132#if defined(FEAT_CRYPT)
10133 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10134#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010135#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010136 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010137#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010138 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010139#ifdef FEAT_LISP
10140 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10141#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010142 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010143 }
10144 return NULL; /* "cannot happen" */
10145 }
10146 return get_varp(p);
10147}
10148
10149/*
10150 * Get pointer to option variable.
10151 */
10152 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010153get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154{
10155 /* hidden option, always return NULL */
10156 if (p->var == NULL)
10157 return NULL;
10158
10159 switch ((int)p->indir)
10160 {
10161 case PV_NONE: return p->var;
10162
10163 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010164 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010165 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010166 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010168 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010170 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010172 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010174 case PV_TC: return *curbuf->b_p_tc != NUL
10175 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010176 case PV_BKC: return *curbuf->b_p_bkc != NUL
10177 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010179 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010181 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10183#endif
10184#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010185 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010187 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10189#endif
10190#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010191 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010193 case PV_GP: return *curbuf->b_p_gp != NUL
10194 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10195 case PV_MP: return *curbuf->b_p_mp != NUL
10196 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010198#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10199 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10200 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10201#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010202#if defined(FEAT_CRYPT)
10203 case PV_CM: return *curbuf->b_p_cm != NUL
10204 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10205#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010206#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010207 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010208 ? (char_u *)&(curwin->w_p_stl) : p->var;
10209#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010210 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10211 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010212#ifdef FEAT_LISP
10213 case PV_LW: return *curbuf->b_p_lw != NUL
10214 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216
10217#ifdef FEAT_ARABIC
10218 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10219#endif
10220 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010221#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010222 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10223#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010224#ifdef FEAT_SYN_HL
10225 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10226 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010227 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010228#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229#ifdef FEAT_DIFF
10230 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10231#endif
10232#ifdef FEAT_FOLDING
10233 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10234 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10235 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10236 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10237 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10238 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10239 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10240# ifdef FEAT_EVAL
10241 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10242 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10243# endif
10244 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10245#endif
10246 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010247 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010248#ifdef FEAT_LINEBREAK
10249 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10250#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010251#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10253#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010254#ifdef FEAT_VERTSPLIT
10255 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10256#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10258 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10259#endif
10260#ifdef FEAT_RIGHTLEFT
10261 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10262 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10263#endif
10264 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10265 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10266#ifdef FEAT_LINEBREAK
10267 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010268 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10269 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270#endif
10271#ifdef FEAT_SCROLLBIND
10272 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10273#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010274#ifdef FEAT_CURSORBIND
10275 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10276#endif
10277#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010278 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10279 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010280#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281
10282 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10283 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10284#ifdef FEAT_MBYTE
10285 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10286#endif
10287#if defined(FEAT_QUICKFIX)
10288 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10289 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10290#endif
10291 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10292 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10293#ifdef FEAT_CINDENT
10294 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10295 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10296 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10297#endif
10298#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10299 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10300#endif
10301#ifdef FEAT_COMMENTS
10302 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10303#endif
10304#ifdef FEAT_FOLDING
10305 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10306#endif
10307#ifdef FEAT_INS_EXPAND
10308 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10309#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010310#ifdef FEAT_COMPL_FUNC
10311 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010312 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010313#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010315 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10317#ifdef FEAT_MBYTE
10318 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10319#endif
10320 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10321#ifdef FEAT_AUTOCMD
10322 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10323#endif
10324 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010325 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10327 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10328 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10329 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10330#ifdef FEAT_FIND_ID
10331# ifdef FEAT_EVAL
10332 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10333# endif
10334#endif
10335#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10336 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10337 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10338#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010339#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010340 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10341#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342#ifdef FEAT_CRYPT
10343 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10344#endif
10345#ifdef FEAT_LISP
10346 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10347#endif
10348 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10349 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10350 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10351 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10352 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010354#ifdef FEAT_TEXTOBJ
10355 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10356#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10358#ifdef FEAT_SMARTINDENT
10359 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10360#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010361 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010362 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10363#ifdef FEAT_SEARCHPATH
10364 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10365#endif
10366 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10367#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010368 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010369 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10370#endif
10371#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010372 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10373 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10374 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375#endif
10376 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10377 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10378 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10379 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010380#ifdef FEAT_PERSISTENT_UNDO
10381 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10382#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10384#ifdef FEAT_KEYMAP
10385 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10386#endif
10387 default: EMSG(_("E356: get_varp ERROR"));
10388 }
10389 /* always return a valid pointer to avoid a crash! */
10390 return (char_u *)&(curbuf->b_p_wm);
10391}
10392
10393/*
10394 * Get the value of 'equalprg', either the buffer-local one or the global one.
10395 */
10396 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010397get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398{
10399 if (*curbuf->b_p_ep == NUL)
10400 return p_ep;
10401 return curbuf->b_p_ep;
10402}
10403
10404#if defined(FEAT_WINDOWS) || defined(PROTO)
10405/*
10406 * Copy options from one window to another.
10407 * Used when splitting a window.
10408 */
10409 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010410win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010411{
10412 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10413 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10414# ifdef FEAT_RIGHTLEFT
10415# ifdef FEAT_FKMAP
10416 /* Is this right? */
10417 wp_to->w_farsi = wp_from->w_farsi;
10418# endif
10419# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010420#if defined(FEAT_LINEBREAK)
10421 briopt_check(wp_to);
10422#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010423}
10424#endif
10425
10426/*
10427 * Copy the options from one winopt_T to another.
10428 * Doesn't free the old option values in "to", use clear_winopt() for that.
10429 * The 'scroll' option is not copied, because it depends on the window height.
10430 * The 'previewwindow' option is reset, there can be only one preview window.
10431 */
10432 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010433copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434{
10435#ifdef FEAT_ARABIC
10436 to->wo_arab = from->wo_arab;
10437#endif
10438 to->wo_list = from->wo_list;
10439 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010440 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010441#ifdef FEAT_LINEBREAK
10442 to->wo_nuw = from->wo_nuw;
10443#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010444#ifdef FEAT_RIGHTLEFT
10445 to->wo_rl = from->wo_rl;
10446 to->wo_rlc = vim_strsave(from->wo_rlc);
10447#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010448#ifdef FEAT_STL_OPT
10449 to->wo_stl = vim_strsave(from->wo_stl);
10450#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010452#ifdef FEAT_DIFF
10453 to->wo_wrap_save = from->wo_wrap_save;
10454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010455#ifdef FEAT_LINEBREAK
10456 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010457 to->wo_bri = from->wo_bri;
10458 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459#endif
10460#ifdef FEAT_SCROLLBIND
10461 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010462 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010463#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010464#ifdef FEAT_CURSORBIND
10465 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010466 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010467#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010468#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010469 to->wo_spell = from->wo_spell;
10470#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010471#ifdef FEAT_SYN_HL
10472 to->wo_cuc = from->wo_cuc;
10473 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010474 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010475#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476#ifdef FEAT_DIFF
10477 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010478 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010479#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010480#ifdef FEAT_CONCEAL
10481 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010482 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484#ifdef FEAT_FOLDING
10485 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010486 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010488 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010489 to->wo_fdi = vim_strsave(from->wo_fdi);
10490 to->wo_fml = from->wo_fml;
10491 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010492 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010494 to->wo_fdm_save = from->wo_diff_saved
10495 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010496 to->wo_fdn = from->wo_fdn;
10497# ifdef FEAT_EVAL
10498 to->wo_fde = vim_strsave(from->wo_fde);
10499 to->wo_fdt = vim_strsave(from->wo_fdt);
10500# endif
10501 to->wo_fmr = vim_strsave(from->wo_fmr);
10502#endif
10503 check_winopt(to); /* don't want NULL pointers */
10504}
10505
10506/*
10507 * Check string options in a window for a NULL value.
10508 */
10509 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010510check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511{
10512 check_winopt(&win->w_onebuf_opt);
10513 check_winopt(&win->w_allbuf_opt);
10514}
10515
10516/*
10517 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10518 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010519 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010520check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521{
10522#ifdef FEAT_FOLDING
10523 check_string_option(&wop->wo_fdi);
10524 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010525 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526# ifdef FEAT_EVAL
10527 check_string_option(&wop->wo_fde);
10528 check_string_option(&wop->wo_fdt);
10529# endif
10530 check_string_option(&wop->wo_fmr);
10531#endif
10532#ifdef FEAT_RIGHTLEFT
10533 check_string_option(&wop->wo_rlc);
10534#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010535#ifdef FEAT_STL_OPT
10536 check_string_option(&wop->wo_stl);
10537#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010538#ifdef FEAT_SYN_HL
10539 check_string_option(&wop->wo_cc);
10540#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010541#ifdef FEAT_CONCEAL
10542 check_string_option(&wop->wo_cocu);
10543#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010544#ifdef FEAT_LINEBREAK
10545 check_string_option(&wop->wo_briopt);
10546#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547}
10548
10549/*
10550 * Free the allocated memory inside a winopt_T.
10551 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010553clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554{
10555#ifdef FEAT_FOLDING
10556 clear_string_option(&wop->wo_fdi);
10557 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010558 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010559# ifdef FEAT_EVAL
10560 clear_string_option(&wop->wo_fde);
10561 clear_string_option(&wop->wo_fdt);
10562# endif
10563 clear_string_option(&wop->wo_fmr);
10564#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010565#ifdef FEAT_LINEBREAK
10566 clear_string_option(&wop->wo_briopt);
10567#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568#ifdef FEAT_RIGHTLEFT
10569 clear_string_option(&wop->wo_rlc);
10570#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010571#ifdef FEAT_STL_OPT
10572 clear_string_option(&wop->wo_stl);
10573#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010574#ifdef FEAT_SYN_HL
10575 clear_string_option(&wop->wo_cc);
10576#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010577#ifdef FEAT_CONCEAL
10578 clear_string_option(&wop->wo_cocu);
10579#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580}
10581
10582/*
10583 * Copy global option values to local options for one buffer.
10584 * Used when creating a new buffer and sometimes when entering a buffer.
10585 * flags:
10586 * BCO_ENTER We will enter the buf buffer.
10587 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10588 * appropriate.
10589 * BCO_NOHELP Don't copy the values to a help buffer.
10590 */
10591 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010592buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593{
10594 int should_copy = TRUE;
10595 char_u *save_p_isk = NULL; /* init for GCC */
10596 int dont_do_help;
10597 int did_isk = FALSE;
10598
10599 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010600 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601 */
10602 if (buf == NULL || !buf_valid(buf))
10603 return;
10604
10605 /*
10606 * Skip this when the option defaults have not been set yet. Happens when
10607 * main() allocates the first buffer.
10608 */
10609 if (p_cpo != NULL)
10610 {
10611 /*
10612 * Always copy when entering and 'cpo' contains 'S'.
10613 * Don't copy when already initialized.
10614 * Don't copy when 'cpo' contains 's' and not entering.
10615 * 'S' BCO_ENTER initialized 's' should_copy
10616 * yes yes X X TRUE
10617 * yes no yes X FALSE
10618 * no X yes X FALSE
10619 * X no no yes FALSE
10620 * X no no no TRUE
10621 * no yes no X TRUE
10622 */
10623 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10624 && (buf->b_p_initialized
10625 || (!(flags & BCO_ENTER)
10626 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10627 should_copy = FALSE;
10628
10629 if (should_copy || (flags & BCO_ALWAYS))
10630 {
10631 /* Don't copy the options specific to a help buffer when
10632 * BCO_NOHELP is given or the options were initialized already
10633 * (jumping back to a help file with CTRL-T or CTRL-O) */
10634 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10635 || buf->b_p_initialized;
10636 if (dont_do_help) /* don't free b_p_isk */
10637 {
10638 save_p_isk = buf->b_p_isk;
10639 buf->b_p_isk = NULL;
10640 }
10641 /*
10642 * Always free the allocated strings.
10643 * If not already initialized, set 'readonly' and copy 'fileformat'.
10644 */
10645 if (!buf->b_p_initialized)
10646 {
10647 free_buf_options(buf, TRUE);
10648 buf->b_p_ro = FALSE; /* don't copy readonly */
10649 buf->b_p_tx = p_tx;
10650#ifdef FEAT_MBYTE
10651 buf->b_p_fenc = vim_strsave(p_fenc);
10652#endif
10653 buf->b_p_ff = vim_strsave(p_ff);
10654#if defined(FEAT_QUICKFIX)
10655 buf->b_p_bh = empty_option;
10656 buf->b_p_bt = empty_option;
10657#endif
10658 }
10659 else
10660 free_buf_options(buf, FALSE);
10661
10662 buf->b_p_ai = p_ai;
10663 buf->b_p_ai_nopaste = p_ai_nopaste;
10664 buf->b_p_sw = p_sw;
10665 buf->b_p_tw = p_tw;
10666 buf->b_p_tw_nopaste = p_tw_nopaste;
10667 buf->b_p_tw_nobin = p_tw_nobin;
10668 buf->b_p_wm = p_wm;
10669 buf->b_p_wm_nopaste = p_wm_nopaste;
10670 buf->b_p_wm_nobin = p_wm_nobin;
10671 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010672#ifdef FEAT_MBYTE
10673 buf->b_p_bomb = p_bomb;
10674#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010675 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010676 buf->b_p_et = p_et;
10677 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010678 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679 buf->b_p_ml = p_ml;
10680 buf->b_p_ml_nobin = p_ml_nobin;
10681 buf->b_p_inf = p_inf;
10682 buf->b_p_swf = p_swf;
10683#ifdef FEAT_INS_EXPAND
10684 buf->b_p_cpt = vim_strsave(p_cpt);
10685#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010686#ifdef FEAT_COMPL_FUNC
10687 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010688 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010690 buf->b_p_sts = p_sts;
10691 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010692 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010693#ifdef FEAT_COMMENTS
10694 buf->b_p_com = vim_strsave(p_com);
10695#endif
10696#ifdef FEAT_FOLDING
10697 buf->b_p_cms = vim_strsave(p_cms);
10698#endif
10699 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010700 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010701 buf->b_p_nf = vim_strsave(p_nf);
10702 buf->b_p_mps = vim_strsave(p_mps);
10703#ifdef FEAT_SMARTINDENT
10704 buf->b_p_si = p_si;
10705#endif
10706 buf->b_p_ci = p_ci;
10707#ifdef FEAT_CINDENT
10708 buf->b_p_cin = p_cin;
10709 buf->b_p_cink = vim_strsave(p_cink);
10710 buf->b_p_cino = vim_strsave(p_cino);
10711#endif
10712#ifdef FEAT_AUTOCMD
10713 /* Don't copy 'filetype', it must be detected */
10714 buf->b_p_ft = empty_option;
10715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716 buf->b_p_pi = p_pi;
10717#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10718 buf->b_p_cinw = vim_strsave(p_cinw);
10719#endif
10720#ifdef FEAT_LISP
10721 buf->b_p_lisp = p_lisp;
10722#endif
10723#ifdef FEAT_SYN_HL
10724 /* Don't copy 'syntax', it must be set */
10725 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010726 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010727 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010728#endif
10729#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010730 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010731 (void)compile_cap_prog(&buf->b_s);
10732 buf->b_s.b_p_spf = vim_strsave(p_spf);
10733 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734#endif
10735#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10736 buf->b_p_inde = vim_strsave(p_inde);
10737 buf->b_p_indk = vim_strsave(p_indk);
10738#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010739#if defined(FEAT_EVAL)
10740 buf->b_p_fex = vim_strsave(p_fex);
10741#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010742#ifdef FEAT_CRYPT
10743 buf->b_p_key = vim_strsave(p_key);
10744#endif
10745#ifdef FEAT_SEARCHPATH
10746 buf->b_p_sua = vim_strsave(p_sua);
10747#endif
10748#ifdef FEAT_KEYMAP
10749 buf->b_p_keymap = vim_strsave(p_keymap);
10750 buf->b_kmap_state |= KEYMAP_INIT;
10751#endif
10752 /* This isn't really an option, but copying the langmap and IME
10753 * state from the current buffer is better than resetting it. */
10754 buf->b_p_iminsert = p_iminsert;
10755 buf->b_p_imsearch = p_imsearch;
10756
10757 /* options that are normally global but also have a local value
10758 * are not copied, start using the global value */
10759 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010760 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010761 buf->b_p_bkc = empty_option;
10762 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763#ifdef FEAT_QUICKFIX
10764 buf->b_p_gp = empty_option;
10765 buf->b_p_mp = empty_option;
10766 buf->b_p_efm = empty_option;
10767#endif
10768 buf->b_p_ep = empty_option;
10769 buf->b_p_kp = empty_option;
10770 buf->b_p_path = empty_option;
10771 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010772 buf->b_p_tc = empty_option;
10773 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774#ifdef FEAT_FIND_ID
10775 buf->b_p_def = empty_option;
10776 buf->b_p_inc = empty_option;
10777# ifdef FEAT_EVAL
10778 buf->b_p_inex = vim_strsave(p_inex);
10779# endif
10780#endif
10781#ifdef FEAT_INS_EXPAND
10782 buf->b_p_dict = empty_option;
10783 buf->b_p_tsr = empty_option;
10784#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010785#ifdef FEAT_TEXTOBJ
10786 buf->b_p_qe = vim_strsave(p_qe);
10787#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010788#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10789 buf->b_p_bexpr = empty_option;
10790#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010791#if defined(FEAT_CRYPT)
10792 buf->b_p_cm = empty_option;
10793#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010794#ifdef FEAT_PERSISTENT_UNDO
10795 buf->b_p_udf = p_udf;
10796#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010797#ifdef FEAT_LISP
10798 buf->b_p_lw = empty_option;
10799#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010800
10801 /*
10802 * Don't copy the options set by ex_help(), use the saved values,
10803 * when going from a help buffer to a non-help buffer.
10804 * Don't touch these at all when BCO_NOHELP is used and going from
10805 * or to a help buffer.
10806 */
10807 if (dont_do_help)
10808 buf->b_p_isk = save_p_isk;
10809 else
10810 {
10811 buf->b_p_isk = vim_strsave(p_isk);
10812 did_isk = TRUE;
10813 buf->b_p_ts = p_ts;
10814 buf->b_help = FALSE;
10815#ifdef FEAT_QUICKFIX
10816 if (buf->b_p_bt[0] == 'h')
10817 clear_string_option(&buf->b_p_bt);
10818#endif
10819 buf->b_p_ma = p_ma;
10820 }
10821 }
10822
10823 /*
10824 * When the options should be copied (ignoring BCO_ALWAYS), set the
10825 * flag that indicates that the options have been initialized.
10826 */
10827 if (should_copy)
10828 buf->b_p_initialized = TRUE;
10829 }
10830
10831 check_buf_options(buf); /* make sure we don't have NULLs */
10832 if (did_isk)
10833 (void)buf_init_chartab(buf, FALSE);
10834}
10835
10836/*
10837 * Reset the 'modifiable' option and its default value.
10838 */
10839 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010840reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010841{
10842 int opt_idx;
10843
10844 curbuf->b_p_ma = FALSE;
10845 p_ma = FALSE;
10846 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010847 if (opt_idx >= 0)
10848 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849}
10850
10851/*
10852 * Set the global value for 'iminsert' to the local value.
10853 */
10854 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010855set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856{
10857 p_iminsert = curbuf->b_p_iminsert;
10858}
10859
10860/*
10861 * Set the global value for 'imsearch' to the local value.
10862 */
10863 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010864set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865{
10866 p_imsearch = curbuf->b_p_imsearch;
10867}
10868
10869#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10870static int expand_option_idx = -1;
10871static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10872static int expand_option_flags = 0;
10873
10874 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010875set_context_in_set_cmd(
10876 expand_T *xp,
10877 char_u *arg,
10878 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879{
10880 int nextchar;
10881 long_u flags = 0; /* init for GCC */
10882 int opt_idx = 0; /* init for GCC */
10883 char_u *p;
10884 char_u *s;
10885 int is_term_option = FALSE;
10886 int key;
10887
10888 expand_option_flags = opt_flags;
10889
10890 xp->xp_context = EXPAND_SETTINGS;
10891 if (*arg == NUL)
10892 {
10893 xp->xp_pattern = arg;
10894 return;
10895 }
10896 p = arg + STRLEN(arg) - 1;
10897 if (*p == ' ' && *(p - 1) != '\\')
10898 {
10899 xp->xp_pattern = p + 1;
10900 return;
10901 }
10902 while (p > arg)
10903 {
10904 s = p;
10905 /* count number of backslashes before ' ' or ',' */
10906 if (*p == ' ' || *p == ',')
10907 {
10908 while (s > arg && *(s - 1) == '\\')
10909 --s;
10910 }
10911 /* break at a space with an even number of backslashes */
10912 if (*p == ' ' && ((p - s) & 1) == 0)
10913 {
10914 ++p;
10915 break;
10916 }
10917 --p;
10918 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010919 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920 {
10921 xp->xp_context = EXPAND_BOOL_SETTINGS;
10922 p += 2;
10923 }
10924 if (STRNCMP(p, "inv", 3) == 0)
10925 {
10926 xp->xp_context = EXPAND_BOOL_SETTINGS;
10927 p += 3;
10928 }
10929 xp->xp_pattern = arg = p;
10930 if (*arg == '<')
10931 {
10932 while (*p != '>')
10933 if (*p++ == NUL) /* expand terminal option name */
10934 return;
10935 key = get_special_key_code(arg + 1);
10936 if (key == 0) /* unknown name */
10937 {
10938 xp->xp_context = EXPAND_NOTHING;
10939 return;
10940 }
10941 nextchar = *++p;
10942 is_term_option = TRUE;
10943 expand_option_name[2] = KEY2TERMCAP0(key);
10944 expand_option_name[3] = KEY2TERMCAP1(key);
10945 }
10946 else
10947 {
10948 if (p[0] == 't' && p[1] == '_')
10949 {
10950 p += 2;
10951 if (*p != NUL)
10952 ++p;
10953 if (*p == NUL)
10954 return; /* expand option name */
10955 nextchar = *++p;
10956 is_term_option = TRUE;
10957 expand_option_name[2] = p[-2];
10958 expand_option_name[3] = p[-1];
10959 }
10960 else
10961 {
10962 /* Allow * wildcard */
10963 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10964 p++;
10965 if (*p == NUL)
10966 return;
10967 nextchar = *p;
10968 *p = NUL;
10969 opt_idx = findoption(arg);
10970 *p = nextchar;
10971 if (opt_idx == -1 || options[opt_idx].var == NULL)
10972 {
10973 xp->xp_context = EXPAND_NOTHING;
10974 return;
10975 }
10976 flags = options[opt_idx].flags;
10977 if (flags & P_BOOL)
10978 {
10979 xp->xp_context = EXPAND_NOTHING;
10980 return;
10981 }
10982 }
10983 }
10984 /* handle "-=" and "+=" */
10985 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10986 {
10987 ++p;
10988 nextchar = '=';
10989 }
10990 if ((nextchar != '=' && nextchar != ':')
10991 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10992 {
10993 xp->xp_context = EXPAND_UNSUCCESSFUL;
10994 return;
10995 }
10996 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10997 {
10998 xp->xp_context = EXPAND_OLD_SETTING;
10999 if (is_term_option)
11000 expand_option_idx = -1;
11001 else
11002 expand_option_idx = opt_idx;
11003 xp->xp_pattern = p + 1;
11004 return;
11005 }
11006 xp->xp_context = EXPAND_NOTHING;
11007 if (is_term_option || (flags & P_NUM))
11008 return;
11009
11010 xp->xp_pattern = p + 1;
11011
11012 if (flags & P_EXPAND)
11013 {
11014 p = options[opt_idx].var;
11015 if (p == (char_u *)&p_bdir
11016 || p == (char_u *)&p_dir
11017 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011018 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011019 || p == (char_u *)&p_rtp
11020#ifdef FEAT_SEARCHPATH
11021 || p == (char_u *)&p_cdpath
11022#endif
11023#ifdef FEAT_SESSION
11024 || p == (char_u *)&p_vdir
11025#endif
11026 )
11027 {
11028 xp->xp_context = EXPAND_DIRECTORIES;
11029 if (p == (char_u *)&p_path
11030#ifdef FEAT_SEARCHPATH
11031 || p == (char_u *)&p_cdpath
11032#endif
11033 )
11034 xp->xp_backslash = XP_BS_THREE;
11035 else
11036 xp->xp_backslash = XP_BS_ONE;
11037 }
11038 else
11039 {
11040 xp->xp_context = EXPAND_FILES;
11041 /* for 'tags' need three backslashes for a space */
11042 if (p == (char_u *)&p_tags)
11043 xp->xp_backslash = XP_BS_THREE;
11044 else
11045 xp->xp_backslash = XP_BS_ONE;
11046 }
11047 }
11048
11049 /* For an option that is a list of file names, find the start of the
11050 * last file name. */
11051 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11052 {
11053 /* count number of backslashes before ' ' or ',' */
11054 if (*p == ' ' || *p == ',')
11055 {
11056 s = p;
11057 while (s > xp->xp_pattern && *(s - 1) == '\\')
11058 --s;
11059 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11060 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11061 {
11062 xp->xp_pattern = p + 1;
11063 break;
11064 }
11065 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011066
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011067#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011068 /* for 'spellsuggest' start at "file:" */
11069 if (options[opt_idx].var == (char_u *)&p_sps
11070 && STRNCMP(p, "file:", 5) == 0)
11071 {
11072 xp->xp_pattern = p + 5;
11073 break;
11074 }
11075#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076 }
11077
11078 return;
11079}
11080
11081 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011082ExpandSettings(
11083 expand_T *xp,
11084 regmatch_T *regmatch,
11085 int *num_file,
11086 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011087{
11088 int num_normal = 0; /* Nr of matching non-term-code settings */
11089 int num_term = 0; /* Nr of matching terminal code settings */
11090 int opt_idx;
11091 int match;
11092 int count = 0;
11093 char_u *str;
11094 int loop;
11095 int is_term_opt;
11096 char_u name_buf[MAX_KEY_NAME_LEN];
11097 static char *(names[]) = {"all", "termcap"};
11098 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11099
11100 /* do this loop twice:
11101 * loop == 0: count the number of matching options
11102 * loop == 1: copy the matching options into allocated memory
11103 */
11104 for (loop = 0; loop <= 1; ++loop)
11105 {
11106 regmatch->rm_ic = ic;
11107 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11108 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011109 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11110 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011111 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11112 {
11113 if (loop == 0)
11114 num_normal++;
11115 else
11116 (*file)[count++] = vim_strsave((char_u *)names[match]);
11117 }
11118 }
11119 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11120 opt_idx++)
11121 {
11122 if (options[opt_idx].var == NULL)
11123 continue;
11124 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11125 && !(options[opt_idx].flags & P_BOOL))
11126 continue;
11127 is_term_opt = istermoption(&options[opt_idx]);
11128 if (is_term_opt && num_normal > 0)
11129 continue;
11130 match = FALSE;
11131 if (vim_regexec(regmatch, str, (colnr_T)0)
11132 || (options[opt_idx].shortname != NULL
11133 && vim_regexec(regmatch,
11134 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11135 match = TRUE;
11136 else if (is_term_opt)
11137 {
11138 name_buf[0] = '<';
11139 name_buf[1] = 't';
11140 name_buf[2] = '_';
11141 name_buf[3] = str[2];
11142 name_buf[4] = str[3];
11143 name_buf[5] = '>';
11144 name_buf[6] = NUL;
11145 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11146 {
11147 match = TRUE;
11148 str = name_buf;
11149 }
11150 }
11151 if (match)
11152 {
11153 if (loop == 0)
11154 {
11155 if (is_term_opt)
11156 num_term++;
11157 else
11158 num_normal++;
11159 }
11160 else
11161 (*file)[count++] = vim_strsave(str);
11162 }
11163 }
11164 /*
11165 * Check terminal key codes, these are not in the option table
11166 */
11167 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11168 {
11169 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11170 {
11171 if (!isprint(str[0]) || !isprint(str[1]))
11172 continue;
11173
11174 name_buf[0] = 't';
11175 name_buf[1] = '_';
11176 name_buf[2] = str[0];
11177 name_buf[3] = str[1];
11178 name_buf[4] = NUL;
11179
11180 match = FALSE;
11181 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11182 match = TRUE;
11183 else
11184 {
11185 name_buf[0] = '<';
11186 name_buf[1] = 't';
11187 name_buf[2] = '_';
11188 name_buf[3] = str[0];
11189 name_buf[4] = str[1];
11190 name_buf[5] = '>';
11191 name_buf[6] = NUL;
11192
11193 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11194 match = TRUE;
11195 }
11196 if (match)
11197 {
11198 if (loop == 0)
11199 num_term++;
11200 else
11201 (*file)[count++] = vim_strsave(name_buf);
11202 }
11203 }
11204
11205 /*
11206 * Check special key names.
11207 */
11208 regmatch->rm_ic = TRUE; /* ignore case here */
11209 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11210 {
11211 name_buf[0] = '<';
11212 STRCPY(name_buf + 1, str);
11213 STRCAT(name_buf, ">");
11214
11215 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11216 {
11217 if (loop == 0)
11218 num_term++;
11219 else
11220 (*file)[count++] = vim_strsave(name_buf);
11221 }
11222 }
11223 }
11224 if (loop == 0)
11225 {
11226 if (num_normal > 0)
11227 *num_file = num_normal;
11228 else if (num_term > 0)
11229 *num_file = num_term;
11230 else
11231 return OK;
11232 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11233 if (*file == NULL)
11234 {
11235 *file = (char_u **)"";
11236 return FAIL;
11237 }
11238 }
11239 }
11240 return OK;
11241}
11242
11243 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011244ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245{
11246 char_u *var = NULL; /* init for GCC */
11247 char_u *buf;
11248
11249 *num_file = 0;
11250 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11251 if (*file == NULL)
11252 return FAIL;
11253
11254 /*
11255 * For a terminal key code expand_option_idx is < 0.
11256 */
11257 if (expand_option_idx < 0)
11258 {
11259 var = find_termcode(expand_option_name + 2);
11260 if (var == NULL)
11261 expand_option_idx = findoption(expand_option_name);
11262 }
11263
11264 if (expand_option_idx >= 0)
11265 {
11266 /* put string of option value in NameBuff */
11267 option_value2string(&options[expand_option_idx], expand_option_flags);
11268 var = NameBuff;
11269 }
11270 else if (var == NULL)
11271 var = (char_u *)"";
11272
11273 /* A backslash is required before some characters. This is the reverse of
11274 * what happens in do_set(). */
11275 buf = vim_strsave_escaped(var, escape_chars);
11276
11277 if (buf == NULL)
11278 {
11279 vim_free(*file);
11280 *file = NULL;
11281 return FAIL;
11282 }
11283
11284#ifdef BACKSLASH_IN_FILENAME
11285 /* For MS-Windows et al. we don't double backslashes at the start and
11286 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011287 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011288 if (var[0] == '\\' && var[1] == '\\'
11289 && expand_option_idx >= 0
11290 && (options[expand_option_idx].flags & P_EXPAND)
11291 && vim_isfilec(var[2])
11292 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011293 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011294#endif
11295
11296 *file[0] = buf;
11297 *num_file = 1;
11298 return OK;
11299}
11300#endif
11301
11302/*
11303 * Get the value for the numeric or string option *opp in a nice format into
11304 * NameBuff[]. Must not be called with a hidden option!
11305 */
11306 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011307option_value2string(
11308 struct vimoption *opp,
11309 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310{
11311 char_u *varp;
11312
11313 varp = get_varp_scope(opp, opt_flags);
11314
11315 if (opp->flags & P_NUM)
11316 {
11317 long wc = 0;
11318
11319 if (wc_use_keyname(varp, &wc))
11320 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11321 else if (wc != 0)
11322 STRCPY(NameBuff, transchar((int)wc));
11323 else
11324 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11325 }
11326 else /* P_STRING */
11327 {
11328 varp = *(char_u **)(varp);
11329 if (varp == NULL) /* just in case */
11330 NameBuff[0] = NUL;
11331#ifdef FEAT_CRYPT
11332 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011333 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011334 STRCPY(NameBuff, "*****");
11335#endif
11336 else if (opp->flags & P_EXPAND)
11337 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11338 /* Translate 'pastetoggle' into special key names */
11339 else if ((char_u **)opp->var == &p_pt)
11340 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11341 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011342 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011343 }
11344}
11345
11346/*
11347 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11348 * printed as a keyname.
11349 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11350 */
11351 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011352wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353{
11354 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11355 {
11356 *wcp = *(long *)varp;
11357 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11358 return TRUE;
11359 }
11360 return FALSE;
11361}
11362
Bram Moolenaar01615492015-02-03 13:00:38 +010011363#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011365 * Any character has an equivalent 'langmap' character. This is used for
11366 * keyboards that have a special language mode that sends characters above
11367 * 128 (although other characters can be translated too). The "to" field is a
11368 * Vim command character. This avoids having to switch the keyboard back to
11369 * ASCII mode when leaving Insert mode.
11370 *
11371 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11372 * commands.
11373 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11374 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11375 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011377# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011378/*
11379 * With multi-byte support use growarray for 'langmap' chars >= 256
11380 */
11381typedef struct
11382{
11383 int from;
11384 int to;
11385} langmap_entry_T;
11386
11387static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011388static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389
11390/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011391 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11392 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011393 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011394 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011395langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011396{
11397 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011398 int a = 0;
11399 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011400
11401 /* Do a binary search for an existing entry. */
11402 while (a != b)
11403 {
11404 int i = (a + b) / 2;
11405 int d = entries[i].from - from;
11406
11407 if (d == 0)
11408 {
11409 entries[i].to = to;
11410 return;
11411 }
11412 if (d < 0)
11413 a = i + 1;
11414 else
11415 b = i;
11416 }
11417
11418 if (ga_grow(&langmap_mapga, 1) != OK)
11419 return; /* out of memory */
11420
11421 /* insert new entry at position "a" */
11422 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11423 mch_memmove(entries + 1, entries,
11424 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11425 ++langmap_mapga.ga_len;
11426 entries[0].from = from;
11427 entries[0].to = to;
11428}
11429
11430/*
11431 * Apply 'langmap' to multi-byte character "c" and return the result.
11432 */
11433 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011434langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011435{
11436 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11437 int a = 0;
11438 int b = langmap_mapga.ga_len;
11439
11440 while (a != b)
11441 {
11442 int i = (a + b) / 2;
11443 int d = entries[i].from - c;
11444
11445 if (d == 0)
11446 return entries[i].to; /* found matching entry */
11447 if (d < 0)
11448 a = i + 1;
11449 else
11450 b = i;
11451 }
11452 return c; /* no entry found, return "c" unmodified */
11453}
11454# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011455
11456 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011457langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011458{
11459 int i;
11460
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011461 for (i = 0; i < 256; i++)
11462 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11463# ifdef FEAT_MBYTE
11464 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11465# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011466}
11467
11468/*
11469 * Called when langmap option is set; the language map can be
11470 * changed at any time!
11471 */
11472 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011473langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011474{
11475 char_u *p;
11476 char_u *p2;
11477 int from, to;
11478
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011479#ifdef FEAT_MBYTE
11480 ga_clear(&langmap_mapga); /* clear the previous map first */
11481#endif
11482 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011483
11484 for (p = p_langmap; p[0] != NUL; )
11485 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011486 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11487 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488 {
11489 if (p2[0] == '\\' && p2[1] != NUL)
11490 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491 }
11492 if (p2[0] == ';')
11493 ++p2; /* abcd;ABCD form, p2 points to A */
11494 else
11495 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11496 while (p[0])
11497 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011498 if (p[0] == ',')
11499 {
11500 ++p;
11501 break;
11502 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011503 if (p[0] == '\\' && p[1] != NUL)
11504 ++p;
11505#ifdef FEAT_MBYTE
11506 from = (*mb_ptr2char)(p);
11507#else
11508 from = p[0];
11509#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011510 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011511 if (p2 == NULL)
11512 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011513 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011514 if (p[0] != ',')
11515 {
11516 if (p[0] == '\\')
11517 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011518#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011519 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011520#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011521 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011522#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011523 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524 }
11525 else
11526 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011527 if (p2[0] != ',')
11528 {
11529 if (p2[0] == '\\')
11530 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011532 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011534 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011536 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011537 }
11538 if (to == NUL)
11539 {
11540 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11541 transchar(from));
11542 return;
11543 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011544
11545#ifdef FEAT_MBYTE
11546 if (from >= 256)
11547 langmap_set_entry(from, to);
11548 else
11549#endif
11550 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011551
11552 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011553 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011554 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011556 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557 if (*p == ';')
11558 {
11559 p = p2;
11560 if (p[0] != NUL)
11561 {
11562 if (p[0] != ',')
11563 {
11564 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11565 return;
11566 }
11567 ++p;
11568 }
11569 break;
11570 }
11571 }
11572 }
11573 }
11574}
11575#endif
11576
11577/*
11578 * Return TRUE if format option 'x' is in effect.
11579 * Take care of no formatting when 'paste' is set.
11580 */
11581 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011582has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011583{
11584 if (p_paste)
11585 return FALSE;
11586 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11587}
11588
11589/*
11590 * Return TRUE if "x" is present in 'shortmess' option, or
11591 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11592 */
11593 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011594shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011595{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011596 return p_shm != NULL &&
11597 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011598 || (vim_strchr(p_shm, 'a') != NULL
11599 && vim_strchr((char_u *)SHM_A, x) != NULL));
11600}
11601
11602/*
11603 * paste_option_changed() - Called after p_paste was set or reset.
11604 */
11605 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011606paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011607{
11608 static int old_p_paste = FALSE;
11609 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011610 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011611#ifdef FEAT_CMDL_INFO
11612 static int save_ru = 0;
11613#endif
11614#ifdef FEAT_RIGHTLEFT
11615 static int save_ri = 0;
11616 static int save_hkmap = 0;
11617#endif
11618 buf_T *buf;
11619
11620 if (p_paste)
11621 {
11622 /*
11623 * Paste switched from off to on.
11624 * Save the current values, so they can be restored later.
11625 */
11626 if (!old_p_paste)
11627 {
11628 /* save options for each buffer */
11629 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11630 {
11631 buf->b_p_tw_nopaste = buf->b_p_tw;
11632 buf->b_p_wm_nopaste = buf->b_p_wm;
11633 buf->b_p_sts_nopaste = buf->b_p_sts;
11634 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011635 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011636 }
11637
11638 /* save global options */
11639 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011640 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011641#ifdef FEAT_CMDL_INFO
11642 save_ru = p_ru;
11643#endif
11644#ifdef FEAT_RIGHTLEFT
11645 save_ri = p_ri;
11646 save_hkmap = p_hkmap;
11647#endif
11648 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011649 p_ai_nopaste = p_ai;
11650 p_et_nopaste = p_et;
11651 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011652 p_tw_nopaste = p_tw;
11653 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011654 }
11655
11656 /*
11657 * Always set the option values, also when 'paste' is set when it is
11658 * already on.
11659 */
11660 /* set options for each buffer */
11661 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11662 {
11663 buf->b_p_tw = 0; /* textwidth is 0 */
11664 buf->b_p_wm = 0; /* wrapmargin is 0 */
11665 buf->b_p_sts = 0; /* softtabstop is 0 */
11666 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011667 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011668 }
11669
11670 /* set global options */
11671 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011672 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673#ifdef FEAT_CMDL_INFO
11674# ifdef FEAT_WINDOWS
11675 if (p_ru)
11676 status_redraw_all(); /* redraw to remove the ruler */
11677# endif
11678 p_ru = 0; /* no ruler */
11679#endif
11680#ifdef FEAT_RIGHTLEFT
11681 p_ri = 0; /* no reverse insert */
11682 p_hkmap = 0; /* no Hebrew keyboard */
11683#endif
11684 /* set global values for local buffer options */
11685 p_tw = 0;
11686 p_wm = 0;
11687 p_sts = 0;
11688 p_ai = 0;
11689 }
11690
11691 /*
11692 * Paste switched from on to off: Restore saved values.
11693 */
11694 else if (old_p_paste)
11695 {
11696 /* restore options for each buffer */
11697 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11698 {
11699 buf->b_p_tw = buf->b_p_tw_nopaste;
11700 buf->b_p_wm = buf->b_p_wm_nopaste;
11701 buf->b_p_sts = buf->b_p_sts_nopaste;
11702 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011703 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011704 }
11705
11706 /* restore global options */
11707 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011708 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011709#ifdef FEAT_CMDL_INFO
11710# ifdef FEAT_WINDOWS
11711 if (p_ru != save_ru)
11712 status_redraw_all(); /* redraw to draw the ruler */
11713# endif
11714 p_ru = save_ru;
11715#endif
11716#ifdef FEAT_RIGHTLEFT
11717 p_ri = save_ri;
11718 p_hkmap = save_hkmap;
11719#endif
11720 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011721 p_ai = p_ai_nopaste;
11722 p_et = p_et_nopaste;
11723 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011724 p_tw = p_tw_nopaste;
11725 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011726 }
11727
11728 old_p_paste = p_paste;
11729}
11730
11731/*
11732 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11733 *
11734 * Reset 'compatible' and set the values for options that didn't get set yet
11735 * to the Vim defaults.
11736 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011737 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011738 */
11739 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011740vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011742 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011743 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011744 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011745
11746 if (!option_was_set((char_u *)"cp"))
11747 {
11748 p_cp = FALSE;
11749 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11750 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11751 set_option_default(opt_idx, OPT_FREE, FALSE);
11752 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011753 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011754 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011755
11756 if (fname != NULL)
11757 {
11758 p = vim_getenv(envname, &dofree);
11759 if (p == NULL)
11760 {
11761 /* Set $MYVIMRC to the first vimrc file found. */
11762 p = FullName_save(fname, FALSE);
11763 if (p != NULL)
11764 {
11765 vim_setenv(envname, p);
11766 vim_free(p);
11767 }
11768 }
11769 else if (dofree)
11770 vim_free(p);
11771 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011772}
11773
11774/*
11775 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11776 */
11777 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011778change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011779{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011780 int opt_idx;
11781
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782 if (p_cp != on)
11783 {
11784 p_cp = on;
11785 compatible_set();
11786 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011787 opt_idx = findoption((char_u *)"cp");
11788 if (opt_idx >= 0)
11789 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011790}
11791
11792/*
11793 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011794 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011795 */
11796 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011797option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011798{
11799 int idx;
11800
11801 idx = findoption(name);
11802 if (idx < 0) /* unknown option */
11803 return FALSE;
11804 if (options[idx].flags & P_WAS_SET)
11805 return TRUE;
11806 return FALSE;
11807}
11808
11809/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011810 * Reset the flag indicating option "name" was set.
11811 */
11812 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011813reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011814{
11815 int idx = findoption(name);
11816
11817 if (idx >= 0)
11818 options[idx].flags &= ~P_WAS_SET;
11819}
11820
11821/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011822 * compatible_set() - Called when 'compatible' has been set or unset.
11823 *
11824 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11825 * flag) to a Vi compatible value.
11826 * When 'compatible' is unset: Set all options that have a different default
11827 * for Vim (without the P_VI_DEF flag) to that default.
11828 */
11829 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011830compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831{
11832 int opt_idx;
11833
11834 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11835 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11836 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11837 set_option_default(opt_idx, OPT_FREE, p_cp);
11838 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011839 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840}
11841
11842#ifdef FEAT_LINEBREAK
11843
11844# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11845 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011846 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011847# endif
11848
11849/*
11850 * fill_breakat_flags() -- called when 'breakat' changes value.
11851 */
11852 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011853fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011854{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011855 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856 int i;
11857
11858 for (i = 0; i < 256; i++)
11859 breakat_flags[i] = FALSE;
11860
11861 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011862 for (p = p_breakat; *p; p++)
11863 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011864}
11865
11866# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011867 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868# endif
11869
11870#endif
11871
11872/*
11873 * Check an option that can be a range of string values.
11874 *
11875 * Return OK for correct value, FAIL otherwise.
11876 * Empty is always OK.
11877 */
11878 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011879check_opt_strings(
11880 char_u *val,
11881 char **values,
11882 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883{
11884 return opt_strings_flags(val, values, NULL, list);
11885}
11886
11887/*
11888 * Handle an option that can be a range of string values.
11889 * Set a flag in "*flagp" for each string present.
11890 *
11891 * Return OK for correct value, FAIL otherwise.
11892 * Empty is always OK.
11893 */
11894 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011895opt_strings_flags(
11896 char_u *val, /* new value */
11897 char **values, /* array of valid string values */
11898 unsigned *flagp,
11899 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900{
11901 int i;
11902 int len;
11903 unsigned new_flags = 0;
11904
11905 while (*val)
11906 {
11907 for (i = 0; ; ++i)
11908 {
11909 if (values[i] == NULL) /* val not found in values[] */
11910 return FAIL;
11911
11912 len = (int)STRLEN(values[i]);
11913 if (STRNCMP(values[i], val, len) == 0
11914 && ((list && val[len] == ',') || val[len] == NUL))
11915 {
11916 val += len + (val[len] == ',');
11917 new_flags |= (1 << i);
11918 break; /* check next item in val list */
11919 }
11920 }
11921 }
11922 if (flagp != NULL)
11923 *flagp = new_flags;
11924
11925 return OK;
11926}
11927
11928/*
11929 * Read the 'wildmode' option, fill wim_flags[].
11930 */
11931 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011932check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933{
11934 char_u new_wim_flags[4];
11935 char_u *p;
11936 int i;
11937 int idx = 0;
11938
11939 for (i = 0; i < 4; ++i)
11940 new_wim_flags[i] = 0;
11941
11942 for (p = p_wim; *p; ++p)
11943 {
11944 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11945 ;
11946 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11947 return FAIL;
11948 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11949 new_wim_flags[idx] |= WIM_LONGEST;
11950 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11951 new_wim_flags[idx] |= WIM_FULL;
11952 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11953 new_wim_flags[idx] |= WIM_LIST;
11954 else
11955 return FAIL;
11956 p += i;
11957 if (*p == NUL)
11958 break;
11959 if (*p == ',')
11960 {
11961 if (idx == 3)
11962 return FAIL;
11963 ++idx;
11964 }
11965 }
11966
11967 /* fill remaining entries with last flag */
11968 while (idx < 3)
11969 {
11970 new_wim_flags[idx + 1] = new_wim_flags[idx];
11971 ++idx;
11972 }
11973
11974 /* only when there are no errors, wim_flags[] is changed */
11975 for (i = 0; i < 4; ++i)
11976 wim_flags[i] = new_wim_flags[i];
11977 return OK;
11978}
11979
11980/*
11981 * Check if backspacing over something is allowed.
11982 */
11983 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011984can_bs(
11985 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011986{
11987 switch (*p_bs)
11988 {
11989 case '2': return TRUE;
11990 case '1': return (what != BS_START);
11991 case '0': return FALSE;
11992 }
11993 return vim_strchr(p_bs, what) != NULL;
11994}
11995
11996/*
11997 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11998 * the file must be considered changed when the value is different.
11999 */
12000 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012001save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002{
12003 buf->b_start_ffc = *buf->b_p_ff;
12004 buf->b_start_eol = buf->b_p_eol;
12005#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012006 buf->b_start_bomb = buf->b_p_bomb;
12007
Bram Moolenaar071d4272004-06-13 20:20:40 +000012008 /* Only use free/alloc when necessary, they take time. */
12009 if (buf->b_start_fenc == NULL
12010 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12011 {
12012 vim_free(buf->b_start_fenc);
12013 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12014 }
12015#endif
12016}
12017
12018/*
12019 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12020 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012021 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12022 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012023 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012024 * When "ignore_empty" is true don't consider a new, empty buffer to be
12025 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012026 */
12027 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012028file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012030 /* In a buffer that was never loaded the options are not valid. */
12031 if (buf->b_flags & BF_NEVERLOADED)
12032 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012033 if (ignore_empty
12034 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012035 && buf->b_ml.ml_line_count == 1
12036 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12037 return FALSE;
12038 if (buf->b_start_ffc != *buf->b_p_ff)
12039 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012040 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012041 return TRUE;
12042#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012043 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12044 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045 if (buf->b_start_fenc == NULL)
12046 return (*buf->b_p_fenc != NUL);
12047 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12048#else
12049 return FALSE;
12050#endif
12051}
12052
12053/*
12054 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12055 */
12056 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012057check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012058{
12059 return check_opt_strings(p, p_ff_values, FALSE);
12060}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012061
12062/*
12063 * Return the effective shiftwidth value for current buffer, using the
12064 * 'tabstop' value when 'shiftwidth' is zero.
12065 */
12066 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012067get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012068{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012069 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012070}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012071
12072/*
12073 * Return the effective softtabstop value for the current buffer, using the
12074 * 'tabstop' value when 'softtabstop' is negative.
12075 */
12076 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012077get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012078{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012079 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012080}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012081
12082/*
12083 * Check matchpairs option for "*initc".
12084 * If there is a match set "*initc" to the matching character and "*findc" to
12085 * the opposite character. Set "*backwards" to the direction.
12086 * When "switchit" is TRUE swap the direction.
12087 */
12088 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012089find_mps_values(
12090 int *initc,
12091 int *findc,
12092 int *backwards,
12093 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012094{
12095 char_u *ptr;
12096
12097 ptr = curbuf->b_p_mps;
12098 while (*ptr != NUL)
12099 {
12100#ifdef FEAT_MBYTE
12101 if (has_mbyte)
12102 {
12103 char_u *prev;
12104
12105 if (mb_ptr2char(ptr) == *initc)
12106 {
12107 if (switchit)
12108 {
12109 *findc = *initc;
12110 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12111 *backwards = TRUE;
12112 }
12113 else
12114 {
12115 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12116 *backwards = FALSE;
12117 }
12118 return;
12119 }
12120 prev = ptr;
12121 ptr += mb_ptr2len(ptr) + 1;
12122 if (mb_ptr2char(ptr) == *initc)
12123 {
12124 if (switchit)
12125 {
12126 *findc = *initc;
12127 *initc = mb_ptr2char(prev);
12128 *backwards = FALSE;
12129 }
12130 else
12131 {
12132 *findc = mb_ptr2char(prev);
12133 *backwards = TRUE;
12134 }
12135 return;
12136 }
12137 ptr += mb_ptr2len(ptr);
12138 }
12139 else
12140#endif
12141 {
12142 if (*ptr == *initc)
12143 {
12144 if (switchit)
12145 {
12146 *backwards = TRUE;
12147 *findc = *initc;
12148 *initc = ptr[2];
12149 }
12150 else
12151 {
12152 *backwards = FALSE;
12153 *findc = ptr[2];
12154 }
12155 return;
12156 }
12157 ptr += 2;
12158 if (*ptr == *initc)
12159 {
12160 if (switchit)
12161 {
12162 *backwards = FALSE;
12163 *findc = *initc;
12164 *initc = ptr[-2];
12165 }
12166 else
12167 {
12168 *backwards = TRUE;
12169 *findc = ptr[-2];
12170 }
12171 return;
12172 }
12173 ++ptr;
12174 }
12175 if (*ptr == ',')
12176 ++ptr;
12177 }
12178}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012179
12180#if defined(FEAT_LINEBREAK) || defined(PROTO)
12181/*
12182 * This is called when 'breakindentopt' is changed and when a window is
12183 * initialized.
12184 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012185 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012186briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012187{
12188 char_u *p;
12189 int bri_shift = 0;
12190 long bri_min = 20;
12191 int bri_sbr = FALSE;
12192
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012193 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012194 while (*p != NUL)
12195 {
12196 if (STRNCMP(p, "shift:", 6) == 0
12197 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12198 {
12199 p += 6;
12200 bri_shift = getdigits(&p);
12201 }
12202 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12203 {
12204 p += 4;
12205 bri_min = getdigits(&p);
12206 }
12207 else if (STRNCMP(p, "sbr", 3) == 0)
12208 {
12209 p += 3;
12210 bri_sbr = TRUE;
12211 }
12212 if (*p != ',' && *p != NUL)
12213 return FAIL;
12214 if (*p == ',')
12215 ++p;
12216 }
12217
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012218 wp->w_p_brishift = bri_shift;
12219 wp->w_p_brimin = bri_min;
12220 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012221
12222 return OK;
12223}
12224#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012225
12226/*
12227 * Get the local or global value of 'backupcopy'.
12228 */
12229 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012230get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012231{
12232 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12233}