blob: b17fc2822bed165c7390430d4bf06f60dff9ea96 [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 Moolenaar8a633e32016-04-21 21:10:14 +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 Moolenaarfd89d7e2016-06-04 20:25:05 +02001668#ifdef 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 Moolenaara6e42502016-04-20 16:19:52 +02001769 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001770 (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 Moolenaara6e42502016-04-20 16:19:52 +02002015 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002016 (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 Moolenaara6e42502016-04-20 16:19:52 +02002126 {"pythonthreedll", NULL, P_STRING|P_EXPAND|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 Moolenaara6e42502016-04-20 16:19:52 +02002132 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133 (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 Moolenaara6e42502016-04-20 16:19:52 +02002211 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002212 (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)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002595 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002596 (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 Moolenaar61be73b2016-04-29 22:59:22 +02002619 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2620#ifdef FEAT_TERMGUICOLORS
2621 (char_u *)&p_tgc, PV_NONE,
2622 {(char_u *)FALSE, (char_u *)FALSE}
2623#else
2624 (char_u*)NULL, PV_NONE,
2625 {(char_u *)FALSE, (char_u *)FALSE}
2626#endif
2627 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"terse", NULL, P_BOOL|P_VI_DEF,
2629 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"textauto", "ta", P_BOOL|P_VIM,
2632 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2634 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2636 (char_u *)&p_tx, PV_TX,
2637 {
2638#ifdef USE_CRNL
2639 (char_u *)TRUE,
2640#else
2641 (char_u *)FALSE,
2642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002643 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002644 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002647 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002649 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650#else
2651 (char_u *)NULL, PV_NONE,
2652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2655 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657 {"timeout", "to", P_BOOL|P_VI_DEF,
2658 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002659 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2661 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002662 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 {"title", NULL, P_BOOL|P_VI_DEF,
2664#ifdef FEAT_TITLE
2665 (char_u *)&p_title, PV_NONE,
2666#else
2667 (char_u *)NULL, PV_NONE,
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"titlelen", NULL, P_NUM|P_VI_DEF,
2671#ifdef FEAT_TITLE
2672 (char_u *)&p_titlelen, PV_NONE,
2673#else
2674 (char_u *)NULL, PV_NONE,
2675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002677 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678#ifdef FEAT_TITLE
2679 (char_u *)&p_titleold, PV_NONE,
2680 {(char_u *)N_("Thanks for flying Vim"),
2681 (char_u *)0L}
2682#else
2683 (char_u *)NULL, PV_NONE,
2684 {(char_u *)0L, (char_u *)0L}
2685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002686 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"titlestring", NULL, P_STRING|P_VI_DEF,
2688#ifdef FEAT_TITLE
2689 (char_u *)&p_titlestring, PV_NONE,
2690#else
2691 (char_u *)NULL, PV_NONE,
2692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002693 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002695 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 {(char_u *)"icons,tooltips", (char_u *)0L}
2698 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002700#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2702 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704#endif
2705 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2706 (char_u *)&p_ttimeout, 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 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2709 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2712 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2715 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2718#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2719 (char_u *)&p_ttym, PV_NONE,
2720#else
2721 (char_u *)NULL, PV_NONE,
2722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2725 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002727 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2728 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002730 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2731 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002732#ifdef FEAT_PERSISTENT_UNDO
2733 (char_u *)&p_udir, PV_NONE,
2734 {(char_u *)".", (char_u *)0L}
2735#else
2736 (char_u *)NULL, PV_NONE,
2737 {(char_u *)0L, (char_u *)0L}
2738#endif
2739 SCRIPTID_INIT},
2740 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2741#ifdef FEAT_PERSISTENT_UNDO
2742 (char_u *)&p_udf, PV_UDF,
2743#else
2744 (char_u *)NULL, PV_NONE,
2745#endif
2746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002748 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002749 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002750#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 (char_u *)1000L,
2752#else
2753 (char_u *)100L,
2754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002756 {"undoreload", "ur", P_NUM|P_VI_DEF,
2757 (char_u *)&p_ur, PV_NONE,
2758 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"updatecount", "uc", P_NUM|P_VI_DEF,
2760 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"updatetime", "ut", P_NUM|P_VI_DEF,
2763 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"verbose", "vbs", P_NUM|P_VI_DEF,
2766 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002768 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2769 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2772#ifdef FEAT_SESSION
2773 (char_u *)&p_vdir, PV_NONE,
2774 {(char_u *)DFLT_VDIR, (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 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781#ifdef FEAT_SESSION
2782 (char_u *)&p_vop, PV_NONE,
2783 {(char_u *)"folds,options,cursor", (char_u *)0L}
2784#else
2785 (char_u *)NULL, PV_NONE,
2786 {(char_u *)0L, (char_u *)0L}
2787#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002789 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790#ifdef FEAT_VIMINFO
2791 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002792#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002793 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794#else
2795# ifdef AMIGA
2796 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002797 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002799 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800# endif
2801#endif
2802#else
2803 (char_u *)NULL, PV_NONE,
2804 {(char_u *)0L, (char_u *)0L}
2805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002807 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2808 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809#ifdef FEAT_VIRTUALEDIT
2810 (char_u *)&p_ve, PV_NONE,
2811 {(char_u *)"", (char_u *)""}
2812#else
2813 (char_u *)NULL, PV_NONE,
2814 {(char_u *)0L, (char_u *)0L}
2815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2818 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"w300", NULL, P_NUM|P_VI_DEF,
2821 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"w1200", NULL, P_NUM|P_VI_DEF,
2824 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"w9600", NULL, P_NUM|P_VI_DEF,
2827 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"warn", NULL, P_BOOL|P_VI_DEF,
2830 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2833 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002835 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"wildchar", "wc", P_NUM|P_VIM,
2839 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2841 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002842 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002845 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846#ifdef FEAT_WILDIGN
2847 (char_u *)&p_wig, PV_NONE,
2848#else
2849 (char_u *)NULL, PV_NONE,
2850#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002851 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002852 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2853 (char_u *)&p_wic, PV_NONE,
2854 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2856#ifdef FEAT_WILDMENU
2857 (char_u *)&p_wmnu, PV_NONE,
2858#else
2859 (char_u *)NULL, PV_NONE,
2860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002861 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002862 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002864 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002865 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2866#ifdef FEAT_CMDL_COMPL
2867 (char_u *)&p_wop, PV_NONE,
2868 {(char_u *)"", (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 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2875#ifdef FEAT_WAK
2876 (char_u *)&p_wak, PV_NONE,
2877 {(char_u *)"menu", (char_u *)0L}
2878#else
2879 (char_u *)NULL, PV_NONE,
2880 {(char_u *)NULL, (char_u *)0L}
2881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002884 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"winheight", "wh", P_NUM|P_VI_DEF,
2887#ifdef FEAT_WINDOWS
2888 (char_u *)&p_wh, PV_NONE,
2889#else
2890 (char_u *)NULL, PV_NONE,
2891#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002892 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002894#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 (char_u *)VAR_WIN, PV_WFH,
2896#else
2897 (char_u *)NULL, PV_NONE,
2898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002899 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002900 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002901#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002902 (char_u *)VAR_WIN, PV_WFW,
2903#else
2904 (char_u *)NULL, PV_NONE,
2905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2908#ifdef FEAT_WINDOWS
2909 (char_u *)&p_wmh, PV_NONE,
2910#else
2911 (char_u *)NULL, PV_NONE,
2912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002913 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002915#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 (char_u *)&p_wmw, PV_NONE,
2917#else
2918 (char_u *)NULL, PV_NONE,
2919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002922#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 (char_u *)&p_wiw, PV_NONE,
2924#else
2925 (char_u *)NULL, PV_NONE,
2926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2929 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002930 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2932 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002933 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2935 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937 {"write", NULL, P_BOOL|P_VI_DEF,
2938 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940 {"writeany", "wa", P_BOOL|P_VI_DEF,
2941 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002942 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2944 (char_u *)&p_wb, PV_NONE,
2945 {
2946#ifdef FEAT_WRITEBACKUP
2947 (char_u *)TRUE,
2948#else
2949 (char_u *)FALSE,
2950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002951 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952 {"writedelay", "wd", P_NUM|P_VI_DEF,
2953 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002954 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955
2956/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002957#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002959 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960
2961 p_term("t_AB", T_CAB)
2962 p_term("t_AF", T_CAF)
2963 p_term("t_AL", T_CAL)
2964 p_term("t_al", T_AL)
2965 p_term("t_bc", T_BC)
2966 p_term("t_cd", T_CD)
2967 p_term("t_ce", T_CE)
2968 p_term("t_cl", T_CL)
2969 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002970 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 p_term("t_Co", T_CCO)
2972 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002973 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002975#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 p_term("t_CV", T_CSV)
2977#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978 p_term("t_da", T_DA)
2979 p_term("t_db", T_DB)
2980 p_term("t_DL", T_CDL)
2981 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002982 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 p_term("t_fs", T_FS)
2984 p_term("t_IE", T_CIE)
2985 p_term("t_IS", T_CIS)
2986 p_term("t_ke", T_KE)
2987 p_term("t_ks", T_KS)
2988 p_term("t_le", T_LE)
2989 p_term("t_mb", T_MB)
2990 p_term("t_md", T_MD)
2991 p_term("t_me", T_ME)
2992 p_term("t_mr", T_MR)
2993 p_term("t_ms", T_MS)
2994 p_term("t_nd", T_ND)
2995 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002996 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 p_term("t_RI", T_CRI)
2998 p_term("t_RV", T_CRV)
2999 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003001 p_term("t_Sf", T_CSF)
3002 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003004 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 p_term("t_te", T_TE)
3007 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003008 p_term("t_ts", T_TS)
3009 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010 p_term("t_ue", T_UE)
3011 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003012 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013 p_term("t_vb", T_VB)
3014 p_term("t_ve", T_VE)
3015 p_term("t_vi", T_VI)
3016 p_term("t_vs", T_VS)
3017 p_term("t_WP", T_CWP)
3018 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003019 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 p_term("t_xs", T_XS)
3021 p_term("t_ZH", T_CZH)
3022 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003023 p_term("t_8f", T_8F)
3024 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025
3026/* terminal key codes are not in here */
3027
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003028 /* end marker */
3029 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030};
3031
3032#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3033
3034#ifdef FEAT_MBYTE
3035static char *(p_ambw_values[]) = {"single", "double", NULL};
3036#endif
3037static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003038static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003040#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003041static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003042#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003043#ifdef FEAT_CMDL_COMPL
3044static char *(p_wop_values[]) = {"tagfile", NULL};
3045#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046#ifdef FEAT_WAK
3047static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3048#endif
3049static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3051static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053#ifdef FEAT_BROWSE
3054static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3055#endif
3056#ifdef FEAT_SCROLLBIND
3057static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3058#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003059static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003060#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3062#endif
3063#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003064# ifdef FEAT_AUTOCMD
3065static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3066# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003068# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3070#endif
3071static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3072#ifdef FEAT_FOLDING
3073static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003074# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003076# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 NULL};
3078static char *(p_fcl_values[]) = {"all", NULL};
3079#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003080#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003081static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003082#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003084static void set_option_default(int, int opt_flags, int compatible);
3085static void set_options_default(int opt_flags);
3086static char_u *term_bg_default(void);
3087static void did_set_option(int opt_idx, int opt_flags, int new_value);
3088static char_u *illegal_char(char_u *, int);
3089static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003091static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092#endif
3093#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003094static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003096static char_u *option_expand(int opt_idx, char_u *val);
3097static void didset_options(void);
3098static void didset_options2(void);
3099static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003100#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003101static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003102#else
3103# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3104#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003105static void set_string_option_global(int opt_idx, char_u **varp);
3106static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3107static 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);
3108static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003109#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003110static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003113static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003115#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003116static char_u *did_set_spell_option(int is_spellfile);
3117static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003118#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003119#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003120static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003121#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003122static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3123static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3124static void check_redraw(long_u flags);
3125static int findoption(char_u *);
3126static int find_key_option(char_u *);
3127static void showoptions(int all, int opt_flags);
3128static int optval_default(struct vimoption *, char_u *varp);
3129static void showoneopt(struct vimoption *, int opt_flags);
3130static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3131static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3132static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3133static int istermoption(struct vimoption *);
3134static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3135static char_u *get_varp(struct vimoption *);
3136static void option_value2string(struct vimoption *, int opt_flags);
3137static void check_winopt(winopt_T *wop);
3138static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003140static void langmap_init(void);
3141static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003143static void paste_option_changed(void);
3144static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003146static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003148static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3149static int check_opt_strings(char_u *val, char **values, int);
3150static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003151#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003152static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154
3155/*
3156 * Initialize the options, first part.
3157 *
3158 * Called only once from main(), just after creating the first buffer.
3159 */
3160 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003161set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162{
3163 char_u *p;
3164 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003165 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166
3167#ifdef FEAT_LANGMAP
3168 langmap_init();
3169#endif
3170
3171 /* Be Vi compatible by default */
3172 p_cp = TRUE;
3173
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003174 /* Use POSIX compatibility when $VIM_POSIX is set. */
3175 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003176 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003177 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003178 set_string_default("shm", (char_u *)"A");
3179 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003180
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 /*
3182 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003183 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003185 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003186#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003188 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003190 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003192 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193# endif
3194#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003195 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196 set_string_default("sh", p);
3197
3198#ifdef FEAT_WILDIGN
3199 /*
3200 * Set the default for 'backupskip' to include environment variables for
3201 * temp files.
3202 */
3203 {
3204# ifdef UNIX
3205 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3206# else
3207 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3208# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003209 int len;
3210 garray_T ga;
3211 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212
3213 ga_init2(&ga, 1, 100);
3214 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3215 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003216 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217# ifdef UNIX
3218 if (*names[n] == NUL)
3219 p = (char_u *)"/tmp";
3220 else
3221# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003222 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 if (p != NULL && *p != NUL)
3224 {
3225 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003226 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 if (ga_grow(&ga, len) == OK)
3228 {
3229 if (ga.ga_len > 0)
3230 STRCAT(ga.ga_data, ",");
3231 STRCAT(ga.ga_data, p);
3232 add_pathsep(ga.ga_data);
3233 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234 ga.ga_len += len;
3235 }
3236 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003237 if (mustfree)
3238 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239 }
3240 if (ga.ga_data != NULL)
3241 {
3242 set_string_default("bsk", ga.ga_data);
3243 vim_free(ga.ga_data);
3244 }
3245 }
3246#endif
3247
3248 /*
3249 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3250 */
3251 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003252 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003254#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3255 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3256#endif
3257 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003260 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261#else
3262# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003263 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003264 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003266 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267# endif
3268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003270 opt_idx = findoption((char_u *)"maxmem");
3271 if (opt_idx >= 0)
3272 {
3273#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003274 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3275 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003276#endif
3277 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3278 }
3279 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280 }
3281
3282#ifdef FEAT_GUI_W32
3283 /* force 'shortname' for Win32s */
3284 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003285 {
3286 opt_idx = findoption((char_u *)"shortname");
3287 if (opt_idx >= 0)
3288 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3289 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003290#endif
3291
3292#ifdef FEAT_SEARCHPATH
3293 {
3294 char_u *cdpath;
3295 char_u *buf;
3296 int i;
3297 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003298 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299
3300 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003301 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302 if (cdpath != NULL)
3303 {
3304 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3305 if (buf != NULL)
3306 {
3307 buf[0] = ','; /* start with ",", current dir first */
3308 j = 1;
3309 for (i = 0; cdpath[i] != NUL; ++i)
3310 {
3311 if (vim_ispathlistsep(cdpath[i]))
3312 buf[j++] = ',';
3313 else
3314 {
3315 if (cdpath[i] == ' ' || cdpath[i] == ',')
3316 buf[j++] = '\\';
3317 buf[j++] = cdpath[i];
3318 }
3319 }
3320 buf[j] = NUL;
3321 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003322 if (opt_idx >= 0)
3323 {
3324 options[opt_idx].def_val[VI_DEFAULT] = buf;
3325 options[opt_idx].flags |= P_DEF_ALLOCED;
3326 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003327 else
3328 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003330 if (mustfree)
3331 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332 }
3333 }
3334#endif
3335
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003336#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337 /* Set print encoding on platforms that don't default to latin1 */
3338 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003339# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340 (char_u *)"cp1252"
3341# else
3342# ifdef VMS
3343 (char_u *)"dec-mcs"
3344# else
3345# ifdef EBCDIC
3346 (char_u *)"ebcdic-uk"
3347# else
3348# ifdef MAC
3349 (char_u *)"mac-roman"
3350# else /* HPUX */
3351 (char_u *)"hp-roman8"
3352# endif
3353# endif
3354# endif
3355# endif
3356 );
3357#endif
3358
3359#ifdef FEAT_POSTSCRIPT
3360 /* 'printexpr' must be allocated to be able to evaluate it. */
3361 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003362# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003363 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003364# else
3365# ifdef VMS
3366 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3367
3368# else
3369 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3370# endif
3371# endif
3372 );
3373#endif
3374
3375 /*
3376 * Set all the options (except the terminal options) to their default
3377 * value. Also set the global value for local options.
3378 */
3379 set_options_default(0);
3380
3381#ifdef FEAT_GUI
3382 if (found_reverse_arg)
3383 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3384#endif
3385
3386 curbuf->b_p_initialized = TRUE;
3387 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003388 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 check_buf_options(curbuf);
3390 check_win_options(curwin);
3391 check_options();
3392
3393 /* Must be before option_expand(), because that one needs vim_isIDc() */
3394 didset_options();
3395
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003396#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003397 /* Use the current chartab for the generic chartab. This is not in
3398 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003399 init_spell_chartab();
3400#endif
3401
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402 /*
3403 * Expand environment variables and things like "~" for the defaults.
3404 * If option_expand() returns non-NULL the variable is expanded. This can
3405 * only happen for non-indirect options.
3406 * Also set the default to the expanded value, so ":set" does not list
3407 * them.
3408 * Don't set the P_ALLOCED flag, because we don't want to free the
3409 * default.
3410 */
3411 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3412 {
3413 if ((options[opt_idx].flags & P_GETTEXT)
3414 && options[opt_idx].var != NULL)
3415 p = (char_u *)_(*(char **)options[opt_idx].var);
3416 else
3417 p = option_expand(opt_idx, NULL);
3418 if (p != NULL && (p = vim_strsave(p)) != NULL)
3419 {
3420 *(char_u **)options[opt_idx].var = p;
3421 /* VIMEXP
3422 * Defaults for all expanded options are currently the same for Vi
3423 * and Vim. When this changes, add some code here! Also need to
3424 * split P_DEF_ALLOCED in two.
3425 */
3426 if (options[opt_idx].flags & P_DEF_ALLOCED)
3427 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3428 options[opt_idx].def_val[VI_DEFAULT] = p;
3429 options[opt_idx].flags |= P_DEF_ALLOCED;
3430 }
3431 }
3432
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 save_file_ff(curbuf); /* Buffer is unchanged */
3434
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435#if defined(FEAT_ARABIC)
3436 /* Detect use of mlterm.
3437 * Mlterm is a terminal emulator akin to xterm that has some special
3438 * abilities (bidi namely).
3439 * NOTE: mlterm's author is being asked to 'set' a variable
3440 * instead of an environment variable due to inheritance.
3441 */
3442 if (mch_getenv((char_u *)"MLTERM") != NULL)
3443 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3444#endif
3445
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003446 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447
3448#ifdef FEAT_MBYTE
3449# if defined(WIN3264) && defined(FEAT_GETTEXT)
3450 /*
3451 * If $LANG isn't set, try to get a good value for it. This makes the
3452 * right language be used automatically. Don't do this for English.
3453 */
3454 if (mch_getenv((char_u *)"LANG") == NULL)
3455 {
3456 char buf[20];
3457
3458 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3459 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3460 * only the first two. */
3461 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3462 (LPTSTR)buf, 20);
3463 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3464 {
3465 /* There are a few exceptions (probably more) */
3466 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3467 STRCPY(buf, "zh_TW");
3468 else if (STRNICMP(buf, "chs", 3) == 0
3469 || STRNICMP(buf, "zhc", 3) == 0)
3470 STRCPY(buf, "zh_CN");
3471 else if (STRNICMP(buf, "jp", 2) == 0)
3472 STRCPY(buf, "ja");
3473 else
3474 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003475 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476 }
3477 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003478# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003479# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003480 /* Moved to os_mac_conv.c to avoid dependency problems. */
3481 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003482# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483# endif
3484
3485 /* enc_locale() will try to find the encoding of the current locale. */
3486 p = enc_locale();
3487 if (p != NULL)
3488 {
3489 char_u *save_enc;
3490
3491 /* Try setting 'encoding' and check if the value is valid.
3492 * If not, go back to the default "latin1". */
3493 save_enc = p_enc;
3494 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003495 if (STRCMP(p_enc, "gb18030") == 0)
3496 {
3497 /* We don't support "gb18030", but "cp936" is a good substitute
3498 * for practical purposes, thus use that. It's not an alias to
3499 * still support conversion between gb18030 and utf-8. */
3500 p_enc = vim_strsave((char_u *)"cp936");
3501 vim_free(p);
3502 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003503 if (mb_init() == NULL)
3504 {
3505 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003506 if (opt_idx >= 0)
3507 {
3508 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3509 options[opt_idx].flags |= P_DEF_ALLOCED;
3510 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003512#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003513 if (STRCMP(p_enc, "latin1") == 0
3514# ifdef FEAT_MBYTE
3515 || enc_utf8
3516# endif
3517 )
3518 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003519 /* Adjust the default for 'isprint' and 'iskeyword' to match
3520 * latin1. Also set the defaults for when 'nocompatible' is
3521 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003522 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003523 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003524 set_string_option_direct((char_u *)"isk", -1,
3525 ISK_LATIN1, OPT_FREE, SID_NONE);
3526 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003527 if (opt_idx >= 0)
3528 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003529 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003530 if (opt_idx >= 0)
3531 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003532 (void)init_chartab();
3533 }
3534#endif
3535
Bram Moolenaar071d4272004-06-13 20:20:40 +00003536# if defined(WIN3264) && !defined(FEAT_GUI)
3537 /* Win32 console: When GetACP() returns a different value from
3538 * GetConsoleCP() set 'termencoding'. */
3539 if (GetACP() != GetConsoleCP())
3540 {
3541 char buf[50];
3542
3543 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3544 p_tenc = vim_strsave((char_u *)buf);
3545 if (p_tenc != NULL)
3546 {
3547 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003548 if (opt_idx >= 0)
3549 {
3550 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3551 options[opt_idx].flags |= P_DEF_ALLOCED;
3552 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 convert_setup(&input_conv, p_tenc, p_enc);
3554 convert_setup(&output_conv, p_enc, p_tenc);
3555 }
3556 else
3557 p_tenc = empty_option;
3558 }
3559# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003560# if defined(WIN3264) && defined(FEAT_MBYTE)
3561 /* $HOME may have characters in active code page. */
3562 init_homedir();
3563# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564 }
3565 else
3566 {
3567 vim_free(p_enc);
3568 p_enc = save_enc;
3569 }
3570 }
3571#endif
3572
3573#ifdef FEAT_MULTI_LANG
3574 /* Set the default for 'helplang'. */
3575 set_helplang_default(get_mess_lang());
3576#endif
3577}
3578
3579/*
3580 * Set an option to its default value.
3581 * This does not take care of side effects!
3582 */
3583 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003584set_option_default(
3585 int opt_idx,
3586 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3587 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588{
3589 char_u *varp; /* pointer to variable for current option */
3590 int dvi; /* index in def_val[] */
3591 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003592 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3594
3595 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3596 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003597 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 {
3599 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3600 if (flags & P_STRING)
3601 {
3602 /* Use set_string_option_direct() for local options to handle
3603 * freeing and allocating the value. */
3604 if (options[opt_idx].indir != PV_NONE)
3605 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003606 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607 else
3608 {
3609 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3610 free_string_option(*(char_u **)(varp));
3611 *(char_u **)varp = options[opt_idx].def_val[dvi];
3612 options[opt_idx].flags &= ~P_ALLOCED;
3613 }
3614 }
3615 else if (flags & P_NUM)
3616 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003617 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 win_comp_scroll(curwin);
3619 else
3620 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003621 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 /* May also set global value for local option. */
3623 if (both)
3624 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3625 *(long *)varp;
3626 }
3627 }
3628 else /* P_BOOL */
3629 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003630 /* the cast to long is required for Manx C, long_i is needed for
3631 * MSVC */
3632 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003633#ifdef UNIX
3634 /* 'modeline' defaults to off for root */
3635 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3636 *(int *)varp = FALSE;
3637#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638 /* May also set global value for local option. */
3639 if (both)
3640 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3641 *(int *)varp;
3642 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003643
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003644 /* The default value is not insecure. */
3645 flagsp = insecure_flag(opt_idx, opt_flags);
3646 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003647 }
3648
3649#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003650 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651#endif
3652}
3653
3654/*
3655 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003656 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003657 */
3658 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003659set_options_default(
3660 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661{
3662 int i;
3663#ifdef FEAT_WINDOWS
3664 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003665 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003666#endif
3667
3668 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003669 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003670#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003671 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003672 || (TRUE
3673# if defined(FEAT_MBYTE)
3674 && options[i].var != (char_u *)&p_enc
3675# endif
3676# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003677 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003678 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003679# endif
3680 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003681#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003682 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683 set_option_default(i, opt_flags, p_cp);
3684
3685#ifdef FEAT_WINDOWS
3686 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003687 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688 win_comp_scroll(wp);
3689#else
3690 win_comp_scroll(curwin);
3691#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003692#ifdef FEAT_CINDENT
3693 parse_cino(curbuf);
3694#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695}
3696
3697/*
3698 * Set the Vi-default value of a string option.
3699 * Used for 'sh', 'backupskip' and 'term'.
3700 */
3701 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003702set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703{
3704 char_u *p;
3705 int opt_idx;
3706
3707 p = vim_strsave(val);
3708 if (p != NULL) /* we don't want a NULL */
3709 {
3710 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003711 if (opt_idx >= 0)
3712 {
3713 if (options[opt_idx].flags & P_DEF_ALLOCED)
3714 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3715 options[opt_idx].def_val[VI_DEFAULT] = p;
3716 options[opt_idx].flags |= P_DEF_ALLOCED;
3717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 }
3719}
3720
3721/*
3722 * Set the Vi-default value of a number option.
3723 * Used for 'lines' and 'columns'.
3724 */
3725 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003726set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003728 int opt_idx;
3729
3730 opt_idx = findoption((char_u *)name);
3731 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003732 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733}
3734
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003735#if defined(EXITFREE) || defined(PROTO)
3736/*
3737 * Free all options.
3738 */
3739 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003740free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003741{
3742 int i;
3743
3744 for (i = 0; !istermoption(&options[i]); i++)
3745 {
3746 if (options[i].indir == PV_NONE)
3747 {
3748 /* global option: free value and default value. */
3749 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3750 free_string_option(*(char_u **)options[i].var);
3751 if (options[i].flags & P_DEF_ALLOCED)
3752 free_string_option(options[i].def_val[VI_DEFAULT]);
3753 }
3754 else if (options[i].var != VAR_WIN
3755 && (options[i].flags & P_STRING))
3756 /* buffer-local option: free global value */
3757 free_string_option(*(char_u **)options[i].var);
3758 }
3759}
3760#endif
3761
3762
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763/*
3764 * Initialize the options, part two: After getting Rows and Columns and
3765 * setting 'term'.
3766 */
3767 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003768set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003770 int idx;
3771
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 /*
3773 * 'scroll' defaults to half the window height. Note that this default is
3774 * wrong when the window height changes.
3775 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003776 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003777 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003778 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003779 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780 comp_col();
3781
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003782 /*
3783 * 'window' is only for backwards compatibility with Vi.
3784 * Default is Rows - 1.
3785 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003786 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003787 p_window = Rows - 1;
3788 set_number_default("window", Rows - 1);
3789
Bram Moolenaarf740b292006-02-16 22:11:02 +00003790 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003791#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003792 /*
3793 * If 'background' wasn't set by the user, try guessing the value,
3794 * depending on the terminal name. Only need to check for terminals
3795 * with a dark background, that can handle color.
3796 */
3797 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003798 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3799 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003801 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003802 /* don't mark it as set, when starting the GUI it may be
3803 * changed again */
3804 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805 }
3806#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003807
3808#ifdef CURSOR_SHAPE
3809 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3810#endif
3811#ifdef FEAT_MOUSESHAPE
3812 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3813#endif
3814#ifdef FEAT_PRINTER
3815 (void)parse_printoptions(); /* parse 'printoptions' default value */
3816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817}
3818
3819/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003820 * Return "dark" or "light" depending on the kind of terminal.
3821 * This is just guessing! Recognized are:
3822 * "linux" Linux console
3823 * "screen.linux" Linux console with screen
3824 * "cygwin" Cygwin shell
3825 * "putty" Putty program
3826 * We also check the COLORFGBG environment variable, which is set by
3827 * rxvt and derivatives. This variable contains either two or three
3828 * values separated by semicolons; we want the last value in either
3829 * case. If this value is 0-6 or 8, our background is dark.
3830 */
3831 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003832term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003833{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003834#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003835 /* DOS console nearly always black */
3836 return (char_u *)"dark";
3837#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003838 char_u *p;
3839
Bram Moolenaarf740b292006-02-16 22:11:02 +00003840 if (STRCMP(T_NAME, "linux") == 0
3841 || STRCMP(T_NAME, "screen.linux") == 0
3842 || STRCMP(T_NAME, "cygwin") == 0
3843 || STRCMP(T_NAME, "putty") == 0
3844 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3845 && (p = vim_strrchr(p, ';')) != NULL
3846 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3847 && p[2] == NUL))
3848 return (char_u *)"dark";
3849 return (char_u *)"light";
3850#endif
3851}
3852
3853/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 * Initialize the options, part three: After reading the .vimrc
3855 */
3856 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003857set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003859#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003860/*
3861 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3862 * This is done after other initializations, where 'shell' might have been
3863 * set, but only if they have not been set before.
3864 */
3865 char_u *p;
3866 int idx_srr;
3867 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003868# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 int idx_sp;
3870 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003871# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872
3873 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003874 if (idx_srr < 0)
3875 do_srr = FALSE;
3876 else
3877 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003878# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003880 if (idx_sp < 0)
3881 do_sp = FALSE;
3882 else
3883 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003884# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003885 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886 if (p != NULL)
3887 {
3888 /*
3889 * Default for p_sp is "| tee", for p_srr is ">".
3890 * For known shells it is changed here to include stderr.
3891 */
3892 if ( fnamecmp(p, "csh") == 0
3893 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003894# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 || fnamecmp(p, "csh.exe") == 0
3896 || fnamecmp(p, "tcsh.exe") == 0
3897# endif
3898 )
3899 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003900# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 if (do_sp)
3902 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003903# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003905# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003907# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3909 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003910# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 if (do_srr)
3912 {
3913 p_srr = (char_u *)">&";
3914 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3915 }
3916 }
3917 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003918 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 if ( fnamecmp(p, "sh") == 0
3920 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003921 || fnamecmp(p, "mksh") == 0
3922 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003924 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003926 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003927# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 || fnamecmp(p, "cmd") == 0
3929 || fnamecmp(p, "sh.exe") == 0
3930 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003931 || fnamecmp(p, "mksh.exe") == 0
3932 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003934 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 || fnamecmp(p, "bash.exe") == 0
3936 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003938 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003940# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 if (do_sp)
3942 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003943# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003945# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003947# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3949 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003950# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 if (do_srr)
3952 {
3953 p_srr = (char_u *)">%s 2>&1";
3954 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3955 }
3956 }
3957 vim_free(p);
3958 }
3959#endif
3960
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003961#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003963 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3964 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965 * This is done after other initializations, where 'shell' might have been
3966 * set, but only if they have not been set before. Default for p_shcf is
3967 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003968 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003970 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 {
3972 int idx3;
3973
3974 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003975 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976 {
3977 p_shcf = (char_u *)"-c";
3978 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3979 }
3980
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003981# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982 /* Somehow Win32 requires the quotes around the redirection too */
3983 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003984 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985 {
3986 p_sxq = (char_u *)"\"";
3987 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3988 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003989# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003991 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003992 {
3993 p_shq = (char_u *)"\"";
3994 options[idx3].def_val[VI_DEFAULT] = p_shq;
3995 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003996# endif
3997 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003998 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3999 {
4000 int idx3;
4001
4002 /*
4003 * cmd.exe on Windows will strip the first and last double quote given
4004 * on the command line, e.g. most of the time things like:
4005 * cmd /c "my path/to/echo" "my args to echo"
4006 * become:
4007 * my path/to/echo" "my args to echo
4008 * when executed.
4009 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004010 * To avoid this, set shellxquote to surround the command in
4011 * parenthesis. This appears to make most commands work, without
4012 * breaking commands that worked previously, such as
4013 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004014 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004015 idx3 = findoption((char_u *)"sxq");
4016 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4017 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004018 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004019 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4020 }
4021
Bram Moolenaara64ba222012-02-12 23:23:31 +01004022 idx3 = findoption((char_u *)"shcf");
4023 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4024 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004025 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004026 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4027 }
4028 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029#endif
4030
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004031 if (bufempty())
4032 {
4033 int idx_ffs = findoption((char_u *)"ffs");
4034
4035 /* Apply the first entry of 'fileformats' to the initial buffer. */
4036 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4037 set_fileformat(default_fileformat(), OPT_LOCAL);
4038 }
4039
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040#ifdef FEAT_TITLE
4041 set_title_defaults();
4042#endif
4043}
4044
4045#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4046/*
4047 * When 'helplang' is still at its default value, set it to "lang".
4048 * Only the first two characters of "lang" are used.
4049 */
4050 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004051set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052{
4053 int idx;
4054
4055 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4056 return;
4057 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004058 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 {
4060 if (options[idx].flags & P_ALLOCED)
4061 free_string_option(p_hlg);
4062 p_hlg = vim_strsave(lang);
4063 if (p_hlg == NULL)
4064 p_hlg = empty_option;
4065 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004066 {
4067 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4068 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4069 {
4070 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4071 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4072 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004074 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075 options[idx].flags |= P_ALLOCED;
4076 }
4077}
4078#endif
4079
4080#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004081static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082
4083 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004084gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085{
4086 if (gui_get_lightness(gui.back_pixel) < 127)
4087 return (char_u *)"dark";
4088 return (char_u *)"light";
4089}
4090
4091/*
4092 * Option initializations that can only be done after opening the GUI window.
4093 */
4094 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004095init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096{
4097 /* Set the 'background' option according to the lightness of the
4098 * background color, unless the user has set it already. */
4099 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4100 {
4101 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4102 highlight_changed();
4103 }
4104}
4105#endif
4106
4107#ifdef FEAT_TITLE
4108/*
4109 * 'title' and 'icon' only default to true if they have not been set or reset
4110 * in .vimrc and we can read the old value.
4111 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4112 * they can be reset. This reduces startup time when using X on a remote
4113 * machine.
4114 */
4115 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004116set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117{
4118 int idx1;
4119 long val;
4120
4121 /*
4122 * If GUI is (going to be) used, we can always set the window title and
4123 * icon name. Saves a bit of time, because the X11 display server does
4124 * not need to be contacted.
4125 */
4126 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004127 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 {
4129#ifdef FEAT_GUI
4130 if (gui.starting || gui.in_use)
4131 val = TRUE;
4132 else
4133#endif
4134 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004135 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 p_title = val;
4137 }
4138 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004139 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 {
4141#ifdef FEAT_GUI
4142 if (gui.starting || gui.in_use)
4143 val = TRUE;
4144 else
4145#endif
4146 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004147 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 p_icon = val;
4149 }
4150}
4151#endif
4152
4153/*
4154 * Parse 'arg' for option settings.
4155 *
4156 * 'arg' may be IObuff, but only when no errors can be present and option
4157 * does not need to be expanded with option_expand().
4158 * "opt_flags":
4159 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004160 * OPT_GLOBAL for ":setglobal"
4161 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004163 * OPT_WINONLY to only set window-local options
4164 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 *
4166 * returns FAIL if an error is detected, OK otherwise
4167 */
4168 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004169do_set(
4170 char_u *arg, /* option string (may be written to!) */
4171 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172{
4173 int opt_idx;
4174 char_u *errmsg;
4175 char_u errbuf[80];
4176 char_u *startarg;
4177 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4178 int nextchar; /* next non-white char after option name */
4179 int afterchar; /* character just after option name */
4180 int len;
4181 int i;
4182 long value;
4183 int key;
4184 long_u flags; /* flags for current option */
4185 char_u *varp = NULL; /* pointer to variable for current option */
4186 int did_show = FALSE; /* already showed one value */
4187 int adding; /* "opt+=arg" */
4188 int prepending; /* "opt^=arg" */
4189 int removing; /* "opt-=arg" */
4190 int cp_val = 0;
4191 char_u key_name[2];
4192
4193 if (*arg == NUL)
4194 {
4195 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004196 did_show = TRUE;
4197 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004198 }
4199
4200 while (*arg != NUL) /* loop to process all options */
4201 {
4202 errmsg = NULL;
4203 startarg = arg; /* remember for error message */
4204
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004205 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4206 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 {
4208 /*
4209 * ":set all" show all options.
4210 * ":set all&" set all options to their default value.
4211 */
4212 arg += 3;
4213 if (*arg == '&')
4214 {
4215 ++arg;
4216 /* Only for :set command set global value of local options. */
4217 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004218 didset_options();
4219 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004220 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221 }
4222 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004223 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004225 did_show = TRUE;
4226 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004228 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229 {
4230 showoptions(2, opt_flags);
4231 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004232 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233 arg += 7;
4234 }
4235 else
4236 {
4237 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004238 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004239 {
4240 prefix = 0;
4241 arg += 2;
4242 }
4243 else if (STRNCMP(arg, "inv", 3) == 0)
4244 {
4245 prefix = 2;
4246 arg += 3;
4247 }
4248
4249 /* find end of name */
4250 key = 0;
4251 if (*arg == '<')
4252 {
4253 nextchar = 0;
4254 opt_idx = -1;
4255 /* look out for <t_>;> */
4256 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4257 len = 5;
4258 else
4259 {
4260 len = 1;
4261 while (arg[len] != NUL && arg[len] != '>')
4262 ++len;
4263 }
4264 if (arg[len] != '>')
4265 {
4266 errmsg = e_invarg;
4267 goto skip;
4268 }
4269 arg[len] = NUL; /* put NUL after name */
4270 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4271 opt_idx = findoption(arg + 1);
4272 arg[len++] = '>'; /* restore '>' */
4273 if (opt_idx == -1)
4274 key = find_key_option(arg + 1);
4275 }
4276 else
4277 {
4278 len = 0;
4279 /*
4280 * The two characters after "t_" may not be alphanumeric.
4281 */
4282 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4283 len = 4;
4284 else
4285 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4286 ++len;
4287 nextchar = arg[len];
4288 arg[len] = NUL; /* put NUL after name */
4289 opt_idx = findoption(arg);
4290 arg[len] = nextchar; /* restore nextchar */
4291 if (opt_idx == -1)
4292 key = find_key_option(arg);
4293 }
4294
4295 /* remember character after option name */
4296 afterchar = arg[len];
4297
4298 /* skip white space, allow ":set ai ?" */
4299 while (vim_iswhite(arg[len]))
4300 ++len;
4301
4302 adding = FALSE;
4303 prepending = FALSE;
4304 removing = FALSE;
4305 if (arg[len] != NUL && arg[len + 1] == '=')
4306 {
4307 if (arg[len] == '+')
4308 {
4309 adding = TRUE; /* "+=" */
4310 ++len;
4311 }
4312 else if (arg[len] == '^')
4313 {
4314 prepending = TRUE; /* "^=" */
4315 ++len;
4316 }
4317 else if (arg[len] == '-')
4318 {
4319 removing = TRUE; /* "-=" */
4320 ++len;
4321 }
4322 }
4323 nextchar = arg[len];
4324
4325 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4326 {
4327 errmsg = (char_u *)N_("E518: Unknown option");
4328 goto skip;
4329 }
4330
4331 if (opt_idx >= 0)
4332 {
4333 if (options[opt_idx].var == NULL) /* hidden option: skip */
4334 {
4335 /* Only give an error message when requesting the value of
4336 * a hidden option, ignore setting it. */
4337 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4338 && (!(options[opt_idx].flags & P_BOOL)
4339 || nextchar == '?'))
4340 errmsg = (char_u *)N_("E519: Option not supported");
4341 goto skip;
4342 }
4343
4344 flags = options[opt_idx].flags;
4345 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4346 }
4347 else
4348 {
4349 flags = P_STRING;
4350 if (key < 0)
4351 {
4352 key_name[0] = KEY2TERMCAP0(key);
4353 key_name[1] = KEY2TERMCAP1(key);
4354 }
4355 else
4356 {
4357 key_name[0] = KS_KEY;
4358 key_name[1] = (key & 0xff);
4359 }
4360 }
4361
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004362 /* Skip all options that are not window-local (used when showing
4363 * an already loaded buffer in a window). */
4364 if ((opt_flags & OPT_WINONLY)
4365 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4366 goto skip;
4367
Bram Moolenaara3227e22006-03-08 21:32:40 +00004368 /* Skip all options that are window-local (used for :vimgrep). */
4369 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4370 && options[opt_idx].var == VAR_WIN)
4371 goto skip;
4372
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004373 /* Disallow changing some options from modelines. */
4374 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004376 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004377 {
4378 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4379 goto skip;
4380 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004381#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004382 /* In diff mode some options are overruled. This avoids that
4383 * 'foldmethod' becomes "marker" instead of "diff" and that
4384 * "wrap" gets set. */
4385 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004386 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004387 && (options[opt_idx].indir == PV_FDM
4388 || options[opt_idx].indir == PV_WRAP))
4389 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004391 }
4392
4393#ifdef HAVE_SANDBOX
4394 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004395 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004396 {
4397 errmsg = (char_u *)_(e_sandbox);
4398 goto skip;
4399 }
4400#endif
4401
4402 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4403 {
4404 arg += len;
4405 cp_val = p_cp;
4406 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4407 {
4408 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4409 {
4410 cp_val = FALSE;
4411 arg += 3;
4412 }
4413 else /* "opt&vi": set to Vi default */
4414 {
4415 cp_val = TRUE;
4416 arg += 2;
4417 }
4418 }
4419 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4420 && arg[1] != NUL && !vim_iswhite(arg[1]))
4421 {
4422 errmsg = e_trailing;
4423 goto skip;
4424 }
4425 }
4426
4427 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004428 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4429 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004430 */
4431 if (nextchar == '?'
4432 || (prefix == 1
4433 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4434 && !(flags & P_BOOL)))
4435 {
4436 /*
4437 * print value
4438 */
4439 if (did_show)
4440 msg_putchar('\n'); /* cursor below last one */
4441 else
4442 {
4443 gotocmdline(TRUE); /* cursor at status line */
4444 did_show = TRUE; /* remember that we did a line */
4445 }
4446 if (opt_idx >= 0)
4447 {
4448 showoneopt(&options[opt_idx], opt_flags);
4449#ifdef FEAT_EVAL
4450 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004451 {
4452 /* Mention where the option was last set. */
4453 if (varp == options[opt_idx].var)
4454 last_set_msg(options[opt_idx].scriptID);
4455 else if ((int)options[opt_idx].indir & PV_WIN)
4456 last_set_msg(curwin->w_p_scriptID[
4457 (int)options[opt_idx].indir & PV_MASK]);
4458 else if ((int)options[opt_idx].indir & PV_BUF)
4459 last_set_msg(curbuf->b_p_scriptID[
4460 (int)options[opt_idx].indir & PV_MASK]);
4461 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004462#endif
4463 }
4464 else
4465 {
4466 char_u *p;
4467
4468 p = find_termcode(key_name);
4469 if (p == NULL)
4470 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004471 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004472 goto skip;
4473 }
4474 else
4475 (void)show_one_termcode(key_name, p, TRUE);
4476 }
4477 if (nextchar != '?'
4478 && nextchar != NUL && !vim_iswhite(afterchar))
4479 errmsg = e_trailing;
4480 }
4481 else
4482 {
4483 if (flags & P_BOOL) /* boolean */
4484 {
4485 if (nextchar == '=' || nextchar == ':')
4486 {
4487 errmsg = e_invarg;
4488 goto skip;
4489 }
4490
4491 /*
4492 * ":set opt!": invert
4493 * ":set opt&": reset to default value
4494 * ":set opt<": reset to global value
4495 */
4496 if (nextchar == '!')
4497 value = *(int *)(varp) ^ 1;
4498 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004499 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004500 ((flags & P_VI_DEF) || cp_val)
4501 ? VI_DEFAULT : VIM_DEFAULT];
4502 else if (nextchar == '<')
4503 {
4504 /* For 'autoread' -1 means to use global value. */
4505 if ((int *)varp == &curbuf->b_p_ar
4506 && opt_flags == OPT_LOCAL)
4507 value = -1;
4508 else
4509 value = *(int *)get_varp_scope(&(options[opt_idx]),
4510 OPT_GLOBAL);
4511 }
4512 else
4513 {
4514 /*
4515 * ":set invopt": invert
4516 * ":set opt" or ":set noopt": set or reset
4517 */
4518 if (nextchar != NUL && !vim_iswhite(afterchar))
4519 {
4520 errmsg = e_trailing;
4521 goto skip;
4522 }
4523 if (prefix == 2) /* inv */
4524 value = *(int *)(varp) ^ 1;
4525 else
4526 value = prefix;
4527 }
4528
4529 errmsg = set_bool_option(opt_idx, varp, (int)value,
4530 opt_flags);
4531 }
4532 else /* numeric or string */
4533 {
4534 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4535 || prefix != 1)
4536 {
4537 errmsg = e_invarg;
4538 goto skip;
4539 }
4540
4541 if (flags & P_NUM) /* numeric */
4542 {
4543 /*
4544 * Different ways to set a number option:
4545 * & set to default value
4546 * < set to global value
4547 * <xx> accept special key codes for 'wildchar'
4548 * c accept any non-digit for 'wildchar'
4549 * [-]0-9 set number
4550 * other error
4551 */
4552 ++arg;
4553 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004554 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004555 ((flags & P_VI_DEF) || cp_val)
4556 ? VI_DEFAULT : VIM_DEFAULT];
4557 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004558 {
4559 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4560 * use the global value. */
4561 if ((long *)varp == &curbuf->b_p_ul
4562 && opt_flags == OPT_LOCAL)
4563 value = NO_LOCAL_UNDOLEVEL;
4564 else
4565 value = *(long *)get_varp_scope(
4566 &(options[opt_idx]), OPT_GLOBAL);
4567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004568 else if (((long *)varp == &p_wc
4569 || (long *)varp == &p_wcm)
4570 && (*arg == '<'
4571 || *arg == '^'
4572 || ((!arg[1] || vim_iswhite(arg[1]))
4573 && !VIM_ISDIGIT(*arg))))
4574 {
4575 value = string_to_key(arg);
4576 if (value == 0 && (long *)varp != &p_wcm)
4577 {
4578 errmsg = e_invarg;
4579 goto skip;
4580 }
4581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004582 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4583 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004584 /* Allow negative (for 'undolevels'), octal and
4585 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004586 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4587 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004588 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4589 {
4590 errmsg = e_invarg;
4591 goto skip;
4592 }
4593 }
4594 else
4595 {
4596 errmsg = (char_u *)N_("E521: Number required after =");
4597 goto skip;
4598 }
4599
4600 if (adding)
4601 value = *(long *)varp + value;
4602 if (prepending)
4603 value = *(long *)varp * value;
4604 if (removing)
4605 value = *(long *)varp - value;
4606 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004607 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004608 }
4609 else if (opt_idx >= 0) /* string */
4610 {
4611 char_u *save_arg = NULL;
4612 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004613 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004614 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004615 char_u *origval = NULL;
4616#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4617 char_u *saved_origval = NULL;
4618#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004619 unsigned newlen;
4620 int comma;
4621 int bs;
4622 int new_value_alloced; /* new string option
4623 was allocated */
4624
4625 /* When using ":set opt=val" for a global option
4626 * with a local value the local value will be
4627 * reset, use the global value here. */
4628 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004629 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004630 varp = options[opt_idx].var;
4631
4632 /* The old value is kept until we are sure that the
4633 * new value is valid. */
4634 oldval = *(char_u **)varp;
4635 if (nextchar == '&') /* set to default val */
4636 {
4637 newval = options[opt_idx].def_val[
4638 ((flags & P_VI_DEF) || cp_val)
4639 ? VI_DEFAULT : VIM_DEFAULT];
4640 if ((char_u **)varp == &p_bg)
4641 {
4642 /* guess the value of 'background' */
4643#ifdef FEAT_GUI
4644 if (gui.in_use)
4645 newval = gui_bg_default();
4646 else
4647#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004648 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004649 }
4650
4651 /* expand environment variables and ~ (since the
4652 * default value was already expanded, only
4653 * required when an environment variable was set
4654 * later */
4655 if (newval == NULL)
4656 newval = empty_option;
4657 else
4658 {
4659 s = option_expand(opt_idx, newval);
4660 if (s == NULL)
4661 s = newval;
4662 newval = vim_strsave(s);
4663 }
4664 new_value_alloced = TRUE;
4665 }
4666 else if (nextchar == '<') /* set to global val */
4667 {
4668 newval = vim_strsave(*(char_u **)get_varp_scope(
4669 &(options[opt_idx]), OPT_GLOBAL));
4670 new_value_alloced = TRUE;
4671 }
4672 else
4673 {
4674 ++arg; /* jump to after the '=' or ':' */
4675
4676 /*
4677 * Set 'keywordprg' to ":help" if an empty
4678 * value was passed to :set by the user.
4679 * Misuse errbuf[] for the resulting string.
4680 */
4681 if (varp == (char_u *)&p_kp
4682 && (*arg == NUL || *arg == ' '))
4683 {
4684 STRCPY(errbuf, ":help");
4685 save_arg = arg;
4686 arg = errbuf;
4687 }
4688 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004689 * Convert 'backspace' number to string, for
4690 * adding, prepending and removing string.
4691 */
4692 else if (varp == (char_u *)&p_bs
4693 && VIM_ISDIGIT(**(char_u **)varp))
4694 {
4695 i = getdigits((char_u **)varp);
4696 switch (i)
4697 {
4698 case 0:
4699 *(char_u **)varp = empty_option;
4700 break;
4701 case 1:
4702 *(char_u **)varp = vim_strsave(
4703 (char_u *)"indent,eol");
4704 break;
4705 case 2:
4706 *(char_u **)varp = vim_strsave(
4707 (char_u *)"indent,eol,start");
4708 break;
4709 }
4710 vim_free(oldval);
4711 oldval = *(char_u **)varp;
4712 }
4713 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004714 * Convert 'whichwrap' number to string, for
4715 * backwards compatibility with Vim 3.0.
4716 * Misuse errbuf[] for the resulting string.
4717 */
4718 else if (varp == (char_u *)&p_ww
4719 && VIM_ISDIGIT(*arg))
4720 {
4721 *errbuf = NUL;
4722 i = getdigits(&arg);
4723 if (i & 1)
4724 STRCAT(errbuf, "b,");
4725 if (i & 2)
4726 STRCAT(errbuf, "s,");
4727 if (i & 4)
4728 STRCAT(errbuf, "h,l,");
4729 if (i & 8)
4730 STRCAT(errbuf, "<,>,");
4731 if (i & 16)
4732 STRCAT(errbuf, "[,],");
4733 if (*errbuf != NUL) /* remove trailing , */
4734 errbuf[STRLEN(errbuf) - 1] = NUL;
4735 save_arg = arg;
4736 arg = errbuf;
4737 }
4738 /*
4739 * Remove '>' before 'dir' and 'bdir', for
4740 * backwards compatibility with version 3.0
4741 */
4742 else if ( *arg == '>'
4743 && (varp == (char_u *)&p_dir
4744 || varp == (char_u *)&p_bdir))
4745 {
4746 ++arg;
4747 }
4748
4749 /* When setting the local value of a global
4750 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004751 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004752 && (opt_flags & OPT_LOCAL))
4753 origval = *(char_u **)get_varp(
4754 &options[opt_idx]);
4755 else
4756 origval = oldval;
4757
4758 /*
4759 * Copy the new string into allocated memory.
4760 * Can't use set_string_option_direct(), because
4761 * we need to remove the backslashes.
4762 */
4763 /* get a bit too much */
4764 newlen = (unsigned)STRLEN(arg) + 1;
4765 if (adding || prepending || removing)
4766 newlen += (unsigned)STRLEN(origval) + 1;
4767 newval = alloc(newlen);
4768 if (newval == NULL) /* out of mem, don't change */
4769 break;
4770 s = newval;
4771
4772 /*
4773 * Copy the string, skip over escaped chars.
4774 * For MS-DOS and WIN32 backslashes before normal
4775 * file name characters are not removed, and keep
4776 * backslash at start, for "\\machine\path", but
4777 * do remove it for "\\\\machine\\path".
4778 * The reverse is found in ExpandOldSetting().
4779 */
4780 while (*arg && !vim_iswhite(*arg))
4781 {
4782 if (*arg == '\\' && arg[1] != NUL
4783#ifdef BACKSLASH_IN_FILENAME
4784 && !((flags & P_EXPAND)
4785 && vim_isfilec(arg[1])
4786 && (arg[1] != '\\'
4787 || (s == newval
4788 && arg[2] != '\\')))
4789#endif
4790 )
4791 ++arg; /* remove backslash */
4792#ifdef FEAT_MBYTE
4793 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004794 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 {
4796 /* copy multibyte char */
4797 mch_memmove(s, arg, (size_t)i);
4798 arg += i;
4799 s += i;
4800 }
4801 else
4802#endif
4803 *s++ = *arg++;
4804 }
4805 *s = NUL;
4806
4807 /*
4808 * Expand environment variables and ~.
4809 * Don't do it when adding without inserting a
4810 * comma.
4811 */
4812 if (!(adding || prepending || removing)
4813 || (flags & P_COMMA))
4814 {
4815 s = option_expand(opt_idx, newval);
4816 if (s != NULL)
4817 {
4818 vim_free(newval);
4819 newlen = (unsigned)STRLEN(s) + 1;
4820 if (adding || prepending || removing)
4821 newlen += (unsigned)STRLEN(origval) + 1;
4822 newval = alloc(newlen);
4823 if (newval == NULL)
4824 break;
4825 STRCPY(newval, s);
4826 }
4827 }
4828
4829 /* locate newval[] in origval[] when removing it
4830 * and when adding to avoid duplicates */
4831 i = 0; /* init for GCC */
4832 if (removing || (flags & P_NODUP))
4833 {
4834 i = (int)STRLEN(newval);
4835 bs = 0;
4836 for (s = origval; *s; ++s)
4837 {
4838 if ((!(flags & P_COMMA)
4839 || s == origval
4840 || (s[-1] == ',' && !(bs & 1)))
4841 && STRNCMP(s, newval, i) == 0
4842 && (!(flags & P_COMMA)
4843 || s[i] == ','
4844 || s[i] == NUL))
4845 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004846 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004847 * even number of backslashes or a single
4848 * backslash preceded by a comma before it
4849 * is recognized as a separator */
4850 if ((s > origval + 1
4851 && s[-1] == '\\'
4852 && s[-2] != ',')
4853 || (s == origval + 1
4854 && s[-1] == '\\'))
4855
Bram Moolenaar071d4272004-06-13 20:20:40 +00004856 ++bs;
4857 else
4858 bs = 0;
4859 }
4860
4861 /* do not add if already there */
4862 if ((adding || prepending) && *s)
4863 {
4864 prepending = FALSE;
4865 adding = FALSE;
4866 STRCPY(newval, origval);
4867 }
4868 }
4869
4870 /* concatenate the two strings; add a ',' if
4871 * needed */
4872 if (adding || prepending)
4873 {
4874 comma = ((flags & P_COMMA) && *origval != NUL
4875 && *newval != NUL);
4876 if (adding)
4877 {
4878 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004879 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004880 if (comma && i > 1
4881 && (flags & P_ONECOMMA) == P_ONECOMMA
4882 && origval[i - 1] == ','
4883 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004884 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004885 mch_memmove(newval + i + comma, newval,
4886 STRLEN(newval) + 1);
4887 mch_memmove(newval, origval, (size_t)i);
4888 }
4889 else
4890 {
4891 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004892 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004893 }
4894 if (comma)
4895 newval[i] = ',';
4896 }
4897
4898 /* Remove newval[] from origval[]. (Note: "i" has
4899 * been set above and is used here). */
4900 if (removing)
4901 {
4902 STRCPY(newval, origval);
4903 if (*s)
4904 {
4905 /* may need to remove a comma */
4906 if (flags & P_COMMA)
4907 {
4908 if (s == origval)
4909 {
4910 /* include comma after string */
4911 if (s[i] == ',')
4912 ++i;
4913 }
4914 else
4915 {
4916 /* include comma before string */
4917 --s;
4918 ++i;
4919 }
4920 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004921 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004922 }
4923 }
4924
4925 if (flags & P_FLAGLIST)
4926 {
4927 /* Remove flags that appear twice. */
4928 for (s = newval; *s; ++s)
4929 if ((!(flags & P_COMMA) || *s != ',')
4930 && vim_strchr(s + 1, *s) != NULL)
4931 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004932 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004933 --s;
4934 }
4935 }
4936
4937 if (save_arg != NULL) /* number for 'whichwrap' */
4938 arg = save_arg;
4939 new_value_alloced = TRUE;
4940 }
4941
4942 /* Set the new value. */
4943 *(char_u **)(varp) = newval;
4944
Bram Moolenaar53744302015-07-17 17:38:22 +02004945#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004946 if (!starting
4947# ifdef FEAT_CRYPT
4948 && options[opt_idx].indir != PV_KEY
4949# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004950 && origval != NULL)
4951 /* origval may be freed by
4952 * did_set_string_option(), make a copy. */
4953 saved_origval = vim_strsave(origval);
4954#endif
4955
Bram Moolenaar071d4272004-06-13 20:20:40 +00004956 /* Handle side effects, and set the global value for
4957 * ":set" on local options. */
4958 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4959 new_value_alloced, oldval, errbuf, opt_flags);
4960
4961 /* If error detected, print the error message. */
4962 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004963 {
4964#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4965 vim_free(saved_origval);
4966#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004967 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004968 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004969#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4970 if (saved_origval != NULL)
4971 {
4972 char_u buf_type[7];
4973
4974 sprintf((char *)buf_type, "%s",
4975 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004976 set_vim_var_string(VV_OPTION_NEW,
4977 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004978 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4979 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4980 apply_autocmds(EVENT_OPTIONSET,
4981 (char_u *)options[opt_idx].fullname,
4982 NULL, FALSE, NULL);
4983 reset_v_option_vars();
4984 vim_free(saved_origval);
4985 }
4986#endif
4987
Bram Moolenaar071d4272004-06-13 20:20:40 +00004988 }
4989 else /* key code option */
4990 {
4991 char_u *p;
4992
4993 if (nextchar == '&')
4994 {
4995 if (add_termcap_entry(key_name, TRUE) == FAIL)
4996 errmsg = (char_u *)N_("E522: Not found in termcap");
4997 }
4998 else
4999 {
5000 ++arg; /* jump to after the '=' or ':' */
5001 for (p = arg; *p && !vim_iswhite(*p); ++p)
5002 if (*p == '\\' && p[1] != NUL)
5003 ++p;
5004 nextchar = *p;
5005 *p = NUL;
5006 add_termcode(key_name, arg, FALSE);
5007 *p = nextchar;
5008 }
5009 if (full_screen)
5010 ttest(FALSE);
5011 redraw_all_later(CLEAR);
5012 }
5013 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005014
Bram Moolenaar071d4272004-06-13 20:20:40 +00005015 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005016 did_set_option(opt_idx, opt_flags,
5017 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005018 }
5019
5020skip:
5021 /*
5022 * Advance to next argument.
5023 * - skip until a blank found, taking care of backslashes
5024 * - skip blanks
5025 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5026 */
5027 for (i = 0; i < 2 ; ++i)
5028 {
5029 while (*arg != NUL && !vim_iswhite(*arg))
5030 if (*arg++ == '\\' && *arg != NUL)
5031 ++arg;
5032 arg = skipwhite(arg);
5033 if (*arg != '=')
5034 break;
5035 }
5036 }
5037
5038 if (errmsg != NULL)
5039 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005040 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005041 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005042 if (i + (arg - startarg) < IOSIZE)
5043 {
5044 /* append the argument with the error */
5045 STRCAT(IObuff, ": ");
5046 mch_memmove(IObuff + i, startarg, (arg - startarg));
5047 IObuff[i + (arg - startarg)] = NUL;
5048 }
5049 /* make sure all characters are printable */
5050 trans_characters(IObuff, IOSIZE);
5051
5052 ++no_wait_return; /* wait_return done later */
5053 emsg(IObuff); /* show error highlighted */
5054 --no_wait_return;
5055
5056 return FAIL;
5057 }
5058
5059 arg = skipwhite(arg);
5060 }
5061
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005062theend:
5063 if (silent_mode && did_show)
5064 {
5065 /* After displaying option values in silent mode. */
5066 silent_mode = FALSE;
5067 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5068 msg_putchar('\n');
5069 cursor_on(); /* msg_start() switches it off */
5070 out_flush();
5071 silent_mode = TRUE;
5072 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5073 }
5074
Bram Moolenaar071d4272004-06-13 20:20:40 +00005075 return OK;
5076}
5077
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005078/*
5079 * Call this when an option has been given a new value through a user command.
5080 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5081 */
5082 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005083did_set_option(
5084 int opt_idx,
5085 int opt_flags, /* possibly with OPT_MODELINE */
5086 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005087{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005088 long_u *p;
5089
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005090 options[opt_idx].flags |= P_WAS_SET;
5091
5092 /* When an option is set in the sandbox, from a modeline or in secure mode
5093 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005094 * flag. */
5095 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005096 if (secure
5097#ifdef HAVE_SANDBOX
5098 || sandbox != 0
5099#endif
5100 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005101 *p = *p | P_INSECURE;
5102 else if (new_value)
5103 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005104}
5105
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005107illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005108{
5109 if (errbuf == NULL)
5110 return (char_u *)"";
5111 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005112 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005113 return errbuf;
5114}
5115
5116/*
5117 * Convert a key name or string into a key value.
5118 * Used for 'wildchar' and 'cedit' options.
5119 */
5120 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005121string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005122{
5123 if (*arg == '<')
5124 return find_key_option(arg + 1);
5125 if (*arg == '^')
5126 return Ctrl_chr(arg[1]);
5127 return *arg;
5128}
5129
5130#ifdef FEAT_CMDWIN
5131/*
5132 * Check value of 'cedit' and set cedit_key.
5133 * Returns NULL if value is OK, error message otherwise.
5134 */
5135 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005136check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005137{
5138 int n;
5139
5140 if (*p_cedit == NUL)
5141 cedit_key = -1;
5142 else
5143 {
5144 n = string_to_key(p_cedit);
5145 if (vim_isprintc(n))
5146 return e_invarg;
5147 cedit_key = n;
5148 }
5149 return NULL;
5150}
5151#endif
5152
5153#ifdef FEAT_TITLE
5154/*
5155 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5156 * maketitle() to create and display it.
5157 * When switching the title or icon off, call mch_restore_title() to get
5158 * the old value back.
5159 */
5160 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005161did_set_title(
5162 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005163{
5164 if (starting != NO_SCREEN
5165#ifdef FEAT_GUI
5166 && !gui.starting
5167#endif
5168 )
5169 {
5170 maketitle();
5171 if (icon)
5172 {
5173 if (!p_icon)
5174 mch_restore_title(2);
5175 }
5176 else
5177 {
5178 if (!p_title)
5179 mch_restore_title(1);
5180 }
5181 }
5182}
5183#endif
5184
5185/*
5186 * set_options_bin - called when 'bin' changes value.
5187 */
5188 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005189set_options_bin(
5190 int oldval,
5191 int newval,
5192 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005193{
5194 /*
5195 * The option values that are changed when 'bin' changes are
5196 * copied when 'bin is set and restored when 'bin' is reset.
5197 */
5198 if (newval)
5199 {
5200 if (!oldval) /* switched on */
5201 {
5202 if (!(opt_flags & OPT_GLOBAL))
5203 {
5204 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5205 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5206 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5207 curbuf->b_p_et_nobin = curbuf->b_p_et;
5208 }
5209 if (!(opt_flags & OPT_LOCAL))
5210 {
5211 p_tw_nobin = p_tw;
5212 p_wm_nobin = p_wm;
5213 p_ml_nobin = p_ml;
5214 p_et_nobin = p_et;
5215 }
5216 }
5217
5218 if (!(opt_flags & OPT_GLOBAL))
5219 {
5220 curbuf->b_p_tw = 0; /* no automatic line wrap */
5221 curbuf->b_p_wm = 0; /* no automatic line wrap */
5222 curbuf->b_p_ml = 0; /* no modelines */
5223 curbuf->b_p_et = 0; /* no expandtab */
5224 }
5225 if (!(opt_flags & OPT_LOCAL))
5226 {
5227 p_tw = 0;
5228 p_wm = 0;
5229 p_ml = FALSE;
5230 p_et = FALSE;
5231 p_bin = TRUE; /* needed when called for the "-b" argument */
5232 }
5233 }
5234 else if (oldval) /* switched off */
5235 {
5236 if (!(opt_flags & OPT_GLOBAL))
5237 {
5238 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5239 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5240 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5241 curbuf->b_p_et = curbuf->b_p_et_nobin;
5242 }
5243 if (!(opt_flags & OPT_LOCAL))
5244 {
5245 p_tw = p_tw_nobin;
5246 p_wm = p_wm_nobin;
5247 p_ml = p_ml_nobin;
5248 p_et = p_et_nobin;
5249 }
5250 }
5251}
5252
5253#ifdef FEAT_VIMINFO
5254/*
5255 * Find the parameter represented by the given character (eg ', :, ", or /),
5256 * and return its associated value in the 'viminfo' string.
5257 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005258 * If the parameter is not specified in the string or there is no following
5259 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005260 */
5261 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005262get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005263{
5264 char_u *p;
5265
5266 p = find_viminfo_parameter(type);
5267 if (p != NULL && VIM_ISDIGIT(*p))
5268 return atoi((char *)p);
5269 return -1;
5270}
5271
5272/*
5273 * Find the parameter represented by the given character (eg ''', ':', '"', or
5274 * '/') in the 'viminfo' option and return a pointer to the string after it.
5275 * Return NULL if the parameter is not specified in the string.
5276 */
5277 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005278find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005279{
5280 char_u *p;
5281
5282 for (p = p_viminfo; *p; ++p)
5283 {
5284 if (*p == type)
5285 return p + 1;
5286 if (*p == 'n') /* 'n' is always the last one */
5287 break;
5288 p = vim_strchr(p, ','); /* skip until next ',' */
5289 if (p == NULL) /* hit the end without finding parameter */
5290 break;
5291 }
5292 return NULL;
5293}
5294#endif
5295
5296/*
5297 * Expand environment variables for some string options.
5298 * These string options cannot be indirect!
5299 * If "val" is NULL expand the current value of the option.
5300 * Return pointer to NameBuff, or NULL when not expanded.
5301 */
5302 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005303option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005304{
5305 /* if option doesn't need expansion nothing to do */
5306 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5307 return NULL;
5308
5309 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5310 * expand_env() would truncate the string. */
5311 if (val != NULL && STRLEN(val) > MAXPATHL)
5312 return NULL;
5313
5314 if (val == NULL)
5315 val = *(char_u **)options[opt_idx].var;
5316
5317 /*
5318 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5319 * Escape spaces when expanding 'tags', they are used to separate file
5320 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005321 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322 */
5323 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005324 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005325#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005326 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5327#endif
5328 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005329 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5330 return NULL;
5331
5332 return NameBuff;
5333}
5334
5335/*
5336 * After setting various option values: recompute variables that depend on
5337 * option values.
5338 */
5339 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005340didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341{
5342 /* initialize the table for 'iskeyword' et.al. */
5343 (void)init_chartab();
5344
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005345#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005349 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350#ifdef FEAT_SESSION
5351 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5352 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5353#endif
5354#ifdef FEAT_FOLDING
5355 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5356#endif
5357 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005358 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005359#ifdef FEAT_VIRTUALEDIT
5360 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5361#endif
5362#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5363 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5364#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005365#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005366 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005367 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005368 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005369 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005371#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5372 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5373#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005374#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5376#endif
5377#ifdef FEAT_CMDWIN
5378 /* set cedit_key */
5379 (void)check_cedit();
5380#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005381#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005382 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005383#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005384#ifdef FEAT_LINEBREAK
5385 /* initialize the table for 'breakat'. */
5386 fill_breakat_flags();
5387#endif
5388
5389}
5390
5391/*
5392 * More side effects of setting options.
5393 */
5394 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005395didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005396{
5397 /* Initialize the highlight_attr[] table. */
5398 (void)highlight_changed();
5399
5400 /* Parse default for 'wildmode' */
5401 check_opt_wim();
5402
5403 (void)set_chars_option(&p_lcs);
5404#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5405 /* Parse default for 'fillchars'. */
5406 (void)set_chars_option(&p_fcs);
5407#endif
5408
5409#ifdef FEAT_CLIPBOARD
5410 /* Parse default for 'clipboard' */
5411 (void)check_clipboard_option();
5412#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005413}
5414
5415/*
5416 * Check for string options that are NULL (normally only termcap options).
5417 */
5418 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005419check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005420{
5421 int opt_idx;
5422
5423 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5424 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5425 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5426}
5427
5428/*
5429 * Check string options in a buffer for NULL value.
5430 */
5431 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005432check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433{
5434#if defined(FEAT_QUICKFIX)
5435 check_string_option(&buf->b_p_bh);
5436 check_string_option(&buf->b_p_bt);
5437#endif
5438#ifdef FEAT_MBYTE
5439 check_string_option(&buf->b_p_fenc);
5440#endif
5441 check_string_option(&buf->b_p_ff);
5442#ifdef FEAT_FIND_ID
5443 check_string_option(&buf->b_p_def);
5444 check_string_option(&buf->b_p_inc);
5445# ifdef FEAT_EVAL
5446 check_string_option(&buf->b_p_inex);
5447# endif
5448#endif
5449#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5450 check_string_option(&buf->b_p_inde);
5451 check_string_option(&buf->b_p_indk);
5452#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005453#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5454 check_string_option(&buf->b_p_bexpr);
5455#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005456#if defined(FEAT_CRYPT)
5457 check_string_option(&buf->b_p_cm);
5458#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005459#if defined(FEAT_EVAL)
5460 check_string_option(&buf->b_p_fex);
5461#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462#ifdef FEAT_CRYPT
5463 check_string_option(&buf->b_p_key);
5464#endif
5465 check_string_option(&buf->b_p_kp);
5466 check_string_option(&buf->b_p_mps);
5467 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005468 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469 check_string_option(&buf->b_p_isk);
5470#ifdef FEAT_COMMENTS
5471 check_string_option(&buf->b_p_com);
5472#endif
5473#ifdef FEAT_FOLDING
5474 check_string_option(&buf->b_p_cms);
5475#endif
5476 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005477#ifdef FEAT_TEXTOBJ
5478 check_string_option(&buf->b_p_qe);
5479#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005480#ifdef FEAT_SYN_HL
5481 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005482 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005483#endif
5484#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005485 check_string_option(&buf->b_s.b_p_spc);
5486 check_string_option(&buf->b_s.b_p_spf);
5487 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005488#endif
5489#ifdef FEAT_SEARCHPATH
5490 check_string_option(&buf->b_p_sua);
5491#endif
5492#ifdef FEAT_CINDENT
5493 check_string_option(&buf->b_p_cink);
5494 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005495 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496#endif
5497#ifdef FEAT_AUTOCMD
5498 check_string_option(&buf->b_p_ft);
5499#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005500#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5501 check_string_option(&buf->b_p_cinw);
5502#endif
5503#ifdef FEAT_INS_EXPAND
5504 check_string_option(&buf->b_p_cpt);
5505#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005506#ifdef FEAT_COMPL_FUNC
5507 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005508 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005510#ifdef FEAT_KEYMAP
5511 check_string_option(&buf->b_p_keymap);
5512#endif
5513#ifdef FEAT_QUICKFIX
5514 check_string_option(&buf->b_p_gp);
5515 check_string_option(&buf->b_p_mp);
5516 check_string_option(&buf->b_p_efm);
5517#endif
5518 check_string_option(&buf->b_p_ep);
5519 check_string_option(&buf->b_p_path);
5520 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005521 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522#ifdef FEAT_INS_EXPAND
5523 check_string_option(&buf->b_p_dict);
5524 check_string_option(&buf->b_p_tsr);
5525#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005526#ifdef FEAT_LISP
5527 check_string_option(&buf->b_p_lw);
5528#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005529 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005530}
5531
5532/*
5533 * Free the string allocated for an option.
5534 * Checks for the string being empty_option. This may happen if we're out of
5535 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5536 * check_options().
5537 * Does NOT check for P_ALLOCED flag!
5538 */
5539 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005540free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541{
5542 if (p != empty_option)
5543 vim_free(p);
5544}
5545
5546 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005547clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005548{
5549 if (*pp != empty_option)
5550 vim_free(*pp);
5551 *pp = empty_option;
5552}
5553
5554 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005555check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005556{
5557 if (*pp == NULL)
5558 *pp = empty_option;
5559}
5560
5561/*
5562 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5563 */
5564 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005565set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566{
5567 int opt_idx;
5568
5569 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5570 if (options[opt_idx].var == (char_u *)p)
5571 {
5572 options[opt_idx].flags |= P_ALLOCED;
5573 return;
5574 }
5575 return; /* cannot happen: didn't find it! */
5576}
5577
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005578#if defined(FEAT_EVAL) || defined(PROTO)
5579/*
5580 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5581 * Return FALSE when it wasn't.
5582 * Return -1 for an unknown option.
5583 */
5584 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005585was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005586{
5587 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005588 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005589
5590 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005591 {
5592 flagp = insecure_flag(idx, opt_flags);
5593 return (*flagp & P_INSECURE) != 0;
5594 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005595 EMSG2(_(e_intern2), "was_set_insecurely()");
5596 return -1;
5597}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005598
5599/*
5600 * Get a pointer to the flags used for the P_INSECURE flag of option
5601 * "opt_idx". For some local options a local flags field is used.
5602 */
5603 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005604insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005605{
5606 if (opt_flags & OPT_LOCAL)
5607 switch ((int)options[opt_idx].indir)
5608 {
5609#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005610 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005611#endif
5612#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005613# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005614 case PV_FDE: return &curwin->w_p_fde_flags;
5615 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005616# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005617# ifdef FEAT_BEVAL
5618 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5619# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005620# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005621 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005622# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005623 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005624# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005625 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005626# endif
5627#endif
5628 }
5629
5630 /* Nothing special, return global flags field. */
5631 return &options[opt_idx].flags;
5632}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005633#endif
5634
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005635#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005636static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005637
5638/*
5639 * Redraw the window title and/or tab page text later.
5640 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005641static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005642{
5643 need_maketitle = TRUE;
5644# ifdef FEAT_WINDOWS
5645 redraw_tabline = TRUE;
5646# endif
5647}
5648#endif
5649
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650/*
5651 * Set a string option to a new value (without checking the effect).
5652 * The string is copied into allocated memory.
5653 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005654 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005655 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656 */
5657 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005658set_string_option_direct(
5659 char_u *name,
5660 int opt_idx,
5661 char_u *val,
5662 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5663 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664{
5665 char_u *s;
5666 char_u **varp;
5667 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005668 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005669
Bram Moolenaar89d40322006-08-29 15:30:07 +00005670 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005672 idx = findoption(name);
5673 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005674 {
5675 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005676 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005678 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005679 }
5680
Bram Moolenaar89d40322006-08-29 15:30:07 +00005681 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682 return;
5683
5684 s = vim_strsave(val);
5685 if (s != NULL)
5686 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005687 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005689 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690 free_string_option(*varp);
5691 *varp = s;
5692
5693 /* For buffer/window local option may also set the global value. */
5694 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005695 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696
Bram Moolenaar89d40322006-08-29 15:30:07 +00005697 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698
5699 /* When setting both values of a global option with a local value,
5700 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005701 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702 {
5703 free_string_option(*varp);
5704 *varp = empty_option;
5705 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005706# ifdef FEAT_EVAL
5707 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005708 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005709 set_sid == 0 ? current_SID : set_sid);
5710# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711 }
5712}
5713
5714/*
5715 * Set global value for string option when it's a local option.
5716 */
5717 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005718set_string_option_global(
5719 int opt_idx, /* option index */
5720 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005721{
5722 char_u **p, *s;
5723
5724 /* the global value is always allocated */
5725 if (options[opt_idx].var == VAR_WIN)
5726 p = (char_u **)GLOBAL_WO(varp);
5727 else
5728 p = (char_u **)options[opt_idx].var;
5729 if (options[opt_idx].indir != PV_NONE
5730 && p != varp
5731 && (s = vim_strsave(*varp)) != NULL)
5732 {
5733 free_string_option(*p);
5734 *p = s;
5735 }
5736}
5737
5738/*
5739 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005740 *
5741 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005743 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005744set_string_option(
5745 int opt_idx,
5746 char_u *value,
5747 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005748{
5749 char_u *s;
5750 char_u **varp;
5751 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005752#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5753 char_u *saved_oldval = NULL;
5754#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005755 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756
5757 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005758 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759
5760 s = vim_strsave(value);
5761 if (s != NULL)
5762 {
5763 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5764 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005765 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005766 ? OPT_GLOBAL : OPT_LOCAL)
5767 : opt_flags);
5768 oldval = *varp;
5769 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005770
5771#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005772 if (!starting
5773# ifdef FEAT_CRYPT
5774 && options[opt_idx].indir != PV_KEY
5775# endif
5776 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005777 saved_oldval = vim_strsave(oldval);
5778#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005779 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5780 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005781 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005782
5783 /* call autocomamnd after handling side effects */
5784#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5785 if (saved_oldval != NULL)
5786 {
5787 char_u buf_type[7];
5788 sprintf((char *)buf_type, "%s",
5789 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005790 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5791 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005792 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5793 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5794 reset_v_option_vars();
5795 vim_free(saved_oldval);
5796 }
5797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005799 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005800}
5801
5802/*
5803 * Handle string options that need some action to perform when changed.
5804 * Returns NULL for success, or an error message for an error.
5805 */
5806 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005807did_set_string_option(
5808 int opt_idx, /* index in options[] table */
5809 char_u **varp, /* pointer to the option variable */
5810 int new_value_alloced, /* new value was allocated */
5811 char_u *oldval, /* previous value of the option */
5812 char_u *errbuf, /* buffer for errors, or NULL */
5813 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005814{
5815 char_u *errmsg = NULL;
5816 char_u *s, *p;
5817 int did_chartab = FALSE;
5818 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005819 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005820#ifdef FEAT_GUI
5821 /* set when changing an option that only requires a redraw in the GUI */
5822 int redraw_gui_only = FALSE;
5823#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005824
5825 /* Get the global option to compare with, otherwise we would have to check
5826 * two values for all local options. */
5827 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5828
5829 /* Disallow changing some options from secure mode */
5830 if ((secure
5831#ifdef HAVE_SANDBOX
5832 || sandbox != 0
5833#endif
5834 ) && (options[opt_idx].flags & P_SECURE))
5835 {
5836 errmsg = e_secure;
5837 }
5838
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005839 /* Check for a "normal" file name in some options. Disallow a path
5840 * separator (slash and/or backslash), wildcards and characters that are
5841 * often illegal in a file name. */
5842 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005843 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005844 {
5845 errmsg = e_invarg;
5846 }
5847
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848 /* 'term' */
5849 else if (varp == &T_NAME)
5850 {
5851 if (T_NAME[0] == NUL)
5852 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5853#ifdef FEAT_GUI
5854 if (gui.in_use)
5855 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5856 else if (term_is_gui(T_NAME))
5857 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5858#endif
5859 else if (set_termname(T_NAME) == FAIL)
5860 errmsg = (char_u *)N_("E522: Not found in termcap");
5861 else
5862 /* Screen colors may have changed. */
5863 redraw_later_clear();
5864 }
5865
5866 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005867 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005869 char_u *bkc = p_bkc;
5870 unsigned int *flags = &bkc_flags;
5871
5872 if (opt_flags & OPT_LOCAL)
5873 {
5874 bkc = curbuf->b_p_bkc;
5875 flags = &curbuf->b_bkc_flags;
5876 }
5877
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005878 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5879 /* make the local value empty: use the global value */
5880 *flags = 0;
5881 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005882 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005883 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5884 errmsg = e_invarg;
5885 if ((((int)*flags & BKC_AUTO) != 0)
5886 + (((int)*flags & BKC_YES) != 0)
5887 + (((int)*flags & BKC_NO) != 0) != 1)
5888 {
5889 /* Must have exactly one of "auto", "yes" and "no". */
5890 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5891 errmsg = e_invarg;
5892 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 }
5894 }
5895
5896 /* 'backupext' and 'patchmode' */
5897 else if (varp == &p_bex || varp == &p_pm)
5898 {
5899 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5900 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5901 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5902 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005903#ifdef FEAT_LINEBREAK
5904 /* 'breakindentopt' */
5905 else if (varp == &curwin->w_p_briopt)
5906 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005907 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005908 errmsg = e_invarg;
5909 }
5910#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911
5912 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005913 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005914 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005915 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916 */
5917 else if ( varp == &p_isi
5918 || varp == &(curbuf->b_p_isk)
5919 || varp == &p_isp
5920 || varp == &p_isf)
5921 {
5922 if (init_chartab() == FAIL)
5923 {
5924 did_chartab = TRUE; /* need to restore it below */
5925 errmsg = e_invarg; /* error in value */
5926 }
5927 }
5928
5929 /* 'helpfile' */
5930 else if (varp == &p_hf)
5931 {
5932 /* May compute new values for $VIM and $VIMRUNTIME */
5933 if (didset_vim)
5934 {
5935 vim_setenv((char_u *)"VIM", (char_u *)"");
5936 didset_vim = FALSE;
5937 }
5938 if (didset_vimruntime)
5939 {
5940 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5941 didset_vimruntime = FALSE;
5942 }
5943 }
5944
Bram Moolenaar1a384422010-07-14 19:53:30 +02005945#ifdef FEAT_SYN_HL
5946 /* 'colorcolumn' */
5947 else if (varp == &curwin->w_p_cc)
5948 errmsg = check_colorcolumn(curwin);
5949#endif
5950
Bram Moolenaar071d4272004-06-13 20:20:40 +00005951#ifdef FEAT_MULTI_LANG
5952 /* 'helplang' */
5953 else if (varp == &p_hlg)
5954 {
5955 /* Check for "", "ab", "ab,cd", etc. */
5956 for (s = p_hlg; *s != NUL; s += 3)
5957 {
5958 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5959 {
5960 errmsg = e_invarg;
5961 break;
5962 }
5963 if (s[2] == NUL)
5964 break;
5965 }
5966 }
5967#endif
5968
5969 /* 'highlight' */
5970 else if (varp == &p_hl)
5971 {
5972 if (highlight_changed() == FAIL)
5973 errmsg = e_invarg; /* invalid flags */
5974 }
5975
5976 /* 'nrformats' */
5977 else if (gvarp == &p_nf)
5978 {
5979 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5980 errmsg = e_invarg;
5981 }
5982
5983#ifdef FEAT_SESSION
5984 /* 'sessionoptions' */
5985 else if (varp == &p_ssop)
5986 {
5987 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5988 errmsg = e_invarg;
5989 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5990 {
5991 /* Don't allow both "sesdir" and "curdir". */
5992 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5993 errmsg = e_invarg;
5994 }
5995 }
5996 /* 'viewoptions' */
5997 else if (varp == &p_vop)
5998 {
5999 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6000 errmsg = e_invarg;
6001 }
6002#endif
6003
6004 /* 'scrollopt' */
6005#ifdef FEAT_SCROLLBIND
6006 else if (varp == &p_sbo)
6007 {
6008 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6009 errmsg = e_invarg;
6010 }
6011#endif
6012
6013 /* 'ambiwidth' */
6014#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006015 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006016 {
6017 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6018 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006019 else if (set_chars_option(&p_lcs) != NULL)
6020 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6021# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6022 else if (set_chars_option(&p_fcs) != NULL)
6023 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6024# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006025 }
6026#endif
6027
6028 /* 'background' */
6029 else if (varp == &p_bg)
6030 {
6031 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6032 {
6033#ifdef FEAT_EVAL
6034 int dark = (*p_bg == 'd');
6035#endif
6036
6037 init_highlight(FALSE, FALSE);
6038
6039#ifdef FEAT_EVAL
6040 if (dark != (*p_bg == 'd')
6041 && get_var_value((char_u *)"g:colors_name") != NULL)
6042 {
6043 /* The color scheme must have set 'background' back to another
6044 * value, that's not what we want here. Disable the color
6045 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006046 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006047 free_string_option(p_bg);
6048 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6049 check_string_option(&p_bg);
6050 init_highlight(FALSE, FALSE);
6051 }
6052#endif
6053 }
6054 else
6055 errmsg = e_invarg;
6056 }
6057
6058 /* 'wildmode' */
6059 else if (varp == &p_wim)
6060 {
6061 if (check_opt_wim() == FAIL)
6062 errmsg = e_invarg;
6063 }
6064
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006065#ifdef FEAT_CMDL_COMPL
6066 /* 'wildoptions' */
6067 else if (varp == &p_wop)
6068 {
6069 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6070 errmsg = e_invarg;
6071 }
6072#endif
6073
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074#ifdef FEAT_WAK
6075 /* 'winaltkeys' */
6076 else if (varp == &p_wak)
6077 {
6078 if (*p_wak == NUL
6079 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6080 errmsg = e_invarg;
6081# ifdef FEAT_MENU
6082# ifdef FEAT_GUI_MOTIF
6083 else if (gui.in_use)
6084 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6085# else
6086# ifdef FEAT_GUI_GTK
6087 else if (gui.in_use)
6088 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6089# endif
6090# endif
6091# endif
6092 }
6093#endif
6094
6095#ifdef FEAT_AUTOCMD
6096 /* 'eventignore' */
6097 else if (varp == &p_ei)
6098 {
6099 if (check_ei() == FAIL)
6100 errmsg = e_invarg;
6101 }
6102#endif
6103
6104#ifdef FEAT_MBYTE
6105 /* 'encoding' and 'fileencoding' */
6106 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6107 {
6108 if (gvarp == &p_fenc)
6109 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006110 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 errmsg = e_modifiable;
6112 else if (vim_strchr(*varp, ',') != NULL)
6113 /* No comma allowed in 'fileencoding'; catches confusing it
6114 * with 'fileencodings'. */
6115 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006117 {
6118# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006120 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006121# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006122 /* Add 'fileencoding' to the swap file. */
6123 ml_setflags(curbuf);
6124 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006125 }
6126 if (errmsg == NULL)
6127 {
6128 /* canonize the value, so that STRCMP() can be used on it */
6129 p = enc_canonize(*varp);
6130 if (p != NULL)
6131 {
6132 vim_free(*varp);
6133 *varp = p;
6134 }
6135 if (varp == &p_enc)
6136 {
6137 errmsg = mb_init();
6138# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006139 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006140# endif
6141 }
6142 }
6143
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006144# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006145 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6146 {
6147 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6148 if (STRCMP(p_tenc, "utf-8") != 0)
6149 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6150 }
6151# endif
6152
6153 if (errmsg == NULL)
6154 {
6155# ifdef FEAT_KEYMAP
6156 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6157 * (with another encoding). */
6158 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6159 (void)keymap_init();
6160# endif
6161
6162 /* When 'termencoding' is not empty and 'encoding' changes or when
6163 * 'termencoding' changes, need to setup for keyboard input and
6164 * display output conversion. */
6165 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6166 {
6167 convert_setup(&input_conv, p_tenc, p_enc);
6168 convert_setup(&output_conv, p_enc, p_tenc);
6169 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006170
6171# if defined(WIN3264) && defined(FEAT_MBYTE)
6172 /* $HOME may have characters in active code page. */
6173 if (varp == &p_enc)
6174 init_homedir();
6175# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006176 }
6177 }
6178#endif
6179
6180#if defined(FEAT_POSTSCRIPT)
6181 else if (varp == &p_penc)
6182 {
6183 /* Canonize printencoding if VIM standard one */
6184 p = enc_canonize(p_penc);
6185 if (p != NULL)
6186 {
6187 vim_free(p_penc);
6188 p_penc = p;
6189 }
6190 else
6191 {
6192 /* Ensure lower case and '-' for '_' */
6193 for (s = p_penc; *s != NUL; s++)
6194 {
6195 if (*s == '_')
6196 *s = '-';
6197 else
6198 *s = TOLOWER_ASC(*s);
6199 }
6200 }
6201 }
6202#endif
6203
Bram Moolenaar9372a112005-12-06 19:59:18 +00006204#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006205 else if (varp == &p_imak)
6206 {
6207 if (gui.in_use && !im_xim_isvalid_imactivate())
6208 errmsg = e_invarg;
6209 }
6210#endif
6211
6212#ifdef FEAT_KEYMAP
6213 else if (varp == &curbuf->b_p_keymap)
6214 {
6215 /* load or unload key mapping tables */
6216 errmsg = keymap_init();
6217
Bram Moolenaarfab06232009-03-04 03:13:35 +00006218 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006219 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006220 if (*curbuf->b_p_keymap != NUL)
6221 {
6222 /* Installed a new keymap, switch on using it. */
6223 curbuf->b_p_iminsert = B_IMODE_LMAP;
6224 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6225 curbuf->b_p_imsearch = B_IMODE_LMAP;
6226 }
6227 else
6228 {
6229 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6230 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6231 curbuf->b_p_iminsert = B_IMODE_NONE;
6232 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6233 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6234 }
6235 if ((opt_flags & OPT_LOCAL) == 0)
6236 {
6237 set_iminsert_global();
6238 set_imsearch_global();
6239 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240# ifdef FEAT_WINDOWS
6241 status_redraw_curbuf();
6242# endif
6243 }
6244 }
6245#endif
6246
6247 /* 'fileformat' */
6248 else if (gvarp == &p_ff)
6249 {
6250 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6251 errmsg = e_modifiable;
6252 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6253 errmsg = e_invarg;
6254 else
6255 {
6256 /* may also change 'textmode' */
6257 if (get_fileformat(curbuf) == EOL_DOS)
6258 curbuf->b_p_tx = TRUE;
6259 else
6260 curbuf->b_p_tx = FALSE;
6261#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006262 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006264 /* update flag in swap file */
6265 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006266 /* Redraw needed when switching to/from "mac": a CR in the text
6267 * will be displayed differently. */
6268 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6269 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006270 }
6271 }
6272
6273 /* 'fileformats' */
6274 else if (varp == &p_ffs)
6275 {
6276 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6277 errmsg = e_invarg;
6278 else
6279 {
6280 /* also change 'textauto' */
6281 if (*p_ffs == NUL)
6282 p_ta = FALSE;
6283 else
6284 p_ta = TRUE;
6285 }
6286 }
6287
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006288#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289 /* 'cryptkey' */
6290 else if (gvarp == &p_key)
6291 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006292# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293 /* Make sure the ":set" command doesn't show the new value in the
6294 * history. */
6295 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006296# endif
6297 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6298 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006299 ml_set_crypt_key(curbuf, oldval,
6300 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006301 }
6302
6303 else if (gvarp == &p_cm)
6304 {
6305 if (opt_flags & OPT_LOCAL)
6306 p = curbuf->b_p_cm;
6307 else
6308 p = p_cm;
6309 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6310 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006311 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006312 errmsg = e_invarg;
6313 else
6314 {
6315 /* When setting the global value to empty, make it "zip". */
6316 if (*p_cm == NUL)
6317 {
6318 if (new_value_alloced)
6319 free_string_option(p_cm);
6320 p_cm = vim_strsave((char_u *)"zip");
6321 new_value_alloced = TRUE;
6322 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006323 /* When using ":set cm=name" the local value is going to be empty.
6324 * Do that here, otherwise the crypt functions will still use the
6325 * local value. */
6326 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6327 {
6328 free_string_option(curbuf->b_p_cm);
6329 curbuf->b_p_cm = empty_option;
6330 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006331
6332 /* Need to update the swapfile when the effective method changed.
6333 * Set "s" to the effective old value, "p" to the effective new
6334 * method and compare. */
6335 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6336 s = p_cm; /* was previously using the global value */
6337 else
6338 s = oldval;
6339 if (*curbuf->b_p_cm == NUL)
6340 p = p_cm; /* is now using the global value */
6341 else
6342 p = curbuf->b_p_cm;
6343 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006344 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006345
6346 /* If the global value changes need to update the swapfile for all
6347 * buffers using that value. */
6348 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6349 {
6350 buf_T *buf;
6351
6352 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6353 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006354 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006355 }
6356 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357 }
6358#endif
6359
6360 /* 'matchpairs' */
6361 else if (gvarp == &p_mps)
6362 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006363#ifdef FEAT_MBYTE
6364 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006365 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006366 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006367 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006368 int x2 = -1;
6369 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006370
6371 if (*p != NUL)
6372 p += mb_ptr2len(p);
6373 if (*p != NUL)
6374 x2 = *p++;
6375 if (*p != NUL)
6376 {
6377 x3 = mb_ptr2char(p);
6378 p += mb_ptr2len(p);
6379 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006380 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006381 {
6382 errmsg = e_invarg;
6383 break;
6384 }
6385 if (*p == NUL)
6386 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006387 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006388 }
6389 else
6390#endif
6391 {
6392 /* Check for "x:y,x:y" */
6393 for (p = *varp; *p != NUL; p += 4)
6394 {
6395 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6396 {
6397 errmsg = e_invarg;
6398 break;
6399 }
6400 if (p[3] == NUL)
6401 break;
6402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006403 }
6404 }
6405
6406#ifdef FEAT_COMMENTS
6407 /* 'comments' */
6408 else if (gvarp == &p_com)
6409 {
6410 for (s = *varp; *s; )
6411 {
6412 while (*s && *s != ':')
6413 {
6414 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6415 && !VIM_ISDIGIT(*s) && *s != '-')
6416 {
6417 errmsg = illegal_char(errbuf, *s);
6418 break;
6419 }
6420 ++s;
6421 }
6422 if (*s++ == NUL)
6423 errmsg = (char_u *)N_("E524: Missing colon");
6424 else if (*s == ',' || *s == NUL)
6425 errmsg = (char_u *)N_("E525: Zero length string");
6426 if (errmsg != NULL)
6427 break;
6428 while (*s && *s != ',')
6429 {
6430 if (*s == '\\' && s[1] != NUL)
6431 ++s;
6432 ++s;
6433 }
6434 s = skip_to_option_part(s);
6435 }
6436 }
6437#endif
6438
6439 /* 'listchars' */
6440 else if (varp == &p_lcs)
6441 {
6442 errmsg = set_chars_option(varp);
6443 }
6444
6445#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6446 /* 'fillchars' */
6447 else if (varp == &p_fcs)
6448 {
6449 errmsg = set_chars_option(varp);
6450 }
6451#endif
6452
6453#ifdef FEAT_CMDWIN
6454 /* 'cedit' */
6455 else if (varp == &p_cedit)
6456 {
6457 errmsg = check_cedit();
6458 }
6459#endif
6460
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006461 /* 'verbosefile' */
6462 else if (varp == &p_vfile)
6463 {
6464 verbose_stop();
6465 if (*p_vfile != NUL && verbose_open() == FAIL)
6466 errmsg = e_invarg;
6467 }
6468
Bram Moolenaar071d4272004-06-13 20:20:40 +00006469#ifdef FEAT_VIMINFO
6470 /* 'viminfo' */
6471 else if (varp == &p_viminfo)
6472 {
6473 for (s = p_viminfo; *s;)
6474 {
6475 /* Check it's a valid character */
6476 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6477 {
6478 errmsg = illegal_char(errbuf, *s);
6479 break;
6480 }
6481 if (*s == 'n') /* name is always last one */
6482 {
6483 break;
6484 }
6485 else if (*s == 'r') /* skip until next ',' */
6486 {
6487 while (*++s && *s != ',')
6488 ;
6489 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006490 else if (*s == '%')
6491 {
6492 /* optional number */
6493 while (vim_isdigit(*++s))
6494 ;
6495 }
6496 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006497 ++s; /* no extra chars */
6498 else /* must have a number */
6499 {
6500 while (vim_isdigit(*++s))
6501 ;
6502
6503 if (!VIM_ISDIGIT(*(s - 1)))
6504 {
6505 if (errbuf != NULL)
6506 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006507 sprintf((char *)errbuf,
6508 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006509 transchar_byte(*(s - 1)));
6510 errmsg = errbuf;
6511 }
6512 else
6513 errmsg = (char_u *)"";
6514 break;
6515 }
6516 }
6517 if (*s == ',')
6518 ++s;
6519 else if (*s)
6520 {
6521 if (errbuf != NULL)
6522 errmsg = (char_u *)N_("E527: Missing comma");
6523 else
6524 errmsg = (char_u *)"";
6525 break;
6526 }
6527 }
6528 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6529 errmsg = (char_u *)N_("E528: Must specify a ' value");
6530 }
6531#endif /* FEAT_VIMINFO */
6532
6533 /* terminal options */
6534 else if (istermoption(&options[opt_idx]) && full_screen)
6535 {
6536 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6537 if (varp == &T_CCO)
6538 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006539 int colors = atoi((char *)T_CCO);
6540
6541 /* Only reinitialize colors if t_Co value has really changed to
6542 * avoid expensive reload of colorscheme if t_Co is set to the
6543 * same value multiple times. */
6544 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006545 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006546 t_colors = colors;
6547 if (t_colors <= 1)
6548 {
6549 if (new_value_alloced)
6550 vim_free(T_CCO);
6551 T_CCO = empty_option;
6552 }
6553 /* We now have a different color setup, initialize it again. */
6554 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006556 }
6557 ttest(FALSE);
6558 if (varp == &T_ME)
6559 {
6560 out_str(T_ME);
6561 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006562#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563 /* Since t_me has been set, this probably means that the user
6564 * wants to use this as default colors. Need to reset default
6565 * background/foreground colors. */
6566 mch_set_normal_colors();
6567#endif
6568 }
6569 }
6570
6571#ifdef FEAT_LINEBREAK
6572 /* 'showbreak' */
6573 else if (varp == &p_sbr)
6574 {
6575 for (s = p_sbr; *s; )
6576 {
6577 if (ptr2cells(s) != 1)
6578 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006579 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006580 }
6581 }
6582#endif
6583
6584#ifdef FEAT_GUI
6585 /* 'guifont' */
6586 else if (varp == &p_guifont)
6587 {
6588 if (gui.in_use)
6589 {
6590 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006591# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006592 /*
6593 * Put up a font dialog and let the user select a new value.
6594 * If this is cancelled go back to the old value but don't
6595 * give an error message.
6596 */
6597 if (STRCMP(p, "*") == 0)
6598 {
6599 p = gui_mch_font_dialog(oldval);
6600
6601 if (new_value_alloced)
6602 free_string_option(p_guifont);
6603
6604 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6605 new_value_alloced = TRUE;
6606 }
6607# endif
6608 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6609 {
6610# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6611 if (STRCMP(p_guifont, "*") == 0)
6612 {
6613 /* Dialog was cancelled: Keep the old value without giving
6614 * an error message. */
6615 if (new_value_alloced)
6616 free_string_option(p_guifont);
6617 p_guifont = vim_strsave(oldval);
6618 new_value_alloced = TRUE;
6619 }
6620 else
6621# endif
6622 errmsg = (char_u *)N_("E596: Invalid font(s)");
6623 }
6624 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006625 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006626 }
6627# ifdef FEAT_XFONTSET
6628 else if (varp == &p_guifontset)
6629 {
6630 if (STRCMP(p_guifontset, "*") == 0)
6631 errmsg = (char_u *)N_("E597: can't select fontset");
6632 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6633 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006634 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 }
6636# endif
6637# ifdef FEAT_MBYTE
6638 else if (varp == &p_guifontwide)
6639 {
6640 if (STRCMP(p_guifontwide, "*") == 0)
6641 errmsg = (char_u *)N_("E533: can't select wide font");
6642 else if (gui_get_wide_font() == FAIL)
6643 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006644 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006645 }
6646# endif
6647#endif
6648
6649#ifdef CURSOR_SHAPE
6650 /* 'guicursor' */
6651 else if (varp == &p_guicursor)
6652 errmsg = parse_shape_opt(SHAPE_CURSOR);
6653#endif
6654
6655#ifdef FEAT_MOUSESHAPE
6656 /* 'mouseshape' */
6657 else if (varp == &p_mouseshape)
6658 {
6659 errmsg = parse_shape_opt(SHAPE_MOUSE);
6660 update_mouseshape(-1);
6661 }
6662#endif
6663
6664#ifdef FEAT_PRINTER
6665 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006666 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006667# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006668 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006669 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006670# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006671#endif
6672
6673#ifdef FEAT_LANGMAP
6674 /* 'langmap' */
6675 else if (varp == &p_langmap)
6676 langmap_set();
6677#endif
6678
6679#ifdef FEAT_LINEBREAK
6680 /* 'breakat' */
6681 else if (varp == &p_breakat)
6682 fill_breakat_flags();
6683#endif
6684
6685#ifdef FEAT_TITLE
6686 /* 'titlestring' and 'iconstring' */
6687 else if (varp == &p_titlestring || varp == &p_iconstring)
6688 {
6689# ifdef FEAT_STL_OPT
6690 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6691
6692 /* NULL => statusline syntax */
6693 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6694 stl_syntax |= flagval;
6695 else
6696 stl_syntax &= ~flagval;
6697# endif
6698 did_set_title(varp == &p_iconstring);
6699
6700 }
6701#endif
6702
6703#ifdef FEAT_GUI
6704 /* 'guioptions' */
6705 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006706 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006707 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006708 redraw_gui_only = TRUE;
6709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006710#endif
6711
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006712#if defined(FEAT_GUI_TABLINE)
6713 /* 'guitablabel' */
6714 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006715 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006716 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006717 redraw_gui_only = TRUE;
6718 }
6719 /* 'guitabtooltip' */
6720 else if (varp == &p_gtt)
6721 {
6722 redraw_gui_only = TRUE;
6723 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006724#endif
6725
Bram Moolenaar071d4272004-06-13 20:20:40 +00006726#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6727 /* 'ttymouse' */
6728 else if (varp == &p_ttym)
6729 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006730 /* Switch the mouse off before changing the escape sequences used for
6731 * that. */
6732 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6734 errmsg = e_invarg;
6735 else
6736 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006737 if (termcap_active)
6738 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006739 }
6740#endif
6741
Bram Moolenaar071d4272004-06-13 20:20:40 +00006742 /* 'selection' */
6743 else if (varp == &p_sel)
6744 {
6745 if (*p_sel == NUL
6746 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6747 errmsg = e_invarg;
6748 }
6749
6750 /* 'selectmode' */
6751 else if (varp == &p_slm)
6752 {
6753 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6754 errmsg = e_invarg;
6755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756
6757#ifdef FEAT_BROWSE
6758 /* 'browsedir' */
6759 else if (varp == &p_bsdir)
6760 {
6761 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6762 && !mch_isdir(p_bsdir))
6763 errmsg = e_invarg;
6764 }
6765#endif
6766
Bram Moolenaar071d4272004-06-13 20:20:40 +00006767 /* 'keymodel' */
6768 else if (varp == &p_km)
6769 {
6770 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6771 errmsg = e_invarg;
6772 else
6773 {
6774 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6775 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6776 }
6777 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778
6779 /* 'mousemodel' */
6780 else if (varp == &p_mousem)
6781 {
6782 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6783 errmsg = e_invarg;
6784#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6785 else if (*p_mousem != *oldval)
6786 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6787 * to create or delete the popup menus. */
6788 gui_motif_update_mousemodel(root_menu);
6789#endif
6790 }
6791
6792 /* 'switchbuf' */
6793 else if (varp == &p_swb)
6794 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006795 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796 errmsg = e_invarg;
6797 }
6798
6799 /* 'debug' */
6800 else if (varp == &p_debug)
6801 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006802 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006803 errmsg = e_invarg;
6804 }
6805
6806 /* 'display' */
6807 else if (varp == &p_dy)
6808 {
6809 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6810 errmsg = e_invarg;
6811 else
6812 (void)init_chartab();
6813
6814 }
6815
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006816#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006817 /* 'eadirection' */
6818 else if (varp == &p_ead)
6819 {
6820 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6821 errmsg = e_invarg;
6822 }
6823#endif
6824
6825#ifdef FEAT_CLIPBOARD
6826 /* 'clipboard' */
6827 else if (varp == &p_cb)
6828 errmsg = check_clipboard_option();
6829#endif
6830
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006831#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006832 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6833 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006834 else if (varp == &(curwin->w_s->b_p_spl)
6835 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006836 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006837 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006838 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006839 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006840 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006841 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006842 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006843 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006844 /* 'spellsuggest' */
6845 else if (varp == &p_sps)
6846 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006847 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006848 errmsg = e_invarg;
6849 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006850 /* 'mkspellmem' */
6851 else if (varp == &p_msm)
6852 {
6853 if (spell_check_msm() != OK)
6854 errmsg = e_invarg;
6855 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006856#endif
6857
Bram Moolenaar071d4272004-06-13 20:20:40 +00006858#ifdef FEAT_QUICKFIX
6859 /* When 'bufhidden' is set, check for valid value. */
6860 else if (gvarp == &p_bh)
6861 {
6862 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6863 errmsg = e_invarg;
6864 }
6865
6866 /* When 'buftype' is set, check for valid value. */
6867 else if (gvarp == &p_bt)
6868 {
6869 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6870 errmsg = e_invarg;
6871 else
6872 {
6873# ifdef FEAT_WINDOWS
6874 if (curwin->w_status_height)
6875 {
6876 curwin->w_redr_status = TRUE;
6877 redraw_later(VALID);
6878 }
6879# endif
6880 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006881# ifdef FEAT_TITLE
6882 redraw_titles();
6883# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 }
6885 }
6886#endif
6887
6888#ifdef FEAT_STL_OPT
6889 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006890 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006891 {
6892 int wid;
6893
6894 if (varp == &p_ruf) /* reset ru_wid first */
6895 ru_wid = 0;
6896 s = *varp;
6897 if (varp == &p_ruf && *s == '%')
6898 {
6899 /* set ru_wid if 'ruf' starts with "%99(" */
6900 if (*++s == '-') /* ignore a '-' */
6901 s++;
6902 wid = getdigits(&s);
6903 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6904 ru_wid = wid;
6905 else
6906 errmsg = check_stl_option(p_ruf);
6907 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006908 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006909 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006911 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006912 comp_col();
6913 }
6914#endif
6915
6916#ifdef FEAT_INS_EXPAND
6917 /* check if it is a valid value for 'complete' -- Acevedo */
6918 else if (gvarp == &p_cpt)
6919 {
6920 for (s = *varp; *s;)
6921 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006922 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923 s++;
6924 if (!*s)
6925 break;
6926 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6927 {
6928 errmsg = illegal_char(errbuf, *s);
6929 break;
6930 }
6931 if (*++s != NUL && *s != ',' && *s != ' ')
6932 {
6933 if (s[-1] == 'k' || s[-1] == 's')
6934 {
6935 /* skip optional filename after 'k' and 's' */
6936 while (*s && *s != ',' && *s != ' ')
6937 {
6938 if (*s == '\\')
6939 ++s;
6940 ++s;
6941 }
6942 }
6943 else
6944 {
6945 if (errbuf != NULL)
6946 {
6947 sprintf((char *)errbuf,
6948 _("E535: Illegal character after <%c>"),
6949 *--s);
6950 errmsg = errbuf;
6951 }
6952 else
6953 errmsg = (char_u *)"";
6954 break;
6955 }
6956 }
6957 }
6958 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006959
6960 /* 'completeopt' */
6961 else if (varp == &p_cot)
6962 {
6963 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6964 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02006965 else
6966 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006967 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006968#endif /* FEAT_INS_EXPAND */
6969
6970
6971#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6972 else if (varp == &p_toolbar)
6973 {
6974 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6975 &toolbar_flags, TRUE) != OK)
6976 errmsg = e_invarg;
6977 else
6978 {
6979 out_flush();
6980 gui_mch_show_toolbar((toolbar_flags &
6981 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6982 }
6983 }
6984#endif
6985
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006986#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006987 /* 'toolbariconsize': GTK+ 2 only */
6988 else if (varp == &p_tbis)
6989 {
6990 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6991 errmsg = e_invarg;
6992 else
6993 {
6994 out_flush();
6995 gui_mch_show_toolbar((toolbar_flags &
6996 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6997 }
6998 }
6999#endif
7000
7001 /* 'pastetoggle': translate key codes like in a mapping */
7002 else if (varp == &p_pt)
7003 {
7004 if (*p_pt)
7005 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007006 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007007 if (p != NULL)
7008 {
7009 if (new_value_alloced)
7010 free_string_option(p_pt);
7011 p_pt = p;
7012 new_value_alloced = TRUE;
7013 }
7014 }
7015 }
7016
7017 /* 'backspace' */
7018 else if (varp == &p_bs)
7019 {
7020 if (VIM_ISDIGIT(*p_bs))
7021 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007022 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007023 errmsg = e_invarg;
7024 }
7025 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7026 errmsg = e_invarg;
7027 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007028 else if (varp == &p_bo)
7029 {
7030 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7031 errmsg = e_invarg;
7032 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007033
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007034 /* 'tagcase' */
7035 else if (gvarp == &p_tc)
7036 {
7037 unsigned int *flags;
7038
7039 if (opt_flags & OPT_LOCAL)
7040 {
7041 p = curbuf->b_p_tc;
7042 flags = &curbuf->b_tc_flags;
7043 }
7044 else
7045 {
7046 p = p_tc;
7047 flags = &tc_flags;
7048 }
7049
7050 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7051 /* make the local value empty: use the global value */
7052 *flags = 0;
7053 else if (*p == NUL
7054 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7055 errmsg = e_invarg;
7056 }
7057
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007058#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059 /* 'casemap' */
7060 else if (varp == &p_cmp)
7061 {
7062 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7063 errmsg = e_invarg;
7064 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007065#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007066
7067#ifdef FEAT_DIFF
7068 /* 'diffopt' */
7069 else if (varp == &p_dip)
7070 {
7071 if (diffopt_changed() == FAIL)
7072 errmsg = e_invarg;
7073 }
7074#endif
7075
7076#ifdef FEAT_FOLDING
7077 /* 'foldmethod' */
7078 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7079 {
7080 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7081 || *curwin->w_p_fdm == NUL)
7082 errmsg = e_invarg;
7083 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007084 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007086 if (foldmethodIsDiff(curwin))
7087 newFoldLevel();
7088 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007089 }
7090# ifdef FEAT_EVAL
7091 /* 'foldexpr' */
7092 else if (varp == &curwin->w_p_fde)
7093 {
7094 if (foldmethodIsExpr(curwin))
7095 foldUpdateAll(curwin);
7096 }
7097# endif
7098 /* 'foldmarker' */
7099 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7100 {
7101 p = vim_strchr(*varp, ',');
7102 if (p == NULL)
7103 errmsg = (char_u *)N_("E536: comma required");
7104 else if (p == *varp || p[1] == NUL)
7105 errmsg = e_invarg;
7106 else if (foldmethodIsMarker(curwin))
7107 foldUpdateAll(curwin);
7108 }
7109 /* 'commentstring' */
7110 else if (gvarp == &p_cms)
7111 {
7112 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7113 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7114 }
7115 /* 'foldopen' */
7116 else if (varp == &p_fdo)
7117 {
7118 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7119 errmsg = e_invarg;
7120 }
7121 /* 'foldclose' */
7122 else if (varp == &p_fcl)
7123 {
7124 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7125 errmsg = e_invarg;
7126 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007127 /* 'foldignore' */
7128 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7129 {
7130 if (foldmethodIsIndent(curwin))
7131 foldUpdateAll(curwin);
7132 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133#endif
7134
7135#ifdef FEAT_VIRTUALEDIT
7136 /* 'virtualedit' */
7137 else if (varp == &p_ve)
7138 {
7139 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7140 errmsg = e_invarg;
7141 else if (STRCMP(p_ve, oldval) != 0)
7142 {
7143 /* Recompute cursor position in case the new 've' setting
7144 * changes something. */
7145 validate_virtcol();
7146 coladvance(curwin->w_virtcol);
7147 }
7148 }
7149#endif
7150
7151#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7152 else if (varp == &p_csqf)
7153 {
7154 if (p_csqf != NULL)
7155 {
7156 p = p_csqf;
7157 while (*p != NUL)
7158 {
7159 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7160 || p[1] == NUL
7161 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7162 || (p[2] != NUL && p[2] != ','))
7163 {
7164 errmsg = e_invarg;
7165 break;
7166 }
7167 else if (p[2] == NUL)
7168 break;
7169 else
7170 p += 3;
7171 }
7172 }
7173 }
7174#endif
7175
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007176#ifdef FEAT_CINDENT
7177 /* 'cinoptions' */
7178 else if (gvarp == &p_cino)
7179 {
7180 /* TODO: recognize errors */
7181 parse_cino(curbuf);
7182 }
7183#endif
7184
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007185#if defined(FEAT_RENDER_OPTIONS)
7186 else if (varp == &p_rop && gui.in_use)
7187 {
7188 if (!gui_mch_set_rendering_options(p_rop))
7189 errmsg = e_invarg;
7190 }
7191#endif
7192
Bram Moolenaar071d4272004-06-13 20:20:40 +00007193 /* Options that are a list of flags. */
7194 else
7195 {
7196 p = NULL;
7197 if (varp == &p_ww)
7198 p = (char_u *)WW_ALL;
7199 if (varp == &p_shm)
7200 p = (char_u *)SHM_ALL;
7201 else if (varp == &(p_cpo))
7202 p = (char_u *)CPO_ALL;
7203 else if (varp == &(curbuf->b_p_fo))
7204 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007205#ifdef FEAT_CONCEAL
7206 else if (varp == &curwin->w_p_cocu)
7207 p = (char_u *)COCU_ALL;
7208#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007209 else if (varp == &p_mouse)
7210 {
7211#ifdef FEAT_MOUSE
7212 p = (char_u *)MOUSE_ALL;
7213#else
7214 if (*p_mouse != NUL)
7215 errmsg = (char_u *)N_("E538: No mouse support");
7216#endif
7217 }
7218#if defined(FEAT_GUI)
7219 else if (varp == &p_go)
7220 p = (char_u *)GO_ALL;
7221#endif
7222 if (p != NULL)
7223 {
7224 for (s = *varp; *s; ++s)
7225 if (vim_strchr(p, *s) == NULL)
7226 {
7227 errmsg = illegal_char(errbuf, *s);
7228 break;
7229 }
7230 }
7231 }
7232
7233 /*
7234 * If error detected, restore the previous value.
7235 */
7236 if (errmsg != NULL)
7237 {
7238 if (new_value_alloced)
7239 free_string_option(*varp);
7240 *varp = oldval;
7241 /*
7242 * When resetting some values, need to act on it.
7243 */
7244 if (did_chartab)
7245 (void)init_chartab();
7246 if (varp == &p_hl)
7247 (void)highlight_changed();
7248 }
7249 else
7250 {
7251#ifdef FEAT_EVAL
7252 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007253 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007254#endif
7255 /*
7256 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007257 * Use "free_oldval", because recursiveness may change the flags under
7258 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007259 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007260 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007261 free_string_option(oldval);
7262 if (new_value_alloced)
7263 options[opt_idx].flags |= P_ALLOCED;
7264 else
7265 options[opt_idx].flags &= ~P_ALLOCED;
7266
7267 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007268 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007269 {
7270 /* global option with local value set to use global value; free
7271 * the local value and make it empty */
7272 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7273 free_string_option(*(char_u **)p);
7274 *(char_u **)p = empty_option;
7275 }
7276
7277 /* May set global value for local option. */
7278 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7279 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007280
7281#ifdef FEAT_AUTOCMD
7282 /*
7283 * Trigger the autocommand only after setting the flags.
7284 */
7285# ifdef FEAT_SYN_HL
7286 /* When 'syntax' is set, load the syntax of that name */
7287 if (varp == &(curbuf->b_p_syn))
7288 {
7289 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7290 curbuf->b_fname, TRUE, curbuf);
7291 }
7292# endif
7293 else if (varp == &(curbuf->b_p_ft))
7294 {
7295 /* 'filetype' is set, trigger the FileType autocommand */
7296 did_filetype = TRUE;
7297 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7298 curbuf->b_fname, TRUE, curbuf);
7299 }
7300#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007301#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007302 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007303 {
7304 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007305 char_u *q = curwin->w_s->b_p_spl;
7306
7307 /* Skip the first name if it is "cjk". */
7308 if (STRNCMP(q, "cjk,", 4) == 0)
7309 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007310
7311 /*
7312 * Source the spell/LANG.vim in 'runtimepath'.
7313 * They could set 'spellcapcheck' depending on the language.
7314 * Use the first name in 'spelllang' up to '_region' or
7315 * '.encoding'.
7316 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007317 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007318 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7319 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007320 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007321 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007322 }
7323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007324 }
7325
7326#ifdef FEAT_MOUSE
7327 if (varp == &p_mouse)
7328 {
7329# ifdef FEAT_MOUSE_TTY
7330 if (*p_mouse == NUL)
7331 mch_setmouse(FALSE); /* switch mouse off */
7332 else
7333# endif
7334 setmouse(); /* in case 'mouse' changed */
7335 }
7336#endif
7337
Bram Moolenaar913077c2012-03-28 19:59:04 +02007338 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007339 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007340 curwin->w_set_curswant = TRUE;
7341
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007342#ifdef FEAT_GUI
7343 /* check redraw when it's not a GUI option or the GUI is active. */
7344 if (!redraw_gui_only || gui.in_use)
7345#endif
7346 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007347
7348 return errmsg;
7349}
7350
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007351#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007352/*
7353 * Simple int comparison function for use with qsort()
7354 */
7355 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007356int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007357{
7358 return *(const int *)a - *(const int *)b;
7359}
7360
7361/*
7362 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7363 * Returns error message, NULL if it's OK.
7364 */
7365 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007366check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007367{
7368 char_u *s;
7369 int col;
7370 int count = 0;
7371 int color_cols[256];
7372 int i;
7373 int j = 0;
7374
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007375 if (wp->w_buffer == NULL)
7376 return NULL; /* buffer was closed */
7377
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007378 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007379 {
7380 if (*s == '-' || *s == '+')
7381 {
7382 /* -N and +N: add to 'textwidth' */
7383 col = (*s == '-') ? -1 : 1;
7384 ++s;
7385 if (!VIM_ISDIGIT(*s))
7386 return e_invarg;
7387 col = col * getdigits(&s);
7388 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007389 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007390 col += wp->w_buffer->b_p_tw;
7391 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007392 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007393 }
7394 else if (VIM_ISDIGIT(*s))
7395 col = getdigits(&s);
7396 else
7397 return e_invarg;
7398 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007399skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007400 if (*s == NUL)
7401 break;
7402 if (*s != ',')
7403 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007404 if (*++s == NUL)
7405 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007406 }
7407
7408 vim_free(wp->w_p_cc_cols);
7409 if (count == 0)
7410 wp->w_p_cc_cols = NULL;
7411 else
7412 {
7413 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7414 if (wp->w_p_cc_cols != NULL)
7415 {
7416 /* sort the columns for faster usage on screen redraw inside
7417 * win_line() */
7418 qsort(color_cols, count, sizeof(int), int_cmp);
7419
7420 for (i = 0; i < count; ++i)
7421 /* skip duplicates */
7422 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7423 wp->w_p_cc_cols[j++] = color_cols[i];
7424 wp->w_p_cc_cols[j] = -1; /* end marker */
7425 }
7426 }
7427
7428 return NULL; /* no error */
7429}
7430#endif
7431
Bram Moolenaar071d4272004-06-13 20:20:40 +00007432/*
7433 * Handle setting 'listchars' or 'fillchars'.
7434 * Returns error message, NULL if it's OK.
7435 */
7436 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007437set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007438{
7439 int round, i, len, entries;
7440 char_u *p, *s;
7441 int c1, c2 = 0;
7442 struct charstab
7443 {
7444 int *cp;
7445 char *name;
7446 };
7447#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7448 static struct charstab filltab[] =
7449 {
7450 {&fill_stl, "stl"},
7451 {&fill_stlnc, "stlnc"},
7452 {&fill_vert, "vert"},
7453 {&fill_fold, "fold"},
7454 {&fill_diff, "diff"},
7455 };
7456#endif
7457 static struct charstab lcstab[] =
7458 {
7459 {&lcs_eol, "eol"},
7460 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007461 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007463 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007464 {&lcs_tab2, "tab"},
7465 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007466#ifdef FEAT_CONCEAL
7467 {&lcs_conceal, "conceal"},
7468#else
7469 {NULL, "conceal"},
7470#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007471 };
7472 struct charstab *tab;
7473
7474#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7475 if (varp == &p_lcs)
7476#endif
7477 {
7478 tab = lcstab;
7479 entries = sizeof(lcstab) / sizeof(struct charstab);
7480 }
7481#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7482 else
7483 {
7484 tab = filltab;
7485 entries = sizeof(filltab) / sizeof(struct charstab);
7486 }
7487#endif
7488
7489 /* first round: check for valid value, second round: assign values */
7490 for (round = 0; round <= 1; ++round)
7491 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007492 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007493 {
7494 /* After checking that the value is valid: set defaults: space for
7495 * 'fillchars', NUL for 'listchars' */
7496 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007497 if (tab[i].cp != NULL)
7498 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499 if (varp == &p_lcs)
7500 lcs_tab1 = NUL;
7501#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7502 else
7503 fill_diff = '-';
7504#endif
7505 }
7506 p = *varp;
7507 while (*p)
7508 {
7509 for (i = 0; i < entries; ++i)
7510 {
7511 len = (int)STRLEN(tab[i].name);
7512 if (STRNCMP(p, tab[i].name, len) == 0
7513 && p[len] == ':'
7514 && p[len + 1] != NUL)
7515 {
7516 s = p + len + 1;
7517#ifdef FEAT_MBYTE
7518 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007519 if (mb_char2cells(c1) > 1)
7520 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521#else
7522 c1 = *s++;
7523#endif
7524 if (tab[i].cp == &lcs_tab2)
7525 {
7526 if (*s == NUL)
7527 continue;
7528#ifdef FEAT_MBYTE
7529 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007530 if (mb_char2cells(c2) > 1)
7531 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007532#else
7533 c2 = *s++;
7534#endif
7535 }
7536 if (*s == ',' || *s == NUL)
7537 {
7538 if (round)
7539 {
7540 if (tab[i].cp == &lcs_tab2)
7541 {
7542 lcs_tab1 = c1;
7543 lcs_tab2 = c2;
7544 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007545 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546 *(tab[i].cp) = c1;
7547
7548 }
7549 p = s;
7550 break;
7551 }
7552 }
7553 }
7554
7555 if (i == entries)
7556 return e_invarg;
7557 if (*p == ',')
7558 ++p;
7559 }
7560 }
7561
7562 return NULL; /* no error */
7563}
7564
7565#ifdef FEAT_STL_OPT
7566/*
7567 * Check validity of options with the 'statusline' format.
7568 * Return error message or NULL.
7569 */
7570 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007571check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007572{
7573 int itemcnt = 0;
7574 int groupdepth = 0;
7575 static char_u errbuf[80];
7576
7577 while (*s && itemcnt < STL_MAX_ITEM)
7578 {
7579 /* Check for valid keys after % sequences */
7580 while (*s && *s != '%')
7581 s++;
7582 if (!*s)
7583 break;
7584 s++;
7585 if (*s != '%' && *s != ')')
7586 ++itemcnt;
7587 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7588 {
7589 s++;
7590 continue;
7591 }
7592 if (*s == ')')
7593 {
7594 s++;
7595 if (--groupdepth < 0)
7596 break;
7597 continue;
7598 }
7599 if (*s == '-')
7600 s++;
7601 while (VIM_ISDIGIT(*s))
7602 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007603 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007604 continue;
7605 if (*s == '.')
7606 {
7607 s++;
7608 while (*s && VIM_ISDIGIT(*s))
7609 s++;
7610 }
7611 if (*s == '(')
7612 {
7613 groupdepth++;
7614 continue;
7615 }
7616 if (vim_strchr(STL_ALL, *s) == NULL)
7617 {
7618 return illegal_char(errbuf, *s);
7619 }
7620 if (*s == '{')
7621 {
7622 s++;
7623 while (*s != '}' && *s)
7624 s++;
7625 if (*s != '}')
7626 return (char_u *)N_("E540: Unclosed expression sequence");
7627 }
7628 }
7629 if (itemcnt >= STL_MAX_ITEM)
7630 return (char_u *)N_("E541: too many items");
7631 if (groupdepth != 0)
7632 return (char_u *)N_("E542: unbalanced groups");
7633 return NULL;
7634}
7635#endif
7636
7637#ifdef FEAT_CLIPBOARD
7638/*
7639 * Extract the items in the 'clipboard' option and set global values.
7640 */
7641 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007642check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007643{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007644 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007645 int new_autoselect_star = FALSE;
7646 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007648 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007649 regprog_T *new_exclude_prog = NULL;
7650 char_u *errmsg = NULL;
7651 char_u *p;
7652
7653 for (p = p_cb; *p != NUL; )
7654 {
7655 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7656 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007657 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007658 p += 7;
7659 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007660 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007661 && (p[11] == ',' || p[11] == NUL))
7662 {
7663 new_unnamed |= CLIP_UNNAMED_PLUS;
7664 p += 11;
7665 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007666 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007667 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007668 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007669 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670 p += 10;
7671 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007672 else if (STRNCMP(p, "autoselectplus", 14) == 0
7673 && (p[14] == ',' || p[14] == NUL))
7674 {
7675 new_autoselect_plus = TRUE;
7676 p += 14;
7677 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007678 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007679 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007680 {
7681 new_autoselectml = TRUE;
7682 p += 12;
7683 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007684 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7685 {
7686 new_html = TRUE;
7687 p += 4;
7688 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007689 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7690 {
7691 p += 8;
7692 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7693 if (new_exclude_prog == NULL)
7694 errmsg = e_invarg;
7695 break;
7696 }
7697 else
7698 {
7699 errmsg = e_invarg;
7700 break;
7701 }
7702 if (*p == ',')
7703 ++p;
7704 }
7705 if (errmsg == NULL)
7706 {
7707 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007708 clip_autoselect_star = new_autoselect_star;
7709 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007711 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007712 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007714#ifdef FEAT_GUI_GTK
7715 if (gui.in_use)
7716 {
7717 gui_gtk_set_selection_targets();
7718 gui_gtk_set_dnd_targets();
7719 }
7720#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721 }
7722 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007723 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724
7725 return errmsg;
7726}
7727#endif
7728
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007729#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007730 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007731did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007732{
7733 char_u *errmsg = NULL;
7734 win_T *wp;
7735 int l;
7736
7737 if (is_spellfile)
7738 {
7739 l = (int)STRLEN(curwin->w_s->b_p_spf);
7740 if (l > 0 && (l < 4
7741 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7742 errmsg = e_invarg;
7743 }
7744
7745 if (errmsg == NULL)
7746 {
7747 FOR_ALL_WINDOWS(wp)
7748 if (wp->w_buffer == curbuf && wp->w_p_spell)
7749 {
7750 errmsg = did_set_spelllang(wp);
7751# ifdef FEAT_WINDOWS
7752 break;
7753# endif
7754 }
7755 }
7756 return errmsg;
7757}
7758
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007759/*
7760 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7761 * Return error message when failed, NULL when OK.
7762 */
7763 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007764compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007765{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007766 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007767 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007768
Bram Moolenaar860cae12010-06-05 23:22:07 +02007769 if (*synblock->b_p_spc == NUL)
7770 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007771 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007772 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007773 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007774 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007775 if (re != NULL)
7776 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007777 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007778 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007779 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007780 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007781 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007782 return e_invarg;
7783 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007784 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007785 }
7786
Bram Moolenaar473de612013-06-08 18:19:48 +02007787 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007788 return NULL;
7789}
7790#endif
7791
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007792#if defined(FEAT_EVAL) || defined(PROTO)
7793/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007794 * Set the scriptID for an option, taking care of setting the buffer- or
7795 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007796 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007797 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007798set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007799{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007800 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7801 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007802
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007803 /* Remember where the option was set. For local options need to do that
7804 * in the buffer or window structure. */
7805 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007806 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007807 if (both || (opt_flags & OPT_LOCAL))
7808 {
7809 if (indir & PV_BUF)
7810 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7811 else if (indir & PV_WIN)
7812 curwin->w_p_scriptID[indir & PV_MASK] = id;
7813 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007814}
7815#endif
7816
Bram Moolenaar071d4272004-06-13 20:20:40 +00007817/*
7818 * Set the value of a boolean option, and take care of side effects.
7819 * Returns NULL for success, or an error message for an error.
7820 */
7821 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007822set_bool_option(
7823 int opt_idx, /* index in options[] table */
7824 char_u *varp, /* pointer to the option variable */
7825 int value, /* new value */
7826 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007827{
7828 int old_value = *(int *)varp;
7829
Bram Moolenaar071d4272004-06-13 20:20:40 +00007830 /* Disallow changing some options from secure mode */
7831 if ((secure
7832#ifdef HAVE_SANDBOX
7833 || sandbox != 0
7834#endif
7835 ) && (options[opt_idx].flags & P_SECURE))
7836 return e_secure;
7837
7838 *(int *)varp = value; /* set the new value */
7839#ifdef FEAT_EVAL
7840 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007841 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007842#endif
7843
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007844#ifdef FEAT_GUI
7845 need_mouse_correct = TRUE;
7846#endif
7847
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848 /* May set global value for local option. */
7849 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7850 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7851
7852 /*
7853 * Handle side effects of changing a bool option.
7854 */
7855
7856 /* 'compatible' */
7857 if ((int *)varp == &p_cp)
7858 {
7859 compatible_set();
7860 }
7861
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007862#ifdef FEAT_PERSISTENT_UNDO
7863 /* 'undofile' */
7864 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7865 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007866 /* Only take action when the option was set. When reset we do not
7867 * delete the undo file, the option may be set again without making
7868 * any changes in between. */
7869 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007870 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007871 char_u hash[UNDO_HASH_SIZE];
7872 buf_T *save_curbuf = curbuf;
7873
7874 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007875 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007876 /* When 'undofile' is set globally: for every buffer, otherwise
7877 * only for the current buffer: Try to read in the undofile,
7878 * if one exists, the buffer wasn't changed and the buffer was
7879 * loaded */
7880 if ((curbuf == save_curbuf
7881 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7882 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7883 {
7884 u_compute_hash(hash);
7885 u_read_undo(NULL, hash, curbuf->b_fname);
7886 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007887 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007888 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007889 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007890 }
7891#endif
7892
Bram Moolenaar071d4272004-06-13 20:20:40 +00007893 else if ((int *)varp == &curbuf->b_p_ro)
7894 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007895 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007896 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7897 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007898
7899 /* when 'readonly' is set may give W10 again */
7900 if (curbuf->b_p_ro)
7901 curbuf->b_did_warn = FALSE;
7902
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007904 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905#endif
7906 }
7907
Bram Moolenaar9c449722010-07-20 18:44:27 +02007908#ifdef FEAT_GUI
7909 else if ((int *)varp == &p_mh)
7910 {
7911 if (!p_mh)
7912 gui_mch_mousehide(FALSE);
7913 }
7914#endif
7915
Bram Moolenaara539df02010-08-01 14:35:05 +02007916#ifdef FEAT_TITLE
7917 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007919 {
7920 redraw_titles();
7921 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007922 /* when 'endofline' is changed, redraw the window title */
7923 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007924 {
7925 redraw_titles();
7926 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007927 /* when 'fixeol' is changed, redraw the window title */
7928 else if ((int *)varp == &curbuf->b_p_fixeol)
7929 {
7930 redraw_titles();
7931 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007932# ifdef FEAT_MBYTE
7933 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007934 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007935 {
7936 redraw_titles();
7937 }
7938# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939#endif
7940
7941 /* when 'bin' is set also set some other options */
7942 else if ((int *)varp == &curbuf->b_p_bin)
7943 {
7944 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7945#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007946 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947#endif
7948 }
7949
7950#ifdef FEAT_AUTOCMD
7951 /* when 'buflisted' changes, trigger autocommands */
7952 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7953 {
7954 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7955 NULL, NULL, TRUE, curbuf);
7956 }
7957#endif
7958
7959 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7960 else if ((int *)varp == &curbuf->b_p_swf)
7961 {
7962 if (curbuf->b_p_swf && p_uc)
7963 ml_open_file(curbuf); /* create the swap file */
7964 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007965 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7966 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 mf_close_file(curbuf, TRUE); /* remove the swap file */
7968 }
7969
7970 /* when 'terse' is set change 'shortmess' */
7971 else if ((int *)varp == &p_terse)
7972 {
7973 char_u *p;
7974
7975 p = vim_strchr(p_shm, SHM_SEARCH);
7976
7977 /* insert 's' in p_shm */
7978 if (p_terse && p == NULL)
7979 {
7980 STRCPY(IObuff, p_shm);
7981 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007982 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 }
7984 /* remove 's' from p_shm */
7985 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007986 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007987 }
7988
7989 /* when 'paste' is set or reset also change other options */
7990 else if ((int *)varp == &p_paste)
7991 {
7992 paste_option_changed();
7993 }
7994
7995 /* when 'insertmode' is set from an autocommand need to do work here */
7996 else if ((int *)varp == &p_im)
7997 {
7998 if (p_im)
7999 {
8000 if ((State & INSERT) == 0)
8001 need_start_insertmode = TRUE;
8002 stop_insert_mode = FALSE;
8003 }
8004 else
8005 {
8006 need_start_insertmode = FALSE;
8007 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008008 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009 clear_cmdline = TRUE; /* remove "(insert)" */
8010 restart_edit = 0;
8011 }
8012 }
8013
8014 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8015 else if ((int *)varp == &p_ic && p_hls)
8016 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008017 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 }
8019
8020#ifdef FEAT_SEARCH_EXTRA
8021 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8022 else if ((int *)varp == &p_hls)
8023 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008024 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025 }
8026#endif
8027
8028#ifdef FEAT_SCROLLBIND
8029 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8030 * at the end of normal_cmd() */
8031 else if ((int *)varp == &curwin->w_p_scb)
8032 {
8033 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008034 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008036 curwin->w_scbind_pos = curwin->w_topline;
8037 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008038 }
8039#endif
8040
8041#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8042 /* There can be only one window with 'previewwindow' set. */
8043 else if ((int *)varp == &curwin->w_p_pvw)
8044 {
8045 if (curwin->w_p_pvw)
8046 {
8047 win_T *win;
8048
8049 for (win = firstwin; win != NULL; win = win->w_next)
8050 if (win->w_p_pvw && win != curwin)
8051 {
8052 curwin->w_p_pvw = FALSE;
8053 return (char_u *)N_("E590: A preview window already exists");
8054 }
8055 }
8056 }
8057#endif
8058
8059 /* when 'textmode' is set or reset also change 'fileformat' */
8060 else if ((int *)varp == &curbuf->b_p_tx)
8061 {
8062 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8063 }
8064
8065 /* when 'textauto' is set or reset also change 'fileformats' */
8066 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008067 set_string_option_direct((char_u *)"ffs", -1,
8068 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008069 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070
8071 /*
8072 * When 'lisp' option changes include/exclude '-' in
8073 * keyword characters.
8074 */
8075#ifdef FEAT_LISP
8076 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8077 {
8078 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8079 }
8080#endif
8081
8082#ifdef FEAT_TITLE
8083 /* when 'title' changed, may need to change the title; same for 'icon' */
8084 else if ((int *)varp == &p_title)
8085 {
8086 did_set_title(FALSE);
8087 }
8088
8089 else if ((int *)varp == &p_icon)
8090 {
8091 did_set_title(TRUE);
8092 }
8093#endif
8094
8095 else if ((int *)varp == &curbuf->b_changed)
8096 {
8097 if (!value)
8098 save_file_ff(curbuf); /* Buffer is unchanged */
8099#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008100 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101#endif
8102#ifdef FEAT_AUTOCMD
8103 modified_was_set = value;
8104#endif
8105 }
8106
8107#ifdef BACKSLASH_IN_FILENAME
8108 else if ((int *)varp == &p_ssl)
8109 {
8110 if (p_ssl)
8111 {
8112 psepc = '/';
8113 psepcN = '\\';
8114 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115 }
8116 else
8117 {
8118 psepc = '\\';
8119 psepcN = '/';
8120 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008121 }
8122
8123 /* need to adjust the file name arguments and buffer names. */
8124 buflist_slash_adjust();
8125 alist_slash_adjust();
8126# ifdef FEAT_EVAL
8127 scriptnames_slash_adjust();
8128# endif
8129 }
8130#endif
8131
8132 /* If 'wrap' is set, set w_leftcol to zero. */
8133 else if ((int *)varp == &curwin->w_p_wrap)
8134 {
8135 if (curwin->w_p_wrap)
8136 curwin->w_leftcol = 0;
8137 }
8138
8139#ifdef FEAT_WINDOWS
8140 else if ((int *)varp == &p_ea)
8141 {
8142 if (p_ea && !old_value)
8143 win_equal(curwin, FALSE, 0);
8144 }
8145#endif
8146
8147 else if ((int *)varp == &p_wiv)
8148 {
8149 /*
8150 * When 'weirdinvert' changed, set/reset 't_xs'.
8151 * Then set 'weirdinvert' according to value of 't_xs'.
8152 */
8153 if (p_wiv && !old_value)
8154 T_XS = (char_u *)"y";
8155 else if (!p_wiv && old_value)
8156 T_XS = empty_option;
8157 p_wiv = (*T_XS != NUL);
8158 }
8159
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008160#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161 else if ((int *)varp == &p_beval)
8162 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008163 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008165 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008166 gui_mch_disable_beval_area(balloonEval);
8167 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008168#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008170#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 else if ((int *)varp == &p_acd)
8172 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008173 /* Change directories when the 'acd' option is set now. */
8174 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175 }
8176#endif
8177
8178#ifdef FEAT_DIFF
8179 /* 'diff' */
8180 else if ((int *)varp == &curwin->w_p_diff)
8181 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008182 /* May add or remove the buffer from the list of diff buffers. */
8183 diff_buf_adjust(curwin);
8184# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185 if (foldmethodIsDiff(curwin))
8186 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008187# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188 }
8189#endif
8190
8191#ifdef USE_IM_CONTROL
8192 /* 'imdisable' */
8193 else if ((int *)varp == &p_imdisable)
8194 {
8195 /* Only de-activate it here, it will be enabled when changing mode. */
8196 if (p_imdisable)
8197 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008198 else if (State & INSERT)
8199 /* When the option is set from an autocommand, it may need to take
8200 * effect right away. */
8201 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 }
8203#endif
8204
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008205#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008206 /* 'spell' */
8207 else if ((int *)varp == &curwin->w_p_spell)
8208 {
8209 if (curwin->w_p_spell)
8210 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008211 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008212 if (errmsg != NULL)
8213 EMSG(_(errmsg));
8214 }
8215 }
8216#endif
8217
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218#ifdef FEAT_FKMAP
8219 else if ((int *)varp == &p_altkeymap)
8220 {
8221 if (old_value != p_altkeymap)
8222 {
8223 if (!p_altkeymap)
8224 {
8225 p_hkmap = p_fkmap;
8226 p_fkmap = 0;
8227 }
8228 else
8229 {
8230 p_fkmap = p_hkmap;
8231 p_hkmap = 0;
8232 }
8233 (void)init_chartab();
8234 }
8235 }
8236
8237 /*
8238 * In case some second language keymapping options have changed, check
8239 * and correct the setting in a consistent way.
8240 */
8241
8242 /*
8243 * If hkmap or fkmap are set, reset Arabic keymapping.
8244 */
8245 if ((p_hkmap || p_fkmap) && p_altkeymap)
8246 {
8247 p_altkeymap = p_fkmap;
8248# ifdef FEAT_ARABIC
8249 curwin->w_p_arab = FALSE;
8250# endif
8251 (void)init_chartab();
8252 }
8253
8254 /*
8255 * If hkmap set, reset Farsi keymapping.
8256 */
8257 if (p_hkmap && p_altkeymap)
8258 {
8259 p_altkeymap = 0;
8260 p_fkmap = 0;
8261# ifdef FEAT_ARABIC
8262 curwin->w_p_arab = FALSE;
8263# endif
8264 (void)init_chartab();
8265 }
8266
8267 /*
8268 * If fkmap set, reset Hebrew keymapping.
8269 */
8270 if (p_fkmap && !p_altkeymap)
8271 {
8272 p_altkeymap = 1;
8273 p_hkmap = 0;
8274# ifdef FEAT_ARABIC
8275 curwin->w_p_arab = FALSE;
8276# endif
8277 (void)init_chartab();
8278 }
8279#endif
8280
8281#ifdef FEAT_ARABIC
8282 if ((int *)varp == &curwin->w_p_arab)
8283 {
8284 if (curwin->w_p_arab)
8285 {
8286 /*
8287 * 'arabic' is set, handle various sub-settings.
8288 */
8289 if (!p_tbidi)
8290 {
8291 /* set rightleft mode */
8292 if (!curwin->w_p_rl)
8293 {
8294 curwin->w_p_rl = TRUE;
8295 changed_window_setting();
8296 }
8297
8298 /* Enable Arabic shaping (major part of what Arabic requires) */
8299 if (!p_arshape)
8300 {
8301 p_arshape = TRUE;
8302 redraw_later_clear();
8303 }
8304 }
8305
8306 /* Arabic requires a utf-8 encoding, inform the user if its not
8307 * set. */
8308 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008309 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008310 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8311
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008312 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008313 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8314#ifdef FEAT_EVAL
8315 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8316#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008317 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008318
8319# ifdef FEAT_MBYTE
8320 /* set 'delcombine' */
8321 p_deco = TRUE;
8322# endif
8323
8324# ifdef FEAT_KEYMAP
8325 /* Force-set the necessary keymap for arabic */
8326 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8327 OPT_LOCAL);
8328# endif
8329# ifdef FEAT_FKMAP
8330 p_altkeymap = 0;
8331 p_hkmap = 0;
8332 p_fkmap = 0;
8333 (void)init_chartab();
8334# endif
8335 }
8336 else
8337 {
8338 /*
8339 * 'arabic' is reset, handle various sub-settings.
8340 */
8341 if (!p_tbidi)
8342 {
8343 /* reset rightleft mode */
8344 if (curwin->w_p_rl)
8345 {
8346 curwin->w_p_rl = FALSE;
8347 changed_window_setting();
8348 }
8349
8350 /* 'arabicshape' isn't reset, it is a global option and
8351 * another window may still need it "on". */
8352 }
8353
8354 /* 'delcombine' isn't reset, it is a global option and another
8355 * window may still want it "on". */
8356
8357# ifdef FEAT_KEYMAP
8358 /* Revert to the default keymap */
8359 curbuf->b_p_iminsert = B_IMODE_NONE;
8360 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8361# endif
8362 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008363 }
8364
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008365#endif
8366
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008367#ifdef FEAT_TERMGUICOLORS
8368 /* 'termguicolors' */
8369 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008370 {
8371# ifdef FEAT_GUI
8372 if (!gui.in_use && !gui.starting)
8373# endif
8374 highlight_gui_started();
8375 }
8376#endif
8377
Bram Moolenaar071d4272004-06-13 20:20:40 +00008378 /*
8379 * End of handling side effects for bool options.
8380 */
8381
Bram Moolenaar53744302015-07-17 17:38:22 +02008382 /* after handling side effects, call autocommand */
8383
Bram Moolenaar071d4272004-06-13 20:20:40 +00008384 options[opt_idx].flags |= P_WAS_SET;
8385
Bram Moolenaar53744302015-07-17 17:38:22 +02008386#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8387 if (!starting)
8388 {
8389 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008390 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8391 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8392 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008393 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8394 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8395 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8396 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8397 reset_v_option_vars();
8398 }
8399#endif
8400
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008402 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008403 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008404 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405 check_redraw(options[opt_idx].flags);
8406
8407 return NULL;
8408}
8409
8410/*
8411 * Set the value of a number option, and take care of side effects.
8412 * Returns NULL for success, or an error message for an error.
8413 */
8414 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008415set_num_option(
8416 int opt_idx, /* index in options[] table */
8417 char_u *varp, /* pointer to the option variable */
8418 long value, /* new value */
8419 char_u *errbuf, /* buffer for error messages */
8420 size_t errbuflen, /* length of "errbuf" */
8421 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008422 OPT_MODELINE */
8423{
8424 char_u *errmsg = NULL;
8425 long old_value = *(long *)varp;
8426 long old_Rows = Rows; /* remember old Rows */
8427 long old_Columns = Columns; /* remember old Columns */
8428 long *pp = (long *)varp;
8429
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008430 /* Disallow changing some options from secure mode. */
8431 if ((secure
8432#ifdef HAVE_SANDBOX
8433 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008435 ) && (options[opt_idx].flags & P_SECURE))
8436 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437
8438 *pp = value;
8439#ifdef FEAT_EVAL
8440 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008441 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008442#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008443#ifdef FEAT_GUI
8444 need_mouse_correct = TRUE;
8445#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008446
Bram Moolenaar14f24742012-08-08 18:01:05 +02008447 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008448 {
8449 errmsg = e_positive;
8450 curbuf->b_p_sw = curbuf->b_p_ts;
8451 }
8452
8453 /*
8454 * Number options that need some action when changed
8455 */
8456#ifdef FEAT_WINDOWS
8457 if (pp == &p_wh || pp == &p_hh)
8458 {
8459 if (p_wh < 1)
8460 {
8461 errmsg = e_positive;
8462 p_wh = 1;
8463 }
8464 if (p_wmh > p_wh)
8465 {
8466 errmsg = e_winheight;
8467 p_wh = p_wmh;
8468 }
8469 if (p_hh < 0)
8470 {
8471 errmsg = e_positive;
8472 p_hh = 0;
8473 }
8474
8475 /* Change window height NOW */
8476 if (lastwin != firstwin)
8477 {
8478 if (pp == &p_wh && curwin->w_height < p_wh)
8479 win_setheight((int)p_wh);
8480 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8481 win_setheight((int)p_hh);
8482 }
8483 }
8484
8485 /* 'winminheight' */
8486 else if (pp == &p_wmh)
8487 {
8488 if (p_wmh < 0)
8489 {
8490 errmsg = e_positive;
8491 p_wmh = 0;
8492 }
8493 if (p_wmh > p_wh)
8494 {
8495 errmsg = e_winheight;
8496 p_wmh = p_wh;
8497 }
8498 win_setminheight();
8499 }
8500
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008501# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008502 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008503 {
8504 if (p_wiw < 1)
8505 {
8506 errmsg = e_positive;
8507 p_wiw = 1;
8508 }
8509 if (p_wmw > p_wiw)
8510 {
8511 errmsg = e_winwidth;
8512 p_wiw = p_wmw;
8513 }
8514
8515 /* Change window width NOW */
8516 if (lastwin != firstwin && curwin->w_width < p_wiw)
8517 win_setwidth((int)p_wiw);
8518 }
8519
8520 /* 'winminwidth' */
8521 else if (pp == &p_wmw)
8522 {
8523 if (p_wmw < 0)
8524 {
8525 errmsg = e_positive;
8526 p_wmw = 0;
8527 }
8528 if (p_wmw > p_wiw)
8529 {
8530 errmsg = e_winwidth;
8531 p_wmw = p_wiw;
8532 }
8533 win_setminheight();
8534 }
8535# endif
8536
8537#endif
8538
8539#ifdef FEAT_WINDOWS
8540 /* (re)set last window status line */
8541 else if (pp == &p_ls)
8542 {
8543 last_status(FALSE);
8544 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008545
8546 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008547 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008548 {
8549 shell_new_rows(); /* recompute window positions and heights */
8550 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551#endif
8552
8553#ifdef FEAT_GUI
8554 else if (pp == &p_linespace)
8555 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008556 /* Recompute gui.char_height and resize the Vim window to keep the
8557 * same number of lines. */
8558 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008559 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560 }
8561#endif
8562
8563#ifdef FEAT_FOLDING
8564 /* 'foldlevel' */
8565 else if (pp == &curwin->w_p_fdl)
8566 {
8567 if (curwin->w_p_fdl < 0)
8568 curwin->w_p_fdl = 0;
8569 newFoldLevel();
8570 }
8571
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008572 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008573 else if (pp == &curwin->w_p_fml)
8574 {
8575 foldUpdateAll(curwin);
8576 }
8577
8578 /* 'foldnestmax' */
8579 else if (pp == &curwin->w_p_fdn)
8580 {
8581 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8582 foldUpdateAll(curwin);
8583 }
8584
8585 /* 'foldcolumn' */
8586 else if (pp == &curwin->w_p_fdc)
8587 {
8588 if (curwin->w_p_fdc < 0)
8589 {
8590 errmsg = e_positive;
8591 curwin->w_p_fdc = 0;
8592 }
8593 else if (curwin->w_p_fdc > 12)
8594 {
8595 errmsg = e_invarg;
8596 curwin->w_p_fdc = 12;
8597 }
8598 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008599#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008600
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008601#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008602 /* 'shiftwidth' or 'tabstop' */
8603 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8604 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008605# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008606 if (foldmethodIsIndent(curwin))
8607 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008608# endif
8609# ifdef FEAT_CINDENT
8610 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8611 * parse 'cinoptions'. */
8612 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8613 parse_cino(curbuf);
8614# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008615 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008617
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008618#ifdef FEAT_MBYTE
8619 /* 'maxcombine' */
8620 else if (pp == &p_mco)
8621 {
8622 if (p_mco > MAX_MCO)
8623 p_mco = MAX_MCO;
8624 else if (p_mco < 0)
8625 p_mco = 0;
8626 screenclear(); /* will re-allocate the screen */
8627 }
8628#endif
8629
Bram Moolenaar071d4272004-06-13 20:20:40 +00008630 else if (pp == &curbuf->b_p_iminsert)
8631 {
8632 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8633 {
8634 errmsg = e_invarg;
8635 curbuf->b_p_iminsert = B_IMODE_NONE;
8636 }
8637 p_iminsert = curbuf->b_p_iminsert;
8638 if (termcap_active) /* don't do this in the alternate screen */
8639 showmode();
8640#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8641 /* Show/unshow value of 'keymap' in status lines. */
8642 status_redraw_curbuf();
8643#endif
8644 }
8645
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008646 else if (pp == &p_window)
8647 {
8648 if (p_window < 1)
8649 p_window = 1;
8650 else if (p_window >= Rows)
8651 p_window = Rows - 1;
8652 }
8653
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654 else if (pp == &curbuf->b_p_imsearch)
8655 {
8656 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8657 {
8658 errmsg = e_invarg;
8659 curbuf->b_p_imsearch = B_IMODE_NONE;
8660 }
8661 p_imsearch = curbuf->b_p_imsearch;
8662 }
8663
8664#ifdef FEAT_TITLE
8665 /* if 'titlelen' has changed, redraw the title */
8666 else if (pp == &p_titlelen)
8667 {
8668 if (p_titlelen < 0)
8669 {
8670 errmsg = e_positive;
8671 p_titlelen = 85;
8672 }
8673 if (starting != NO_SCREEN && old_value != p_titlelen)
8674 need_maketitle = TRUE;
8675 }
8676#endif
8677
8678 /* if p_ch changed value, change the command line height */
8679 else if (pp == &p_ch)
8680 {
8681 if (p_ch < 1)
8682 {
8683 errmsg = e_positive;
8684 p_ch = 1;
8685 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008686 if (p_ch > Rows - min_rows() + 1)
8687 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688
8689 /* Only compute the new window layout when startup has been
8690 * completed. Otherwise the frame sizes may be wrong. */
8691 if (p_ch != old_value && full_screen
8692#ifdef FEAT_GUI
8693 && !gui.starting
8694#endif
8695 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008696 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697 }
8698
8699 /* when 'updatecount' changes from zero to non-zero, open swap files */
8700 else if (pp == &p_uc)
8701 {
8702 if (p_uc < 0)
8703 {
8704 errmsg = e_positive;
8705 p_uc = 100;
8706 }
8707 if (p_uc && !old_value)
8708 ml_open_files();
8709 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008710#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008711 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008712 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008713 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008714 {
8715 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008716 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008717 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008718 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008719 {
8720 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008721 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008722 }
8723 }
8724#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008725#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008726 else if (pp == &p_mzq)
8727 mzvim_reset_timer();
8728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729
8730 /* sync undo before 'undolevels' changes */
8731 else if (pp == &p_ul)
8732 {
8733 /* use the old value, otherwise u_sync() may not work properly */
8734 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008735 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008736 p_ul = value;
8737 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008738 else if (pp == &curbuf->b_p_ul)
8739 {
8740 /* use the old value, otherwise u_sync() may not work properly */
8741 curbuf->b_p_ul = old_value;
8742 u_sync(TRUE);
8743 curbuf->b_p_ul = value;
8744 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008746#ifdef FEAT_LINEBREAK
8747 /* 'numberwidth' must be positive */
8748 else if (pp == &curwin->w_p_nuw)
8749 {
8750 if (curwin->w_p_nuw < 1)
8751 {
8752 errmsg = e_positive;
8753 curwin->w_p_nuw = 1;
8754 }
8755 if (curwin->w_p_nuw > 10)
8756 {
8757 errmsg = e_invarg;
8758 curwin->w_p_nuw = 10;
8759 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008760 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008761 }
8762#endif
8763
Bram Moolenaar1a384422010-07-14 19:53:30 +02008764 else if (pp == &curbuf->b_p_tw)
8765 {
8766 if (curbuf->b_p_tw < 0)
8767 {
8768 errmsg = e_positive;
8769 curbuf->b_p_tw = 0;
8770 }
8771#ifdef FEAT_SYN_HL
8772# ifdef FEAT_WINDOWS
8773 {
8774 win_T *wp;
8775 tabpage_T *tp;
8776
8777 FOR_ALL_TAB_WINDOWS(tp, wp)
8778 check_colorcolumn(wp);
8779 }
8780# else
8781 check_colorcolumn(curwin);
8782# endif
8783#endif
8784 }
8785
Bram Moolenaar071d4272004-06-13 20:20:40 +00008786 /*
8787 * Check the bounds for numeric options here
8788 */
8789 if (Rows < min_rows() && full_screen)
8790 {
8791 if (errbuf != NULL)
8792 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008793 vim_snprintf((char *)errbuf, errbuflen,
8794 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 errmsg = errbuf;
8796 }
8797 Rows = min_rows();
8798 }
8799 if (Columns < MIN_COLUMNS && full_screen)
8800 {
8801 if (errbuf != NULL)
8802 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008803 vim_snprintf((char *)errbuf, errbuflen,
8804 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008805 errmsg = errbuf;
8806 }
8807 Columns = MIN_COLUMNS;
8808 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008809 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008810
Bram Moolenaar071d4272004-06-13 20:20:40 +00008811 /*
8812 * If the screen (shell) height has been changed, assume it is the
8813 * physical screenheight.
8814 */
8815 if (old_Rows != Rows || old_Columns != Columns)
8816 {
8817 /* Changing the screen size is not allowed while updating the screen. */
8818 if (updating_screen)
8819 *pp = old_value;
8820 else if (full_screen
8821#ifdef FEAT_GUI
8822 && !gui.starting
8823#endif
8824 )
8825 set_shellsize((int)Columns, (int)Rows, TRUE);
8826 else
8827 {
8828 /* Postpone the resizing; check the size and cmdline position for
8829 * messages. */
8830 check_shellsize();
8831 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8832 cmdline_row = Rows - p_ch;
8833 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008834 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008835 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008836 }
8837
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 if (curbuf->b_p_ts <= 0)
8839 {
8840 errmsg = e_positive;
8841 curbuf->b_p_ts = 8;
8842 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008843 if (p_tm < 0)
8844 {
8845 errmsg = e_positive;
8846 p_tm = 0;
8847 }
8848 if ((curwin->w_p_scr <= 0
8849 || (curwin->w_p_scr > curwin->w_height
8850 && curwin->w_height > 0))
8851 && full_screen)
8852 {
8853 if (pp == &(curwin->w_p_scr))
8854 {
8855 if (curwin->w_p_scr != 0)
8856 errmsg = e_scroll;
8857 win_comp_scroll(curwin);
8858 }
8859 /* If 'scroll' became invalid because of a side effect silently adjust
8860 * it. */
8861 else if (curwin->w_p_scr <= 0)
8862 curwin->w_p_scr = 1;
8863 else /* curwin->w_p_scr > curwin->w_height */
8864 curwin->w_p_scr = curwin->w_height;
8865 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008866 if (p_hi < 0)
8867 {
8868 errmsg = e_positive;
8869 p_hi = 0;
8870 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008871 else if (p_hi > 10000)
8872 {
8873 errmsg = e_invarg;
8874 p_hi = 10000;
8875 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008876 if (p_re < 0 || p_re > 2)
8877 {
8878 errmsg = e_invarg;
8879 p_re = 0;
8880 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 if (p_report < 0)
8882 {
8883 errmsg = e_positive;
8884 p_report = 1;
8885 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008886 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008887 {
8888 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8889 p_sj = Rows / 2;
8890 else
8891 {
8892 errmsg = e_scroll;
8893 p_sj = 1;
8894 }
8895 }
8896 if (p_so < 0 && full_screen)
8897 {
8898 errmsg = e_scroll;
8899 p_so = 0;
8900 }
8901 if (p_siso < 0 && full_screen)
8902 {
8903 errmsg = e_positive;
8904 p_siso = 0;
8905 }
8906#ifdef FEAT_CMDWIN
8907 if (p_cwh < 1)
8908 {
8909 errmsg = e_positive;
8910 p_cwh = 1;
8911 }
8912#endif
8913 if (p_ut < 0)
8914 {
8915 errmsg = e_positive;
8916 p_ut = 2000;
8917 }
8918 if (p_ss < 0)
8919 {
8920 errmsg = e_positive;
8921 p_ss = 0;
8922 }
8923
8924 /* May set global value for local option. */
8925 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8926 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8927
8928 options[opt_idx].flags |= P_WAS_SET;
8929
Bram Moolenaar53744302015-07-17 17:38:22 +02008930#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8931 if (!starting && errmsg == NULL)
8932 {
8933 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008934 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8935 vim_snprintf((char *)buf_new, 10, "%ld", value);
8936 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008937 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8938 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8939 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8940 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8941 reset_v_option_vars();
8942 }
8943#endif
8944
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008946 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008947 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008948 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008949 check_redraw(options[opt_idx].flags);
8950
8951 return errmsg;
8952}
8953
8954/*
8955 * Called after an option changed: check if something needs to be redrawn.
8956 */
8957 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008958check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008959{
8960 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008961 int doclear = (flags & P_RCLR) == P_RCLR;
8962 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008963
8964#ifdef FEAT_WINDOWS
8965 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8966 status_redraw_all();
8967#endif
8968
8969 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8970 changed_window_setting();
8971 if (flags & P_RBUF)
8972 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008973 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008974 redraw_all_later(CLEAR);
8975 else if (all)
8976 redraw_all_later(NOT_VALID);
8977}
8978
8979/*
8980 * Find index for option 'arg'.
8981 * Return -1 if not found.
8982 */
8983 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008984findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985{
8986 int opt_idx;
8987 char *s, *p;
8988 static short quick_tab[27] = {0, 0}; /* quick access table */
8989 int is_term_opt;
8990
8991 /*
8992 * For first call: Initialize the quick-access table.
8993 * It contains the index for the first option that starts with a certain
8994 * letter. There are 26 letters, plus the first "t_" option.
8995 */
8996 if (quick_tab[1] == 0)
8997 {
8998 p = options[0].fullname;
8999 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9000 {
9001 if (s[0] != p[0])
9002 {
9003 if (s[0] == 't' && s[1] == '_')
9004 quick_tab[26] = opt_idx;
9005 else
9006 quick_tab[CharOrdLow(s[0])] = opt_idx;
9007 }
9008 p = s;
9009 }
9010 }
9011
9012 /*
9013 * Check for name starting with an illegal character.
9014 */
9015#ifdef EBCDIC
9016 if (!islower(arg[0]))
9017#else
9018 if (arg[0] < 'a' || arg[0] > 'z')
9019#endif
9020 return -1;
9021
9022 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9023 if (is_term_opt)
9024 opt_idx = quick_tab[26];
9025 else
9026 opt_idx = quick_tab[CharOrdLow(arg[0])];
9027 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9028 {
9029 if (STRCMP(arg, s) == 0) /* match full name */
9030 break;
9031 }
9032 if (s == NULL && !is_term_opt)
9033 {
9034 opt_idx = quick_tab[CharOrdLow(arg[0])];
9035 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9036 {
9037 s = options[opt_idx].shortname;
9038 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9039 break;
9040 s = NULL;
9041 }
9042 }
9043 if (s == NULL)
9044 opt_idx = -1;
9045 return opt_idx;
9046}
9047
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009048#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009049/*
9050 * Get the value for an option.
9051 *
9052 * Returns:
9053 * Number or Toggle option: 1, *numval gets value.
9054 * String option: 0, *stringval gets allocated string.
9055 * Hidden Number or Toggle option: -1.
9056 * hidden String option: -2.
9057 * unknown option: -3.
9058 */
9059 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009060get_option_value(
9061 char_u *name,
9062 long *numval,
9063 char_u **stringval, /* NULL when only checking existence */
9064 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009065{
9066 int opt_idx;
9067 char_u *varp;
9068
9069 opt_idx = findoption(name);
9070 if (opt_idx < 0) /* unknown option */
9071 return -3;
9072
9073 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9074
9075 if (options[opt_idx].flags & P_STRING)
9076 {
9077 if (varp == NULL) /* hidden option */
9078 return -2;
9079 if (stringval != NULL)
9080 {
9081#ifdef FEAT_CRYPT
9082 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009083 if ((char_u **)varp == &curbuf->b_p_key
9084 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085 *stringval = vim_strsave((char_u *)"*****");
9086 else
9087#endif
9088 *stringval = vim_strsave(*(char_u **)(varp));
9089 }
9090 return 0;
9091 }
9092
9093 if (varp == NULL) /* hidden option */
9094 return -1;
9095 if (options[opt_idx].flags & P_NUM)
9096 *numval = *(long *)varp;
9097 else
9098 {
9099 /* Special case: 'modified' is b_changed, but we also want to consider
9100 * it set when 'ff' or 'fenc' changed. */
9101 if ((int *)varp == &curbuf->b_changed)
9102 *numval = curbufIsChanged();
9103 else
9104 *numval = *(int *)varp;
9105 }
9106 return 1;
9107}
9108#endif
9109
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009110#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009111/*
9112 * Returns the option attributes and its value. Unlike the above function it
9113 * will return either global value or local value of the option depending on
9114 * what was requested, but it will never return global value if it was
9115 * requested to return local one and vice versa. Neither it will return
9116 * buffer-local value if it was requested to return window-local one.
9117 *
9118 * Pretends that option is absent if it is not present in the requested scope
9119 * (i.e. has no global, window-local or buffer-local value depending on
9120 * opt_type). Uses
9121 *
9122 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009123 * 0 hidden or unknown option, also option that does not have requested
9124 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009125 * see SOPT_* in vim.h for other flags
9126 *
9127 * Possible opt_type values: see SREQ_* in vim.h
9128 */
9129 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009130get_option_value_strict(
9131 char_u *name,
9132 long *numval,
9133 char_u **stringval, /* NULL when only obtaining attributes */
9134 int opt_type,
9135 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009136{
9137 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009138 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009139 struct vimoption *p;
9140 int r = 0;
9141
9142 opt_idx = findoption(name);
9143 if (opt_idx < 0)
9144 return 0;
9145
9146 p = &(options[opt_idx]);
9147
9148 /* Hidden option */
9149 if (p->var == NULL)
9150 return 0;
9151
9152 if (p->flags & P_BOOL)
9153 r |= SOPT_BOOL;
9154 else if (p->flags & P_NUM)
9155 r |= SOPT_NUM;
9156 else if (p->flags & P_STRING)
9157 r |= SOPT_STRING;
9158
9159 if (p->indir == PV_NONE)
9160 {
9161 if (opt_type == SREQ_GLOBAL)
9162 r |= SOPT_GLOBAL;
9163 else
9164 return 0; /* Did not request global-only option */
9165 }
9166 else
9167 {
9168 if (p->indir & PV_BOTH)
9169 r |= SOPT_GLOBAL;
9170 else if (opt_type == SREQ_GLOBAL)
9171 return 0; /* Requested global option */
9172
9173 if (p->indir & PV_WIN)
9174 {
9175 if (opt_type == SREQ_BUF)
9176 return 0; /* Did not request window-local option */
9177 else
9178 r |= SOPT_WIN;
9179 }
9180 else if (p->indir & PV_BUF)
9181 {
9182 if (opt_type == SREQ_WIN)
9183 return 0; /* Did not request buffer-local option */
9184 else
9185 r |= SOPT_BUF;
9186 }
9187 }
9188
9189 if (stringval == NULL)
9190 return r;
9191
9192 if (opt_type == SREQ_GLOBAL)
9193 varp = p->var;
9194 else
9195 {
9196 if (opt_type == SREQ_BUF)
9197 {
9198 /* Special case: 'modified' is b_changed, but we also want to
9199 * consider it set when 'ff' or 'fenc' changed. */
9200 if (p->indir == PV_MOD)
9201 {
9202 *numval = bufIsChanged((buf_T *) from);
9203 varp = NULL;
9204 }
9205#ifdef FEAT_CRYPT
9206 else if (p->indir == PV_KEY)
9207 {
9208 /* never return the value of the crypt key */
9209 *stringval = NULL;
9210 varp = NULL;
9211 }
9212#endif
9213 else
9214 {
9215 aco_save_T aco;
9216 aucmd_prepbuf(&aco, (buf_T *) from);
9217 varp = get_varp(p);
9218 aucmd_restbuf(&aco);
9219 }
9220 }
9221 else if (opt_type == SREQ_WIN)
9222 {
9223 win_T *save_curwin;
9224 save_curwin = curwin;
9225 curwin = (win_T *) from;
9226 curbuf = curwin->w_buffer;
9227 varp = get_varp(p);
9228 curwin = save_curwin;
9229 curbuf = curwin->w_buffer;
9230 }
9231 if (varp == p->var)
9232 return (r | SOPT_UNSET);
9233 }
9234
9235 if (varp != NULL)
9236 {
9237 if (p->flags & P_STRING)
9238 *stringval = vim_strsave(*(char_u **)(varp));
9239 else if (p->flags & P_NUM)
9240 *numval = *(long *) varp;
9241 else
9242 *numval = *(int *)varp;
9243 }
9244
9245 return r;
9246}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009247
9248/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009249 * Iterate over options. First argument is a pointer to a pointer to a
9250 * structure inside options[] array, second is option type like in the above
9251 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009252 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009253 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009254 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009255 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009256 * first argument to NULL.
9257 *
9258 * Returns full option name for current option on each call.
9259 */
9260 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009261option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009262{
9263 struct vimoption *ret = NULL;
9264 do
9265 {
9266 if (*option == NULL)
9267 *option = (void *) options;
9268 else if (((struct vimoption *) (*option))->fullname == NULL)
9269 {
9270 *option = NULL;
9271 return NULL;
9272 }
9273 else
9274 *option = (void *) (((struct vimoption *) (*option)) + 1);
9275
9276 ret = ((struct vimoption *) (*option));
9277
9278 /* Hidden option */
9279 if (ret->var == NULL)
9280 {
9281 ret = NULL;
9282 continue;
9283 }
9284
9285 switch (opt_type)
9286 {
9287 case SREQ_GLOBAL:
9288 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9289 ret = NULL;
9290 break;
9291 case SREQ_BUF:
9292 if (!(ret->indir & PV_BUF))
9293 ret = NULL;
9294 break;
9295 case SREQ_WIN:
9296 if (!(ret->indir & PV_WIN))
9297 ret = NULL;
9298 break;
9299 default:
9300 EMSG2(_(e_intern2), "option_iter_next()");
9301 return NULL;
9302 }
9303 }
9304 while (ret == NULL);
9305
9306 return (char_u *)ret->fullname;
9307}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009308#endif
9309
Bram Moolenaar071d4272004-06-13 20:20:40 +00009310/*
9311 * Set the value of option "name".
9312 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009313 *
9314 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009315 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009316 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009317set_option_value(
9318 char_u *name,
9319 long number,
9320 char_u *string,
9321 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009322{
9323 int opt_idx;
9324 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009325 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009326
9327 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009328 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009329 EMSG2(_("E355: Unknown option: %s"), name);
9330 else
9331 {
9332 flags = options[opt_idx].flags;
9333#ifdef HAVE_SANDBOX
9334 /* Disallow changing some options in the sandbox */
9335 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009336 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009338 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009340#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009341 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009342 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343 else
9344 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009345 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009346 if (varp != NULL) /* hidden option is not changed */
9347 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009348 if (number == 0 && string != NULL)
9349 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009350 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009351
9352 /* Either we are given a string or we are setting option
9353 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009354 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009355 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009356 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009357 {
9358 /* There's another character after zeros or the string
9359 * is empty. In both cases, we are trying to set a
9360 * num option using a string. */
9361 EMSG3(_("E521: Number required: &%s = '%s'"),
9362 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009363 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009364
9365 }
9366 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009368 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009369 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009371 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009372 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009373 }
9374 }
9375 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009376 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009377}
9378
9379/*
9380 * Get the terminal code for a terminal option.
9381 * Returns NULL when not found.
9382 */
9383 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009384get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009385{
9386 int opt_idx;
9387 char_u *varp;
9388
9389 if (tname[0] != 't' || tname[1] != '_' ||
9390 tname[2] == NUL || tname[3] == NUL)
9391 return NULL;
9392 if ((opt_idx = findoption(tname)) >= 0)
9393 {
9394 varp = get_varp(&(options[opt_idx]));
9395 if (varp != NULL)
9396 varp = *(char_u **)(varp);
9397 return varp;
9398 }
9399 return find_termcode(tname + 2);
9400}
9401
9402 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009403get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009404{
9405 int i;
9406
9407 i = findoption((char_u *)"hl");
9408 if (i >= 0)
9409 return options[i].def_val[VI_DEFAULT];
9410 return (char_u *)NULL;
9411}
9412
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009413#if defined(FEAT_MBYTE) || defined(PROTO)
9414 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009415get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009416{
9417 int i;
9418
9419 i = findoption((char_u *)"enc");
9420 if (i >= 0)
9421 return options[i].def_val[VI_DEFAULT];
9422 return (char_u *)NULL;
9423}
9424#endif
9425
Bram Moolenaar071d4272004-06-13 20:20:40 +00009426/*
9427 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9428 */
9429 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009430find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009431{
9432 int key;
9433 int modifiers;
9434
9435 /*
9436 * Don't use get_special_key_code() for t_xx, we don't want it to call
9437 * add_termcap_entry().
9438 */
9439 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9440 key = TERMCAP2KEY(arg[2], arg[3]);
9441 else
9442 {
9443 --arg; /* put arg at the '<' */
9444 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009445 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009446 if (modifiers) /* can't handle modifiers here */
9447 key = 0;
9448 }
9449 return key;
9450}
9451
9452/*
9453 * if 'all' == 0: show changed options
9454 * if 'all' == 1: show all normal options
9455 * if 'all' == 2: show all terminal options
9456 */
9457 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009458showoptions(
9459 int all,
9460 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009461{
9462 struct vimoption *p;
9463 int col;
9464 int isterm;
9465 char_u *varp;
9466 struct vimoption **items;
9467 int item_count;
9468 int run;
9469 int row, rows;
9470 int cols;
9471 int i;
9472 int len;
9473
9474#define INC 20
9475#define GAP 3
9476
9477 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9478 PARAM_COUNT));
9479 if (items == NULL)
9480 return;
9481
9482 /* Highlight title */
9483 if (all == 2)
9484 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9485 else if (opt_flags & OPT_GLOBAL)
9486 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9487 else if (opt_flags & OPT_LOCAL)
9488 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9489 else
9490 MSG_PUTS_TITLE(_("\n--- Options ---"));
9491
9492 /*
9493 * do the loop two times:
9494 * 1. display the short items
9495 * 2. display the long items (only strings and numbers)
9496 */
9497 for (run = 1; run <= 2 && !got_int; ++run)
9498 {
9499 /*
9500 * collect the items in items[]
9501 */
9502 item_count = 0;
9503 for (p = &options[0]; p->fullname != NULL; p++)
9504 {
9505 varp = NULL;
9506 isterm = istermoption(p);
9507 if (opt_flags != 0)
9508 {
9509 if (p->indir != PV_NONE && !isterm)
9510 varp = get_varp_scope(p, opt_flags);
9511 }
9512 else
9513 varp = get_varp(p);
9514 if (varp != NULL
9515 && ((all == 2 && isterm)
9516 || (all == 1 && !isterm)
9517 || (all == 0 && !optval_default(p, varp))))
9518 {
9519 if (p->flags & P_BOOL)
9520 len = 1; /* a toggle option fits always */
9521 else
9522 {
9523 option_value2string(p, opt_flags);
9524 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9525 }
9526 if ((len <= INC - GAP && run == 1) ||
9527 (len > INC - GAP && run == 2))
9528 items[item_count++] = p;
9529 }
9530 }
9531
9532 /*
9533 * display the items
9534 */
9535 if (run == 1)
9536 {
9537 cols = (Columns + GAP - 3) / INC;
9538 if (cols == 0)
9539 cols = 1;
9540 rows = (item_count + cols - 1) / cols;
9541 }
9542 else /* run == 2 */
9543 rows = item_count;
9544 for (row = 0; row < rows && !got_int; ++row)
9545 {
9546 msg_putchar('\n'); /* go to next line */
9547 if (got_int) /* 'q' typed in more */
9548 break;
9549 col = 0;
9550 for (i = row; i < item_count; i += rows)
9551 {
9552 msg_col = col; /* make columns */
9553 showoneopt(items[i], opt_flags);
9554 col += INC;
9555 }
9556 out_flush();
9557 ui_breakcheck();
9558 }
9559 }
9560 vim_free(items);
9561}
9562
9563/*
9564 * Return TRUE if option "p" has its default value.
9565 */
9566 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009567optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568{
9569 int dvi;
9570
9571 if (varp == NULL)
9572 return TRUE; /* hidden option is always at default */
9573 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9574 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009575 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009577 /* the cast to long is required for Manx C, long_i is
9578 * needed for MSVC */
9579 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009580 /* P_STRING */
9581 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9582}
9583
9584/*
9585 * showoneopt: show the value of one option
9586 * must not be called with a hidden option!
9587 */
9588 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009589showoneopt(
9590 struct vimoption *p,
9591 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009593 char_u *varp;
9594 int save_silent = silent_mode;
9595
9596 silent_mode = FALSE;
9597 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009598
9599 varp = get_varp_scope(p, opt_flags);
9600
9601 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9602 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9603 ? !curbufIsChanged() : !*(int *)varp))
9604 MSG_PUTS("no");
9605 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9606 MSG_PUTS("--");
9607 else
9608 MSG_PUTS(" ");
9609 MSG_PUTS(p->fullname);
9610 if (!(p->flags & P_BOOL))
9611 {
9612 msg_putchar('=');
9613 /* put value string in NameBuff */
9614 option_value2string(p, opt_flags);
9615 msg_outtrans(NameBuff);
9616 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009617
9618 silent_mode = save_silent;
9619 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620}
9621
9622/*
9623 * Write modified options as ":set" commands to a file.
9624 *
9625 * There are three values for "opt_flags":
9626 * OPT_GLOBAL: Write global option values and fresh values of
9627 * buffer-local options (used for start of a session
9628 * file).
9629 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9630 * curwin (used for a vimrc file).
9631 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9632 * and local values for window-local options of
9633 * curwin. Local values are also written when at the
9634 * default value, because a modeline or autocommand
9635 * may have set them when doing ":edit file" and the
9636 * user has set them back at the default or fresh
9637 * value.
9638 * When "local_only" is TRUE, don't write fresh
9639 * values, only local values (for ":mkview").
9640 * (fresh value = value used for a new buffer or window for a local option).
9641 *
9642 * Return FAIL on error, OK otherwise.
9643 */
9644 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009645makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009646{
9647 struct vimoption *p;
9648 char_u *varp; /* currently used value */
9649 char_u *varp_fresh; /* local value */
9650 char_u *varp_local = NULL; /* fresh value */
9651 char *cmd;
9652 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009653 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654
9655 /*
9656 * The options that don't have a default (terminal name, columns, lines)
9657 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009658 * Do the loop over "options[]" twice: once for options with the
9659 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009661 for (pri = 1; pri >= 0; --pri)
9662 {
9663 for (p = &options[0]; !istermoption(p); p++)
9664 if (!(p->flags & P_NO_MKRC)
9665 && !istermoption(p)
9666 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009667 {
9668 /* skip global option when only doing locals */
9669 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9670 continue;
9671
9672 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9673 * file, they are always buffer-specific. */
9674 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9675 continue;
9676
9677 /* Global values are only written when not at the default value. */
9678 varp = get_varp_scope(p, opt_flags);
9679 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9680 continue;
9681
9682 round = 2;
9683 if (p->indir != PV_NONE)
9684 {
9685 if (p->var == VAR_WIN)
9686 {
9687 /* skip window-local option when only doing globals */
9688 if (!(opt_flags & OPT_LOCAL))
9689 continue;
9690 /* When fresh value of window-local option is not at the
9691 * default, need to write it too. */
9692 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9693 {
9694 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9695 if (!optval_default(p, varp_fresh))
9696 {
9697 round = 1;
9698 varp_local = varp;
9699 varp = varp_fresh;
9700 }
9701 }
9702 }
9703 }
9704
9705 /* Round 1: fresh value for window-local options.
9706 * Round 2: other values */
9707 for ( ; round <= 2; varp = varp_local, ++round)
9708 {
9709 if (round == 1 || (opt_flags & OPT_GLOBAL))
9710 cmd = "set";
9711 else
9712 cmd = "setlocal";
9713
9714 if (p->flags & P_BOOL)
9715 {
9716 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9717 return FAIL;
9718 }
9719 else if (p->flags & P_NUM)
9720 {
9721 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9722 return FAIL;
9723 }
9724 else /* P_STRING */
9725 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009726#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9727 int do_endif = FALSE;
9728
Bram Moolenaar071d4272004-06-13 20:20:40 +00009729 /* Don't set 'syntax' and 'filetype' again if the value is
9730 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009731 if (
9732# if defined(FEAT_SYN_HL)
9733 p->indir == PV_SYN
9734# if defined(FEAT_AUTOCMD)
9735 ||
9736# endif
9737# endif
9738# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009739 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009740# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009741 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742 {
9743 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9744 *(char_u **)(varp)) < 0
9745 || put_eol(fd) < 0)
9746 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009747 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009748 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009749#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9751 (p->flags & P_EXPAND) != 0) == FAIL)
9752 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009753#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9754 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755 {
9756 if (put_line(fd, "endif") == FAIL)
9757 return FAIL;
9758 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009759#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760 }
9761 }
9762 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009763 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009764 return OK;
9765}
9766
9767#if defined(FEAT_FOLDING) || defined(PROTO)
9768/*
9769 * Generate set commands for the local fold options only. Used when
9770 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9771 */
9772 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009773makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009774{
9775 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9776# ifdef FEAT_EVAL
9777 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9778 == FAIL
9779# endif
9780 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9781 == FAIL
9782 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9783 == FAIL
9784 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9785 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9786 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9787 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9788 )
9789 return FAIL;
9790
9791 return OK;
9792}
9793#endif
9794
9795 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009796put_setstring(
9797 FILE *fd,
9798 char *cmd,
9799 char *name,
9800 char_u **valuep,
9801 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009802{
9803 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009804 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009805
9806 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9807 return FAIL;
9808 if (*valuep != NULL)
9809 {
9810 /* Output 'pastetoggle' as key names. For other
9811 * options some characters have to be escaped with
9812 * CTRL-V or backslash */
9813 if (valuep == &p_pt)
9814 {
9815 s = *valuep;
9816 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009817 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009818 return FAIL;
9819 }
9820 else if (expand)
9821 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009822 buf = alloc(MAXPATHL);
9823 if (buf == NULL)
9824 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009825 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9826 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009827 {
9828 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009829 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009830 }
9831 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832 }
9833 else if (put_escstr(fd, *valuep, 2) == FAIL)
9834 return FAIL;
9835 }
9836 if (put_eol(fd) < 0)
9837 return FAIL;
9838 return OK;
9839}
9840
9841 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009842put_setnum(
9843 FILE *fd,
9844 char *cmd,
9845 char *name,
9846 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009847{
9848 long wc;
9849
9850 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9851 return FAIL;
9852 if (wc_use_keyname((char_u *)valuep, &wc))
9853 {
9854 /* print 'wildchar' and 'wildcharm' as a key name */
9855 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9856 return FAIL;
9857 }
9858 else if (fprintf(fd, "%ld", *valuep) < 0)
9859 return FAIL;
9860 if (put_eol(fd) < 0)
9861 return FAIL;
9862 return OK;
9863}
9864
9865 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009866put_setbool(
9867 FILE *fd,
9868 char *cmd,
9869 char *name,
9870 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009871{
Bram Moolenaar893de922007-10-02 18:40:57 +00009872 if (value < 0) /* global/local option using global value */
9873 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009874 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9875 || put_eol(fd) < 0)
9876 return FAIL;
9877 return OK;
9878}
9879
9880/*
9881 * Clear all the terminal options.
9882 * If the option has been allocated, free the memory.
9883 * Terminal options are never hidden or indirect.
9884 */
9885 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009886clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009887{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009888 /*
9889 * Reset a few things before clearing the old options. This may cause
9890 * outputting a few things that the terminal doesn't understand, but the
9891 * screen will be cleared later, so this is OK.
9892 */
9893#ifdef FEAT_MOUSE_TTY
9894 mch_setmouse(FALSE); /* switch mouse off */
9895#endif
9896#ifdef FEAT_TITLE
9897 mch_restore_title(3); /* restore window titles */
9898#endif
9899#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9900 /* When starting the GUI close the display opened for the clipboard.
9901 * After restoring the title, because that will need the display. */
9902 if (gui.starting)
9903 clear_xterm_clip();
9904#endif
9905#ifdef WIN3264
9906 /*
9907 * Check if this is allowed now.
9908 */
9909 if (can_end_termcap_mode(FALSE) == TRUE)
9910#endif
9911 stoptermcap(); /* stop termcap mode */
9912
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009913 free_termoptions();
9914}
9915
9916 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009917free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009918{
9919 struct vimoption *p;
9920
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921 for (p = &options[0]; p->fullname != NULL; p++)
9922 if (istermoption(p))
9923 {
9924 if (p->flags & P_ALLOCED)
9925 free_string_option(*(char_u **)(p->var));
9926 if (p->flags & P_DEF_ALLOCED)
9927 free_string_option(p->def_val[VI_DEFAULT]);
9928 *(char_u **)(p->var) = empty_option;
9929 p->def_val[VI_DEFAULT] = empty_option;
9930 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9931 }
9932 clear_termcodes();
9933}
9934
9935/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009936 * Free the string for one term option, if it was allocated.
9937 * Set the string to empty_option and clear allocated flag.
9938 * "var" points to the option value.
9939 */
9940 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009941free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009942{
9943 struct vimoption *p;
9944
9945 for (p = &options[0]; p->fullname != NULL; p++)
9946 if (p->var == var)
9947 {
9948 if (p->flags & P_ALLOCED)
9949 free_string_option(*(char_u **)(p->var));
9950 *(char_u **)(p->var) = empty_option;
9951 p->flags &= ~P_ALLOCED;
9952 break;
9953 }
9954}
9955
9956/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009957 * Set the terminal option defaults to the current value.
9958 * Used after setting the terminal name.
9959 */
9960 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009961set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962{
9963 struct vimoption *p;
9964
9965 for (p = &options[0]; p->fullname != NULL; p++)
9966 {
9967 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9968 {
9969 if (p->flags & P_DEF_ALLOCED)
9970 {
9971 free_string_option(p->def_val[VI_DEFAULT]);
9972 p->flags &= ~P_DEF_ALLOCED;
9973 }
9974 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9975 if (p->flags & P_ALLOCED)
9976 {
9977 p->flags |= P_DEF_ALLOCED;
9978 p->flags &= ~P_ALLOCED; /* don't free the value now */
9979 }
9980 }
9981 }
9982}
9983
9984/*
9985 * return TRUE if 'p' starts with 't_'
9986 */
9987 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009988istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989{
9990 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9991}
9992
9993/*
9994 * Compute columns for ruler and shown command. 'sc_col' is also used to
9995 * decide what the maximum length of a message on the status line can be.
9996 * If there is a status line for the last window, 'sc_col' is independent
9997 * of 'ru_col'.
9998 */
9999
10000#define COL_RULER 17 /* columns needed by standard ruler */
10001
10002 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010003comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010004{
10005#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10006 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10007
10008 sc_col = 0;
10009 ru_col = 0;
10010 if (p_ru)
10011 {
10012#ifdef FEAT_STL_OPT
10013 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10014#else
10015 ru_col = COL_RULER + 1;
10016#endif
10017 /* no last status line, adjust sc_col */
10018 if (!last_has_status)
10019 sc_col = ru_col;
10020 }
10021 if (p_sc)
10022 {
10023 sc_col += SHOWCMD_COLS;
10024 if (!p_ru || last_has_status) /* no need for separating space */
10025 ++sc_col;
10026 }
10027 sc_col = Columns - sc_col;
10028 ru_col = Columns - ru_col;
10029 if (sc_col <= 0) /* screen too narrow, will become a mess */
10030 sc_col = 1;
10031 if (ru_col <= 0)
10032 ru_col = 1;
10033#else
10034 sc_col = Columns;
10035 ru_col = Columns;
10036#endif
10037}
10038
10039/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010040 * Unset local option value, similar to ":set opt<".
10041 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010042 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010043unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010044{
10045 struct vimoption *p;
10046 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010047 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010048
10049 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010050 if (opt_idx < 0)
10051 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010052 p = &(options[opt_idx]);
10053
10054 switch ((int)p->indir)
10055 {
10056 /* global option with local value: use local value if it's been set */
10057 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010058 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010059 break;
10060 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010061 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010062 break;
10063 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010064 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010065 break;
10066 case PV_AR:
10067 buf->b_p_ar = -1;
10068 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010069 case PV_BKC:
10070 clear_string_option(&buf->b_p_bkc);
10071 buf->b_bkc_flags = 0;
10072 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010073 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010074 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010075 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010076 case PV_TC:
10077 clear_string_option(&buf->b_p_tc);
10078 buf->b_tc_flags = 0;
10079 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080#ifdef FEAT_FIND_ID
10081 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010082 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010083 break;
10084 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010085 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010086 break;
10087#endif
10088#ifdef FEAT_INS_EXPAND
10089 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010090 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010091 break;
10092 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010093 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010094 break;
10095#endif
10096#ifdef FEAT_QUICKFIX
10097 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010098 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010099 break;
10100 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010101 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010102 break;
10103 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010104 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010105 break;
10106#endif
10107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10108 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010109 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010110 break;
10111#endif
10112#if defined(FEAT_CRYPT)
10113 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010114 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010115 break;
10116#endif
10117#ifdef FEAT_STL_OPT
10118 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010119 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010120 break;
10121#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010122 case PV_UL:
10123 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10124 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010125#ifdef FEAT_LISP
10126 case PV_LW:
10127 clear_string_option(&buf->b_p_lw);
10128 break;
10129#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010130 }
10131}
10132
10133/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010134 * Get pointer to option variable, depending on local or global scope.
10135 */
10136 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010137get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010138{
10139 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10140 {
10141 if (p->var == VAR_WIN)
10142 return (char_u *)GLOBAL_WO(get_varp(p));
10143 return p->var;
10144 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010145 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146 {
10147 switch ((int)p->indir)
10148 {
10149#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010150 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10151 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10152 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010154 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10155 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10156 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010157 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010158 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010159 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010161 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10162 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010163#endif
10164#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010165 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10166 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010168#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10169 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10170#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010171#if defined(FEAT_CRYPT)
10172 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10173#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010174#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010175 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010176#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010177 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010178#ifdef FEAT_LISP
10179 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10180#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010181 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182 }
10183 return NULL; /* "cannot happen" */
10184 }
10185 return get_varp(p);
10186}
10187
10188/*
10189 * Get pointer to option variable.
10190 */
10191 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010192get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193{
10194 /* hidden option, always return NULL */
10195 if (p->var == NULL)
10196 return NULL;
10197
10198 switch ((int)p->indir)
10199 {
10200 case PV_NONE: return p->var;
10201
10202 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010203 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010205 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010207 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010208 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010209 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010210 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010211 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010213 case PV_TC: return *curbuf->b_p_tc != NUL
10214 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010215 case PV_BKC: return *curbuf->b_p_bkc != NUL
10216 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010217#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010218 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010220 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10222#endif
10223#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010224 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010225 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010226 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10228#endif
10229#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010230 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010231 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010232 case PV_GP: return *curbuf->b_p_gp != NUL
10233 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10234 case PV_MP: return *curbuf->b_p_mp != NUL
10235 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010236#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010237#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10238 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10239 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10240#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010241#if defined(FEAT_CRYPT)
10242 case PV_CM: return *curbuf->b_p_cm != NUL
10243 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10244#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010245#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010246 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010247 ? (char_u *)&(curwin->w_p_stl) : p->var;
10248#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010249 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10250 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010251#ifdef FEAT_LISP
10252 case PV_LW: return *curbuf->b_p_lw != NUL
10253 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10254#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255
10256#ifdef FEAT_ARABIC
10257 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10258#endif
10259 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010260#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010261 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10262#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010263#ifdef FEAT_SYN_HL
10264 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10265 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010266 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010267#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268#ifdef FEAT_DIFF
10269 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10270#endif
10271#ifdef FEAT_FOLDING
10272 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10273 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10274 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10275 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10276 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10277 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10278 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10279# ifdef FEAT_EVAL
10280 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10281 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10282# endif
10283 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10284#endif
10285 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010286 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010287#ifdef FEAT_LINEBREAK
10288 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10289#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010290#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010291 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010292 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10295 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10296#endif
10297#ifdef FEAT_RIGHTLEFT
10298 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10299 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10300#endif
10301 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10302 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10303#ifdef FEAT_LINEBREAK
10304 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010305 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10306 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307#endif
10308#ifdef FEAT_SCROLLBIND
10309 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10310#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010311#ifdef FEAT_CURSORBIND
10312 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10313#endif
10314#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010315 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10316 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318
10319 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10320 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10321#ifdef FEAT_MBYTE
10322 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10323#endif
10324#if defined(FEAT_QUICKFIX)
10325 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10326 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10327#endif
10328 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10329 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10330#ifdef FEAT_CINDENT
10331 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10332 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10333 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10334#endif
10335#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10336 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10337#endif
10338#ifdef FEAT_COMMENTS
10339 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10340#endif
10341#ifdef FEAT_FOLDING
10342 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10343#endif
10344#ifdef FEAT_INS_EXPAND
10345 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10346#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010347#ifdef FEAT_COMPL_FUNC
10348 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010349 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010352 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10354#ifdef FEAT_MBYTE
10355 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10356#endif
10357 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10358#ifdef FEAT_AUTOCMD
10359 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10360#endif
10361 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010362 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10364 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10365 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10366 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10367#ifdef FEAT_FIND_ID
10368# ifdef FEAT_EVAL
10369 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10370# endif
10371#endif
10372#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10373 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10374 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10375#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010376#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010377 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10378#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010379#ifdef FEAT_CRYPT
10380 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10381#endif
10382#ifdef FEAT_LISP
10383 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10384#endif
10385 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10386 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10387 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10388 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10389 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010390 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010391#ifdef FEAT_TEXTOBJ
10392 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10393#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010394 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10395#ifdef FEAT_SMARTINDENT
10396 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10400#ifdef FEAT_SEARCHPATH
10401 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10402#endif
10403 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10404#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010405 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010406 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10407#endif
10408#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010409 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10410 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10411 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010412#endif
10413 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10414 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10415 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10416 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010417#ifdef FEAT_PERSISTENT_UNDO
10418 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10421#ifdef FEAT_KEYMAP
10422 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10423#endif
10424 default: EMSG(_("E356: get_varp ERROR"));
10425 }
10426 /* always return a valid pointer to avoid a crash! */
10427 return (char_u *)&(curbuf->b_p_wm);
10428}
10429
10430/*
10431 * Get the value of 'equalprg', either the buffer-local one or the global one.
10432 */
10433 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010434get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435{
10436 if (*curbuf->b_p_ep == NUL)
10437 return p_ep;
10438 return curbuf->b_p_ep;
10439}
10440
10441#if defined(FEAT_WINDOWS) || defined(PROTO)
10442/*
10443 * Copy options from one window to another.
10444 * Used when splitting a window.
10445 */
10446 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010447win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448{
10449 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10450 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10451# ifdef FEAT_RIGHTLEFT
10452# ifdef FEAT_FKMAP
10453 /* Is this right? */
10454 wp_to->w_farsi = wp_from->w_farsi;
10455# endif
10456# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010457#if defined(FEAT_LINEBREAK)
10458 briopt_check(wp_to);
10459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010460}
10461#endif
10462
10463/*
10464 * Copy the options from one winopt_T to another.
10465 * Doesn't free the old option values in "to", use clear_winopt() for that.
10466 * The 'scroll' option is not copied, because it depends on the window height.
10467 * The 'previewwindow' option is reset, there can be only one preview window.
10468 */
10469 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010470copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010471{
10472#ifdef FEAT_ARABIC
10473 to->wo_arab = from->wo_arab;
10474#endif
10475 to->wo_list = from->wo_list;
10476 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010477 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010478#ifdef FEAT_LINEBREAK
10479 to->wo_nuw = from->wo_nuw;
10480#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481#ifdef FEAT_RIGHTLEFT
10482 to->wo_rl = from->wo_rl;
10483 to->wo_rlc = vim_strsave(from->wo_rlc);
10484#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010485#ifdef FEAT_STL_OPT
10486 to->wo_stl = vim_strsave(from->wo_stl);
10487#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010488 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010489#ifdef FEAT_DIFF
10490 to->wo_wrap_save = from->wo_wrap_save;
10491#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010492#ifdef FEAT_LINEBREAK
10493 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010494 to->wo_bri = from->wo_bri;
10495 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010496#endif
10497#ifdef FEAT_SCROLLBIND
10498 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010499 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010501#ifdef FEAT_CURSORBIND
10502 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010503 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010504#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010505#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010506 to->wo_spell = from->wo_spell;
10507#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010508#ifdef FEAT_SYN_HL
10509 to->wo_cuc = from->wo_cuc;
10510 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010511 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010513#ifdef FEAT_DIFF
10514 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010515 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010517#ifdef FEAT_CONCEAL
10518 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010519 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010520#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521#ifdef FEAT_FOLDING
10522 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010523 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010525 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526 to->wo_fdi = vim_strsave(from->wo_fdi);
10527 to->wo_fml = from->wo_fml;
10528 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010529 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010531 to->wo_fdm_save = from->wo_diff_saved
10532 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533 to->wo_fdn = from->wo_fdn;
10534# ifdef FEAT_EVAL
10535 to->wo_fde = vim_strsave(from->wo_fde);
10536 to->wo_fdt = vim_strsave(from->wo_fdt);
10537# endif
10538 to->wo_fmr = vim_strsave(from->wo_fmr);
10539#endif
10540 check_winopt(to); /* don't want NULL pointers */
10541}
10542
10543/*
10544 * Check string options in a window for a NULL value.
10545 */
10546 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010547check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548{
10549 check_winopt(&win->w_onebuf_opt);
10550 check_winopt(&win->w_allbuf_opt);
10551}
10552
10553/*
10554 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10555 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010556 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010557check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558{
10559#ifdef FEAT_FOLDING
10560 check_string_option(&wop->wo_fdi);
10561 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010562 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563# ifdef FEAT_EVAL
10564 check_string_option(&wop->wo_fde);
10565 check_string_option(&wop->wo_fdt);
10566# endif
10567 check_string_option(&wop->wo_fmr);
10568#endif
10569#ifdef FEAT_RIGHTLEFT
10570 check_string_option(&wop->wo_rlc);
10571#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010572#ifdef FEAT_STL_OPT
10573 check_string_option(&wop->wo_stl);
10574#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010575#ifdef FEAT_SYN_HL
10576 check_string_option(&wop->wo_cc);
10577#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010578#ifdef FEAT_CONCEAL
10579 check_string_option(&wop->wo_cocu);
10580#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010581#ifdef FEAT_LINEBREAK
10582 check_string_option(&wop->wo_briopt);
10583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584}
10585
10586/*
10587 * Free the allocated memory inside a winopt_T.
10588 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010590clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591{
10592#ifdef FEAT_FOLDING
10593 clear_string_option(&wop->wo_fdi);
10594 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010595 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596# ifdef FEAT_EVAL
10597 clear_string_option(&wop->wo_fde);
10598 clear_string_option(&wop->wo_fdt);
10599# endif
10600 clear_string_option(&wop->wo_fmr);
10601#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010602#ifdef FEAT_LINEBREAK
10603 clear_string_option(&wop->wo_briopt);
10604#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605#ifdef FEAT_RIGHTLEFT
10606 clear_string_option(&wop->wo_rlc);
10607#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010608#ifdef FEAT_STL_OPT
10609 clear_string_option(&wop->wo_stl);
10610#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010611#ifdef FEAT_SYN_HL
10612 clear_string_option(&wop->wo_cc);
10613#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010614#ifdef FEAT_CONCEAL
10615 clear_string_option(&wop->wo_cocu);
10616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617}
10618
10619/*
10620 * Copy global option values to local options for one buffer.
10621 * Used when creating a new buffer and sometimes when entering a buffer.
10622 * flags:
10623 * BCO_ENTER We will enter the buf buffer.
10624 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10625 * appropriate.
10626 * BCO_NOHELP Don't copy the values to a help buffer.
10627 */
10628 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010629buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630{
10631 int should_copy = TRUE;
10632 char_u *save_p_isk = NULL; /* init for GCC */
10633 int dont_do_help;
10634 int did_isk = FALSE;
10635
10636 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010637 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010638 */
10639 if (buf == NULL || !buf_valid(buf))
10640 return;
10641
10642 /*
10643 * Skip this when the option defaults have not been set yet. Happens when
10644 * main() allocates the first buffer.
10645 */
10646 if (p_cpo != NULL)
10647 {
10648 /*
10649 * Always copy when entering and 'cpo' contains 'S'.
10650 * Don't copy when already initialized.
10651 * Don't copy when 'cpo' contains 's' and not entering.
10652 * 'S' BCO_ENTER initialized 's' should_copy
10653 * yes yes X X TRUE
10654 * yes no yes X FALSE
10655 * no X yes X FALSE
10656 * X no no yes FALSE
10657 * X no no no TRUE
10658 * no yes no X TRUE
10659 */
10660 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10661 && (buf->b_p_initialized
10662 || (!(flags & BCO_ENTER)
10663 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10664 should_copy = FALSE;
10665
10666 if (should_copy || (flags & BCO_ALWAYS))
10667 {
10668 /* Don't copy the options specific to a help buffer when
10669 * BCO_NOHELP is given or the options were initialized already
10670 * (jumping back to a help file with CTRL-T or CTRL-O) */
10671 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10672 || buf->b_p_initialized;
10673 if (dont_do_help) /* don't free b_p_isk */
10674 {
10675 save_p_isk = buf->b_p_isk;
10676 buf->b_p_isk = NULL;
10677 }
10678 /*
10679 * Always free the allocated strings.
10680 * If not already initialized, set 'readonly' and copy 'fileformat'.
10681 */
10682 if (!buf->b_p_initialized)
10683 {
10684 free_buf_options(buf, TRUE);
10685 buf->b_p_ro = FALSE; /* don't copy readonly */
10686 buf->b_p_tx = p_tx;
10687#ifdef FEAT_MBYTE
10688 buf->b_p_fenc = vim_strsave(p_fenc);
10689#endif
10690 buf->b_p_ff = vim_strsave(p_ff);
10691#if defined(FEAT_QUICKFIX)
10692 buf->b_p_bh = empty_option;
10693 buf->b_p_bt = empty_option;
10694#endif
10695 }
10696 else
10697 free_buf_options(buf, FALSE);
10698
10699 buf->b_p_ai = p_ai;
10700 buf->b_p_ai_nopaste = p_ai_nopaste;
10701 buf->b_p_sw = p_sw;
10702 buf->b_p_tw = p_tw;
10703 buf->b_p_tw_nopaste = p_tw_nopaste;
10704 buf->b_p_tw_nobin = p_tw_nobin;
10705 buf->b_p_wm = p_wm;
10706 buf->b_p_wm_nopaste = p_wm_nopaste;
10707 buf->b_p_wm_nobin = p_wm_nobin;
10708 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010709#ifdef FEAT_MBYTE
10710 buf->b_p_bomb = p_bomb;
10711#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010712 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713 buf->b_p_et = p_et;
10714 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010715 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716 buf->b_p_ml = p_ml;
10717 buf->b_p_ml_nobin = p_ml_nobin;
10718 buf->b_p_inf = p_inf;
10719 buf->b_p_swf = p_swf;
10720#ifdef FEAT_INS_EXPAND
10721 buf->b_p_cpt = vim_strsave(p_cpt);
10722#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010723#ifdef FEAT_COMPL_FUNC
10724 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010725 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 buf->b_p_sts = p_sts;
10728 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730#ifdef FEAT_COMMENTS
10731 buf->b_p_com = vim_strsave(p_com);
10732#endif
10733#ifdef FEAT_FOLDING
10734 buf->b_p_cms = vim_strsave(p_cms);
10735#endif
10736 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010737 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738 buf->b_p_nf = vim_strsave(p_nf);
10739 buf->b_p_mps = vim_strsave(p_mps);
10740#ifdef FEAT_SMARTINDENT
10741 buf->b_p_si = p_si;
10742#endif
10743 buf->b_p_ci = p_ci;
10744#ifdef FEAT_CINDENT
10745 buf->b_p_cin = p_cin;
10746 buf->b_p_cink = vim_strsave(p_cink);
10747 buf->b_p_cino = vim_strsave(p_cino);
10748#endif
10749#ifdef FEAT_AUTOCMD
10750 /* Don't copy 'filetype', it must be detected */
10751 buf->b_p_ft = empty_option;
10752#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010753 buf->b_p_pi = p_pi;
10754#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10755 buf->b_p_cinw = vim_strsave(p_cinw);
10756#endif
10757#ifdef FEAT_LISP
10758 buf->b_p_lisp = p_lisp;
10759#endif
10760#ifdef FEAT_SYN_HL
10761 /* Don't copy 'syntax', it must be set */
10762 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010763 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010764 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010765#endif
10766#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010767 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010768 (void)compile_cap_prog(&buf->b_s);
10769 buf->b_s.b_p_spf = vim_strsave(p_spf);
10770 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771#endif
10772#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10773 buf->b_p_inde = vim_strsave(p_inde);
10774 buf->b_p_indk = vim_strsave(p_indk);
10775#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010776#if defined(FEAT_EVAL)
10777 buf->b_p_fex = vim_strsave(p_fex);
10778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779#ifdef FEAT_CRYPT
10780 buf->b_p_key = vim_strsave(p_key);
10781#endif
10782#ifdef FEAT_SEARCHPATH
10783 buf->b_p_sua = vim_strsave(p_sua);
10784#endif
10785#ifdef FEAT_KEYMAP
10786 buf->b_p_keymap = vim_strsave(p_keymap);
10787 buf->b_kmap_state |= KEYMAP_INIT;
10788#endif
10789 /* This isn't really an option, but copying the langmap and IME
10790 * state from the current buffer is better than resetting it. */
10791 buf->b_p_iminsert = p_iminsert;
10792 buf->b_p_imsearch = p_imsearch;
10793
10794 /* options that are normally global but also have a local value
10795 * are not copied, start using the global value */
10796 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010797 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010798 buf->b_p_bkc = empty_option;
10799 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010800#ifdef FEAT_QUICKFIX
10801 buf->b_p_gp = empty_option;
10802 buf->b_p_mp = empty_option;
10803 buf->b_p_efm = empty_option;
10804#endif
10805 buf->b_p_ep = empty_option;
10806 buf->b_p_kp = empty_option;
10807 buf->b_p_path = empty_option;
10808 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010809 buf->b_p_tc = empty_option;
10810 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811#ifdef FEAT_FIND_ID
10812 buf->b_p_def = empty_option;
10813 buf->b_p_inc = empty_option;
10814# ifdef FEAT_EVAL
10815 buf->b_p_inex = vim_strsave(p_inex);
10816# endif
10817#endif
10818#ifdef FEAT_INS_EXPAND
10819 buf->b_p_dict = empty_option;
10820 buf->b_p_tsr = empty_option;
10821#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010822#ifdef FEAT_TEXTOBJ
10823 buf->b_p_qe = vim_strsave(p_qe);
10824#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010825#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10826 buf->b_p_bexpr = empty_option;
10827#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010828#if defined(FEAT_CRYPT)
10829 buf->b_p_cm = empty_option;
10830#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010831#ifdef FEAT_PERSISTENT_UNDO
10832 buf->b_p_udf = p_udf;
10833#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010834#ifdef FEAT_LISP
10835 buf->b_p_lw = empty_option;
10836#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837
10838 /*
10839 * Don't copy the options set by ex_help(), use the saved values,
10840 * when going from a help buffer to a non-help buffer.
10841 * Don't touch these at all when BCO_NOHELP is used and going from
10842 * or to a help buffer.
10843 */
10844 if (dont_do_help)
10845 buf->b_p_isk = save_p_isk;
10846 else
10847 {
10848 buf->b_p_isk = vim_strsave(p_isk);
10849 did_isk = TRUE;
10850 buf->b_p_ts = p_ts;
10851 buf->b_help = FALSE;
10852#ifdef FEAT_QUICKFIX
10853 if (buf->b_p_bt[0] == 'h')
10854 clear_string_option(&buf->b_p_bt);
10855#endif
10856 buf->b_p_ma = p_ma;
10857 }
10858 }
10859
10860 /*
10861 * When the options should be copied (ignoring BCO_ALWAYS), set the
10862 * flag that indicates that the options have been initialized.
10863 */
10864 if (should_copy)
10865 buf->b_p_initialized = TRUE;
10866 }
10867
10868 check_buf_options(buf); /* make sure we don't have NULLs */
10869 if (did_isk)
10870 (void)buf_init_chartab(buf, FALSE);
10871}
10872
10873/*
10874 * Reset the 'modifiable' option and its default value.
10875 */
10876 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010877reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878{
10879 int opt_idx;
10880
10881 curbuf->b_p_ma = FALSE;
10882 p_ma = FALSE;
10883 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010884 if (opt_idx >= 0)
10885 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010886}
10887
10888/*
10889 * Set the global value for 'iminsert' to the local value.
10890 */
10891 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010892set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010893{
10894 p_iminsert = curbuf->b_p_iminsert;
10895}
10896
10897/*
10898 * Set the global value for 'imsearch' to the local value.
10899 */
10900 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010901set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902{
10903 p_imsearch = curbuf->b_p_imsearch;
10904}
10905
10906#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10907static int expand_option_idx = -1;
10908static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10909static int expand_option_flags = 0;
10910
10911 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010912set_context_in_set_cmd(
10913 expand_T *xp,
10914 char_u *arg,
10915 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916{
10917 int nextchar;
10918 long_u flags = 0; /* init for GCC */
10919 int opt_idx = 0; /* init for GCC */
10920 char_u *p;
10921 char_u *s;
10922 int is_term_option = FALSE;
10923 int key;
10924
10925 expand_option_flags = opt_flags;
10926
10927 xp->xp_context = EXPAND_SETTINGS;
10928 if (*arg == NUL)
10929 {
10930 xp->xp_pattern = arg;
10931 return;
10932 }
10933 p = arg + STRLEN(arg) - 1;
10934 if (*p == ' ' && *(p - 1) != '\\')
10935 {
10936 xp->xp_pattern = p + 1;
10937 return;
10938 }
10939 while (p > arg)
10940 {
10941 s = p;
10942 /* count number of backslashes before ' ' or ',' */
10943 if (*p == ' ' || *p == ',')
10944 {
10945 while (s > arg && *(s - 1) == '\\')
10946 --s;
10947 }
10948 /* break at a space with an even number of backslashes */
10949 if (*p == ' ' && ((p - s) & 1) == 0)
10950 {
10951 ++p;
10952 break;
10953 }
10954 --p;
10955 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010956 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957 {
10958 xp->xp_context = EXPAND_BOOL_SETTINGS;
10959 p += 2;
10960 }
10961 if (STRNCMP(p, "inv", 3) == 0)
10962 {
10963 xp->xp_context = EXPAND_BOOL_SETTINGS;
10964 p += 3;
10965 }
10966 xp->xp_pattern = arg = p;
10967 if (*arg == '<')
10968 {
10969 while (*p != '>')
10970 if (*p++ == NUL) /* expand terminal option name */
10971 return;
10972 key = get_special_key_code(arg + 1);
10973 if (key == 0) /* unknown name */
10974 {
10975 xp->xp_context = EXPAND_NOTHING;
10976 return;
10977 }
10978 nextchar = *++p;
10979 is_term_option = TRUE;
10980 expand_option_name[2] = KEY2TERMCAP0(key);
10981 expand_option_name[3] = KEY2TERMCAP1(key);
10982 }
10983 else
10984 {
10985 if (p[0] == 't' && p[1] == '_')
10986 {
10987 p += 2;
10988 if (*p != NUL)
10989 ++p;
10990 if (*p == NUL)
10991 return; /* expand option name */
10992 nextchar = *++p;
10993 is_term_option = TRUE;
10994 expand_option_name[2] = p[-2];
10995 expand_option_name[3] = p[-1];
10996 }
10997 else
10998 {
10999 /* Allow * wildcard */
11000 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11001 p++;
11002 if (*p == NUL)
11003 return;
11004 nextchar = *p;
11005 *p = NUL;
11006 opt_idx = findoption(arg);
11007 *p = nextchar;
11008 if (opt_idx == -1 || options[opt_idx].var == NULL)
11009 {
11010 xp->xp_context = EXPAND_NOTHING;
11011 return;
11012 }
11013 flags = options[opt_idx].flags;
11014 if (flags & P_BOOL)
11015 {
11016 xp->xp_context = EXPAND_NOTHING;
11017 return;
11018 }
11019 }
11020 }
11021 /* handle "-=" and "+=" */
11022 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11023 {
11024 ++p;
11025 nextchar = '=';
11026 }
11027 if ((nextchar != '=' && nextchar != ':')
11028 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11029 {
11030 xp->xp_context = EXPAND_UNSUCCESSFUL;
11031 return;
11032 }
11033 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11034 {
11035 xp->xp_context = EXPAND_OLD_SETTING;
11036 if (is_term_option)
11037 expand_option_idx = -1;
11038 else
11039 expand_option_idx = opt_idx;
11040 xp->xp_pattern = p + 1;
11041 return;
11042 }
11043 xp->xp_context = EXPAND_NOTHING;
11044 if (is_term_option || (flags & P_NUM))
11045 return;
11046
11047 xp->xp_pattern = p + 1;
11048
11049 if (flags & P_EXPAND)
11050 {
11051 p = options[opt_idx].var;
11052 if (p == (char_u *)&p_bdir
11053 || p == (char_u *)&p_dir
11054 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011055 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011056 || p == (char_u *)&p_rtp
11057#ifdef FEAT_SEARCHPATH
11058 || p == (char_u *)&p_cdpath
11059#endif
11060#ifdef FEAT_SESSION
11061 || p == (char_u *)&p_vdir
11062#endif
11063 )
11064 {
11065 xp->xp_context = EXPAND_DIRECTORIES;
11066 if (p == (char_u *)&p_path
11067#ifdef FEAT_SEARCHPATH
11068 || p == (char_u *)&p_cdpath
11069#endif
11070 )
11071 xp->xp_backslash = XP_BS_THREE;
11072 else
11073 xp->xp_backslash = XP_BS_ONE;
11074 }
11075 else
11076 {
11077 xp->xp_context = EXPAND_FILES;
11078 /* for 'tags' need three backslashes for a space */
11079 if (p == (char_u *)&p_tags)
11080 xp->xp_backslash = XP_BS_THREE;
11081 else
11082 xp->xp_backslash = XP_BS_ONE;
11083 }
11084 }
11085
11086 /* For an option that is a list of file names, find the start of the
11087 * last file name. */
11088 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11089 {
11090 /* count number of backslashes before ' ' or ',' */
11091 if (*p == ' ' || *p == ',')
11092 {
11093 s = p;
11094 while (s > xp->xp_pattern && *(s - 1) == '\\')
11095 --s;
11096 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11097 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11098 {
11099 xp->xp_pattern = p + 1;
11100 break;
11101 }
11102 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011103
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011104#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011105 /* for 'spellsuggest' start at "file:" */
11106 if (options[opt_idx].var == (char_u *)&p_sps
11107 && STRNCMP(p, "file:", 5) == 0)
11108 {
11109 xp->xp_pattern = p + 5;
11110 break;
11111 }
11112#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011113 }
11114
11115 return;
11116}
11117
11118 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011119ExpandSettings(
11120 expand_T *xp,
11121 regmatch_T *regmatch,
11122 int *num_file,
11123 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124{
11125 int num_normal = 0; /* Nr of matching non-term-code settings */
11126 int num_term = 0; /* Nr of matching terminal code settings */
11127 int opt_idx;
11128 int match;
11129 int count = 0;
11130 char_u *str;
11131 int loop;
11132 int is_term_opt;
11133 char_u name_buf[MAX_KEY_NAME_LEN];
11134 static char *(names[]) = {"all", "termcap"};
11135 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11136
11137 /* do this loop twice:
11138 * loop == 0: count the number of matching options
11139 * loop == 1: copy the matching options into allocated memory
11140 */
11141 for (loop = 0; loop <= 1; ++loop)
11142 {
11143 regmatch->rm_ic = ic;
11144 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11145 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011146 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11147 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11149 {
11150 if (loop == 0)
11151 num_normal++;
11152 else
11153 (*file)[count++] = vim_strsave((char_u *)names[match]);
11154 }
11155 }
11156 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11157 opt_idx++)
11158 {
11159 if (options[opt_idx].var == NULL)
11160 continue;
11161 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11162 && !(options[opt_idx].flags & P_BOOL))
11163 continue;
11164 is_term_opt = istermoption(&options[opt_idx]);
11165 if (is_term_opt && num_normal > 0)
11166 continue;
11167 match = FALSE;
11168 if (vim_regexec(regmatch, str, (colnr_T)0)
11169 || (options[opt_idx].shortname != NULL
11170 && vim_regexec(regmatch,
11171 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11172 match = TRUE;
11173 else if (is_term_opt)
11174 {
11175 name_buf[0] = '<';
11176 name_buf[1] = 't';
11177 name_buf[2] = '_';
11178 name_buf[3] = str[2];
11179 name_buf[4] = str[3];
11180 name_buf[5] = '>';
11181 name_buf[6] = NUL;
11182 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11183 {
11184 match = TRUE;
11185 str = name_buf;
11186 }
11187 }
11188 if (match)
11189 {
11190 if (loop == 0)
11191 {
11192 if (is_term_opt)
11193 num_term++;
11194 else
11195 num_normal++;
11196 }
11197 else
11198 (*file)[count++] = vim_strsave(str);
11199 }
11200 }
11201 /*
11202 * Check terminal key codes, these are not in the option table
11203 */
11204 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11205 {
11206 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11207 {
11208 if (!isprint(str[0]) || !isprint(str[1]))
11209 continue;
11210
11211 name_buf[0] = 't';
11212 name_buf[1] = '_';
11213 name_buf[2] = str[0];
11214 name_buf[3] = str[1];
11215 name_buf[4] = NUL;
11216
11217 match = FALSE;
11218 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11219 match = TRUE;
11220 else
11221 {
11222 name_buf[0] = '<';
11223 name_buf[1] = 't';
11224 name_buf[2] = '_';
11225 name_buf[3] = str[0];
11226 name_buf[4] = str[1];
11227 name_buf[5] = '>';
11228 name_buf[6] = NUL;
11229
11230 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11231 match = TRUE;
11232 }
11233 if (match)
11234 {
11235 if (loop == 0)
11236 num_term++;
11237 else
11238 (*file)[count++] = vim_strsave(name_buf);
11239 }
11240 }
11241
11242 /*
11243 * Check special key names.
11244 */
11245 regmatch->rm_ic = TRUE; /* ignore case here */
11246 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11247 {
11248 name_buf[0] = '<';
11249 STRCPY(name_buf + 1, str);
11250 STRCAT(name_buf, ">");
11251
11252 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11253 {
11254 if (loop == 0)
11255 num_term++;
11256 else
11257 (*file)[count++] = vim_strsave(name_buf);
11258 }
11259 }
11260 }
11261 if (loop == 0)
11262 {
11263 if (num_normal > 0)
11264 *num_file = num_normal;
11265 else if (num_term > 0)
11266 *num_file = num_term;
11267 else
11268 return OK;
11269 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11270 if (*file == NULL)
11271 {
11272 *file = (char_u **)"";
11273 return FAIL;
11274 }
11275 }
11276 }
11277 return OK;
11278}
11279
11280 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011281ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011282{
11283 char_u *var = NULL; /* init for GCC */
11284 char_u *buf;
11285
11286 *num_file = 0;
11287 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11288 if (*file == NULL)
11289 return FAIL;
11290
11291 /*
11292 * For a terminal key code expand_option_idx is < 0.
11293 */
11294 if (expand_option_idx < 0)
11295 {
11296 var = find_termcode(expand_option_name + 2);
11297 if (var == NULL)
11298 expand_option_idx = findoption(expand_option_name);
11299 }
11300
11301 if (expand_option_idx >= 0)
11302 {
11303 /* put string of option value in NameBuff */
11304 option_value2string(&options[expand_option_idx], expand_option_flags);
11305 var = NameBuff;
11306 }
11307 else if (var == NULL)
11308 var = (char_u *)"";
11309
11310 /* A backslash is required before some characters. This is the reverse of
11311 * what happens in do_set(). */
11312 buf = vim_strsave_escaped(var, escape_chars);
11313
11314 if (buf == NULL)
11315 {
11316 vim_free(*file);
11317 *file = NULL;
11318 return FAIL;
11319 }
11320
11321#ifdef BACKSLASH_IN_FILENAME
11322 /* For MS-Windows et al. we don't double backslashes at the start and
11323 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011324 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011325 if (var[0] == '\\' && var[1] == '\\'
11326 && expand_option_idx >= 0
11327 && (options[expand_option_idx].flags & P_EXPAND)
11328 && vim_isfilec(var[2])
11329 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011330 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331#endif
11332
11333 *file[0] = buf;
11334 *num_file = 1;
11335 return OK;
11336}
11337#endif
11338
11339/*
11340 * Get the value for the numeric or string option *opp in a nice format into
11341 * NameBuff[]. Must not be called with a hidden option!
11342 */
11343 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011344option_value2string(
11345 struct vimoption *opp,
11346 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011347{
11348 char_u *varp;
11349
11350 varp = get_varp_scope(opp, opt_flags);
11351
11352 if (opp->flags & P_NUM)
11353 {
11354 long wc = 0;
11355
11356 if (wc_use_keyname(varp, &wc))
11357 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11358 else if (wc != 0)
11359 STRCPY(NameBuff, transchar((int)wc));
11360 else
11361 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11362 }
11363 else /* P_STRING */
11364 {
11365 varp = *(char_u **)(varp);
11366 if (varp == NULL) /* just in case */
11367 NameBuff[0] = NUL;
11368#ifdef FEAT_CRYPT
11369 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011370 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011371 STRCPY(NameBuff, "*****");
11372#endif
11373 else if (opp->flags & P_EXPAND)
11374 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11375 /* Translate 'pastetoggle' into special key names */
11376 else if ((char_u **)opp->var == &p_pt)
11377 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11378 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011379 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011380 }
11381}
11382
11383/*
11384 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11385 * printed as a keyname.
11386 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11387 */
11388 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011389wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011390{
11391 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11392 {
11393 *wcp = *(long *)varp;
11394 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11395 return TRUE;
11396 }
11397 return FALSE;
11398}
11399
Bram Moolenaar01615492015-02-03 13:00:38 +010011400#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011402 * Any character has an equivalent 'langmap' character. This is used for
11403 * keyboards that have a special language mode that sends characters above
11404 * 128 (although other characters can be translated too). The "to" field is a
11405 * Vim command character. This avoids having to switch the keyboard back to
11406 * ASCII mode when leaving Insert mode.
11407 *
11408 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11409 * commands.
11410 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11411 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11412 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011413 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011414# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011415/*
11416 * With multi-byte support use growarray for 'langmap' chars >= 256
11417 */
11418typedef struct
11419{
11420 int from;
11421 int to;
11422} langmap_entry_T;
11423
11424static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011425static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011426
11427/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011428 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11429 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011430 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011431 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011432langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011433{
11434 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011435 int a = 0;
11436 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011437
11438 /* Do a binary search for an existing entry. */
11439 while (a != b)
11440 {
11441 int i = (a + b) / 2;
11442 int d = entries[i].from - from;
11443
11444 if (d == 0)
11445 {
11446 entries[i].to = to;
11447 return;
11448 }
11449 if (d < 0)
11450 a = i + 1;
11451 else
11452 b = i;
11453 }
11454
11455 if (ga_grow(&langmap_mapga, 1) != OK)
11456 return; /* out of memory */
11457
11458 /* insert new entry at position "a" */
11459 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11460 mch_memmove(entries + 1, entries,
11461 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11462 ++langmap_mapga.ga_len;
11463 entries[0].from = from;
11464 entries[0].to = to;
11465}
11466
11467/*
11468 * Apply 'langmap' to multi-byte character "c" and return the result.
11469 */
11470 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011471langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011472{
11473 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11474 int a = 0;
11475 int b = langmap_mapga.ga_len;
11476
11477 while (a != b)
11478 {
11479 int i = (a + b) / 2;
11480 int d = entries[i].from - c;
11481
11482 if (d == 0)
11483 return entries[i].to; /* found matching entry */
11484 if (d < 0)
11485 a = i + 1;
11486 else
11487 b = i;
11488 }
11489 return c; /* no entry found, return "c" unmodified */
11490}
11491# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011492
11493 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011494langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011495{
11496 int i;
11497
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011498 for (i = 0; i < 256; i++)
11499 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11500# ifdef FEAT_MBYTE
11501 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11502# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011503}
11504
11505/*
11506 * Called when langmap option is set; the language map can be
11507 * changed at any time!
11508 */
11509 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011510langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011511{
11512 char_u *p;
11513 char_u *p2;
11514 int from, to;
11515
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011516#ifdef FEAT_MBYTE
11517 ga_clear(&langmap_mapga); /* clear the previous map first */
11518#endif
11519 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011520
11521 for (p = p_langmap; p[0] != NUL; )
11522 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011523 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11524 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011525 {
11526 if (p2[0] == '\\' && p2[1] != NUL)
11527 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528 }
11529 if (p2[0] == ';')
11530 ++p2; /* abcd;ABCD form, p2 points to A */
11531 else
11532 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11533 while (p[0])
11534 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011535 if (p[0] == ',')
11536 {
11537 ++p;
11538 break;
11539 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011540 if (p[0] == '\\' && p[1] != NUL)
11541 ++p;
11542#ifdef FEAT_MBYTE
11543 from = (*mb_ptr2char)(p);
11544#else
11545 from = p[0];
11546#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011547 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011548 if (p2 == NULL)
11549 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011550 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011551 if (p[0] != ',')
11552 {
11553 if (p[0] == '\\')
11554 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011556 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011558 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011559#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561 }
11562 else
11563 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011564 if (p2[0] != ',')
11565 {
11566 if (p2[0] == '\\')
11567 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011568#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011569 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011570#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011571 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011572#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011573 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011574 }
11575 if (to == NUL)
11576 {
11577 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11578 transchar(from));
11579 return;
11580 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011581
11582#ifdef FEAT_MBYTE
11583 if (from >= 256)
11584 langmap_set_entry(from, to);
11585 else
11586#endif
11587 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011588
11589 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011590 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011591 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011592 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011593 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011594 if (*p == ';')
11595 {
11596 p = p2;
11597 if (p[0] != NUL)
11598 {
11599 if (p[0] != ',')
11600 {
11601 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11602 return;
11603 }
11604 ++p;
11605 }
11606 break;
11607 }
11608 }
11609 }
11610 }
11611}
11612#endif
11613
11614/*
11615 * Return TRUE if format option 'x' is in effect.
11616 * Take care of no formatting when 'paste' is set.
11617 */
11618 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011619has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011620{
11621 if (p_paste)
11622 return FALSE;
11623 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11624}
11625
11626/*
11627 * Return TRUE if "x" is present in 'shortmess' option, or
11628 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11629 */
11630 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011631shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011632{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011633 return p_shm != NULL &&
11634 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011635 || (vim_strchr(p_shm, 'a') != NULL
11636 && vim_strchr((char_u *)SHM_A, x) != NULL));
11637}
11638
11639/*
11640 * paste_option_changed() - Called after p_paste was set or reset.
11641 */
11642 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011643paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011644{
11645 static int old_p_paste = FALSE;
11646 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011647 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011648#ifdef FEAT_CMDL_INFO
11649 static int save_ru = 0;
11650#endif
11651#ifdef FEAT_RIGHTLEFT
11652 static int save_ri = 0;
11653 static int save_hkmap = 0;
11654#endif
11655 buf_T *buf;
11656
11657 if (p_paste)
11658 {
11659 /*
11660 * Paste switched from off to on.
11661 * Save the current values, so they can be restored later.
11662 */
11663 if (!old_p_paste)
11664 {
11665 /* save options for each buffer */
11666 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11667 {
11668 buf->b_p_tw_nopaste = buf->b_p_tw;
11669 buf->b_p_wm_nopaste = buf->b_p_wm;
11670 buf->b_p_sts_nopaste = buf->b_p_sts;
11671 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011672 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673 }
11674
11675 /* save global options */
11676 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011677 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011678#ifdef FEAT_CMDL_INFO
11679 save_ru = p_ru;
11680#endif
11681#ifdef FEAT_RIGHTLEFT
11682 save_ri = p_ri;
11683 save_hkmap = p_hkmap;
11684#endif
11685 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011686 p_ai_nopaste = p_ai;
11687 p_et_nopaste = p_et;
11688 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689 p_tw_nopaste = p_tw;
11690 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011691 }
11692
11693 /*
11694 * Always set the option values, also when 'paste' is set when it is
11695 * already on.
11696 */
11697 /* set options for each buffer */
11698 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11699 {
11700 buf->b_p_tw = 0; /* textwidth is 0 */
11701 buf->b_p_wm = 0; /* wrapmargin is 0 */
11702 buf->b_p_sts = 0; /* softtabstop is 0 */
11703 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011704 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011705 }
11706
11707 /* set global options */
11708 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011709 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011710#ifdef FEAT_CMDL_INFO
11711# ifdef FEAT_WINDOWS
11712 if (p_ru)
11713 status_redraw_all(); /* redraw to remove the ruler */
11714# endif
11715 p_ru = 0; /* no ruler */
11716#endif
11717#ifdef FEAT_RIGHTLEFT
11718 p_ri = 0; /* no reverse insert */
11719 p_hkmap = 0; /* no Hebrew keyboard */
11720#endif
11721 /* set global values for local buffer options */
11722 p_tw = 0;
11723 p_wm = 0;
11724 p_sts = 0;
11725 p_ai = 0;
11726 }
11727
11728 /*
11729 * Paste switched from on to off: Restore saved values.
11730 */
11731 else if (old_p_paste)
11732 {
11733 /* restore options for each buffer */
11734 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11735 {
11736 buf->b_p_tw = buf->b_p_tw_nopaste;
11737 buf->b_p_wm = buf->b_p_wm_nopaste;
11738 buf->b_p_sts = buf->b_p_sts_nopaste;
11739 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011740 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741 }
11742
11743 /* restore global options */
11744 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011745 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746#ifdef FEAT_CMDL_INFO
11747# ifdef FEAT_WINDOWS
11748 if (p_ru != save_ru)
11749 status_redraw_all(); /* redraw to draw the ruler */
11750# endif
11751 p_ru = save_ru;
11752#endif
11753#ifdef FEAT_RIGHTLEFT
11754 p_ri = save_ri;
11755 p_hkmap = save_hkmap;
11756#endif
11757 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011758 p_ai = p_ai_nopaste;
11759 p_et = p_et_nopaste;
11760 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 p_tw = p_tw_nopaste;
11762 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011763 }
11764
11765 old_p_paste = p_paste;
11766}
11767
11768/*
11769 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11770 *
11771 * Reset 'compatible' and set the values for options that didn't get set yet
11772 * to the Vim defaults.
11773 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011774 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011775 */
11776 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011777vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011778{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011779 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011780 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011781 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782
11783 if (!option_was_set((char_u *)"cp"))
11784 {
11785 p_cp = FALSE;
11786 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11787 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11788 set_option_default(opt_idx, OPT_FREE, FALSE);
11789 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011790 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011791 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011792
11793 if (fname != NULL)
11794 {
11795 p = vim_getenv(envname, &dofree);
11796 if (p == NULL)
11797 {
11798 /* Set $MYVIMRC to the first vimrc file found. */
11799 p = FullName_save(fname, FALSE);
11800 if (p != NULL)
11801 {
11802 vim_setenv(envname, p);
11803 vim_free(p);
11804 }
11805 }
11806 else if (dofree)
11807 vim_free(p);
11808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011809}
11810
11811/*
11812 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11813 */
11814 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011815change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011817 int opt_idx;
11818
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819 if (p_cp != on)
11820 {
11821 p_cp = on;
11822 compatible_set();
11823 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011824 opt_idx = findoption((char_u *)"cp");
11825 if (opt_idx >= 0)
11826 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011827}
11828
11829/*
11830 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011831 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011832 */
11833 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011834option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011835{
11836 int idx;
11837
11838 idx = findoption(name);
11839 if (idx < 0) /* unknown option */
11840 return FALSE;
11841 if (options[idx].flags & P_WAS_SET)
11842 return TRUE;
11843 return FALSE;
11844}
11845
11846/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011847 * Reset the flag indicating option "name" was set.
11848 */
11849 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011850reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011851{
11852 int idx = findoption(name);
11853
11854 if (idx >= 0)
11855 options[idx].flags &= ~P_WAS_SET;
11856}
11857
11858/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011859 * compatible_set() - Called when 'compatible' has been set or unset.
11860 *
11861 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11862 * flag) to a Vi compatible value.
11863 * When 'compatible' is unset: Set all options that have a different default
11864 * for Vim (without the P_VI_DEF flag) to that default.
11865 */
11866 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011867compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868{
11869 int opt_idx;
11870
11871 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11872 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11873 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11874 set_option_default(opt_idx, OPT_FREE, p_cp);
11875 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011876 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877}
11878
11879#ifdef FEAT_LINEBREAK
11880
11881# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11882 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011883 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011884# endif
11885
11886/*
11887 * fill_breakat_flags() -- called when 'breakat' changes value.
11888 */
11889 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011890fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011891{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011892 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893 int i;
11894
11895 for (i = 0; i < 256; i++)
11896 breakat_flags[i] = FALSE;
11897
11898 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011899 for (p = p_breakat; *p; p++)
11900 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901}
11902
11903# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011904 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011905# endif
11906
11907#endif
11908
11909/*
11910 * Check an option that can be a range of string values.
11911 *
11912 * Return OK for correct value, FAIL otherwise.
11913 * Empty is always OK.
11914 */
11915 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011916check_opt_strings(
11917 char_u *val,
11918 char **values,
11919 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011920{
11921 return opt_strings_flags(val, values, NULL, list);
11922}
11923
11924/*
11925 * Handle an option that can be a range of string values.
11926 * Set a flag in "*flagp" for each string present.
11927 *
11928 * Return OK for correct value, FAIL otherwise.
11929 * Empty is always OK.
11930 */
11931 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011932opt_strings_flags(
11933 char_u *val, /* new value */
11934 char **values, /* array of valid string values */
11935 unsigned *flagp,
11936 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011937{
11938 int i;
11939 int len;
11940 unsigned new_flags = 0;
11941
11942 while (*val)
11943 {
11944 for (i = 0; ; ++i)
11945 {
11946 if (values[i] == NULL) /* val not found in values[] */
11947 return FAIL;
11948
11949 len = (int)STRLEN(values[i]);
11950 if (STRNCMP(values[i], val, len) == 0
11951 && ((list && val[len] == ',') || val[len] == NUL))
11952 {
11953 val += len + (val[len] == ',');
11954 new_flags |= (1 << i);
11955 break; /* check next item in val list */
11956 }
11957 }
11958 }
11959 if (flagp != NULL)
11960 *flagp = new_flags;
11961
11962 return OK;
11963}
11964
11965/*
11966 * Read the 'wildmode' option, fill wim_flags[].
11967 */
11968 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011969check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011970{
11971 char_u new_wim_flags[4];
11972 char_u *p;
11973 int i;
11974 int idx = 0;
11975
11976 for (i = 0; i < 4; ++i)
11977 new_wim_flags[i] = 0;
11978
11979 for (p = p_wim; *p; ++p)
11980 {
11981 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11982 ;
11983 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11984 return FAIL;
11985 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11986 new_wim_flags[idx] |= WIM_LONGEST;
11987 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11988 new_wim_flags[idx] |= WIM_FULL;
11989 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11990 new_wim_flags[idx] |= WIM_LIST;
11991 else
11992 return FAIL;
11993 p += i;
11994 if (*p == NUL)
11995 break;
11996 if (*p == ',')
11997 {
11998 if (idx == 3)
11999 return FAIL;
12000 ++idx;
12001 }
12002 }
12003
12004 /* fill remaining entries with last flag */
12005 while (idx < 3)
12006 {
12007 new_wim_flags[idx + 1] = new_wim_flags[idx];
12008 ++idx;
12009 }
12010
12011 /* only when there are no errors, wim_flags[] is changed */
12012 for (i = 0; i < 4; ++i)
12013 wim_flags[i] = new_wim_flags[i];
12014 return OK;
12015}
12016
12017/*
12018 * Check if backspacing over something is allowed.
12019 */
12020 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012021can_bs(
12022 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023{
12024 switch (*p_bs)
12025 {
12026 case '2': return TRUE;
12027 case '1': return (what != BS_START);
12028 case '0': return FALSE;
12029 }
12030 return vim_strchr(p_bs, what) != NULL;
12031}
12032
12033/*
12034 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12035 * the file must be considered changed when the value is different.
12036 */
12037 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012038save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012039{
12040 buf->b_start_ffc = *buf->b_p_ff;
12041 buf->b_start_eol = buf->b_p_eol;
12042#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012043 buf->b_start_bomb = buf->b_p_bomb;
12044
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045 /* Only use free/alloc when necessary, they take time. */
12046 if (buf->b_start_fenc == NULL
12047 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12048 {
12049 vim_free(buf->b_start_fenc);
12050 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12051 }
12052#endif
12053}
12054
12055/*
12056 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12057 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012058 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12059 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012060 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012061 * When "ignore_empty" is true don't consider a new, empty buffer to be
12062 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012063 */
12064 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012065file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012066{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012067 /* In a buffer that was never loaded the options are not valid. */
12068 if (buf->b_flags & BF_NEVERLOADED)
12069 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012070 if (ignore_empty
12071 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012072 && buf->b_ml.ml_line_count == 1
12073 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12074 return FALSE;
12075 if (buf->b_start_ffc != *buf->b_p_ff)
12076 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012077 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078 return TRUE;
12079#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012080 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12081 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012082 if (buf->b_start_fenc == NULL)
12083 return (*buf->b_p_fenc != NUL);
12084 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12085#else
12086 return FALSE;
12087#endif
12088}
12089
12090/*
12091 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12092 */
12093 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012094check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095{
12096 return check_opt_strings(p, p_ff_values, FALSE);
12097}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012098
12099/*
12100 * Return the effective shiftwidth value for current buffer, using the
12101 * 'tabstop' value when 'shiftwidth' is zero.
12102 */
12103 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012104get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012105{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012106 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012107}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012108
12109/*
12110 * Return the effective softtabstop value for the current buffer, using the
12111 * 'tabstop' value when 'softtabstop' is negative.
12112 */
12113 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012114get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012115{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012116 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012117}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012118
12119/*
12120 * Check matchpairs option for "*initc".
12121 * If there is a match set "*initc" to the matching character and "*findc" to
12122 * the opposite character. Set "*backwards" to the direction.
12123 * When "switchit" is TRUE swap the direction.
12124 */
12125 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012126find_mps_values(
12127 int *initc,
12128 int *findc,
12129 int *backwards,
12130 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012131{
12132 char_u *ptr;
12133
12134 ptr = curbuf->b_p_mps;
12135 while (*ptr != NUL)
12136 {
12137#ifdef FEAT_MBYTE
12138 if (has_mbyte)
12139 {
12140 char_u *prev;
12141
12142 if (mb_ptr2char(ptr) == *initc)
12143 {
12144 if (switchit)
12145 {
12146 *findc = *initc;
12147 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12148 *backwards = TRUE;
12149 }
12150 else
12151 {
12152 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12153 *backwards = FALSE;
12154 }
12155 return;
12156 }
12157 prev = ptr;
12158 ptr += mb_ptr2len(ptr) + 1;
12159 if (mb_ptr2char(ptr) == *initc)
12160 {
12161 if (switchit)
12162 {
12163 *findc = *initc;
12164 *initc = mb_ptr2char(prev);
12165 *backwards = FALSE;
12166 }
12167 else
12168 {
12169 *findc = mb_ptr2char(prev);
12170 *backwards = TRUE;
12171 }
12172 return;
12173 }
12174 ptr += mb_ptr2len(ptr);
12175 }
12176 else
12177#endif
12178 {
12179 if (*ptr == *initc)
12180 {
12181 if (switchit)
12182 {
12183 *backwards = TRUE;
12184 *findc = *initc;
12185 *initc = ptr[2];
12186 }
12187 else
12188 {
12189 *backwards = FALSE;
12190 *findc = ptr[2];
12191 }
12192 return;
12193 }
12194 ptr += 2;
12195 if (*ptr == *initc)
12196 {
12197 if (switchit)
12198 {
12199 *backwards = FALSE;
12200 *findc = *initc;
12201 *initc = ptr[-2];
12202 }
12203 else
12204 {
12205 *backwards = TRUE;
12206 *findc = ptr[-2];
12207 }
12208 return;
12209 }
12210 ++ptr;
12211 }
12212 if (*ptr == ',')
12213 ++ptr;
12214 }
12215}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012216
12217#if defined(FEAT_LINEBREAK) || defined(PROTO)
12218/*
12219 * This is called when 'breakindentopt' is changed and when a window is
12220 * initialized.
12221 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012222 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012223briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012224{
12225 char_u *p;
12226 int bri_shift = 0;
12227 long bri_min = 20;
12228 int bri_sbr = FALSE;
12229
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012230 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012231 while (*p != NUL)
12232 {
12233 if (STRNCMP(p, "shift:", 6) == 0
12234 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12235 {
12236 p += 6;
12237 bri_shift = getdigits(&p);
12238 }
12239 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12240 {
12241 p += 4;
12242 bri_min = getdigits(&p);
12243 }
12244 else if (STRNCMP(p, "sbr", 3) == 0)
12245 {
12246 p += 3;
12247 bri_sbr = TRUE;
12248 }
12249 if (*p != ',' && *p != NUL)
12250 return FAIL;
12251 if (*p == ',')
12252 ++p;
12253 }
12254
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012255 wp->w_p_brishift = bri_shift;
12256 wp->w_p_brimin = bri_min;
12257 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012258
12259 return OK;
12260}
12261#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012262
12263/*
12264 * Get the local or global value of 'backupcopy'.
12265 */
12266 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012267get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012268{
12269 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12270}