blob: 616f9a30397455c9e5adba4d65af20ec99648de6 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000110#ifdef FEAT_EVAL
111# define PV_FEX OPT_BUF(BV_FEX)
112#endif
113#define PV_FF OPT_BUF(BV_FF)
114#define PV_FLP OPT_BUF(BV_FLP)
115#define PV_FO OPT_BUF(BV_FO)
116#ifdef FEAT_AUTOCMD
117# define PV_FT OPT_BUF(BV_FT)
118#endif
119#define PV_IMI OPT_BUF(BV_IMI)
120#define PV_IMS OPT_BUF(BV_IMS)
121#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
122# define PV_INDE OPT_BUF(BV_INDE)
123# define PV_INDK OPT_BUF(BV_INDK)
124#endif
125#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
126# define PV_INEX OPT_BUF(BV_INEX)
127#endif
128#define PV_INF OPT_BUF(BV_INF)
129#define PV_ISK OPT_BUF(BV_ISK)
130#ifdef FEAT_CRYPT
131# define PV_KEY OPT_BUF(BV_KEY)
132#endif
133#ifdef FEAT_KEYMAP
134# define PV_KMAP OPT_BUF(BV_KMAP)
135#endif
136#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
137#ifdef FEAT_LISP
138# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100139# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000140#endif
141#define PV_MA OPT_BUF(BV_MA)
142#define PV_ML OPT_BUF(BV_ML)
143#define PV_MOD OPT_BUF(BV_MOD)
144#define PV_MPS OPT_BUF(BV_MPS)
145#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100158#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000159#ifdef FEAT_SYN_HL
160# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000161# define PV_SYN OPT_BUF(BV_SYN)
162#endif
163#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164# define PV_SPC OPT_BUF(BV_SPC)
165# define PV_SPF OPT_BUF(BV_SPF)
166# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000167#endif
168#define PV_STS OPT_BUF(BV_STS)
169#ifdef FEAT_SEARCHPATH
170# define PV_SUA OPT_BUF(BV_SUA)
171#endif
172#define PV_SW OPT_BUF(BV_SW)
173#define PV_SWF OPT_BUF(BV_SWF)
174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100175#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200179#ifdef FEAT_PERSISTENT_UNDO
180# define PV_UDF OPT_BUF(BV_UDF)
181#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
221#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
228#ifdef FEAT_SCROLLBIND
229# define PV_SCBIND OPT_WIN(WV_SCBIND)
230#endif
231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_WINDOWS
245# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000246# define PV_WFW OPT_WIN(WV_WFW)
247#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200249#ifdef FEAT_CURSORBIND
250# define PV_CRBIND OPT_WIN(WV_CRBIND)
251#endif
252#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200253# define PV_COCU OPT_WIN(WV_COCU)
254# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200255#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000256
257/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000258typedef enum
259{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000260 PV_NONE = 0,
261 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262} idopt_T;
263
264/*
265 * Options local to a window have a value local to a buffer and global to all
266 * buffers. Indicate this by setting "var" to VAR_WIN.
267 */
268#define VAR_WIN ((char_u *)-1)
269
270/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000271 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000272 * Only to be used in option.c!
273 */
274static int p_ai;
275static int p_bin;
276#ifdef FEAT_MBYTE
277static int p_bomb;
278#endif
279#if defined(FEAT_QUICKFIX)
280static char_u *p_bh;
281static char_u *p_bt;
282#endif
283static int p_bl;
284static int p_ci;
285#ifdef FEAT_CINDENT
286static int p_cin;
287static char_u *p_cink;
288static char_u *p_cino;
289#endif
290#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
291static char_u *p_cinw;
292#endif
293#ifdef FEAT_COMMENTS
294static char_u *p_com;
295#endif
296#ifdef FEAT_FOLDING
297static char_u *p_cms;
298#endif
299#ifdef FEAT_INS_EXPAND
300static char_u *p_cpt;
301#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000302#ifdef FEAT_COMPL_FUNC
303static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000304static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200307static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_et;
309#ifdef FEAT_MBYTE
310static char_u *p_fenc;
311#endif
312static char_u *p_ff;
313static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000314static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315#ifdef FEAT_AUTOCMD
316static char_u *p_ft;
317#endif
318static long p_iminsert;
319static long p_imsearch;
320#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
321static char_u *p_inex;
322#endif
323#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
324static char_u *p_inde;
325static char_u *p_indk;
326#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000327#if defined(FEAT_EVAL)
328static char_u *p_fex;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330static int p_inf;
331static char_u *p_isk;
332#ifdef FEAT_CRYPT
333static char_u *p_key;
334#endif
335#ifdef FEAT_LISP
336static int p_lisp;
337#endif
338static int p_ml;
339static int p_ma;
340static int p_mod;
341static char_u *p_mps;
342static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static long p_sts;
353#if defined(FEAT_SEARCHPATH)
354static char_u *p_sua;
355#endif
356static long p_sw;
357static int p_swf;
358#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000359static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000361#endif
362#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000363static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000364static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000365static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366#endif
367static long p_ts;
368static long p_tw;
369static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200370#ifdef FEAT_PERSISTENT_UNDO
371static int p_udf;
372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373static long p_wm;
374#ifdef FEAT_KEYMAP
375static char_u *p_keymap;
376#endif
377
378/* Saved values for when 'bin' is set. */
379static int p_et_nobin;
380static int p_ml_nobin;
381static long p_tw_nobin;
382static long p_wm_nobin;
383
384/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200385static int p_ai_nopaste;
386static int p_et_nopaste;
387static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388static long p_tw_nopaste;
389static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390
391struct vimoption
392{
393 char *fullname; /* full option name */
394 char *shortname; /* permissible abbreviation */
395 long_u flags; /* see below */
396 char_u *var; /* global option: pointer to variable;
397 * window-local option: VAR_WIN;
398 * buffer-local option: global value */
399 idopt_T indir; /* global option: PV_NONE;
400 * local option: indirect option index */
401 char_u *def_val[2]; /* default values for variable (vi and vim) */
402#ifdef FEAT_EVAL
403 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000404# define SCRIPTID_INIT , 0
405#else
406# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000407#endif
408};
409
410#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
411#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
412
413/*
414 * Flags
415 */
416#define P_BOOL 0x01 /* the option is boolean */
417#define P_NUM 0x02 /* the option is numeric */
418#define P_STRING 0x04 /* the option is a string */
419#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000420 must use free_string_option() when
421 assigning new value. Not set if default is
422 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000423#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
424 never be used for local or hidden options! */
425#define P_NODEFAULT 0x40 /* don't set to default value */
426#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
427 use vim_free() when assigning new value */
428#define P_WAS_SET 0x100 /* option has been set/reset */
429#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
430#define P_VI_DEF 0x400 /* Use Vi default for Vim */
431#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
432
433 /* when option changed, what to display: */
434#define P_RSTAT 0x1000 /* redraw status lines */
435#define P_RWIN 0x2000 /* redraw current window */
436#define P_RBUF 0x4000 /* redraw current buffer */
437#define P_RALL 0x6000 /* redraw all windows */
438#define P_RCLR 0x7000 /* clear and redraw all */
439
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200440#define P_COMMA 0x8000 /* comma separated list */
441#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
442 * commas */
443#define P_NODUP 0x20000L /* don't allow duplicate strings */
444#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200446#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
447#define P_GETTEXT 0x100000L /* expand default value with _() */
448#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
449#define P_NFNAME 0x400000L /* only normal file name chars allowed */
450#define P_INSECURE 0x800000L /* option was set from a modeline */
451#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000452 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_NO_ML 0x2000000L /* not allowed in modeline */
454#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200455 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000457#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
458
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000459/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
460 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100461#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000462# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000463#else
464# define ISP_LATIN1 (char_u *)"@,161-255"
465#endif
466
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100467/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000468#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100469 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200470 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100471# 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 +0000472#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100473# 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 +0000474#endif
475
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476/*
477 * options[] is initialized here.
478 * The order of the options MUST be alphabetic for ":set all" and findoption().
479 * All option names MUST start with a lowercase letter (for findoption()).
480 * Exception: "t_" options are at the end.
481 * The options with a NULL variable are 'hidden': a set command for them is
482 * ignored and they are not printed.
483 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100484static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000485{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200486 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000487#ifdef FEAT_RIGHTLEFT
488 (char_u *)&p_aleph, PV_NONE,
489#else
490 (char_u *)NULL, PV_NONE,
491#endif
492 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100493#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494 (char_u *)128L,
495#else
496 (char_u *)224L,
497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
500#if defined(FEAT_GUI) && defined(MACOS_X)
501 (char_u *)&p_antialias, PV_NONE,
502 {(char_u *)FALSE, (char_u *)FALSE}
503#else
504 (char_u *)NULL, PV_NONE,
505 {(char_u *)FALSE, (char_u *)FALSE}
506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000507 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200508 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509#ifdef FEAT_ARABIC
510 (char_u *)VAR_WIN, PV_ARAB,
511#else
512 (char_u *)NULL, PV_NONE,
513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
516#ifdef FEAT_ARABIC
517 (char_u *)&p_arshape, PV_NONE,
518#else
519 (char_u *)NULL, PV_NONE,
520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000521 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
523#ifdef FEAT_RIGHTLEFT
524 (char_u *)&p_ari, PV_NONE,
525#else
526 (char_u *)NULL, PV_NONE,
527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000528 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
530#ifdef FEAT_FKMAP
531 (char_u *)&p_altkeymap, PV_NONE,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
537#if defined(FEAT_MBYTE)
538 (char_u *)&p_ambw, PV_NONE,
539 {(char_u *)"single", (char_u *)0L}
540#else
541 (char_u *)NULL, PV_NONE,
542 {(char_u *)0L, (char_u *)0L}
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000545#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"autochdir", "acd", P_BOOL|P_VI_DEF,
547 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549#endif
550 {"autoindent", "ai", P_BOOL|P_VI_DEF,
551 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autoprint", "ap", P_BOOL|P_VI_DEF,
554 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000557 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autowrite", "aw", P_BOOL|P_VI_DEF,
560 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autowriteall","awa", P_BOOL|P_VI_DEF,
563 (char_u *)&p_awa, 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 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
566 (char_u *)&p_bg, PV_NONE,
567 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100568#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 (char_u *)"dark",
570#else
571 (char_u *)"light",
572#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200574 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
578 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200580 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200581 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582#ifdef UNIX
583 {(char_u *)"yes", (char_u *)"auto"}
584#else
585 {(char_u *)"auto", (char_u *)"auto"}
586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200588 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
589 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000591 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000592 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)&p_bex, PV_NONE,
594 {
595#ifdef VMS
596 (char_u *)"_",
597#else
598 (char_u *)"~",
599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200601 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602#ifdef FEAT_WILDIGN
603 (char_u *)&p_bsk, PV_NONE,
604 {(char_u *)"", (char_u *)0L}
605#else
606 (char_u *)NULL, PV_NONE,
607 {(char_u *)0L, (char_u *)0L}
608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000609 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610#ifdef FEAT_BEVAL
611 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
612 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
615 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000617# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000618 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000619 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000621# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622#endif
623 {"beautify", "bf", P_BOOL|P_VI_DEF,
624 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200626 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
627 (char_u *)&p_bo, PV_NONE,
628 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
630 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
636#ifdef FEAT_MBYTE
637 (char_u *)&p_bomb, PV_BOMB,
638#else
639 (char_u *)NULL, PV_NONE,
640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000641 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
643#ifdef FEAT_LINEBREAK
644 (char_u *)&p_breakat, PV_NONE,
645 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
646#else
647 (char_u *)NULL, PV_NONE,
648 {(char_u *)0L, (char_u *)0L}
649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000650 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200651 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
652#ifdef FEAT_LINEBREAK
653 (char_u *)VAR_WIN, PV_BRI,
654 {(char_u *)FALSE, (char_u *)0L}
655#else
656 (char_u *)NULL, PV_NONE,
657 {(char_u *)0L, (char_u *)0L}
658#endif
659 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200660 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
661 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200662#ifdef FEAT_LINEBREAK
663 (char_u *)VAR_WIN, PV_BRIOPT,
664 {(char_u *)"", (char_u *)NULL}
665#else
666 (char_u *)NULL, PV_NONE,
667 {(char_u *)"", (char_u *)NULL}
668#endif
669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
671#ifdef FEAT_BROWSE
672 (char_u *)&p_bsdir, PV_NONE,
673 {(char_u *)"last", (char_u *)0L}
674#else
675 (char_u *)NULL, PV_NONE,
676 {(char_u *)0L, (char_u *)0L}
677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000679 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
680#if defined(FEAT_QUICKFIX)
681 (char_u *)&p_bh, PV_BH,
682 {(char_u *)"", (char_u *)0L}
683#else
684 (char_u *)NULL, PV_NONE,
685 {(char_u *)0L, (char_u *)0L}
686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000687 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000688 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
689 (char_u *)&p_bl, PV_BL,
690 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000691 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
693#if defined(FEAT_QUICKFIX)
694 (char_u *)&p_bt, PV_BT,
695 {(char_u *)"", (char_u *)0L}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)0L, (char_u *)0L}
699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000700 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200701 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000702#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 (char_u *)&p_cmp, PV_NONE,
704 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
711#ifdef FEAT_SEARCHPATH
712 (char_u *)&p_cdpath, PV_NONE,
713 {(char_u *)",,", (char_u *)0L}
714#else
715 (char_u *)NULL, PV_NONE,
716 {(char_u *)0L, (char_u *)0L}
717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"cedit", NULL, P_STRING,
720#ifdef FEAT_CMDWIN
721 (char_u *)&p_cedit, PV_NONE,
722 {(char_u *)"", (char_u *)CTRL_F_STR}
723#else
724 (char_u *)NULL, PV_NONE,
725 {(char_u *)0L, (char_u *)0L}
726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000727 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
729#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
730 (char_u *)&p_ccv, PV_NONE,
731 {(char_u *)"", (char_u *)0L}
732#else
733 (char_u *)NULL, PV_NONE,
734 {(char_u *)0L, (char_u *)0L}
735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000736 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000737 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
738#ifdef FEAT_CINDENT
739 (char_u *)&p_cin, PV_CIN,
740#else
741 (char_u *)NULL, PV_NONE,
742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000743 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200744 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745#ifdef FEAT_CINDENT
746 (char_u *)&p_cink, PV_CINK,
747 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
748#else
749 (char_u *)NULL, PV_NONE,
750 {(char_u *)0L, (char_u *)0L}
751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000752 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200753 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754#ifdef FEAT_CINDENT
755 (char_u *)&p_cino, PV_CINO,
756#else
757 (char_u *)NULL, PV_NONE,
758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000759 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200760 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
762 (char_u *)&p_cinw, PV_CINW,
763 {(char_u *)"if,else,while,do,for,switch",
764 (char_u *)0L}
765#else
766 (char_u *)NULL, PV_NONE,
767 {(char_u *)0L, (char_u *)0L}
768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000769 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200770 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#ifdef FEAT_CLIPBOARD
772 (char_u *)&p_cb, PV_NONE,
773# ifdef FEAT_XCLIPBOARD
774 {(char_u *)"autoselect,exclude:cons\\|linux",
775 (char_u *)0L}
776# else
777 {(char_u *)"", (char_u *)0L}
778# endif
779#else
780 (char_u *)NULL, PV_NONE,
781 {(char_u *)"", (char_u *)0L}
782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000783 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
785 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
788#ifdef FEAT_CMDWIN
789 (char_u *)&p_cwh, PV_NONE,
790#else
791 (char_u *)NULL, PV_NONE,
792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000793 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200794 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200795#ifdef FEAT_SYN_HL
796 (char_u *)VAR_WIN, PV_CC,
797#else
798 (char_u *)NULL, PV_NONE,
799#endif
800 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
802 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000803 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200804 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
805 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806#ifdef FEAT_COMMENTS
807 (char_u *)&p_com, PV_COM,
808 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
809 (char_u *)0L}
810#else
811 (char_u *)NULL, PV_NONE,
812 {(char_u *)0L, (char_u *)0L}
813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200815 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816#ifdef FEAT_FOLDING
817 (char_u *)&p_cms, PV_CMS,
818 {(char_u *)"/*%s*/", (char_u *)0L}
819#else
820 (char_u *)NULL, PV_NONE,
821 {(char_u *)0L, (char_u *)0L}
822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000823 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000824 /* P_PRI_MKRC isn't needed here, optval_default()
825 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000826 {"compatible", "cp", P_BOOL|P_RALL,
827 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000828 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200829 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830#ifdef FEAT_INS_EXPAND
831 (char_u *)&p_cpt, PV_CPT,
832 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
833#else
834 (char_u *)NULL, PV_NONE,
835 {(char_u *)0L, (char_u *)0L}
836#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000837 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200838 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200839#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200840 (char_u *)VAR_WIN, PV_COCU,
841 {(char_u *)"", (char_u *)NULL}
842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)NULL, (char_u *)0L}
845#endif
846 SCRIPTID_INIT},
847 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
848#ifdef FEAT_CONCEAL
849 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200850#else
851 (char_u *)NULL, PV_NONE,
852#endif
853 {(char_u *)0L, (char_u *)0L}
854 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000855 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
856#ifdef FEAT_COMPL_FUNC
857 (char_u *)&p_cfu, PV_CFU,
858 {(char_u *)"", (char_u *)0L}
859#else
860 (char_u *)NULL, PV_NONE,
861 {(char_u *)0L, (char_u *)0L}
862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000863 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200864 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000865#ifdef FEAT_INS_EXPAND
866 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000867 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000868#else
869 (char_u *)NULL, PV_NONE,
870 {(char_u *)0L, (char_u *)0L}
871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000872 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000873 {"confirm", "cf", P_BOOL|P_VI_DEF,
874#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
875 (char_u *)&p_confirm, PV_NONE,
876#else
877 (char_u *)NULL, PV_NONE,
878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000880 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000881 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
884 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
887 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000888 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
889 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200890 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200891#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200892 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200893 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200894#else
895 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200896 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200897#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200898 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
900#ifdef FEAT_CSCOPE
901 (char_u *)&p_cspc, PV_NONE,
902#else
903 (char_u *)NULL, PV_NONE,
904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
907#ifdef FEAT_CSCOPE
908 (char_u *)&p_csprg, PV_NONE,
909 {(char_u *)"cscope", (char_u *)0L}
910#else
911 (char_u *)NULL, PV_NONE,
912 {(char_u *)0L, (char_u *)0L}
913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200915 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
917 (char_u *)&p_csqf, PV_NONE,
918 {(char_u *)"", (char_u *)0L}
919#else
920 (char_u *)NULL, PV_NONE,
921 {(char_u *)0L, (char_u *)0L}
922#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000923 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200924 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
925#ifdef FEAT_CSCOPE
926 (char_u *)&p_csre, PV_NONE,
927#else
928 (char_u *)NULL, PV_NONE,
929#endif
930 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_cst, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csto, PV_NONE,
941#else
942 (char_u *)NULL, PV_NONE,
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csverbose, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200952 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
953#ifdef FEAT_CURSORBIND
954 (char_u *)VAR_WIN, PV_CRBIND,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
958 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000959 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
960#ifdef FEAT_SYN_HL
961 (char_u *)VAR_WIN, PV_CUC,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000966 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
967#ifdef FEAT_SYN_HL
968 (char_u *)VAR_WIN, PV_CUL,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000973 {"debug", NULL, P_STRING|P_VI_DEF,
974 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200976 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000978 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000979 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980#else
981 (char_u *)NULL, PV_NONE,
982 {(char_u *)NULL, (char_u *)0L}
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
986#ifdef FEAT_MBYTE
987 (char_u *)&p_deco, PV_NONE,
988#else
989 (char_u *)NULL, PV_NONE,
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200992 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000994 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#else
996 (char_u *)NULL, PV_NONE,
997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1000#ifdef FEAT_DIFF
1001 (char_u *)VAR_WIN, PV_DIFF,
1002#else
1003 (char_u *)NULL, PV_NONE,
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001006 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1008 (char_u *)&p_dex, PV_NONE,
1009 {(char_u *)"", (char_u *)0L}
1010#else
1011 (char_u *)NULL, PV_NONE,
1012 {(char_u *)0L, (char_u *)0L}
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001015 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1016 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017#ifdef FEAT_DIFF
1018 (char_u *)&p_dip, PV_NONE,
1019 {(char_u *)"filler", (char_u *)NULL}
1020#else
1021 (char_u *)NULL, PV_NONE,
1022 {(char_u *)"", (char_u *)NULL}
1023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1026#ifdef FEAT_DIGRAPHS
1027 (char_u *)&p_dg, PV_NONE,
1028#else
1029 (char_u *)NULL, PV_NONE,
1030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001031 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001032 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1033 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001036 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001040#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041 (char_u *)&p_ead, PV_NONE,
1042 {(char_u *)"both", (char_u *)0L}
1043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)NULL, (char_u *)0L}
1046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1049 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001051 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1052#if defined(FEAT_MBYTE)
1053 (char_u *)&p_emoji, PV_NONE,
1054 {(char_u *)TRUE, (char_u *)0L}
1055#else
1056 (char_u *)NULL, PV_NONE,
1057 {(char_u *)0L, (char_u *)0L}
1058#endif
1059 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001060 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061#ifdef FEAT_MBYTE
1062 (char_u *)&p_enc, PV_NONE,
1063 {(char_u *)ENC_DFLT, (char_u *)0L}
1064#else
1065 (char_u *)NULL, PV_NONE,
1066 {(char_u *)0L, (char_u *)0L}
1067#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1070 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1073 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001076 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1079 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1082#ifdef FEAT_QUICKFIX
1083 (char_u *)&p_ef, PV_NONE,
1084 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1085#else
1086 (char_u *)NULL, PV_NONE,
1087 {(char_u *)NULL, (char_u *)0L}
1088#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001090 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001092 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094#else
1095 (char_u *)NULL, PV_NONE,
1096 {(char_u *)NULL, (char_u *)0L}
1097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001098 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"esckeys", "ek", P_BOOL|P_VIM,
1100 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001102 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103#ifdef FEAT_AUTOCMD
1104 (char_u *)&p_ei, PV_NONE,
1105#else
1106 (char_u *)NULL, PV_NONE,
1107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1110 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1113 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1116 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117#ifdef FEAT_MBYTE
1118 (char_u *)&p_fenc, PV_FENC,
1119 {(char_u *)"", (char_u *)0L}
1120#else
1121 (char_u *)NULL, PV_NONE,
1122 {(char_u *)0L, (char_u *)0L}
1123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001125 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#ifdef FEAT_MBYTE
1127 (char_u *)&p_fencs, PV_NONE,
1128 {(char_u *)"ucs-bom", (char_u *)0L}
1129#else
1130 (char_u *)NULL, PV_NONE,
1131 {(char_u *)0L, (char_u *)0L}
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1135 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001137 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001138 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1141 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001142 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1143 (char_u *)&p_fic, PV_NONE,
1144 {
1145#ifdef CASE_INSENSITIVE_FILENAME
1146 (char_u *)TRUE,
1147#else
1148 (char_u *)FALSE,
1149#endif
1150 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001151 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152#ifdef FEAT_AUTOCMD
1153 (char_u *)&p_ft, PV_FT,
1154 {(char_u *)"", (char_u *)0L}
1155#else
1156 (char_u *)NULL, PV_NONE,
1157 {(char_u *)0L, (char_u *)0L}
1158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001159 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001160 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1162 (char_u *)&p_fcs, PV_NONE,
1163 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1164#else
1165 (char_u *)NULL, PV_NONE,
1166 {(char_u *)"", (char_u *)0L}
1167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001169 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1170 (char_u *)&p_fixeol, PV_FIXEOL,
1171 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1173#ifdef FEAT_FKMAP
1174 (char_u *)&p_fkmap, PV_NONE,
1175#else
1176 (char_u *)NULL, PV_NONE,
1177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 {"flash", "fl", P_BOOL|P_VI_DEF,
1180 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001183 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1187 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1190 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1193# ifdef FEAT_EVAL
1194 (char_u *)VAR_WIN, PV_FDE,
1195 {(char_u *)"0", (char_u *)NULL}
1196# else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)NULL, (char_u *)0L}
1199# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1202 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1205 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001207 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001211 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)"{{{,}}}", (char_u *)NULL}
1214 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1216 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1219 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001224 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 (char_u *)&p_fdo, PV_NONE,
1226 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1229# ifdef FEAT_EVAL
1230 (char_u *)VAR_WIN, PV_FDT,
1231 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001232# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 (char_u *)NULL, PV_NONE,
1234 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001235# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001238 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001239#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001240 (char_u *)&p_fex, PV_FEX,
1241 {(char_u *)"", (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)0L, (char_u *)0L}
1245#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1248 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1250 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001251 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1252 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001253 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1254 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1256 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001257 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001258 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1259#ifdef HAVE_FSYNC
1260 (char_u *)&p_fs, PV_NONE,
1261 {(char_u *)TRUE, (char_u *)0L}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)FALSE, (char_u *)0L}
1265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1268 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 {"graphic", "gr", P_BOOL|P_VI_DEF,
1271 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001273 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001274#ifdef FEAT_QUICKFIX
1275 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001276 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277#else
1278 (char_u *)NULL, PV_NONE,
1279 {(char_u *)NULL, (char_u *)0L}
1280#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1283#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001284 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285 {
1286# ifdef WIN3264
1287 /* may be changed to "grep -n" in os_win32.c */
1288 (char_u *)"findstr /n",
1289# else
1290# ifdef UNIX
1291 /* Add an extra file name so that grep will always
1292 * insert a file name in the match line. */
1293 (char_u *)"grep -n $* /dev/null",
1294# else
1295# ifdef VMS
1296 (char_u *)"SEARCH/NUMBERS ",
1297# else
1298 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001299# endif
1300# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001302 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303#else
1304 (char_u *)NULL, PV_NONE,
1305 {(char_u *)NULL, (char_u *)0L}
1306#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001307 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001308 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#ifdef CURSOR_SHAPE
1310 (char_u *)&p_guicursor, PV_NONE,
1311 {
1312# ifdef FEAT_GUI
1313 (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 +01001314# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1316# endif
1317 (char_u *)0L}
1318#else
1319 (char_u *)NULL, PV_NONE,
1320 {(char_u *)NULL, (char_u *)0L}
1321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001322 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001323 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324#ifdef FEAT_GUI
1325 (char_u *)&p_guifont, PV_NONE,
1326 {(char_u *)"", (char_u *)0L}
1327#else
1328 (char_u *)NULL, PV_NONE,
1329 {(char_u *)NULL, (char_u *)0L}
1330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001332 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1334 (char_u *)&p_guifontset, PV_NONE,
1335 {(char_u *)"", (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)NULL, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001341 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1343 (char_u *)&p_guifontwide, PV_NONE,
1344 {(char_u *)"", (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)NULL, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001351#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352 (char_u *)&p_ghr, PV_NONE,
1353#else
1354 (char_u *)NULL, PV_NONE,
1355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001356 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001358#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 (char_u *)&p_go, PV_NONE,
1360# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001361 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001363 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364# endif
1365#else
1366 (char_u *)NULL, PV_NONE,
1367 {(char_u *)NULL, (char_u *)0L}
1368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001369 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370 {"guipty", NULL, P_BOOL|P_VI_DEF,
1371#if defined(FEAT_GUI)
1372 (char_u *)&p_guipty, PV_NONE,
1373#else
1374 (char_u *)NULL, PV_NONE,
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001377 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001378#if defined(FEAT_GUI_TABLINE)
1379 (char_u *)&p_gtl, PV_NONE,
1380 {(char_u *)"", (char_u *)0L}
1381#else
1382 (char_u *)NULL, PV_NONE,
1383 {(char_u *)NULL, (char_u *)0L}
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001386 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001387#if defined(FEAT_GUI_TABLINE)
1388 (char_u *)&p_gtt, PV_NONE,
1389 {(char_u *)"", (char_u *)0L}
1390#else
1391 (char_u *)NULL, PV_NONE,
1392 {(char_u *)NULL, (char_u *)0L}
1393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1396 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1399 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1401 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402 {"helpheight", "hh", P_NUM|P_VI_DEF,
1403#ifdef FEAT_WINDOWS
1404 (char_u *)&p_hh, PV_NONE,
1405#else
1406 (char_u *)NULL, PV_NONE,
1407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001409 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410#ifdef FEAT_MULTI_LANG
1411 (char_u *)&p_hlg, PV_NONE,
1412 {(char_u *)"", (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)0L, (char_u *)0L}
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 {"hidden", "hid", P_BOOL|P_VI_DEF,
1419 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001420 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001421 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001422 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1424 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 {"history", "hi", P_NUM|P_VIM,
1426 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001427 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1429#ifdef FEAT_RIGHTLEFT
1430 (char_u *)&p_hkmap, PV_NONE,
1431#else
1432 (char_u *)NULL, PV_NONE,
1433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1436#ifdef FEAT_RIGHTLEFT
1437 (char_u *)&p_hkmapp, PV_NONE,
1438#else
1439 (char_u *)NULL, PV_NONE,
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1443 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"icon", NULL, P_BOOL|P_VI_DEF,
1446#ifdef FEAT_TITLE
1447 (char_u *)&p_icon, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"iconstring", NULL, P_STRING|P_VI_DEF,
1453#ifdef FEAT_TITLE
1454 (char_u *)&p_iconstring, PV_NONE,
1455#else
1456 (char_u *)NULL, PV_NONE,
1457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1460 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001462 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1463# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1464 (char_u *)&p_imaf, PV_NONE,
1465 {(char_u *)"", (char_u *)NULL}
1466# else
1467 (char_u *)NULL, PV_NONE,
1468 {(char_u *)NULL, (char_u *)0L}
1469# endif
1470 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001472#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 (char_u *)&p_imak, PV_NONE,
1474#else
1475 (char_u *)NULL, PV_NONE,
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1479#ifdef USE_IM_CONTROL
1480 (char_u *)&p_imcmdline, PV_NONE,
1481#else
1482 (char_u *)NULL, PV_NONE,
1483#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001484 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1486#ifdef USE_IM_CONTROL
1487 (char_u *)&p_imdisable, PV_NONE,
1488#else
1489 (char_u *)NULL, PV_NONE,
1490#endif
1491#ifdef __sgi
1492 {(char_u *)TRUE, (char_u *)0L}
1493#else
1494 {(char_u *)FALSE, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"iminsert", "imi", P_NUM|P_VI_DEF,
1498 (char_u *)&p_iminsert, PV_IMI,
1499#ifdef B_IMODE_IM
1500 {(char_u *)B_IMODE_IM, (char_u *)0L}
1501#else
1502 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"imsearch", "ims", P_NUM|P_VI_DEF,
1506 (char_u *)&p_imsearch, PV_IMS,
1507#ifdef B_IMODE_IM
1508 {(char_u *)B_IMODE_IM, (char_u *)0L}
1509#else
1510 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001512 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001513 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001514# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1515 (char_u *)&p_imsf, PV_NONE,
1516 {(char_u *)"", (char_u *)NULL}
1517# else
1518 (char_u *)NULL, PV_NONE,
1519 {(char_u *)NULL, (char_u *)0L}
1520# endif
1521 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1523#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001524 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1526#else
1527 (char_u *)NULL, PV_NONE,
1528 {(char_u *)0L, (char_u *)0L}
1529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1532#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1533 (char_u *)&p_inex, PV_INEX,
1534 {(char_u *)"", (char_u *)0L}
1535#else
1536 (char_u *)NULL, PV_NONE,
1537 {(char_u *)0L, (char_u *)0L}
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1541 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1544#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1545 (char_u *)&p_inde, PV_INDE,
1546 {(char_u *)"", (char_u *)0L}
1547#else
1548 (char_u *)NULL, PV_NONE,
1549 {(char_u *)0L, (char_u *)0L}
1550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001551 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001552 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1554 (char_u *)&p_indk, PV_INDK,
1555 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1556#else
1557 (char_u *)NULL, PV_NONE,
1558 {(char_u *)0L, (char_u *)0L}
1559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001560 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"infercase", "inf", P_BOOL|P_VI_DEF,
1562 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1565 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1568 (char_u *)&p_isf, PV_NONE,
1569 {
1570#ifdef BACKSLASH_IN_FILENAME
1571 /* Excluded are: & and ^ are special in cmd.exe
1572 * ( and ) are used in text separating fnames */
1573 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1574#else
1575# ifdef AMIGA
1576 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1577# else
1578# ifdef VMS
1579 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1580# else /* UNIX et al. */
1581# ifdef EBCDIC
1582 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1583# else
1584 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1585# endif
1586# endif
1587# endif
1588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001589 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1591 (char_u *)&p_isi, PV_NONE,
1592 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001593#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 (char_u *)"@,48-57,_,128-167,224-235",
1595#else
1596# ifdef EBCDIC
1597 /* TODO: EBCDIC Check this! @ == isalpha()*/
1598 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1599 "112-120,128,140-142,156,158,172,"
1600 "174,186,191,203-207,219-225,235-239,"
1601 "251-254",
1602# else
1603 (char_u *)"@,48-57,_,192-255",
1604# endif
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1608 (char_u *)&p_isk, PV_ISK,
1609 {
1610#ifdef EBCDIC
1611 (char_u *)"@,240-249,_",
1612 /* TODO: EBCDIC Check this! @ == isalpha()*/
1613 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1614 "112-120,128,140-142,156,158,172,"
1615 "174,186,191,203-207,219-225,235-239,"
1616 "251-254",
1617#else
1618 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001619# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 (char_u *)"@,48-57,_,128-167,224-235"
1621# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001622 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623# endif
1624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1627 (char_u *)&p_isp, PV_NONE,
1628 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001629#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 || defined(VMS)
1631 (char_u *)"@,~-255",
1632#else
1633# ifdef EBCDIC
1634 /* all chars above 63 are printable */
1635 (char_u *)"63-255",
1636# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001637 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638# endif
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1642 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1645#ifdef FEAT_CRYPT
1646 (char_u *)&p_key, PV_KEY,
1647 {(char_u *)"", (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)0L, (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001653 {"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 +00001654#ifdef FEAT_KEYMAP
1655 (char_u *)&p_keymap, PV_KMAP,
1656 {(char_u *)"", (char_u *)0L}
1657#else
1658 (char_u *)NULL, PV_NONE,
1659 {(char_u *)"", (char_u *)0L}
1660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001662 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001666 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001668#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669 (char_u *)":help",
1670#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001671# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001673# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001674# ifdef USEMAN_S
1675 (char_u *)"man -s",
1676# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001678# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679# endif
1680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001681 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001682 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683#ifdef FEAT_LANGMAP
1684 (char_u *)&p_langmap, PV_NONE,
1685 {(char_u *)"", /* unmatched } */
1686#else
1687 (char_u *)NULL, PV_NONE,
1688 {(char_u *)NULL,
1689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001690 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001691 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1693 (char_u *)&p_lm, PV_NONE,
1694#else
1695 (char_u *)NULL, PV_NONE,
1696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001697 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001698 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1699#ifdef FEAT_LANGMAP
1700 (char_u *)&p_lnr, PV_NONE,
1701#else
1702 (char_u *)NULL, PV_NONE,
1703#endif
1704 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1706#ifdef FEAT_WINDOWS
1707 (char_u *)&p_ls, PV_NONE,
1708#else
1709 (char_u *)NULL, PV_NONE,
1710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001711 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1713 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1716#ifdef FEAT_LINEBREAK
1717 (char_u *)VAR_WIN, PV_LBR,
1718#else
1719 (char_u *)NULL, PV_NONE,
1720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1723 (char_u *)&Rows, PV_NONE,
1724 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001725#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 (char_u *)25L,
1727#else
1728 (char_u *)24L,
1729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1732#ifdef FEAT_GUI
1733 (char_u *)&p_linespace, PV_NONE,
1734#else
1735 (char_u *)NULL, PV_NONE,
1736#endif
1737#ifdef FEAT_GUI_W32
1738 {(char_u *)1L, (char_u *)0L}
1739#else
1740 {(char_u *)0L, (char_u *)0L}
1741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001742 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 {"lisp", NULL, P_BOOL|P_VI_DEF,
1744#ifdef FEAT_LISP
1745 (char_u *)&p_lisp, PV_LISP,
1746#else
1747 (char_u *)NULL, PV_NONE,
1748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001750 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001752 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1754#else
1755 (char_u *)NULL, PV_NONE,
1756 {(char_u *)"", (char_u *)0L}
1757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001758 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1760 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001761 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001762 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001764 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1766 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001768#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001769 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1770 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001771 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1772 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001773#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001774#ifdef FEAT_GUI_MAC
1775 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1776 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 {"magic", NULL, P_BOOL|P_VI_DEF,
1780 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001781 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001782 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783#ifdef FEAT_QUICKFIX
1784 (char_u *)&p_mef, PV_NONE,
1785 {(char_u *)"", (char_u *)0L}
1786#else
1787 (char_u *)NULL, PV_NONE,
1788 {(char_u *)NULL, (char_u *)0L}
1789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1792#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001793 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794# ifdef VMS
1795 {(char_u *)"MMS", (char_u *)0L}
1796# else
1797 {(char_u *)"make", (char_u *)0L}
1798# endif
1799#else
1800 (char_u *)NULL, PV_NONE,
1801 {(char_u *)NULL, (char_u *)0L}
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001804 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001806 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1807 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"matchtime", "mat", P_NUM|P_VI_DEF,
1809 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001811 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001812#ifdef FEAT_MBYTE
1813 (char_u *)&p_mco, PV_NONE,
1814#else
1815 (char_u *)NULL, PV_NONE,
1816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1819#ifdef FEAT_EVAL
1820 (char_u *)&p_mfd, PV_NONE,
1821#else
1822 (char_u *)NULL, PV_NONE,
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1826 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"maxmem", "mm", P_NUM|P_VI_DEF,
1829 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1831 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001832 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1838 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"menuitems", "mis", P_NUM|P_VI_DEF,
1840#ifdef FEAT_MENU
1841 (char_u *)&p_mis, PV_NONE,
1842#else
1843 (char_u *)NULL, PV_NONE,
1844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"mesg", NULL, P_BOOL|P_VI_DEF,
1847 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001849 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001850#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001851 (char_u *)&p_msm, PV_NONE,
1852 {(char_u *)"460000,2000,500", (char_u *)0L}
1853#else
1854 (char_u *)NULL, PV_NONE,
1855 {(char_u *)0L, (char_u *)0L}
1856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001857 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {"modeline", "ml", P_BOOL|P_VIM,
1859 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"modelines", "mls", P_NUM|P_VI_DEF,
1862 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1865 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1868 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"more", NULL, P_BOOL|P_VIM,
1871 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1874 (char_u *)&p_mouse, PV_NONE,
1875 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001876#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 (char_u *)"a",
1878#else
1879 (char_u *)"",
1880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1883#ifdef FEAT_GUI
1884 (char_u *)&p_mousef, PV_NONE,
1885#else
1886 (char_u *)NULL, PV_NONE,
1887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1890#ifdef FEAT_GUI
1891 (char_u *)&p_mh, PV_NONE,
1892#else
1893 (char_u *)NULL, PV_NONE,
1894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1897 (char_u *)&p_mousem, PV_NONE,
1898 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001899#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 (char_u *)"popup",
1901#else
1902# if defined(MACOS)
1903 (char_u *)"popup_setpos",
1904# else
1905 (char_u *)"extend",
1906# endif
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001909 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910#ifdef FEAT_MOUSESHAPE
1911 (char_u *)&p_mouseshape, PV_NONE,
1912 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1913#else
1914 (char_u *)NULL, PV_NONE,
1915 {(char_u *)NULL, (char_u *)0L}
1916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1919 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001921 {"mzquantum", "mzq", P_NUM,
1922#ifdef FEAT_MZSCHEME
1923 (char_u *)&p_mzq, PV_NONE,
1924#else
1925 (char_u *)NULL, PV_NONE,
1926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"novice", NULL, P_BOOL|P_VI_DEF,
1929 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001931 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001933 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1936 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001938 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1939#ifdef FEAT_LINEBREAK
1940 (char_u *)VAR_WIN, PV_NUW,
1941#else
1942 (char_u *)NULL, PV_NONE,
1943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001945 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001946#ifdef FEAT_COMPL_FUNC
1947 (char_u *)&p_ofu, PV_OFU,
1948 {(char_u *)"", (char_u *)0L}
1949#else
1950 (char_u *)NULL, PV_NONE,
1951 {(char_u *)0L, (char_u *)0L}
1952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"open", NULL, P_BOOL|P_VI_DEF,
1955 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001957 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001958#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001959 (char_u *)&p_odev, PV_NONE,
1960#else
1961 (char_u *)NULL, PV_NONE,
1962#endif
1963 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001965 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1966 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"optimize", "opt", P_BOOL|P_VI_DEF,
1969 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001973 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001974 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1975 |P_SECURE,
1976 (char_u *)&p_pp, PV_NONE,
1977 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
1978 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"paragraphs", "para", P_STRING|P_VI_DEF,
1980 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001981 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001983 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1987 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1990#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1991 (char_u *)&p_pex, PV_NONE,
1992 {(char_u *)"", (char_u *)0L}
1993#else
1994 (char_u *)NULL, PV_NONE,
1995 {(char_u *)0L, (char_u *)0L}
1996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001998 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002002 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002004#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002005 (char_u *)".,,",
2006#else
2007# if defined(__EMX__)
2008 (char_u *)".,/emx/include,,",
2009# else /* Unix, probably */
2010 (char_u *)".,/usr/include,,",
2011# endif
2012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002013 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002014#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002015 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2016 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002017 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2018 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2021 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002023 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2025 (char_u *)&p_pvh, PV_NONE,
2026#else
2027 (char_u *)NULL, PV_NONE,
2028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2031#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2032 (char_u *)VAR_WIN, PV_PVW,
2033#else
2034 (char_u *)NULL, PV_NONE,
2035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002037 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038#ifdef FEAT_PRINTER
2039 (char_u *)&p_pdev, PV_NONE,
2040 {(char_u *)"", (char_u *)0L}
2041#else
2042 (char_u *)NULL, PV_NONE,
2043 {(char_u *)NULL, (char_u *)0L}
2044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046 {"printencoding", "penc", P_STRING|P_VI_DEF,
2047#ifdef FEAT_POSTSCRIPT
2048 (char_u *)&p_penc, PV_NONE,
2049 {(char_u *)"", (char_u *)0L}
2050#else
2051 (char_u *)NULL, PV_NONE,
2052 {(char_u *)NULL, (char_u *)0L}
2053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2056#ifdef FEAT_POSTSCRIPT
2057 (char_u *)&p_pexpr, PV_NONE,
2058 {(char_u *)"", (char_u *)0L}
2059#else
2060 (char_u *)NULL, PV_NONE,
2061 {(char_u *)NULL, (char_u *)0L}
2062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"printfont", "pfn", P_STRING|P_VI_DEF,
2065#ifdef FEAT_PRINTER
2066 (char_u *)&p_pfn, PV_NONE,
2067 {
2068# ifdef MSWIN
2069 (char_u *)"Courier_New:h10",
2070# else
2071 (char_u *)"courier",
2072# endif
2073 (char_u *)0L}
2074#else
2075 (char_u *)NULL, PV_NONE,
2076 {(char_u *)NULL, (char_u *)0L}
2077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002078 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2080#ifdef FEAT_PRINTER
2081 (char_u *)&p_header, PV_NONE,
2082 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2083#else
2084 (char_u *)NULL, PV_NONE,
2085 {(char_u *)NULL, (char_u *)0L}
2086#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002087 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002088 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2089#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2090 (char_u *)&p_pmcs, PV_NONE,
2091 {(char_u *)"", (char_u *)0L}
2092#else
2093 (char_u *)NULL, PV_NONE,
2094 {(char_u *)NULL, (char_u *)0L}
2095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002097 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2098#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2099 (char_u *)&p_pmfn, PV_NONE,
2100 {(char_u *)"", (char_u *)0L}
2101#else
2102 (char_u *)NULL, PV_NONE,
2103 {(char_u *)NULL, (char_u *)0L}
2104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002106 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107#ifdef FEAT_PRINTER
2108 (char_u *)&p_popt, PV_NONE,
2109 {(char_u *)"", (char_u *)0L}
2110#else
2111 (char_u *)NULL, PV_NONE,
2112 {(char_u *)NULL, (char_u *)0L}
2113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002116 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002118 {"pumheight", "ph", P_NUM|P_VI_DEF,
2119#ifdef FEAT_INS_EXPAND
2120 (char_u *)&p_ph, PV_NONE,
2121#else
2122 (char_u *)NULL, PV_NONE,
2123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002125#if defined(DYNAMIC_PYTHON3)
Bram Moolenaar0796c062015-11-10 19:41:37 +01002126 {"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002127 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002128 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2129 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002130#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002131#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002132 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2133 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002134 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2135 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002137 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2138#ifdef FEAT_TEXTOBJ
2139 (char_u *)&p_qe, PV_QE,
2140 {(char_u *)"\\", (char_u *)0L}
2141#else
2142 (char_u *)NULL, PV_NONE,
2143 {(char_u *)NULL, (char_u *)0L}
2144#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2147 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 {"redraw", NULL, P_BOOL|P_VI_DEF,
2150 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002152 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2153#ifdef FEAT_RELTIME
2154 (char_u *)&p_rdt, PV_NONE,
2155#else
2156 (char_u *)NULL, PV_NONE,
2157#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002158 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002159 {"regexpengine", "re", P_NUM|P_VI_DEF,
2160 (char_u *)&p_re, PV_NONE,
2161 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002162 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2163 (char_u *)VAR_WIN, PV_RNU,
2164 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165 {"remap", NULL, P_BOOL|P_VI_DEF,
2166 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002168 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002169#ifdef FEAT_RENDER_OPTIONS
2170 (char_u *)&p_rop, PV_NONE,
2171 {(char_u *)"", (char_u *)0L}
2172#else
2173 (char_u *)NULL, PV_NONE,
2174 {(char_u *)NULL, (char_u *)0L}
2175#endif
2176 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"report", NULL, P_NUM|P_VI_DEF,
2178 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002179 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2181#ifdef WIN3264
2182 (char_u *)&p_rs, PV_NONE,
2183#else
2184 (char_u *)NULL, PV_NONE,
2185#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2188#ifdef FEAT_RIGHTLEFT
2189 (char_u *)&p_ri, PV_NONE,
2190#else
2191 (char_u *)NULL, PV_NONE,
2192#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2195#ifdef FEAT_RIGHTLEFT
2196 (char_u *)VAR_WIN, PV_RL,
2197#else
2198 (char_u *)NULL, PV_NONE,
2199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002200 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002201 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2202#ifdef FEAT_RIGHTLEFT
2203 (char_u *)VAR_WIN, PV_RLC,
2204 {(char_u *)"search", (char_u *)NULL}
2205#else
2206 (char_u *)NULL, PV_NONE,
2207 {(char_u *)NULL, (char_u *)0L}
2208#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002209 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002210#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002211 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2212 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002213 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2214 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2217#ifdef FEAT_CMDL_INFO
2218 (char_u *)&p_ru, PV_NONE,
2219#else
2220 (char_u *)NULL, PV_NONE,
2221#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2224#ifdef FEAT_STL_OPT
2225 (char_u *)&p_ruf, PV_NONE,
2226#else
2227 (char_u *)NULL, PV_NONE,
2228#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002230 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2231 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2234 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002235 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2236 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2239#ifdef FEAT_SCROLLBIND
2240 (char_u *)VAR_WIN, PV_SCBIND,
2241#else
2242 (char_u *)NULL, PV_NONE,
2243#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002244 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002245 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2246 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002247 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002248 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2249 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002250 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002251 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002252#ifdef FEAT_SCROLLBIND
2253 (char_u *)&p_sbo, PV_NONE,
2254 {(char_u *)"ver,jump", (char_u *)0L}
2255#else
2256 (char_u *)NULL, PV_NONE,
2257 {(char_u *)0L, (char_u *)0L}
2258#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002259 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 {"sections", "sect", P_STRING|P_VI_DEF,
2261 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002262 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2263 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002264 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2265 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002266 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002269 {(char_u *)"inclusive", (char_u *)0L}
2270 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002271 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002274 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275#ifdef FEAT_SESSION
2276 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002277 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 (char_u *)0L}
2279#else
2280 (char_u *)NULL, PV_NONE,
2281 {(char_u *)0L, (char_u *)0L}
2282#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002283 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2285 (char_u *)&p_sh, PV_NONE,
2286 {
2287#ifdef VMS
2288 (char_u *)"-",
2289#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002290# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002292# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294# endif
2295#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002296 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2298 (char_u *)&p_shcf, PV_NONE,
2299 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002300#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 (char_u *)"/c",
2302#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002305 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2307#ifdef FEAT_QUICKFIX
2308 (char_u *)&p_sp, PV_NONE,
2309 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002310#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312#else
2313 (char_u *)">",
2314#endif
2315 (char_u *)0L}
2316#else
2317 (char_u *)NULL, PV_NONE,
2318 {(char_u *)0L, (char_u *)0L}
2319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2322 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2325 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2328#ifdef BACKSLASH_IN_FILENAME
2329 (char_u *)&p_ssl, PV_NONE,
2330#else
2331 (char_u *)NULL, PV_NONE,
2332#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002333 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002334 {"shelltemp", "stmp", P_BOOL,
2335 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"shelltype", "st", P_NUM|P_VI_DEF,
2338#ifdef AMIGA
2339 (char_u *)&p_st, PV_NONE,
2340#else
2341 (char_u *)NULL, PV_NONE,
2342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2345 (char_u *)&p_sxq, PV_NONE,
2346 {
2347#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2348 (char_u *)"\"",
2349#else
2350 (char_u *)"",
2351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002353 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2354 (char_u *)&p_sxe, PV_NONE,
2355 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002356#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002357 (char_u *)"\"&|<>()@^",
2358#else
2359 (char_u *)"",
2360#endif
2361 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2363 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2366 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2369 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)"", (char_u *)"filnxtToO"}
2371 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2376#ifdef FEAT_LINEBREAK
2377 (char_u *)&p_sbr, PV_NONE,
2378#else
2379 (char_u *)NULL, PV_NONE,
2380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"showcmd", "sc", P_BOOL|P_VIM,
2383#ifdef FEAT_CMDL_INFO
2384 (char_u *)&p_sc, PV_NONE,
2385#else
2386 (char_u *)NULL, PV_NONE,
2387#endif
2388 {(char_u *)FALSE,
2389#ifdef UNIX
2390 (char_u *)FALSE
2391#else
2392 (char_u *)TRUE
2393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2396 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002397 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2399 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"showmode", "smd", P_BOOL|P_VIM,
2402 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002404 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2405#ifdef FEAT_WINDOWS
2406 (char_u *)&p_stal, PV_NONE,
2407#else
2408 (char_u *)NULL, PV_NONE,
2409#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2412 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2415 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2418 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2421 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2424#ifdef FEAT_SMARTINDENT
2425 (char_u *)&p_si, PV_SI,
2426#else
2427 (char_u *)NULL, PV_NONE,
2428#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2431 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2434 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2437 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002439 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002440#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002441 (char_u *)VAR_WIN, PV_SPELL,
2442#else
2443 (char_u *)NULL, PV_NONE,
2444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002446 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002447#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002448 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002449 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002450#else
2451 (char_u *)NULL, PV_NONE,
2452 {(char_u *)0L, (char_u *)0L}
2453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002455 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2456 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002457#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002458 (char_u *)&p_spf, PV_SPF,
2459 {(char_u *)"", (char_u *)0L}
2460#else
2461 (char_u *)NULL, PV_NONE,
2462 {(char_u *)0L, (char_u *)0L}
2463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002465 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2466 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002467#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002468 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002469 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002470#else
2471 (char_u *)NULL, PV_NONE,
2472 {(char_u *)0L, (char_u *)0L}
2473#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002474 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002475 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002476#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002477 (char_u *)&p_sps, PV_NONE,
2478 {(char_u *)"best", (char_u *)0L}
2479#else
2480 (char_u *)NULL, PV_NONE,
2481 {(char_u *)0L, (char_u *)0L}
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2485#ifdef FEAT_WINDOWS
2486 (char_u *)&p_sb, PV_NONE,
2487#else
2488 (char_u *)NULL, PV_NONE,
2489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002492#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 (char_u *)&p_spr, PV_NONE,
2494#else
2495 (char_u *)NULL, PV_NONE,
2496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2499 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2502#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002503 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504#else
2505 (char_u *)NULL, PV_NONE,
2506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002508 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 (char_u *)&p_su, PV_NONE,
2510 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002512 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002513#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 (char_u *)&p_sua, PV_SUA,
2515 {(char_u *)"", (char_u *)0L}
2516#else
2517 (char_u *)NULL, PV_NONE,
2518 {(char_u *)0L, (char_u *)0L}
2519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2522 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"swapsync", "sws", P_STRING|P_VI_DEF,
2525 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002527 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002530 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2531#ifdef FEAT_SYN_HL
2532 (char_u *)&p_smc, PV_SMC,
2533 {(char_u *)3000L, (char_u *)0L}
2534#else
2535 (char_u *)NULL, PV_NONE,
2536 {(char_u *)0L, (char_u *)0L}
2537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002539 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540#ifdef FEAT_SYN_HL
2541 (char_u *)&p_syn, PV_SYN,
2542 {(char_u *)"", (char_u *)0L}
2543#else
2544 (char_u *)NULL, PV_NONE,
2545 {(char_u *)0L, (char_u *)0L}
2546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002548 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2549#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002550 (char_u *)&p_tal, PV_NONE,
2551#else
2552 (char_u *)NULL, PV_NONE,
2553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002554 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002555 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2556#ifdef FEAT_WINDOWS
2557 (char_u *)&p_tpm, PV_NONE,
2558#else
2559 (char_u *)NULL, PV_NONE,
2560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2563 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2566 (char_u *)&p_tbs, PV_NONE,
2567#ifdef VMS /* binary searching doesn't appear to work on VMS */
2568 {(char_u *)0L, (char_u *)0L}
2569#else
2570 {(char_u *)TRUE, (char_u *)0L}
2571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002573 {"tagcase", "tc", P_STRING|P_VIM,
2574 (char_u *)&p_tc, PV_TC,
2575 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"taglength", "tl", P_NUM|P_VI_DEF,
2577 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"tagrelative", "tr", P_BOOL|P_VIM,
2580 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002582 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002583 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {
2585#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2586 (char_u *)"./tags,./TAGS,tags,TAGS",
2587#else
2588 (char_u *)"./tags,tags",
2589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2592 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002594#if defined(DYNAMIC_TCL)
2595 {"tcldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2596 (char_u *)&p_tcldll, PV_NONE,
2597 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2598 SCRIPTID_INIT},
2599#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2601 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002602 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2604#ifdef FEAT_ARABIC
2605 (char_u *)&p_tbidi, PV_NONE,
2606#else
2607 (char_u *)NULL, PV_NONE,
2608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2611#ifdef FEAT_MBYTE
2612 (char_u *)&p_tenc, PV_NONE,
2613 {(char_u *)"", (char_u *)0L}
2614#else
2615 (char_u *)NULL, PV_NONE,
2616 {(char_u *)0L, (char_u *)0L}
2617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 {"terse", NULL, P_BOOL|P_VI_DEF,
2620 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"textauto", "ta", P_BOOL|P_VIM,
2623 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2625 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2627 (char_u *)&p_tx, PV_TX,
2628 {
2629#ifdef USE_CRNL
2630 (char_u *)TRUE,
2631#else
2632 (char_u *)FALSE,
2633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002635 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002638 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002640 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641#else
2642 (char_u *)NULL, PV_NONE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2646 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"timeout", "to", P_BOOL|P_VI_DEF,
2649 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2652 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"title", NULL, P_BOOL|P_VI_DEF,
2655#ifdef FEAT_TITLE
2656 (char_u *)&p_title, PV_NONE,
2657#else
2658 (char_u *)NULL, PV_NONE,
2659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"titlelen", NULL, P_NUM|P_VI_DEF,
2662#ifdef FEAT_TITLE
2663 (char_u *)&p_titlelen, PV_NONE,
2664#else
2665 (char_u *)NULL, PV_NONE,
2666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002668 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669#ifdef FEAT_TITLE
2670 (char_u *)&p_titleold, PV_NONE,
2671 {(char_u *)N_("Thanks for flying Vim"),
2672 (char_u *)0L}
2673#else
2674 (char_u *)NULL, PV_NONE,
2675 {(char_u *)0L, (char_u *)0L}
2676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"titlestring", NULL, P_STRING|P_VI_DEF,
2679#ifdef FEAT_TITLE
2680 (char_u *)&p_titlestring, PV_NONE,
2681#else
2682 (char_u *)NULL, PV_NONE,
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002686 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002688 {(char_u *)"icons,tooltips", (char_u *)0L}
2689 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002691#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2693 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695#endif
2696 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2697 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2700 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2703 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2706 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2709#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2710 (char_u *)&p_ttym, PV_NONE,
2711#else
2712 (char_u *)NULL, PV_NONE,
2713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2716 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2719 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002721 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2722 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002723#ifdef FEAT_PERSISTENT_UNDO
2724 (char_u *)&p_udir, PV_NONE,
2725 {(char_u *)".", (char_u *)0L}
2726#else
2727 (char_u *)NULL, PV_NONE,
2728 {(char_u *)0L, (char_u *)0L}
2729#endif
2730 SCRIPTID_INIT},
2731 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2732#ifdef FEAT_PERSISTENT_UNDO
2733 (char_u *)&p_udf, PV_UDF,
2734#else
2735 (char_u *)NULL, PV_NONE,
2736#endif
2737 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002739 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002741#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 (char_u *)1000L,
2743#else
2744 (char_u *)100L,
2745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002747 {"undoreload", "ur", P_NUM|P_VI_DEF,
2748 (char_u *)&p_ur, PV_NONE,
2749 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"updatecount", "uc", P_NUM|P_VI_DEF,
2751 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002752 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"updatetime", "ut", P_NUM|P_VI_DEF,
2754 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"verbose", "vbs", P_NUM|P_VI_DEF,
2757 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002759 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2760 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2763#ifdef FEAT_SESSION
2764 (char_u *)&p_vdir, PV_NONE,
2765 {(char_u *)DFLT_VDIR, (char_u *)0L}
2766#else
2767 (char_u *)NULL, PV_NONE,
2768 {(char_u *)0L, (char_u *)0L}
2769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002771 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772#ifdef FEAT_SESSION
2773 (char_u *)&p_vop, PV_NONE,
2774 {(char_u *)"folds,options,cursor", (char_u *)0L}
2775#else
2776 (char_u *)NULL, PV_NONE,
2777 {(char_u *)0L, (char_u *)0L}
2778#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002779 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002780 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781#ifdef FEAT_VIMINFO
2782 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002783#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002784 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785#else
2786# ifdef AMIGA
2787 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002788 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002790 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791# endif
2792#endif
2793#else
2794 (char_u *)NULL, PV_NONE,
2795 {(char_u *)0L, (char_u *)0L}
2796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002798 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2799 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#ifdef FEAT_VIRTUALEDIT
2801 (char_u *)&p_ve, PV_NONE,
2802 {(char_u *)"", (char_u *)""}
2803#else
2804 (char_u *)NULL, PV_NONE,
2805 {(char_u *)0L, (char_u *)0L}
2806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2809 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"w300", 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 {"w1200", NULL, P_NUM|P_VI_DEF,
2815 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"w9600", NULL, P_NUM|P_VI_DEF,
2818 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"warn", NULL, P_BOOL|P_VI_DEF,
2821 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2824 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002826 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"wildchar", "wc", P_NUM|P_VIM,
2830 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2832 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002833 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002835 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002836 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837#ifdef FEAT_WILDIGN
2838 (char_u *)&p_wig, PV_NONE,
2839#else
2840 (char_u *)NULL, PV_NONE,
2841#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002843 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2844 (char_u *)&p_wic, PV_NONE,
2845 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2847#ifdef FEAT_WILDMENU
2848 (char_u *)&p_wmnu, PV_NONE,
2849#else
2850 (char_u *)NULL, PV_NONE,
2851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002853 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002856 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2857#ifdef FEAT_CMDL_COMPL
2858 (char_u *)&p_wop, PV_NONE,
2859 {(char_u *)"", (char_u *)0L}
2860#else
2861 (char_u *)NULL, PV_NONE,
2862 {(char_u *)NULL, (char_u *)0L}
2863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002864 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2866#ifdef FEAT_WAK
2867 (char_u *)&p_wak, PV_NONE,
2868 {(char_u *)"menu", (char_u *)0L}
2869#else
2870 (char_u *)NULL, PV_NONE,
2871 {(char_u *)NULL, (char_u *)0L}
2872#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002875 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"winheight", "wh", P_NUM|P_VI_DEF,
2878#ifdef FEAT_WINDOWS
2879 (char_u *)&p_wh, PV_NONE,
2880#else
2881 (char_u *)NULL, PV_NONE,
2882#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002885#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 (char_u *)VAR_WIN, PV_WFH,
2887#else
2888 (char_u *)NULL, PV_NONE,
2889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002891 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002892#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002893 (char_u *)VAR_WIN, PV_WFW,
2894#else
2895 (char_u *)NULL, PV_NONE,
2896#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2899#ifdef FEAT_WINDOWS
2900 (char_u *)&p_wmh, PV_NONE,
2901#else
2902 (char_u *)NULL, PV_NONE,
2903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002904 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002906#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 (char_u *)&p_wmw, PV_NONE,
2908#else
2909 (char_u *)NULL, PV_NONE,
2910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002913#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 (char_u *)&p_wiw, PV_NONE,
2915#else
2916 (char_u *)NULL, PV_NONE,
2917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002918 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2920 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2923 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2926 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"write", NULL, P_BOOL|P_VI_DEF,
2929 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002930 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 {"writeany", "wa", P_BOOL|P_VI_DEF,
2932 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002933 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2935 (char_u *)&p_wb, PV_NONE,
2936 {
2937#ifdef FEAT_WRITEBACKUP
2938 (char_u *)TRUE,
2939#else
2940 (char_u *)FALSE,
2941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002942 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 {"writedelay", "wd", P_NUM|P_VI_DEF,
2944 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002945 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946
2947/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002948#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951
2952 p_term("t_AB", T_CAB)
2953 p_term("t_AF", T_CAF)
2954 p_term("t_AL", T_CAL)
2955 p_term("t_al", T_AL)
2956 p_term("t_bc", T_BC)
2957 p_term("t_cd", T_CD)
2958 p_term("t_ce", T_CE)
2959 p_term("t_cl", T_CL)
2960 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002961 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962 p_term("t_Co", T_CCO)
2963 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002964 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002966#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 p_term("t_CV", T_CSV)
2968#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 p_term("t_da", T_DA)
2970 p_term("t_db", T_DB)
2971 p_term("t_DL", T_CDL)
2972 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002973 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 p_term("t_fs", T_FS)
2975 p_term("t_IE", T_CIE)
2976 p_term("t_IS", T_CIS)
2977 p_term("t_ke", T_KE)
2978 p_term("t_ks", T_KS)
2979 p_term("t_le", T_LE)
2980 p_term("t_mb", T_MB)
2981 p_term("t_md", T_MD)
2982 p_term("t_me", T_ME)
2983 p_term("t_mr", T_MR)
2984 p_term("t_ms", T_MS)
2985 p_term("t_nd", T_ND)
2986 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002987 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 p_term("t_RI", T_CRI)
2989 p_term("t_RV", T_CRV)
2990 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002992 p_term("t_Sf", T_CSF)
2993 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02002995 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 p_term("t_te", T_TE)
2998 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02002999 p_term("t_ts", T_TS)
3000 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 p_term("t_ue", T_UE)
3002 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003003 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 p_term("t_vb", T_VB)
3005 p_term("t_ve", T_VE)
3006 p_term("t_vi", T_VI)
3007 p_term("t_vs", T_VS)
3008 p_term("t_WP", T_CWP)
3009 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003010 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_xs", T_XS)
3012 p_term("t_ZH", T_CZH)
3013 p_term("t_ZR", T_CZR)
3014
3015/* terminal key codes are not in here */
3016
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003017 /* end marker */
3018 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019};
3020
3021#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3022
3023#ifdef FEAT_MBYTE
3024static char *(p_ambw_values[]) = {"single", "double", NULL};
3025#endif
3026static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003027static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003029#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003030static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003031#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003032#ifdef FEAT_CMDL_COMPL
3033static char *(p_wop_values[]) = {"tagfile", NULL};
3034#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035#ifdef FEAT_WAK
3036static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3037#endif
3038static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3040static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042#ifdef FEAT_BROWSE
3043static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3044#endif
3045#ifdef FEAT_SCROLLBIND
3046static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3047#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003048static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003049#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3051#endif
3052#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003053# ifdef FEAT_AUTOCMD
3054static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3055# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003057# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3059#endif
3060static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3061#ifdef FEAT_FOLDING
3062static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003063# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003065# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 NULL};
3067static char *(p_fcl_values[]) = {"all", NULL};
3068#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003069#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003070static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003073static void set_option_default(int, int opt_flags, int compatible);
3074static void set_options_default(int opt_flags);
3075static char_u *term_bg_default(void);
3076static void did_set_option(int opt_idx, int opt_flags, int new_value);
3077static char_u *illegal_char(char_u *, int);
3078static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003080static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081#endif
3082#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003083static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003085static char_u *option_expand(int opt_idx, char_u *val);
3086static void didset_options(void);
3087static void didset_options2(void);
3088static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003089#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003090static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003091#else
3092# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3093#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003094static void set_string_option_global(int opt_idx, char_u **varp);
3095static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3096static 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);
3097static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003098#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003099static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003102static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003104#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003105static char_u *did_set_spell_option(int is_spellfile);
3106static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003108#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003109static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003110#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003111static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3112static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3113static void check_redraw(long_u flags);
3114static int findoption(char_u *);
3115static int find_key_option(char_u *);
3116static void showoptions(int all, int opt_flags);
3117static int optval_default(struct vimoption *, char_u *varp);
3118static void showoneopt(struct vimoption *, int opt_flags);
3119static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3120static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3121static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3122static int istermoption(struct vimoption *);
3123static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3124static char_u *get_varp(struct vimoption *);
3125static void option_value2string(struct vimoption *, int opt_flags);
3126static void check_winopt(winopt_T *wop);
3127static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003129static void langmap_init(void);
3130static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003132static void paste_option_changed(void);
3133static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003135static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003137static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3138static int check_opt_strings(char_u *val, char **values, int);
3139static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003140#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003141static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143
3144/*
3145 * Initialize the options, first part.
3146 *
3147 * Called only once from main(), just after creating the first buffer.
3148 */
3149 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003150set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151{
3152 char_u *p;
3153 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003154 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155
3156#ifdef FEAT_LANGMAP
3157 langmap_init();
3158#endif
3159
3160 /* Be Vi compatible by default */
3161 p_cp = TRUE;
3162
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003163 /* Use POSIX compatibility when $VIM_POSIX is set. */
3164 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003165 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003166 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003167 set_string_default("shm", (char_u *)"A");
3168 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003169
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 /*
3171 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003172 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003174 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003175#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003177 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003179 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003181 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182# endif
3183#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003184 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 set_string_default("sh", p);
3186
3187#ifdef FEAT_WILDIGN
3188 /*
3189 * Set the default for 'backupskip' to include environment variables for
3190 * temp files.
3191 */
3192 {
3193# ifdef UNIX
3194 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3195# else
3196 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3197# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003198 int len;
3199 garray_T ga;
3200 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201
3202 ga_init2(&ga, 1, 100);
3203 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3204 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003205 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206# ifdef UNIX
3207 if (*names[n] == NUL)
3208 p = (char_u *)"/tmp";
3209 else
3210# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003211 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 if (p != NULL && *p != NUL)
3213 {
3214 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003215 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 if (ga_grow(&ga, len) == OK)
3217 {
3218 if (ga.ga_len > 0)
3219 STRCAT(ga.ga_data, ",");
3220 STRCAT(ga.ga_data, p);
3221 add_pathsep(ga.ga_data);
3222 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 ga.ga_len += len;
3224 }
3225 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003226 if (mustfree)
3227 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 }
3229 if (ga.ga_data != NULL)
3230 {
3231 set_string_default("bsk", ga.ga_data);
3232 vim_free(ga.ga_data);
3233 }
3234 }
3235#endif
3236
3237 /*
3238 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3239 */
3240 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003241 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003243#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3244 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3245#endif
3246 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003248 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003249 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250#else
3251# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003252 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003253 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003255 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256# endif
3257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 opt_idx = findoption((char_u *)"maxmem");
3260 if (opt_idx >= 0)
3261 {
3262#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003263 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3264 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003265#endif
3266 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3267 }
3268 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269 }
3270
3271#ifdef FEAT_GUI_W32
3272 /* force 'shortname' for Win32s */
3273 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003274 {
3275 opt_idx = findoption((char_u *)"shortname");
3276 if (opt_idx >= 0)
3277 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3278 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279#endif
3280
3281#ifdef FEAT_SEARCHPATH
3282 {
3283 char_u *cdpath;
3284 char_u *buf;
3285 int i;
3286 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003287 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288
3289 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003290 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291 if (cdpath != NULL)
3292 {
3293 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3294 if (buf != NULL)
3295 {
3296 buf[0] = ','; /* start with ",", current dir first */
3297 j = 1;
3298 for (i = 0; cdpath[i] != NUL; ++i)
3299 {
3300 if (vim_ispathlistsep(cdpath[i]))
3301 buf[j++] = ',';
3302 else
3303 {
3304 if (cdpath[i] == ' ' || cdpath[i] == ',')
3305 buf[j++] = '\\';
3306 buf[j++] = cdpath[i];
3307 }
3308 }
3309 buf[j] = NUL;
3310 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003311 if (opt_idx >= 0)
3312 {
3313 options[opt_idx].def_val[VI_DEFAULT] = buf;
3314 options[opt_idx].flags |= P_DEF_ALLOCED;
3315 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003316 else
3317 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003319 if (mustfree)
3320 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321 }
3322 }
3323#endif
3324
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003325#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326 /* Set print encoding on platforms that don't default to latin1 */
3327 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003328# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329 (char_u *)"cp1252"
3330# else
3331# ifdef VMS
3332 (char_u *)"dec-mcs"
3333# else
3334# ifdef EBCDIC
3335 (char_u *)"ebcdic-uk"
3336# else
3337# ifdef MAC
3338 (char_u *)"mac-roman"
3339# else /* HPUX */
3340 (char_u *)"hp-roman8"
3341# endif
3342# endif
3343# endif
3344# endif
3345 );
3346#endif
3347
3348#ifdef FEAT_POSTSCRIPT
3349 /* 'printexpr' must be allocated to be able to evaluate it. */
3350 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003351# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003352 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353# else
3354# ifdef VMS
3355 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3356
3357# else
3358 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3359# endif
3360# endif
3361 );
3362#endif
3363
3364 /*
3365 * Set all the options (except the terminal options) to their default
3366 * value. Also set the global value for local options.
3367 */
3368 set_options_default(0);
3369
3370#ifdef FEAT_GUI
3371 if (found_reverse_arg)
3372 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3373#endif
3374
3375 curbuf->b_p_initialized = TRUE;
3376 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003377 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 check_buf_options(curbuf);
3379 check_win_options(curwin);
3380 check_options();
3381
3382 /* Must be before option_expand(), because that one needs vim_isIDc() */
3383 didset_options();
3384
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003385#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003386 /* Use the current chartab for the generic chartab. This is not in
3387 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003388 init_spell_chartab();
3389#endif
3390
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391 /*
3392 * Expand environment variables and things like "~" for the defaults.
3393 * If option_expand() returns non-NULL the variable is expanded. This can
3394 * only happen for non-indirect options.
3395 * Also set the default to the expanded value, so ":set" does not list
3396 * them.
3397 * Don't set the P_ALLOCED flag, because we don't want to free the
3398 * default.
3399 */
3400 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3401 {
3402 if ((options[opt_idx].flags & P_GETTEXT)
3403 && options[opt_idx].var != NULL)
3404 p = (char_u *)_(*(char **)options[opt_idx].var);
3405 else
3406 p = option_expand(opt_idx, NULL);
3407 if (p != NULL && (p = vim_strsave(p)) != NULL)
3408 {
3409 *(char_u **)options[opt_idx].var = p;
3410 /* VIMEXP
3411 * Defaults for all expanded options are currently the same for Vi
3412 * and Vim. When this changes, add some code here! Also need to
3413 * split P_DEF_ALLOCED in two.
3414 */
3415 if (options[opt_idx].flags & P_DEF_ALLOCED)
3416 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3417 options[opt_idx].def_val[VI_DEFAULT] = p;
3418 options[opt_idx].flags |= P_DEF_ALLOCED;
3419 }
3420 }
3421
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422 save_file_ff(curbuf); /* Buffer is unchanged */
3423
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424#if defined(FEAT_ARABIC)
3425 /* Detect use of mlterm.
3426 * Mlterm is a terminal emulator akin to xterm that has some special
3427 * abilities (bidi namely).
3428 * NOTE: mlterm's author is being asked to 'set' a variable
3429 * instead of an environment variable due to inheritance.
3430 */
3431 if (mch_getenv((char_u *)"MLTERM") != NULL)
3432 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3433#endif
3434
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003435 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436
3437#ifdef FEAT_MBYTE
3438# if defined(WIN3264) && defined(FEAT_GETTEXT)
3439 /*
3440 * If $LANG isn't set, try to get a good value for it. This makes the
3441 * right language be used automatically. Don't do this for English.
3442 */
3443 if (mch_getenv((char_u *)"LANG") == NULL)
3444 {
3445 char buf[20];
3446
3447 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3448 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3449 * only the first two. */
3450 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3451 (LPTSTR)buf, 20);
3452 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3453 {
3454 /* There are a few exceptions (probably more) */
3455 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3456 STRCPY(buf, "zh_TW");
3457 else if (STRNICMP(buf, "chs", 3) == 0
3458 || STRNICMP(buf, "zhc", 3) == 0)
3459 STRCPY(buf, "zh_CN");
3460 else if (STRNICMP(buf, "jp", 2) == 0)
3461 STRCPY(buf, "ja");
3462 else
3463 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003464 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003465 }
3466 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003467# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003468# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003469 /* Moved to os_mac_conv.c to avoid dependency problems. */
3470 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003471# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472# endif
3473
3474 /* enc_locale() will try to find the encoding of the current locale. */
3475 p = enc_locale();
3476 if (p != NULL)
3477 {
3478 char_u *save_enc;
3479
3480 /* Try setting 'encoding' and check if the value is valid.
3481 * If not, go back to the default "latin1". */
3482 save_enc = p_enc;
3483 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003484 if (STRCMP(p_enc, "gb18030") == 0)
3485 {
3486 /* We don't support "gb18030", but "cp936" is a good substitute
3487 * for practical purposes, thus use that. It's not an alias to
3488 * still support conversion between gb18030 and utf-8. */
3489 p_enc = vim_strsave((char_u *)"cp936");
3490 vim_free(p);
3491 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003492 if (mb_init() == NULL)
3493 {
3494 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003495 if (opt_idx >= 0)
3496 {
3497 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3498 options[opt_idx].flags |= P_DEF_ALLOCED;
3499 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003501#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003502 if (STRCMP(p_enc, "latin1") == 0
3503# ifdef FEAT_MBYTE
3504 || enc_utf8
3505# endif
3506 )
3507 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003508 /* Adjust the default for 'isprint' and 'iskeyword' to match
3509 * latin1. Also set the defaults for when 'nocompatible' is
3510 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003511 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003512 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003513 set_string_option_direct((char_u *)"isk", -1,
3514 ISK_LATIN1, OPT_FREE, SID_NONE);
3515 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003516 if (opt_idx >= 0)
3517 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003518 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003519 if (opt_idx >= 0)
3520 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003521 (void)init_chartab();
3522 }
3523#endif
3524
Bram Moolenaar071d4272004-06-13 20:20:40 +00003525# if defined(WIN3264) && !defined(FEAT_GUI)
3526 /* Win32 console: When GetACP() returns a different value from
3527 * GetConsoleCP() set 'termencoding'. */
3528 if (GetACP() != GetConsoleCP())
3529 {
3530 char buf[50];
3531
3532 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3533 p_tenc = vim_strsave((char_u *)buf);
3534 if (p_tenc != NULL)
3535 {
3536 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003537 if (opt_idx >= 0)
3538 {
3539 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3540 options[opt_idx].flags |= P_DEF_ALLOCED;
3541 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542 convert_setup(&input_conv, p_tenc, p_enc);
3543 convert_setup(&output_conv, p_enc, p_tenc);
3544 }
3545 else
3546 p_tenc = empty_option;
3547 }
3548# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003549# if defined(WIN3264) && defined(FEAT_MBYTE)
3550 /* $HOME may have characters in active code page. */
3551 init_homedir();
3552# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 }
3554 else
3555 {
3556 vim_free(p_enc);
3557 p_enc = save_enc;
3558 }
3559 }
3560#endif
3561
3562#ifdef FEAT_MULTI_LANG
3563 /* Set the default for 'helplang'. */
3564 set_helplang_default(get_mess_lang());
3565#endif
3566}
3567
3568/*
3569 * Set an option to its default value.
3570 * This does not take care of side effects!
3571 */
3572 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003573set_option_default(
3574 int opt_idx,
3575 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3576 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003577{
3578 char_u *varp; /* pointer to variable for current option */
3579 int dvi; /* index in def_val[] */
3580 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003581 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3583
3584 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3585 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003586 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587 {
3588 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3589 if (flags & P_STRING)
3590 {
3591 /* Use set_string_option_direct() for local options to handle
3592 * freeing and allocating the value. */
3593 if (options[opt_idx].indir != PV_NONE)
3594 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003595 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 else
3597 {
3598 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3599 free_string_option(*(char_u **)(varp));
3600 *(char_u **)varp = options[opt_idx].def_val[dvi];
3601 options[opt_idx].flags &= ~P_ALLOCED;
3602 }
3603 }
3604 else if (flags & P_NUM)
3605 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003606 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607 win_comp_scroll(curwin);
3608 else
3609 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003610 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611 /* May also set global value for local option. */
3612 if (both)
3613 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3614 *(long *)varp;
3615 }
3616 }
3617 else /* P_BOOL */
3618 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003619 /* the cast to long is required for Manx C, long_i is needed for
3620 * MSVC */
3621 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003622#ifdef UNIX
3623 /* 'modeline' defaults to off for root */
3624 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3625 *(int *)varp = FALSE;
3626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 /* May also set global value for local option. */
3628 if (both)
3629 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3630 *(int *)varp;
3631 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003632
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003633 /* The default value is not insecure. */
3634 flagsp = insecure_flag(opt_idx, opt_flags);
3635 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 }
3637
3638#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003639 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640#endif
3641}
3642
3643/*
3644 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003645 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 */
3647 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003648set_options_default(
3649 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650{
3651 int i;
3652#ifdef FEAT_WINDOWS
3653 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003654 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655#endif
3656
3657 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003658 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003659#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003660 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003661 || (TRUE
3662# if defined(FEAT_MBYTE)
3663 && options[i].var != (char_u *)&p_enc
3664# endif
3665# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003666 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003667 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003668# endif
3669 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003670#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003671 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003672 set_option_default(i, opt_flags, p_cp);
3673
3674#ifdef FEAT_WINDOWS
3675 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003676 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677 win_comp_scroll(wp);
3678#else
3679 win_comp_scroll(curwin);
3680#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003681#ifdef FEAT_CINDENT
3682 parse_cino(curbuf);
3683#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684}
3685
3686/*
3687 * Set the Vi-default value of a string option.
3688 * Used for 'sh', 'backupskip' and 'term'.
3689 */
3690 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003691set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692{
3693 char_u *p;
3694 int opt_idx;
3695
3696 p = vim_strsave(val);
3697 if (p != NULL) /* we don't want a NULL */
3698 {
3699 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003700 if (opt_idx >= 0)
3701 {
3702 if (options[opt_idx].flags & P_DEF_ALLOCED)
3703 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3704 options[opt_idx].def_val[VI_DEFAULT] = p;
3705 options[opt_idx].flags |= P_DEF_ALLOCED;
3706 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707 }
3708}
3709
3710/*
3711 * Set the Vi-default value of a number option.
3712 * Used for 'lines' and 'columns'.
3713 */
3714 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003715set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003717 int opt_idx;
3718
3719 opt_idx = findoption((char_u *)name);
3720 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003721 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722}
3723
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003724#if defined(EXITFREE) || defined(PROTO)
3725/*
3726 * Free all options.
3727 */
3728 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003729free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003730{
3731 int i;
3732
3733 for (i = 0; !istermoption(&options[i]); i++)
3734 {
3735 if (options[i].indir == PV_NONE)
3736 {
3737 /* global option: free value and default value. */
3738 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3739 free_string_option(*(char_u **)options[i].var);
3740 if (options[i].flags & P_DEF_ALLOCED)
3741 free_string_option(options[i].def_val[VI_DEFAULT]);
3742 }
3743 else if (options[i].var != VAR_WIN
3744 && (options[i].flags & P_STRING))
3745 /* buffer-local option: free global value */
3746 free_string_option(*(char_u **)options[i].var);
3747 }
3748}
3749#endif
3750
3751
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752/*
3753 * Initialize the options, part two: After getting Rows and Columns and
3754 * setting 'term'.
3755 */
3756 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003757set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003759 int idx;
3760
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 /*
3762 * 'scroll' defaults to half the window height. Note that this default is
3763 * wrong when the window height changes.
3764 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003765 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003766 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003767 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003768 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 comp_col();
3770
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003771 /*
3772 * 'window' is only for backwards compatibility with Vi.
3773 * Default is Rows - 1.
3774 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003775 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003776 p_window = Rows - 1;
3777 set_number_default("window", Rows - 1);
3778
Bram Moolenaarf740b292006-02-16 22:11:02 +00003779 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003780#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003781 /*
3782 * If 'background' wasn't set by the user, try guessing the value,
3783 * depending on the terminal name. Only need to check for terminals
3784 * with a dark background, that can handle color.
3785 */
3786 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003787 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3788 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003790 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003791 /* don't mark it as set, when starting the GUI it may be
3792 * changed again */
3793 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 }
3795#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003796
3797#ifdef CURSOR_SHAPE
3798 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3799#endif
3800#ifdef FEAT_MOUSESHAPE
3801 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3802#endif
3803#ifdef FEAT_PRINTER
3804 (void)parse_printoptions(); /* parse 'printoptions' default value */
3805#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806}
3807
3808/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003809 * Return "dark" or "light" depending on the kind of terminal.
3810 * This is just guessing! Recognized are:
3811 * "linux" Linux console
3812 * "screen.linux" Linux console with screen
3813 * "cygwin" Cygwin shell
3814 * "putty" Putty program
3815 * We also check the COLORFGBG environment variable, which is set by
3816 * rxvt and derivatives. This variable contains either two or three
3817 * values separated by semicolons; we want the last value in either
3818 * case. If this value is 0-6 or 8, our background is dark.
3819 */
3820 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003821term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003822{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003823#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003824 /* DOS console nearly always black */
3825 return (char_u *)"dark";
3826#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003827 char_u *p;
3828
Bram Moolenaarf740b292006-02-16 22:11:02 +00003829 if (STRCMP(T_NAME, "linux") == 0
3830 || STRCMP(T_NAME, "screen.linux") == 0
3831 || STRCMP(T_NAME, "cygwin") == 0
3832 || STRCMP(T_NAME, "putty") == 0
3833 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3834 && (p = vim_strrchr(p, ';')) != NULL
3835 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3836 && p[2] == NUL))
3837 return (char_u *)"dark";
3838 return (char_u *)"light";
3839#endif
3840}
3841
3842/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843 * Initialize the options, part three: After reading the .vimrc
3844 */
3845 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003846set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003848#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003849/*
3850 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3851 * This is done after other initializations, where 'shell' might have been
3852 * set, but only if they have not been set before.
3853 */
3854 char_u *p;
3855 int idx_srr;
3856 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003857# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 int idx_sp;
3859 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003860# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861
3862 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003863 if (idx_srr < 0)
3864 do_srr = FALSE;
3865 else
3866 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003867# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003869 if (idx_sp < 0)
3870 do_sp = FALSE;
3871 else
3872 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003873# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003874 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 if (p != NULL)
3876 {
3877 /*
3878 * Default for p_sp is "| tee", for p_srr is ">".
3879 * For known shells it is changed here to include stderr.
3880 */
3881 if ( fnamecmp(p, "csh") == 0
3882 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003883# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 || fnamecmp(p, "csh.exe") == 0
3885 || fnamecmp(p, "tcsh.exe") == 0
3886# endif
3887 )
3888 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003889# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890 if (do_sp)
3891 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003892# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003894# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003896# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3898 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003899# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900 if (do_srr)
3901 {
3902 p_srr = (char_u *)">&";
3903 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3904 }
3905 }
3906 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003907 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 if ( fnamecmp(p, "sh") == 0
3909 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003910 || fnamecmp(p, "mksh") == 0
3911 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003913 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003915 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003916# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 || fnamecmp(p, "cmd") == 0
3918 || fnamecmp(p, "sh.exe") == 0
3919 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003920 || fnamecmp(p, "mksh.exe") == 0
3921 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003923 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 || fnamecmp(p, "bash.exe") == 0
3925 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003927 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003929# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 if (do_sp)
3931 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003932# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003934# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3938 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003939# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 if (do_srr)
3941 {
3942 p_srr = (char_u *)">%s 2>&1";
3943 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3944 }
3945 }
3946 vim_free(p);
3947 }
3948#endif
3949
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003950#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003952 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3953 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 * This is done after other initializations, where 'shell' might have been
3955 * set, but only if they have not been set before. Default for p_shcf is
3956 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003957 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003959 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960 {
3961 int idx3;
3962
3963 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003964 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965 {
3966 p_shcf = (char_u *)"-c";
3967 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3968 }
3969
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003970# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 /* Somehow Win32 requires the quotes around the redirection too */
3972 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003973 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 {
3975 p_sxq = (char_u *)"\"";
3976 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3977 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003978# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003980 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 {
3982 p_shq = (char_u *)"\"";
3983 options[idx3].def_val[VI_DEFAULT] = p_shq;
3984 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985# endif
3986 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003987 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3988 {
3989 int idx3;
3990
3991 /*
3992 * cmd.exe on Windows will strip the first and last double quote given
3993 * on the command line, e.g. most of the time things like:
3994 * cmd /c "my path/to/echo" "my args to echo"
3995 * become:
3996 * my path/to/echo" "my args to echo
3997 * when executed.
3998 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003999 * To avoid this, set shellxquote to surround the command in
4000 * parenthesis. This appears to make most commands work, without
4001 * breaking commands that worked previously, such as
4002 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004003 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004004 idx3 = findoption((char_u *)"sxq");
4005 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4006 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004007 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004008 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4009 }
4010
Bram Moolenaara64ba222012-02-12 23:23:31 +01004011 idx3 = findoption((char_u *)"shcf");
4012 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4013 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004014 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004015 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4016 }
4017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018#endif
4019
4020#ifdef FEAT_TITLE
4021 set_title_defaults();
4022#endif
4023}
4024
4025#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4026/*
4027 * When 'helplang' is still at its default value, set it to "lang".
4028 * Only the first two characters of "lang" are used.
4029 */
4030 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004031set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032{
4033 int idx;
4034
4035 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4036 return;
4037 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004038 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 {
4040 if (options[idx].flags & P_ALLOCED)
4041 free_string_option(p_hlg);
4042 p_hlg = vim_strsave(lang);
4043 if (p_hlg == NULL)
4044 p_hlg = empty_option;
4045 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004046 {
4047 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4048 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4049 {
4050 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4051 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4052 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004054 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 options[idx].flags |= P_ALLOCED;
4056 }
4057}
4058#endif
4059
4060#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004061static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062
4063 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004064gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065{
4066 if (gui_get_lightness(gui.back_pixel) < 127)
4067 return (char_u *)"dark";
4068 return (char_u *)"light";
4069}
4070
4071/*
4072 * Option initializations that can only be done after opening the GUI window.
4073 */
4074 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004075init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076{
4077 /* Set the 'background' option according to the lightness of the
4078 * background color, unless the user has set it already. */
4079 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4080 {
4081 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4082 highlight_changed();
4083 }
4084}
4085#endif
4086
4087#ifdef FEAT_TITLE
4088/*
4089 * 'title' and 'icon' only default to true if they have not been set or reset
4090 * in .vimrc and we can read the old value.
4091 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4092 * they can be reset. This reduces startup time when using X on a remote
4093 * machine.
4094 */
4095 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004096set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097{
4098 int idx1;
4099 long val;
4100
4101 /*
4102 * If GUI is (going to be) used, we can always set the window title and
4103 * icon name. Saves a bit of time, because the X11 display server does
4104 * not need to be contacted.
4105 */
4106 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004107 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 {
4109#ifdef FEAT_GUI
4110 if (gui.starting || gui.in_use)
4111 val = TRUE;
4112 else
4113#endif
4114 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004115 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 p_title = val;
4117 }
4118 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004119 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 {
4121#ifdef FEAT_GUI
4122 if (gui.starting || gui.in_use)
4123 val = TRUE;
4124 else
4125#endif
4126 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004127 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 p_icon = val;
4129 }
4130}
4131#endif
4132
4133/*
4134 * Parse 'arg' for option settings.
4135 *
4136 * 'arg' may be IObuff, but only when no errors can be present and option
4137 * does not need to be expanded with option_expand().
4138 * "opt_flags":
4139 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004140 * OPT_GLOBAL for ":setglobal"
4141 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004143 * OPT_WINONLY to only set window-local options
4144 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 *
4146 * returns FAIL if an error is detected, OK otherwise
4147 */
4148 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004149do_set(
4150 char_u *arg, /* option string (may be written to!) */
4151 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004152{
4153 int opt_idx;
4154 char_u *errmsg;
4155 char_u errbuf[80];
4156 char_u *startarg;
4157 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4158 int nextchar; /* next non-white char after option name */
4159 int afterchar; /* character just after option name */
4160 int len;
4161 int i;
4162 long value;
4163 int key;
4164 long_u flags; /* flags for current option */
4165 char_u *varp = NULL; /* pointer to variable for current option */
4166 int did_show = FALSE; /* already showed one value */
4167 int adding; /* "opt+=arg" */
4168 int prepending; /* "opt^=arg" */
4169 int removing; /* "opt-=arg" */
4170 int cp_val = 0;
4171 char_u key_name[2];
4172
4173 if (*arg == NUL)
4174 {
4175 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004176 did_show = TRUE;
4177 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004178 }
4179
4180 while (*arg != NUL) /* loop to process all options */
4181 {
4182 errmsg = NULL;
4183 startarg = arg; /* remember for error message */
4184
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004185 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4186 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 {
4188 /*
4189 * ":set all" show all options.
4190 * ":set all&" set all options to their default value.
4191 */
4192 arg += 3;
4193 if (*arg == '&')
4194 {
4195 ++arg;
4196 /* Only for :set command set global value of local options. */
4197 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004198 didset_options();
4199 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004200 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201 }
4202 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004203 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004204 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004205 did_show = TRUE;
4206 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004208 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004209 {
4210 showoptions(2, opt_flags);
4211 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004212 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004213 arg += 7;
4214 }
4215 else
4216 {
4217 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004218 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219 {
4220 prefix = 0;
4221 arg += 2;
4222 }
4223 else if (STRNCMP(arg, "inv", 3) == 0)
4224 {
4225 prefix = 2;
4226 arg += 3;
4227 }
4228
4229 /* find end of name */
4230 key = 0;
4231 if (*arg == '<')
4232 {
4233 nextchar = 0;
4234 opt_idx = -1;
4235 /* look out for <t_>;> */
4236 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4237 len = 5;
4238 else
4239 {
4240 len = 1;
4241 while (arg[len] != NUL && arg[len] != '>')
4242 ++len;
4243 }
4244 if (arg[len] != '>')
4245 {
4246 errmsg = e_invarg;
4247 goto skip;
4248 }
4249 arg[len] = NUL; /* put NUL after name */
4250 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4251 opt_idx = findoption(arg + 1);
4252 arg[len++] = '>'; /* restore '>' */
4253 if (opt_idx == -1)
4254 key = find_key_option(arg + 1);
4255 }
4256 else
4257 {
4258 len = 0;
4259 /*
4260 * The two characters after "t_" may not be alphanumeric.
4261 */
4262 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4263 len = 4;
4264 else
4265 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4266 ++len;
4267 nextchar = arg[len];
4268 arg[len] = NUL; /* put NUL after name */
4269 opt_idx = findoption(arg);
4270 arg[len] = nextchar; /* restore nextchar */
4271 if (opt_idx == -1)
4272 key = find_key_option(arg);
4273 }
4274
4275 /* remember character after option name */
4276 afterchar = arg[len];
4277
4278 /* skip white space, allow ":set ai ?" */
4279 while (vim_iswhite(arg[len]))
4280 ++len;
4281
4282 adding = FALSE;
4283 prepending = FALSE;
4284 removing = FALSE;
4285 if (arg[len] != NUL && arg[len + 1] == '=')
4286 {
4287 if (arg[len] == '+')
4288 {
4289 adding = TRUE; /* "+=" */
4290 ++len;
4291 }
4292 else if (arg[len] == '^')
4293 {
4294 prepending = TRUE; /* "^=" */
4295 ++len;
4296 }
4297 else if (arg[len] == '-')
4298 {
4299 removing = TRUE; /* "-=" */
4300 ++len;
4301 }
4302 }
4303 nextchar = arg[len];
4304
4305 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4306 {
4307 errmsg = (char_u *)N_("E518: Unknown option");
4308 goto skip;
4309 }
4310
4311 if (opt_idx >= 0)
4312 {
4313 if (options[opt_idx].var == NULL) /* hidden option: skip */
4314 {
4315 /* Only give an error message when requesting the value of
4316 * a hidden option, ignore setting it. */
4317 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4318 && (!(options[opt_idx].flags & P_BOOL)
4319 || nextchar == '?'))
4320 errmsg = (char_u *)N_("E519: Option not supported");
4321 goto skip;
4322 }
4323
4324 flags = options[opt_idx].flags;
4325 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4326 }
4327 else
4328 {
4329 flags = P_STRING;
4330 if (key < 0)
4331 {
4332 key_name[0] = KEY2TERMCAP0(key);
4333 key_name[1] = KEY2TERMCAP1(key);
4334 }
4335 else
4336 {
4337 key_name[0] = KS_KEY;
4338 key_name[1] = (key & 0xff);
4339 }
4340 }
4341
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004342 /* Skip all options that are not window-local (used when showing
4343 * an already loaded buffer in a window). */
4344 if ((opt_flags & OPT_WINONLY)
4345 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4346 goto skip;
4347
Bram Moolenaara3227e22006-03-08 21:32:40 +00004348 /* Skip all options that are window-local (used for :vimgrep). */
4349 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4350 && options[opt_idx].var == VAR_WIN)
4351 goto skip;
4352
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004353 /* Disallow changing some options from modelines. */
4354 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004355 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004356 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004357 {
4358 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4359 goto skip;
4360 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004361#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004362 /* In diff mode some options are overruled. This avoids that
4363 * 'foldmethod' becomes "marker" instead of "diff" and that
4364 * "wrap" gets set. */
4365 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004366 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004367 && (options[opt_idx].indir == PV_FDM
4368 || options[opt_idx].indir == PV_WRAP))
4369 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371 }
4372
4373#ifdef HAVE_SANDBOX
4374 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004375 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004376 {
4377 errmsg = (char_u *)_(e_sandbox);
4378 goto skip;
4379 }
4380#endif
4381
4382 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4383 {
4384 arg += len;
4385 cp_val = p_cp;
4386 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4387 {
4388 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4389 {
4390 cp_val = FALSE;
4391 arg += 3;
4392 }
4393 else /* "opt&vi": set to Vi default */
4394 {
4395 cp_val = TRUE;
4396 arg += 2;
4397 }
4398 }
4399 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4400 && arg[1] != NUL && !vim_iswhite(arg[1]))
4401 {
4402 errmsg = e_trailing;
4403 goto skip;
4404 }
4405 }
4406
4407 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004408 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4409 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410 */
4411 if (nextchar == '?'
4412 || (prefix == 1
4413 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4414 && !(flags & P_BOOL)))
4415 {
4416 /*
4417 * print value
4418 */
4419 if (did_show)
4420 msg_putchar('\n'); /* cursor below last one */
4421 else
4422 {
4423 gotocmdline(TRUE); /* cursor at status line */
4424 did_show = TRUE; /* remember that we did a line */
4425 }
4426 if (opt_idx >= 0)
4427 {
4428 showoneopt(&options[opt_idx], opt_flags);
4429#ifdef FEAT_EVAL
4430 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004431 {
4432 /* Mention where the option was last set. */
4433 if (varp == options[opt_idx].var)
4434 last_set_msg(options[opt_idx].scriptID);
4435 else if ((int)options[opt_idx].indir & PV_WIN)
4436 last_set_msg(curwin->w_p_scriptID[
4437 (int)options[opt_idx].indir & PV_MASK]);
4438 else if ((int)options[opt_idx].indir & PV_BUF)
4439 last_set_msg(curbuf->b_p_scriptID[
4440 (int)options[opt_idx].indir & PV_MASK]);
4441 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004442#endif
4443 }
4444 else
4445 {
4446 char_u *p;
4447
4448 p = find_termcode(key_name);
4449 if (p == NULL)
4450 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004451 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004452 goto skip;
4453 }
4454 else
4455 (void)show_one_termcode(key_name, p, TRUE);
4456 }
4457 if (nextchar != '?'
4458 && nextchar != NUL && !vim_iswhite(afterchar))
4459 errmsg = e_trailing;
4460 }
4461 else
4462 {
4463 if (flags & P_BOOL) /* boolean */
4464 {
4465 if (nextchar == '=' || nextchar == ':')
4466 {
4467 errmsg = e_invarg;
4468 goto skip;
4469 }
4470
4471 /*
4472 * ":set opt!": invert
4473 * ":set opt&": reset to default value
4474 * ":set opt<": reset to global value
4475 */
4476 if (nextchar == '!')
4477 value = *(int *)(varp) ^ 1;
4478 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004479 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004480 ((flags & P_VI_DEF) || cp_val)
4481 ? VI_DEFAULT : VIM_DEFAULT];
4482 else if (nextchar == '<')
4483 {
4484 /* For 'autoread' -1 means to use global value. */
4485 if ((int *)varp == &curbuf->b_p_ar
4486 && opt_flags == OPT_LOCAL)
4487 value = -1;
4488 else
4489 value = *(int *)get_varp_scope(&(options[opt_idx]),
4490 OPT_GLOBAL);
4491 }
4492 else
4493 {
4494 /*
4495 * ":set invopt": invert
4496 * ":set opt" or ":set noopt": set or reset
4497 */
4498 if (nextchar != NUL && !vim_iswhite(afterchar))
4499 {
4500 errmsg = e_trailing;
4501 goto skip;
4502 }
4503 if (prefix == 2) /* inv */
4504 value = *(int *)(varp) ^ 1;
4505 else
4506 value = prefix;
4507 }
4508
4509 errmsg = set_bool_option(opt_idx, varp, (int)value,
4510 opt_flags);
4511 }
4512 else /* numeric or string */
4513 {
4514 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4515 || prefix != 1)
4516 {
4517 errmsg = e_invarg;
4518 goto skip;
4519 }
4520
4521 if (flags & P_NUM) /* numeric */
4522 {
4523 /*
4524 * Different ways to set a number option:
4525 * & set to default value
4526 * < set to global value
4527 * <xx> accept special key codes for 'wildchar'
4528 * c accept any non-digit for 'wildchar'
4529 * [-]0-9 set number
4530 * other error
4531 */
4532 ++arg;
4533 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004534 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004535 ((flags & P_VI_DEF) || cp_val)
4536 ? VI_DEFAULT : VIM_DEFAULT];
4537 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004538 {
4539 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4540 * use the global value. */
4541 if ((long *)varp == &curbuf->b_p_ul
4542 && opt_flags == OPT_LOCAL)
4543 value = NO_LOCAL_UNDOLEVEL;
4544 else
4545 value = *(long *)get_varp_scope(
4546 &(options[opt_idx]), OPT_GLOBAL);
4547 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004548 else if (((long *)varp == &p_wc
4549 || (long *)varp == &p_wcm)
4550 && (*arg == '<'
4551 || *arg == '^'
4552 || ((!arg[1] || vim_iswhite(arg[1]))
4553 && !VIM_ISDIGIT(*arg))))
4554 {
4555 value = string_to_key(arg);
4556 if (value == 0 && (long *)varp != &p_wcm)
4557 {
4558 errmsg = e_invarg;
4559 goto skip;
4560 }
4561 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4563 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004564 /* Allow negative (for 'undolevels'), octal and
4565 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004566 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4567 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004568 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4569 {
4570 errmsg = e_invarg;
4571 goto skip;
4572 }
4573 }
4574 else
4575 {
4576 errmsg = (char_u *)N_("E521: Number required after =");
4577 goto skip;
4578 }
4579
4580 if (adding)
4581 value = *(long *)varp + value;
4582 if (prepending)
4583 value = *(long *)varp * value;
4584 if (removing)
4585 value = *(long *)varp - value;
4586 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004587 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004588 }
4589 else if (opt_idx >= 0) /* string */
4590 {
4591 char_u *save_arg = NULL;
4592 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004593 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004594 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004595 char_u *origval = NULL;
4596#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4597 char_u *saved_origval = NULL;
4598#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004599 unsigned newlen;
4600 int comma;
4601 int bs;
4602 int new_value_alloced; /* new string option
4603 was allocated */
4604
4605 /* When using ":set opt=val" for a global option
4606 * with a local value the local value will be
4607 * reset, use the global value here. */
4608 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004609 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004610 varp = options[opt_idx].var;
4611
4612 /* The old value is kept until we are sure that the
4613 * new value is valid. */
4614 oldval = *(char_u **)varp;
4615 if (nextchar == '&') /* set to default val */
4616 {
4617 newval = options[opt_idx].def_val[
4618 ((flags & P_VI_DEF) || cp_val)
4619 ? VI_DEFAULT : VIM_DEFAULT];
4620 if ((char_u **)varp == &p_bg)
4621 {
4622 /* guess the value of 'background' */
4623#ifdef FEAT_GUI
4624 if (gui.in_use)
4625 newval = gui_bg_default();
4626 else
4627#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004628 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629 }
4630
4631 /* expand environment variables and ~ (since the
4632 * default value was already expanded, only
4633 * required when an environment variable was set
4634 * later */
4635 if (newval == NULL)
4636 newval = empty_option;
4637 else
4638 {
4639 s = option_expand(opt_idx, newval);
4640 if (s == NULL)
4641 s = newval;
4642 newval = vim_strsave(s);
4643 }
4644 new_value_alloced = TRUE;
4645 }
4646 else if (nextchar == '<') /* set to global val */
4647 {
4648 newval = vim_strsave(*(char_u **)get_varp_scope(
4649 &(options[opt_idx]), OPT_GLOBAL));
4650 new_value_alloced = TRUE;
4651 }
4652 else
4653 {
4654 ++arg; /* jump to after the '=' or ':' */
4655
4656 /*
4657 * Set 'keywordprg' to ":help" if an empty
4658 * value was passed to :set by the user.
4659 * Misuse errbuf[] for the resulting string.
4660 */
4661 if (varp == (char_u *)&p_kp
4662 && (*arg == NUL || *arg == ' '))
4663 {
4664 STRCPY(errbuf, ":help");
4665 save_arg = arg;
4666 arg = errbuf;
4667 }
4668 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004669 * Convert 'backspace' number to string, for
4670 * adding, prepending and removing string.
4671 */
4672 else if (varp == (char_u *)&p_bs
4673 && VIM_ISDIGIT(**(char_u **)varp))
4674 {
4675 i = getdigits((char_u **)varp);
4676 switch (i)
4677 {
4678 case 0:
4679 *(char_u **)varp = empty_option;
4680 break;
4681 case 1:
4682 *(char_u **)varp = vim_strsave(
4683 (char_u *)"indent,eol");
4684 break;
4685 case 2:
4686 *(char_u **)varp = vim_strsave(
4687 (char_u *)"indent,eol,start");
4688 break;
4689 }
4690 vim_free(oldval);
4691 oldval = *(char_u **)varp;
4692 }
4693 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004694 * Convert 'whichwrap' number to string, for
4695 * backwards compatibility with Vim 3.0.
4696 * Misuse errbuf[] for the resulting string.
4697 */
4698 else if (varp == (char_u *)&p_ww
4699 && VIM_ISDIGIT(*arg))
4700 {
4701 *errbuf = NUL;
4702 i = getdigits(&arg);
4703 if (i & 1)
4704 STRCAT(errbuf, "b,");
4705 if (i & 2)
4706 STRCAT(errbuf, "s,");
4707 if (i & 4)
4708 STRCAT(errbuf, "h,l,");
4709 if (i & 8)
4710 STRCAT(errbuf, "<,>,");
4711 if (i & 16)
4712 STRCAT(errbuf, "[,],");
4713 if (*errbuf != NUL) /* remove trailing , */
4714 errbuf[STRLEN(errbuf) - 1] = NUL;
4715 save_arg = arg;
4716 arg = errbuf;
4717 }
4718 /*
4719 * Remove '>' before 'dir' and 'bdir', for
4720 * backwards compatibility with version 3.0
4721 */
4722 else if ( *arg == '>'
4723 && (varp == (char_u *)&p_dir
4724 || varp == (char_u *)&p_bdir))
4725 {
4726 ++arg;
4727 }
4728
4729 /* When setting the local value of a global
4730 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004731 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004732 && (opt_flags & OPT_LOCAL))
4733 origval = *(char_u **)get_varp(
4734 &options[opt_idx]);
4735 else
4736 origval = oldval;
4737
4738 /*
4739 * Copy the new string into allocated memory.
4740 * Can't use set_string_option_direct(), because
4741 * we need to remove the backslashes.
4742 */
4743 /* get a bit too much */
4744 newlen = (unsigned)STRLEN(arg) + 1;
4745 if (adding || prepending || removing)
4746 newlen += (unsigned)STRLEN(origval) + 1;
4747 newval = alloc(newlen);
4748 if (newval == NULL) /* out of mem, don't change */
4749 break;
4750 s = newval;
4751
4752 /*
4753 * Copy the string, skip over escaped chars.
4754 * For MS-DOS and WIN32 backslashes before normal
4755 * file name characters are not removed, and keep
4756 * backslash at start, for "\\machine\path", but
4757 * do remove it for "\\\\machine\\path".
4758 * The reverse is found in ExpandOldSetting().
4759 */
4760 while (*arg && !vim_iswhite(*arg))
4761 {
4762 if (*arg == '\\' && arg[1] != NUL
4763#ifdef BACKSLASH_IN_FILENAME
4764 && !((flags & P_EXPAND)
4765 && vim_isfilec(arg[1])
4766 && (arg[1] != '\\'
4767 || (s == newval
4768 && arg[2] != '\\')))
4769#endif
4770 )
4771 ++arg; /* remove backslash */
4772#ifdef FEAT_MBYTE
4773 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004774 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004775 {
4776 /* copy multibyte char */
4777 mch_memmove(s, arg, (size_t)i);
4778 arg += i;
4779 s += i;
4780 }
4781 else
4782#endif
4783 *s++ = *arg++;
4784 }
4785 *s = NUL;
4786
4787 /*
4788 * Expand environment variables and ~.
4789 * Don't do it when adding without inserting a
4790 * comma.
4791 */
4792 if (!(adding || prepending || removing)
4793 || (flags & P_COMMA))
4794 {
4795 s = option_expand(opt_idx, newval);
4796 if (s != NULL)
4797 {
4798 vim_free(newval);
4799 newlen = (unsigned)STRLEN(s) + 1;
4800 if (adding || prepending || removing)
4801 newlen += (unsigned)STRLEN(origval) + 1;
4802 newval = alloc(newlen);
4803 if (newval == NULL)
4804 break;
4805 STRCPY(newval, s);
4806 }
4807 }
4808
4809 /* locate newval[] in origval[] when removing it
4810 * and when adding to avoid duplicates */
4811 i = 0; /* init for GCC */
4812 if (removing || (flags & P_NODUP))
4813 {
4814 i = (int)STRLEN(newval);
4815 bs = 0;
4816 for (s = origval; *s; ++s)
4817 {
4818 if ((!(flags & P_COMMA)
4819 || s == origval
4820 || (s[-1] == ',' && !(bs & 1)))
4821 && STRNCMP(s, newval, i) == 0
4822 && (!(flags & P_COMMA)
4823 || s[i] == ','
4824 || s[i] == NUL))
4825 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004826 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004827 * even number of backslashes or a single
4828 * backslash preceded by a comma before it
4829 * is recognized as a separator */
4830 if ((s > origval + 1
4831 && s[-1] == '\\'
4832 && s[-2] != ',')
4833 || (s == origval + 1
4834 && s[-1] == '\\'))
4835
Bram Moolenaar071d4272004-06-13 20:20:40 +00004836 ++bs;
4837 else
4838 bs = 0;
4839 }
4840
4841 /* do not add if already there */
4842 if ((adding || prepending) && *s)
4843 {
4844 prepending = FALSE;
4845 adding = FALSE;
4846 STRCPY(newval, origval);
4847 }
4848 }
4849
4850 /* concatenate the two strings; add a ',' if
4851 * needed */
4852 if (adding || prepending)
4853 {
4854 comma = ((flags & P_COMMA) && *origval != NUL
4855 && *newval != NUL);
4856 if (adding)
4857 {
4858 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004859 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004860 if (comma && i > 1
4861 && (flags & P_ONECOMMA) == P_ONECOMMA
4862 && origval[i - 1] == ','
4863 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004864 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004865 mch_memmove(newval + i + comma, newval,
4866 STRLEN(newval) + 1);
4867 mch_memmove(newval, origval, (size_t)i);
4868 }
4869 else
4870 {
4871 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004872 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004873 }
4874 if (comma)
4875 newval[i] = ',';
4876 }
4877
4878 /* Remove newval[] from origval[]. (Note: "i" has
4879 * been set above and is used here). */
4880 if (removing)
4881 {
4882 STRCPY(newval, origval);
4883 if (*s)
4884 {
4885 /* may need to remove a comma */
4886 if (flags & P_COMMA)
4887 {
4888 if (s == origval)
4889 {
4890 /* include comma after string */
4891 if (s[i] == ',')
4892 ++i;
4893 }
4894 else
4895 {
4896 /* include comma before string */
4897 --s;
4898 ++i;
4899 }
4900 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004901 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004902 }
4903 }
4904
4905 if (flags & P_FLAGLIST)
4906 {
4907 /* Remove flags that appear twice. */
4908 for (s = newval; *s; ++s)
4909 if ((!(flags & P_COMMA) || *s != ',')
4910 && vim_strchr(s + 1, *s) != NULL)
4911 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004912 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004913 --s;
4914 }
4915 }
4916
4917 if (save_arg != NULL) /* number for 'whichwrap' */
4918 arg = save_arg;
4919 new_value_alloced = TRUE;
4920 }
4921
4922 /* Set the new value. */
4923 *(char_u **)(varp) = newval;
4924
Bram Moolenaar53744302015-07-17 17:38:22 +02004925#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004926 if (!starting
4927# ifdef FEAT_CRYPT
4928 && options[opt_idx].indir != PV_KEY
4929# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004930 && origval != NULL)
4931 /* origval may be freed by
4932 * did_set_string_option(), make a copy. */
4933 saved_origval = vim_strsave(origval);
4934#endif
4935
Bram Moolenaar071d4272004-06-13 20:20:40 +00004936 /* Handle side effects, and set the global value for
4937 * ":set" on local options. */
4938 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4939 new_value_alloced, oldval, errbuf, opt_flags);
4940
4941 /* If error detected, print the error message. */
4942 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004943 {
4944#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4945 vim_free(saved_origval);
4946#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004947 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004948 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004949#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4950 if (saved_origval != NULL)
4951 {
4952 char_u buf_type[7];
4953
4954 sprintf((char *)buf_type, "%s",
4955 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004956 set_vim_var_string(VV_OPTION_NEW,
4957 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004958 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4959 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4960 apply_autocmds(EVENT_OPTIONSET,
4961 (char_u *)options[opt_idx].fullname,
4962 NULL, FALSE, NULL);
4963 reset_v_option_vars();
4964 vim_free(saved_origval);
4965 }
4966#endif
4967
Bram Moolenaar071d4272004-06-13 20:20:40 +00004968 }
4969 else /* key code option */
4970 {
4971 char_u *p;
4972
4973 if (nextchar == '&')
4974 {
4975 if (add_termcap_entry(key_name, TRUE) == FAIL)
4976 errmsg = (char_u *)N_("E522: Not found in termcap");
4977 }
4978 else
4979 {
4980 ++arg; /* jump to after the '=' or ':' */
4981 for (p = arg; *p && !vim_iswhite(*p); ++p)
4982 if (*p == '\\' && p[1] != NUL)
4983 ++p;
4984 nextchar = *p;
4985 *p = NUL;
4986 add_termcode(key_name, arg, FALSE);
4987 *p = nextchar;
4988 }
4989 if (full_screen)
4990 ttest(FALSE);
4991 redraw_all_later(CLEAR);
4992 }
4993 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004994
Bram Moolenaar071d4272004-06-13 20:20:40 +00004995 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004996 did_set_option(opt_idx, opt_flags,
4997 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004998 }
4999
5000skip:
5001 /*
5002 * Advance to next argument.
5003 * - skip until a blank found, taking care of backslashes
5004 * - skip blanks
5005 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5006 */
5007 for (i = 0; i < 2 ; ++i)
5008 {
5009 while (*arg != NUL && !vim_iswhite(*arg))
5010 if (*arg++ == '\\' && *arg != NUL)
5011 ++arg;
5012 arg = skipwhite(arg);
5013 if (*arg != '=')
5014 break;
5015 }
5016 }
5017
5018 if (errmsg != NULL)
5019 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005020 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005021 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005022 if (i + (arg - startarg) < IOSIZE)
5023 {
5024 /* append the argument with the error */
5025 STRCAT(IObuff, ": ");
5026 mch_memmove(IObuff + i, startarg, (arg - startarg));
5027 IObuff[i + (arg - startarg)] = NUL;
5028 }
5029 /* make sure all characters are printable */
5030 trans_characters(IObuff, IOSIZE);
5031
5032 ++no_wait_return; /* wait_return done later */
5033 emsg(IObuff); /* show error highlighted */
5034 --no_wait_return;
5035
5036 return FAIL;
5037 }
5038
5039 arg = skipwhite(arg);
5040 }
5041
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005042theend:
5043 if (silent_mode && did_show)
5044 {
5045 /* After displaying option values in silent mode. */
5046 silent_mode = FALSE;
5047 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5048 msg_putchar('\n');
5049 cursor_on(); /* msg_start() switches it off */
5050 out_flush();
5051 silent_mode = TRUE;
5052 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5053 }
5054
Bram Moolenaar071d4272004-06-13 20:20:40 +00005055 return OK;
5056}
5057
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005058/*
5059 * Call this when an option has been given a new value through a user command.
5060 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5061 */
5062 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005063did_set_option(
5064 int opt_idx,
5065 int opt_flags, /* possibly with OPT_MODELINE */
5066 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005067{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005068 long_u *p;
5069
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005070 options[opt_idx].flags |= P_WAS_SET;
5071
5072 /* When an option is set in the sandbox, from a modeline or in secure mode
5073 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005074 * flag. */
5075 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005076 if (secure
5077#ifdef HAVE_SANDBOX
5078 || sandbox != 0
5079#endif
5080 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005081 *p = *p | P_INSECURE;
5082 else if (new_value)
5083 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005084}
5085
Bram Moolenaar071d4272004-06-13 20:20:40 +00005086 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005087illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005088{
5089 if (errbuf == NULL)
5090 return (char_u *)"";
5091 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005092 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005093 return errbuf;
5094}
5095
5096/*
5097 * Convert a key name or string into a key value.
5098 * Used for 'wildchar' and 'cedit' options.
5099 */
5100 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005101string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005102{
5103 if (*arg == '<')
5104 return find_key_option(arg + 1);
5105 if (*arg == '^')
5106 return Ctrl_chr(arg[1]);
5107 return *arg;
5108}
5109
5110#ifdef FEAT_CMDWIN
5111/*
5112 * Check value of 'cedit' and set cedit_key.
5113 * Returns NULL if value is OK, error message otherwise.
5114 */
5115 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005116check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005117{
5118 int n;
5119
5120 if (*p_cedit == NUL)
5121 cedit_key = -1;
5122 else
5123 {
5124 n = string_to_key(p_cedit);
5125 if (vim_isprintc(n))
5126 return e_invarg;
5127 cedit_key = n;
5128 }
5129 return NULL;
5130}
5131#endif
5132
5133#ifdef FEAT_TITLE
5134/*
5135 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5136 * maketitle() to create and display it.
5137 * When switching the title or icon off, call mch_restore_title() to get
5138 * the old value back.
5139 */
5140 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005141did_set_title(
5142 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005143{
5144 if (starting != NO_SCREEN
5145#ifdef FEAT_GUI
5146 && !gui.starting
5147#endif
5148 )
5149 {
5150 maketitle();
5151 if (icon)
5152 {
5153 if (!p_icon)
5154 mch_restore_title(2);
5155 }
5156 else
5157 {
5158 if (!p_title)
5159 mch_restore_title(1);
5160 }
5161 }
5162}
5163#endif
5164
5165/*
5166 * set_options_bin - called when 'bin' changes value.
5167 */
5168 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005169set_options_bin(
5170 int oldval,
5171 int newval,
5172 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005173{
5174 /*
5175 * The option values that are changed when 'bin' changes are
5176 * copied when 'bin is set and restored when 'bin' is reset.
5177 */
5178 if (newval)
5179 {
5180 if (!oldval) /* switched on */
5181 {
5182 if (!(opt_flags & OPT_GLOBAL))
5183 {
5184 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5185 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5186 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5187 curbuf->b_p_et_nobin = curbuf->b_p_et;
5188 }
5189 if (!(opt_flags & OPT_LOCAL))
5190 {
5191 p_tw_nobin = p_tw;
5192 p_wm_nobin = p_wm;
5193 p_ml_nobin = p_ml;
5194 p_et_nobin = p_et;
5195 }
5196 }
5197
5198 if (!(opt_flags & OPT_GLOBAL))
5199 {
5200 curbuf->b_p_tw = 0; /* no automatic line wrap */
5201 curbuf->b_p_wm = 0; /* no automatic line wrap */
5202 curbuf->b_p_ml = 0; /* no modelines */
5203 curbuf->b_p_et = 0; /* no expandtab */
5204 }
5205 if (!(opt_flags & OPT_LOCAL))
5206 {
5207 p_tw = 0;
5208 p_wm = 0;
5209 p_ml = FALSE;
5210 p_et = FALSE;
5211 p_bin = TRUE; /* needed when called for the "-b" argument */
5212 }
5213 }
5214 else if (oldval) /* switched off */
5215 {
5216 if (!(opt_flags & OPT_GLOBAL))
5217 {
5218 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5219 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5220 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5221 curbuf->b_p_et = curbuf->b_p_et_nobin;
5222 }
5223 if (!(opt_flags & OPT_LOCAL))
5224 {
5225 p_tw = p_tw_nobin;
5226 p_wm = p_wm_nobin;
5227 p_ml = p_ml_nobin;
5228 p_et = p_et_nobin;
5229 }
5230 }
5231}
5232
5233#ifdef FEAT_VIMINFO
5234/*
5235 * Find the parameter represented by the given character (eg ', :, ", or /),
5236 * and return its associated value in the 'viminfo' string.
5237 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005238 * If the parameter is not specified in the string or there is no following
5239 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005240 */
5241 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005242get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005243{
5244 char_u *p;
5245
5246 p = find_viminfo_parameter(type);
5247 if (p != NULL && VIM_ISDIGIT(*p))
5248 return atoi((char *)p);
5249 return -1;
5250}
5251
5252/*
5253 * Find the parameter represented by the given character (eg ''', ':', '"', or
5254 * '/') in the 'viminfo' option and return a pointer to the string after it.
5255 * Return NULL if the parameter is not specified in the string.
5256 */
5257 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005258find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005259{
5260 char_u *p;
5261
5262 for (p = p_viminfo; *p; ++p)
5263 {
5264 if (*p == type)
5265 return p + 1;
5266 if (*p == 'n') /* 'n' is always the last one */
5267 break;
5268 p = vim_strchr(p, ','); /* skip until next ',' */
5269 if (p == NULL) /* hit the end without finding parameter */
5270 break;
5271 }
5272 return NULL;
5273}
5274#endif
5275
5276/*
5277 * Expand environment variables for some string options.
5278 * These string options cannot be indirect!
5279 * If "val" is NULL expand the current value of the option.
5280 * Return pointer to NameBuff, or NULL when not expanded.
5281 */
5282 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005283option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005284{
5285 /* if option doesn't need expansion nothing to do */
5286 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5287 return NULL;
5288
5289 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5290 * expand_env() would truncate the string. */
5291 if (val != NULL && STRLEN(val) > MAXPATHL)
5292 return NULL;
5293
5294 if (val == NULL)
5295 val = *(char_u **)options[opt_idx].var;
5296
5297 /*
5298 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5299 * Escape spaces when expanding 'tags', they are used to separate file
5300 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005301 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005302 */
5303 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005304 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005305#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005306 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5307#endif
5308 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5310 return NULL;
5311
5312 return NameBuff;
5313}
5314
5315/*
5316 * After setting various option values: recompute variables that depend on
5317 * option values.
5318 */
5319 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005320didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005321{
5322 /* initialize the table for 'iskeyword' et.al. */
5323 (void)init_chartab();
5324
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005325#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005327#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005328 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005329 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330#ifdef FEAT_SESSION
5331 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5332 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5333#endif
5334#ifdef FEAT_FOLDING
5335 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5336#endif
5337 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005338 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005339#ifdef FEAT_VIRTUALEDIT
5340 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5341#endif
5342#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5343 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5344#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005345#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005346 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005347 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005348 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005349 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5352 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5353#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005354#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5356#endif
5357#ifdef FEAT_CMDWIN
5358 /* set cedit_key */
5359 (void)check_cedit();
5360#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005361#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005362 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005363#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005364#ifdef FEAT_LINEBREAK
5365 /* initialize the table for 'breakat'. */
5366 fill_breakat_flags();
5367#endif
5368
5369}
5370
5371/*
5372 * More side effects of setting options.
5373 */
5374 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005375didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005376{
5377 /* Initialize the highlight_attr[] table. */
5378 (void)highlight_changed();
5379
5380 /* Parse default for 'wildmode' */
5381 check_opt_wim();
5382
5383 (void)set_chars_option(&p_lcs);
5384#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5385 /* Parse default for 'fillchars'. */
5386 (void)set_chars_option(&p_fcs);
5387#endif
5388
5389#ifdef FEAT_CLIPBOARD
5390 /* Parse default for 'clipboard' */
5391 (void)check_clipboard_option();
5392#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005393}
5394
5395/*
5396 * Check for string options that are NULL (normally only termcap options).
5397 */
5398 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005399check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005400{
5401 int opt_idx;
5402
5403 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5404 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5405 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5406}
5407
5408/*
5409 * Check string options in a buffer for NULL value.
5410 */
5411 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005412check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005413{
5414#if defined(FEAT_QUICKFIX)
5415 check_string_option(&buf->b_p_bh);
5416 check_string_option(&buf->b_p_bt);
5417#endif
5418#ifdef FEAT_MBYTE
5419 check_string_option(&buf->b_p_fenc);
5420#endif
5421 check_string_option(&buf->b_p_ff);
5422#ifdef FEAT_FIND_ID
5423 check_string_option(&buf->b_p_def);
5424 check_string_option(&buf->b_p_inc);
5425# ifdef FEAT_EVAL
5426 check_string_option(&buf->b_p_inex);
5427# endif
5428#endif
5429#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5430 check_string_option(&buf->b_p_inde);
5431 check_string_option(&buf->b_p_indk);
5432#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005433#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5434 check_string_option(&buf->b_p_bexpr);
5435#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005436#if defined(FEAT_CRYPT)
5437 check_string_option(&buf->b_p_cm);
5438#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005439#if defined(FEAT_EVAL)
5440 check_string_option(&buf->b_p_fex);
5441#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005442#ifdef FEAT_CRYPT
5443 check_string_option(&buf->b_p_key);
5444#endif
5445 check_string_option(&buf->b_p_kp);
5446 check_string_option(&buf->b_p_mps);
5447 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005448 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005449 check_string_option(&buf->b_p_isk);
5450#ifdef FEAT_COMMENTS
5451 check_string_option(&buf->b_p_com);
5452#endif
5453#ifdef FEAT_FOLDING
5454 check_string_option(&buf->b_p_cms);
5455#endif
5456 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005457#ifdef FEAT_TEXTOBJ
5458 check_string_option(&buf->b_p_qe);
5459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460#ifdef FEAT_SYN_HL
5461 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005462 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005463#endif
5464#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005465 check_string_option(&buf->b_s.b_p_spc);
5466 check_string_option(&buf->b_s.b_p_spf);
5467 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005468#endif
5469#ifdef FEAT_SEARCHPATH
5470 check_string_option(&buf->b_p_sua);
5471#endif
5472#ifdef FEAT_CINDENT
5473 check_string_option(&buf->b_p_cink);
5474 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005475 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005476#endif
5477#ifdef FEAT_AUTOCMD
5478 check_string_option(&buf->b_p_ft);
5479#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005480#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5481 check_string_option(&buf->b_p_cinw);
5482#endif
5483#ifdef FEAT_INS_EXPAND
5484 check_string_option(&buf->b_p_cpt);
5485#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005486#ifdef FEAT_COMPL_FUNC
5487 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005488 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005489#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005490#ifdef FEAT_KEYMAP
5491 check_string_option(&buf->b_p_keymap);
5492#endif
5493#ifdef FEAT_QUICKFIX
5494 check_string_option(&buf->b_p_gp);
5495 check_string_option(&buf->b_p_mp);
5496 check_string_option(&buf->b_p_efm);
5497#endif
5498 check_string_option(&buf->b_p_ep);
5499 check_string_option(&buf->b_p_path);
5500 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005501 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502#ifdef FEAT_INS_EXPAND
5503 check_string_option(&buf->b_p_dict);
5504 check_string_option(&buf->b_p_tsr);
5505#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005506#ifdef FEAT_LISP
5507 check_string_option(&buf->b_p_lw);
5508#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005509 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005510}
5511
5512/*
5513 * Free the string allocated for an option.
5514 * Checks for the string being empty_option. This may happen if we're out of
5515 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5516 * check_options().
5517 * Does NOT check for P_ALLOCED flag!
5518 */
5519 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005520free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521{
5522 if (p != empty_option)
5523 vim_free(p);
5524}
5525
5526 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005527clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528{
5529 if (*pp != empty_option)
5530 vim_free(*pp);
5531 *pp = empty_option;
5532}
5533
5534 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005535check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536{
5537 if (*pp == NULL)
5538 *pp = empty_option;
5539}
5540
5541/*
5542 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5543 */
5544 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005545set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546{
5547 int opt_idx;
5548
5549 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5550 if (options[opt_idx].var == (char_u *)p)
5551 {
5552 options[opt_idx].flags |= P_ALLOCED;
5553 return;
5554 }
5555 return; /* cannot happen: didn't find it! */
5556}
5557
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005558#if defined(FEAT_EVAL) || defined(PROTO)
5559/*
5560 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5561 * Return FALSE when it wasn't.
5562 * Return -1 for an unknown option.
5563 */
5564 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005565was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005566{
5567 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005568 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005569
5570 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005571 {
5572 flagp = insecure_flag(idx, opt_flags);
5573 return (*flagp & P_INSECURE) != 0;
5574 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005575 EMSG2(_(e_intern2), "was_set_insecurely()");
5576 return -1;
5577}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005578
5579/*
5580 * Get a pointer to the flags used for the P_INSECURE flag of option
5581 * "opt_idx". For some local options a local flags field is used.
5582 */
5583 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005584insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005585{
5586 if (opt_flags & OPT_LOCAL)
5587 switch ((int)options[opt_idx].indir)
5588 {
5589#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005590 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005591#endif
5592#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005593# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005594 case PV_FDE: return &curwin->w_p_fde_flags;
5595 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005596# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005597# ifdef FEAT_BEVAL
5598 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5599# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005600# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005601 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005602# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005603 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005604# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005605 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005606# endif
5607#endif
5608 }
5609
5610 /* Nothing special, return global flags field. */
5611 return &options[opt_idx].flags;
5612}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005613#endif
5614
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005615#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005616static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005617
5618/*
5619 * Redraw the window title and/or tab page text later.
5620 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005621static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005622{
5623 need_maketitle = TRUE;
5624# ifdef FEAT_WINDOWS
5625 redraw_tabline = TRUE;
5626# endif
5627}
5628#endif
5629
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630/*
5631 * Set a string option to a new value (without checking the effect).
5632 * The string is copied into allocated memory.
5633 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005634 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005635 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636 */
5637 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005638set_string_option_direct(
5639 char_u *name,
5640 int opt_idx,
5641 char_u *val,
5642 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5643 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005644{
5645 char_u *s;
5646 char_u **varp;
5647 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005648 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649
Bram Moolenaar89d40322006-08-29 15:30:07 +00005650 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005651 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005652 idx = findoption(name);
5653 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005654 {
5655 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005656 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005659 }
5660
Bram Moolenaar89d40322006-08-29 15:30:07 +00005661 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662 return;
5663
5664 s = vim_strsave(val);
5665 if (s != NULL)
5666 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005667 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005669 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670 free_string_option(*varp);
5671 *varp = s;
5672
5673 /* For buffer/window local option may also set the global value. */
5674 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005675 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676
Bram Moolenaar89d40322006-08-29 15:30:07 +00005677 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005678
5679 /* When setting both values of a global option with a local value,
5680 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005681 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682 {
5683 free_string_option(*varp);
5684 *varp = empty_option;
5685 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005686# ifdef FEAT_EVAL
5687 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005688 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005689 set_sid == 0 ? current_SID : set_sid);
5690# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691 }
5692}
5693
5694/*
5695 * Set global value for string option when it's a local option.
5696 */
5697 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005698set_string_option_global(
5699 int opt_idx, /* option index */
5700 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701{
5702 char_u **p, *s;
5703
5704 /* the global value is always allocated */
5705 if (options[opt_idx].var == VAR_WIN)
5706 p = (char_u **)GLOBAL_WO(varp);
5707 else
5708 p = (char_u **)options[opt_idx].var;
5709 if (options[opt_idx].indir != PV_NONE
5710 && p != varp
5711 && (s = vim_strsave(*varp)) != NULL)
5712 {
5713 free_string_option(*p);
5714 *p = s;
5715 }
5716}
5717
5718/*
5719 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005720 *
5721 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005723 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005724set_string_option(
5725 int opt_idx,
5726 char_u *value,
5727 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728{
5729 char_u *s;
5730 char_u **varp;
5731 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005732#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5733 char_u *saved_oldval = NULL;
5734#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005735 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736
5737 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005738 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739
5740 s = vim_strsave(value);
5741 if (s != NULL)
5742 {
5743 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5744 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005745 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746 ? OPT_GLOBAL : OPT_LOCAL)
5747 : opt_flags);
5748 oldval = *varp;
5749 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005750
5751#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005752 if (!starting
5753# ifdef FEAT_CRYPT
5754 && options[opt_idx].indir != PV_KEY
5755# endif
5756 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005757 saved_oldval = vim_strsave(oldval);
5758#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005759 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5760 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005761 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005762
5763 /* call autocomamnd after handling side effects */
5764#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5765 if (saved_oldval != NULL)
5766 {
5767 char_u buf_type[7];
5768 sprintf((char *)buf_type, "%s",
5769 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005770 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5771 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005772 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5773 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5774 reset_v_option_vars();
5775 vim_free(saved_oldval);
5776 }
5777#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005778 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005779 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005780}
5781
5782/*
5783 * Handle string options that need some action to perform when changed.
5784 * Returns NULL for success, or an error message for an error.
5785 */
5786 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005787did_set_string_option(
5788 int opt_idx, /* index in options[] table */
5789 char_u **varp, /* pointer to the option variable */
5790 int new_value_alloced, /* new value was allocated */
5791 char_u *oldval, /* previous value of the option */
5792 char_u *errbuf, /* buffer for errors, or NULL */
5793 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005794{
5795 char_u *errmsg = NULL;
5796 char_u *s, *p;
5797 int did_chartab = FALSE;
5798 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005799 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005800#ifdef FEAT_GUI
5801 /* set when changing an option that only requires a redraw in the GUI */
5802 int redraw_gui_only = FALSE;
5803#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005804
5805 /* Get the global option to compare with, otherwise we would have to check
5806 * two values for all local options. */
5807 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5808
5809 /* Disallow changing some options from secure mode */
5810 if ((secure
5811#ifdef HAVE_SANDBOX
5812 || sandbox != 0
5813#endif
5814 ) && (options[opt_idx].flags & P_SECURE))
5815 {
5816 errmsg = e_secure;
5817 }
5818
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005819 /* Check for a "normal" file name in some options. Disallow a path
5820 * separator (slash and/or backslash), wildcards and characters that are
5821 * often illegal in a file name. */
5822 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005823 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005824 {
5825 errmsg = e_invarg;
5826 }
5827
Bram Moolenaar071d4272004-06-13 20:20:40 +00005828 /* 'term' */
5829 else if (varp == &T_NAME)
5830 {
5831 if (T_NAME[0] == NUL)
5832 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5833#ifdef FEAT_GUI
5834 if (gui.in_use)
5835 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5836 else if (term_is_gui(T_NAME))
5837 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5838#endif
5839 else if (set_termname(T_NAME) == FAIL)
5840 errmsg = (char_u *)N_("E522: Not found in termcap");
5841 else
5842 /* Screen colors may have changed. */
5843 redraw_later_clear();
5844 }
5845
5846 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005847 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005849 char_u *bkc = p_bkc;
5850 unsigned int *flags = &bkc_flags;
5851
5852 if (opt_flags & OPT_LOCAL)
5853 {
5854 bkc = curbuf->b_p_bkc;
5855 flags = &curbuf->b_bkc_flags;
5856 }
5857
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005858 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5859 /* make the local value empty: use the global value */
5860 *flags = 0;
5861 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005862 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005863 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5864 errmsg = e_invarg;
5865 if ((((int)*flags & BKC_AUTO) != 0)
5866 + (((int)*flags & BKC_YES) != 0)
5867 + (((int)*flags & BKC_NO) != 0) != 1)
5868 {
5869 /* Must have exactly one of "auto", "yes" and "no". */
5870 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5871 errmsg = e_invarg;
5872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873 }
5874 }
5875
5876 /* 'backupext' and 'patchmode' */
5877 else if (varp == &p_bex || varp == &p_pm)
5878 {
5879 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5880 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5881 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5882 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005883#ifdef FEAT_LINEBREAK
5884 /* 'breakindentopt' */
5885 else if (varp == &curwin->w_p_briopt)
5886 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005887 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005888 errmsg = e_invarg;
5889 }
5890#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891
5892 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005893 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005895 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 */
5897 else if ( varp == &p_isi
5898 || varp == &(curbuf->b_p_isk)
5899 || varp == &p_isp
5900 || varp == &p_isf)
5901 {
5902 if (init_chartab() == FAIL)
5903 {
5904 did_chartab = TRUE; /* need to restore it below */
5905 errmsg = e_invarg; /* error in value */
5906 }
5907 }
5908
5909 /* 'helpfile' */
5910 else if (varp == &p_hf)
5911 {
5912 /* May compute new values for $VIM and $VIMRUNTIME */
5913 if (didset_vim)
5914 {
5915 vim_setenv((char_u *)"VIM", (char_u *)"");
5916 didset_vim = FALSE;
5917 }
5918 if (didset_vimruntime)
5919 {
5920 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5921 didset_vimruntime = FALSE;
5922 }
5923 }
5924
Bram Moolenaar1a384422010-07-14 19:53:30 +02005925#ifdef FEAT_SYN_HL
5926 /* 'colorcolumn' */
5927 else if (varp == &curwin->w_p_cc)
5928 errmsg = check_colorcolumn(curwin);
5929#endif
5930
Bram Moolenaar071d4272004-06-13 20:20:40 +00005931#ifdef FEAT_MULTI_LANG
5932 /* 'helplang' */
5933 else if (varp == &p_hlg)
5934 {
5935 /* Check for "", "ab", "ab,cd", etc. */
5936 for (s = p_hlg; *s != NUL; s += 3)
5937 {
5938 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5939 {
5940 errmsg = e_invarg;
5941 break;
5942 }
5943 if (s[2] == NUL)
5944 break;
5945 }
5946 }
5947#endif
5948
5949 /* 'highlight' */
5950 else if (varp == &p_hl)
5951 {
5952 if (highlight_changed() == FAIL)
5953 errmsg = e_invarg; /* invalid flags */
5954 }
5955
5956 /* 'nrformats' */
5957 else if (gvarp == &p_nf)
5958 {
5959 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5960 errmsg = e_invarg;
5961 }
5962
5963#ifdef FEAT_SESSION
5964 /* 'sessionoptions' */
5965 else if (varp == &p_ssop)
5966 {
5967 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5968 errmsg = e_invarg;
5969 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5970 {
5971 /* Don't allow both "sesdir" and "curdir". */
5972 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5973 errmsg = e_invarg;
5974 }
5975 }
5976 /* 'viewoptions' */
5977 else if (varp == &p_vop)
5978 {
5979 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5980 errmsg = e_invarg;
5981 }
5982#endif
5983
5984 /* 'scrollopt' */
5985#ifdef FEAT_SCROLLBIND
5986 else if (varp == &p_sbo)
5987 {
5988 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5989 errmsg = e_invarg;
5990 }
5991#endif
5992
5993 /* 'ambiwidth' */
5994#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01005995 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005996 {
5997 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5998 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005999 else if (set_chars_option(&p_lcs) != NULL)
6000 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6001# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6002 else if (set_chars_option(&p_fcs) != NULL)
6003 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6004# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005 }
6006#endif
6007
6008 /* 'background' */
6009 else if (varp == &p_bg)
6010 {
6011 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6012 {
6013#ifdef FEAT_EVAL
6014 int dark = (*p_bg == 'd');
6015#endif
6016
6017 init_highlight(FALSE, FALSE);
6018
6019#ifdef FEAT_EVAL
6020 if (dark != (*p_bg == 'd')
6021 && get_var_value((char_u *)"g:colors_name") != NULL)
6022 {
6023 /* The color scheme must have set 'background' back to another
6024 * value, that's not what we want here. Disable the color
6025 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006026 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006027 free_string_option(p_bg);
6028 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6029 check_string_option(&p_bg);
6030 init_highlight(FALSE, FALSE);
6031 }
6032#endif
6033 }
6034 else
6035 errmsg = e_invarg;
6036 }
6037
6038 /* 'wildmode' */
6039 else if (varp == &p_wim)
6040 {
6041 if (check_opt_wim() == FAIL)
6042 errmsg = e_invarg;
6043 }
6044
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006045#ifdef FEAT_CMDL_COMPL
6046 /* 'wildoptions' */
6047 else if (varp == &p_wop)
6048 {
6049 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6050 errmsg = e_invarg;
6051 }
6052#endif
6053
Bram Moolenaar071d4272004-06-13 20:20:40 +00006054#ifdef FEAT_WAK
6055 /* 'winaltkeys' */
6056 else if (varp == &p_wak)
6057 {
6058 if (*p_wak == NUL
6059 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6060 errmsg = e_invarg;
6061# ifdef FEAT_MENU
6062# ifdef FEAT_GUI_MOTIF
6063 else if (gui.in_use)
6064 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6065# else
6066# ifdef FEAT_GUI_GTK
6067 else if (gui.in_use)
6068 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6069# endif
6070# endif
6071# endif
6072 }
6073#endif
6074
6075#ifdef FEAT_AUTOCMD
6076 /* 'eventignore' */
6077 else if (varp == &p_ei)
6078 {
6079 if (check_ei() == FAIL)
6080 errmsg = e_invarg;
6081 }
6082#endif
6083
6084#ifdef FEAT_MBYTE
6085 /* 'encoding' and 'fileencoding' */
6086 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6087 {
6088 if (gvarp == &p_fenc)
6089 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006090 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006091 errmsg = e_modifiable;
6092 else if (vim_strchr(*varp, ',') != NULL)
6093 /* No comma allowed in 'fileencoding'; catches confusing it
6094 * with 'fileencodings'. */
6095 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006096 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006097 {
6098# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006100 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006102 /* Add 'fileencoding' to the swap file. */
6103 ml_setflags(curbuf);
6104 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 }
6106 if (errmsg == NULL)
6107 {
6108 /* canonize the value, so that STRCMP() can be used on it */
6109 p = enc_canonize(*varp);
6110 if (p != NULL)
6111 {
6112 vim_free(*varp);
6113 *varp = p;
6114 }
6115 if (varp == &p_enc)
6116 {
6117 errmsg = mb_init();
6118# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006119 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006120# endif
6121 }
6122 }
6123
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006124# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006125 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6126 {
6127 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6128 if (STRCMP(p_tenc, "utf-8") != 0)
6129 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6130 }
6131# endif
6132
6133 if (errmsg == NULL)
6134 {
6135# ifdef FEAT_KEYMAP
6136 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6137 * (with another encoding). */
6138 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6139 (void)keymap_init();
6140# endif
6141
6142 /* When 'termencoding' is not empty and 'encoding' changes or when
6143 * 'termencoding' changes, need to setup for keyboard input and
6144 * display output conversion. */
6145 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6146 {
6147 convert_setup(&input_conv, p_tenc, p_enc);
6148 convert_setup(&output_conv, p_enc, p_tenc);
6149 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006150
6151# if defined(WIN3264) && defined(FEAT_MBYTE)
6152 /* $HOME may have characters in active code page. */
6153 if (varp == &p_enc)
6154 init_homedir();
6155# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156 }
6157 }
6158#endif
6159
6160#if defined(FEAT_POSTSCRIPT)
6161 else if (varp == &p_penc)
6162 {
6163 /* Canonize printencoding if VIM standard one */
6164 p = enc_canonize(p_penc);
6165 if (p != NULL)
6166 {
6167 vim_free(p_penc);
6168 p_penc = p;
6169 }
6170 else
6171 {
6172 /* Ensure lower case and '-' for '_' */
6173 for (s = p_penc; *s != NUL; s++)
6174 {
6175 if (*s == '_')
6176 *s = '-';
6177 else
6178 *s = TOLOWER_ASC(*s);
6179 }
6180 }
6181 }
6182#endif
6183
Bram Moolenaar9372a112005-12-06 19:59:18 +00006184#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006185 else if (varp == &p_imak)
6186 {
6187 if (gui.in_use && !im_xim_isvalid_imactivate())
6188 errmsg = e_invarg;
6189 }
6190#endif
6191
6192#ifdef FEAT_KEYMAP
6193 else if (varp == &curbuf->b_p_keymap)
6194 {
6195 /* load or unload key mapping tables */
6196 errmsg = keymap_init();
6197
Bram Moolenaarfab06232009-03-04 03:13:35 +00006198 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006199 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006200 if (*curbuf->b_p_keymap != NUL)
6201 {
6202 /* Installed a new keymap, switch on using it. */
6203 curbuf->b_p_iminsert = B_IMODE_LMAP;
6204 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6205 curbuf->b_p_imsearch = B_IMODE_LMAP;
6206 }
6207 else
6208 {
6209 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6210 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6211 curbuf->b_p_iminsert = B_IMODE_NONE;
6212 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6213 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6214 }
6215 if ((opt_flags & OPT_LOCAL) == 0)
6216 {
6217 set_iminsert_global();
6218 set_imsearch_global();
6219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006220# ifdef FEAT_WINDOWS
6221 status_redraw_curbuf();
6222# endif
6223 }
6224 }
6225#endif
6226
6227 /* 'fileformat' */
6228 else if (gvarp == &p_ff)
6229 {
6230 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6231 errmsg = e_modifiable;
6232 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6233 errmsg = e_invarg;
6234 else
6235 {
6236 /* may also change 'textmode' */
6237 if (get_fileformat(curbuf) == EOL_DOS)
6238 curbuf->b_p_tx = TRUE;
6239 else
6240 curbuf->b_p_tx = FALSE;
6241#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006242 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006243#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006244 /* update flag in swap file */
6245 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006246 /* Redraw needed when switching to/from "mac": a CR in the text
6247 * will be displayed differently. */
6248 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6249 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006250 }
6251 }
6252
6253 /* 'fileformats' */
6254 else if (varp == &p_ffs)
6255 {
6256 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6257 errmsg = e_invarg;
6258 else
6259 {
6260 /* also change 'textauto' */
6261 if (*p_ffs == NUL)
6262 p_ta = FALSE;
6263 else
6264 p_ta = TRUE;
6265 }
6266 }
6267
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006268#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006269 /* 'cryptkey' */
6270 else if (gvarp == &p_key)
6271 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006272# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006273 /* Make sure the ":set" command doesn't show the new value in the
6274 * history. */
6275 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006276# endif
6277 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6278 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006279 ml_set_crypt_key(curbuf, oldval,
6280 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006281 }
6282
6283 else if (gvarp == &p_cm)
6284 {
6285 if (opt_flags & OPT_LOCAL)
6286 p = curbuf->b_p_cm;
6287 else
6288 p = p_cm;
6289 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6290 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006291 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006292 errmsg = e_invarg;
6293 else
6294 {
6295 /* When setting the global value to empty, make it "zip". */
6296 if (*p_cm == NUL)
6297 {
6298 if (new_value_alloced)
6299 free_string_option(p_cm);
6300 p_cm = vim_strsave((char_u *)"zip");
6301 new_value_alloced = TRUE;
6302 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006303 /* When using ":set cm=name" the local value is going to be empty.
6304 * Do that here, otherwise the crypt functions will still use the
6305 * local value. */
6306 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6307 {
6308 free_string_option(curbuf->b_p_cm);
6309 curbuf->b_p_cm = empty_option;
6310 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006311
6312 /* Need to update the swapfile when the effective method changed.
6313 * Set "s" to the effective old value, "p" to the effective new
6314 * method and compare. */
6315 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6316 s = p_cm; /* was previously using the global value */
6317 else
6318 s = oldval;
6319 if (*curbuf->b_p_cm == NUL)
6320 p = p_cm; /* is now using the global value */
6321 else
6322 p = curbuf->b_p_cm;
6323 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006324 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006325
6326 /* If the global value changes need to update the swapfile for all
6327 * buffers using that value. */
6328 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6329 {
6330 buf_T *buf;
6331
6332 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6333 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006334 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006335 }
6336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006337 }
6338#endif
6339
6340 /* 'matchpairs' */
6341 else if (gvarp == &p_mps)
6342 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006343#ifdef FEAT_MBYTE
6344 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006345 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006346 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006347 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006348 int x2 = -1;
6349 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006350
6351 if (*p != NUL)
6352 p += mb_ptr2len(p);
6353 if (*p != NUL)
6354 x2 = *p++;
6355 if (*p != NUL)
6356 {
6357 x3 = mb_ptr2char(p);
6358 p += mb_ptr2len(p);
6359 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006360 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006361 {
6362 errmsg = e_invarg;
6363 break;
6364 }
6365 if (*p == NUL)
6366 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006367 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006368 }
6369 else
6370#endif
6371 {
6372 /* Check for "x:y,x:y" */
6373 for (p = *varp; *p != NUL; p += 4)
6374 {
6375 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6376 {
6377 errmsg = e_invarg;
6378 break;
6379 }
6380 if (p[3] == NUL)
6381 break;
6382 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 }
6384 }
6385
6386#ifdef FEAT_COMMENTS
6387 /* 'comments' */
6388 else if (gvarp == &p_com)
6389 {
6390 for (s = *varp; *s; )
6391 {
6392 while (*s && *s != ':')
6393 {
6394 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6395 && !VIM_ISDIGIT(*s) && *s != '-')
6396 {
6397 errmsg = illegal_char(errbuf, *s);
6398 break;
6399 }
6400 ++s;
6401 }
6402 if (*s++ == NUL)
6403 errmsg = (char_u *)N_("E524: Missing colon");
6404 else if (*s == ',' || *s == NUL)
6405 errmsg = (char_u *)N_("E525: Zero length string");
6406 if (errmsg != NULL)
6407 break;
6408 while (*s && *s != ',')
6409 {
6410 if (*s == '\\' && s[1] != NUL)
6411 ++s;
6412 ++s;
6413 }
6414 s = skip_to_option_part(s);
6415 }
6416 }
6417#endif
6418
6419 /* 'listchars' */
6420 else if (varp == &p_lcs)
6421 {
6422 errmsg = set_chars_option(varp);
6423 }
6424
6425#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6426 /* 'fillchars' */
6427 else if (varp == &p_fcs)
6428 {
6429 errmsg = set_chars_option(varp);
6430 }
6431#endif
6432
6433#ifdef FEAT_CMDWIN
6434 /* 'cedit' */
6435 else if (varp == &p_cedit)
6436 {
6437 errmsg = check_cedit();
6438 }
6439#endif
6440
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006441 /* 'verbosefile' */
6442 else if (varp == &p_vfile)
6443 {
6444 verbose_stop();
6445 if (*p_vfile != NUL && verbose_open() == FAIL)
6446 errmsg = e_invarg;
6447 }
6448
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449#ifdef FEAT_VIMINFO
6450 /* 'viminfo' */
6451 else if (varp == &p_viminfo)
6452 {
6453 for (s = p_viminfo; *s;)
6454 {
6455 /* Check it's a valid character */
6456 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6457 {
6458 errmsg = illegal_char(errbuf, *s);
6459 break;
6460 }
6461 if (*s == 'n') /* name is always last one */
6462 {
6463 break;
6464 }
6465 else if (*s == 'r') /* skip until next ',' */
6466 {
6467 while (*++s && *s != ',')
6468 ;
6469 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006470 else if (*s == '%')
6471 {
6472 /* optional number */
6473 while (vim_isdigit(*++s))
6474 ;
6475 }
6476 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006477 ++s; /* no extra chars */
6478 else /* must have a number */
6479 {
6480 while (vim_isdigit(*++s))
6481 ;
6482
6483 if (!VIM_ISDIGIT(*(s - 1)))
6484 {
6485 if (errbuf != NULL)
6486 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006487 sprintf((char *)errbuf,
6488 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006489 transchar_byte(*(s - 1)));
6490 errmsg = errbuf;
6491 }
6492 else
6493 errmsg = (char_u *)"";
6494 break;
6495 }
6496 }
6497 if (*s == ',')
6498 ++s;
6499 else if (*s)
6500 {
6501 if (errbuf != NULL)
6502 errmsg = (char_u *)N_("E527: Missing comma");
6503 else
6504 errmsg = (char_u *)"";
6505 break;
6506 }
6507 }
6508 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6509 errmsg = (char_u *)N_("E528: Must specify a ' value");
6510 }
6511#endif /* FEAT_VIMINFO */
6512
6513 /* terminal options */
6514 else if (istermoption(&options[opt_idx]) && full_screen)
6515 {
6516 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6517 if (varp == &T_CCO)
6518 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006519 int colors = atoi((char *)T_CCO);
6520
6521 /* Only reinitialize colors if t_Co value has really changed to
6522 * avoid expensive reload of colorscheme if t_Co is set to the
6523 * same value multiple times. */
6524 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006525 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006526 t_colors = colors;
6527 if (t_colors <= 1)
6528 {
6529 if (new_value_alloced)
6530 vim_free(T_CCO);
6531 T_CCO = empty_option;
6532 }
6533 /* We now have a different color setup, initialize it again. */
6534 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006535 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006536 }
6537 ttest(FALSE);
6538 if (varp == &T_ME)
6539 {
6540 out_str(T_ME);
6541 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006542#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006543 /* Since t_me has been set, this probably means that the user
6544 * wants to use this as default colors. Need to reset default
6545 * background/foreground colors. */
6546 mch_set_normal_colors();
6547#endif
6548 }
6549 }
6550
6551#ifdef FEAT_LINEBREAK
6552 /* 'showbreak' */
6553 else if (varp == &p_sbr)
6554 {
6555 for (s = p_sbr; *s; )
6556 {
6557 if (ptr2cells(s) != 1)
6558 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006559 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006560 }
6561 }
6562#endif
6563
6564#ifdef FEAT_GUI
6565 /* 'guifont' */
6566 else if (varp == &p_guifont)
6567 {
6568 if (gui.in_use)
6569 {
6570 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006571# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006572 /*
6573 * Put up a font dialog and let the user select a new value.
6574 * If this is cancelled go back to the old value but don't
6575 * give an error message.
6576 */
6577 if (STRCMP(p, "*") == 0)
6578 {
6579 p = gui_mch_font_dialog(oldval);
6580
6581 if (new_value_alloced)
6582 free_string_option(p_guifont);
6583
6584 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6585 new_value_alloced = TRUE;
6586 }
6587# endif
6588 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6589 {
6590# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6591 if (STRCMP(p_guifont, "*") == 0)
6592 {
6593 /* Dialog was cancelled: Keep the old value without giving
6594 * an error message. */
6595 if (new_value_alloced)
6596 free_string_option(p_guifont);
6597 p_guifont = vim_strsave(oldval);
6598 new_value_alloced = TRUE;
6599 }
6600 else
6601# endif
6602 errmsg = (char_u *)N_("E596: Invalid font(s)");
6603 }
6604 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006605 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 }
6607# ifdef FEAT_XFONTSET
6608 else if (varp == &p_guifontset)
6609 {
6610 if (STRCMP(p_guifontset, "*") == 0)
6611 errmsg = (char_u *)N_("E597: can't select fontset");
6612 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6613 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006614 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006615 }
6616# endif
6617# ifdef FEAT_MBYTE
6618 else if (varp == &p_guifontwide)
6619 {
6620 if (STRCMP(p_guifontwide, "*") == 0)
6621 errmsg = (char_u *)N_("E533: can't select wide font");
6622 else if (gui_get_wide_font() == FAIL)
6623 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006624 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006625 }
6626# endif
6627#endif
6628
6629#ifdef CURSOR_SHAPE
6630 /* 'guicursor' */
6631 else if (varp == &p_guicursor)
6632 errmsg = parse_shape_opt(SHAPE_CURSOR);
6633#endif
6634
6635#ifdef FEAT_MOUSESHAPE
6636 /* 'mouseshape' */
6637 else if (varp == &p_mouseshape)
6638 {
6639 errmsg = parse_shape_opt(SHAPE_MOUSE);
6640 update_mouseshape(-1);
6641 }
6642#endif
6643
6644#ifdef FEAT_PRINTER
6645 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006646 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006647# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006648 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006649 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006650# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006651#endif
6652
6653#ifdef FEAT_LANGMAP
6654 /* 'langmap' */
6655 else if (varp == &p_langmap)
6656 langmap_set();
6657#endif
6658
6659#ifdef FEAT_LINEBREAK
6660 /* 'breakat' */
6661 else if (varp == &p_breakat)
6662 fill_breakat_flags();
6663#endif
6664
6665#ifdef FEAT_TITLE
6666 /* 'titlestring' and 'iconstring' */
6667 else if (varp == &p_titlestring || varp == &p_iconstring)
6668 {
6669# ifdef FEAT_STL_OPT
6670 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6671
6672 /* NULL => statusline syntax */
6673 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6674 stl_syntax |= flagval;
6675 else
6676 stl_syntax &= ~flagval;
6677# endif
6678 did_set_title(varp == &p_iconstring);
6679
6680 }
6681#endif
6682
6683#ifdef FEAT_GUI
6684 /* 'guioptions' */
6685 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006686 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006687 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006688 redraw_gui_only = TRUE;
6689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006690#endif
6691
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006692#if defined(FEAT_GUI_TABLINE)
6693 /* 'guitablabel' */
6694 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006695 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006696 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006697 redraw_gui_only = TRUE;
6698 }
6699 /* 'guitabtooltip' */
6700 else if (varp == &p_gtt)
6701 {
6702 redraw_gui_only = TRUE;
6703 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006704#endif
6705
Bram Moolenaar071d4272004-06-13 20:20:40 +00006706#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6707 /* 'ttymouse' */
6708 else if (varp == &p_ttym)
6709 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006710 /* Switch the mouse off before changing the escape sequences used for
6711 * that. */
6712 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006713 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6714 errmsg = e_invarg;
6715 else
6716 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006717 if (termcap_active)
6718 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719 }
6720#endif
6721
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722 /* 'selection' */
6723 else if (varp == &p_sel)
6724 {
6725 if (*p_sel == NUL
6726 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6727 errmsg = e_invarg;
6728 }
6729
6730 /* 'selectmode' */
6731 else if (varp == &p_slm)
6732 {
6733 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6734 errmsg = e_invarg;
6735 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006736
6737#ifdef FEAT_BROWSE
6738 /* 'browsedir' */
6739 else if (varp == &p_bsdir)
6740 {
6741 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6742 && !mch_isdir(p_bsdir))
6743 errmsg = e_invarg;
6744 }
6745#endif
6746
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747 /* 'keymodel' */
6748 else if (varp == &p_km)
6749 {
6750 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6751 errmsg = e_invarg;
6752 else
6753 {
6754 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6755 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6756 }
6757 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758
6759 /* 'mousemodel' */
6760 else if (varp == &p_mousem)
6761 {
6762 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6763 errmsg = e_invarg;
6764#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6765 else if (*p_mousem != *oldval)
6766 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6767 * to create or delete the popup menus. */
6768 gui_motif_update_mousemodel(root_menu);
6769#endif
6770 }
6771
6772 /* 'switchbuf' */
6773 else if (varp == &p_swb)
6774 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006775 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006776 errmsg = e_invarg;
6777 }
6778
6779 /* 'debug' */
6780 else if (varp == &p_debug)
6781 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006782 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 errmsg = e_invarg;
6784 }
6785
6786 /* 'display' */
6787 else if (varp == &p_dy)
6788 {
6789 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6790 errmsg = e_invarg;
6791 else
6792 (void)init_chartab();
6793
6794 }
6795
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006796#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006797 /* 'eadirection' */
6798 else if (varp == &p_ead)
6799 {
6800 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6801 errmsg = e_invarg;
6802 }
6803#endif
6804
6805#ifdef FEAT_CLIPBOARD
6806 /* 'clipboard' */
6807 else if (varp == &p_cb)
6808 errmsg = check_clipboard_option();
6809#endif
6810
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006811#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006812 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6813 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006814 else if (varp == &(curwin->w_s->b_p_spl)
6815 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006816 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006817 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006818 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006819 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006820 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006821 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006822 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006823 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006824 /* 'spellsuggest' */
6825 else if (varp == &p_sps)
6826 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006827 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006828 errmsg = e_invarg;
6829 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006830 /* 'mkspellmem' */
6831 else if (varp == &p_msm)
6832 {
6833 if (spell_check_msm() != OK)
6834 errmsg = e_invarg;
6835 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006836#endif
6837
Bram Moolenaar071d4272004-06-13 20:20:40 +00006838#ifdef FEAT_QUICKFIX
6839 /* When 'bufhidden' is set, check for valid value. */
6840 else if (gvarp == &p_bh)
6841 {
6842 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6843 errmsg = e_invarg;
6844 }
6845
6846 /* When 'buftype' is set, check for valid value. */
6847 else if (gvarp == &p_bt)
6848 {
6849 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6850 errmsg = e_invarg;
6851 else
6852 {
6853# ifdef FEAT_WINDOWS
6854 if (curwin->w_status_height)
6855 {
6856 curwin->w_redr_status = TRUE;
6857 redraw_later(VALID);
6858 }
6859# endif
6860 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006861# ifdef FEAT_TITLE
6862 redraw_titles();
6863# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006864 }
6865 }
6866#endif
6867
6868#ifdef FEAT_STL_OPT
6869 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006870 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871 {
6872 int wid;
6873
6874 if (varp == &p_ruf) /* reset ru_wid first */
6875 ru_wid = 0;
6876 s = *varp;
6877 if (varp == &p_ruf && *s == '%')
6878 {
6879 /* set ru_wid if 'ruf' starts with "%99(" */
6880 if (*++s == '-') /* ignore a '-' */
6881 s++;
6882 wid = getdigits(&s);
6883 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6884 ru_wid = wid;
6885 else
6886 errmsg = check_stl_option(p_ruf);
6887 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006888 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006889 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006890 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006891 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006892 comp_col();
6893 }
6894#endif
6895
6896#ifdef FEAT_INS_EXPAND
6897 /* check if it is a valid value for 'complete' -- Acevedo */
6898 else if (gvarp == &p_cpt)
6899 {
6900 for (s = *varp; *s;)
6901 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006902 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903 s++;
6904 if (!*s)
6905 break;
6906 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6907 {
6908 errmsg = illegal_char(errbuf, *s);
6909 break;
6910 }
6911 if (*++s != NUL && *s != ',' && *s != ' ')
6912 {
6913 if (s[-1] == 'k' || s[-1] == 's')
6914 {
6915 /* skip optional filename after 'k' and 's' */
6916 while (*s && *s != ',' && *s != ' ')
6917 {
6918 if (*s == '\\')
6919 ++s;
6920 ++s;
6921 }
6922 }
6923 else
6924 {
6925 if (errbuf != NULL)
6926 {
6927 sprintf((char *)errbuf,
6928 _("E535: Illegal character after <%c>"),
6929 *--s);
6930 errmsg = errbuf;
6931 }
6932 else
6933 errmsg = (char_u *)"";
6934 break;
6935 }
6936 }
6937 }
6938 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006939
6940 /* 'completeopt' */
6941 else if (varp == &p_cot)
6942 {
6943 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6944 errmsg = e_invarg;
6945 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946#endif /* FEAT_INS_EXPAND */
6947
6948
6949#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6950 else if (varp == &p_toolbar)
6951 {
6952 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6953 &toolbar_flags, TRUE) != OK)
6954 errmsg = e_invarg;
6955 else
6956 {
6957 out_flush();
6958 gui_mch_show_toolbar((toolbar_flags &
6959 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6960 }
6961 }
6962#endif
6963
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006964#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965 /* 'toolbariconsize': GTK+ 2 only */
6966 else if (varp == &p_tbis)
6967 {
6968 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6969 errmsg = e_invarg;
6970 else
6971 {
6972 out_flush();
6973 gui_mch_show_toolbar((toolbar_flags &
6974 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6975 }
6976 }
6977#endif
6978
6979 /* 'pastetoggle': translate key codes like in a mapping */
6980 else if (varp == &p_pt)
6981 {
6982 if (*p_pt)
6983 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006984 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985 if (p != NULL)
6986 {
6987 if (new_value_alloced)
6988 free_string_option(p_pt);
6989 p_pt = p;
6990 new_value_alloced = TRUE;
6991 }
6992 }
6993 }
6994
6995 /* 'backspace' */
6996 else if (varp == &p_bs)
6997 {
6998 if (VIM_ISDIGIT(*p_bs))
6999 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007000 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007001 errmsg = e_invarg;
7002 }
7003 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7004 errmsg = e_invarg;
7005 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007006 else if (varp == &p_bo)
7007 {
7008 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7009 errmsg = e_invarg;
7010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007012 /* 'tagcase' */
7013 else if (gvarp == &p_tc)
7014 {
7015 unsigned int *flags;
7016
7017 if (opt_flags & OPT_LOCAL)
7018 {
7019 p = curbuf->b_p_tc;
7020 flags = &curbuf->b_tc_flags;
7021 }
7022 else
7023 {
7024 p = p_tc;
7025 flags = &tc_flags;
7026 }
7027
7028 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7029 /* make the local value empty: use the global value */
7030 *flags = 0;
7031 else if (*p == NUL
7032 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7033 errmsg = e_invarg;
7034 }
7035
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007036#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007037 /* 'casemap' */
7038 else if (varp == &p_cmp)
7039 {
7040 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7041 errmsg = e_invarg;
7042 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007043#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044
7045#ifdef FEAT_DIFF
7046 /* 'diffopt' */
7047 else if (varp == &p_dip)
7048 {
7049 if (diffopt_changed() == FAIL)
7050 errmsg = e_invarg;
7051 }
7052#endif
7053
7054#ifdef FEAT_FOLDING
7055 /* 'foldmethod' */
7056 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7057 {
7058 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7059 || *curwin->w_p_fdm == NUL)
7060 errmsg = e_invarg;
7061 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007062 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007064 if (foldmethodIsDiff(curwin))
7065 newFoldLevel();
7066 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067 }
7068# ifdef FEAT_EVAL
7069 /* 'foldexpr' */
7070 else if (varp == &curwin->w_p_fde)
7071 {
7072 if (foldmethodIsExpr(curwin))
7073 foldUpdateAll(curwin);
7074 }
7075# endif
7076 /* 'foldmarker' */
7077 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7078 {
7079 p = vim_strchr(*varp, ',');
7080 if (p == NULL)
7081 errmsg = (char_u *)N_("E536: comma required");
7082 else if (p == *varp || p[1] == NUL)
7083 errmsg = e_invarg;
7084 else if (foldmethodIsMarker(curwin))
7085 foldUpdateAll(curwin);
7086 }
7087 /* 'commentstring' */
7088 else if (gvarp == &p_cms)
7089 {
7090 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7091 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7092 }
7093 /* 'foldopen' */
7094 else if (varp == &p_fdo)
7095 {
7096 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7097 errmsg = e_invarg;
7098 }
7099 /* 'foldclose' */
7100 else if (varp == &p_fcl)
7101 {
7102 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7103 errmsg = e_invarg;
7104 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007105 /* 'foldignore' */
7106 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7107 {
7108 if (foldmethodIsIndent(curwin))
7109 foldUpdateAll(curwin);
7110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111#endif
7112
7113#ifdef FEAT_VIRTUALEDIT
7114 /* 'virtualedit' */
7115 else if (varp == &p_ve)
7116 {
7117 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7118 errmsg = e_invarg;
7119 else if (STRCMP(p_ve, oldval) != 0)
7120 {
7121 /* Recompute cursor position in case the new 've' setting
7122 * changes something. */
7123 validate_virtcol();
7124 coladvance(curwin->w_virtcol);
7125 }
7126 }
7127#endif
7128
7129#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7130 else if (varp == &p_csqf)
7131 {
7132 if (p_csqf != NULL)
7133 {
7134 p = p_csqf;
7135 while (*p != NUL)
7136 {
7137 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7138 || p[1] == NUL
7139 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7140 || (p[2] != NUL && p[2] != ','))
7141 {
7142 errmsg = e_invarg;
7143 break;
7144 }
7145 else if (p[2] == NUL)
7146 break;
7147 else
7148 p += 3;
7149 }
7150 }
7151 }
7152#endif
7153
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007154#ifdef FEAT_CINDENT
7155 /* 'cinoptions' */
7156 else if (gvarp == &p_cino)
7157 {
7158 /* TODO: recognize errors */
7159 parse_cino(curbuf);
7160 }
7161#endif
7162
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007163#if defined(FEAT_RENDER_OPTIONS)
7164 else if (varp == &p_rop && gui.in_use)
7165 {
7166 if (!gui_mch_set_rendering_options(p_rop))
7167 errmsg = e_invarg;
7168 }
7169#endif
7170
Bram Moolenaar071d4272004-06-13 20:20:40 +00007171 /* Options that are a list of flags. */
7172 else
7173 {
7174 p = NULL;
7175 if (varp == &p_ww)
7176 p = (char_u *)WW_ALL;
7177 if (varp == &p_shm)
7178 p = (char_u *)SHM_ALL;
7179 else if (varp == &(p_cpo))
7180 p = (char_u *)CPO_ALL;
7181 else if (varp == &(curbuf->b_p_fo))
7182 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007183#ifdef FEAT_CONCEAL
7184 else if (varp == &curwin->w_p_cocu)
7185 p = (char_u *)COCU_ALL;
7186#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007187 else if (varp == &p_mouse)
7188 {
7189#ifdef FEAT_MOUSE
7190 p = (char_u *)MOUSE_ALL;
7191#else
7192 if (*p_mouse != NUL)
7193 errmsg = (char_u *)N_("E538: No mouse support");
7194#endif
7195 }
7196#if defined(FEAT_GUI)
7197 else if (varp == &p_go)
7198 p = (char_u *)GO_ALL;
7199#endif
7200 if (p != NULL)
7201 {
7202 for (s = *varp; *s; ++s)
7203 if (vim_strchr(p, *s) == NULL)
7204 {
7205 errmsg = illegal_char(errbuf, *s);
7206 break;
7207 }
7208 }
7209 }
7210
7211 /*
7212 * If error detected, restore the previous value.
7213 */
7214 if (errmsg != NULL)
7215 {
7216 if (new_value_alloced)
7217 free_string_option(*varp);
7218 *varp = oldval;
7219 /*
7220 * When resetting some values, need to act on it.
7221 */
7222 if (did_chartab)
7223 (void)init_chartab();
7224 if (varp == &p_hl)
7225 (void)highlight_changed();
7226 }
7227 else
7228 {
7229#ifdef FEAT_EVAL
7230 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007231 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007232#endif
7233 /*
7234 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007235 * Use "free_oldval", because recursiveness may change the flags under
7236 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007237 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007238 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007239 free_string_option(oldval);
7240 if (new_value_alloced)
7241 options[opt_idx].flags |= P_ALLOCED;
7242 else
7243 options[opt_idx].flags &= ~P_ALLOCED;
7244
7245 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007246 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247 {
7248 /* global option with local value set to use global value; free
7249 * the local value and make it empty */
7250 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7251 free_string_option(*(char_u **)p);
7252 *(char_u **)p = empty_option;
7253 }
7254
7255 /* May set global value for local option. */
7256 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7257 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007258
7259#ifdef FEAT_AUTOCMD
7260 /*
7261 * Trigger the autocommand only after setting the flags.
7262 */
7263# ifdef FEAT_SYN_HL
7264 /* When 'syntax' is set, load the syntax of that name */
7265 if (varp == &(curbuf->b_p_syn))
7266 {
7267 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7268 curbuf->b_fname, TRUE, curbuf);
7269 }
7270# endif
7271 else if (varp == &(curbuf->b_p_ft))
7272 {
7273 /* 'filetype' is set, trigger the FileType autocommand */
7274 did_filetype = TRUE;
7275 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7276 curbuf->b_fname, TRUE, curbuf);
7277 }
7278#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007279#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007280 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007281 {
7282 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007283 char_u *q = curwin->w_s->b_p_spl;
7284
7285 /* Skip the first name if it is "cjk". */
7286 if (STRNCMP(q, "cjk,", 4) == 0)
7287 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007288
7289 /*
7290 * Source the spell/LANG.vim in 'runtimepath'.
7291 * They could set 'spellcapcheck' depending on the language.
7292 * Use the first name in 'spelllang' up to '_region' or
7293 * '.encoding'.
7294 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007295 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007296 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7297 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007298 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007299 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007300 }
7301#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007302 }
7303
7304#ifdef FEAT_MOUSE
7305 if (varp == &p_mouse)
7306 {
7307# ifdef FEAT_MOUSE_TTY
7308 if (*p_mouse == NUL)
7309 mch_setmouse(FALSE); /* switch mouse off */
7310 else
7311# endif
7312 setmouse(); /* in case 'mouse' changed */
7313 }
7314#endif
7315
Bram Moolenaar913077c2012-03-28 19:59:04 +02007316 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007317 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007318 curwin->w_set_curswant = TRUE;
7319
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007320#ifdef FEAT_GUI
7321 /* check redraw when it's not a GUI option or the GUI is active. */
7322 if (!redraw_gui_only || gui.in_use)
7323#endif
7324 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007325
7326 return errmsg;
7327}
7328
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007329#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007330/*
7331 * Simple int comparison function for use with qsort()
7332 */
7333 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007334int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007335{
7336 return *(const int *)a - *(const int *)b;
7337}
7338
7339/*
7340 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7341 * Returns error message, NULL if it's OK.
7342 */
7343 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007344check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007345{
7346 char_u *s;
7347 int col;
7348 int count = 0;
7349 int color_cols[256];
7350 int i;
7351 int j = 0;
7352
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007353 if (wp->w_buffer == NULL)
7354 return NULL; /* buffer was closed */
7355
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007356 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007357 {
7358 if (*s == '-' || *s == '+')
7359 {
7360 /* -N and +N: add to 'textwidth' */
7361 col = (*s == '-') ? -1 : 1;
7362 ++s;
7363 if (!VIM_ISDIGIT(*s))
7364 return e_invarg;
7365 col = col * getdigits(&s);
7366 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007367 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007368 col += wp->w_buffer->b_p_tw;
7369 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007370 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007371 }
7372 else if (VIM_ISDIGIT(*s))
7373 col = getdigits(&s);
7374 else
7375 return e_invarg;
7376 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007377skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007378 if (*s == NUL)
7379 break;
7380 if (*s != ',')
7381 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007382 if (*++s == NUL)
7383 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007384 }
7385
7386 vim_free(wp->w_p_cc_cols);
7387 if (count == 0)
7388 wp->w_p_cc_cols = NULL;
7389 else
7390 {
7391 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7392 if (wp->w_p_cc_cols != NULL)
7393 {
7394 /* sort the columns for faster usage on screen redraw inside
7395 * win_line() */
7396 qsort(color_cols, count, sizeof(int), int_cmp);
7397
7398 for (i = 0; i < count; ++i)
7399 /* skip duplicates */
7400 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7401 wp->w_p_cc_cols[j++] = color_cols[i];
7402 wp->w_p_cc_cols[j] = -1; /* end marker */
7403 }
7404 }
7405
7406 return NULL; /* no error */
7407}
7408#endif
7409
Bram Moolenaar071d4272004-06-13 20:20:40 +00007410/*
7411 * Handle setting 'listchars' or 'fillchars'.
7412 * Returns error message, NULL if it's OK.
7413 */
7414 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007415set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007416{
7417 int round, i, len, entries;
7418 char_u *p, *s;
7419 int c1, c2 = 0;
7420 struct charstab
7421 {
7422 int *cp;
7423 char *name;
7424 };
7425#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7426 static struct charstab filltab[] =
7427 {
7428 {&fill_stl, "stl"},
7429 {&fill_stlnc, "stlnc"},
7430 {&fill_vert, "vert"},
7431 {&fill_fold, "fold"},
7432 {&fill_diff, "diff"},
7433 };
7434#endif
7435 static struct charstab lcstab[] =
7436 {
7437 {&lcs_eol, "eol"},
7438 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007439 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007440 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007441 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007442 {&lcs_tab2, "tab"},
7443 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007444#ifdef FEAT_CONCEAL
7445 {&lcs_conceal, "conceal"},
7446#else
7447 {NULL, "conceal"},
7448#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449 };
7450 struct charstab *tab;
7451
7452#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7453 if (varp == &p_lcs)
7454#endif
7455 {
7456 tab = lcstab;
7457 entries = sizeof(lcstab) / sizeof(struct charstab);
7458 }
7459#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7460 else
7461 {
7462 tab = filltab;
7463 entries = sizeof(filltab) / sizeof(struct charstab);
7464 }
7465#endif
7466
7467 /* first round: check for valid value, second round: assign values */
7468 for (round = 0; round <= 1; ++round)
7469 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007470 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007471 {
7472 /* After checking that the value is valid: set defaults: space for
7473 * 'fillchars', NUL for 'listchars' */
7474 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007475 if (tab[i].cp != NULL)
7476 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477 if (varp == &p_lcs)
7478 lcs_tab1 = NUL;
7479#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7480 else
7481 fill_diff = '-';
7482#endif
7483 }
7484 p = *varp;
7485 while (*p)
7486 {
7487 for (i = 0; i < entries; ++i)
7488 {
7489 len = (int)STRLEN(tab[i].name);
7490 if (STRNCMP(p, tab[i].name, len) == 0
7491 && p[len] == ':'
7492 && p[len + 1] != NUL)
7493 {
7494 s = p + len + 1;
7495#ifdef FEAT_MBYTE
7496 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007497 if (mb_char2cells(c1) > 1)
7498 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499#else
7500 c1 = *s++;
7501#endif
7502 if (tab[i].cp == &lcs_tab2)
7503 {
7504 if (*s == NUL)
7505 continue;
7506#ifdef FEAT_MBYTE
7507 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007508 if (mb_char2cells(c2) > 1)
7509 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510#else
7511 c2 = *s++;
7512#endif
7513 }
7514 if (*s == ',' || *s == NUL)
7515 {
7516 if (round)
7517 {
7518 if (tab[i].cp == &lcs_tab2)
7519 {
7520 lcs_tab1 = c1;
7521 lcs_tab2 = c2;
7522 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007523 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007524 *(tab[i].cp) = c1;
7525
7526 }
7527 p = s;
7528 break;
7529 }
7530 }
7531 }
7532
7533 if (i == entries)
7534 return e_invarg;
7535 if (*p == ',')
7536 ++p;
7537 }
7538 }
7539
7540 return NULL; /* no error */
7541}
7542
7543#ifdef FEAT_STL_OPT
7544/*
7545 * Check validity of options with the 'statusline' format.
7546 * Return error message or NULL.
7547 */
7548 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007549check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007550{
7551 int itemcnt = 0;
7552 int groupdepth = 0;
7553 static char_u errbuf[80];
7554
7555 while (*s && itemcnt < STL_MAX_ITEM)
7556 {
7557 /* Check for valid keys after % sequences */
7558 while (*s && *s != '%')
7559 s++;
7560 if (!*s)
7561 break;
7562 s++;
7563 if (*s != '%' && *s != ')')
7564 ++itemcnt;
7565 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7566 {
7567 s++;
7568 continue;
7569 }
7570 if (*s == ')')
7571 {
7572 s++;
7573 if (--groupdepth < 0)
7574 break;
7575 continue;
7576 }
7577 if (*s == '-')
7578 s++;
7579 while (VIM_ISDIGIT(*s))
7580 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007581 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007582 continue;
7583 if (*s == '.')
7584 {
7585 s++;
7586 while (*s && VIM_ISDIGIT(*s))
7587 s++;
7588 }
7589 if (*s == '(')
7590 {
7591 groupdepth++;
7592 continue;
7593 }
7594 if (vim_strchr(STL_ALL, *s) == NULL)
7595 {
7596 return illegal_char(errbuf, *s);
7597 }
7598 if (*s == '{')
7599 {
7600 s++;
7601 while (*s != '}' && *s)
7602 s++;
7603 if (*s != '}')
7604 return (char_u *)N_("E540: Unclosed expression sequence");
7605 }
7606 }
7607 if (itemcnt >= STL_MAX_ITEM)
7608 return (char_u *)N_("E541: too many items");
7609 if (groupdepth != 0)
7610 return (char_u *)N_("E542: unbalanced groups");
7611 return NULL;
7612}
7613#endif
7614
7615#ifdef FEAT_CLIPBOARD
7616/*
7617 * Extract the items in the 'clipboard' option and set global values.
7618 */
7619 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007620check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007622 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007623 int new_autoselect_star = FALSE;
7624 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007625 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007626 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007627 regprog_T *new_exclude_prog = NULL;
7628 char_u *errmsg = NULL;
7629 char_u *p;
7630
7631 for (p = p_cb; *p != NUL; )
7632 {
7633 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7634 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007635 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636 p += 7;
7637 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007638 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007639 && (p[11] == ',' || p[11] == NUL))
7640 {
7641 new_unnamed |= CLIP_UNNAMED_PLUS;
7642 p += 11;
7643 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007644 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007645 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007646 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007647 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007648 p += 10;
7649 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007650 else if (STRNCMP(p, "autoselectplus", 14) == 0
7651 && (p[14] == ',' || p[14] == NUL))
7652 {
7653 new_autoselect_plus = TRUE;
7654 p += 14;
7655 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007656 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007657 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007658 {
7659 new_autoselectml = TRUE;
7660 p += 12;
7661 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007662 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7663 {
7664 new_html = TRUE;
7665 p += 4;
7666 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007667 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7668 {
7669 p += 8;
7670 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7671 if (new_exclude_prog == NULL)
7672 errmsg = e_invarg;
7673 break;
7674 }
7675 else
7676 {
7677 errmsg = e_invarg;
7678 break;
7679 }
7680 if (*p == ',')
7681 ++p;
7682 }
7683 if (errmsg == NULL)
7684 {
7685 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007686 clip_autoselect_star = new_autoselect_star;
7687 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007688 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007689 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007690 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007692#ifdef FEAT_GUI_GTK
7693 if (gui.in_use)
7694 {
7695 gui_gtk_set_selection_targets();
7696 gui_gtk_set_dnd_targets();
7697 }
7698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007699 }
7700 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007701 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007702
7703 return errmsg;
7704}
7705#endif
7706
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007707#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007708 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007709did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007710{
7711 char_u *errmsg = NULL;
7712 win_T *wp;
7713 int l;
7714
7715 if (is_spellfile)
7716 {
7717 l = (int)STRLEN(curwin->w_s->b_p_spf);
7718 if (l > 0 && (l < 4
7719 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7720 errmsg = e_invarg;
7721 }
7722
7723 if (errmsg == NULL)
7724 {
7725 FOR_ALL_WINDOWS(wp)
7726 if (wp->w_buffer == curbuf && wp->w_p_spell)
7727 {
7728 errmsg = did_set_spelllang(wp);
7729# ifdef FEAT_WINDOWS
7730 break;
7731# endif
7732 }
7733 }
7734 return errmsg;
7735}
7736
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007737/*
7738 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7739 * Return error message when failed, NULL when OK.
7740 */
7741 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007742compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007743{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007744 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007745 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007746
Bram Moolenaar860cae12010-06-05 23:22:07 +02007747 if (*synblock->b_p_spc == NUL)
7748 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007749 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007750 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007751 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007752 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007753 if (re != NULL)
7754 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007755 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007756 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007757 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007758 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007759 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007760 return e_invarg;
7761 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007762 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007763 }
7764
Bram Moolenaar473de612013-06-08 18:19:48 +02007765 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007766 return NULL;
7767}
7768#endif
7769
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007770#if defined(FEAT_EVAL) || defined(PROTO)
7771/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007772 * Set the scriptID for an option, taking care of setting the buffer- or
7773 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007774 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007775 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007776set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007777{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007778 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7779 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007780
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007781 /* Remember where the option was set. For local options need to do that
7782 * in the buffer or window structure. */
7783 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007784 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007785 if (both || (opt_flags & OPT_LOCAL))
7786 {
7787 if (indir & PV_BUF)
7788 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7789 else if (indir & PV_WIN)
7790 curwin->w_p_scriptID[indir & PV_MASK] = id;
7791 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007792}
7793#endif
7794
Bram Moolenaar071d4272004-06-13 20:20:40 +00007795/*
7796 * Set the value of a boolean option, and take care of side effects.
7797 * Returns NULL for success, or an error message for an error.
7798 */
7799 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007800set_bool_option(
7801 int opt_idx, /* index in options[] table */
7802 char_u *varp, /* pointer to the option variable */
7803 int value, /* new value */
7804 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007805{
7806 int old_value = *(int *)varp;
7807
Bram Moolenaar071d4272004-06-13 20:20:40 +00007808 /* Disallow changing some options from secure mode */
7809 if ((secure
7810#ifdef HAVE_SANDBOX
7811 || sandbox != 0
7812#endif
7813 ) && (options[opt_idx].flags & P_SECURE))
7814 return e_secure;
7815
7816 *(int *)varp = value; /* set the new value */
7817#ifdef FEAT_EVAL
7818 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007819 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820#endif
7821
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007822#ifdef FEAT_GUI
7823 need_mouse_correct = TRUE;
7824#endif
7825
Bram Moolenaar071d4272004-06-13 20:20:40 +00007826 /* May set global value for local option. */
7827 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7828 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7829
7830 /*
7831 * Handle side effects of changing a bool option.
7832 */
7833
7834 /* 'compatible' */
7835 if ((int *)varp == &p_cp)
7836 {
7837 compatible_set();
7838 }
7839
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007840#ifdef FEAT_PERSISTENT_UNDO
7841 /* 'undofile' */
7842 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7843 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007844 /* Only take action when the option was set. When reset we do not
7845 * delete the undo file, the option may be set again without making
7846 * any changes in between. */
7847 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007848 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007849 char_u hash[UNDO_HASH_SIZE];
7850 buf_T *save_curbuf = curbuf;
7851
7852 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007853 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007854 /* When 'undofile' is set globally: for every buffer, otherwise
7855 * only for the current buffer: Try to read in the undofile,
7856 * if one exists, the buffer wasn't changed and the buffer was
7857 * loaded */
7858 if ((curbuf == save_curbuf
7859 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7860 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7861 {
7862 u_compute_hash(hash);
7863 u_read_undo(NULL, hash, curbuf->b_fname);
7864 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007865 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007866 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007867 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007868 }
7869#endif
7870
Bram Moolenaar071d4272004-06-13 20:20:40 +00007871 else if ((int *)varp == &curbuf->b_p_ro)
7872 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007873 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007874 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7875 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007876
7877 /* when 'readonly' is set may give W10 again */
7878 if (curbuf->b_p_ro)
7879 curbuf->b_did_warn = FALSE;
7880
Bram Moolenaar071d4272004-06-13 20:20:40 +00007881#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007882 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007883#endif
7884 }
7885
Bram Moolenaar9c449722010-07-20 18:44:27 +02007886#ifdef FEAT_GUI
7887 else if ((int *)varp == &p_mh)
7888 {
7889 if (!p_mh)
7890 gui_mch_mousehide(FALSE);
7891 }
7892#endif
7893
Bram Moolenaara539df02010-08-01 14:35:05 +02007894#ifdef FEAT_TITLE
7895 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007896 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007897 {
7898 redraw_titles();
7899 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900 /* when 'endofline' is changed, redraw the window title */
7901 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007902 {
7903 redraw_titles();
7904 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007905 /* when 'fixeol' is changed, redraw the window title */
7906 else if ((int *)varp == &curbuf->b_p_fixeol)
7907 {
7908 redraw_titles();
7909 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007910# ifdef FEAT_MBYTE
7911 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007912 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007913 {
7914 redraw_titles();
7915 }
7916# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917#endif
7918
7919 /* when 'bin' is set also set some other options */
7920 else if ((int *)varp == &curbuf->b_p_bin)
7921 {
7922 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7923#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007924 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925#endif
7926 }
7927
7928#ifdef FEAT_AUTOCMD
7929 /* when 'buflisted' changes, trigger autocommands */
7930 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7931 {
7932 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7933 NULL, NULL, TRUE, curbuf);
7934 }
7935#endif
7936
7937 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7938 else if ((int *)varp == &curbuf->b_p_swf)
7939 {
7940 if (curbuf->b_p_swf && p_uc)
7941 ml_open_file(curbuf); /* create the swap file */
7942 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007943 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7944 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945 mf_close_file(curbuf, TRUE); /* remove the swap file */
7946 }
7947
7948 /* when 'terse' is set change 'shortmess' */
7949 else if ((int *)varp == &p_terse)
7950 {
7951 char_u *p;
7952
7953 p = vim_strchr(p_shm, SHM_SEARCH);
7954
7955 /* insert 's' in p_shm */
7956 if (p_terse && p == NULL)
7957 {
7958 STRCPY(IObuff, p_shm);
7959 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007960 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007961 }
7962 /* remove 's' from p_shm */
7963 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007964 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007965 }
7966
7967 /* when 'paste' is set or reset also change other options */
7968 else if ((int *)varp == &p_paste)
7969 {
7970 paste_option_changed();
7971 }
7972
7973 /* when 'insertmode' is set from an autocommand need to do work here */
7974 else if ((int *)varp == &p_im)
7975 {
7976 if (p_im)
7977 {
7978 if ((State & INSERT) == 0)
7979 need_start_insertmode = TRUE;
7980 stop_insert_mode = FALSE;
7981 }
7982 else
7983 {
7984 need_start_insertmode = FALSE;
7985 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007986 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007987 clear_cmdline = TRUE; /* remove "(insert)" */
7988 restart_edit = 0;
7989 }
7990 }
7991
7992 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7993 else if ((int *)varp == &p_ic && p_hls)
7994 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007995 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996 }
7997
7998#ifdef FEAT_SEARCH_EXTRA
7999 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8000 else if ((int *)varp == &p_hls)
8001 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008002 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003 }
8004#endif
8005
8006#ifdef FEAT_SCROLLBIND
8007 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8008 * at the end of normal_cmd() */
8009 else if ((int *)varp == &curwin->w_p_scb)
8010 {
8011 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008012 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008014 curwin->w_scbind_pos = curwin->w_topline;
8015 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 }
8017#endif
8018
8019#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8020 /* There can be only one window with 'previewwindow' set. */
8021 else if ((int *)varp == &curwin->w_p_pvw)
8022 {
8023 if (curwin->w_p_pvw)
8024 {
8025 win_T *win;
8026
8027 for (win = firstwin; win != NULL; win = win->w_next)
8028 if (win->w_p_pvw && win != curwin)
8029 {
8030 curwin->w_p_pvw = FALSE;
8031 return (char_u *)N_("E590: A preview window already exists");
8032 }
8033 }
8034 }
8035#endif
8036
8037 /* when 'textmode' is set or reset also change 'fileformat' */
8038 else if ((int *)varp == &curbuf->b_p_tx)
8039 {
8040 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8041 }
8042
8043 /* when 'textauto' is set or reset also change 'fileformats' */
8044 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045 set_string_option_direct((char_u *)"ffs", -1,
8046 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008047 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008048
8049 /*
8050 * When 'lisp' option changes include/exclude '-' in
8051 * keyword characters.
8052 */
8053#ifdef FEAT_LISP
8054 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8055 {
8056 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8057 }
8058#endif
8059
8060#ifdef FEAT_TITLE
8061 /* when 'title' changed, may need to change the title; same for 'icon' */
8062 else if ((int *)varp == &p_title)
8063 {
8064 did_set_title(FALSE);
8065 }
8066
8067 else if ((int *)varp == &p_icon)
8068 {
8069 did_set_title(TRUE);
8070 }
8071#endif
8072
8073 else if ((int *)varp == &curbuf->b_changed)
8074 {
8075 if (!value)
8076 save_file_ff(curbuf); /* Buffer is unchanged */
8077#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008078 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008079#endif
8080#ifdef FEAT_AUTOCMD
8081 modified_was_set = value;
8082#endif
8083 }
8084
8085#ifdef BACKSLASH_IN_FILENAME
8086 else if ((int *)varp == &p_ssl)
8087 {
8088 if (p_ssl)
8089 {
8090 psepc = '/';
8091 psepcN = '\\';
8092 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 }
8094 else
8095 {
8096 psepc = '\\';
8097 psepcN = '/';
8098 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008099 }
8100
8101 /* need to adjust the file name arguments and buffer names. */
8102 buflist_slash_adjust();
8103 alist_slash_adjust();
8104# ifdef FEAT_EVAL
8105 scriptnames_slash_adjust();
8106# endif
8107 }
8108#endif
8109
8110 /* If 'wrap' is set, set w_leftcol to zero. */
8111 else if ((int *)varp == &curwin->w_p_wrap)
8112 {
8113 if (curwin->w_p_wrap)
8114 curwin->w_leftcol = 0;
8115 }
8116
8117#ifdef FEAT_WINDOWS
8118 else if ((int *)varp == &p_ea)
8119 {
8120 if (p_ea && !old_value)
8121 win_equal(curwin, FALSE, 0);
8122 }
8123#endif
8124
8125 else if ((int *)varp == &p_wiv)
8126 {
8127 /*
8128 * When 'weirdinvert' changed, set/reset 't_xs'.
8129 * Then set 'weirdinvert' according to value of 't_xs'.
8130 */
8131 if (p_wiv && !old_value)
8132 T_XS = (char_u *)"y";
8133 else if (!p_wiv && old_value)
8134 T_XS = empty_option;
8135 p_wiv = (*T_XS != NUL);
8136 }
8137
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008138#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139 else if ((int *)varp == &p_beval)
8140 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008141 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008143 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144 gui_mch_disable_beval_area(balloonEval);
8145 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008146#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008148#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 else if ((int *)varp == &p_acd)
8150 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008151 /* Change directories when the 'acd' option is set now. */
8152 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 }
8154#endif
8155
8156#ifdef FEAT_DIFF
8157 /* 'diff' */
8158 else if ((int *)varp == &curwin->w_p_diff)
8159 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008160 /* May add or remove the buffer from the list of diff buffers. */
8161 diff_buf_adjust(curwin);
8162# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 if (foldmethodIsDiff(curwin))
8164 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008165# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008166 }
8167#endif
8168
8169#ifdef USE_IM_CONTROL
8170 /* 'imdisable' */
8171 else if ((int *)varp == &p_imdisable)
8172 {
8173 /* Only de-activate it here, it will be enabled when changing mode. */
8174 if (p_imdisable)
8175 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008176 else if (State & INSERT)
8177 /* When the option is set from an autocommand, it may need to take
8178 * effect right away. */
8179 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008180 }
8181#endif
8182
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008183#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008184 /* 'spell' */
8185 else if ((int *)varp == &curwin->w_p_spell)
8186 {
8187 if (curwin->w_p_spell)
8188 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008189 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008190 if (errmsg != NULL)
8191 EMSG(_(errmsg));
8192 }
8193 }
8194#endif
8195
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196#ifdef FEAT_FKMAP
8197 else if ((int *)varp == &p_altkeymap)
8198 {
8199 if (old_value != p_altkeymap)
8200 {
8201 if (!p_altkeymap)
8202 {
8203 p_hkmap = p_fkmap;
8204 p_fkmap = 0;
8205 }
8206 else
8207 {
8208 p_fkmap = p_hkmap;
8209 p_hkmap = 0;
8210 }
8211 (void)init_chartab();
8212 }
8213 }
8214
8215 /*
8216 * In case some second language keymapping options have changed, check
8217 * and correct the setting in a consistent way.
8218 */
8219
8220 /*
8221 * If hkmap or fkmap are set, reset Arabic keymapping.
8222 */
8223 if ((p_hkmap || p_fkmap) && p_altkeymap)
8224 {
8225 p_altkeymap = p_fkmap;
8226# ifdef FEAT_ARABIC
8227 curwin->w_p_arab = FALSE;
8228# endif
8229 (void)init_chartab();
8230 }
8231
8232 /*
8233 * If hkmap set, reset Farsi keymapping.
8234 */
8235 if (p_hkmap && p_altkeymap)
8236 {
8237 p_altkeymap = 0;
8238 p_fkmap = 0;
8239# ifdef FEAT_ARABIC
8240 curwin->w_p_arab = FALSE;
8241# endif
8242 (void)init_chartab();
8243 }
8244
8245 /*
8246 * If fkmap set, reset Hebrew keymapping.
8247 */
8248 if (p_fkmap && !p_altkeymap)
8249 {
8250 p_altkeymap = 1;
8251 p_hkmap = 0;
8252# ifdef FEAT_ARABIC
8253 curwin->w_p_arab = FALSE;
8254# endif
8255 (void)init_chartab();
8256 }
8257#endif
8258
8259#ifdef FEAT_ARABIC
8260 if ((int *)varp == &curwin->w_p_arab)
8261 {
8262 if (curwin->w_p_arab)
8263 {
8264 /*
8265 * 'arabic' is set, handle various sub-settings.
8266 */
8267 if (!p_tbidi)
8268 {
8269 /* set rightleft mode */
8270 if (!curwin->w_p_rl)
8271 {
8272 curwin->w_p_rl = TRUE;
8273 changed_window_setting();
8274 }
8275
8276 /* Enable Arabic shaping (major part of what Arabic requires) */
8277 if (!p_arshape)
8278 {
8279 p_arshape = TRUE;
8280 redraw_later_clear();
8281 }
8282 }
8283
8284 /* Arabic requires a utf-8 encoding, inform the user if its not
8285 * set. */
8286 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008287 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008288 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8289
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008290 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008291 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8292#ifdef FEAT_EVAL
8293 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8294#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008295 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008296
8297# ifdef FEAT_MBYTE
8298 /* set 'delcombine' */
8299 p_deco = TRUE;
8300# endif
8301
8302# ifdef FEAT_KEYMAP
8303 /* Force-set the necessary keymap for arabic */
8304 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8305 OPT_LOCAL);
8306# endif
8307# ifdef FEAT_FKMAP
8308 p_altkeymap = 0;
8309 p_hkmap = 0;
8310 p_fkmap = 0;
8311 (void)init_chartab();
8312# endif
8313 }
8314 else
8315 {
8316 /*
8317 * 'arabic' is reset, handle various sub-settings.
8318 */
8319 if (!p_tbidi)
8320 {
8321 /* reset rightleft mode */
8322 if (curwin->w_p_rl)
8323 {
8324 curwin->w_p_rl = FALSE;
8325 changed_window_setting();
8326 }
8327
8328 /* 'arabicshape' isn't reset, it is a global option and
8329 * another window may still need it "on". */
8330 }
8331
8332 /* 'delcombine' isn't reset, it is a global option and another
8333 * window may still want it "on". */
8334
8335# ifdef FEAT_KEYMAP
8336 /* Revert to the default keymap */
8337 curbuf->b_p_iminsert = B_IMODE_NONE;
8338 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8339# endif
8340 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008341 }
8342
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008343#endif
8344
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 /*
8346 * End of handling side effects for bool options.
8347 */
8348
Bram Moolenaar53744302015-07-17 17:38:22 +02008349 /* after handling side effects, call autocommand */
8350
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351 options[opt_idx].flags |= P_WAS_SET;
8352
Bram Moolenaar53744302015-07-17 17:38:22 +02008353#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8354 if (!starting)
8355 {
8356 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008357 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8358 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8359 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008360 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8361 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8362 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8363 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8364 reset_v_option_vars();
8365 }
8366#endif
8367
Bram Moolenaar071d4272004-06-13 20:20:40 +00008368 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008369 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008370 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008371 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372 check_redraw(options[opt_idx].flags);
8373
8374 return NULL;
8375}
8376
8377/*
8378 * Set the value of a number option, and take care of side effects.
8379 * Returns NULL for success, or an error message for an error.
8380 */
8381 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008382set_num_option(
8383 int opt_idx, /* index in options[] table */
8384 char_u *varp, /* pointer to the option variable */
8385 long value, /* new value */
8386 char_u *errbuf, /* buffer for error messages */
8387 size_t errbuflen, /* length of "errbuf" */
8388 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389 OPT_MODELINE */
8390{
8391 char_u *errmsg = NULL;
8392 long old_value = *(long *)varp;
8393 long old_Rows = Rows; /* remember old Rows */
8394 long old_Columns = Columns; /* remember old Columns */
8395 long *pp = (long *)varp;
8396
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008397 /* Disallow changing some options from secure mode. */
8398 if ((secure
8399#ifdef HAVE_SANDBOX
8400 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008402 ) && (options[opt_idx].flags & P_SECURE))
8403 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404
8405 *pp = value;
8406#ifdef FEAT_EVAL
8407 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008408 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008410#ifdef FEAT_GUI
8411 need_mouse_correct = TRUE;
8412#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008413
Bram Moolenaar14f24742012-08-08 18:01:05 +02008414 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415 {
8416 errmsg = e_positive;
8417 curbuf->b_p_sw = curbuf->b_p_ts;
8418 }
8419
8420 /*
8421 * Number options that need some action when changed
8422 */
8423#ifdef FEAT_WINDOWS
8424 if (pp == &p_wh || pp == &p_hh)
8425 {
8426 if (p_wh < 1)
8427 {
8428 errmsg = e_positive;
8429 p_wh = 1;
8430 }
8431 if (p_wmh > p_wh)
8432 {
8433 errmsg = e_winheight;
8434 p_wh = p_wmh;
8435 }
8436 if (p_hh < 0)
8437 {
8438 errmsg = e_positive;
8439 p_hh = 0;
8440 }
8441
8442 /* Change window height NOW */
8443 if (lastwin != firstwin)
8444 {
8445 if (pp == &p_wh && curwin->w_height < p_wh)
8446 win_setheight((int)p_wh);
8447 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8448 win_setheight((int)p_hh);
8449 }
8450 }
8451
8452 /* 'winminheight' */
8453 else if (pp == &p_wmh)
8454 {
8455 if (p_wmh < 0)
8456 {
8457 errmsg = e_positive;
8458 p_wmh = 0;
8459 }
8460 if (p_wmh > p_wh)
8461 {
8462 errmsg = e_winheight;
8463 p_wmh = p_wh;
8464 }
8465 win_setminheight();
8466 }
8467
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008468# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008469 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008470 {
8471 if (p_wiw < 1)
8472 {
8473 errmsg = e_positive;
8474 p_wiw = 1;
8475 }
8476 if (p_wmw > p_wiw)
8477 {
8478 errmsg = e_winwidth;
8479 p_wiw = p_wmw;
8480 }
8481
8482 /* Change window width NOW */
8483 if (lastwin != firstwin && curwin->w_width < p_wiw)
8484 win_setwidth((int)p_wiw);
8485 }
8486
8487 /* 'winminwidth' */
8488 else if (pp == &p_wmw)
8489 {
8490 if (p_wmw < 0)
8491 {
8492 errmsg = e_positive;
8493 p_wmw = 0;
8494 }
8495 if (p_wmw > p_wiw)
8496 {
8497 errmsg = e_winwidth;
8498 p_wmw = p_wiw;
8499 }
8500 win_setminheight();
8501 }
8502# endif
8503
8504#endif
8505
8506#ifdef FEAT_WINDOWS
8507 /* (re)set last window status line */
8508 else if (pp == &p_ls)
8509 {
8510 last_status(FALSE);
8511 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008512
8513 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008514 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008515 {
8516 shell_new_rows(); /* recompute window positions and heights */
8517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008518#endif
8519
8520#ifdef FEAT_GUI
8521 else if (pp == &p_linespace)
8522 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008523 /* Recompute gui.char_height and resize the Vim window to keep the
8524 * same number of lines. */
8525 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008526 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008527 }
8528#endif
8529
8530#ifdef FEAT_FOLDING
8531 /* 'foldlevel' */
8532 else if (pp == &curwin->w_p_fdl)
8533 {
8534 if (curwin->w_p_fdl < 0)
8535 curwin->w_p_fdl = 0;
8536 newFoldLevel();
8537 }
8538
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008539 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540 else if (pp == &curwin->w_p_fml)
8541 {
8542 foldUpdateAll(curwin);
8543 }
8544
8545 /* 'foldnestmax' */
8546 else if (pp == &curwin->w_p_fdn)
8547 {
8548 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8549 foldUpdateAll(curwin);
8550 }
8551
8552 /* 'foldcolumn' */
8553 else if (pp == &curwin->w_p_fdc)
8554 {
8555 if (curwin->w_p_fdc < 0)
8556 {
8557 errmsg = e_positive;
8558 curwin->w_p_fdc = 0;
8559 }
8560 else if (curwin->w_p_fdc > 12)
8561 {
8562 errmsg = e_invarg;
8563 curwin->w_p_fdc = 12;
8564 }
8565 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008566#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008568#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569 /* 'shiftwidth' or 'tabstop' */
8570 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8571 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008572# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008573 if (foldmethodIsIndent(curwin))
8574 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008575# endif
8576# ifdef FEAT_CINDENT
8577 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8578 * parse 'cinoptions'. */
8579 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8580 parse_cino(curbuf);
8581# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008582 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008584
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008585#ifdef FEAT_MBYTE
8586 /* 'maxcombine' */
8587 else if (pp == &p_mco)
8588 {
8589 if (p_mco > MAX_MCO)
8590 p_mco = MAX_MCO;
8591 else if (p_mco < 0)
8592 p_mco = 0;
8593 screenclear(); /* will re-allocate the screen */
8594 }
8595#endif
8596
Bram Moolenaar071d4272004-06-13 20:20:40 +00008597 else if (pp == &curbuf->b_p_iminsert)
8598 {
8599 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8600 {
8601 errmsg = e_invarg;
8602 curbuf->b_p_iminsert = B_IMODE_NONE;
8603 }
8604 p_iminsert = curbuf->b_p_iminsert;
8605 if (termcap_active) /* don't do this in the alternate screen */
8606 showmode();
8607#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8608 /* Show/unshow value of 'keymap' in status lines. */
8609 status_redraw_curbuf();
8610#endif
8611 }
8612
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008613 else if (pp == &p_window)
8614 {
8615 if (p_window < 1)
8616 p_window = 1;
8617 else if (p_window >= Rows)
8618 p_window = Rows - 1;
8619 }
8620
Bram Moolenaar071d4272004-06-13 20:20:40 +00008621 else if (pp == &curbuf->b_p_imsearch)
8622 {
8623 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8624 {
8625 errmsg = e_invarg;
8626 curbuf->b_p_imsearch = B_IMODE_NONE;
8627 }
8628 p_imsearch = curbuf->b_p_imsearch;
8629 }
8630
8631#ifdef FEAT_TITLE
8632 /* if 'titlelen' has changed, redraw the title */
8633 else if (pp == &p_titlelen)
8634 {
8635 if (p_titlelen < 0)
8636 {
8637 errmsg = e_positive;
8638 p_titlelen = 85;
8639 }
8640 if (starting != NO_SCREEN && old_value != p_titlelen)
8641 need_maketitle = TRUE;
8642 }
8643#endif
8644
8645 /* if p_ch changed value, change the command line height */
8646 else if (pp == &p_ch)
8647 {
8648 if (p_ch < 1)
8649 {
8650 errmsg = e_positive;
8651 p_ch = 1;
8652 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008653 if (p_ch > Rows - min_rows() + 1)
8654 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008655
8656 /* Only compute the new window layout when startup has been
8657 * completed. Otherwise the frame sizes may be wrong. */
8658 if (p_ch != old_value && full_screen
8659#ifdef FEAT_GUI
8660 && !gui.starting
8661#endif
8662 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008663 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 }
8665
8666 /* when 'updatecount' changes from zero to non-zero, open swap files */
8667 else if (pp == &p_uc)
8668 {
8669 if (p_uc < 0)
8670 {
8671 errmsg = e_positive;
8672 p_uc = 100;
8673 }
8674 if (p_uc && !old_value)
8675 ml_open_files();
8676 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008677#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008678 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008679 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008680 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008681 {
8682 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008683 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008684 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008685 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008686 {
8687 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008688 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008689 }
8690 }
8691#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008692#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008693 else if (pp == &p_mzq)
8694 mzvim_reset_timer();
8695#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008696
8697 /* sync undo before 'undolevels' changes */
8698 else if (pp == &p_ul)
8699 {
8700 /* use the old value, otherwise u_sync() may not work properly */
8701 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008702 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703 p_ul = value;
8704 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008705 else if (pp == &curbuf->b_p_ul)
8706 {
8707 /* use the old value, otherwise u_sync() may not work properly */
8708 curbuf->b_p_ul = old_value;
8709 u_sync(TRUE);
8710 curbuf->b_p_ul = value;
8711 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008712
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008713#ifdef FEAT_LINEBREAK
8714 /* 'numberwidth' must be positive */
8715 else if (pp == &curwin->w_p_nuw)
8716 {
8717 if (curwin->w_p_nuw < 1)
8718 {
8719 errmsg = e_positive;
8720 curwin->w_p_nuw = 1;
8721 }
8722 if (curwin->w_p_nuw > 10)
8723 {
8724 errmsg = e_invarg;
8725 curwin->w_p_nuw = 10;
8726 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008727 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008728 }
8729#endif
8730
Bram Moolenaar1a384422010-07-14 19:53:30 +02008731 else if (pp == &curbuf->b_p_tw)
8732 {
8733 if (curbuf->b_p_tw < 0)
8734 {
8735 errmsg = e_positive;
8736 curbuf->b_p_tw = 0;
8737 }
8738#ifdef FEAT_SYN_HL
8739# ifdef FEAT_WINDOWS
8740 {
8741 win_T *wp;
8742 tabpage_T *tp;
8743
8744 FOR_ALL_TAB_WINDOWS(tp, wp)
8745 check_colorcolumn(wp);
8746 }
8747# else
8748 check_colorcolumn(curwin);
8749# endif
8750#endif
8751 }
8752
Bram Moolenaar071d4272004-06-13 20:20:40 +00008753 /*
8754 * Check the bounds for numeric options here
8755 */
8756 if (Rows < min_rows() && full_screen)
8757 {
8758 if (errbuf != NULL)
8759 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008760 vim_snprintf((char *)errbuf, errbuflen,
8761 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762 errmsg = errbuf;
8763 }
8764 Rows = min_rows();
8765 }
8766 if (Columns < MIN_COLUMNS && full_screen)
8767 {
8768 if (errbuf != NULL)
8769 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008770 vim_snprintf((char *)errbuf, errbuflen,
8771 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 errmsg = errbuf;
8773 }
8774 Columns = MIN_COLUMNS;
8775 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008776 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008777
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778 /*
8779 * If the screen (shell) height has been changed, assume it is the
8780 * physical screenheight.
8781 */
8782 if (old_Rows != Rows || old_Columns != Columns)
8783 {
8784 /* Changing the screen size is not allowed while updating the screen. */
8785 if (updating_screen)
8786 *pp = old_value;
8787 else if (full_screen
8788#ifdef FEAT_GUI
8789 && !gui.starting
8790#endif
8791 )
8792 set_shellsize((int)Columns, (int)Rows, TRUE);
8793 else
8794 {
8795 /* Postpone the resizing; check the size and cmdline position for
8796 * messages. */
8797 check_shellsize();
8798 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8799 cmdline_row = Rows - p_ch;
8800 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008801 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008802 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008803 }
8804
Bram Moolenaar071d4272004-06-13 20:20:40 +00008805 if (curbuf->b_p_ts <= 0)
8806 {
8807 errmsg = e_positive;
8808 curbuf->b_p_ts = 8;
8809 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008810 if (p_tm < 0)
8811 {
8812 errmsg = e_positive;
8813 p_tm = 0;
8814 }
8815 if ((curwin->w_p_scr <= 0
8816 || (curwin->w_p_scr > curwin->w_height
8817 && curwin->w_height > 0))
8818 && full_screen)
8819 {
8820 if (pp == &(curwin->w_p_scr))
8821 {
8822 if (curwin->w_p_scr != 0)
8823 errmsg = e_scroll;
8824 win_comp_scroll(curwin);
8825 }
8826 /* If 'scroll' became invalid because of a side effect silently adjust
8827 * it. */
8828 else if (curwin->w_p_scr <= 0)
8829 curwin->w_p_scr = 1;
8830 else /* curwin->w_p_scr > curwin->w_height */
8831 curwin->w_p_scr = curwin->w_height;
8832 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008833 if (p_hi < 0)
8834 {
8835 errmsg = e_positive;
8836 p_hi = 0;
8837 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008838 else if (p_hi > 10000)
8839 {
8840 errmsg = e_invarg;
8841 p_hi = 10000;
8842 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008843 if (p_re < 0 || p_re > 2)
8844 {
8845 errmsg = e_invarg;
8846 p_re = 0;
8847 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848 if (p_report < 0)
8849 {
8850 errmsg = e_positive;
8851 p_report = 1;
8852 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008853 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008854 {
8855 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8856 p_sj = Rows / 2;
8857 else
8858 {
8859 errmsg = e_scroll;
8860 p_sj = 1;
8861 }
8862 }
8863 if (p_so < 0 && full_screen)
8864 {
8865 errmsg = e_scroll;
8866 p_so = 0;
8867 }
8868 if (p_siso < 0 && full_screen)
8869 {
8870 errmsg = e_positive;
8871 p_siso = 0;
8872 }
8873#ifdef FEAT_CMDWIN
8874 if (p_cwh < 1)
8875 {
8876 errmsg = e_positive;
8877 p_cwh = 1;
8878 }
8879#endif
8880 if (p_ut < 0)
8881 {
8882 errmsg = e_positive;
8883 p_ut = 2000;
8884 }
8885 if (p_ss < 0)
8886 {
8887 errmsg = e_positive;
8888 p_ss = 0;
8889 }
8890
8891 /* May set global value for local option. */
8892 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8893 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8894
8895 options[opt_idx].flags |= P_WAS_SET;
8896
Bram Moolenaar53744302015-07-17 17:38:22 +02008897#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8898 if (!starting && errmsg == NULL)
8899 {
8900 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008901 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8902 vim_snprintf((char *)buf_new, 10, "%ld", value);
8903 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008904 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8905 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8906 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8907 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8908 reset_v_option_vars();
8909 }
8910#endif
8911
Bram Moolenaar071d4272004-06-13 20:20:40 +00008912 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008913 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008914 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008915 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008916 check_redraw(options[opt_idx].flags);
8917
8918 return errmsg;
8919}
8920
8921/*
8922 * Called after an option changed: check if something needs to be redrawn.
8923 */
8924 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008925check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926{
8927 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008928 int doclear = (flags & P_RCLR) == P_RCLR;
8929 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008930
8931#ifdef FEAT_WINDOWS
8932 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8933 status_redraw_all();
8934#endif
8935
8936 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8937 changed_window_setting();
8938 if (flags & P_RBUF)
8939 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008940 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941 redraw_all_later(CLEAR);
8942 else if (all)
8943 redraw_all_later(NOT_VALID);
8944}
8945
8946/*
8947 * Find index for option 'arg'.
8948 * Return -1 if not found.
8949 */
8950 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008951findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952{
8953 int opt_idx;
8954 char *s, *p;
8955 static short quick_tab[27] = {0, 0}; /* quick access table */
8956 int is_term_opt;
8957
8958 /*
8959 * For first call: Initialize the quick-access table.
8960 * It contains the index for the first option that starts with a certain
8961 * letter. There are 26 letters, plus the first "t_" option.
8962 */
8963 if (quick_tab[1] == 0)
8964 {
8965 p = options[0].fullname;
8966 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8967 {
8968 if (s[0] != p[0])
8969 {
8970 if (s[0] == 't' && s[1] == '_')
8971 quick_tab[26] = opt_idx;
8972 else
8973 quick_tab[CharOrdLow(s[0])] = opt_idx;
8974 }
8975 p = s;
8976 }
8977 }
8978
8979 /*
8980 * Check for name starting with an illegal character.
8981 */
8982#ifdef EBCDIC
8983 if (!islower(arg[0]))
8984#else
8985 if (arg[0] < 'a' || arg[0] > 'z')
8986#endif
8987 return -1;
8988
8989 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8990 if (is_term_opt)
8991 opt_idx = quick_tab[26];
8992 else
8993 opt_idx = quick_tab[CharOrdLow(arg[0])];
8994 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8995 {
8996 if (STRCMP(arg, s) == 0) /* match full name */
8997 break;
8998 }
8999 if (s == NULL && !is_term_opt)
9000 {
9001 opt_idx = quick_tab[CharOrdLow(arg[0])];
9002 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9003 {
9004 s = options[opt_idx].shortname;
9005 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9006 break;
9007 s = NULL;
9008 }
9009 }
9010 if (s == NULL)
9011 opt_idx = -1;
9012 return opt_idx;
9013}
9014
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009015#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016/*
9017 * Get the value for an option.
9018 *
9019 * Returns:
9020 * Number or Toggle option: 1, *numval gets value.
9021 * String option: 0, *stringval gets allocated string.
9022 * Hidden Number or Toggle option: -1.
9023 * hidden String option: -2.
9024 * unknown option: -3.
9025 */
9026 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009027get_option_value(
9028 char_u *name,
9029 long *numval,
9030 char_u **stringval, /* NULL when only checking existence */
9031 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009032{
9033 int opt_idx;
9034 char_u *varp;
9035
9036 opt_idx = findoption(name);
9037 if (opt_idx < 0) /* unknown option */
9038 return -3;
9039
9040 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9041
9042 if (options[opt_idx].flags & P_STRING)
9043 {
9044 if (varp == NULL) /* hidden option */
9045 return -2;
9046 if (stringval != NULL)
9047 {
9048#ifdef FEAT_CRYPT
9049 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009050 if ((char_u **)varp == &curbuf->b_p_key
9051 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009052 *stringval = vim_strsave((char_u *)"*****");
9053 else
9054#endif
9055 *stringval = vim_strsave(*(char_u **)(varp));
9056 }
9057 return 0;
9058 }
9059
9060 if (varp == NULL) /* hidden option */
9061 return -1;
9062 if (options[opt_idx].flags & P_NUM)
9063 *numval = *(long *)varp;
9064 else
9065 {
9066 /* Special case: 'modified' is b_changed, but we also want to consider
9067 * it set when 'ff' or 'fenc' changed. */
9068 if ((int *)varp == &curbuf->b_changed)
9069 *numval = curbufIsChanged();
9070 else
9071 *numval = *(int *)varp;
9072 }
9073 return 1;
9074}
9075#endif
9076
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009077#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009078/*
9079 * Returns the option attributes and its value. Unlike the above function it
9080 * will return either global value or local value of the option depending on
9081 * what was requested, but it will never return global value if it was
9082 * requested to return local one and vice versa. Neither it will return
9083 * buffer-local value if it was requested to return window-local one.
9084 *
9085 * Pretends that option is absent if it is not present in the requested scope
9086 * (i.e. has no global, window-local or buffer-local value depending on
9087 * opt_type). Uses
9088 *
9089 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009090 * 0 hidden or unknown option, also option that does not have requested
9091 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009092 * see SOPT_* in vim.h for other flags
9093 *
9094 * Possible opt_type values: see SREQ_* in vim.h
9095 */
9096 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009097get_option_value_strict(
9098 char_u *name,
9099 long *numval,
9100 char_u **stringval, /* NULL when only obtaining attributes */
9101 int opt_type,
9102 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009103{
9104 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009105 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009106 struct vimoption *p;
9107 int r = 0;
9108
9109 opt_idx = findoption(name);
9110 if (opt_idx < 0)
9111 return 0;
9112
9113 p = &(options[opt_idx]);
9114
9115 /* Hidden option */
9116 if (p->var == NULL)
9117 return 0;
9118
9119 if (p->flags & P_BOOL)
9120 r |= SOPT_BOOL;
9121 else if (p->flags & P_NUM)
9122 r |= SOPT_NUM;
9123 else if (p->flags & P_STRING)
9124 r |= SOPT_STRING;
9125
9126 if (p->indir == PV_NONE)
9127 {
9128 if (opt_type == SREQ_GLOBAL)
9129 r |= SOPT_GLOBAL;
9130 else
9131 return 0; /* Did not request global-only option */
9132 }
9133 else
9134 {
9135 if (p->indir & PV_BOTH)
9136 r |= SOPT_GLOBAL;
9137 else if (opt_type == SREQ_GLOBAL)
9138 return 0; /* Requested global option */
9139
9140 if (p->indir & PV_WIN)
9141 {
9142 if (opt_type == SREQ_BUF)
9143 return 0; /* Did not request window-local option */
9144 else
9145 r |= SOPT_WIN;
9146 }
9147 else if (p->indir & PV_BUF)
9148 {
9149 if (opt_type == SREQ_WIN)
9150 return 0; /* Did not request buffer-local option */
9151 else
9152 r |= SOPT_BUF;
9153 }
9154 }
9155
9156 if (stringval == NULL)
9157 return r;
9158
9159 if (opt_type == SREQ_GLOBAL)
9160 varp = p->var;
9161 else
9162 {
9163 if (opt_type == SREQ_BUF)
9164 {
9165 /* Special case: 'modified' is b_changed, but we also want to
9166 * consider it set when 'ff' or 'fenc' changed. */
9167 if (p->indir == PV_MOD)
9168 {
9169 *numval = bufIsChanged((buf_T *) from);
9170 varp = NULL;
9171 }
9172#ifdef FEAT_CRYPT
9173 else if (p->indir == PV_KEY)
9174 {
9175 /* never return the value of the crypt key */
9176 *stringval = NULL;
9177 varp = NULL;
9178 }
9179#endif
9180 else
9181 {
9182 aco_save_T aco;
9183 aucmd_prepbuf(&aco, (buf_T *) from);
9184 varp = get_varp(p);
9185 aucmd_restbuf(&aco);
9186 }
9187 }
9188 else if (opt_type == SREQ_WIN)
9189 {
9190 win_T *save_curwin;
9191 save_curwin = curwin;
9192 curwin = (win_T *) from;
9193 curbuf = curwin->w_buffer;
9194 varp = get_varp(p);
9195 curwin = save_curwin;
9196 curbuf = curwin->w_buffer;
9197 }
9198 if (varp == p->var)
9199 return (r | SOPT_UNSET);
9200 }
9201
9202 if (varp != NULL)
9203 {
9204 if (p->flags & P_STRING)
9205 *stringval = vim_strsave(*(char_u **)(varp));
9206 else if (p->flags & P_NUM)
9207 *numval = *(long *) varp;
9208 else
9209 *numval = *(int *)varp;
9210 }
9211
9212 return r;
9213}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009214
9215/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009216 * Iterate over options. First argument is a pointer to a pointer to a
9217 * structure inside options[] array, second is option type like in the above
9218 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009219 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009220 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009221 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009222 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009223 * first argument to NULL.
9224 *
9225 * Returns full option name for current option on each call.
9226 */
9227 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009228option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009229{
9230 struct vimoption *ret = NULL;
9231 do
9232 {
9233 if (*option == NULL)
9234 *option = (void *) options;
9235 else if (((struct vimoption *) (*option))->fullname == NULL)
9236 {
9237 *option = NULL;
9238 return NULL;
9239 }
9240 else
9241 *option = (void *) (((struct vimoption *) (*option)) + 1);
9242
9243 ret = ((struct vimoption *) (*option));
9244
9245 /* Hidden option */
9246 if (ret->var == NULL)
9247 {
9248 ret = NULL;
9249 continue;
9250 }
9251
9252 switch (opt_type)
9253 {
9254 case SREQ_GLOBAL:
9255 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9256 ret = NULL;
9257 break;
9258 case SREQ_BUF:
9259 if (!(ret->indir & PV_BUF))
9260 ret = NULL;
9261 break;
9262 case SREQ_WIN:
9263 if (!(ret->indir & PV_WIN))
9264 ret = NULL;
9265 break;
9266 default:
9267 EMSG2(_(e_intern2), "option_iter_next()");
9268 return NULL;
9269 }
9270 }
9271 while (ret == NULL);
9272
9273 return (char_u *)ret->fullname;
9274}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009275#endif
9276
Bram Moolenaar071d4272004-06-13 20:20:40 +00009277/*
9278 * Set the value of option "name".
9279 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009280 *
9281 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009282 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009283 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009284set_option_value(
9285 char_u *name,
9286 long number,
9287 char_u *string,
9288 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009289{
9290 int opt_idx;
9291 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009292 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009293
9294 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009295 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009296 EMSG2(_("E355: Unknown option: %s"), name);
9297 else
9298 {
9299 flags = options[opt_idx].flags;
9300#ifdef HAVE_SANDBOX
9301 /* Disallow changing some options in the sandbox */
9302 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009303 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009305 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009306 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009308 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009309 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009310 else
9311 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009312 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009313 if (varp != NULL) /* hidden option is not changed */
9314 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009315 if (number == 0 && string != NULL)
9316 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009317 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009318
9319 /* Either we are given a string or we are setting option
9320 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009321 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009322 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009323 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009324 {
9325 /* There's another character after zeros or the string
9326 * is empty. In both cases, we are trying to set a
9327 * num option using a string. */
9328 EMSG3(_("E521: Number required: &%s = '%s'"),
9329 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009330 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009331
9332 }
9333 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009335 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009336 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009338 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009339 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009340 }
9341 }
9342 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009343 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009344}
9345
9346/*
9347 * Get the terminal code for a terminal option.
9348 * Returns NULL when not found.
9349 */
9350 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009351get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009352{
9353 int opt_idx;
9354 char_u *varp;
9355
9356 if (tname[0] != 't' || tname[1] != '_' ||
9357 tname[2] == NUL || tname[3] == NUL)
9358 return NULL;
9359 if ((opt_idx = findoption(tname)) >= 0)
9360 {
9361 varp = get_varp(&(options[opt_idx]));
9362 if (varp != NULL)
9363 varp = *(char_u **)(varp);
9364 return varp;
9365 }
9366 return find_termcode(tname + 2);
9367}
9368
9369 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009370get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009371{
9372 int i;
9373
9374 i = findoption((char_u *)"hl");
9375 if (i >= 0)
9376 return options[i].def_val[VI_DEFAULT];
9377 return (char_u *)NULL;
9378}
9379
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009380#if defined(FEAT_MBYTE) || defined(PROTO)
9381 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009382get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009383{
9384 int i;
9385
9386 i = findoption((char_u *)"enc");
9387 if (i >= 0)
9388 return options[i].def_val[VI_DEFAULT];
9389 return (char_u *)NULL;
9390}
9391#endif
9392
Bram Moolenaar071d4272004-06-13 20:20:40 +00009393/*
9394 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9395 */
9396 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009397find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009398{
9399 int key;
9400 int modifiers;
9401
9402 /*
9403 * Don't use get_special_key_code() for t_xx, we don't want it to call
9404 * add_termcap_entry().
9405 */
9406 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9407 key = TERMCAP2KEY(arg[2], arg[3]);
9408 else
9409 {
9410 --arg; /* put arg at the '<' */
9411 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009412 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413 if (modifiers) /* can't handle modifiers here */
9414 key = 0;
9415 }
9416 return key;
9417}
9418
9419/*
9420 * if 'all' == 0: show changed options
9421 * if 'all' == 1: show all normal options
9422 * if 'all' == 2: show all terminal options
9423 */
9424 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009425showoptions(
9426 int all,
9427 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009428{
9429 struct vimoption *p;
9430 int col;
9431 int isterm;
9432 char_u *varp;
9433 struct vimoption **items;
9434 int item_count;
9435 int run;
9436 int row, rows;
9437 int cols;
9438 int i;
9439 int len;
9440
9441#define INC 20
9442#define GAP 3
9443
9444 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9445 PARAM_COUNT));
9446 if (items == NULL)
9447 return;
9448
9449 /* Highlight title */
9450 if (all == 2)
9451 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9452 else if (opt_flags & OPT_GLOBAL)
9453 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9454 else if (opt_flags & OPT_LOCAL)
9455 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9456 else
9457 MSG_PUTS_TITLE(_("\n--- Options ---"));
9458
9459 /*
9460 * do the loop two times:
9461 * 1. display the short items
9462 * 2. display the long items (only strings and numbers)
9463 */
9464 for (run = 1; run <= 2 && !got_int; ++run)
9465 {
9466 /*
9467 * collect the items in items[]
9468 */
9469 item_count = 0;
9470 for (p = &options[0]; p->fullname != NULL; p++)
9471 {
9472 varp = NULL;
9473 isterm = istermoption(p);
9474 if (opt_flags != 0)
9475 {
9476 if (p->indir != PV_NONE && !isterm)
9477 varp = get_varp_scope(p, opt_flags);
9478 }
9479 else
9480 varp = get_varp(p);
9481 if (varp != NULL
9482 && ((all == 2 && isterm)
9483 || (all == 1 && !isterm)
9484 || (all == 0 && !optval_default(p, varp))))
9485 {
9486 if (p->flags & P_BOOL)
9487 len = 1; /* a toggle option fits always */
9488 else
9489 {
9490 option_value2string(p, opt_flags);
9491 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9492 }
9493 if ((len <= INC - GAP && run == 1) ||
9494 (len > INC - GAP && run == 2))
9495 items[item_count++] = p;
9496 }
9497 }
9498
9499 /*
9500 * display the items
9501 */
9502 if (run == 1)
9503 {
9504 cols = (Columns + GAP - 3) / INC;
9505 if (cols == 0)
9506 cols = 1;
9507 rows = (item_count + cols - 1) / cols;
9508 }
9509 else /* run == 2 */
9510 rows = item_count;
9511 for (row = 0; row < rows && !got_int; ++row)
9512 {
9513 msg_putchar('\n'); /* go to next line */
9514 if (got_int) /* 'q' typed in more */
9515 break;
9516 col = 0;
9517 for (i = row; i < item_count; i += rows)
9518 {
9519 msg_col = col; /* make columns */
9520 showoneopt(items[i], opt_flags);
9521 col += INC;
9522 }
9523 out_flush();
9524 ui_breakcheck();
9525 }
9526 }
9527 vim_free(items);
9528}
9529
9530/*
9531 * Return TRUE if option "p" has its default value.
9532 */
9533 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009534optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009535{
9536 int dvi;
9537
9538 if (varp == NULL)
9539 return TRUE; /* hidden option is always at default */
9540 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9541 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009542 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009543 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009544 /* the cast to long is required for Manx C, long_i is
9545 * needed for MSVC */
9546 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 /* P_STRING */
9548 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9549}
9550
9551/*
9552 * showoneopt: show the value of one option
9553 * must not be called with a hidden option!
9554 */
9555 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009556showoneopt(
9557 struct vimoption *p,
9558 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009559{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009560 char_u *varp;
9561 int save_silent = silent_mode;
9562
9563 silent_mode = FALSE;
9564 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009565
9566 varp = get_varp_scope(p, opt_flags);
9567
9568 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9569 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9570 ? !curbufIsChanged() : !*(int *)varp))
9571 MSG_PUTS("no");
9572 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9573 MSG_PUTS("--");
9574 else
9575 MSG_PUTS(" ");
9576 MSG_PUTS(p->fullname);
9577 if (!(p->flags & P_BOOL))
9578 {
9579 msg_putchar('=');
9580 /* put value string in NameBuff */
9581 option_value2string(p, opt_flags);
9582 msg_outtrans(NameBuff);
9583 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009584
9585 silent_mode = save_silent;
9586 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009587}
9588
9589/*
9590 * Write modified options as ":set" commands to a file.
9591 *
9592 * There are three values for "opt_flags":
9593 * OPT_GLOBAL: Write global option values and fresh values of
9594 * buffer-local options (used for start of a session
9595 * file).
9596 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9597 * curwin (used for a vimrc file).
9598 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9599 * and local values for window-local options of
9600 * curwin. Local values are also written when at the
9601 * default value, because a modeline or autocommand
9602 * may have set them when doing ":edit file" and the
9603 * user has set them back at the default or fresh
9604 * value.
9605 * When "local_only" is TRUE, don't write fresh
9606 * values, only local values (for ":mkview").
9607 * (fresh value = value used for a new buffer or window for a local option).
9608 *
9609 * Return FAIL on error, OK otherwise.
9610 */
9611 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009612makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009613{
9614 struct vimoption *p;
9615 char_u *varp; /* currently used value */
9616 char_u *varp_fresh; /* local value */
9617 char_u *varp_local = NULL; /* fresh value */
9618 char *cmd;
9619 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009620 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621
9622 /*
9623 * The options that don't have a default (terminal name, columns, lines)
9624 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009625 * Do the loop over "options[]" twice: once for options with the
9626 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009627 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009628 for (pri = 1; pri >= 0; --pri)
9629 {
9630 for (p = &options[0]; !istermoption(p); p++)
9631 if (!(p->flags & P_NO_MKRC)
9632 && !istermoption(p)
9633 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009634 {
9635 /* skip global option when only doing locals */
9636 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9637 continue;
9638
9639 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9640 * file, they are always buffer-specific. */
9641 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9642 continue;
9643
9644 /* Global values are only written when not at the default value. */
9645 varp = get_varp_scope(p, opt_flags);
9646 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9647 continue;
9648
9649 round = 2;
9650 if (p->indir != PV_NONE)
9651 {
9652 if (p->var == VAR_WIN)
9653 {
9654 /* skip window-local option when only doing globals */
9655 if (!(opt_flags & OPT_LOCAL))
9656 continue;
9657 /* When fresh value of window-local option is not at the
9658 * default, need to write it too. */
9659 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9660 {
9661 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9662 if (!optval_default(p, varp_fresh))
9663 {
9664 round = 1;
9665 varp_local = varp;
9666 varp = varp_fresh;
9667 }
9668 }
9669 }
9670 }
9671
9672 /* Round 1: fresh value for window-local options.
9673 * Round 2: other values */
9674 for ( ; round <= 2; varp = varp_local, ++round)
9675 {
9676 if (round == 1 || (opt_flags & OPT_GLOBAL))
9677 cmd = "set";
9678 else
9679 cmd = "setlocal";
9680
9681 if (p->flags & P_BOOL)
9682 {
9683 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9684 return FAIL;
9685 }
9686 else if (p->flags & P_NUM)
9687 {
9688 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9689 return FAIL;
9690 }
9691 else /* P_STRING */
9692 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009693#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9694 int do_endif = FALSE;
9695
Bram Moolenaar071d4272004-06-13 20:20:40 +00009696 /* Don't set 'syntax' and 'filetype' again if the value is
9697 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009698 if (
9699# if defined(FEAT_SYN_HL)
9700 p->indir == PV_SYN
9701# if defined(FEAT_AUTOCMD)
9702 ||
9703# endif
9704# endif
9705# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009706 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009707# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009708 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009709 {
9710 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9711 *(char_u **)(varp)) < 0
9712 || put_eol(fd) < 0)
9713 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009714 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009716#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009717 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9718 (p->flags & P_EXPAND) != 0) == FAIL)
9719 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009720#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9721 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009722 {
9723 if (put_line(fd, "endif") == FAIL)
9724 return FAIL;
9725 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009727 }
9728 }
9729 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731 return OK;
9732}
9733
9734#if defined(FEAT_FOLDING) || defined(PROTO)
9735/*
9736 * Generate set commands for the local fold options only. Used when
9737 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9738 */
9739 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009740makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741{
9742 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9743# ifdef FEAT_EVAL
9744 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9745 == FAIL
9746# endif
9747 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9748 == FAIL
9749 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9750 == FAIL
9751 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9752 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9753 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9754 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9755 )
9756 return FAIL;
9757
9758 return OK;
9759}
9760#endif
9761
9762 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009763put_setstring(
9764 FILE *fd,
9765 char *cmd,
9766 char *name,
9767 char_u **valuep,
9768 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009769{
9770 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009771 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009772
9773 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9774 return FAIL;
9775 if (*valuep != NULL)
9776 {
9777 /* Output 'pastetoggle' as key names. For other
9778 * options some characters have to be escaped with
9779 * CTRL-V or backslash */
9780 if (valuep == &p_pt)
9781 {
9782 s = *valuep;
9783 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009784 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009785 return FAIL;
9786 }
9787 else if (expand)
9788 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009789 buf = alloc(MAXPATHL);
9790 if (buf == NULL)
9791 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009792 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9793 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009794 {
9795 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009796 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009797 }
9798 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009799 }
9800 else if (put_escstr(fd, *valuep, 2) == FAIL)
9801 return FAIL;
9802 }
9803 if (put_eol(fd) < 0)
9804 return FAIL;
9805 return OK;
9806}
9807
9808 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009809put_setnum(
9810 FILE *fd,
9811 char *cmd,
9812 char *name,
9813 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009814{
9815 long wc;
9816
9817 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9818 return FAIL;
9819 if (wc_use_keyname((char_u *)valuep, &wc))
9820 {
9821 /* print 'wildchar' and 'wildcharm' as a key name */
9822 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9823 return FAIL;
9824 }
9825 else if (fprintf(fd, "%ld", *valuep) < 0)
9826 return FAIL;
9827 if (put_eol(fd) < 0)
9828 return FAIL;
9829 return OK;
9830}
9831
9832 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009833put_setbool(
9834 FILE *fd,
9835 char *cmd,
9836 char *name,
9837 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009838{
Bram Moolenaar893de922007-10-02 18:40:57 +00009839 if (value < 0) /* global/local option using global value */
9840 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009841 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9842 || put_eol(fd) < 0)
9843 return FAIL;
9844 return OK;
9845}
9846
9847/*
9848 * Clear all the terminal options.
9849 * If the option has been allocated, free the memory.
9850 * Terminal options are never hidden or indirect.
9851 */
9852 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009853clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009854{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009855 /*
9856 * Reset a few things before clearing the old options. This may cause
9857 * outputting a few things that the terminal doesn't understand, but the
9858 * screen will be cleared later, so this is OK.
9859 */
9860#ifdef FEAT_MOUSE_TTY
9861 mch_setmouse(FALSE); /* switch mouse off */
9862#endif
9863#ifdef FEAT_TITLE
9864 mch_restore_title(3); /* restore window titles */
9865#endif
9866#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9867 /* When starting the GUI close the display opened for the clipboard.
9868 * After restoring the title, because that will need the display. */
9869 if (gui.starting)
9870 clear_xterm_clip();
9871#endif
9872#ifdef WIN3264
9873 /*
9874 * Check if this is allowed now.
9875 */
9876 if (can_end_termcap_mode(FALSE) == TRUE)
9877#endif
9878 stoptermcap(); /* stop termcap mode */
9879
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009880 free_termoptions();
9881}
9882
9883 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009884free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009885{
9886 struct vimoption *p;
9887
Bram Moolenaar071d4272004-06-13 20:20:40 +00009888 for (p = &options[0]; p->fullname != NULL; p++)
9889 if (istermoption(p))
9890 {
9891 if (p->flags & P_ALLOCED)
9892 free_string_option(*(char_u **)(p->var));
9893 if (p->flags & P_DEF_ALLOCED)
9894 free_string_option(p->def_val[VI_DEFAULT]);
9895 *(char_u **)(p->var) = empty_option;
9896 p->def_val[VI_DEFAULT] = empty_option;
9897 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9898 }
9899 clear_termcodes();
9900}
9901
9902/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009903 * Free the string for one term option, if it was allocated.
9904 * Set the string to empty_option and clear allocated flag.
9905 * "var" points to the option value.
9906 */
9907 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009908free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009909{
9910 struct vimoption *p;
9911
9912 for (p = &options[0]; p->fullname != NULL; p++)
9913 if (p->var == var)
9914 {
9915 if (p->flags & P_ALLOCED)
9916 free_string_option(*(char_u **)(p->var));
9917 *(char_u **)(p->var) = empty_option;
9918 p->flags &= ~P_ALLOCED;
9919 break;
9920 }
9921}
9922
9923/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009924 * Set the terminal option defaults to the current value.
9925 * Used after setting the terminal name.
9926 */
9927 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009928set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009929{
9930 struct vimoption *p;
9931
9932 for (p = &options[0]; p->fullname != NULL; p++)
9933 {
9934 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9935 {
9936 if (p->flags & P_DEF_ALLOCED)
9937 {
9938 free_string_option(p->def_val[VI_DEFAULT]);
9939 p->flags &= ~P_DEF_ALLOCED;
9940 }
9941 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9942 if (p->flags & P_ALLOCED)
9943 {
9944 p->flags |= P_DEF_ALLOCED;
9945 p->flags &= ~P_ALLOCED; /* don't free the value now */
9946 }
9947 }
9948 }
9949}
9950
9951/*
9952 * return TRUE if 'p' starts with 't_'
9953 */
9954 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009955istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009956{
9957 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9958}
9959
9960/*
9961 * Compute columns for ruler and shown command. 'sc_col' is also used to
9962 * decide what the maximum length of a message on the status line can be.
9963 * If there is a status line for the last window, 'sc_col' is independent
9964 * of 'ru_col'.
9965 */
9966
9967#define COL_RULER 17 /* columns needed by standard ruler */
9968
9969 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009970comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009971{
9972#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9973 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9974
9975 sc_col = 0;
9976 ru_col = 0;
9977 if (p_ru)
9978 {
9979#ifdef FEAT_STL_OPT
9980 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9981#else
9982 ru_col = COL_RULER + 1;
9983#endif
9984 /* no last status line, adjust sc_col */
9985 if (!last_has_status)
9986 sc_col = ru_col;
9987 }
9988 if (p_sc)
9989 {
9990 sc_col += SHOWCMD_COLS;
9991 if (!p_ru || last_has_status) /* no need for separating space */
9992 ++sc_col;
9993 }
9994 sc_col = Columns - sc_col;
9995 ru_col = Columns - ru_col;
9996 if (sc_col <= 0) /* screen too narrow, will become a mess */
9997 sc_col = 1;
9998 if (ru_col <= 0)
9999 ru_col = 1;
10000#else
10001 sc_col = Columns;
10002 ru_col = Columns;
10003#endif
10004}
10005
10006/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010007 * Unset local option value, similar to ":set opt<".
10008 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010009 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010010unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010011{
10012 struct vimoption *p;
10013 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010014 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010015
10016 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010017 if (opt_idx < 0)
10018 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010019 p = &(options[opt_idx]);
10020
10021 switch ((int)p->indir)
10022 {
10023 /* global option with local value: use local value if it's been set */
10024 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010025 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010026 break;
10027 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010028 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010029 break;
10030 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010031 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010032 break;
10033 case PV_AR:
10034 buf->b_p_ar = -1;
10035 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010036 case PV_BKC:
10037 clear_string_option(&buf->b_p_bkc);
10038 buf->b_bkc_flags = 0;
10039 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010040 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010041 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010042 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010043 case PV_TC:
10044 clear_string_option(&buf->b_p_tc);
10045 buf->b_tc_flags = 0;
10046 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010047#ifdef FEAT_FIND_ID
10048 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010049 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010050 break;
10051 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010052 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010053 break;
10054#endif
10055#ifdef FEAT_INS_EXPAND
10056 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010057 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010058 break;
10059 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010060 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010061 break;
10062#endif
10063#ifdef FEAT_QUICKFIX
10064 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010065 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010066 break;
10067 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010068 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010069 break;
10070 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010071 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010072 break;
10073#endif
10074#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10075 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010076 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010077 break;
10078#endif
10079#if defined(FEAT_CRYPT)
10080 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010081 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010082 break;
10083#endif
10084#ifdef FEAT_STL_OPT
10085 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010086 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010087 break;
10088#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010089 case PV_UL:
10090 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10091 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010092#ifdef FEAT_LISP
10093 case PV_LW:
10094 clear_string_option(&buf->b_p_lw);
10095 break;
10096#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097 }
10098}
10099
10100/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101 * Get pointer to option variable, depending on local or global scope.
10102 */
10103 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010104get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010105{
10106 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10107 {
10108 if (p->var == VAR_WIN)
10109 return (char_u *)GLOBAL_WO(get_varp(p));
10110 return p->var;
10111 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010112 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010113 {
10114 switch ((int)p->indir)
10115 {
10116#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010117 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10118 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10119 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010121 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10122 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10123 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010124 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010125 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010126 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010128 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10129 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010130#endif
10131#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010132 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10133 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010134#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010135#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10136 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10137#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010138#if defined(FEAT_CRYPT)
10139 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10140#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010141#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010142 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010143#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010144 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010145#ifdef FEAT_LISP
10146 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10147#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010148 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149 }
10150 return NULL; /* "cannot happen" */
10151 }
10152 return get_varp(p);
10153}
10154
10155/*
10156 * Get pointer to option variable.
10157 */
10158 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010159get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160{
10161 /* hidden option, always return NULL */
10162 if (p->var == NULL)
10163 return NULL;
10164
10165 switch ((int)p->indir)
10166 {
10167 case PV_NONE: return p->var;
10168
10169 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010170 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010172 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010174 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010176 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010177 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010178 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010180 case PV_TC: return *curbuf->b_p_tc != NUL
10181 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010182 case PV_BKC: return *curbuf->b_p_bkc != NUL
10183 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010185 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010187 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10189#endif
10190#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010191 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010193 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10195#endif
10196#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010197 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010199 case PV_GP: return *curbuf->b_p_gp != NUL
10200 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10201 case PV_MP: return *curbuf->b_p_mp != NUL
10202 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010204#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10205 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10206 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10207#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010208#if defined(FEAT_CRYPT)
10209 case PV_CM: return *curbuf->b_p_cm != NUL
10210 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10211#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010212#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010213 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010214 ? (char_u *)&(curwin->w_p_stl) : p->var;
10215#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010216 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10217 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010218#ifdef FEAT_LISP
10219 case PV_LW: return *curbuf->b_p_lw != NUL
10220 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010222
10223#ifdef FEAT_ARABIC
10224 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10225#endif
10226 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010227#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010228 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10229#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010230#ifdef FEAT_SYN_HL
10231 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10232 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010233 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010234#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010235#ifdef FEAT_DIFF
10236 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10237#endif
10238#ifdef FEAT_FOLDING
10239 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10240 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10241 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10242 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10243 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10244 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10245 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10246# ifdef FEAT_EVAL
10247 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10248 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10249# endif
10250 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10251#endif
10252 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010253 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010254#ifdef FEAT_LINEBREAK
10255 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10256#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010257#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010258 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010259 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10262 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10263#endif
10264#ifdef FEAT_RIGHTLEFT
10265 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10266 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10267#endif
10268 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10269 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10270#ifdef FEAT_LINEBREAK
10271 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010272 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10273 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274#endif
10275#ifdef FEAT_SCROLLBIND
10276 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10277#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010278#ifdef FEAT_CURSORBIND
10279 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10280#endif
10281#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010282 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10283 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010284#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285
10286 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10287 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10288#ifdef FEAT_MBYTE
10289 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10290#endif
10291#if defined(FEAT_QUICKFIX)
10292 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10293 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10294#endif
10295 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10296 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10297#ifdef FEAT_CINDENT
10298 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10299 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10300 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10301#endif
10302#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10303 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10304#endif
10305#ifdef FEAT_COMMENTS
10306 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10307#endif
10308#ifdef FEAT_FOLDING
10309 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10310#endif
10311#ifdef FEAT_INS_EXPAND
10312 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10313#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010314#ifdef FEAT_COMPL_FUNC
10315 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010316 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010319 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10321#ifdef FEAT_MBYTE
10322 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10323#endif
10324 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10325#ifdef FEAT_AUTOCMD
10326 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10327#endif
10328 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010329 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10331 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10332 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10333 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10334#ifdef FEAT_FIND_ID
10335# ifdef FEAT_EVAL
10336 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10337# endif
10338#endif
10339#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10340 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10341 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10342#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010343#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010344 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346#ifdef FEAT_CRYPT
10347 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10348#endif
10349#ifdef FEAT_LISP
10350 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10351#endif
10352 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10353 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10354 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10355 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10356 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010358#ifdef FEAT_TEXTOBJ
10359 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10360#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010361 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10362#ifdef FEAT_SMARTINDENT
10363 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010366 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10367#ifdef FEAT_SEARCHPATH
10368 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10369#endif
10370 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10371#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010372 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010373 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10374#endif
10375#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010376 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10377 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10378 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010379#endif
10380 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10381 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10382 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10383 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010384#ifdef FEAT_PERSISTENT_UNDO
10385 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10388#ifdef FEAT_KEYMAP
10389 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10390#endif
10391 default: EMSG(_("E356: get_varp ERROR"));
10392 }
10393 /* always return a valid pointer to avoid a crash! */
10394 return (char_u *)&(curbuf->b_p_wm);
10395}
10396
10397/*
10398 * Get the value of 'equalprg', either the buffer-local one or the global one.
10399 */
10400 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010401get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402{
10403 if (*curbuf->b_p_ep == NUL)
10404 return p_ep;
10405 return curbuf->b_p_ep;
10406}
10407
10408#if defined(FEAT_WINDOWS) || defined(PROTO)
10409/*
10410 * Copy options from one window to another.
10411 * Used when splitting a window.
10412 */
10413 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010414win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415{
10416 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10417 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10418# ifdef FEAT_RIGHTLEFT
10419# ifdef FEAT_FKMAP
10420 /* Is this right? */
10421 wp_to->w_farsi = wp_from->w_farsi;
10422# endif
10423# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010424#if defined(FEAT_LINEBREAK)
10425 briopt_check(wp_to);
10426#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010427}
10428#endif
10429
10430/*
10431 * Copy the options from one winopt_T to another.
10432 * Doesn't free the old option values in "to", use clear_winopt() for that.
10433 * The 'scroll' option is not copied, because it depends on the window height.
10434 * The 'previewwindow' option is reset, there can be only one preview window.
10435 */
10436 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010437copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438{
10439#ifdef FEAT_ARABIC
10440 to->wo_arab = from->wo_arab;
10441#endif
10442 to->wo_list = from->wo_list;
10443 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010444 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010445#ifdef FEAT_LINEBREAK
10446 to->wo_nuw = from->wo_nuw;
10447#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448#ifdef FEAT_RIGHTLEFT
10449 to->wo_rl = from->wo_rl;
10450 to->wo_rlc = vim_strsave(from->wo_rlc);
10451#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010452#ifdef FEAT_STL_OPT
10453 to->wo_stl = vim_strsave(from->wo_stl);
10454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010455 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010456#ifdef FEAT_DIFF
10457 to->wo_wrap_save = from->wo_wrap_save;
10458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459#ifdef FEAT_LINEBREAK
10460 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010461 to->wo_bri = from->wo_bri;
10462 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010463#endif
10464#ifdef FEAT_SCROLLBIND
10465 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010466 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010467#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010468#ifdef FEAT_CURSORBIND
10469 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010470 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010471#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010472#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010473 to->wo_spell = from->wo_spell;
10474#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010475#ifdef FEAT_SYN_HL
10476 to->wo_cuc = from->wo_cuc;
10477 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010478 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010479#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010480#ifdef FEAT_DIFF
10481 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010482 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010484#ifdef FEAT_CONCEAL
10485 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010486 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010487#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010488#ifdef FEAT_FOLDING
10489 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010490 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010492 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493 to->wo_fdi = vim_strsave(from->wo_fdi);
10494 to->wo_fml = from->wo_fml;
10495 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010496 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010497 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010498 to->wo_fdm_save = from->wo_diff_saved
10499 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500 to->wo_fdn = from->wo_fdn;
10501# ifdef FEAT_EVAL
10502 to->wo_fde = vim_strsave(from->wo_fde);
10503 to->wo_fdt = vim_strsave(from->wo_fdt);
10504# endif
10505 to->wo_fmr = vim_strsave(from->wo_fmr);
10506#endif
10507 check_winopt(to); /* don't want NULL pointers */
10508}
10509
10510/*
10511 * Check string options in a window for a NULL value.
10512 */
10513 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010514check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515{
10516 check_winopt(&win->w_onebuf_opt);
10517 check_winopt(&win->w_allbuf_opt);
10518}
10519
10520/*
10521 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10522 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010523 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010524check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010525{
10526#ifdef FEAT_FOLDING
10527 check_string_option(&wop->wo_fdi);
10528 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010529 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530# ifdef FEAT_EVAL
10531 check_string_option(&wop->wo_fde);
10532 check_string_option(&wop->wo_fdt);
10533# endif
10534 check_string_option(&wop->wo_fmr);
10535#endif
10536#ifdef FEAT_RIGHTLEFT
10537 check_string_option(&wop->wo_rlc);
10538#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010539#ifdef FEAT_STL_OPT
10540 check_string_option(&wop->wo_stl);
10541#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010542#ifdef FEAT_SYN_HL
10543 check_string_option(&wop->wo_cc);
10544#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010545#ifdef FEAT_CONCEAL
10546 check_string_option(&wop->wo_cocu);
10547#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010548#ifdef FEAT_LINEBREAK
10549 check_string_option(&wop->wo_briopt);
10550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551}
10552
10553/*
10554 * Free the allocated memory inside a winopt_T.
10555 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010557clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558{
10559#ifdef FEAT_FOLDING
10560 clear_string_option(&wop->wo_fdi);
10561 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010562 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563# ifdef FEAT_EVAL
10564 clear_string_option(&wop->wo_fde);
10565 clear_string_option(&wop->wo_fdt);
10566# endif
10567 clear_string_option(&wop->wo_fmr);
10568#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010569#ifdef FEAT_LINEBREAK
10570 clear_string_option(&wop->wo_briopt);
10571#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572#ifdef FEAT_RIGHTLEFT
10573 clear_string_option(&wop->wo_rlc);
10574#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010575#ifdef FEAT_STL_OPT
10576 clear_string_option(&wop->wo_stl);
10577#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010578#ifdef FEAT_SYN_HL
10579 clear_string_option(&wop->wo_cc);
10580#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010581#ifdef FEAT_CONCEAL
10582 clear_string_option(&wop->wo_cocu);
10583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584}
10585
10586/*
10587 * Copy global option values to local options for one buffer.
10588 * Used when creating a new buffer and sometimes when entering a buffer.
10589 * flags:
10590 * BCO_ENTER We will enter the buf buffer.
10591 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10592 * appropriate.
10593 * BCO_NOHELP Don't copy the values to a help buffer.
10594 */
10595 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010596buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597{
10598 int should_copy = TRUE;
10599 char_u *save_p_isk = NULL; /* init for GCC */
10600 int dont_do_help;
10601 int did_isk = FALSE;
10602
10603 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010604 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605 */
10606 if (buf == NULL || !buf_valid(buf))
10607 return;
10608
10609 /*
10610 * Skip this when the option defaults have not been set yet. Happens when
10611 * main() allocates the first buffer.
10612 */
10613 if (p_cpo != NULL)
10614 {
10615 /*
10616 * Always copy when entering and 'cpo' contains 'S'.
10617 * Don't copy when already initialized.
10618 * Don't copy when 'cpo' contains 's' and not entering.
10619 * 'S' BCO_ENTER initialized 's' should_copy
10620 * yes yes X X TRUE
10621 * yes no yes X FALSE
10622 * no X yes X FALSE
10623 * X no no yes FALSE
10624 * X no no no TRUE
10625 * no yes no X TRUE
10626 */
10627 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10628 && (buf->b_p_initialized
10629 || (!(flags & BCO_ENTER)
10630 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10631 should_copy = FALSE;
10632
10633 if (should_copy || (flags & BCO_ALWAYS))
10634 {
10635 /* Don't copy the options specific to a help buffer when
10636 * BCO_NOHELP is given or the options were initialized already
10637 * (jumping back to a help file with CTRL-T or CTRL-O) */
10638 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10639 || buf->b_p_initialized;
10640 if (dont_do_help) /* don't free b_p_isk */
10641 {
10642 save_p_isk = buf->b_p_isk;
10643 buf->b_p_isk = NULL;
10644 }
10645 /*
10646 * Always free the allocated strings.
10647 * If not already initialized, set 'readonly' and copy 'fileformat'.
10648 */
10649 if (!buf->b_p_initialized)
10650 {
10651 free_buf_options(buf, TRUE);
10652 buf->b_p_ro = FALSE; /* don't copy readonly */
10653 buf->b_p_tx = p_tx;
10654#ifdef FEAT_MBYTE
10655 buf->b_p_fenc = vim_strsave(p_fenc);
10656#endif
10657 buf->b_p_ff = vim_strsave(p_ff);
10658#if defined(FEAT_QUICKFIX)
10659 buf->b_p_bh = empty_option;
10660 buf->b_p_bt = empty_option;
10661#endif
10662 }
10663 else
10664 free_buf_options(buf, FALSE);
10665
10666 buf->b_p_ai = p_ai;
10667 buf->b_p_ai_nopaste = p_ai_nopaste;
10668 buf->b_p_sw = p_sw;
10669 buf->b_p_tw = p_tw;
10670 buf->b_p_tw_nopaste = p_tw_nopaste;
10671 buf->b_p_tw_nobin = p_tw_nobin;
10672 buf->b_p_wm = p_wm;
10673 buf->b_p_wm_nopaste = p_wm_nopaste;
10674 buf->b_p_wm_nobin = p_wm_nobin;
10675 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010676#ifdef FEAT_MBYTE
10677 buf->b_p_bomb = p_bomb;
10678#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010679 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680 buf->b_p_et = p_et;
10681 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010682 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010683 buf->b_p_ml = p_ml;
10684 buf->b_p_ml_nobin = p_ml_nobin;
10685 buf->b_p_inf = p_inf;
10686 buf->b_p_swf = p_swf;
10687#ifdef FEAT_INS_EXPAND
10688 buf->b_p_cpt = vim_strsave(p_cpt);
10689#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010690#ifdef FEAT_COMPL_FUNC
10691 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010692 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010693#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010694 buf->b_p_sts = p_sts;
10695 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010696 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010697#ifdef FEAT_COMMENTS
10698 buf->b_p_com = vim_strsave(p_com);
10699#endif
10700#ifdef FEAT_FOLDING
10701 buf->b_p_cms = vim_strsave(p_cms);
10702#endif
10703 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010704 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010705 buf->b_p_nf = vim_strsave(p_nf);
10706 buf->b_p_mps = vim_strsave(p_mps);
10707#ifdef FEAT_SMARTINDENT
10708 buf->b_p_si = p_si;
10709#endif
10710 buf->b_p_ci = p_ci;
10711#ifdef FEAT_CINDENT
10712 buf->b_p_cin = p_cin;
10713 buf->b_p_cink = vim_strsave(p_cink);
10714 buf->b_p_cino = vim_strsave(p_cino);
10715#endif
10716#ifdef FEAT_AUTOCMD
10717 /* Don't copy 'filetype', it must be detected */
10718 buf->b_p_ft = empty_option;
10719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720 buf->b_p_pi = p_pi;
10721#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10722 buf->b_p_cinw = vim_strsave(p_cinw);
10723#endif
10724#ifdef FEAT_LISP
10725 buf->b_p_lisp = p_lisp;
10726#endif
10727#ifdef FEAT_SYN_HL
10728 /* Don't copy 'syntax', it must be set */
10729 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010730 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010731 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010732#endif
10733#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010734 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010735 (void)compile_cap_prog(&buf->b_s);
10736 buf->b_s.b_p_spf = vim_strsave(p_spf);
10737 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738#endif
10739#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10740 buf->b_p_inde = vim_strsave(p_inde);
10741 buf->b_p_indk = vim_strsave(p_indk);
10742#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010743#if defined(FEAT_EVAL)
10744 buf->b_p_fex = vim_strsave(p_fex);
10745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746#ifdef FEAT_CRYPT
10747 buf->b_p_key = vim_strsave(p_key);
10748#endif
10749#ifdef FEAT_SEARCHPATH
10750 buf->b_p_sua = vim_strsave(p_sua);
10751#endif
10752#ifdef FEAT_KEYMAP
10753 buf->b_p_keymap = vim_strsave(p_keymap);
10754 buf->b_kmap_state |= KEYMAP_INIT;
10755#endif
10756 /* This isn't really an option, but copying the langmap and IME
10757 * state from the current buffer is better than resetting it. */
10758 buf->b_p_iminsert = p_iminsert;
10759 buf->b_p_imsearch = p_imsearch;
10760
10761 /* options that are normally global but also have a local value
10762 * are not copied, start using the global value */
10763 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010764 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010765 buf->b_p_bkc = empty_option;
10766 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767#ifdef FEAT_QUICKFIX
10768 buf->b_p_gp = empty_option;
10769 buf->b_p_mp = empty_option;
10770 buf->b_p_efm = empty_option;
10771#endif
10772 buf->b_p_ep = empty_option;
10773 buf->b_p_kp = empty_option;
10774 buf->b_p_path = empty_option;
10775 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010776 buf->b_p_tc = empty_option;
10777 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778#ifdef FEAT_FIND_ID
10779 buf->b_p_def = empty_option;
10780 buf->b_p_inc = empty_option;
10781# ifdef FEAT_EVAL
10782 buf->b_p_inex = vim_strsave(p_inex);
10783# endif
10784#endif
10785#ifdef FEAT_INS_EXPAND
10786 buf->b_p_dict = empty_option;
10787 buf->b_p_tsr = empty_option;
10788#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010789#ifdef FEAT_TEXTOBJ
10790 buf->b_p_qe = vim_strsave(p_qe);
10791#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010792#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10793 buf->b_p_bexpr = empty_option;
10794#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010795#if defined(FEAT_CRYPT)
10796 buf->b_p_cm = empty_option;
10797#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010798#ifdef FEAT_PERSISTENT_UNDO
10799 buf->b_p_udf = p_udf;
10800#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010801#ifdef FEAT_LISP
10802 buf->b_p_lw = empty_option;
10803#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010804
10805 /*
10806 * Don't copy the options set by ex_help(), use the saved values,
10807 * when going from a help buffer to a non-help buffer.
10808 * Don't touch these at all when BCO_NOHELP is used and going from
10809 * or to a help buffer.
10810 */
10811 if (dont_do_help)
10812 buf->b_p_isk = save_p_isk;
10813 else
10814 {
10815 buf->b_p_isk = vim_strsave(p_isk);
10816 did_isk = TRUE;
10817 buf->b_p_ts = p_ts;
10818 buf->b_help = FALSE;
10819#ifdef FEAT_QUICKFIX
10820 if (buf->b_p_bt[0] == 'h')
10821 clear_string_option(&buf->b_p_bt);
10822#endif
10823 buf->b_p_ma = p_ma;
10824 }
10825 }
10826
10827 /*
10828 * When the options should be copied (ignoring BCO_ALWAYS), set the
10829 * flag that indicates that the options have been initialized.
10830 */
10831 if (should_copy)
10832 buf->b_p_initialized = TRUE;
10833 }
10834
10835 check_buf_options(buf); /* make sure we don't have NULLs */
10836 if (did_isk)
10837 (void)buf_init_chartab(buf, FALSE);
10838}
10839
10840/*
10841 * Reset the 'modifiable' option and its default value.
10842 */
10843 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010844reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845{
10846 int opt_idx;
10847
10848 curbuf->b_p_ma = FALSE;
10849 p_ma = FALSE;
10850 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010851 if (opt_idx >= 0)
10852 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853}
10854
10855/*
10856 * Set the global value for 'iminsert' to the local value.
10857 */
10858 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010859set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860{
10861 p_iminsert = curbuf->b_p_iminsert;
10862}
10863
10864/*
10865 * Set the global value for 'imsearch' to the local value.
10866 */
10867 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010868set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869{
10870 p_imsearch = curbuf->b_p_imsearch;
10871}
10872
10873#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10874static int expand_option_idx = -1;
10875static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10876static int expand_option_flags = 0;
10877
10878 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010879set_context_in_set_cmd(
10880 expand_T *xp,
10881 char_u *arg,
10882 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883{
10884 int nextchar;
10885 long_u flags = 0; /* init for GCC */
10886 int opt_idx = 0; /* init for GCC */
10887 char_u *p;
10888 char_u *s;
10889 int is_term_option = FALSE;
10890 int key;
10891
10892 expand_option_flags = opt_flags;
10893
10894 xp->xp_context = EXPAND_SETTINGS;
10895 if (*arg == NUL)
10896 {
10897 xp->xp_pattern = arg;
10898 return;
10899 }
10900 p = arg + STRLEN(arg) - 1;
10901 if (*p == ' ' && *(p - 1) != '\\')
10902 {
10903 xp->xp_pattern = p + 1;
10904 return;
10905 }
10906 while (p > arg)
10907 {
10908 s = p;
10909 /* count number of backslashes before ' ' or ',' */
10910 if (*p == ' ' || *p == ',')
10911 {
10912 while (s > arg && *(s - 1) == '\\')
10913 --s;
10914 }
10915 /* break at a space with an even number of backslashes */
10916 if (*p == ' ' && ((p - s) & 1) == 0)
10917 {
10918 ++p;
10919 break;
10920 }
10921 --p;
10922 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010923 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924 {
10925 xp->xp_context = EXPAND_BOOL_SETTINGS;
10926 p += 2;
10927 }
10928 if (STRNCMP(p, "inv", 3) == 0)
10929 {
10930 xp->xp_context = EXPAND_BOOL_SETTINGS;
10931 p += 3;
10932 }
10933 xp->xp_pattern = arg = p;
10934 if (*arg == '<')
10935 {
10936 while (*p != '>')
10937 if (*p++ == NUL) /* expand terminal option name */
10938 return;
10939 key = get_special_key_code(arg + 1);
10940 if (key == 0) /* unknown name */
10941 {
10942 xp->xp_context = EXPAND_NOTHING;
10943 return;
10944 }
10945 nextchar = *++p;
10946 is_term_option = TRUE;
10947 expand_option_name[2] = KEY2TERMCAP0(key);
10948 expand_option_name[3] = KEY2TERMCAP1(key);
10949 }
10950 else
10951 {
10952 if (p[0] == 't' && p[1] == '_')
10953 {
10954 p += 2;
10955 if (*p != NUL)
10956 ++p;
10957 if (*p == NUL)
10958 return; /* expand option name */
10959 nextchar = *++p;
10960 is_term_option = TRUE;
10961 expand_option_name[2] = p[-2];
10962 expand_option_name[3] = p[-1];
10963 }
10964 else
10965 {
10966 /* Allow * wildcard */
10967 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10968 p++;
10969 if (*p == NUL)
10970 return;
10971 nextchar = *p;
10972 *p = NUL;
10973 opt_idx = findoption(arg);
10974 *p = nextchar;
10975 if (opt_idx == -1 || options[opt_idx].var == NULL)
10976 {
10977 xp->xp_context = EXPAND_NOTHING;
10978 return;
10979 }
10980 flags = options[opt_idx].flags;
10981 if (flags & P_BOOL)
10982 {
10983 xp->xp_context = EXPAND_NOTHING;
10984 return;
10985 }
10986 }
10987 }
10988 /* handle "-=" and "+=" */
10989 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10990 {
10991 ++p;
10992 nextchar = '=';
10993 }
10994 if ((nextchar != '=' && nextchar != ':')
10995 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10996 {
10997 xp->xp_context = EXPAND_UNSUCCESSFUL;
10998 return;
10999 }
11000 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11001 {
11002 xp->xp_context = EXPAND_OLD_SETTING;
11003 if (is_term_option)
11004 expand_option_idx = -1;
11005 else
11006 expand_option_idx = opt_idx;
11007 xp->xp_pattern = p + 1;
11008 return;
11009 }
11010 xp->xp_context = EXPAND_NOTHING;
11011 if (is_term_option || (flags & P_NUM))
11012 return;
11013
11014 xp->xp_pattern = p + 1;
11015
11016 if (flags & P_EXPAND)
11017 {
11018 p = options[opt_idx].var;
11019 if (p == (char_u *)&p_bdir
11020 || p == (char_u *)&p_dir
11021 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011022 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011023 || p == (char_u *)&p_rtp
11024#ifdef FEAT_SEARCHPATH
11025 || p == (char_u *)&p_cdpath
11026#endif
11027#ifdef FEAT_SESSION
11028 || p == (char_u *)&p_vdir
11029#endif
11030 )
11031 {
11032 xp->xp_context = EXPAND_DIRECTORIES;
11033 if (p == (char_u *)&p_path
11034#ifdef FEAT_SEARCHPATH
11035 || p == (char_u *)&p_cdpath
11036#endif
11037 )
11038 xp->xp_backslash = XP_BS_THREE;
11039 else
11040 xp->xp_backslash = XP_BS_ONE;
11041 }
11042 else
11043 {
11044 xp->xp_context = EXPAND_FILES;
11045 /* for 'tags' need three backslashes for a space */
11046 if (p == (char_u *)&p_tags)
11047 xp->xp_backslash = XP_BS_THREE;
11048 else
11049 xp->xp_backslash = XP_BS_ONE;
11050 }
11051 }
11052
11053 /* For an option that is a list of file names, find the start of the
11054 * last file name. */
11055 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11056 {
11057 /* count number of backslashes before ' ' or ',' */
11058 if (*p == ' ' || *p == ',')
11059 {
11060 s = p;
11061 while (s > xp->xp_pattern && *(s - 1) == '\\')
11062 --s;
11063 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11064 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11065 {
11066 xp->xp_pattern = p + 1;
11067 break;
11068 }
11069 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011070
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011071#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011072 /* for 'spellsuggest' start at "file:" */
11073 if (options[opt_idx].var == (char_u *)&p_sps
11074 && STRNCMP(p, "file:", 5) == 0)
11075 {
11076 xp->xp_pattern = p + 5;
11077 break;
11078 }
11079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011080 }
11081
11082 return;
11083}
11084
11085 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011086ExpandSettings(
11087 expand_T *xp,
11088 regmatch_T *regmatch,
11089 int *num_file,
11090 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091{
11092 int num_normal = 0; /* Nr of matching non-term-code settings */
11093 int num_term = 0; /* Nr of matching terminal code settings */
11094 int opt_idx;
11095 int match;
11096 int count = 0;
11097 char_u *str;
11098 int loop;
11099 int is_term_opt;
11100 char_u name_buf[MAX_KEY_NAME_LEN];
11101 static char *(names[]) = {"all", "termcap"};
11102 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11103
11104 /* do this loop twice:
11105 * loop == 0: count the number of matching options
11106 * loop == 1: copy the matching options into allocated memory
11107 */
11108 for (loop = 0; loop <= 1; ++loop)
11109 {
11110 regmatch->rm_ic = ic;
11111 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11112 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011113 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11114 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11116 {
11117 if (loop == 0)
11118 num_normal++;
11119 else
11120 (*file)[count++] = vim_strsave((char_u *)names[match]);
11121 }
11122 }
11123 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11124 opt_idx++)
11125 {
11126 if (options[opt_idx].var == NULL)
11127 continue;
11128 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11129 && !(options[opt_idx].flags & P_BOOL))
11130 continue;
11131 is_term_opt = istermoption(&options[opt_idx]);
11132 if (is_term_opt && num_normal > 0)
11133 continue;
11134 match = FALSE;
11135 if (vim_regexec(regmatch, str, (colnr_T)0)
11136 || (options[opt_idx].shortname != NULL
11137 && vim_regexec(regmatch,
11138 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11139 match = TRUE;
11140 else if (is_term_opt)
11141 {
11142 name_buf[0] = '<';
11143 name_buf[1] = 't';
11144 name_buf[2] = '_';
11145 name_buf[3] = str[2];
11146 name_buf[4] = str[3];
11147 name_buf[5] = '>';
11148 name_buf[6] = NUL;
11149 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11150 {
11151 match = TRUE;
11152 str = name_buf;
11153 }
11154 }
11155 if (match)
11156 {
11157 if (loop == 0)
11158 {
11159 if (is_term_opt)
11160 num_term++;
11161 else
11162 num_normal++;
11163 }
11164 else
11165 (*file)[count++] = vim_strsave(str);
11166 }
11167 }
11168 /*
11169 * Check terminal key codes, these are not in the option table
11170 */
11171 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11172 {
11173 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11174 {
11175 if (!isprint(str[0]) || !isprint(str[1]))
11176 continue;
11177
11178 name_buf[0] = 't';
11179 name_buf[1] = '_';
11180 name_buf[2] = str[0];
11181 name_buf[3] = str[1];
11182 name_buf[4] = NUL;
11183
11184 match = FALSE;
11185 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11186 match = TRUE;
11187 else
11188 {
11189 name_buf[0] = '<';
11190 name_buf[1] = 't';
11191 name_buf[2] = '_';
11192 name_buf[3] = str[0];
11193 name_buf[4] = str[1];
11194 name_buf[5] = '>';
11195 name_buf[6] = NUL;
11196
11197 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11198 match = TRUE;
11199 }
11200 if (match)
11201 {
11202 if (loop == 0)
11203 num_term++;
11204 else
11205 (*file)[count++] = vim_strsave(name_buf);
11206 }
11207 }
11208
11209 /*
11210 * Check special key names.
11211 */
11212 regmatch->rm_ic = TRUE; /* ignore case here */
11213 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11214 {
11215 name_buf[0] = '<';
11216 STRCPY(name_buf + 1, str);
11217 STRCAT(name_buf, ">");
11218
11219 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11220 {
11221 if (loop == 0)
11222 num_term++;
11223 else
11224 (*file)[count++] = vim_strsave(name_buf);
11225 }
11226 }
11227 }
11228 if (loop == 0)
11229 {
11230 if (num_normal > 0)
11231 *num_file = num_normal;
11232 else if (num_term > 0)
11233 *num_file = num_term;
11234 else
11235 return OK;
11236 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11237 if (*file == NULL)
11238 {
11239 *file = (char_u **)"";
11240 return FAIL;
11241 }
11242 }
11243 }
11244 return OK;
11245}
11246
11247 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011248ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011249{
11250 char_u *var = NULL; /* init for GCC */
11251 char_u *buf;
11252
11253 *num_file = 0;
11254 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11255 if (*file == NULL)
11256 return FAIL;
11257
11258 /*
11259 * For a terminal key code expand_option_idx is < 0.
11260 */
11261 if (expand_option_idx < 0)
11262 {
11263 var = find_termcode(expand_option_name + 2);
11264 if (var == NULL)
11265 expand_option_idx = findoption(expand_option_name);
11266 }
11267
11268 if (expand_option_idx >= 0)
11269 {
11270 /* put string of option value in NameBuff */
11271 option_value2string(&options[expand_option_idx], expand_option_flags);
11272 var = NameBuff;
11273 }
11274 else if (var == NULL)
11275 var = (char_u *)"";
11276
11277 /* A backslash is required before some characters. This is the reverse of
11278 * what happens in do_set(). */
11279 buf = vim_strsave_escaped(var, escape_chars);
11280
11281 if (buf == NULL)
11282 {
11283 vim_free(*file);
11284 *file = NULL;
11285 return FAIL;
11286 }
11287
11288#ifdef BACKSLASH_IN_FILENAME
11289 /* For MS-Windows et al. we don't double backslashes at the start and
11290 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011291 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011292 if (var[0] == '\\' && var[1] == '\\'
11293 && expand_option_idx >= 0
11294 && (options[expand_option_idx].flags & P_EXPAND)
11295 && vim_isfilec(var[2])
11296 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011297 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011298#endif
11299
11300 *file[0] = buf;
11301 *num_file = 1;
11302 return OK;
11303}
11304#endif
11305
11306/*
11307 * Get the value for the numeric or string option *opp in a nice format into
11308 * NameBuff[]. Must not be called with a hidden option!
11309 */
11310 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011311option_value2string(
11312 struct vimoption *opp,
11313 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011314{
11315 char_u *varp;
11316
11317 varp = get_varp_scope(opp, opt_flags);
11318
11319 if (opp->flags & P_NUM)
11320 {
11321 long wc = 0;
11322
11323 if (wc_use_keyname(varp, &wc))
11324 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11325 else if (wc != 0)
11326 STRCPY(NameBuff, transchar((int)wc));
11327 else
11328 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11329 }
11330 else /* P_STRING */
11331 {
11332 varp = *(char_u **)(varp);
11333 if (varp == NULL) /* just in case */
11334 NameBuff[0] = NUL;
11335#ifdef FEAT_CRYPT
11336 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011337 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338 STRCPY(NameBuff, "*****");
11339#endif
11340 else if (opp->flags & P_EXPAND)
11341 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11342 /* Translate 'pastetoggle' into special key names */
11343 else if ((char_u **)opp->var == &p_pt)
11344 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11345 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011346 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011347 }
11348}
11349
11350/*
11351 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11352 * printed as a keyname.
11353 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11354 */
11355 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011356wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011357{
11358 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11359 {
11360 *wcp = *(long *)varp;
11361 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11362 return TRUE;
11363 }
11364 return FALSE;
11365}
11366
Bram Moolenaar01615492015-02-03 13:00:38 +010011367#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011369 * Any character has an equivalent 'langmap' character. This is used for
11370 * keyboards that have a special language mode that sends characters above
11371 * 128 (although other characters can be translated too). The "to" field is a
11372 * Vim command character. This avoids having to switch the keyboard back to
11373 * ASCII mode when leaving Insert mode.
11374 *
11375 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11376 * commands.
11377 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11378 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11379 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011380 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011381# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011382/*
11383 * With multi-byte support use growarray for 'langmap' chars >= 256
11384 */
11385typedef struct
11386{
11387 int from;
11388 int to;
11389} langmap_entry_T;
11390
11391static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011392static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011393
11394/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011395 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11396 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011397 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011398 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011399langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011400{
11401 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011402 int a = 0;
11403 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011404
11405 /* Do a binary search for an existing entry. */
11406 while (a != b)
11407 {
11408 int i = (a + b) / 2;
11409 int d = entries[i].from - from;
11410
11411 if (d == 0)
11412 {
11413 entries[i].to = to;
11414 return;
11415 }
11416 if (d < 0)
11417 a = i + 1;
11418 else
11419 b = i;
11420 }
11421
11422 if (ga_grow(&langmap_mapga, 1) != OK)
11423 return; /* out of memory */
11424
11425 /* insert new entry at position "a" */
11426 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11427 mch_memmove(entries + 1, entries,
11428 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11429 ++langmap_mapga.ga_len;
11430 entries[0].from = from;
11431 entries[0].to = to;
11432}
11433
11434/*
11435 * Apply 'langmap' to multi-byte character "c" and return the result.
11436 */
11437 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011438langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011439{
11440 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11441 int a = 0;
11442 int b = langmap_mapga.ga_len;
11443
11444 while (a != b)
11445 {
11446 int i = (a + b) / 2;
11447 int d = entries[i].from - c;
11448
11449 if (d == 0)
11450 return entries[i].to; /* found matching entry */
11451 if (d < 0)
11452 a = i + 1;
11453 else
11454 b = i;
11455 }
11456 return c; /* no entry found, return "c" unmodified */
11457}
11458# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011459
11460 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011461langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011462{
11463 int i;
11464
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011465 for (i = 0; i < 256; i++)
11466 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11467# ifdef FEAT_MBYTE
11468 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11469# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011470}
11471
11472/*
11473 * Called when langmap option is set; the language map can be
11474 * changed at any time!
11475 */
11476 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011477langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011478{
11479 char_u *p;
11480 char_u *p2;
11481 int from, to;
11482
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011483#ifdef FEAT_MBYTE
11484 ga_clear(&langmap_mapga); /* clear the previous map first */
11485#endif
11486 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011487
11488 for (p = p_langmap; p[0] != NUL; )
11489 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011490 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11491 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011492 {
11493 if (p2[0] == '\\' && p2[1] != NUL)
11494 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011495 }
11496 if (p2[0] == ';')
11497 ++p2; /* abcd;ABCD form, p2 points to A */
11498 else
11499 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11500 while (p[0])
11501 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011502 if (p[0] == ',')
11503 {
11504 ++p;
11505 break;
11506 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011507 if (p[0] == '\\' && p[1] != NUL)
11508 ++p;
11509#ifdef FEAT_MBYTE
11510 from = (*mb_ptr2char)(p);
11511#else
11512 from = p[0];
11513#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011514 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011515 if (p2 == NULL)
11516 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011517 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011518 if (p[0] != ',')
11519 {
11520 if (p[0] == '\\')
11521 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011522#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011523 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011525 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011527 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528 }
11529 else
11530 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011531 if (p2[0] != ',')
11532 {
11533 if (p2[0] == '\\')
11534 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011536 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011537#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011538 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011539#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011540 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011541 }
11542 if (to == NUL)
11543 {
11544 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11545 transchar(from));
11546 return;
11547 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011548
11549#ifdef FEAT_MBYTE
11550 if (from >= 256)
11551 langmap_set_entry(from, to);
11552 else
11553#endif
11554 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555
11556 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011557 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011558 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011559 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011560 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561 if (*p == ';')
11562 {
11563 p = p2;
11564 if (p[0] != NUL)
11565 {
11566 if (p[0] != ',')
11567 {
11568 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11569 return;
11570 }
11571 ++p;
11572 }
11573 break;
11574 }
11575 }
11576 }
11577 }
11578}
11579#endif
11580
11581/*
11582 * Return TRUE if format option 'x' is in effect.
11583 * Take care of no formatting when 'paste' is set.
11584 */
11585 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011586has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011587{
11588 if (p_paste)
11589 return FALSE;
11590 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11591}
11592
11593/*
11594 * Return TRUE if "x" is present in 'shortmess' option, or
11595 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11596 */
11597 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011598shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011599{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011600 return p_shm != NULL &&
11601 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011602 || (vim_strchr(p_shm, 'a') != NULL
11603 && vim_strchr((char_u *)SHM_A, x) != NULL));
11604}
11605
11606/*
11607 * paste_option_changed() - Called after p_paste was set or reset.
11608 */
11609 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011610paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011611{
11612 static int old_p_paste = FALSE;
11613 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011614 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011615#ifdef FEAT_CMDL_INFO
11616 static int save_ru = 0;
11617#endif
11618#ifdef FEAT_RIGHTLEFT
11619 static int save_ri = 0;
11620 static int save_hkmap = 0;
11621#endif
11622 buf_T *buf;
11623
11624 if (p_paste)
11625 {
11626 /*
11627 * Paste switched from off to on.
11628 * Save the current values, so they can be restored later.
11629 */
11630 if (!old_p_paste)
11631 {
11632 /* save options for each buffer */
11633 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11634 {
11635 buf->b_p_tw_nopaste = buf->b_p_tw;
11636 buf->b_p_wm_nopaste = buf->b_p_wm;
11637 buf->b_p_sts_nopaste = buf->b_p_sts;
11638 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011639 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640 }
11641
11642 /* save global options */
11643 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011644 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011645#ifdef FEAT_CMDL_INFO
11646 save_ru = p_ru;
11647#endif
11648#ifdef FEAT_RIGHTLEFT
11649 save_ri = p_ri;
11650 save_hkmap = p_hkmap;
11651#endif
11652 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011653 p_ai_nopaste = p_ai;
11654 p_et_nopaste = p_et;
11655 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011656 p_tw_nopaste = p_tw;
11657 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011658 }
11659
11660 /*
11661 * Always set the option values, also when 'paste' is set when it is
11662 * already on.
11663 */
11664 /* set options for each buffer */
11665 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11666 {
11667 buf->b_p_tw = 0; /* textwidth is 0 */
11668 buf->b_p_wm = 0; /* wrapmargin is 0 */
11669 buf->b_p_sts = 0; /* softtabstop is 0 */
11670 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011671 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011672 }
11673
11674 /* set global options */
11675 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011676 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011677#ifdef FEAT_CMDL_INFO
11678# ifdef FEAT_WINDOWS
11679 if (p_ru)
11680 status_redraw_all(); /* redraw to remove the ruler */
11681# endif
11682 p_ru = 0; /* no ruler */
11683#endif
11684#ifdef FEAT_RIGHTLEFT
11685 p_ri = 0; /* no reverse insert */
11686 p_hkmap = 0; /* no Hebrew keyboard */
11687#endif
11688 /* set global values for local buffer options */
11689 p_tw = 0;
11690 p_wm = 0;
11691 p_sts = 0;
11692 p_ai = 0;
11693 }
11694
11695 /*
11696 * Paste switched from on to off: Restore saved values.
11697 */
11698 else if (old_p_paste)
11699 {
11700 /* restore options for each buffer */
11701 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11702 {
11703 buf->b_p_tw = buf->b_p_tw_nopaste;
11704 buf->b_p_wm = buf->b_p_wm_nopaste;
11705 buf->b_p_sts = buf->b_p_sts_nopaste;
11706 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011707 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011708 }
11709
11710 /* restore global options */
11711 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011712 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011713#ifdef FEAT_CMDL_INFO
11714# ifdef FEAT_WINDOWS
11715 if (p_ru != save_ru)
11716 status_redraw_all(); /* redraw to draw the ruler */
11717# endif
11718 p_ru = save_ru;
11719#endif
11720#ifdef FEAT_RIGHTLEFT
11721 p_ri = save_ri;
11722 p_hkmap = save_hkmap;
11723#endif
11724 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011725 p_ai = p_ai_nopaste;
11726 p_et = p_et_nopaste;
11727 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011728 p_tw = p_tw_nopaste;
11729 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011730 }
11731
11732 old_p_paste = p_paste;
11733}
11734
11735/*
11736 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11737 *
11738 * Reset 'compatible' and set the values for options that didn't get set yet
11739 * to the Vim defaults.
11740 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011741 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011742 */
11743 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011744vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011745{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011746 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011747 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011748 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011749
11750 if (!option_was_set((char_u *)"cp"))
11751 {
11752 p_cp = FALSE;
11753 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11754 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11755 set_option_default(opt_idx, OPT_FREE, FALSE);
11756 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011757 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011758 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011759
11760 if (fname != NULL)
11761 {
11762 p = vim_getenv(envname, &dofree);
11763 if (p == NULL)
11764 {
11765 /* Set $MYVIMRC to the first vimrc file found. */
11766 p = FullName_save(fname, FALSE);
11767 if (p != NULL)
11768 {
11769 vim_setenv(envname, p);
11770 vim_free(p);
11771 }
11772 }
11773 else if (dofree)
11774 vim_free(p);
11775 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776}
11777
11778/*
11779 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11780 */
11781 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011782change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011783{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011784 int opt_idx;
11785
Bram Moolenaar071d4272004-06-13 20:20:40 +000011786 if (p_cp != on)
11787 {
11788 p_cp = on;
11789 compatible_set();
11790 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011791 opt_idx = findoption((char_u *)"cp");
11792 if (opt_idx >= 0)
11793 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794}
11795
11796/*
11797 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011798 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799 */
11800 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011801option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802{
11803 int idx;
11804
11805 idx = findoption(name);
11806 if (idx < 0) /* unknown option */
11807 return FALSE;
11808 if (options[idx].flags & P_WAS_SET)
11809 return TRUE;
11810 return FALSE;
11811}
11812
11813/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011814 * Reset the flag indicating option "name" was set.
11815 */
11816 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011817reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011818{
11819 int idx = findoption(name);
11820
11821 if (idx >= 0)
11822 options[idx].flags &= ~P_WAS_SET;
11823}
11824
11825/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011826 * compatible_set() - Called when 'compatible' has been set or unset.
11827 *
11828 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11829 * flag) to a Vi compatible value.
11830 * When 'compatible' is unset: Set all options that have a different default
11831 * for Vim (without the P_VI_DEF flag) to that default.
11832 */
11833 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011834compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011835{
11836 int opt_idx;
11837
11838 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11839 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11840 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11841 set_option_default(opt_idx, OPT_FREE, p_cp);
11842 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011843 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011844}
11845
11846#ifdef FEAT_LINEBREAK
11847
11848# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11849 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011850 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011851# endif
11852
11853/*
11854 * fill_breakat_flags() -- called when 'breakat' changes value.
11855 */
11856 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011857fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011858{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011859 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011860 int i;
11861
11862 for (i = 0; i < 256; i++)
11863 breakat_flags[i] = FALSE;
11864
11865 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011866 for (p = p_breakat; *p; p++)
11867 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868}
11869
11870# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011871 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011872# endif
11873
11874#endif
11875
11876/*
11877 * Check an option that can be a range of string values.
11878 *
11879 * Return OK for correct value, FAIL otherwise.
11880 * Empty is always OK.
11881 */
11882 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011883check_opt_strings(
11884 char_u *val,
11885 char **values,
11886 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887{
11888 return opt_strings_flags(val, values, NULL, list);
11889}
11890
11891/*
11892 * Handle an option that can be a range of string values.
11893 * Set a flag in "*flagp" for each string present.
11894 *
11895 * Return OK for correct value, FAIL otherwise.
11896 * Empty is always OK.
11897 */
11898 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011899opt_strings_flags(
11900 char_u *val, /* new value */
11901 char **values, /* array of valid string values */
11902 unsigned *flagp,
11903 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011904{
11905 int i;
11906 int len;
11907 unsigned new_flags = 0;
11908
11909 while (*val)
11910 {
11911 for (i = 0; ; ++i)
11912 {
11913 if (values[i] == NULL) /* val not found in values[] */
11914 return FAIL;
11915
11916 len = (int)STRLEN(values[i]);
11917 if (STRNCMP(values[i], val, len) == 0
11918 && ((list && val[len] == ',') || val[len] == NUL))
11919 {
11920 val += len + (val[len] == ',');
11921 new_flags |= (1 << i);
11922 break; /* check next item in val list */
11923 }
11924 }
11925 }
11926 if (flagp != NULL)
11927 *flagp = new_flags;
11928
11929 return OK;
11930}
11931
11932/*
11933 * Read the 'wildmode' option, fill wim_flags[].
11934 */
11935 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011936check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011937{
11938 char_u new_wim_flags[4];
11939 char_u *p;
11940 int i;
11941 int idx = 0;
11942
11943 for (i = 0; i < 4; ++i)
11944 new_wim_flags[i] = 0;
11945
11946 for (p = p_wim; *p; ++p)
11947 {
11948 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11949 ;
11950 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11951 return FAIL;
11952 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11953 new_wim_flags[idx] |= WIM_LONGEST;
11954 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11955 new_wim_flags[idx] |= WIM_FULL;
11956 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11957 new_wim_flags[idx] |= WIM_LIST;
11958 else
11959 return FAIL;
11960 p += i;
11961 if (*p == NUL)
11962 break;
11963 if (*p == ',')
11964 {
11965 if (idx == 3)
11966 return FAIL;
11967 ++idx;
11968 }
11969 }
11970
11971 /* fill remaining entries with last flag */
11972 while (idx < 3)
11973 {
11974 new_wim_flags[idx + 1] = new_wim_flags[idx];
11975 ++idx;
11976 }
11977
11978 /* only when there are no errors, wim_flags[] is changed */
11979 for (i = 0; i < 4; ++i)
11980 wim_flags[i] = new_wim_flags[i];
11981 return OK;
11982}
11983
11984/*
11985 * Check if backspacing over something is allowed.
11986 */
11987 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011988can_bs(
11989 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011990{
11991 switch (*p_bs)
11992 {
11993 case '2': return TRUE;
11994 case '1': return (what != BS_START);
11995 case '0': return FALSE;
11996 }
11997 return vim_strchr(p_bs, what) != NULL;
11998}
11999
12000/*
12001 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12002 * the file must be considered changed when the value is different.
12003 */
12004 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012005save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012006{
12007 buf->b_start_ffc = *buf->b_p_ff;
12008 buf->b_start_eol = buf->b_p_eol;
12009#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012010 buf->b_start_bomb = buf->b_p_bomb;
12011
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012 /* Only use free/alloc when necessary, they take time. */
12013 if (buf->b_start_fenc == NULL
12014 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12015 {
12016 vim_free(buf->b_start_fenc);
12017 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12018 }
12019#endif
12020}
12021
12022/*
12023 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12024 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012025 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12026 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012027 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012028 * When "ignore_empty" is true don't consider a new, empty buffer to be
12029 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012030 */
12031 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012032file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012033{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012034 /* In a buffer that was never loaded the options are not valid. */
12035 if (buf->b_flags & BF_NEVERLOADED)
12036 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012037 if (ignore_empty
12038 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012039 && buf->b_ml.ml_line_count == 1
12040 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12041 return FALSE;
12042 if (buf->b_start_ffc != *buf->b_p_ff)
12043 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012044 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045 return TRUE;
12046#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012047 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12048 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012049 if (buf->b_start_fenc == NULL)
12050 return (*buf->b_p_fenc != NUL);
12051 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12052#else
12053 return FALSE;
12054#endif
12055}
12056
12057/*
12058 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12059 */
12060 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012061check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012062{
12063 return check_opt_strings(p, p_ff_values, FALSE);
12064}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012065
12066/*
12067 * Return the effective shiftwidth value for current buffer, using the
12068 * 'tabstop' value when 'shiftwidth' is zero.
12069 */
12070 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012071get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012072{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012073 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012074}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012075
12076/*
12077 * Return the effective softtabstop value for the current buffer, using the
12078 * 'tabstop' value when 'softtabstop' is negative.
12079 */
12080 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012081get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012082{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012083 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012084}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012085
12086/*
12087 * Check matchpairs option for "*initc".
12088 * If there is a match set "*initc" to the matching character and "*findc" to
12089 * the opposite character. Set "*backwards" to the direction.
12090 * When "switchit" is TRUE swap the direction.
12091 */
12092 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012093find_mps_values(
12094 int *initc,
12095 int *findc,
12096 int *backwards,
12097 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012098{
12099 char_u *ptr;
12100
12101 ptr = curbuf->b_p_mps;
12102 while (*ptr != NUL)
12103 {
12104#ifdef FEAT_MBYTE
12105 if (has_mbyte)
12106 {
12107 char_u *prev;
12108
12109 if (mb_ptr2char(ptr) == *initc)
12110 {
12111 if (switchit)
12112 {
12113 *findc = *initc;
12114 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12115 *backwards = TRUE;
12116 }
12117 else
12118 {
12119 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12120 *backwards = FALSE;
12121 }
12122 return;
12123 }
12124 prev = ptr;
12125 ptr += mb_ptr2len(ptr) + 1;
12126 if (mb_ptr2char(ptr) == *initc)
12127 {
12128 if (switchit)
12129 {
12130 *findc = *initc;
12131 *initc = mb_ptr2char(prev);
12132 *backwards = FALSE;
12133 }
12134 else
12135 {
12136 *findc = mb_ptr2char(prev);
12137 *backwards = TRUE;
12138 }
12139 return;
12140 }
12141 ptr += mb_ptr2len(ptr);
12142 }
12143 else
12144#endif
12145 {
12146 if (*ptr == *initc)
12147 {
12148 if (switchit)
12149 {
12150 *backwards = TRUE;
12151 *findc = *initc;
12152 *initc = ptr[2];
12153 }
12154 else
12155 {
12156 *backwards = FALSE;
12157 *findc = ptr[2];
12158 }
12159 return;
12160 }
12161 ptr += 2;
12162 if (*ptr == *initc)
12163 {
12164 if (switchit)
12165 {
12166 *backwards = FALSE;
12167 *findc = *initc;
12168 *initc = ptr[-2];
12169 }
12170 else
12171 {
12172 *backwards = TRUE;
12173 *findc = ptr[-2];
12174 }
12175 return;
12176 }
12177 ++ptr;
12178 }
12179 if (*ptr == ',')
12180 ++ptr;
12181 }
12182}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012183
12184#if defined(FEAT_LINEBREAK) || defined(PROTO)
12185/*
12186 * This is called when 'breakindentopt' is changed and when a window is
12187 * initialized.
12188 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012189 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012190briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012191{
12192 char_u *p;
12193 int bri_shift = 0;
12194 long bri_min = 20;
12195 int bri_sbr = FALSE;
12196
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012197 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012198 while (*p != NUL)
12199 {
12200 if (STRNCMP(p, "shift:", 6) == 0
12201 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12202 {
12203 p += 6;
12204 bri_shift = getdigits(&p);
12205 }
12206 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12207 {
12208 p += 4;
12209 bri_min = getdigits(&p);
12210 }
12211 else if (STRNCMP(p, "sbr", 3) == 0)
12212 {
12213 p += 3;
12214 bri_sbr = TRUE;
12215 }
12216 if (*p != ',' && *p != NUL)
12217 return FAIL;
12218 if (*p == ',')
12219 ++p;
12220 }
12221
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012222 wp->w_p_brishift = bri_shift;
12223 wp->w_p_brimin = bri_min;
12224 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012225
12226 return OK;
12227}
12228#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012229
12230/*
12231 * Get the local or global value of 'backupcopy'.
12232 */
12233 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012234get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012235{
12236 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12237}