blob: ff7973fd40e09161a799c0b5137a4105e33d6975 [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
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002009 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002010#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002011 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002012 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002013 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2014 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2017 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002019 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2021 (char_u *)&p_pvh, PV_NONE,
2022#else
2023 (char_u *)NULL, PV_NONE,
2024#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2027#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2028 (char_u *)VAR_WIN, PV_PVW,
2029#else
2030 (char_u *)NULL, PV_NONE,
2031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002033 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034#ifdef FEAT_PRINTER
2035 (char_u *)&p_pdev, PV_NONE,
2036 {(char_u *)"", (char_u *)0L}
2037#else
2038 (char_u *)NULL, PV_NONE,
2039 {(char_u *)NULL, (char_u *)0L}
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"printencoding", "penc", P_STRING|P_VI_DEF,
2043#ifdef FEAT_POSTSCRIPT
2044 (char_u *)&p_penc, PV_NONE,
2045 {(char_u *)"", (char_u *)0L}
2046#else
2047 (char_u *)NULL, PV_NONE,
2048 {(char_u *)NULL, (char_u *)0L}
2049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2052#ifdef FEAT_POSTSCRIPT
2053 (char_u *)&p_pexpr, PV_NONE,
2054 {(char_u *)"", (char_u *)0L}
2055#else
2056 (char_u *)NULL, PV_NONE,
2057 {(char_u *)NULL, (char_u *)0L}
2058#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002060 {"printfont", "pfn", P_STRING|P_VI_DEF,
2061#ifdef FEAT_PRINTER
2062 (char_u *)&p_pfn, PV_NONE,
2063 {
2064# ifdef MSWIN
2065 (char_u *)"Courier_New:h10",
2066# else
2067 (char_u *)"courier",
2068# endif
2069 (char_u *)0L}
2070#else
2071 (char_u *)NULL, PV_NONE,
2072 {(char_u *)NULL, (char_u *)0L}
2073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2076#ifdef FEAT_PRINTER
2077 (char_u *)&p_header, PV_NONE,
2078 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2079#else
2080 (char_u *)NULL, PV_NONE,
2081 {(char_u *)NULL, (char_u *)0L}
2082#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002084 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2085#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2086 (char_u *)&p_pmcs, PV_NONE,
2087 {(char_u *)"", (char_u *)0L}
2088#else
2089 (char_u *)NULL, PV_NONE,
2090 {(char_u *)NULL, (char_u *)0L}
2091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002092 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002093 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2094#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2095 (char_u *)&p_pmfn, PV_NONE,
2096 {(char_u *)"", (char_u *)0L}
2097#else
2098 (char_u *)NULL, PV_NONE,
2099 {(char_u *)NULL, (char_u *)0L}
2100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002101 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002102 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103#ifdef FEAT_PRINTER
2104 (char_u *)&p_popt, PV_NONE,
2105 {(char_u *)"", (char_u *)0L}
2106#else
2107 (char_u *)NULL, PV_NONE,
2108 {(char_u *)NULL, (char_u *)0L}
2109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002110 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002112 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002114 {"pumheight", "ph", P_NUM|P_VI_DEF,
2115#ifdef FEAT_INS_EXPAND
2116 (char_u *)&p_ph, PV_NONE,
2117#else
2118 (char_u *)NULL, PV_NONE,
2119#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002121#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002122 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002123 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002124 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2125 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002126#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002127#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002128 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002129 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002130 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2131 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002132#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002133 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2134#ifdef FEAT_TEXTOBJ
2135 (char_u *)&p_qe, PV_QE,
2136 {(char_u *)"\\", (char_u *)0L}
2137#else
2138 (char_u *)NULL, PV_NONE,
2139 {(char_u *)NULL, (char_u *)0L}
2140#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002141 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2143 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"redraw", NULL, P_BOOL|P_VI_DEF,
2146 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002147 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002148 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2149#ifdef FEAT_RELTIME
2150 (char_u *)&p_rdt, PV_NONE,
2151#else
2152 (char_u *)NULL, PV_NONE,
2153#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002155 {"regexpengine", "re", P_NUM|P_VI_DEF,
2156 (char_u *)&p_re, PV_NONE,
2157 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002158 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2159 (char_u *)VAR_WIN, PV_RNU,
2160 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"remap", NULL, P_BOOL|P_VI_DEF,
2162 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002163 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002164 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002165#ifdef FEAT_RENDER_OPTIONS
2166 (char_u *)&p_rop, PV_NONE,
2167 {(char_u *)"", (char_u *)0L}
2168#else
2169 (char_u *)NULL, PV_NONE,
2170 {(char_u *)NULL, (char_u *)0L}
2171#endif
2172 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 {"report", NULL, P_NUM|P_VI_DEF,
2174 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002175 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2177#ifdef WIN3264
2178 (char_u *)&p_rs, PV_NONE,
2179#else
2180 (char_u *)NULL, PV_NONE,
2181#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002182 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2184#ifdef FEAT_RIGHTLEFT
2185 (char_u *)&p_ri, PV_NONE,
2186#else
2187 (char_u *)NULL, PV_NONE,
2188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002189 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2191#ifdef FEAT_RIGHTLEFT
2192 (char_u *)VAR_WIN, PV_RL,
2193#else
2194 (char_u *)NULL, PV_NONE,
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2198#ifdef FEAT_RIGHTLEFT
2199 (char_u *)VAR_WIN, PV_RLC,
2200 {(char_u *)"search", (char_u *)NULL}
2201#else
2202 (char_u *)NULL, PV_NONE,
2203 {(char_u *)NULL, (char_u *)0L}
2204#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002205 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002206#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002207 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002208 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002209 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2210 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002211#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2213#ifdef FEAT_CMDL_INFO
2214 (char_u *)&p_ru, PV_NONE,
2215#else
2216 (char_u *)NULL, PV_NONE,
2217#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002218 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2220#ifdef FEAT_STL_OPT
2221 (char_u *)&p_ruf, PV_NONE,
2222#else
2223 (char_u *)NULL, PV_NONE,
2224#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002226 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2227 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002228 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2230 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2232 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2235#ifdef FEAT_SCROLLBIND
2236 (char_u *)VAR_WIN, PV_SCBIND,
2237#else
2238 (char_u *)NULL, PV_NONE,
2239#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002240 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2242 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2245 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002247 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002248#ifdef FEAT_SCROLLBIND
2249 (char_u *)&p_sbo, PV_NONE,
2250 {(char_u *)"ver,jump", (char_u *)0L}
2251#else
2252 (char_u *)NULL, PV_NONE,
2253 {(char_u *)0L, (char_u *)0L}
2254#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002256 {"sections", "sect", P_STRING|P_VI_DEF,
2257 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002258 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2259 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2261 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002262 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002264 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 {(char_u *)"inclusive", (char_u *)0L}
2266 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002267 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002269 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002270 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271#ifdef FEAT_SESSION
2272 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002273 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 (char_u *)0L}
2275#else
2276 (char_u *)NULL, PV_NONE,
2277 {(char_u *)0L, (char_u *)0L}
2278#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2281 (char_u *)&p_sh, PV_NONE,
2282 {
2283#ifdef VMS
2284 (char_u *)"-",
2285#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002286# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002288# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290# endif
2291#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2294 (char_u *)&p_shcf, PV_NONE,
2295 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002296#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 (char_u *)"/c",
2298#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2303#ifdef FEAT_QUICKFIX
2304 (char_u *)&p_sp, PV_NONE,
2305 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002306#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308#else
2309 (char_u *)">",
2310#endif
2311 (char_u *)0L}
2312#else
2313 (char_u *)NULL, PV_NONE,
2314 {(char_u *)0L, (char_u *)0L}
2315#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2318 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2321 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2324#ifdef BACKSLASH_IN_FILENAME
2325 (char_u *)&p_ssl, PV_NONE,
2326#else
2327 (char_u *)NULL, PV_NONE,
2328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002330 {"shelltemp", "stmp", P_BOOL,
2331 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"shelltype", "st", P_NUM|P_VI_DEF,
2334#ifdef AMIGA
2335 (char_u *)&p_st, PV_NONE,
2336#else
2337 (char_u *)NULL, PV_NONE,
2338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2341 (char_u *)&p_sxq, PV_NONE,
2342 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002343#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 (char_u *)"\"",
2345#else
2346 (char_u *)"",
2347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002349 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2350 (char_u *)&p_sxe, PV_NONE,
2351 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002352#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002353 (char_u *)"\"&|<>()@^",
2354#else
2355 (char_u *)"",
2356#endif
2357 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2359 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002360 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2362 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2365 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)"", (char_u *)"filnxtToO"}
2367 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2372#ifdef FEAT_LINEBREAK
2373 (char_u *)&p_sbr, PV_NONE,
2374#else
2375 (char_u *)NULL, PV_NONE,
2376#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"showcmd", "sc", P_BOOL|P_VIM,
2379#ifdef FEAT_CMDL_INFO
2380 (char_u *)&p_sc, PV_NONE,
2381#else
2382 (char_u *)NULL, PV_NONE,
2383#endif
2384 {(char_u *)FALSE,
2385#ifdef UNIX
2386 (char_u *)FALSE
2387#else
2388 (char_u *)TRUE
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2392 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2395 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"showmode", "smd", P_BOOL|P_VIM,
2398 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002400 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2401#ifdef FEAT_WINDOWS
2402 (char_u *)&p_stal, PV_NONE,
2403#else
2404 (char_u *)NULL, PV_NONE,
2405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2408 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2411 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2414 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2417 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2420#ifdef FEAT_SMARTINDENT
2421 (char_u *)&p_si, PV_SI,
2422#else
2423 (char_u *)NULL, PV_NONE,
2424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2427 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2430 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2433 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002435 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002436#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002437 (char_u *)VAR_WIN, PV_SPELL,
2438#else
2439 (char_u *)NULL, PV_NONE,
2440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002442 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002443#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002444 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002445 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002446#else
2447 (char_u *)NULL, PV_NONE,
2448 {(char_u *)0L, (char_u *)0L}
2449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002451 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2452 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002453#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002454 (char_u *)&p_spf, PV_SPF,
2455 {(char_u *)"", (char_u *)0L}
2456#else
2457 (char_u *)NULL, PV_NONE,
2458 {(char_u *)0L, (char_u *)0L}
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002461 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2462 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002463#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002464 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002465 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002466#else
2467 (char_u *)NULL, PV_NONE,
2468 {(char_u *)0L, (char_u *)0L}
2469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002471 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002472#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002473 (char_u *)&p_sps, PV_NONE,
2474 {(char_u *)"best", (char_u *)0L}
2475#else
2476 (char_u *)NULL, PV_NONE,
2477 {(char_u *)0L, (char_u *)0L}
2478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002479 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2481#ifdef FEAT_WINDOWS
2482 (char_u *)&p_sb, PV_NONE,
2483#else
2484 (char_u *)NULL, PV_NONE,
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002488#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 (char_u *)&p_spr, PV_NONE,
2490#else
2491 (char_u *)NULL, PV_NONE,
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2495 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2498#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002499 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500#else
2501 (char_u *)NULL, PV_NONE,
2502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002504 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 (char_u *)&p_su, PV_NONE,
2506 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002508 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002509#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 (char_u *)&p_sua, PV_SUA,
2511 {(char_u *)"", (char_u *)0L}
2512#else
2513 (char_u *)NULL, PV_NONE,
2514 {(char_u *)0L, (char_u *)0L}
2515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002516 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2518 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"swapsync", "sws", P_STRING|P_VI_DEF,
2521 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002523 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002526 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2527#ifdef FEAT_SYN_HL
2528 (char_u *)&p_smc, PV_SMC,
2529 {(char_u *)3000L, (char_u *)0L}
2530#else
2531 (char_u *)NULL, PV_NONE,
2532 {(char_u *)0L, (char_u *)0L}
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002535 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536#ifdef FEAT_SYN_HL
2537 (char_u *)&p_syn, PV_SYN,
2538 {(char_u *)"", (char_u *)0L}
2539#else
2540 (char_u *)NULL, PV_NONE,
2541 {(char_u *)0L, (char_u *)0L}
2542#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002544 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2545#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002546 (char_u *)&p_tal, PV_NONE,
2547#else
2548 (char_u *)NULL, PV_NONE,
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002551 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2552#ifdef FEAT_WINDOWS
2553 (char_u *)&p_tpm, PV_NONE,
2554#else
2555 (char_u *)NULL, PV_NONE,
2556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2559 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2562 (char_u *)&p_tbs, PV_NONE,
2563#ifdef VMS /* binary searching doesn't appear to work on VMS */
2564 {(char_u *)0L, (char_u *)0L}
2565#else
2566 {(char_u *)TRUE, (char_u *)0L}
2567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002569 {"tagcase", "tc", P_STRING|P_VIM,
2570 (char_u *)&p_tc, PV_TC,
2571 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"taglength", "tl", P_NUM|P_VI_DEF,
2573 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"tagrelative", "tr", P_BOOL|P_VIM,
2576 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002578 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002579 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {
2581#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2582 (char_u *)"./tags,./TAGS,tags,TAGS",
2583#else
2584 (char_u *)"./tags,tags",
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2588 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002590#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002591 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002592 (char_u *)&p_tcldll, PV_NONE,
2593 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2594 SCRIPTID_INIT},
2595#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2597 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2600#ifdef FEAT_ARABIC
2601 (char_u *)&p_tbidi, PV_NONE,
2602#else
2603 (char_u *)NULL, PV_NONE,
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2607#ifdef FEAT_MBYTE
2608 (char_u *)&p_tenc, PV_NONE,
2609 {(char_u *)"", (char_u *)0L}
2610#else
2611 (char_u *)NULL, PV_NONE,
2612 {(char_u *)0L, (char_u *)0L}
2613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002615 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2616#ifdef FEAT_TERMGUICOLORS
2617 (char_u *)&p_tgc, PV_NONE,
2618 {(char_u *)FALSE, (char_u *)FALSE}
2619#else
2620 (char_u*)NULL, PV_NONE,
2621 {(char_u *)FALSE, (char_u *)FALSE}
2622#endif
2623 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"terse", NULL, P_BOOL|P_VI_DEF,
2625 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 {"textauto", "ta", P_BOOL|P_VIM,
2628 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2630 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2632 (char_u *)&p_tx, PV_TX,
2633 {
2634#ifdef USE_CRNL
2635 (char_u *)TRUE,
2636#else
2637 (char_u *)FALSE,
2638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002640 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002643 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002645 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646#else
2647 (char_u *)NULL, PV_NONE,
2648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2651 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {"timeout", "to", P_BOOL|P_VI_DEF,
2654 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2657 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 {"title", NULL, P_BOOL|P_VI_DEF,
2660#ifdef FEAT_TITLE
2661 (char_u *)&p_title, PV_NONE,
2662#else
2663 (char_u *)NULL, PV_NONE,
2664#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666 {"titlelen", NULL, P_NUM|P_VI_DEF,
2667#ifdef FEAT_TITLE
2668 (char_u *)&p_titlelen, PV_NONE,
2669#else
2670 (char_u *)NULL, PV_NONE,
2671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002673 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674#ifdef FEAT_TITLE
2675 (char_u *)&p_titleold, PV_NONE,
2676 {(char_u *)N_("Thanks for flying Vim"),
2677 (char_u *)0L}
2678#else
2679 (char_u *)NULL, PV_NONE,
2680 {(char_u *)0L, (char_u *)0L}
2681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 {"titlestring", NULL, P_STRING|P_VI_DEF,
2684#ifdef FEAT_TITLE
2685 (char_u *)&p_titlestring, PV_NONE,
2686#else
2687 (char_u *)NULL, PV_NONE,
2688#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002689 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002691 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002693 {(char_u *)"icons,tooltips", (char_u *)0L}
2694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002696#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2698 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700#endif
2701 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2702 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2705 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2708 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002709 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2711 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2714#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2715 (char_u *)&p_ttym, PV_NONE,
2716#else
2717 (char_u *)NULL, PV_NONE,
2718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2721 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2724 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002725 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002726 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2727 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002728#ifdef FEAT_PERSISTENT_UNDO
2729 (char_u *)&p_udir, PV_NONE,
2730 {(char_u *)".", (char_u *)0L}
2731#else
2732 (char_u *)NULL, PV_NONE,
2733 {(char_u *)0L, (char_u *)0L}
2734#endif
2735 SCRIPTID_INIT},
2736 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2737#ifdef FEAT_PERSISTENT_UNDO
2738 (char_u *)&p_udf, PV_UDF,
2739#else
2740 (char_u *)NULL, PV_NONE,
2741#endif
2742 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002744 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002746#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 (char_u *)1000L,
2748#else
2749 (char_u *)100L,
2750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002751 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002752 {"undoreload", "ur", P_NUM|P_VI_DEF,
2753 (char_u *)&p_ur, PV_NONE,
2754 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {"updatecount", "uc", P_NUM|P_VI_DEF,
2756 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002757 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 {"updatetime", "ut", P_NUM|P_VI_DEF,
2759 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002760 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 {"verbose", "vbs", P_NUM|P_VI_DEF,
2762 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002763 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002764 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2765 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2768#ifdef FEAT_SESSION
2769 (char_u *)&p_vdir, PV_NONE,
2770 {(char_u *)DFLT_VDIR, (char_u *)0L}
2771#else
2772 (char_u *)NULL, PV_NONE,
2773 {(char_u *)0L, (char_u *)0L}
2774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002776 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777#ifdef FEAT_SESSION
2778 (char_u *)&p_vop, PV_NONE,
2779 {(char_u *)"folds,options,cursor", (char_u *)0L}
2780#else
2781 (char_u *)NULL, PV_NONE,
2782 {(char_u *)0L, (char_u *)0L}
2783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002785 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786#ifdef FEAT_VIMINFO
2787 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002788#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002789 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790#else
2791# ifdef AMIGA
2792 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002793 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002795 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796# endif
2797#endif
2798#else
2799 (char_u *)NULL, PV_NONE,
2800 {(char_u *)0L, (char_u *)0L}
2801#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002803 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2804 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805#ifdef FEAT_VIRTUALEDIT
2806 (char_u *)&p_ve, PV_NONE,
2807 {(char_u *)"", (char_u *)""}
2808#else
2809 (char_u *)NULL, PV_NONE,
2810 {(char_u *)0L, (char_u *)0L}
2811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2814 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 {"w300", NULL, P_NUM|P_VI_DEF,
2817 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 {"w1200", NULL, P_NUM|P_VI_DEF,
2820 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"w9600", NULL, P_NUM|P_VI_DEF,
2823 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 {"warn", NULL, P_BOOL|P_VI_DEF,
2826 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002827 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2829 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002830 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002831 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"wildchar", "wc", P_NUM|P_VIM,
2835 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2837 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002838 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002841 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842#ifdef FEAT_WILDIGN
2843 (char_u *)&p_wig, PV_NONE,
2844#else
2845 (char_u *)NULL, PV_NONE,
2846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002847 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002848 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2849 (char_u *)&p_wic, PV_NONE,
2850 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2852#ifdef FEAT_WILDMENU
2853 (char_u *)&p_wmnu, PV_NONE,
2854#else
2855 (char_u *)NULL, PV_NONE,
2856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002858 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002861 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2862#ifdef FEAT_CMDL_COMPL
2863 (char_u *)&p_wop, PV_NONE,
2864 {(char_u *)"", (char_u *)0L}
2865#else
2866 (char_u *)NULL, PV_NONE,
2867 {(char_u *)NULL, (char_u *)0L}
2868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2871#ifdef FEAT_WAK
2872 (char_u *)&p_wak, PV_NONE,
2873 {(char_u *)"menu", (char_u *)0L}
2874#else
2875 (char_u *)NULL, PV_NONE,
2876 {(char_u *)NULL, (char_u *)0L}
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002880 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"winheight", "wh", P_NUM|P_VI_DEF,
2883#ifdef FEAT_WINDOWS
2884 (char_u *)&p_wh, PV_NONE,
2885#else
2886 (char_u *)NULL, PV_NONE,
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002890#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 (char_u *)VAR_WIN, PV_WFH,
2892#else
2893 (char_u *)NULL, PV_NONE,
2894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002895 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002896 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002897#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002898 (char_u *)VAR_WIN, PV_WFW,
2899#else
2900 (char_u *)NULL, PV_NONE,
2901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002902 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2904#ifdef FEAT_WINDOWS
2905 (char_u *)&p_wmh, PV_NONE,
2906#else
2907 (char_u *)NULL, PV_NONE,
2908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002911#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 (char_u *)&p_wmw, PV_NONE,
2913#else
2914 (char_u *)NULL, PV_NONE,
2915#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002918#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 (char_u *)&p_wiw, PV_NONE,
2920#else
2921 (char_u *)NULL, PV_NONE,
2922#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002923 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2925 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2928 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2931 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002932 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933 {"write", NULL, P_BOOL|P_VI_DEF,
2934 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 {"writeany", "wa", P_BOOL|P_VI_DEF,
2937 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2940 (char_u *)&p_wb, PV_NONE,
2941 {
2942#ifdef FEAT_WRITEBACKUP
2943 (char_u *)TRUE,
2944#else
2945 (char_u *)FALSE,
2946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 {"writedelay", "wd", P_NUM|P_VI_DEF,
2949 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951
2952/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002953#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002955 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956
2957 p_term("t_AB", T_CAB)
2958 p_term("t_AF", T_CAF)
2959 p_term("t_AL", T_CAL)
2960 p_term("t_al", T_AL)
2961 p_term("t_bc", T_BC)
2962 p_term("t_cd", T_CD)
2963 p_term("t_ce", T_CE)
2964 p_term("t_cl", T_CL)
2965 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002966 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 p_term("t_Co", T_CCO)
2968 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002969 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002971#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 p_term("t_CV", T_CSV)
2973#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 p_term("t_da", T_DA)
2975 p_term("t_db", T_DB)
2976 p_term("t_DL", T_CDL)
2977 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002978 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 p_term("t_fs", T_FS)
2980 p_term("t_IE", T_CIE)
2981 p_term("t_IS", T_CIS)
2982 p_term("t_ke", T_KE)
2983 p_term("t_ks", T_KS)
2984 p_term("t_le", T_LE)
2985 p_term("t_mb", T_MB)
2986 p_term("t_md", T_MD)
2987 p_term("t_me", T_ME)
2988 p_term("t_mr", T_MR)
2989 p_term("t_ms", T_MS)
2990 p_term("t_nd", T_ND)
2991 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002992 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 p_term("t_RI", T_CRI)
2994 p_term("t_RV", T_CRV)
2995 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002997 p_term("t_Sf", T_CSF)
2998 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003000 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 p_term("t_te", T_TE)
3003 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003004 p_term("t_ts", T_TS)
3005 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 p_term("t_ue", T_UE)
3007 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003008 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 p_term("t_vb", T_VB)
3010 p_term("t_ve", T_VE)
3011 p_term("t_vi", T_VI)
3012 p_term("t_vs", T_VS)
3013 p_term("t_WP", T_CWP)
3014 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003015 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 p_term("t_xs", T_XS)
3017 p_term("t_ZH", T_CZH)
3018 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003019 p_term("t_8f", T_8F)
3020 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021
3022/* terminal key codes are not in here */
3023
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 /* end marker */
3025 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026};
3027
3028#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3029
3030#ifdef FEAT_MBYTE
3031static char *(p_ambw_values[]) = {"single", "double", NULL};
3032#endif
3033static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003034static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003036#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003037static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003038#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003039#ifdef FEAT_CMDL_COMPL
3040static char *(p_wop_values[]) = {"tagfile", NULL};
3041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042#ifdef FEAT_WAK
3043static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3044#endif
3045static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3047static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049#ifdef FEAT_BROWSE
3050static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3051#endif
3052#ifdef FEAT_SCROLLBIND
3053static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3054#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003055static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003056#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3058#endif
3059#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003060# ifdef FEAT_AUTOCMD
3061static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3062# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003064# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3066#endif
3067static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3068#ifdef FEAT_FOLDING
3069static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003070# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 NULL};
3074static char *(p_fcl_values[]) = {"all", NULL};
3075#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003076#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003077static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003080static void set_option_default(int, int opt_flags, int compatible);
3081static void set_options_default(int opt_flags);
3082static char_u *term_bg_default(void);
3083static void did_set_option(int opt_idx, int opt_flags, int new_value);
3084static char_u *illegal_char(char_u *, int);
3085static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003087static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088#endif
3089#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003090static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003092static char_u *option_expand(int opt_idx, char_u *val);
3093static void didset_options(void);
3094static void didset_options2(void);
3095static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003096#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003097static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003098#else
3099# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3100#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003101static void set_string_option_global(int opt_idx, char_u **varp);
3102static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3103static 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);
3104static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003105#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003106static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003107#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003109static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003111#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003112static char_u *did_set_spell_option(int is_spellfile);
3113static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003114#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003115#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003116static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003117#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003118static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3119static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3120static void check_redraw(long_u flags);
3121static int findoption(char_u *);
3122static int find_key_option(char_u *);
3123static void showoptions(int all, int opt_flags);
3124static int optval_default(struct vimoption *, char_u *varp);
3125static void showoneopt(struct vimoption *, int opt_flags);
3126static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3127static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3128static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3129static int istermoption(struct vimoption *);
3130static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3131static char_u *get_varp(struct vimoption *);
3132static void option_value2string(struct vimoption *, int opt_flags);
3133static void check_winopt(winopt_T *wop);
3134static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003136static void langmap_init(void);
3137static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003139static void paste_option_changed(void);
3140static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003142static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003144static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3145static int check_opt_strings(char_u *val, char **values, int);
3146static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003147#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003148static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003149#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150
3151/*
3152 * Initialize the options, first part.
3153 *
3154 * Called only once from main(), just after creating the first buffer.
3155 */
3156 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003157set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158{
3159 char_u *p;
3160 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003161 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162
3163#ifdef FEAT_LANGMAP
3164 langmap_init();
3165#endif
3166
3167 /* Be Vi compatible by default */
3168 p_cp = TRUE;
3169
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003170 /* Use POSIX compatibility when $VIM_POSIX is set. */
3171 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003172 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003173 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003174 set_string_default("shm", (char_u *)"A");
3175 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003176
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 /*
3178 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003179 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003181 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003182#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003183 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003185 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186# endif
3187#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003188 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 set_string_default("sh", p);
3190
3191#ifdef FEAT_WILDIGN
3192 /*
3193 * Set the default for 'backupskip' to include environment variables for
3194 * temp files.
3195 */
3196 {
3197# ifdef UNIX
3198 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3199# else
3200 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3201# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003202 int len;
3203 garray_T ga;
3204 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205
3206 ga_init2(&ga, 1, 100);
3207 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3208 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003209 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210# ifdef UNIX
3211 if (*names[n] == NUL)
3212 p = (char_u *)"/tmp";
3213 else
3214# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003215 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 if (p != NULL && *p != NUL)
3217 {
3218 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003219 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220 if (ga_grow(&ga, len) == OK)
3221 {
3222 if (ga.ga_len > 0)
3223 STRCAT(ga.ga_data, ",");
3224 STRCAT(ga.ga_data, p);
3225 add_pathsep(ga.ga_data);
3226 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 ga.ga_len += len;
3228 }
3229 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003230 if (mustfree)
3231 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232 }
3233 if (ga.ga_data != NULL)
3234 {
3235 set_string_default("bsk", ga.ga_data);
3236 vim_free(ga.ga_data);
3237 }
3238 }
3239#endif
3240
3241 /*
3242 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3243 */
3244 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003245 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003247#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3248 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3249#endif
3250 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003252 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003253 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254#else
3255# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003256 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003257 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260# endif
3261#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003263 opt_idx = findoption((char_u *)"maxmem");
3264 if (opt_idx >= 0)
3265 {
3266#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003267 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3268 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003269#endif
3270 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3271 }
3272 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273 }
3274
3275#ifdef FEAT_GUI_W32
3276 /* force 'shortname' for Win32s */
3277 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003278 {
3279 opt_idx = findoption((char_u *)"shortname");
3280 if (opt_idx >= 0)
3281 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3282 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283#endif
3284
3285#ifdef FEAT_SEARCHPATH
3286 {
3287 char_u *cdpath;
3288 char_u *buf;
3289 int i;
3290 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003291 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292
3293 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003294 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295 if (cdpath != NULL)
3296 {
3297 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3298 if (buf != NULL)
3299 {
3300 buf[0] = ','; /* start with ",", current dir first */
3301 j = 1;
3302 for (i = 0; cdpath[i] != NUL; ++i)
3303 {
3304 if (vim_ispathlistsep(cdpath[i]))
3305 buf[j++] = ',';
3306 else
3307 {
3308 if (cdpath[i] == ' ' || cdpath[i] == ',')
3309 buf[j++] = '\\';
3310 buf[j++] = cdpath[i];
3311 }
3312 }
3313 buf[j] = NUL;
3314 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003315 if (opt_idx >= 0)
3316 {
3317 options[opt_idx].def_val[VI_DEFAULT] = buf;
3318 options[opt_idx].flags |= P_DEF_ALLOCED;
3319 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003320 else
3321 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003323 if (mustfree)
3324 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325 }
3326 }
3327#endif
3328
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003329#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330 /* Set print encoding on platforms that don't default to latin1 */
3331 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003332# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 (char_u *)"cp1252"
3334# else
3335# ifdef VMS
3336 (char_u *)"dec-mcs"
3337# else
3338# ifdef EBCDIC
3339 (char_u *)"ebcdic-uk"
3340# else
3341# ifdef MAC
3342 (char_u *)"mac-roman"
3343# else /* HPUX */
3344 (char_u *)"hp-roman8"
3345# endif
3346# endif
3347# endif
3348# endif
3349 );
3350#endif
3351
3352#ifdef FEAT_POSTSCRIPT
3353 /* 'printexpr' must be allocated to be able to evaluate it. */
3354 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003355# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003356 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357# else
3358# ifdef VMS
3359 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3360
3361# else
3362 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3363# endif
3364# endif
3365 );
3366#endif
3367
3368 /*
3369 * Set all the options (except the terminal options) to their default
3370 * value. Also set the global value for local options.
3371 */
3372 set_options_default(0);
3373
3374#ifdef FEAT_GUI
3375 if (found_reverse_arg)
3376 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3377#endif
3378
3379 curbuf->b_p_initialized = TRUE;
3380 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003381 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382 check_buf_options(curbuf);
3383 check_win_options(curwin);
3384 check_options();
3385
3386 /* Must be before option_expand(), because that one needs vim_isIDc() */
3387 didset_options();
3388
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003389#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003390 /* Use the current chartab for the generic chartab. This is not in
3391 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003392 init_spell_chartab();
3393#endif
3394
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 /*
3396 * Expand environment variables and things like "~" for the defaults.
3397 * If option_expand() returns non-NULL the variable is expanded. This can
3398 * only happen for non-indirect options.
3399 * Also set the default to the expanded value, so ":set" does not list
3400 * them.
3401 * Don't set the P_ALLOCED flag, because we don't want to free the
3402 * default.
3403 */
3404 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3405 {
3406 if ((options[opt_idx].flags & P_GETTEXT)
3407 && options[opt_idx].var != NULL)
3408 p = (char_u *)_(*(char **)options[opt_idx].var);
3409 else
3410 p = option_expand(opt_idx, NULL);
3411 if (p != NULL && (p = vim_strsave(p)) != NULL)
3412 {
3413 *(char_u **)options[opt_idx].var = p;
3414 /* VIMEXP
3415 * Defaults for all expanded options are currently the same for Vi
3416 * and Vim. When this changes, add some code here! Also need to
3417 * split P_DEF_ALLOCED in two.
3418 */
3419 if (options[opt_idx].flags & P_DEF_ALLOCED)
3420 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3421 options[opt_idx].def_val[VI_DEFAULT] = p;
3422 options[opt_idx].flags |= P_DEF_ALLOCED;
3423 }
3424 }
3425
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426 save_file_ff(curbuf); /* Buffer is unchanged */
3427
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428#if defined(FEAT_ARABIC)
3429 /* Detect use of mlterm.
3430 * Mlterm is a terminal emulator akin to xterm that has some special
3431 * abilities (bidi namely).
3432 * NOTE: mlterm's author is being asked to 'set' a variable
3433 * instead of an environment variable due to inheritance.
3434 */
3435 if (mch_getenv((char_u *)"MLTERM") != NULL)
3436 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3437#endif
3438
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003439 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440
3441#ifdef FEAT_MBYTE
3442# if defined(WIN3264) && defined(FEAT_GETTEXT)
3443 /*
3444 * If $LANG isn't set, try to get a good value for it. This makes the
3445 * right language be used automatically. Don't do this for English.
3446 */
3447 if (mch_getenv((char_u *)"LANG") == NULL)
3448 {
3449 char buf[20];
3450
3451 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3452 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3453 * only the first two. */
3454 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3455 (LPTSTR)buf, 20);
3456 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3457 {
3458 /* There are a few exceptions (probably more) */
3459 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3460 STRCPY(buf, "zh_TW");
3461 else if (STRNICMP(buf, "chs", 3) == 0
3462 || STRNICMP(buf, "zhc", 3) == 0)
3463 STRCPY(buf, "zh_CN");
3464 else if (STRNICMP(buf, "jp", 2) == 0)
3465 STRCPY(buf, "ja");
3466 else
3467 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003468 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 }
3470 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003471# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003472# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003473 /* Moved to os_mac_conv.c to avoid dependency problems. */
3474 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003475# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476# endif
3477
3478 /* enc_locale() will try to find the encoding of the current locale. */
3479 p = enc_locale();
3480 if (p != NULL)
3481 {
3482 char_u *save_enc;
3483
3484 /* Try setting 'encoding' and check if the value is valid.
3485 * If not, go back to the default "latin1". */
3486 save_enc = p_enc;
3487 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003488 if (STRCMP(p_enc, "gb18030") == 0)
3489 {
3490 /* We don't support "gb18030", but "cp936" is a good substitute
3491 * for practical purposes, thus use that. It's not an alias to
3492 * still support conversion between gb18030 and utf-8. */
3493 p_enc = vim_strsave((char_u *)"cp936");
3494 vim_free(p);
3495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496 if (mb_init() == NULL)
3497 {
3498 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003499 if (opt_idx >= 0)
3500 {
3501 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3502 options[opt_idx].flags |= P_DEF_ALLOCED;
3503 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003505#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003506 if (STRCMP(p_enc, "latin1") == 0
3507# ifdef FEAT_MBYTE
3508 || enc_utf8
3509# endif
3510 )
3511 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003512 /* Adjust the default for 'isprint' and 'iskeyword' to match
3513 * latin1. Also set the defaults for when 'nocompatible' is
3514 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003515 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003516 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003517 set_string_option_direct((char_u *)"isk", -1,
3518 ISK_LATIN1, OPT_FREE, SID_NONE);
3519 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003520 if (opt_idx >= 0)
3521 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003522 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003523 if (opt_idx >= 0)
3524 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003525 (void)init_chartab();
3526 }
3527#endif
3528
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529# if defined(WIN3264) && !defined(FEAT_GUI)
3530 /* Win32 console: When GetACP() returns a different value from
3531 * GetConsoleCP() set 'termencoding'. */
3532 if (GetACP() != GetConsoleCP())
3533 {
3534 char buf[50];
3535
3536 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3537 p_tenc = vim_strsave((char_u *)buf);
3538 if (p_tenc != NULL)
3539 {
3540 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003541 if (opt_idx >= 0)
3542 {
3543 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3544 options[opt_idx].flags |= P_DEF_ALLOCED;
3545 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003546 convert_setup(&input_conv, p_tenc, p_enc);
3547 convert_setup(&output_conv, p_enc, p_tenc);
3548 }
3549 else
3550 p_tenc = empty_option;
3551 }
3552# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003553# if defined(WIN3264) && defined(FEAT_MBYTE)
3554 /* $HOME may have characters in active code page. */
3555 init_homedir();
3556# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557 }
3558 else
3559 {
3560 vim_free(p_enc);
3561 p_enc = save_enc;
3562 }
3563 }
3564#endif
3565
3566#ifdef FEAT_MULTI_LANG
3567 /* Set the default for 'helplang'. */
3568 set_helplang_default(get_mess_lang());
3569#endif
3570}
3571
3572/*
3573 * Set an option to its default value.
3574 * This does not take care of side effects!
3575 */
3576 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003577set_option_default(
3578 int opt_idx,
3579 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3580 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003581{
3582 char_u *varp; /* pointer to variable for current option */
3583 int dvi; /* index in def_val[] */
3584 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003585 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3587
3588 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3589 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003590 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003591 {
3592 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3593 if (flags & P_STRING)
3594 {
3595 /* Use set_string_option_direct() for local options to handle
3596 * freeing and allocating the value. */
3597 if (options[opt_idx].indir != PV_NONE)
3598 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003599 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003600 else
3601 {
3602 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3603 free_string_option(*(char_u **)(varp));
3604 *(char_u **)varp = options[opt_idx].def_val[dvi];
3605 options[opt_idx].flags &= ~P_ALLOCED;
3606 }
3607 }
3608 else if (flags & P_NUM)
3609 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003610 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611 win_comp_scroll(curwin);
3612 else
3613 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003614 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615 /* May also set global value for local option. */
3616 if (both)
3617 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3618 *(long *)varp;
3619 }
3620 }
3621 else /* P_BOOL */
3622 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003623 /* the cast to long is required for Manx C, long_i is needed for
3624 * MSVC */
3625 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003626#ifdef UNIX
3627 /* 'modeline' defaults to off for root */
3628 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3629 *(int *)varp = FALSE;
3630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631 /* May also set global value for local option. */
3632 if (both)
3633 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3634 *(int *)varp;
3635 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003636
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003637 /* The default value is not insecure. */
3638 flagsp = insecure_flag(opt_idx, opt_flags);
3639 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640 }
3641
3642#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003643 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644#endif
3645}
3646
3647/*
3648 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003649 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650 */
3651 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003652set_options_default(
3653 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654{
3655 int i;
3656#ifdef FEAT_WINDOWS
3657 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003658 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003659#endif
3660
3661 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003662 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003663#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003664 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003665 || (TRUE
3666# if defined(FEAT_MBYTE)
3667 && options[i].var != (char_u *)&p_enc
3668# endif
3669# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003670 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003671 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003672# endif
3673 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003674#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003675 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676 set_option_default(i, opt_flags, p_cp);
3677
3678#ifdef FEAT_WINDOWS
3679 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003680 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681 win_comp_scroll(wp);
3682#else
3683 win_comp_scroll(curwin);
3684#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003685#ifdef FEAT_CINDENT
3686 parse_cino(curbuf);
3687#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688}
3689
3690/*
3691 * Set the Vi-default value of a string option.
3692 * Used for 'sh', 'backupskip' and 'term'.
3693 */
3694 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003695set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696{
3697 char_u *p;
3698 int opt_idx;
3699
3700 p = vim_strsave(val);
3701 if (p != NULL) /* we don't want a NULL */
3702 {
3703 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003704 if (opt_idx >= 0)
3705 {
3706 if (options[opt_idx].flags & P_DEF_ALLOCED)
3707 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3708 options[opt_idx].def_val[VI_DEFAULT] = p;
3709 options[opt_idx].flags |= P_DEF_ALLOCED;
3710 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711 }
3712}
3713
3714/*
3715 * Set the Vi-default value of a number option.
3716 * Used for 'lines' and 'columns'.
3717 */
3718 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003719set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003721 int opt_idx;
3722
3723 opt_idx = findoption((char_u *)name);
3724 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003725 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003726}
3727
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003728#if defined(EXITFREE) || defined(PROTO)
3729/*
3730 * Free all options.
3731 */
3732 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003733free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003734{
3735 int i;
3736
3737 for (i = 0; !istermoption(&options[i]); i++)
3738 {
3739 if (options[i].indir == PV_NONE)
3740 {
3741 /* global option: free value and default value. */
3742 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3743 free_string_option(*(char_u **)options[i].var);
3744 if (options[i].flags & P_DEF_ALLOCED)
3745 free_string_option(options[i].def_val[VI_DEFAULT]);
3746 }
3747 else if (options[i].var != VAR_WIN
3748 && (options[i].flags & P_STRING))
3749 /* buffer-local option: free global value */
3750 free_string_option(*(char_u **)options[i].var);
3751 }
3752}
3753#endif
3754
3755
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756/*
3757 * Initialize the options, part two: After getting Rows and Columns and
3758 * setting 'term'.
3759 */
3760 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003761set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003763 int idx;
3764
Bram Moolenaar071d4272004-06-13 20:20:40 +00003765 /*
3766 * 'scroll' defaults to half the window height. Note that this default is
3767 * wrong when the window height changes.
3768 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003769 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003770 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003771 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003772 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 comp_col();
3774
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003775 /*
3776 * 'window' is only for backwards compatibility with Vi.
3777 * Default is Rows - 1.
3778 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003779 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003780 p_window = Rows - 1;
3781 set_number_default("window", Rows - 1);
3782
Bram Moolenaarf740b292006-02-16 22:11:02 +00003783 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003784#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003785 /*
3786 * If 'background' wasn't set by the user, try guessing the value,
3787 * depending on the terminal name. Only need to check for terminals
3788 * with a dark background, that can handle color.
3789 */
3790 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003791 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3792 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003794 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003795 /* don't mark it as set, when starting the GUI it may be
3796 * changed again */
3797 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798 }
3799#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003800
3801#ifdef CURSOR_SHAPE
3802 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3803#endif
3804#ifdef FEAT_MOUSESHAPE
3805 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3806#endif
3807#ifdef FEAT_PRINTER
3808 (void)parse_printoptions(); /* parse 'printoptions' default value */
3809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810}
3811
3812/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003813 * Return "dark" or "light" depending on the kind of terminal.
3814 * This is just guessing! Recognized are:
3815 * "linux" Linux console
3816 * "screen.linux" Linux console with screen
3817 * "cygwin" Cygwin shell
3818 * "putty" Putty program
3819 * We also check the COLORFGBG environment variable, which is set by
3820 * rxvt and derivatives. This variable contains either two or three
3821 * values separated by semicolons; we want the last value in either
3822 * case. If this value is 0-6 or 8, our background is dark.
3823 */
3824 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003825term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003826{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003827#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003828 /* DOS console nearly always black */
3829 return (char_u *)"dark";
3830#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003831 char_u *p;
3832
Bram Moolenaarf740b292006-02-16 22:11:02 +00003833 if (STRCMP(T_NAME, "linux") == 0
3834 || STRCMP(T_NAME, "screen.linux") == 0
3835 || STRCMP(T_NAME, "cygwin") == 0
3836 || STRCMP(T_NAME, "putty") == 0
3837 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3838 && (p = vim_strrchr(p, ';')) != NULL
3839 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3840 && p[2] == NUL))
3841 return (char_u *)"dark";
3842 return (char_u *)"light";
3843#endif
3844}
3845
3846/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847 * Initialize the options, part three: After reading the .vimrc
3848 */
3849 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003850set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003852#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853/*
3854 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3855 * This is done after other initializations, where 'shell' might have been
3856 * set, but only if they have not been set before.
3857 */
3858 char_u *p;
3859 int idx_srr;
3860 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003861# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 int idx_sp;
3863 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003864# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865
3866 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003867 if (idx_srr < 0)
3868 do_srr = FALSE;
3869 else
3870 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003871# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003873 if (idx_sp < 0)
3874 do_sp = FALSE;
3875 else
3876 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003877# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003878 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 if (p != NULL)
3880 {
3881 /*
3882 * Default for p_sp is "| tee", for p_srr is ">".
3883 * For known shells it is changed here to include stderr.
3884 */
3885 if ( fnamecmp(p, "csh") == 0
3886 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003887# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 || fnamecmp(p, "csh.exe") == 0
3889 || fnamecmp(p, "tcsh.exe") == 0
3890# endif
3891 )
3892 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003893# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 if (do_sp)
3895 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003896# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003898# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003899 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003900# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3902 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003903# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904 if (do_srr)
3905 {
3906 p_srr = (char_u *)">&";
3907 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3908 }
3909 }
3910 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003911 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 if ( fnamecmp(p, "sh") == 0
3913 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003914 || fnamecmp(p, "mksh") == 0
3915 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003917 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003919 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003920# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003921 || fnamecmp(p, "cmd") == 0
3922 || fnamecmp(p, "sh.exe") == 0
3923 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003924 || fnamecmp(p, "mksh.exe") == 0
3925 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003927 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 || fnamecmp(p, "bash.exe") == 0
3929 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003931 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003933# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 if (do_sp)
3935 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003936# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003938# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003940# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3942 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003943# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 if (do_srr)
3945 {
3946 p_srr = (char_u *)">%s 2>&1";
3947 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3948 }
3949 }
3950 vim_free(p);
3951 }
3952#endif
3953
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003954#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003956 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3957 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 * This is done after other initializations, where 'shell' might have been
3959 * set, but only if they have not been set before. Default for p_shcf is
3960 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003961 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003963 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 {
3965 int idx3;
3966
3967 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003968 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969 {
3970 p_shcf = (char_u *)"-c";
3971 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3972 }
3973
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003974# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 /* Somehow Win32 requires the quotes around the redirection too */
3976 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003977 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 {
3979 p_sxq = (char_u *)"\"";
3980 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3981 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003982# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983 idx3 = findoption((char_u *)"shq");
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_shq = (char_u *)"\"";
3987 options[idx3].def_val[VI_DEFAULT] = p_shq;
3988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989# endif
3990 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003991 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3992 {
3993 int idx3;
3994
3995 /*
3996 * cmd.exe on Windows will strip the first and last double quote given
3997 * on the command line, e.g. most of the time things like:
3998 * cmd /c "my path/to/echo" "my args to echo"
3999 * become:
4000 * my path/to/echo" "my args to echo
4001 * when executed.
4002 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004003 * To avoid this, set shellxquote to surround the command in
4004 * parenthesis. This appears to make most commands work, without
4005 * breaking commands that worked previously, such as
4006 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004007 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004008 idx3 = findoption((char_u *)"sxq");
4009 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4010 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004011 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004012 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4013 }
4014
Bram Moolenaara64ba222012-02-12 23:23:31 +01004015 idx3 = findoption((char_u *)"shcf");
4016 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4017 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004018 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004019 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4020 }
4021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022#endif
4023
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004024 if (bufempty())
4025 {
4026 int idx_ffs = findoption((char_u *)"ffs");
4027
4028 /* Apply the first entry of 'fileformats' to the initial buffer. */
4029 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4030 set_fileformat(default_fileformat(), OPT_LOCAL);
4031 }
4032
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033#ifdef FEAT_TITLE
4034 set_title_defaults();
4035#endif
4036}
4037
4038#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4039/*
4040 * When 'helplang' is still at its default value, set it to "lang".
4041 * Only the first two characters of "lang" are used.
4042 */
4043 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004044set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045{
4046 int idx;
4047
4048 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4049 return;
4050 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004051 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 {
4053 if (options[idx].flags & P_ALLOCED)
4054 free_string_option(p_hlg);
4055 p_hlg = vim_strsave(lang);
4056 if (p_hlg == NULL)
4057 p_hlg = empty_option;
4058 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004059 {
4060 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4061 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4062 {
4063 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4064 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4065 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004067 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 options[idx].flags |= P_ALLOCED;
4069 }
4070}
4071#endif
4072
4073#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004074static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075
4076 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004077gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078{
4079 if (gui_get_lightness(gui.back_pixel) < 127)
4080 return (char_u *)"dark";
4081 return (char_u *)"light";
4082}
4083
4084/*
4085 * Option initializations that can only be done after opening the GUI window.
4086 */
4087 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004088init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089{
4090 /* Set the 'background' option according to the lightness of the
4091 * background color, unless the user has set it already. */
4092 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4093 {
4094 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4095 highlight_changed();
4096 }
4097}
4098#endif
4099
4100#ifdef FEAT_TITLE
4101/*
4102 * 'title' and 'icon' only default to true if they have not been set or reset
4103 * in .vimrc and we can read the old value.
4104 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4105 * they can be reset. This reduces startup time when using X on a remote
4106 * machine.
4107 */
4108 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004109set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110{
4111 int idx1;
4112 long val;
4113
4114 /*
4115 * If GUI is (going to be) used, we can always set the window title and
4116 * icon name. Saves a bit of time, because the X11 display server does
4117 * not need to be contacted.
4118 */
4119 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004120 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 {
4122#ifdef FEAT_GUI
4123 if (gui.starting || gui.in_use)
4124 val = TRUE;
4125 else
4126#endif
4127 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004128 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 p_title = val;
4130 }
4131 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004132 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 {
4134#ifdef FEAT_GUI
4135 if (gui.starting || gui.in_use)
4136 val = TRUE;
4137 else
4138#endif
4139 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004140 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 p_icon = val;
4142 }
4143}
4144#endif
4145
4146/*
4147 * Parse 'arg' for option settings.
4148 *
4149 * 'arg' may be IObuff, but only when no errors can be present and option
4150 * does not need to be expanded with option_expand().
4151 * "opt_flags":
4152 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004153 * OPT_GLOBAL for ":setglobal"
4154 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004156 * OPT_WINONLY to only set window-local options
4157 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158 *
4159 * returns FAIL if an error is detected, OK otherwise
4160 */
4161 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004162do_set(
4163 char_u *arg, /* option string (may be written to!) */
4164 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165{
4166 int opt_idx;
4167 char_u *errmsg;
4168 char_u errbuf[80];
4169 char_u *startarg;
4170 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4171 int nextchar; /* next non-white char after option name */
4172 int afterchar; /* character just after option name */
4173 int len;
4174 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004175 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176 int key;
4177 long_u flags; /* flags for current option */
4178 char_u *varp = NULL; /* pointer to variable for current option */
4179 int did_show = FALSE; /* already showed one value */
4180 int adding; /* "opt+=arg" */
4181 int prepending; /* "opt^=arg" */
4182 int removing; /* "opt-=arg" */
4183 int cp_val = 0;
4184 char_u key_name[2];
4185
4186 if (*arg == NUL)
4187 {
4188 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004189 did_show = TRUE;
4190 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 }
4192
4193 while (*arg != NUL) /* loop to process all options */
4194 {
4195 errmsg = NULL;
4196 startarg = arg; /* remember for error message */
4197
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004198 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4199 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004200 {
4201 /*
4202 * ":set all" show all options.
4203 * ":set all&" set all options to their default value.
4204 */
4205 arg += 3;
4206 if (*arg == '&')
4207 {
4208 ++arg;
4209 /* Only for :set command set global value of local options. */
4210 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004211 didset_options();
4212 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004213 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004214 }
4215 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004216 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004217 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004218 did_show = TRUE;
4219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004220 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004221 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 {
4223 showoptions(2, opt_flags);
4224 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004225 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226 arg += 7;
4227 }
4228 else
4229 {
4230 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004231 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232 {
4233 prefix = 0;
4234 arg += 2;
4235 }
4236 else if (STRNCMP(arg, "inv", 3) == 0)
4237 {
4238 prefix = 2;
4239 arg += 3;
4240 }
4241
4242 /* find end of name */
4243 key = 0;
4244 if (*arg == '<')
4245 {
4246 nextchar = 0;
4247 opt_idx = -1;
4248 /* look out for <t_>;> */
4249 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4250 len = 5;
4251 else
4252 {
4253 len = 1;
4254 while (arg[len] != NUL && arg[len] != '>')
4255 ++len;
4256 }
4257 if (arg[len] != '>')
4258 {
4259 errmsg = e_invarg;
4260 goto skip;
4261 }
4262 arg[len] = NUL; /* put NUL after name */
4263 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4264 opt_idx = findoption(arg + 1);
4265 arg[len++] = '>'; /* restore '>' */
4266 if (opt_idx == -1)
4267 key = find_key_option(arg + 1);
4268 }
4269 else
4270 {
4271 len = 0;
4272 /*
4273 * The two characters after "t_" may not be alphanumeric.
4274 */
4275 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4276 len = 4;
4277 else
4278 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4279 ++len;
4280 nextchar = arg[len];
4281 arg[len] = NUL; /* put NUL after name */
4282 opt_idx = findoption(arg);
4283 arg[len] = nextchar; /* restore nextchar */
4284 if (opt_idx == -1)
4285 key = find_key_option(arg);
4286 }
4287
4288 /* remember character after option name */
4289 afterchar = arg[len];
4290
4291 /* skip white space, allow ":set ai ?" */
4292 while (vim_iswhite(arg[len]))
4293 ++len;
4294
4295 adding = FALSE;
4296 prepending = FALSE;
4297 removing = FALSE;
4298 if (arg[len] != NUL && arg[len + 1] == '=')
4299 {
4300 if (arg[len] == '+')
4301 {
4302 adding = TRUE; /* "+=" */
4303 ++len;
4304 }
4305 else if (arg[len] == '^')
4306 {
4307 prepending = TRUE; /* "^=" */
4308 ++len;
4309 }
4310 else if (arg[len] == '-')
4311 {
4312 removing = TRUE; /* "-=" */
4313 ++len;
4314 }
4315 }
4316 nextchar = arg[len];
4317
4318 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4319 {
4320 errmsg = (char_u *)N_("E518: Unknown option");
4321 goto skip;
4322 }
4323
4324 if (opt_idx >= 0)
4325 {
4326 if (options[opt_idx].var == NULL) /* hidden option: skip */
4327 {
4328 /* Only give an error message when requesting the value of
4329 * a hidden option, ignore setting it. */
4330 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4331 && (!(options[opt_idx].flags & P_BOOL)
4332 || nextchar == '?'))
4333 errmsg = (char_u *)N_("E519: Option not supported");
4334 goto skip;
4335 }
4336
4337 flags = options[opt_idx].flags;
4338 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4339 }
4340 else
4341 {
4342 flags = P_STRING;
4343 if (key < 0)
4344 {
4345 key_name[0] = KEY2TERMCAP0(key);
4346 key_name[1] = KEY2TERMCAP1(key);
4347 }
4348 else
4349 {
4350 key_name[0] = KS_KEY;
4351 key_name[1] = (key & 0xff);
4352 }
4353 }
4354
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004355 /* Skip all options that are not window-local (used when showing
4356 * an already loaded buffer in a window). */
4357 if ((opt_flags & OPT_WINONLY)
4358 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4359 goto skip;
4360
Bram Moolenaara3227e22006-03-08 21:32:40 +00004361 /* Skip all options that are window-local (used for :vimgrep). */
4362 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4363 && options[opt_idx].var == VAR_WIN)
4364 goto skip;
4365
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004366 /* Disallow changing some options from modelines. */
4367 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004368 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004369 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004370 {
4371 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4372 goto skip;
4373 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004374#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004375 /* In diff mode some options are overruled. This avoids that
4376 * 'foldmethod' becomes "marker" instead of "diff" and that
4377 * "wrap" gets set. */
4378 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004379 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004380 && (options[opt_idx].indir == PV_FDM
4381 || options[opt_idx].indir == PV_WRAP))
4382 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384 }
4385
4386#ifdef HAVE_SANDBOX
4387 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004388 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004389 {
4390 errmsg = (char_u *)_(e_sandbox);
4391 goto skip;
4392 }
4393#endif
4394
4395 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4396 {
4397 arg += len;
4398 cp_val = p_cp;
4399 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4400 {
4401 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4402 {
4403 cp_val = FALSE;
4404 arg += 3;
4405 }
4406 else /* "opt&vi": set to Vi default */
4407 {
4408 cp_val = TRUE;
4409 arg += 2;
4410 }
4411 }
4412 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4413 && arg[1] != NUL && !vim_iswhite(arg[1]))
4414 {
4415 errmsg = e_trailing;
4416 goto skip;
4417 }
4418 }
4419
4420 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004421 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4422 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004423 */
4424 if (nextchar == '?'
4425 || (prefix == 1
4426 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4427 && !(flags & P_BOOL)))
4428 {
4429 /*
4430 * print value
4431 */
4432 if (did_show)
4433 msg_putchar('\n'); /* cursor below last one */
4434 else
4435 {
4436 gotocmdline(TRUE); /* cursor at status line */
4437 did_show = TRUE; /* remember that we did a line */
4438 }
4439 if (opt_idx >= 0)
4440 {
4441 showoneopt(&options[opt_idx], opt_flags);
4442#ifdef FEAT_EVAL
4443 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004444 {
4445 /* Mention where the option was last set. */
4446 if (varp == options[opt_idx].var)
4447 last_set_msg(options[opt_idx].scriptID);
4448 else if ((int)options[opt_idx].indir & PV_WIN)
4449 last_set_msg(curwin->w_p_scriptID[
4450 (int)options[opt_idx].indir & PV_MASK]);
4451 else if ((int)options[opt_idx].indir & PV_BUF)
4452 last_set_msg(curbuf->b_p_scriptID[
4453 (int)options[opt_idx].indir & PV_MASK]);
4454 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004455#endif
4456 }
4457 else
4458 {
4459 char_u *p;
4460
4461 p = find_termcode(key_name);
4462 if (p == NULL)
4463 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004464 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004465 goto skip;
4466 }
4467 else
4468 (void)show_one_termcode(key_name, p, TRUE);
4469 }
4470 if (nextchar != '?'
4471 && nextchar != NUL && !vim_iswhite(afterchar))
4472 errmsg = e_trailing;
4473 }
4474 else
4475 {
4476 if (flags & P_BOOL) /* boolean */
4477 {
4478 if (nextchar == '=' || nextchar == ':')
4479 {
4480 errmsg = e_invarg;
4481 goto skip;
4482 }
4483
4484 /*
4485 * ":set opt!": invert
4486 * ":set opt&": reset to default value
4487 * ":set opt<": reset to global value
4488 */
4489 if (nextchar == '!')
4490 value = *(int *)(varp) ^ 1;
4491 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004492 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004493 ((flags & P_VI_DEF) || cp_val)
4494 ? VI_DEFAULT : VIM_DEFAULT];
4495 else if (nextchar == '<')
4496 {
4497 /* For 'autoread' -1 means to use global value. */
4498 if ((int *)varp == &curbuf->b_p_ar
4499 && opt_flags == OPT_LOCAL)
4500 value = -1;
4501 else
4502 value = *(int *)get_varp_scope(&(options[opt_idx]),
4503 OPT_GLOBAL);
4504 }
4505 else
4506 {
4507 /*
4508 * ":set invopt": invert
4509 * ":set opt" or ":set noopt": set or reset
4510 */
4511 if (nextchar != NUL && !vim_iswhite(afterchar))
4512 {
4513 errmsg = e_trailing;
4514 goto skip;
4515 }
4516 if (prefix == 2) /* inv */
4517 value = *(int *)(varp) ^ 1;
4518 else
4519 value = prefix;
4520 }
4521
4522 errmsg = set_bool_option(opt_idx, varp, (int)value,
4523 opt_flags);
4524 }
4525 else /* numeric or string */
4526 {
4527 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4528 || prefix != 1)
4529 {
4530 errmsg = e_invarg;
4531 goto skip;
4532 }
4533
4534 if (flags & P_NUM) /* numeric */
4535 {
4536 /*
4537 * Different ways to set a number option:
4538 * & set to default value
4539 * < set to global value
4540 * <xx> accept special key codes for 'wildchar'
4541 * c accept any non-digit for 'wildchar'
4542 * [-]0-9 set number
4543 * other error
4544 */
4545 ++arg;
4546 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004547 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004548 ((flags & P_VI_DEF) || cp_val)
4549 ? VI_DEFAULT : VIM_DEFAULT];
4550 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004551 {
4552 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4553 * use the global value. */
4554 if ((long *)varp == &curbuf->b_p_ul
4555 && opt_flags == OPT_LOCAL)
4556 value = NO_LOCAL_UNDOLEVEL;
4557 else
4558 value = *(long *)get_varp_scope(
4559 &(options[opt_idx]), OPT_GLOBAL);
4560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004561 else if (((long *)varp == &p_wc
4562 || (long *)varp == &p_wcm)
4563 && (*arg == '<'
4564 || *arg == '^'
4565 || ((!arg[1] || vim_iswhite(arg[1]))
4566 && !VIM_ISDIGIT(*arg))))
4567 {
4568 value = string_to_key(arg);
4569 if (value == 0 && (long *)varp != &p_wcm)
4570 {
4571 errmsg = e_invarg;
4572 goto skip;
4573 }
4574 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004575 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4576 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004577 /* Allow negative (for 'undolevels'), octal and
4578 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004579 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4580 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4582 {
4583 errmsg = e_invarg;
4584 goto skip;
4585 }
4586 }
4587 else
4588 {
4589 errmsg = (char_u *)N_("E521: Number required after =");
4590 goto skip;
4591 }
4592
4593 if (adding)
4594 value = *(long *)varp + value;
4595 if (prepending)
4596 value = *(long *)varp * value;
4597 if (removing)
4598 value = *(long *)varp - value;
4599 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004600 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004601 }
4602 else if (opt_idx >= 0) /* string */
4603 {
4604 char_u *save_arg = NULL;
4605 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004606 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004607 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004608 char_u *origval = NULL;
4609#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4610 char_u *saved_origval = NULL;
4611#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004612 unsigned newlen;
4613 int comma;
4614 int bs;
4615 int new_value_alloced; /* new string option
4616 was allocated */
4617
4618 /* When using ":set opt=val" for a global option
4619 * with a local value the local value will be
4620 * reset, use the global value here. */
4621 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004622 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623 varp = options[opt_idx].var;
4624
4625 /* The old value is kept until we are sure that the
4626 * new value is valid. */
4627 oldval = *(char_u **)varp;
4628 if (nextchar == '&') /* set to default val */
4629 {
4630 newval = options[opt_idx].def_val[
4631 ((flags & P_VI_DEF) || cp_val)
4632 ? VI_DEFAULT : VIM_DEFAULT];
4633 if ((char_u **)varp == &p_bg)
4634 {
4635 /* guess the value of 'background' */
4636#ifdef FEAT_GUI
4637 if (gui.in_use)
4638 newval = gui_bg_default();
4639 else
4640#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004641 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004642 }
4643
4644 /* expand environment variables and ~ (since the
4645 * default value was already expanded, only
4646 * required when an environment variable was set
4647 * later */
4648 if (newval == NULL)
4649 newval = empty_option;
4650 else
4651 {
4652 s = option_expand(opt_idx, newval);
4653 if (s == NULL)
4654 s = newval;
4655 newval = vim_strsave(s);
4656 }
4657 new_value_alloced = TRUE;
4658 }
4659 else if (nextchar == '<') /* set to global val */
4660 {
4661 newval = vim_strsave(*(char_u **)get_varp_scope(
4662 &(options[opt_idx]), OPT_GLOBAL));
4663 new_value_alloced = TRUE;
4664 }
4665 else
4666 {
4667 ++arg; /* jump to after the '=' or ':' */
4668
4669 /*
4670 * Set 'keywordprg' to ":help" if an empty
4671 * value was passed to :set by the user.
4672 * Misuse errbuf[] for the resulting string.
4673 */
4674 if (varp == (char_u *)&p_kp
4675 && (*arg == NUL || *arg == ' '))
4676 {
4677 STRCPY(errbuf, ":help");
4678 save_arg = arg;
4679 arg = errbuf;
4680 }
4681 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004682 * Convert 'backspace' number to string, for
4683 * adding, prepending and removing string.
4684 */
4685 else if (varp == (char_u *)&p_bs
4686 && VIM_ISDIGIT(**(char_u **)varp))
4687 {
4688 i = getdigits((char_u **)varp);
4689 switch (i)
4690 {
4691 case 0:
4692 *(char_u **)varp = empty_option;
4693 break;
4694 case 1:
4695 *(char_u **)varp = vim_strsave(
4696 (char_u *)"indent,eol");
4697 break;
4698 case 2:
4699 *(char_u **)varp = vim_strsave(
4700 (char_u *)"indent,eol,start");
4701 break;
4702 }
4703 vim_free(oldval);
4704 oldval = *(char_u **)varp;
4705 }
4706 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004707 * Convert 'whichwrap' number to string, for
4708 * backwards compatibility with Vim 3.0.
4709 * Misuse errbuf[] for the resulting string.
4710 */
4711 else if (varp == (char_u *)&p_ww
4712 && VIM_ISDIGIT(*arg))
4713 {
4714 *errbuf = NUL;
4715 i = getdigits(&arg);
4716 if (i & 1)
4717 STRCAT(errbuf, "b,");
4718 if (i & 2)
4719 STRCAT(errbuf, "s,");
4720 if (i & 4)
4721 STRCAT(errbuf, "h,l,");
4722 if (i & 8)
4723 STRCAT(errbuf, "<,>,");
4724 if (i & 16)
4725 STRCAT(errbuf, "[,],");
4726 if (*errbuf != NUL) /* remove trailing , */
4727 errbuf[STRLEN(errbuf) - 1] = NUL;
4728 save_arg = arg;
4729 arg = errbuf;
4730 }
4731 /*
4732 * Remove '>' before 'dir' and 'bdir', for
4733 * backwards compatibility with version 3.0
4734 */
4735 else if ( *arg == '>'
4736 && (varp == (char_u *)&p_dir
4737 || varp == (char_u *)&p_bdir))
4738 {
4739 ++arg;
4740 }
4741
4742 /* When setting the local value of a global
4743 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004744 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004745 && (opt_flags & OPT_LOCAL))
4746 origval = *(char_u **)get_varp(
4747 &options[opt_idx]);
4748 else
4749 origval = oldval;
4750
4751 /*
4752 * Copy the new string into allocated memory.
4753 * Can't use set_string_option_direct(), because
4754 * we need to remove the backslashes.
4755 */
4756 /* get a bit too much */
4757 newlen = (unsigned)STRLEN(arg) + 1;
4758 if (adding || prepending || removing)
4759 newlen += (unsigned)STRLEN(origval) + 1;
4760 newval = alloc(newlen);
4761 if (newval == NULL) /* out of mem, don't change */
4762 break;
4763 s = newval;
4764
4765 /*
4766 * Copy the string, skip over escaped chars.
4767 * For MS-DOS and WIN32 backslashes before normal
4768 * file name characters are not removed, and keep
4769 * backslash at start, for "\\machine\path", but
4770 * do remove it for "\\\\machine\\path".
4771 * The reverse is found in ExpandOldSetting().
4772 */
4773 while (*arg && !vim_iswhite(*arg))
4774 {
4775 if (*arg == '\\' && arg[1] != NUL
4776#ifdef BACKSLASH_IN_FILENAME
4777 && !((flags & P_EXPAND)
4778 && vim_isfilec(arg[1])
4779 && (arg[1] != '\\'
4780 || (s == newval
4781 && arg[2] != '\\')))
4782#endif
4783 )
4784 ++arg; /* remove backslash */
4785#ifdef FEAT_MBYTE
4786 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004787 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004788 {
4789 /* copy multibyte char */
4790 mch_memmove(s, arg, (size_t)i);
4791 arg += i;
4792 s += i;
4793 }
4794 else
4795#endif
4796 *s++ = *arg++;
4797 }
4798 *s = NUL;
4799
4800 /*
4801 * Expand environment variables and ~.
4802 * Don't do it when adding without inserting a
4803 * comma.
4804 */
4805 if (!(adding || prepending || removing)
4806 || (flags & P_COMMA))
4807 {
4808 s = option_expand(opt_idx, newval);
4809 if (s != NULL)
4810 {
4811 vim_free(newval);
4812 newlen = (unsigned)STRLEN(s) + 1;
4813 if (adding || prepending || removing)
4814 newlen += (unsigned)STRLEN(origval) + 1;
4815 newval = alloc(newlen);
4816 if (newval == NULL)
4817 break;
4818 STRCPY(newval, s);
4819 }
4820 }
4821
4822 /* locate newval[] in origval[] when removing it
4823 * and when adding to avoid duplicates */
4824 i = 0; /* init for GCC */
4825 if (removing || (flags & P_NODUP))
4826 {
4827 i = (int)STRLEN(newval);
4828 bs = 0;
4829 for (s = origval; *s; ++s)
4830 {
4831 if ((!(flags & P_COMMA)
4832 || s == origval
4833 || (s[-1] == ',' && !(bs & 1)))
4834 && STRNCMP(s, newval, i) == 0
4835 && (!(flags & P_COMMA)
4836 || s[i] == ','
4837 || s[i] == NUL))
4838 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004839 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004840 * even number of backslashes or a single
4841 * backslash preceded by a comma before it
4842 * is recognized as a separator */
4843 if ((s > origval + 1
4844 && s[-1] == '\\'
4845 && s[-2] != ',')
4846 || (s == origval + 1
4847 && s[-1] == '\\'))
4848
Bram Moolenaar071d4272004-06-13 20:20:40 +00004849 ++bs;
4850 else
4851 bs = 0;
4852 }
4853
4854 /* do not add if already there */
4855 if ((adding || prepending) && *s)
4856 {
4857 prepending = FALSE;
4858 adding = FALSE;
4859 STRCPY(newval, origval);
4860 }
4861 }
4862
4863 /* concatenate the two strings; add a ',' if
4864 * needed */
4865 if (adding || prepending)
4866 {
4867 comma = ((flags & P_COMMA) && *origval != NUL
4868 && *newval != NUL);
4869 if (adding)
4870 {
4871 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004872 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004873 if (comma && i > 1
4874 && (flags & P_ONECOMMA) == P_ONECOMMA
4875 && origval[i - 1] == ','
4876 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004877 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004878 mch_memmove(newval + i + comma, newval,
4879 STRLEN(newval) + 1);
4880 mch_memmove(newval, origval, (size_t)i);
4881 }
4882 else
4883 {
4884 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004885 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004886 }
4887 if (comma)
4888 newval[i] = ',';
4889 }
4890
4891 /* Remove newval[] from origval[]. (Note: "i" has
4892 * been set above and is used here). */
4893 if (removing)
4894 {
4895 STRCPY(newval, origval);
4896 if (*s)
4897 {
4898 /* may need to remove a comma */
4899 if (flags & P_COMMA)
4900 {
4901 if (s == origval)
4902 {
4903 /* include comma after string */
4904 if (s[i] == ',')
4905 ++i;
4906 }
4907 else
4908 {
4909 /* include comma before string */
4910 --s;
4911 ++i;
4912 }
4913 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004914 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004915 }
4916 }
4917
4918 if (flags & P_FLAGLIST)
4919 {
4920 /* Remove flags that appear twice. */
4921 for (s = newval; *s; ++s)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004922 {
4923 /* if options have P_FLAGLIST and
4924 * P_ONECOMMA such as 'whichwrap' */
4925 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004926 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004927 if (*s != ',' && *(s + 1) == ','
4928 && vim_strchr(s + 2, *s) != NULL)
4929 {
4930 /* Remove the duplicated value and
4931 * the next comma. */
4932 STRMOVE(s, s + 2);
4933 s -= 2;
4934 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004935 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004936 else
4937 {
4938 if ((!(flags & P_COMMA) || *s != ',')
4939 && vim_strchr(s + 1, *s) != NULL)
4940 {
4941 STRMOVE(s, s + 1);
4942 --s;
4943 }
4944 }
4945 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004946 }
4947
4948 if (save_arg != NULL) /* number for 'whichwrap' */
4949 arg = save_arg;
4950 new_value_alloced = TRUE;
4951 }
4952
4953 /* Set the new value. */
4954 *(char_u **)(varp) = newval;
4955
Bram Moolenaar53744302015-07-17 17:38:22 +02004956#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004957 if (!starting
4958# ifdef FEAT_CRYPT
4959 && options[opt_idx].indir != PV_KEY
4960# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004961 && origval != NULL)
4962 /* origval may be freed by
4963 * did_set_string_option(), make a copy. */
4964 saved_origval = vim_strsave(origval);
4965#endif
4966
Bram Moolenaar071d4272004-06-13 20:20:40 +00004967 /* Handle side effects, and set the global value for
4968 * ":set" on local options. */
4969 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4970 new_value_alloced, oldval, errbuf, opt_flags);
4971
4972 /* If error detected, print the error message. */
4973 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004974 {
4975#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4976 vim_free(saved_origval);
4977#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004978 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004979 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004980#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4981 if (saved_origval != NULL)
4982 {
4983 char_u buf_type[7];
4984
4985 sprintf((char *)buf_type, "%s",
4986 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004987 set_vim_var_string(VV_OPTION_NEW,
4988 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004989 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4990 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4991 apply_autocmds(EVENT_OPTIONSET,
4992 (char_u *)options[opt_idx].fullname,
4993 NULL, FALSE, NULL);
4994 reset_v_option_vars();
4995 vim_free(saved_origval);
4996 }
4997#endif
4998
Bram Moolenaar071d4272004-06-13 20:20:40 +00004999 }
5000 else /* key code option */
5001 {
5002 char_u *p;
5003
5004 if (nextchar == '&')
5005 {
5006 if (add_termcap_entry(key_name, TRUE) == FAIL)
5007 errmsg = (char_u *)N_("E522: Not found in termcap");
5008 }
5009 else
5010 {
5011 ++arg; /* jump to after the '=' or ':' */
5012 for (p = arg; *p && !vim_iswhite(*p); ++p)
5013 if (*p == '\\' && p[1] != NUL)
5014 ++p;
5015 nextchar = *p;
5016 *p = NUL;
5017 add_termcode(key_name, arg, FALSE);
5018 *p = nextchar;
5019 }
5020 if (full_screen)
5021 ttest(FALSE);
5022 redraw_all_later(CLEAR);
5023 }
5024 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005025
Bram Moolenaar071d4272004-06-13 20:20:40 +00005026 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005027 did_set_option(opt_idx, opt_flags,
5028 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005029 }
5030
5031skip:
5032 /*
5033 * Advance to next argument.
5034 * - skip until a blank found, taking care of backslashes
5035 * - skip blanks
5036 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5037 */
5038 for (i = 0; i < 2 ; ++i)
5039 {
5040 while (*arg != NUL && !vim_iswhite(*arg))
5041 if (*arg++ == '\\' && *arg != NUL)
5042 ++arg;
5043 arg = skipwhite(arg);
5044 if (*arg != '=')
5045 break;
5046 }
5047 }
5048
5049 if (errmsg != NULL)
5050 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005051 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005052 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005053 if (i + (arg - startarg) < IOSIZE)
5054 {
5055 /* append the argument with the error */
5056 STRCAT(IObuff, ": ");
5057 mch_memmove(IObuff + i, startarg, (arg - startarg));
5058 IObuff[i + (arg - startarg)] = NUL;
5059 }
5060 /* make sure all characters are printable */
5061 trans_characters(IObuff, IOSIZE);
5062
5063 ++no_wait_return; /* wait_return done later */
5064 emsg(IObuff); /* show error highlighted */
5065 --no_wait_return;
5066
5067 return FAIL;
5068 }
5069
5070 arg = skipwhite(arg);
5071 }
5072
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005073theend:
5074 if (silent_mode && did_show)
5075 {
5076 /* After displaying option values in silent mode. */
5077 silent_mode = FALSE;
5078 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5079 msg_putchar('\n');
5080 cursor_on(); /* msg_start() switches it off */
5081 out_flush();
5082 silent_mode = TRUE;
5083 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5084 }
5085
Bram Moolenaar071d4272004-06-13 20:20:40 +00005086 return OK;
5087}
5088
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005089/*
5090 * Call this when an option has been given a new value through a user command.
5091 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5092 */
5093 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005094did_set_option(
5095 int opt_idx,
5096 int opt_flags, /* possibly with OPT_MODELINE */
5097 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005098{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005099 long_u *p;
5100
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005101 options[opt_idx].flags |= P_WAS_SET;
5102
5103 /* When an option is set in the sandbox, from a modeline or in secure mode
5104 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005105 * flag. */
5106 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005107 if (secure
5108#ifdef HAVE_SANDBOX
5109 || sandbox != 0
5110#endif
5111 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005112 *p = *p | P_INSECURE;
5113 else if (new_value)
5114 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005115}
5116
Bram Moolenaar071d4272004-06-13 20:20:40 +00005117 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005118illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005119{
5120 if (errbuf == NULL)
5121 return (char_u *)"";
5122 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005123 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005124 return errbuf;
5125}
5126
5127/*
5128 * Convert a key name or string into a key value.
5129 * Used for 'wildchar' and 'cedit' options.
5130 */
5131 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005132string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005133{
5134 if (*arg == '<')
5135 return find_key_option(arg + 1);
5136 if (*arg == '^')
5137 return Ctrl_chr(arg[1]);
5138 return *arg;
5139}
5140
5141#ifdef FEAT_CMDWIN
5142/*
5143 * Check value of 'cedit' and set cedit_key.
5144 * Returns NULL if value is OK, error message otherwise.
5145 */
5146 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005147check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005148{
5149 int n;
5150
5151 if (*p_cedit == NUL)
5152 cedit_key = -1;
5153 else
5154 {
5155 n = string_to_key(p_cedit);
5156 if (vim_isprintc(n))
5157 return e_invarg;
5158 cedit_key = n;
5159 }
5160 return NULL;
5161}
5162#endif
5163
5164#ifdef FEAT_TITLE
5165/*
5166 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5167 * maketitle() to create and display it.
5168 * When switching the title or icon off, call mch_restore_title() to get
5169 * the old value back.
5170 */
5171 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005172did_set_title(
5173 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005174{
5175 if (starting != NO_SCREEN
5176#ifdef FEAT_GUI
5177 && !gui.starting
5178#endif
5179 )
5180 {
5181 maketitle();
5182 if (icon)
5183 {
5184 if (!p_icon)
5185 mch_restore_title(2);
5186 }
5187 else
5188 {
5189 if (!p_title)
5190 mch_restore_title(1);
5191 }
5192 }
5193}
5194#endif
5195
5196/*
5197 * set_options_bin - called when 'bin' changes value.
5198 */
5199 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005200set_options_bin(
5201 int oldval,
5202 int newval,
5203 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005204{
5205 /*
5206 * The option values that are changed when 'bin' changes are
5207 * copied when 'bin is set and restored when 'bin' is reset.
5208 */
5209 if (newval)
5210 {
5211 if (!oldval) /* switched on */
5212 {
5213 if (!(opt_flags & OPT_GLOBAL))
5214 {
5215 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5216 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5217 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5218 curbuf->b_p_et_nobin = curbuf->b_p_et;
5219 }
5220 if (!(opt_flags & OPT_LOCAL))
5221 {
5222 p_tw_nobin = p_tw;
5223 p_wm_nobin = p_wm;
5224 p_ml_nobin = p_ml;
5225 p_et_nobin = p_et;
5226 }
5227 }
5228
5229 if (!(opt_flags & OPT_GLOBAL))
5230 {
5231 curbuf->b_p_tw = 0; /* no automatic line wrap */
5232 curbuf->b_p_wm = 0; /* no automatic line wrap */
5233 curbuf->b_p_ml = 0; /* no modelines */
5234 curbuf->b_p_et = 0; /* no expandtab */
5235 }
5236 if (!(opt_flags & OPT_LOCAL))
5237 {
5238 p_tw = 0;
5239 p_wm = 0;
5240 p_ml = FALSE;
5241 p_et = FALSE;
5242 p_bin = TRUE; /* needed when called for the "-b" argument */
5243 }
5244 }
5245 else if (oldval) /* switched off */
5246 {
5247 if (!(opt_flags & OPT_GLOBAL))
5248 {
5249 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5250 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5251 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5252 curbuf->b_p_et = curbuf->b_p_et_nobin;
5253 }
5254 if (!(opt_flags & OPT_LOCAL))
5255 {
5256 p_tw = p_tw_nobin;
5257 p_wm = p_wm_nobin;
5258 p_ml = p_ml_nobin;
5259 p_et = p_et_nobin;
5260 }
5261 }
5262}
5263
5264#ifdef FEAT_VIMINFO
5265/*
5266 * Find the parameter represented by the given character (eg ', :, ", or /),
5267 * and return its associated value in the 'viminfo' string.
5268 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005269 * If the parameter is not specified in the string or there is no following
5270 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005271 */
5272 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005273get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005274{
5275 char_u *p;
5276
5277 p = find_viminfo_parameter(type);
5278 if (p != NULL && VIM_ISDIGIT(*p))
5279 return atoi((char *)p);
5280 return -1;
5281}
5282
5283/*
5284 * Find the parameter represented by the given character (eg ''', ':', '"', or
5285 * '/') in the 'viminfo' option and return a pointer to the string after it.
5286 * Return NULL if the parameter is not specified in the string.
5287 */
5288 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005289find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290{
5291 char_u *p;
5292
5293 for (p = p_viminfo; *p; ++p)
5294 {
5295 if (*p == type)
5296 return p + 1;
5297 if (*p == 'n') /* 'n' is always the last one */
5298 break;
5299 p = vim_strchr(p, ','); /* skip until next ',' */
5300 if (p == NULL) /* hit the end without finding parameter */
5301 break;
5302 }
5303 return NULL;
5304}
5305#endif
5306
5307/*
5308 * Expand environment variables for some string options.
5309 * These string options cannot be indirect!
5310 * If "val" is NULL expand the current value of the option.
5311 * Return pointer to NameBuff, or NULL when not expanded.
5312 */
5313 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005314option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005315{
5316 /* if option doesn't need expansion nothing to do */
5317 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5318 return NULL;
5319
5320 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5321 * expand_env() would truncate the string. */
5322 if (val != NULL && STRLEN(val) > MAXPATHL)
5323 return NULL;
5324
5325 if (val == NULL)
5326 val = *(char_u **)options[opt_idx].var;
5327
5328 /*
5329 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5330 * Escape spaces when expanding 'tags', they are used to separate file
5331 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005332 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333 */
5334 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005335 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005336#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005337 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5338#endif
5339 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005340 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5341 return NULL;
5342
5343 return NameBuff;
5344}
5345
5346/*
5347 * After setting various option values: recompute variables that depend on
5348 * option values.
5349 */
5350 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005351didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352{
5353 /* initialize the table for 'iskeyword' et.al. */
5354 (void)init_chartab();
5355
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005356#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005359 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005360 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005361#ifdef FEAT_SESSION
5362 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5363 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5364#endif
5365#ifdef FEAT_FOLDING
5366 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5367#endif
5368 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005369 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005370#ifdef FEAT_VIRTUALEDIT
5371 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5372#endif
5373#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5374 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5375#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005376#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005377 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005378 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005379 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005380 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005382#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5383 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5384#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005385#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005386 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5387#endif
5388#ifdef FEAT_CMDWIN
5389 /* set cedit_key */
5390 (void)check_cedit();
5391#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005392#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005393 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005394#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005395#ifdef FEAT_LINEBREAK
5396 /* initialize the table for 'breakat'. */
5397 fill_breakat_flags();
5398#endif
5399
5400}
5401
5402/*
5403 * More side effects of setting options.
5404 */
5405 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005406didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005407{
5408 /* Initialize the highlight_attr[] table. */
5409 (void)highlight_changed();
5410
5411 /* Parse default for 'wildmode' */
5412 check_opt_wim();
5413
5414 (void)set_chars_option(&p_lcs);
5415#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5416 /* Parse default for 'fillchars'. */
5417 (void)set_chars_option(&p_fcs);
5418#endif
5419
5420#ifdef FEAT_CLIPBOARD
5421 /* Parse default for 'clipboard' */
5422 (void)check_clipboard_option();
5423#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005424}
5425
5426/*
5427 * Check for string options that are NULL (normally only termcap options).
5428 */
5429 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005430check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005431{
5432 int opt_idx;
5433
5434 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5435 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5436 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5437}
5438
5439/*
5440 * Check string options in a buffer for NULL value.
5441 */
5442 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005443check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005444{
5445#if defined(FEAT_QUICKFIX)
5446 check_string_option(&buf->b_p_bh);
5447 check_string_option(&buf->b_p_bt);
5448#endif
5449#ifdef FEAT_MBYTE
5450 check_string_option(&buf->b_p_fenc);
5451#endif
5452 check_string_option(&buf->b_p_ff);
5453#ifdef FEAT_FIND_ID
5454 check_string_option(&buf->b_p_def);
5455 check_string_option(&buf->b_p_inc);
5456# ifdef FEAT_EVAL
5457 check_string_option(&buf->b_p_inex);
5458# endif
5459#endif
5460#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5461 check_string_option(&buf->b_p_inde);
5462 check_string_option(&buf->b_p_indk);
5463#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005464#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5465 check_string_option(&buf->b_p_bexpr);
5466#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005467#if defined(FEAT_CRYPT)
5468 check_string_option(&buf->b_p_cm);
5469#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005470#if defined(FEAT_EVAL)
5471 check_string_option(&buf->b_p_fex);
5472#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005473#ifdef FEAT_CRYPT
5474 check_string_option(&buf->b_p_key);
5475#endif
5476 check_string_option(&buf->b_p_kp);
5477 check_string_option(&buf->b_p_mps);
5478 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005479 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005480 check_string_option(&buf->b_p_isk);
5481#ifdef FEAT_COMMENTS
5482 check_string_option(&buf->b_p_com);
5483#endif
5484#ifdef FEAT_FOLDING
5485 check_string_option(&buf->b_p_cms);
5486#endif
5487 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005488#ifdef FEAT_TEXTOBJ
5489 check_string_option(&buf->b_p_qe);
5490#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005491#ifdef FEAT_SYN_HL
5492 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005493 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005494#endif
5495#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005496 check_string_option(&buf->b_s.b_p_spc);
5497 check_string_option(&buf->b_s.b_p_spf);
5498 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499#endif
5500#ifdef FEAT_SEARCHPATH
5501 check_string_option(&buf->b_p_sua);
5502#endif
5503#ifdef FEAT_CINDENT
5504 check_string_option(&buf->b_p_cink);
5505 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005506 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005507#endif
5508#ifdef FEAT_AUTOCMD
5509 check_string_option(&buf->b_p_ft);
5510#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5512 check_string_option(&buf->b_p_cinw);
5513#endif
5514#ifdef FEAT_INS_EXPAND
5515 check_string_option(&buf->b_p_cpt);
5516#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005517#ifdef FEAT_COMPL_FUNC
5518 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005519 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005520#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521#ifdef FEAT_KEYMAP
5522 check_string_option(&buf->b_p_keymap);
5523#endif
5524#ifdef FEAT_QUICKFIX
5525 check_string_option(&buf->b_p_gp);
5526 check_string_option(&buf->b_p_mp);
5527 check_string_option(&buf->b_p_efm);
5528#endif
5529 check_string_option(&buf->b_p_ep);
5530 check_string_option(&buf->b_p_path);
5531 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005532 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533#ifdef FEAT_INS_EXPAND
5534 check_string_option(&buf->b_p_dict);
5535 check_string_option(&buf->b_p_tsr);
5536#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005537#ifdef FEAT_LISP
5538 check_string_option(&buf->b_p_lw);
5539#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005540 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541}
5542
5543/*
5544 * Free the string allocated for an option.
5545 * Checks for the string being empty_option. This may happen if we're out of
5546 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5547 * check_options().
5548 * Does NOT check for P_ALLOCED flag!
5549 */
5550 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005551free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552{
5553 if (p != empty_option)
5554 vim_free(p);
5555}
5556
5557 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005558clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559{
5560 if (*pp != empty_option)
5561 vim_free(*pp);
5562 *pp = empty_option;
5563}
5564
5565 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005566check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005567{
5568 if (*pp == NULL)
5569 *pp = empty_option;
5570}
5571
5572/*
5573 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5574 */
5575 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005576set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577{
5578 int opt_idx;
5579
5580 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5581 if (options[opt_idx].var == (char_u *)p)
5582 {
5583 options[opt_idx].flags |= P_ALLOCED;
5584 return;
5585 }
5586 return; /* cannot happen: didn't find it! */
5587}
5588
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005589#if defined(FEAT_EVAL) || defined(PROTO)
5590/*
5591 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5592 * Return FALSE when it wasn't.
5593 * Return -1 for an unknown option.
5594 */
5595 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005596was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005597{
5598 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005599 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005600
5601 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005602 {
5603 flagp = insecure_flag(idx, opt_flags);
5604 return (*flagp & P_INSECURE) != 0;
5605 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005606 EMSG2(_(e_intern2), "was_set_insecurely()");
5607 return -1;
5608}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005609
5610/*
5611 * Get a pointer to the flags used for the P_INSECURE flag of option
5612 * "opt_idx". For some local options a local flags field is used.
5613 */
5614 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005615insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005616{
5617 if (opt_flags & OPT_LOCAL)
5618 switch ((int)options[opt_idx].indir)
5619 {
5620#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005621 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005622#endif
5623#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005624# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005625 case PV_FDE: return &curwin->w_p_fde_flags;
5626 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005627# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005628# ifdef FEAT_BEVAL
5629 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5630# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005631# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005632 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005633# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005634 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005635# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005636 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005637# endif
5638#endif
5639 }
5640
5641 /* Nothing special, return global flags field. */
5642 return &options[opt_idx].flags;
5643}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005644#endif
5645
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005646#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005647static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005648
5649/*
5650 * Redraw the window title and/or tab page text later.
5651 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005652static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005653{
5654 need_maketitle = TRUE;
5655# ifdef FEAT_WINDOWS
5656 redraw_tabline = TRUE;
5657# endif
5658}
5659#endif
5660
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661/*
5662 * Set a string option to a new value (without checking the effect).
5663 * The string is copied into allocated memory.
5664 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005665 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005666 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667 */
5668 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005669set_string_option_direct(
5670 char_u *name,
5671 int opt_idx,
5672 char_u *val,
5673 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5674 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675{
5676 char_u *s;
5677 char_u **varp;
5678 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005679 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680
Bram Moolenaar89d40322006-08-29 15:30:07 +00005681 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005683 idx = findoption(name);
5684 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005685 {
5686 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005687 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690 }
5691
Bram Moolenaar89d40322006-08-29 15:30:07 +00005692 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693 return;
5694
5695 s = vim_strsave(val);
5696 if (s != NULL)
5697 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005698 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005700 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 free_string_option(*varp);
5702 *varp = s;
5703
5704 /* For buffer/window local option may also set the global value. */
5705 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005706 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707
Bram Moolenaar89d40322006-08-29 15:30:07 +00005708 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709
5710 /* When setting both values of a global option with a local value,
5711 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005712 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713 {
5714 free_string_option(*varp);
5715 *varp = empty_option;
5716 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005717# ifdef FEAT_EVAL
5718 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005719 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005720 set_sid == 0 ? current_SID : set_sid);
5721# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722 }
5723}
5724
5725/*
5726 * Set global value for string option when it's a local option.
5727 */
5728 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005729set_string_option_global(
5730 int opt_idx, /* option index */
5731 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005732{
5733 char_u **p, *s;
5734
5735 /* the global value is always allocated */
5736 if (options[opt_idx].var == VAR_WIN)
5737 p = (char_u **)GLOBAL_WO(varp);
5738 else
5739 p = (char_u **)options[opt_idx].var;
5740 if (options[opt_idx].indir != PV_NONE
5741 && p != varp
5742 && (s = vim_strsave(*varp)) != NULL)
5743 {
5744 free_string_option(*p);
5745 *p = s;
5746 }
5747}
5748
5749/*
5750 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005751 *
5752 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005754 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005755set_string_option(
5756 int opt_idx,
5757 char_u *value,
5758 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759{
5760 char_u *s;
5761 char_u **varp;
5762 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005763#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5764 char_u *saved_oldval = NULL;
5765#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005766 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005767
5768 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005769 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770
5771 s = vim_strsave(value);
5772 if (s != NULL)
5773 {
5774 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5775 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005776 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005777 ? OPT_GLOBAL : OPT_LOCAL)
5778 : opt_flags);
5779 oldval = *varp;
5780 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005781
5782#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005783 if (!starting
5784# ifdef FEAT_CRYPT
5785 && options[opt_idx].indir != PV_KEY
5786# endif
5787 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005788 saved_oldval = vim_strsave(oldval);
5789#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005790 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5791 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005792 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005793
5794 /* call autocomamnd after handling side effects */
5795#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5796 if (saved_oldval != NULL)
5797 {
5798 char_u buf_type[7];
5799 sprintf((char *)buf_type, "%s",
5800 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005801 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5802 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005803 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5804 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5805 reset_v_option_vars();
5806 vim_free(saved_oldval);
5807 }
5808#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005809 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005810 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005811}
5812
5813/*
5814 * Handle string options that need some action to perform when changed.
5815 * Returns NULL for success, or an error message for an error.
5816 */
5817 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005818did_set_string_option(
5819 int opt_idx, /* index in options[] table */
5820 char_u **varp, /* pointer to the option variable */
5821 int new_value_alloced, /* new value was allocated */
5822 char_u *oldval, /* previous value of the option */
5823 char_u *errbuf, /* buffer for errors, or NULL */
5824 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005825{
5826 char_u *errmsg = NULL;
5827 char_u *s, *p;
5828 int did_chartab = FALSE;
5829 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005830 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005831#ifdef FEAT_GUI
5832 /* set when changing an option that only requires a redraw in the GUI */
5833 int redraw_gui_only = FALSE;
5834#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005835
5836 /* Get the global option to compare with, otherwise we would have to check
5837 * two values for all local options. */
5838 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5839
5840 /* Disallow changing some options from secure mode */
5841 if ((secure
5842#ifdef HAVE_SANDBOX
5843 || sandbox != 0
5844#endif
5845 ) && (options[opt_idx].flags & P_SECURE))
5846 {
5847 errmsg = e_secure;
5848 }
5849
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005850 /* Check for a "normal" file name in some options. Disallow a path
5851 * separator (slash and/or backslash), wildcards and characters that are
5852 * often illegal in a file name. */
5853 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005854 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005855 {
5856 errmsg = e_invarg;
5857 }
5858
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859 /* 'term' */
5860 else if (varp == &T_NAME)
5861 {
5862 if (T_NAME[0] == NUL)
5863 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5864#ifdef FEAT_GUI
5865 if (gui.in_use)
5866 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5867 else if (term_is_gui(T_NAME))
5868 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5869#endif
5870 else if (set_termname(T_NAME) == FAIL)
5871 errmsg = (char_u *)N_("E522: Not found in termcap");
5872 else
5873 /* Screen colors may have changed. */
5874 redraw_later_clear();
5875 }
5876
5877 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005878 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005880 char_u *bkc = p_bkc;
5881 unsigned int *flags = &bkc_flags;
5882
5883 if (opt_flags & OPT_LOCAL)
5884 {
5885 bkc = curbuf->b_p_bkc;
5886 flags = &curbuf->b_bkc_flags;
5887 }
5888
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005889 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5890 /* make the local value empty: use the global value */
5891 *flags = 0;
5892 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005894 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5895 errmsg = e_invarg;
5896 if ((((int)*flags & BKC_AUTO) != 0)
5897 + (((int)*flags & BKC_YES) != 0)
5898 + (((int)*flags & BKC_NO) != 0) != 1)
5899 {
5900 /* Must have exactly one of "auto", "yes" and "no". */
5901 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5902 errmsg = e_invarg;
5903 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 }
5905 }
5906
5907 /* 'backupext' and 'patchmode' */
5908 else if (varp == &p_bex || varp == &p_pm)
5909 {
5910 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5911 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5912 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5913 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005914#ifdef FEAT_LINEBREAK
5915 /* 'breakindentopt' */
5916 else if (varp == &curwin->w_p_briopt)
5917 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005918 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005919 errmsg = e_invarg;
5920 }
5921#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005922
5923 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005924 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005926 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927 */
5928 else if ( varp == &p_isi
5929 || varp == &(curbuf->b_p_isk)
5930 || varp == &p_isp
5931 || varp == &p_isf)
5932 {
5933 if (init_chartab() == FAIL)
5934 {
5935 did_chartab = TRUE; /* need to restore it below */
5936 errmsg = e_invarg; /* error in value */
5937 }
5938 }
5939
5940 /* 'helpfile' */
5941 else if (varp == &p_hf)
5942 {
5943 /* May compute new values for $VIM and $VIMRUNTIME */
5944 if (didset_vim)
5945 {
5946 vim_setenv((char_u *)"VIM", (char_u *)"");
5947 didset_vim = FALSE;
5948 }
5949 if (didset_vimruntime)
5950 {
5951 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5952 didset_vimruntime = FALSE;
5953 }
5954 }
5955
Bram Moolenaar1a384422010-07-14 19:53:30 +02005956#ifdef FEAT_SYN_HL
5957 /* 'colorcolumn' */
5958 else if (varp == &curwin->w_p_cc)
5959 errmsg = check_colorcolumn(curwin);
5960#endif
5961
Bram Moolenaar071d4272004-06-13 20:20:40 +00005962#ifdef FEAT_MULTI_LANG
5963 /* 'helplang' */
5964 else if (varp == &p_hlg)
5965 {
5966 /* Check for "", "ab", "ab,cd", etc. */
5967 for (s = p_hlg; *s != NUL; s += 3)
5968 {
5969 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5970 {
5971 errmsg = e_invarg;
5972 break;
5973 }
5974 if (s[2] == NUL)
5975 break;
5976 }
5977 }
5978#endif
5979
5980 /* 'highlight' */
5981 else if (varp == &p_hl)
5982 {
5983 if (highlight_changed() == FAIL)
5984 errmsg = e_invarg; /* invalid flags */
5985 }
5986
5987 /* 'nrformats' */
5988 else if (gvarp == &p_nf)
5989 {
5990 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5991 errmsg = e_invarg;
5992 }
5993
5994#ifdef FEAT_SESSION
5995 /* 'sessionoptions' */
5996 else if (varp == &p_ssop)
5997 {
5998 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5999 errmsg = e_invarg;
6000 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6001 {
6002 /* Don't allow both "sesdir" and "curdir". */
6003 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6004 errmsg = e_invarg;
6005 }
6006 }
6007 /* 'viewoptions' */
6008 else if (varp == &p_vop)
6009 {
6010 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6011 errmsg = e_invarg;
6012 }
6013#endif
6014
6015 /* 'scrollopt' */
6016#ifdef FEAT_SCROLLBIND
6017 else if (varp == &p_sbo)
6018 {
6019 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6020 errmsg = e_invarg;
6021 }
6022#endif
6023
6024 /* 'ambiwidth' */
6025#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006026 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006027 {
6028 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6029 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006030 else if (set_chars_option(&p_lcs) != NULL)
6031 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6032# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6033 else if (set_chars_option(&p_fcs) != NULL)
6034 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6035# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006036 }
6037#endif
6038
6039 /* 'background' */
6040 else if (varp == &p_bg)
6041 {
6042 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6043 {
6044#ifdef FEAT_EVAL
6045 int dark = (*p_bg == 'd');
6046#endif
6047
6048 init_highlight(FALSE, FALSE);
6049
6050#ifdef FEAT_EVAL
6051 if (dark != (*p_bg == 'd')
6052 && get_var_value((char_u *)"g:colors_name") != NULL)
6053 {
6054 /* The color scheme must have set 'background' back to another
6055 * value, that's not what we want here. Disable the color
6056 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006057 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058 free_string_option(p_bg);
6059 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6060 check_string_option(&p_bg);
6061 init_highlight(FALSE, FALSE);
6062 }
6063#endif
6064 }
6065 else
6066 errmsg = e_invarg;
6067 }
6068
6069 /* 'wildmode' */
6070 else if (varp == &p_wim)
6071 {
6072 if (check_opt_wim() == FAIL)
6073 errmsg = e_invarg;
6074 }
6075
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006076#ifdef FEAT_CMDL_COMPL
6077 /* 'wildoptions' */
6078 else if (varp == &p_wop)
6079 {
6080 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6081 errmsg = e_invarg;
6082 }
6083#endif
6084
Bram Moolenaar071d4272004-06-13 20:20:40 +00006085#ifdef FEAT_WAK
6086 /* 'winaltkeys' */
6087 else if (varp == &p_wak)
6088 {
6089 if (*p_wak == NUL
6090 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6091 errmsg = e_invarg;
6092# ifdef FEAT_MENU
6093# ifdef FEAT_GUI_MOTIF
6094 else if (gui.in_use)
6095 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6096# else
6097# ifdef FEAT_GUI_GTK
6098 else if (gui.in_use)
6099 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6100# endif
6101# endif
6102# endif
6103 }
6104#endif
6105
6106#ifdef FEAT_AUTOCMD
6107 /* 'eventignore' */
6108 else if (varp == &p_ei)
6109 {
6110 if (check_ei() == FAIL)
6111 errmsg = e_invarg;
6112 }
6113#endif
6114
6115#ifdef FEAT_MBYTE
6116 /* 'encoding' and 'fileencoding' */
6117 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6118 {
6119 if (gvarp == &p_fenc)
6120 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006121 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006122 errmsg = e_modifiable;
6123 else if (vim_strchr(*varp, ',') != NULL)
6124 /* No comma allowed in 'fileencoding'; catches confusing it
6125 * with 'fileencodings'. */
6126 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006128 {
6129# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006131 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006133 /* Add 'fileencoding' to the swap file. */
6134 ml_setflags(curbuf);
6135 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136 }
6137 if (errmsg == NULL)
6138 {
6139 /* canonize the value, so that STRCMP() can be used on it */
6140 p = enc_canonize(*varp);
6141 if (p != NULL)
6142 {
6143 vim_free(*varp);
6144 *varp = p;
6145 }
6146 if (varp == &p_enc)
6147 {
6148 errmsg = mb_init();
6149# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006150 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151# endif
6152 }
6153 }
6154
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006155# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6157 {
6158 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6159 if (STRCMP(p_tenc, "utf-8") != 0)
6160 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6161 }
6162# endif
6163
6164 if (errmsg == NULL)
6165 {
6166# ifdef FEAT_KEYMAP
6167 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6168 * (with another encoding). */
6169 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6170 (void)keymap_init();
6171# endif
6172
6173 /* When 'termencoding' is not empty and 'encoding' changes or when
6174 * 'termencoding' changes, need to setup for keyboard input and
6175 * display output conversion. */
6176 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6177 {
6178 convert_setup(&input_conv, p_tenc, p_enc);
6179 convert_setup(&output_conv, p_enc, p_tenc);
6180 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006181
6182# if defined(WIN3264) && defined(FEAT_MBYTE)
6183 /* $HOME may have characters in active code page. */
6184 if (varp == &p_enc)
6185 init_homedir();
6186# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006187 }
6188 }
6189#endif
6190
6191#if defined(FEAT_POSTSCRIPT)
6192 else if (varp == &p_penc)
6193 {
6194 /* Canonize printencoding if VIM standard one */
6195 p = enc_canonize(p_penc);
6196 if (p != NULL)
6197 {
6198 vim_free(p_penc);
6199 p_penc = p;
6200 }
6201 else
6202 {
6203 /* Ensure lower case and '-' for '_' */
6204 for (s = p_penc; *s != NUL; s++)
6205 {
6206 if (*s == '_')
6207 *s = '-';
6208 else
6209 *s = TOLOWER_ASC(*s);
6210 }
6211 }
6212 }
6213#endif
6214
Bram Moolenaar9372a112005-12-06 19:59:18 +00006215#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006216 else if (varp == &p_imak)
6217 {
6218 if (gui.in_use && !im_xim_isvalid_imactivate())
6219 errmsg = e_invarg;
6220 }
6221#endif
6222
6223#ifdef FEAT_KEYMAP
6224 else if (varp == &curbuf->b_p_keymap)
6225 {
6226 /* load or unload key mapping tables */
6227 errmsg = keymap_init();
6228
Bram Moolenaarfab06232009-03-04 03:13:35 +00006229 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006230 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006231 if (*curbuf->b_p_keymap != NUL)
6232 {
6233 /* Installed a new keymap, switch on using it. */
6234 curbuf->b_p_iminsert = B_IMODE_LMAP;
6235 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6236 curbuf->b_p_imsearch = B_IMODE_LMAP;
6237 }
6238 else
6239 {
6240 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6241 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6242 curbuf->b_p_iminsert = B_IMODE_NONE;
6243 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6244 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6245 }
6246 if ((opt_flags & OPT_LOCAL) == 0)
6247 {
6248 set_iminsert_global();
6249 set_imsearch_global();
6250 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251# ifdef FEAT_WINDOWS
6252 status_redraw_curbuf();
6253# endif
6254 }
6255 }
6256#endif
6257
6258 /* 'fileformat' */
6259 else if (gvarp == &p_ff)
6260 {
6261 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6262 errmsg = e_modifiable;
6263 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6264 errmsg = e_invarg;
6265 else
6266 {
6267 /* may also change 'textmode' */
6268 if (get_fileformat(curbuf) == EOL_DOS)
6269 curbuf->b_p_tx = TRUE;
6270 else
6271 curbuf->b_p_tx = FALSE;
6272#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006273 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006274#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006275 /* update flag in swap file */
6276 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006277 /* Redraw needed when switching to/from "mac": a CR in the text
6278 * will be displayed differently. */
6279 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6280 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006281 }
6282 }
6283
6284 /* 'fileformats' */
6285 else if (varp == &p_ffs)
6286 {
6287 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6288 errmsg = e_invarg;
6289 else
6290 {
6291 /* also change 'textauto' */
6292 if (*p_ffs == NUL)
6293 p_ta = FALSE;
6294 else
6295 p_ta = TRUE;
6296 }
6297 }
6298
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006299#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006300 /* 'cryptkey' */
6301 else if (gvarp == &p_key)
6302 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006303# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006304 /* Make sure the ":set" command doesn't show the new value in the
6305 * history. */
6306 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006307# endif
6308 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6309 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006310 ml_set_crypt_key(curbuf, oldval,
6311 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006312 }
6313
6314 else if (gvarp == &p_cm)
6315 {
6316 if (opt_flags & OPT_LOCAL)
6317 p = curbuf->b_p_cm;
6318 else
6319 p = p_cm;
6320 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6321 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006322 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006323 errmsg = e_invarg;
6324 else
6325 {
6326 /* When setting the global value to empty, make it "zip". */
6327 if (*p_cm == NUL)
6328 {
6329 if (new_value_alloced)
6330 free_string_option(p_cm);
6331 p_cm = vim_strsave((char_u *)"zip");
6332 new_value_alloced = TRUE;
6333 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006334 /* When using ":set cm=name" the local value is going to be empty.
6335 * Do that here, otherwise the crypt functions will still use the
6336 * local value. */
6337 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6338 {
6339 free_string_option(curbuf->b_p_cm);
6340 curbuf->b_p_cm = empty_option;
6341 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006342
6343 /* Need to update the swapfile when the effective method changed.
6344 * Set "s" to the effective old value, "p" to the effective new
6345 * method and compare. */
6346 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6347 s = p_cm; /* was previously using the global value */
6348 else
6349 s = oldval;
6350 if (*curbuf->b_p_cm == NUL)
6351 p = p_cm; /* is now using the global value */
6352 else
6353 p = curbuf->b_p_cm;
6354 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006355 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006356
6357 /* If the global value changes need to update the swapfile for all
6358 * buffers using that value. */
6359 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6360 {
6361 buf_T *buf;
6362
Bram Moolenaar29323592016-07-24 22:04:11 +02006363 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006364 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006365 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006366 }
6367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006368 }
6369#endif
6370
6371 /* 'matchpairs' */
6372 else if (gvarp == &p_mps)
6373 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006374#ifdef FEAT_MBYTE
6375 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006376 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006377 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006378 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006379 int x2 = -1;
6380 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006381
6382 if (*p != NUL)
6383 p += mb_ptr2len(p);
6384 if (*p != NUL)
6385 x2 = *p++;
6386 if (*p != NUL)
6387 {
6388 x3 = mb_ptr2char(p);
6389 p += mb_ptr2len(p);
6390 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006391 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006392 {
6393 errmsg = e_invarg;
6394 break;
6395 }
6396 if (*p == NUL)
6397 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006398 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006399 }
6400 else
6401#endif
6402 {
6403 /* Check for "x:y,x:y" */
6404 for (p = *varp; *p != NUL; p += 4)
6405 {
6406 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6407 {
6408 errmsg = e_invarg;
6409 break;
6410 }
6411 if (p[3] == NUL)
6412 break;
6413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006414 }
6415 }
6416
6417#ifdef FEAT_COMMENTS
6418 /* 'comments' */
6419 else if (gvarp == &p_com)
6420 {
6421 for (s = *varp; *s; )
6422 {
6423 while (*s && *s != ':')
6424 {
6425 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6426 && !VIM_ISDIGIT(*s) && *s != '-')
6427 {
6428 errmsg = illegal_char(errbuf, *s);
6429 break;
6430 }
6431 ++s;
6432 }
6433 if (*s++ == NUL)
6434 errmsg = (char_u *)N_("E524: Missing colon");
6435 else if (*s == ',' || *s == NUL)
6436 errmsg = (char_u *)N_("E525: Zero length string");
6437 if (errmsg != NULL)
6438 break;
6439 while (*s && *s != ',')
6440 {
6441 if (*s == '\\' && s[1] != NUL)
6442 ++s;
6443 ++s;
6444 }
6445 s = skip_to_option_part(s);
6446 }
6447 }
6448#endif
6449
6450 /* 'listchars' */
6451 else if (varp == &p_lcs)
6452 {
6453 errmsg = set_chars_option(varp);
6454 }
6455
6456#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6457 /* 'fillchars' */
6458 else if (varp == &p_fcs)
6459 {
6460 errmsg = set_chars_option(varp);
6461 }
6462#endif
6463
6464#ifdef FEAT_CMDWIN
6465 /* 'cedit' */
6466 else if (varp == &p_cedit)
6467 {
6468 errmsg = check_cedit();
6469 }
6470#endif
6471
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006472 /* 'verbosefile' */
6473 else if (varp == &p_vfile)
6474 {
6475 verbose_stop();
6476 if (*p_vfile != NUL && verbose_open() == FAIL)
6477 errmsg = e_invarg;
6478 }
6479
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480#ifdef FEAT_VIMINFO
6481 /* 'viminfo' */
6482 else if (varp == &p_viminfo)
6483 {
6484 for (s = p_viminfo; *s;)
6485 {
6486 /* Check it's a valid character */
6487 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6488 {
6489 errmsg = illegal_char(errbuf, *s);
6490 break;
6491 }
6492 if (*s == 'n') /* name is always last one */
6493 {
6494 break;
6495 }
6496 else if (*s == 'r') /* skip until next ',' */
6497 {
6498 while (*++s && *s != ',')
6499 ;
6500 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006501 else if (*s == '%')
6502 {
6503 /* optional number */
6504 while (vim_isdigit(*++s))
6505 ;
6506 }
6507 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006508 ++s; /* no extra chars */
6509 else /* must have a number */
6510 {
6511 while (vim_isdigit(*++s))
6512 ;
6513
6514 if (!VIM_ISDIGIT(*(s - 1)))
6515 {
6516 if (errbuf != NULL)
6517 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006518 sprintf((char *)errbuf,
6519 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006520 transchar_byte(*(s - 1)));
6521 errmsg = errbuf;
6522 }
6523 else
6524 errmsg = (char_u *)"";
6525 break;
6526 }
6527 }
6528 if (*s == ',')
6529 ++s;
6530 else if (*s)
6531 {
6532 if (errbuf != NULL)
6533 errmsg = (char_u *)N_("E527: Missing comma");
6534 else
6535 errmsg = (char_u *)"";
6536 break;
6537 }
6538 }
6539 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6540 errmsg = (char_u *)N_("E528: Must specify a ' value");
6541 }
6542#endif /* FEAT_VIMINFO */
6543
6544 /* terminal options */
6545 else if (istermoption(&options[opt_idx]) && full_screen)
6546 {
6547 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6548 if (varp == &T_CCO)
6549 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006550 int colors = atoi((char *)T_CCO);
6551
6552 /* Only reinitialize colors if t_Co value has really changed to
6553 * avoid expensive reload of colorscheme if t_Co is set to the
6554 * same value multiple times. */
6555 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006556 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006557 t_colors = colors;
6558 if (t_colors <= 1)
6559 {
6560 if (new_value_alloced)
6561 vim_free(T_CCO);
6562 T_CCO = empty_option;
6563 }
6564 /* We now have a different color setup, initialize it again. */
6565 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 }
6568 ttest(FALSE);
6569 if (varp == &T_ME)
6570 {
6571 out_str(T_ME);
6572 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006573#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006574 /* Since t_me has been set, this probably means that the user
6575 * wants to use this as default colors. Need to reset default
6576 * background/foreground colors. */
6577 mch_set_normal_colors();
6578#endif
6579 }
6580 }
6581
6582#ifdef FEAT_LINEBREAK
6583 /* 'showbreak' */
6584 else if (varp == &p_sbr)
6585 {
6586 for (s = p_sbr; *s; )
6587 {
6588 if (ptr2cells(s) != 1)
6589 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006590 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006591 }
6592 }
6593#endif
6594
6595#ifdef FEAT_GUI
6596 /* 'guifont' */
6597 else if (varp == &p_guifont)
6598 {
6599 if (gui.in_use)
6600 {
6601 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006602# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006603 /*
6604 * Put up a font dialog and let the user select a new value.
6605 * If this is cancelled go back to the old value but don't
6606 * give an error message.
6607 */
6608 if (STRCMP(p, "*") == 0)
6609 {
6610 p = gui_mch_font_dialog(oldval);
6611
6612 if (new_value_alloced)
6613 free_string_option(p_guifont);
6614
6615 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6616 new_value_alloced = TRUE;
6617 }
6618# endif
6619 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6620 {
6621# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6622 if (STRCMP(p_guifont, "*") == 0)
6623 {
6624 /* Dialog was cancelled: Keep the old value without giving
6625 * an error message. */
6626 if (new_value_alloced)
6627 free_string_option(p_guifont);
6628 p_guifont = vim_strsave(oldval);
6629 new_value_alloced = TRUE;
6630 }
6631 else
6632# endif
6633 errmsg = (char_u *)N_("E596: Invalid font(s)");
6634 }
6635 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006636 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006637 }
6638# ifdef FEAT_XFONTSET
6639 else if (varp == &p_guifontset)
6640 {
6641 if (STRCMP(p_guifontset, "*") == 0)
6642 errmsg = (char_u *)N_("E597: can't select fontset");
6643 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6644 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006645 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006646 }
6647# endif
6648# ifdef FEAT_MBYTE
6649 else if (varp == &p_guifontwide)
6650 {
6651 if (STRCMP(p_guifontwide, "*") == 0)
6652 errmsg = (char_u *)N_("E533: can't select wide font");
6653 else if (gui_get_wide_font() == FAIL)
6654 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006655 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006656 }
6657# endif
6658#endif
6659
6660#ifdef CURSOR_SHAPE
6661 /* 'guicursor' */
6662 else if (varp == &p_guicursor)
6663 errmsg = parse_shape_opt(SHAPE_CURSOR);
6664#endif
6665
6666#ifdef FEAT_MOUSESHAPE
6667 /* 'mouseshape' */
6668 else if (varp == &p_mouseshape)
6669 {
6670 errmsg = parse_shape_opt(SHAPE_MOUSE);
6671 update_mouseshape(-1);
6672 }
6673#endif
6674
6675#ifdef FEAT_PRINTER
6676 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006677 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006678# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006679 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006680 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006681# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006682#endif
6683
6684#ifdef FEAT_LANGMAP
6685 /* 'langmap' */
6686 else if (varp == &p_langmap)
6687 langmap_set();
6688#endif
6689
6690#ifdef FEAT_LINEBREAK
6691 /* 'breakat' */
6692 else if (varp == &p_breakat)
6693 fill_breakat_flags();
6694#endif
6695
6696#ifdef FEAT_TITLE
6697 /* 'titlestring' and 'iconstring' */
6698 else if (varp == &p_titlestring || varp == &p_iconstring)
6699 {
6700# ifdef FEAT_STL_OPT
6701 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6702
6703 /* NULL => statusline syntax */
6704 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6705 stl_syntax |= flagval;
6706 else
6707 stl_syntax &= ~flagval;
6708# endif
6709 did_set_title(varp == &p_iconstring);
6710
6711 }
6712#endif
6713
6714#ifdef FEAT_GUI
6715 /* 'guioptions' */
6716 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006717 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006718 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006719 redraw_gui_only = TRUE;
6720 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006721#endif
6722
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006723#if defined(FEAT_GUI_TABLINE)
6724 /* 'guitablabel' */
6725 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006726 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006727 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006728 redraw_gui_only = TRUE;
6729 }
6730 /* 'guitabtooltip' */
6731 else if (varp == &p_gtt)
6732 {
6733 redraw_gui_only = TRUE;
6734 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006735#endif
6736
Bram Moolenaar071d4272004-06-13 20:20:40 +00006737#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6738 /* 'ttymouse' */
6739 else if (varp == &p_ttym)
6740 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006741 /* Switch the mouse off before changing the escape sequences used for
6742 * that. */
6743 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006744 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6745 errmsg = e_invarg;
6746 else
6747 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006748 if (termcap_active)
6749 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006750 }
6751#endif
6752
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753 /* 'selection' */
6754 else if (varp == &p_sel)
6755 {
6756 if (*p_sel == NUL
6757 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6758 errmsg = e_invarg;
6759 }
6760
6761 /* 'selectmode' */
6762 else if (varp == &p_slm)
6763 {
6764 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6765 errmsg = e_invarg;
6766 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006767
6768#ifdef FEAT_BROWSE
6769 /* 'browsedir' */
6770 else if (varp == &p_bsdir)
6771 {
6772 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6773 && !mch_isdir(p_bsdir))
6774 errmsg = e_invarg;
6775 }
6776#endif
6777
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778 /* 'keymodel' */
6779 else if (varp == &p_km)
6780 {
6781 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6782 errmsg = e_invarg;
6783 else
6784 {
6785 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6786 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6787 }
6788 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006789
6790 /* 'mousemodel' */
6791 else if (varp == &p_mousem)
6792 {
6793 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6794 errmsg = e_invarg;
6795#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6796 else if (*p_mousem != *oldval)
6797 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6798 * to create or delete the popup menus. */
6799 gui_motif_update_mousemodel(root_menu);
6800#endif
6801 }
6802
6803 /* 'switchbuf' */
6804 else if (varp == &p_swb)
6805 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006806 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006807 errmsg = e_invarg;
6808 }
6809
6810 /* 'debug' */
6811 else if (varp == &p_debug)
6812 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006813 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006814 errmsg = e_invarg;
6815 }
6816
6817 /* 'display' */
6818 else if (varp == &p_dy)
6819 {
6820 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6821 errmsg = e_invarg;
6822 else
6823 (void)init_chartab();
6824
6825 }
6826
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006827#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 /* 'eadirection' */
6829 else if (varp == &p_ead)
6830 {
6831 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6832 errmsg = e_invarg;
6833 }
6834#endif
6835
6836#ifdef FEAT_CLIPBOARD
6837 /* 'clipboard' */
6838 else if (varp == &p_cb)
6839 errmsg = check_clipboard_option();
6840#endif
6841
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006842#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006843 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6844 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006845 else if (varp == &(curwin->w_s->b_p_spl)
6846 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006847 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006848 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006849 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006850 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006851 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006852 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006853 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006854 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006855 /* 'spellsuggest' */
6856 else if (varp == &p_sps)
6857 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006858 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006859 errmsg = e_invarg;
6860 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006861 /* 'mkspellmem' */
6862 else if (varp == &p_msm)
6863 {
6864 if (spell_check_msm() != OK)
6865 errmsg = e_invarg;
6866 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006867#endif
6868
Bram Moolenaar071d4272004-06-13 20:20:40 +00006869#ifdef FEAT_QUICKFIX
6870 /* When 'bufhidden' is set, check for valid value. */
6871 else if (gvarp == &p_bh)
6872 {
6873 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6874 errmsg = e_invarg;
6875 }
6876
6877 /* When 'buftype' is set, check for valid value. */
6878 else if (gvarp == &p_bt)
6879 {
6880 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6881 errmsg = e_invarg;
6882 else
6883 {
6884# ifdef FEAT_WINDOWS
6885 if (curwin->w_status_height)
6886 {
6887 curwin->w_redr_status = TRUE;
6888 redraw_later(VALID);
6889 }
6890# endif
6891 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006892# ifdef FEAT_TITLE
6893 redraw_titles();
6894# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006895 }
6896 }
6897#endif
6898
6899#ifdef FEAT_STL_OPT
6900 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006901 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006902 {
6903 int wid;
6904
6905 if (varp == &p_ruf) /* reset ru_wid first */
6906 ru_wid = 0;
6907 s = *varp;
6908 if (varp == &p_ruf && *s == '%')
6909 {
6910 /* set ru_wid if 'ruf' starts with "%99(" */
6911 if (*++s == '-') /* ignore a '-' */
6912 s++;
6913 wid = getdigits(&s);
6914 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6915 ru_wid = wid;
6916 else
6917 errmsg = check_stl_option(p_ruf);
6918 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006919 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006920 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006921 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006922 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923 comp_col();
6924 }
6925#endif
6926
6927#ifdef FEAT_INS_EXPAND
6928 /* check if it is a valid value for 'complete' -- Acevedo */
6929 else if (gvarp == &p_cpt)
6930 {
6931 for (s = *varp; *s;)
6932 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006933 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006934 s++;
6935 if (!*s)
6936 break;
6937 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6938 {
6939 errmsg = illegal_char(errbuf, *s);
6940 break;
6941 }
6942 if (*++s != NUL && *s != ',' && *s != ' ')
6943 {
6944 if (s[-1] == 'k' || s[-1] == 's')
6945 {
6946 /* skip optional filename after 'k' and 's' */
6947 while (*s && *s != ',' && *s != ' ')
6948 {
6949 if (*s == '\\')
6950 ++s;
6951 ++s;
6952 }
6953 }
6954 else
6955 {
6956 if (errbuf != NULL)
6957 {
6958 sprintf((char *)errbuf,
6959 _("E535: Illegal character after <%c>"),
6960 *--s);
6961 errmsg = errbuf;
6962 }
6963 else
6964 errmsg = (char_u *)"";
6965 break;
6966 }
6967 }
6968 }
6969 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006970
6971 /* 'completeopt' */
6972 else if (varp == &p_cot)
6973 {
6974 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6975 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02006976 else
6977 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006978 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979#endif /* FEAT_INS_EXPAND */
6980
6981
6982#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6983 else if (varp == &p_toolbar)
6984 {
6985 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6986 &toolbar_flags, TRUE) != OK)
6987 errmsg = e_invarg;
6988 else
6989 {
6990 out_flush();
6991 gui_mch_show_toolbar((toolbar_flags &
6992 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6993 }
6994 }
6995#endif
6996
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006997#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006998 /* 'toolbariconsize': GTK+ 2 only */
6999 else if (varp == &p_tbis)
7000 {
7001 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7002 errmsg = e_invarg;
7003 else
7004 {
7005 out_flush();
7006 gui_mch_show_toolbar((toolbar_flags &
7007 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7008 }
7009 }
7010#endif
7011
7012 /* 'pastetoggle': translate key codes like in a mapping */
7013 else if (varp == &p_pt)
7014 {
7015 if (*p_pt)
7016 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007017 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018 if (p != NULL)
7019 {
7020 if (new_value_alloced)
7021 free_string_option(p_pt);
7022 p_pt = p;
7023 new_value_alloced = TRUE;
7024 }
7025 }
7026 }
7027
7028 /* 'backspace' */
7029 else if (varp == &p_bs)
7030 {
7031 if (VIM_ISDIGIT(*p_bs))
7032 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007033 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034 errmsg = e_invarg;
7035 }
7036 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7037 errmsg = e_invarg;
7038 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007039 else if (varp == &p_bo)
7040 {
7041 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7042 errmsg = e_invarg;
7043 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007045 /* 'tagcase' */
7046 else if (gvarp == &p_tc)
7047 {
7048 unsigned int *flags;
7049
7050 if (opt_flags & OPT_LOCAL)
7051 {
7052 p = curbuf->b_p_tc;
7053 flags = &curbuf->b_tc_flags;
7054 }
7055 else
7056 {
7057 p = p_tc;
7058 flags = &tc_flags;
7059 }
7060
7061 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7062 /* make the local value empty: use the global value */
7063 *flags = 0;
7064 else if (*p == NUL
7065 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7066 errmsg = e_invarg;
7067 }
7068
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007069#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 /* 'casemap' */
7071 else if (varp == &p_cmp)
7072 {
7073 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7074 errmsg = e_invarg;
7075 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007076#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077
7078#ifdef FEAT_DIFF
7079 /* 'diffopt' */
7080 else if (varp == &p_dip)
7081 {
7082 if (diffopt_changed() == FAIL)
7083 errmsg = e_invarg;
7084 }
7085#endif
7086
7087#ifdef FEAT_FOLDING
7088 /* 'foldmethod' */
7089 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7090 {
7091 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7092 || *curwin->w_p_fdm == NUL)
7093 errmsg = e_invarg;
7094 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007095 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007097 if (foldmethodIsDiff(curwin))
7098 newFoldLevel();
7099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100 }
7101# ifdef FEAT_EVAL
7102 /* 'foldexpr' */
7103 else if (varp == &curwin->w_p_fde)
7104 {
7105 if (foldmethodIsExpr(curwin))
7106 foldUpdateAll(curwin);
7107 }
7108# endif
7109 /* 'foldmarker' */
7110 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7111 {
7112 p = vim_strchr(*varp, ',');
7113 if (p == NULL)
7114 errmsg = (char_u *)N_("E536: comma required");
7115 else if (p == *varp || p[1] == NUL)
7116 errmsg = e_invarg;
7117 else if (foldmethodIsMarker(curwin))
7118 foldUpdateAll(curwin);
7119 }
7120 /* 'commentstring' */
7121 else if (gvarp == &p_cms)
7122 {
7123 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7124 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7125 }
7126 /* 'foldopen' */
7127 else if (varp == &p_fdo)
7128 {
7129 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7130 errmsg = e_invarg;
7131 }
7132 /* 'foldclose' */
7133 else if (varp == &p_fcl)
7134 {
7135 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7136 errmsg = e_invarg;
7137 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007138 /* 'foldignore' */
7139 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7140 {
7141 if (foldmethodIsIndent(curwin))
7142 foldUpdateAll(curwin);
7143 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144#endif
7145
7146#ifdef FEAT_VIRTUALEDIT
7147 /* 'virtualedit' */
7148 else if (varp == &p_ve)
7149 {
7150 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7151 errmsg = e_invarg;
7152 else if (STRCMP(p_ve, oldval) != 0)
7153 {
7154 /* Recompute cursor position in case the new 've' setting
7155 * changes something. */
7156 validate_virtcol();
7157 coladvance(curwin->w_virtcol);
7158 }
7159 }
7160#endif
7161
7162#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7163 else if (varp == &p_csqf)
7164 {
7165 if (p_csqf != NULL)
7166 {
7167 p = p_csqf;
7168 while (*p != NUL)
7169 {
7170 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7171 || p[1] == NUL
7172 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7173 || (p[2] != NUL && p[2] != ','))
7174 {
7175 errmsg = e_invarg;
7176 break;
7177 }
7178 else if (p[2] == NUL)
7179 break;
7180 else
7181 p += 3;
7182 }
7183 }
7184 }
7185#endif
7186
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007187#ifdef FEAT_CINDENT
7188 /* 'cinoptions' */
7189 else if (gvarp == &p_cino)
7190 {
7191 /* TODO: recognize errors */
7192 parse_cino(curbuf);
7193 }
7194#endif
7195
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007196#if defined(FEAT_RENDER_OPTIONS)
7197 else if (varp == &p_rop && gui.in_use)
7198 {
7199 if (!gui_mch_set_rendering_options(p_rop))
7200 errmsg = e_invarg;
7201 }
7202#endif
7203
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204 /* Options that are a list of flags. */
7205 else
7206 {
7207 p = NULL;
7208 if (varp == &p_ww)
7209 p = (char_u *)WW_ALL;
7210 if (varp == &p_shm)
7211 p = (char_u *)SHM_ALL;
7212 else if (varp == &(p_cpo))
7213 p = (char_u *)CPO_ALL;
7214 else if (varp == &(curbuf->b_p_fo))
7215 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007216#ifdef FEAT_CONCEAL
7217 else if (varp == &curwin->w_p_cocu)
7218 p = (char_u *)COCU_ALL;
7219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220 else if (varp == &p_mouse)
7221 {
7222#ifdef FEAT_MOUSE
7223 p = (char_u *)MOUSE_ALL;
7224#else
7225 if (*p_mouse != NUL)
7226 errmsg = (char_u *)N_("E538: No mouse support");
7227#endif
7228 }
7229#if defined(FEAT_GUI)
7230 else if (varp == &p_go)
7231 p = (char_u *)GO_ALL;
7232#endif
7233 if (p != NULL)
7234 {
7235 for (s = *varp; *s; ++s)
7236 if (vim_strchr(p, *s) == NULL)
7237 {
7238 errmsg = illegal_char(errbuf, *s);
7239 break;
7240 }
7241 }
7242 }
7243
7244 /*
7245 * If error detected, restore the previous value.
7246 */
7247 if (errmsg != NULL)
7248 {
7249 if (new_value_alloced)
7250 free_string_option(*varp);
7251 *varp = oldval;
7252 /*
7253 * When resetting some values, need to act on it.
7254 */
7255 if (did_chartab)
7256 (void)init_chartab();
7257 if (varp == &p_hl)
7258 (void)highlight_changed();
7259 }
7260 else
7261 {
7262#ifdef FEAT_EVAL
7263 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007264 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007265#endif
7266 /*
7267 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007268 * Use "free_oldval", because recursiveness may change the flags under
7269 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007270 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007271 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007272 free_string_option(oldval);
7273 if (new_value_alloced)
7274 options[opt_idx].flags |= P_ALLOCED;
7275 else
7276 options[opt_idx].flags &= ~P_ALLOCED;
7277
7278 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007279 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 {
7281 /* global option with local value set to use global value; free
7282 * the local value and make it empty */
7283 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7284 free_string_option(*(char_u **)p);
7285 *(char_u **)p = empty_option;
7286 }
7287
7288 /* May set global value for local option. */
7289 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7290 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007291
7292#ifdef FEAT_AUTOCMD
7293 /*
7294 * Trigger the autocommand only after setting the flags.
7295 */
7296# ifdef FEAT_SYN_HL
7297 /* When 'syntax' is set, load the syntax of that name */
7298 if (varp == &(curbuf->b_p_syn))
7299 {
7300 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7301 curbuf->b_fname, TRUE, curbuf);
7302 }
7303# endif
7304 else if (varp == &(curbuf->b_p_ft))
7305 {
7306 /* 'filetype' is set, trigger the FileType autocommand */
7307 did_filetype = TRUE;
7308 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7309 curbuf->b_fname, TRUE, curbuf);
7310 }
7311#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007312#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007313 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007314 {
7315 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007316 char_u *q = curwin->w_s->b_p_spl;
7317
7318 /* Skip the first name if it is "cjk". */
7319 if (STRNCMP(q, "cjk,", 4) == 0)
7320 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007321
7322 /*
7323 * Source the spell/LANG.vim in 'runtimepath'.
7324 * They could set 'spellcapcheck' depending on the language.
7325 * Use the first name in 'spelllang' up to '_region' or
7326 * '.encoding'.
7327 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007328 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007329 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7330 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007331 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007332 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007333 }
7334#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007335 }
7336
7337#ifdef FEAT_MOUSE
7338 if (varp == &p_mouse)
7339 {
7340# ifdef FEAT_MOUSE_TTY
7341 if (*p_mouse == NUL)
7342 mch_setmouse(FALSE); /* switch mouse off */
7343 else
7344# endif
7345 setmouse(); /* in case 'mouse' changed */
7346 }
7347#endif
7348
Bram Moolenaar913077c2012-03-28 19:59:04 +02007349 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007350 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007351 curwin->w_set_curswant = TRUE;
7352
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007353#ifdef FEAT_GUI
7354 /* check redraw when it's not a GUI option or the GUI is active. */
7355 if (!redraw_gui_only || gui.in_use)
7356#endif
7357 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358
7359 return errmsg;
7360}
7361
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007362#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007363/*
7364 * Simple int comparison function for use with qsort()
7365 */
7366 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007367int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007368{
7369 return *(const int *)a - *(const int *)b;
7370}
7371
7372/*
7373 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7374 * Returns error message, NULL if it's OK.
7375 */
7376 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007377check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007378{
7379 char_u *s;
7380 int col;
7381 int count = 0;
7382 int color_cols[256];
7383 int i;
7384 int j = 0;
7385
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007386 if (wp->w_buffer == NULL)
7387 return NULL; /* buffer was closed */
7388
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007389 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007390 {
7391 if (*s == '-' || *s == '+')
7392 {
7393 /* -N and +N: add to 'textwidth' */
7394 col = (*s == '-') ? -1 : 1;
7395 ++s;
7396 if (!VIM_ISDIGIT(*s))
7397 return e_invarg;
7398 col = col * getdigits(&s);
7399 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007400 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007401 col += wp->w_buffer->b_p_tw;
7402 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007403 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007404 }
7405 else if (VIM_ISDIGIT(*s))
7406 col = getdigits(&s);
7407 else
7408 return e_invarg;
7409 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007410skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007411 if (*s == NUL)
7412 break;
7413 if (*s != ',')
7414 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007415 if (*++s == NUL)
7416 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007417 }
7418
7419 vim_free(wp->w_p_cc_cols);
7420 if (count == 0)
7421 wp->w_p_cc_cols = NULL;
7422 else
7423 {
7424 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7425 if (wp->w_p_cc_cols != NULL)
7426 {
7427 /* sort the columns for faster usage on screen redraw inside
7428 * win_line() */
7429 qsort(color_cols, count, sizeof(int), int_cmp);
7430
7431 for (i = 0; i < count; ++i)
7432 /* skip duplicates */
7433 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7434 wp->w_p_cc_cols[j++] = color_cols[i];
7435 wp->w_p_cc_cols[j] = -1; /* end marker */
7436 }
7437 }
7438
7439 return NULL; /* no error */
7440}
7441#endif
7442
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443/*
7444 * Handle setting 'listchars' or 'fillchars'.
7445 * Returns error message, NULL if it's OK.
7446 */
7447 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007448set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449{
7450 int round, i, len, entries;
7451 char_u *p, *s;
7452 int c1, c2 = 0;
7453 struct charstab
7454 {
7455 int *cp;
7456 char *name;
7457 };
7458#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7459 static struct charstab filltab[] =
7460 {
7461 {&fill_stl, "stl"},
7462 {&fill_stlnc, "stlnc"},
7463 {&fill_vert, "vert"},
7464 {&fill_fold, "fold"},
7465 {&fill_diff, "diff"},
7466 };
7467#endif
7468 static struct charstab lcstab[] =
7469 {
7470 {&lcs_eol, "eol"},
7471 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007472 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007473 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007474 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007475 {&lcs_tab2, "tab"},
7476 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007477#ifdef FEAT_CONCEAL
7478 {&lcs_conceal, "conceal"},
7479#else
7480 {NULL, "conceal"},
7481#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 };
7483 struct charstab *tab;
7484
7485#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7486 if (varp == &p_lcs)
7487#endif
7488 {
7489 tab = lcstab;
7490 entries = sizeof(lcstab) / sizeof(struct charstab);
7491 }
7492#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7493 else
7494 {
7495 tab = filltab;
7496 entries = sizeof(filltab) / sizeof(struct charstab);
7497 }
7498#endif
7499
7500 /* first round: check for valid value, second round: assign values */
7501 for (round = 0; round <= 1; ++round)
7502 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007503 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504 {
7505 /* After checking that the value is valid: set defaults: space for
7506 * 'fillchars', NUL for 'listchars' */
7507 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007508 if (tab[i].cp != NULL)
7509 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510 if (varp == &p_lcs)
7511 lcs_tab1 = NUL;
7512#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7513 else
7514 fill_diff = '-';
7515#endif
7516 }
7517 p = *varp;
7518 while (*p)
7519 {
7520 for (i = 0; i < entries; ++i)
7521 {
7522 len = (int)STRLEN(tab[i].name);
7523 if (STRNCMP(p, tab[i].name, len) == 0
7524 && p[len] == ':'
7525 && p[len + 1] != NUL)
7526 {
7527 s = p + len + 1;
7528#ifdef FEAT_MBYTE
7529 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007530 if (mb_char2cells(c1) > 1)
7531 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007532#else
7533 c1 = *s++;
7534#endif
7535 if (tab[i].cp == &lcs_tab2)
7536 {
7537 if (*s == NUL)
7538 continue;
7539#ifdef FEAT_MBYTE
7540 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007541 if (mb_char2cells(c2) > 1)
7542 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543#else
7544 c2 = *s++;
7545#endif
7546 }
7547 if (*s == ',' || *s == NUL)
7548 {
7549 if (round)
7550 {
7551 if (tab[i].cp == &lcs_tab2)
7552 {
7553 lcs_tab1 = c1;
7554 lcs_tab2 = c2;
7555 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007556 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557 *(tab[i].cp) = c1;
7558
7559 }
7560 p = s;
7561 break;
7562 }
7563 }
7564 }
7565
7566 if (i == entries)
7567 return e_invarg;
7568 if (*p == ',')
7569 ++p;
7570 }
7571 }
7572
7573 return NULL; /* no error */
7574}
7575
7576#ifdef FEAT_STL_OPT
7577/*
7578 * Check validity of options with the 'statusline' format.
7579 * Return error message or NULL.
7580 */
7581 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007582check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007583{
7584 int itemcnt = 0;
7585 int groupdepth = 0;
7586 static char_u errbuf[80];
7587
7588 while (*s && itemcnt < STL_MAX_ITEM)
7589 {
7590 /* Check for valid keys after % sequences */
7591 while (*s && *s != '%')
7592 s++;
7593 if (!*s)
7594 break;
7595 s++;
7596 if (*s != '%' && *s != ')')
7597 ++itemcnt;
7598 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7599 {
7600 s++;
7601 continue;
7602 }
7603 if (*s == ')')
7604 {
7605 s++;
7606 if (--groupdepth < 0)
7607 break;
7608 continue;
7609 }
7610 if (*s == '-')
7611 s++;
7612 while (VIM_ISDIGIT(*s))
7613 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007614 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007615 continue;
7616 if (*s == '.')
7617 {
7618 s++;
7619 while (*s && VIM_ISDIGIT(*s))
7620 s++;
7621 }
7622 if (*s == '(')
7623 {
7624 groupdepth++;
7625 continue;
7626 }
7627 if (vim_strchr(STL_ALL, *s) == NULL)
7628 {
7629 return illegal_char(errbuf, *s);
7630 }
7631 if (*s == '{')
7632 {
7633 s++;
7634 while (*s != '}' && *s)
7635 s++;
7636 if (*s != '}')
7637 return (char_u *)N_("E540: Unclosed expression sequence");
7638 }
7639 }
7640 if (itemcnt >= STL_MAX_ITEM)
7641 return (char_u *)N_("E541: too many items");
7642 if (groupdepth != 0)
7643 return (char_u *)N_("E542: unbalanced groups");
7644 return NULL;
7645}
7646#endif
7647
7648#ifdef FEAT_CLIPBOARD
7649/*
7650 * Extract the items in the 'clipboard' option and set global values.
7651 */
7652 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007653check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007654{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007655 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007656 int new_autoselect_star = FALSE;
7657 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007658 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007659 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007660 regprog_T *new_exclude_prog = NULL;
7661 char_u *errmsg = NULL;
7662 char_u *p;
7663
7664 for (p = p_cb; *p != NUL; )
7665 {
7666 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7667 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007668 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007669 p += 7;
7670 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007671 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007672 && (p[11] == ',' || p[11] == NUL))
7673 {
7674 new_unnamed |= CLIP_UNNAMED_PLUS;
7675 p += 11;
7676 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007677 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007678 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007679 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007680 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681 p += 10;
7682 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007683 else if (STRNCMP(p, "autoselectplus", 14) == 0
7684 && (p[14] == ',' || p[14] == NUL))
7685 {
7686 new_autoselect_plus = TRUE;
7687 p += 14;
7688 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007689 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007690 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691 {
7692 new_autoselectml = TRUE;
7693 p += 12;
7694 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007695 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7696 {
7697 new_html = TRUE;
7698 p += 4;
7699 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007700 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7701 {
7702 p += 8;
7703 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7704 if (new_exclude_prog == NULL)
7705 errmsg = e_invarg;
7706 break;
7707 }
7708 else
7709 {
7710 errmsg = e_invarg;
7711 break;
7712 }
7713 if (*p == ',')
7714 ++p;
7715 }
7716 if (errmsg == NULL)
7717 {
7718 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007719 clip_autoselect_star = new_autoselect_star;
7720 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007722 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007723 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007725#ifdef FEAT_GUI_GTK
7726 if (gui.in_use)
7727 {
7728 gui_gtk_set_selection_targets();
7729 gui_gtk_set_dnd_targets();
7730 }
7731#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732 }
7733 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007734 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735
7736 return errmsg;
7737}
7738#endif
7739
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007740#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007741 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007742did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007743{
7744 char_u *errmsg = NULL;
7745 win_T *wp;
7746 int l;
7747
7748 if (is_spellfile)
7749 {
7750 l = (int)STRLEN(curwin->w_s->b_p_spf);
7751 if (l > 0 && (l < 4
7752 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7753 errmsg = e_invarg;
7754 }
7755
7756 if (errmsg == NULL)
7757 {
7758 FOR_ALL_WINDOWS(wp)
7759 if (wp->w_buffer == curbuf && wp->w_p_spell)
7760 {
7761 errmsg = did_set_spelllang(wp);
7762# ifdef FEAT_WINDOWS
7763 break;
7764# endif
7765 }
7766 }
7767 return errmsg;
7768}
7769
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007770/*
7771 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7772 * Return error message when failed, NULL when OK.
7773 */
7774 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007775compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007776{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007777 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007778 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007779
Bram Moolenaar860cae12010-06-05 23:22:07 +02007780 if (*synblock->b_p_spc == NUL)
7781 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007782 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007783 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007784 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007785 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007786 if (re != NULL)
7787 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007788 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007789 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007790 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007791 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007792 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007793 return e_invarg;
7794 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007795 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007796 }
7797
Bram Moolenaar473de612013-06-08 18:19:48 +02007798 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007799 return NULL;
7800}
7801#endif
7802
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007803#if defined(FEAT_EVAL) || defined(PROTO)
7804/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007805 * Set the scriptID for an option, taking care of setting the buffer- or
7806 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007807 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007808 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007809set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007810{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007811 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7812 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007813
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007814 /* Remember where the option was set. For local options need to do that
7815 * in the buffer or window structure. */
7816 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007817 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007818 if (both || (opt_flags & OPT_LOCAL))
7819 {
7820 if (indir & PV_BUF)
7821 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7822 else if (indir & PV_WIN)
7823 curwin->w_p_scriptID[indir & PV_MASK] = id;
7824 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007825}
7826#endif
7827
Bram Moolenaar071d4272004-06-13 20:20:40 +00007828/*
7829 * Set the value of a boolean option, and take care of side effects.
7830 * Returns NULL for success, or an error message for an error.
7831 */
7832 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007833set_bool_option(
7834 int opt_idx, /* index in options[] table */
7835 char_u *varp, /* pointer to the option variable */
7836 int value, /* new value */
7837 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007838{
7839 int old_value = *(int *)varp;
7840
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841 /* Disallow changing some options from secure mode */
7842 if ((secure
7843#ifdef HAVE_SANDBOX
7844 || sandbox != 0
7845#endif
7846 ) && (options[opt_idx].flags & P_SECURE))
7847 return e_secure;
7848
7849 *(int *)varp = value; /* set the new value */
7850#ifdef FEAT_EVAL
7851 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007852 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007853#endif
7854
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007855#ifdef FEAT_GUI
7856 need_mouse_correct = TRUE;
7857#endif
7858
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859 /* May set global value for local option. */
7860 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7861 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7862
7863 /*
7864 * Handle side effects of changing a bool option.
7865 */
7866
7867 /* 'compatible' */
7868 if ((int *)varp == &p_cp)
7869 {
7870 compatible_set();
7871 }
7872
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007873#ifdef FEAT_PERSISTENT_UNDO
7874 /* 'undofile' */
7875 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7876 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007877 /* Only take action when the option was set. When reset we do not
7878 * delete the undo file, the option may be set again without making
7879 * any changes in between. */
7880 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007881 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007882 char_u hash[UNDO_HASH_SIZE];
7883 buf_T *save_curbuf = curbuf;
7884
Bram Moolenaar29323592016-07-24 22:04:11 +02007885 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007886 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007887 /* When 'undofile' is set globally: for every buffer, otherwise
7888 * only for the current buffer: Try to read in the undofile,
7889 * if one exists, the buffer wasn't changed and the buffer was
7890 * loaded */
7891 if ((curbuf == save_curbuf
7892 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7893 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7894 {
7895 u_compute_hash(hash);
7896 u_read_undo(NULL, hash, curbuf->b_fname);
7897 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007898 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007899 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007900 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007901 }
7902#endif
7903
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 else if ((int *)varp == &curbuf->b_p_ro)
7905 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007906 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7908 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007909
7910 /* when 'readonly' is set may give W10 again */
7911 if (curbuf->b_p_ro)
7912 curbuf->b_did_warn = FALSE;
7913
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007915 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007916#endif
7917 }
7918
Bram Moolenaar9c449722010-07-20 18:44:27 +02007919#ifdef FEAT_GUI
7920 else if ((int *)varp == &p_mh)
7921 {
7922 if (!p_mh)
7923 gui_mch_mousehide(FALSE);
7924 }
7925#endif
7926
Bram Moolenaara539df02010-08-01 14:35:05 +02007927#ifdef FEAT_TITLE
7928 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007929 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007930 {
7931 redraw_titles();
7932 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007933 /* when 'endofline' is changed, redraw the window title */
7934 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007935 {
7936 redraw_titles();
7937 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007938 /* when 'fixeol' is changed, redraw the window title */
7939 else if ((int *)varp == &curbuf->b_p_fixeol)
7940 {
7941 redraw_titles();
7942 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007943# ifdef FEAT_MBYTE
7944 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007945 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007946 {
7947 redraw_titles();
7948 }
7949# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007950#endif
7951
7952 /* when 'bin' is set also set some other options */
7953 else if ((int *)varp == &curbuf->b_p_bin)
7954 {
7955 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7956#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007957 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958#endif
7959 }
7960
7961#ifdef FEAT_AUTOCMD
7962 /* when 'buflisted' changes, trigger autocommands */
7963 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7964 {
7965 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7966 NULL, NULL, TRUE, curbuf);
7967 }
7968#endif
7969
7970 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7971 else if ((int *)varp == &curbuf->b_p_swf)
7972 {
7973 if (curbuf->b_p_swf && p_uc)
7974 ml_open_file(curbuf); /* create the swap file */
7975 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007976 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7977 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978 mf_close_file(curbuf, TRUE); /* remove the swap file */
7979 }
7980
7981 /* when 'terse' is set change 'shortmess' */
7982 else if ((int *)varp == &p_terse)
7983 {
7984 char_u *p;
7985
7986 p = vim_strchr(p_shm, SHM_SEARCH);
7987
7988 /* insert 's' in p_shm */
7989 if (p_terse && p == NULL)
7990 {
7991 STRCPY(IObuff, p_shm);
7992 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007993 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007994 }
7995 /* remove 's' from p_shm */
7996 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007997 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007998 }
7999
8000 /* when 'paste' is set or reset also change other options */
8001 else if ((int *)varp == &p_paste)
8002 {
8003 paste_option_changed();
8004 }
8005
8006 /* when 'insertmode' is set from an autocommand need to do work here */
8007 else if ((int *)varp == &p_im)
8008 {
8009 if (p_im)
8010 {
8011 if ((State & INSERT) == 0)
8012 need_start_insertmode = TRUE;
8013 stop_insert_mode = FALSE;
8014 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008015 /* only reset if it was set previously */
8016 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 {
8018 need_start_insertmode = FALSE;
8019 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008020 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 clear_cmdline = TRUE; /* remove "(insert)" */
8022 restart_edit = 0;
8023 }
8024 }
8025
8026 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8027 else if ((int *)varp == &p_ic && p_hls)
8028 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008029 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008030 }
8031
8032#ifdef FEAT_SEARCH_EXTRA
8033 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8034 else if ((int *)varp == &p_hls)
8035 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008036 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 }
8038#endif
8039
8040#ifdef FEAT_SCROLLBIND
8041 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8042 * at the end of normal_cmd() */
8043 else if ((int *)varp == &curwin->w_p_scb)
8044 {
8045 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008046 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008047 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008048 curwin->w_scbind_pos = curwin->w_topline;
8049 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008050 }
8051#endif
8052
8053#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8054 /* There can be only one window with 'previewwindow' set. */
8055 else if ((int *)varp == &curwin->w_p_pvw)
8056 {
8057 if (curwin->w_p_pvw)
8058 {
8059 win_T *win;
8060
Bram Moolenaar29323592016-07-24 22:04:11 +02008061 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008062 if (win->w_p_pvw && win != curwin)
8063 {
8064 curwin->w_p_pvw = FALSE;
8065 return (char_u *)N_("E590: A preview window already exists");
8066 }
8067 }
8068 }
8069#endif
8070
8071 /* when 'textmode' is set or reset also change 'fileformat' */
8072 else if ((int *)varp == &curbuf->b_p_tx)
8073 {
8074 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8075 }
8076
8077 /* when 'textauto' is set or reset also change 'fileformats' */
8078 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008079 set_string_option_direct((char_u *)"ffs", -1,
8080 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008081 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008082
8083 /*
8084 * When 'lisp' option changes include/exclude '-' in
8085 * keyword characters.
8086 */
8087#ifdef FEAT_LISP
8088 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8089 {
8090 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8091 }
8092#endif
8093
8094#ifdef FEAT_TITLE
8095 /* when 'title' changed, may need to change the title; same for 'icon' */
8096 else if ((int *)varp == &p_title)
8097 {
8098 did_set_title(FALSE);
8099 }
8100
8101 else if ((int *)varp == &p_icon)
8102 {
8103 did_set_title(TRUE);
8104 }
8105#endif
8106
8107 else if ((int *)varp == &curbuf->b_changed)
8108 {
8109 if (!value)
8110 save_file_ff(curbuf); /* Buffer is unchanged */
8111#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008112 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008113#endif
8114#ifdef FEAT_AUTOCMD
8115 modified_was_set = value;
8116#endif
8117 }
8118
8119#ifdef BACKSLASH_IN_FILENAME
8120 else if ((int *)varp == &p_ssl)
8121 {
8122 if (p_ssl)
8123 {
8124 psepc = '/';
8125 psepcN = '\\';
8126 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008127 }
8128 else
8129 {
8130 psepc = '\\';
8131 psepcN = '/';
8132 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008133 }
8134
8135 /* need to adjust the file name arguments and buffer names. */
8136 buflist_slash_adjust();
8137 alist_slash_adjust();
8138# ifdef FEAT_EVAL
8139 scriptnames_slash_adjust();
8140# endif
8141 }
8142#endif
8143
8144 /* If 'wrap' is set, set w_leftcol to zero. */
8145 else if ((int *)varp == &curwin->w_p_wrap)
8146 {
8147 if (curwin->w_p_wrap)
8148 curwin->w_leftcol = 0;
8149 }
8150
8151#ifdef FEAT_WINDOWS
8152 else if ((int *)varp == &p_ea)
8153 {
8154 if (p_ea && !old_value)
8155 win_equal(curwin, FALSE, 0);
8156 }
8157#endif
8158
8159 else if ((int *)varp == &p_wiv)
8160 {
8161 /*
8162 * When 'weirdinvert' changed, set/reset 't_xs'.
8163 * Then set 'weirdinvert' according to value of 't_xs'.
8164 */
8165 if (p_wiv && !old_value)
8166 T_XS = (char_u *)"y";
8167 else if (!p_wiv && old_value)
8168 T_XS = empty_option;
8169 p_wiv = (*T_XS != NUL);
8170 }
8171
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008172#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 else if ((int *)varp == &p_beval)
8174 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008175 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008176 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008177 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178 gui_mch_disable_beval_area(balloonEval);
8179 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008182#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008183 else if ((int *)varp == &p_acd)
8184 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008185 /* Change directories when the 'acd' option is set now. */
8186 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187 }
8188#endif
8189
8190#ifdef FEAT_DIFF
8191 /* 'diff' */
8192 else if ((int *)varp == &curwin->w_p_diff)
8193 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008194 /* May add or remove the buffer from the list of diff buffers. */
8195 diff_buf_adjust(curwin);
8196# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197 if (foldmethodIsDiff(curwin))
8198 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008199# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200 }
8201#endif
8202
8203#ifdef USE_IM_CONTROL
8204 /* 'imdisable' */
8205 else if ((int *)varp == &p_imdisable)
8206 {
8207 /* Only de-activate it here, it will be enabled when changing mode. */
8208 if (p_imdisable)
8209 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008210 else if (State & INSERT)
8211 /* When the option is set from an autocommand, it may need to take
8212 * effect right away. */
8213 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214 }
8215#endif
8216
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008217#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008218 /* 'spell' */
8219 else if ((int *)varp == &curwin->w_p_spell)
8220 {
8221 if (curwin->w_p_spell)
8222 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008223 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008224 if (errmsg != NULL)
8225 EMSG(_(errmsg));
8226 }
8227 }
8228#endif
8229
Bram Moolenaar071d4272004-06-13 20:20:40 +00008230#ifdef FEAT_FKMAP
8231 else if ((int *)varp == &p_altkeymap)
8232 {
8233 if (old_value != p_altkeymap)
8234 {
8235 if (!p_altkeymap)
8236 {
8237 p_hkmap = p_fkmap;
8238 p_fkmap = 0;
8239 }
8240 else
8241 {
8242 p_fkmap = p_hkmap;
8243 p_hkmap = 0;
8244 }
8245 (void)init_chartab();
8246 }
8247 }
8248
8249 /*
8250 * In case some second language keymapping options have changed, check
8251 * and correct the setting in a consistent way.
8252 */
8253
8254 /*
8255 * If hkmap or fkmap are set, reset Arabic keymapping.
8256 */
8257 if ((p_hkmap || p_fkmap) && p_altkeymap)
8258 {
8259 p_altkeymap = p_fkmap;
8260# ifdef FEAT_ARABIC
8261 curwin->w_p_arab = FALSE;
8262# endif
8263 (void)init_chartab();
8264 }
8265
8266 /*
8267 * If hkmap set, reset Farsi keymapping.
8268 */
8269 if (p_hkmap && p_altkeymap)
8270 {
8271 p_altkeymap = 0;
8272 p_fkmap = 0;
8273# ifdef FEAT_ARABIC
8274 curwin->w_p_arab = FALSE;
8275# endif
8276 (void)init_chartab();
8277 }
8278
8279 /*
8280 * If fkmap set, reset Hebrew keymapping.
8281 */
8282 if (p_fkmap && !p_altkeymap)
8283 {
8284 p_altkeymap = 1;
8285 p_hkmap = 0;
8286# ifdef FEAT_ARABIC
8287 curwin->w_p_arab = FALSE;
8288# endif
8289 (void)init_chartab();
8290 }
8291#endif
8292
8293#ifdef FEAT_ARABIC
8294 if ((int *)varp == &curwin->w_p_arab)
8295 {
8296 if (curwin->w_p_arab)
8297 {
8298 /*
8299 * 'arabic' is set, handle various sub-settings.
8300 */
8301 if (!p_tbidi)
8302 {
8303 /* set rightleft mode */
8304 if (!curwin->w_p_rl)
8305 {
8306 curwin->w_p_rl = TRUE;
8307 changed_window_setting();
8308 }
8309
8310 /* Enable Arabic shaping (major part of what Arabic requires) */
8311 if (!p_arshape)
8312 {
8313 p_arshape = TRUE;
8314 redraw_later_clear();
8315 }
8316 }
8317
8318 /* Arabic requires a utf-8 encoding, inform the user if its not
8319 * set. */
8320 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008321 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008322 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8323
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008324 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008325 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8326#ifdef FEAT_EVAL
8327 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8328#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008329 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008330
8331# ifdef FEAT_MBYTE
8332 /* set 'delcombine' */
8333 p_deco = TRUE;
8334# endif
8335
8336# ifdef FEAT_KEYMAP
8337 /* Force-set the necessary keymap for arabic */
8338 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8339 OPT_LOCAL);
8340# endif
8341# ifdef FEAT_FKMAP
8342 p_altkeymap = 0;
8343 p_hkmap = 0;
8344 p_fkmap = 0;
8345 (void)init_chartab();
8346# endif
8347 }
8348 else
8349 {
8350 /*
8351 * 'arabic' is reset, handle various sub-settings.
8352 */
8353 if (!p_tbidi)
8354 {
8355 /* reset rightleft mode */
8356 if (curwin->w_p_rl)
8357 {
8358 curwin->w_p_rl = FALSE;
8359 changed_window_setting();
8360 }
8361
8362 /* 'arabicshape' isn't reset, it is a global option and
8363 * another window may still need it "on". */
8364 }
8365
8366 /* 'delcombine' isn't reset, it is a global option and another
8367 * window may still want it "on". */
8368
8369# ifdef FEAT_KEYMAP
8370 /* Revert to the default keymap */
8371 curbuf->b_p_iminsert = B_IMODE_NONE;
8372 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8373# endif
8374 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008375 }
8376
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008377#endif
8378
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008379#ifdef FEAT_TERMGUICOLORS
8380 /* 'termguicolors' */
8381 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008382 {
8383# ifdef FEAT_GUI
8384 if (!gui.in_use && !gui.starting)
8385# endif
8386 highlight_gui_started();
8387 }
8388#endif
8389
Bram Moolenaar071d4272004-06-13 20:20:40 +00008390 /*
8391 * End of handling side effects for bool options.
8392 */
8393
Bram Moolenaar53744302015-07-17 17:38:22 +02008394 /* after handling side effects, call autocommand */
8395
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 options[opt_idx].flags |= P_WAS_SET;
8397
Bram Moolenaar53744302015-07-17 17:38:22 +02008398#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8399 if (!starting)
8400 {
8401 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008402 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8403 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8404 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008405 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8406 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8407 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8408 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8409 reset_v_option_vars();
8410 }
8411#endif
8412
Bram Moolenaar071d4272004-06-13 20:20:40 +00008413 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008414 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008415 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008416 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417 check_redraw(options[opt_idx].flags);
8418
8419 return NULL;
8420}
8421
8422/*
8423 * Set the value of a number option, and take care of side effects.
8424 * Returns NULL for success, or an error message for an error.
8425 */
8426 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008427set_num_option(
8428 int opt_idx, /* index in options[] table */
8429 char_u *varp, /* pointer to the option variable */
8430 long value, /* new value */
8431 char_u *errbuf, /* buffer for error messages */
8432 size_t errbuflen, /* length of "errbuf" */
8433 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 OPT_MODELINE */
8435{
8436 char_u *errmsg = NULL;
8437 long old_value = *(long *)varp;
8438 long old_Rows = Rows; /* remember old Rows */
8439 long old_Columns = Columns; /* remember old Columns */
8440 long *pp = (long *)varp;
8441
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008442 /* Disallow changing some options from secure mode. */
8443 if ((secure
8444#ifdef HAVE_SANDBOX
8445 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008446#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008447 ) && (options[opt_idx].flags & P_SECURE))
8448 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449
8450 *pp = value;
8451#ifdef FEAT_EVAL
8452 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008453 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008455#ifdef FEAT_GUI
8456 need_mouse_correct = TRUE;
8457#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008458
Bram Moolenaar14f24742012-08-08 18:01:05 +02008459 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460 {
8461 errmsg = e_positive;
8462 curbuf->b_p_sw = curbuf->b_p_ts;
8463 }
8464
8465 /*
8466 * Number options that need some action when changed
8467 */
8468#ifdef FEAT_WINDOWS
8469 if (pp == &p_wh || pp == &p_hh)
8470 {
8471 if (p_wh < 1)
8472 {
8473 errmsg = e_positive;
8474 p_wh = 1;
8475 }
8476 if (p_wmh > p_wh)
8477 {
8478 errmsg = e_winheight;
8479 p_wh = p_wmh;
8480 }
8481 if (p_hh < 0)
8482 {
8483 errmsg = e_positive;
8484 p_hh = 0;
8485 }
8486
8487 /* Change window height NOW */
8488 if (lastwin != firstwin)
8489 {
8490 if (pp == &p_wh && curwin->w_height < p_wh)
8491 win_setheight((int)p_wh);
8492 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8493 win_setheight((int)p_hh);
8494 }
8495 }
8496
8497 /* 'winminheight' */
8498 else if (pp == &p_wmh)
8499 {
8500 if (p_wmh < 0)
8501 {
8502 errmsg = e_positive;
8503 p_wmh = 0;
8504 }
8505 if (p_wmh > p_wh)
8506 {
8507 errmsg = e_winheight;
8508 p_wmh = p_wh;
8509 }
8510 win_setminheight();
8511 }
8512
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008513# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008514 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008515 {
8516 if (p_wiw < 1)
8517 {
8518 errmsg = e_positive;
8519 p_wiw = 1;
8520 }
8521 if (p_wmw > p_wiw)
8522 {
8523 errmsg = e_winwidth;
8524 p_wiw = p_wmw;
8525 }
8526
8527 /* Change window width NOW */
8528 if (lastwin != firstwin && curwin->w_width < p_wiw)
8529 win_setwidth((int)p_wiw);
8530 }
8531
8532 /* 'winminwidth' */
8533 else if (pp == &p_wmw)
8534 {
8535 if (p_wmw < 0)
8536 {
8537 errmsg = e_positive;
8538 p_wmw = 0;
8539 }
8540 if (p_wmw > p_wiw)
8541 {
8542 errmsg = e_winwidth;
8543 p_wmw = p_wiw;
8544 }
8545 win_setminheight();
8546 }
8547# endif
8548
8549#endif
8550
8551#ifdef FEAT_WINDOWS
8552 /* (re)set last window status line */
8553 else if (pp == &p_ls)
8554 {
8555 last_status(FALSE);
8556 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008557
8558 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008559 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008560 {
8561 shell_new_rows(); /* recompute window positions and heights */
8562 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563#endif
8564
8565#ifdef FEAT_GUI
8566 else if (pp == &p_linespace)
8567 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008568 /* Recompute gui.char_height and resize the Vim window to keep the
8569 * same number of lines. */
8570 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008571 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008572 }
8573#endif
8574
8575#ifdef FEAT_FOLDING
8576 /* 'foldlevel' */
8577 else if (pp == &curwin->w_p_fdl)
8578 {
8579 if (curwin->w_p_fdl < 0)
8580 curwin->w_p_fdl = 0;
8581 newFoldLevel();
8582 }
8583
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008584 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008585 else if (pp == &curwin->w_p_fml)
8586 {
8587 foldUpdateAll(curwin);
8588 }
8589
8590 /* 'foldnestmax' */
8591 else if (pp == &curwin->w_p_fdn)
8592 {
8593 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8594 foldUpdateAll(curwin);
8595 }
8596
8597 /* 'foldcolumn' */
8598 else if (pp == &curwin->w_p_fdc)
8599 {
8600 if (curwin->w_p_fdc < 0)
8601 {
8602 errmsg = e_positive;
8603 curwin->w_p_fdc = 0;
8604 }
8605 else if (curwin->w_p_fdc > 12)
8606 {
8607 errmsg = e_invarg;
8608 curwin->w_p_fdc = 12;
8609 }
8610 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008611#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008612
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008613#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008614 /* 'shiftwidth' or 'tabstop' */
8615 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8616 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008617# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618 if (foldmethodIsIndent(curwin))
8619 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008620# endif
8621# ifdef FEAT_CINDENT
8622 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8623 * parse 'cinoptions'. */
8624 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8625 parse_cino(curbuf);
8626# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008627 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008630#ifdef FEAT_MBYTE
8631 /* 'maxcombine' */
8632 else if (pp == &p_mco)
8633 {
8634 if (p_mco > MAX_MCO)
8635 p_mco = MAX_MCO;
8636 else if (p_mco < 0)
8637 p_mco = 0;
8638 screenclear(); /* will re-allocate the screen */
8639 }
8640#endif
8641
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 else if (pp == &curbuf->b_p_iminsert)
8643 {
8644 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8645 {
8646 errmsg = e_invarg;
8647 curbuf->b_p_iminsert = B_IMODE_NONE;
8648 }
8649 p_iminsert = curbuf->b_p_iminsert;
8650 if (termcap_active) /* don't do this in the alternate screen */
8651 showmode();
8652#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8653 /* Show/unshow value of 'keymap' in status lines. */
8654 status_redraw_curbuf();
8655#endif
8656 }
8657
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008658 else if (pp == &p_window)
8659 {
8660 if (p_window < 1)
8661 p_window = 1;
8662 else if (p_window >= Rows)
8663 p_window = Rows - 1;
8664 }
8665
Bram Moolenaar071d4272004-06-13 20:20:40 +00008666 else if (pp == &curbuf->b_p_imsearch)
8667 {
8668 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8669 {
8670 errmsg = e_invarg;
8671 curbuf->b_p_imsearch = B_IMODE_NONE;
8672 }
8673 p_imsearch = curbuf->b_p_imsearch;
8674 }
8675
8676#ifdef FEAT_TITLE
8677 /* if 'titlelen' has changed, redraw the title */
8678 else if (pp == &p_titlelen)
8679 {
8680 if (p_titlelen < 0)
8681 {
8682 errmsg = e_positive;
8683 p_titlelen = 85;
8684 }
8685 if (starting != NO_SCREEN && old_value != p_titlelen)
8686 need_maketitle = TRUE;
8687 }
8688#endif
8689
8690 /* if p_ch changed value, change the command line height */
8691 else if (pp == &p_ch)
8692 {
8693 if (p_ch < 1)
8694 {
8695 errmsg = e_positive;
8696 p_ch = 1;
8697 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008698 if (p_ch > Rows - min_rows() + 1)
8699 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008700
8701 /* Only compute the new window layout when startup has been
8702 * completed. Otherwise the frame sizes may be wrong. */
8703 if (p_ch != old_value && full_screen
8704#ifdef FEAT_GUI
8705 && !gui.starting
8706#endif
8707 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008708 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709 }
8710
8711 /* when 'updatecount' changes from zero to non-zero, open swap files */
8712 else if (pp == &p_uc)
8713 {
8714 if (p_uc < 0)
8715 {
8716 errmsg = e_positive;
8717 p_uc = 100;
8718 }
8719 if (p_uc && !old_value)
8720 ml_open_files();
8721 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008722#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008723 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008724 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008725 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008726 {
8727 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008728 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008729 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008730 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008731 {
8732 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008733 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008734 }
8735 }
8736#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008737#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008738 else if (pp == &p_mzq)
8739 mzvim_reset_timer();
8740#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008741
8742 /* sync undo before 'undolevels' changes */
8743 else if (pp == &p_ul)
8744 {
8745 /* use the old value, otherwise u_sync() may not work properly */
8746 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008747 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008748 p_ul = value;
8749 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008750 else if (pp == &curbuf->b_p_ul)
8751 {
8752 /* use the old value, otherwise u_sync() may not work properly */
8753 curbuf->b_p_ul = old_value;
8754 u_sync(TRUE);
8755 curbuf->b_p_ul = value;
8756 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008758#ifdef FEAT_LINEBREAK
8759 /* 'numberwidth' must be positive */
8760 else if (pp == &curwin->w_p_nuw)
8761 {
8762 if (curwin->w_p_nuw < 1)
8763 {
8764 errmsg = e_positive;
8765 curwin->w_p_nuw = 1;
8766 }
8767 if (curwin->w_p_nuw > 10)
8768 {
8769 errmsg = e_invarg;
8770 curwin->w_p_nuw = 10;
8771 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008772 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008773 }
8774#endif
8775
Bram Moolenaar1a384422010-07-14 19:53:30 +02008776 else if (pp == &curbuf->b_p_tw)
8777 {
8778 if (curbuf->b_p_tw < 0)
8779 {
8780 errmsg = e_positive;
8781 curbuf->b_p_tw = 0;
8782 }
8783#ifdef FEAT_SYN_HL
8784# ifdef FEAT_WINDOWS
8785 {
8786 win_T *wp;
8787 tabpage_T *tp;
8788
8789 FOR_ALL_TAB_WINDOWS(tp, wp)
8790 check_colorcolumn(wp);
8791 }
8792# else
8793 check_colorcolumn(curwin);
8794# endif
8795#endif
8796 }
8797
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798 /*
8799 * Check the bounds for numeric options here
8800 */
8801 if (Rows < min_rows() && full_screen)
8802 {
8803 if (errbuf != NULL)
8804 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008805 vim_snprintf((char *)errbuf, errbuflen,
8806 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807 errmsg = errbuf;
8808 }
8809 Rows = min_rows();
8810 }
8811 if (Columns < MIN_COLUMNS && full_screen)
8812 {
8813 if (errbuf != NULL)
8814 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008815 vim_snprintf((char *)errbuf, errbuflen,
8816 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008817 errmsg = errbuf;
8818 }
8819 Columns = MIN_COLUMNS;
8820 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008821 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 /*
8824 * If the screen (shell) height has been changed, assume it is the
8825 * physical screenheight.
8826 */
8827 if (old_Rows != Rows || old_Columns != Columns)
8828 {
8829 /* Changing the screen size is not allowed while updating the screen. */
8830 if (updating_screen)
8831 *pp = old_value;
8832 else if (full_screen
8833#ifdef FEAT_GUI
8834 && !gui.starting
8835#endif
8836 )
8837 set_shellsize((int)Columns, (int)Rows, TRUE);
8838 else
8839 {
8840 /* Postpone the resizing; check the size and cmdline position for
8841 * messages. */
8842 check_shellsize();
8843 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8844 cmdline_row = Rows - p_ch;
8845 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008846 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008847 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848 }
8849
Bram Moolenaar071d4272004-06-13 20:20:40 +00008850 if (curbuf->b_p_ts <= 0)
8851 {
8852 errmsg = e_positive;
8853 curbuf->b_p_ts = 8;
8854 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855 if (p_tm < 0)
8856 {
8857 errmsg = e_positive;
8858 p_tm = 0;
8859 }
8860 if ((curwin->w_p_scr <= 0
8861 || (curwin->w_p_scr > curwin->w_height
8862 && curwin->w_height > 0))
8863 && full_screen)
8864 {
8865 if (pp == &(curwin->w_p_scr))
8866 {
8867 if (curwin->w_p_scr != 0)
8868 errmsg = e_scroll;
8869 win_comp_scroll(curwin);
8870 }
8871 /* If 'scroll' became invalid because of a side effect silently adjust
8872 * it. */
8873 else if (curwin->w_p_scr <= 0)
8874 curwin->w_p_scr = 1;
8875 else /* curwin->w_p_scr > curwin->w_height */
8876 curwin->w_p_scr = curwin->w_height;
8877 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008878 if (p_hi < 0)
8879 {
8880 errmsg = e_positive;
8881 p_hi = 0;
8882 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008883 else if (p_hi > 10000)
8884 {
8885 errmsg = e_invarg;
8886 p_hi = 10000;
8887 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008888 if (p_re < 0 || p_re > 2)
8889 {
8890 errmsg = e_invarg;
8891 p_re = 0;
8892 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893 if (p_report < 0)
8894 {
8895 errmsg = e_positive;
8896 p_report = 1;
8897 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008898 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008899 {
8900 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8901 p_sj = Rows / 2;
8902 else
8903 {
8904 errmsg = e_scroll;
8905 p_sj = 1;
8906 }
8907 }
8908 if (p_so < 0 && full_screen)
8909 {
8910 errmsg = e_scroll;
8911 p_so = 0;
8912 }
8913 if (p_siso < 0 && full_screen)
8914 {
8915 errmsg = e_positive;
8916 p_siso = 0;
8917 }
8918#ifdef FEAT_CMDWIN
8919 if (p_cwh < 1)
8920 {
8921 errmsg = e_positive;
8922 p_cwh = 1;
8923 }
8924#endif
8925 if (p_ut < 0)
8926 {
8927 errmsg = e_positive;
8928 p_ut = 2000;
8929 }
8930 if (p_ss < 0)
8931 {
8932 errmsg = e_positive;
8933 p_ss = 0;
8934 }
8935
8936 /* May set global value for local option. */
8937 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8938 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8939
8940 options[opt_idx].flags |= P_WAS_SET;
8941
Bram Moolenaar53744302015-07-17 17:38:22 +02008942#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8943 if (!starting && errmsg == NULL)
8944 {
8945 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008946 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8947 vim_snprintf((char *)buf_new, 10, "%ld", value);
8948 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008949 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8950 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8951 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8952 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8953 reset_v_option_vars();
8954 }
8955#endif
8956
Bram Moolenaar071d4272004-06-13 20:20:40 +00008957 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008958 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008959 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008960 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008961 check_redraw(options[opt_idx].flags);
8962
8963 return errmsg;
8964}
8965
8966/*
8967 * Called after an option changed: check if something needs to be redrawn.
8968 */
8969 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008970check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008971{
8972 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008973 int doclear = (flags & P_RCLR) == P_RCLR;
8974 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008975
8976#ifdef FEAT_WINDOWS
8977 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8978 status_redraw_all();
8979#endif
8980
8981 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8982 changed_window_setting();
8983 if (flags & P_RBUF)
8984 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008985 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008986 redraw_all_later(CLEAR);
8987 else if (all)
8988 redraw_all_later(NOT_VALID);
8989}
8990
8991/*
8992 * Find index for option 'arg'.
8993 * Return -1 if not found.
8994 */
8995 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008996findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008997{
8998 int opt_idx;
8999 char *s, *p;
9000 static short quick_tab[27] = {0, 0}; /* quick access table */
9001 int is_term_opt;
9002
9003 /*
9004 * For first call: Initialize the quick-access table.
9005 * It contains the index for the first option that starts with a certain
9006 * letter. There are 26 letters, plus the first "t_" option.
9007 */
9008 if (quick_tab[1] == 0)
9009 {
9010 p = options[0].fullname;
9011 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9012 {
9013 if (s[0] != p[0])
9014 {
9015 if (s[0] == 't' && s[1] == '_')
9016 quick_tab[26] = opt_idx;
9017 else
9018 quick_tab[CharOrdLow(s[0])] = opt_idx;
9019 }
9020 p = s;
9021 }
9022 }
9023
9024 /*
9025 * Check for name starting with an illegal character.
9026 */
9027#ifdef EBCDIC
9028 if (!islower(arg[0]))
9029#else
9030 if (arg[0] < 'a' || arg[0] > 'z')
9031#endif
9032 return -1;
9033
9034 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9035 if (is_term_opt)
9036 opt_idx = quick_tab[26];
9037 else
9038 opt_idx = quick_tab[CharOrdLow(arg[0])];
9039 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9040 {
9041 if (STRCMP(arg, s) == 0) /* match full name */
9042 break;
9043 }
9044 if (s == NULL && !is_term_opt)
9045 {
9046 opt_idx = quick_tab[CharOrdLow(arg[0])];
9047 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9048 {
9049 s = options[opt_idx].shortname;
9050 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9051 break;
9052 s = NULL;
9053 }
9054 }
9055 if (s == NULL)
9056 opt_idx = -1;
9057 return opt_idx;
9058}
9059
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009060#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061/*
9062 * Get the value for an option.
9063 *
9064 * Returns:
9065 * Number or Toggle option: 1, *numval gets value.
9066 * String option: 0, *stringval gets allocated string.
9067 * Hidden Number or Toggle option: -1.
9068 * hidden String option: -2.
9069 * unknown option: -3.
9070 */
9071 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009072get_option_value(
9073 char_u *name,
9074 long *numval,
9075 char_u **stringval, /* NULL when only checking existence */
9076 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077{
9078 int opt_idx;
9079 char_u *varp;
9080
9081 opt_idx = findoption(name);
9082 if (opt_idx < 0) /* unknown option */
9083 return -3;
9084
9085 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9086
9087 if (options[opt_idx].flags & P_STRING)
9088 {
9089 if (varp == NULL) /* hidden option */
9090 return -2;
9091 if (stringval != NULL)
9092 {
9093#ifdef FEAT_CRYPT
9094 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009095 if ((char_u **)varp == &curbuf->b_p_key
9096 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009097 *stringval = vim_strsave((char_u *)"*****");
9098 else
9099#endif
9100 *stringval = vim_strsave(*(char_u **)(varp));
9101 }
9102 return 0;
9103 }
9104
9105 if (varp == NULL) /* hidden option */
9106 return -1;
9107 if (options[opt_idx].flags & P_NUM)
9108 *numval = *(long *)varp;
9109 else
9110 {
9111 /* Special case: 'modified' is b_changed, but we also want to consider
9112 * it set when 'ff' or 'fenc' changed. */
9113 if ((int *)varp == &curbuf->b_changed)
9114 *numval = curbufIsChanged();
9115 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009116 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117 }
9118 return 1;
9119}
9120#endif
9121
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009122#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009123/*
9124 * Returns the option attributes and its value. Unlike the above function it
9125 * will return either global value or local value of the option depending on
9126 * what was requested, but it will never return global value if it was
9127 * requested to return local one and vice versa. Neither it will return
9128 * buffer-local value if it was requested to return window-local one.
9129 *
9130 * Pretends that option is absent if it is not present in the requested scope
9131 * (i.e. has no global, window-local or buffer-local value depending on
9132 * opt_type). Uses
9133 *
9134 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009135 * 0 hidden or unknown option, also option that does not have requested
9136 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009137 * see SOPT_* in vim.h for other flags
9138 *
9139 * Possible opt_type values: see SREQ_* in vim.h
9140 */
9141 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009142get_option_value_strict(
9143 char_u *name,
9144 long *numval,
9145 char_u **stringval, /* NULL when only obtaining attributes */
9146 int opt_type,
9147 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009148{
9149 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009150 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009151 struct vimoption *p;
9152 int r = 0;
9153
9154 opt_idx = findoption(name);
9155 if (opt_idx < 0)
9156 return 0;
9157
9158 p = &(options[opt_idx]);
9159
9160 /* Hidden option */
9161 if (p->var == NULL)
9162 return 0;
9163
9164 if (p->flags & P_BOOL)
9165 r |= SOPT_BOOL;
9166 else if (p->flags & P_NUM)
9167 r |= SOPT_NUM;
9168 else if (p->flags & P_STRING)
9169 r |= SOPT_STRING;
9170
9171 if (p->indir == PV_NONE)
9172 {
9173 if (opt_type == SREQ_GLOBAL)
9174 r |= SOPT_GLOBAL;
9175 else
9176 return 0; /* Did not request global-only option */
9177 }
9178 else
9179 {
9180 if (p->indir & PV_BOTH)
9181 r |= SOPT_GLOBAL;
9182 else if (opt_type == SREQ_GLOBAL)
9183 return 0; /* Requested global option */
9184
9185 if (p->indir & PV_WIN)
9186 {
9187 if (opt_type == SREQ_BUF)
9188 return 0; /* Did not request window-local option */
9189 else
9190 r |= SOPT_WIN;
9191 }
9192 else if (p->indir & PV_BUF)
9193 {
9194 if (opt_type == SREQ_WIN)
9195 return 0; /* Did not request buffer-local option */
9196 else
9197 r |= SOPT_BUF;
9198 }
9199 }
9200
9201 if (stringval == NULL)
9202 return r;
9203
9204 if (opt_type == SREQ_GLOBAL)
9205 varp = p->var;
9206 else
9207 {
9208 if (opt_type == SREQ_BUF)
9209 {
9210 /* Special case: 'modified' is b_changed, but we also want to
9211 * consider it set when 'ff' or 'fenc' changed. */
9212 if (p->indir == PV_MOD)
9213 {
9214 *numval = bufIsChanged((buf_T *) from);
9215 varp = NULL;
9216 }
9217#ifdef FEAT_CRYPT
9218 else if (p->indir == PV_KEY)
9219 {
9220 /* never return the value of the crypt key */
9221 *stringval = NULL;
9222 varp = NULL;
9223 }
9224#endif
9225 else
9226 {
9227 aco_save_T aco;
9228 aucmd_prepbuf(&aco, (buf_T *) from);
9229 varp = get_varp(p);
9230 aucmd_restbuf(&aco);
9231 }
9232 }
9233 else if (opt_type == SREQ_WIN)
9234 {
9235 win_T *save_curwin;
9236 save_curwin = curwin;
9237 curwin = (win_T *) from;
9238 curbuf = curwin->w_buffer;
9239 varp = get_varp(p);
9240 curwin = save_curwin;
9241 curbuf = curwin->w_buffer;
9242 }
9243 if (varp == p->var)
9244 return (r | SOPT_UNSET);
9245 }
9246
9247 if (varp != NULL)
9248 {
9249 if (p->flags & P_STRING)
9250 *stringval = vim_strsave(*(char_u **)(varp));
9251 else if (p->flags & P_NUM)
9252 *numval = *(long *) varp;
9253 else
9254 *numval = *(int *)varp;
9255 }
9256
9257 return r;
9258}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009259
9260/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009261 * Iterate over options. First argument is a pointer to a pointer to a
9262 * structure inside options[] array, second is option type like in the above
9263 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009264 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009265 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009266 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009267 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009268 * first argument to NULL.
9269 *
9270 * Returns full option name for current option on each call.
9271 */
9272 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009273option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009274{
9275 struct vimoption *ret = NULL;
9276 do
9277 {
9278 if (*option == NULL)
9279 *option = (void *) options;
9280 else if (((struct vimoption *) (*option))->fullname == NULL)
9281 {
9282 *option = NULL;
9283 return NULL;
9284 }
9285 else
9286 *option = (void *) (((struct vimoption *) (*option)) + 1);
9287
9288 ret = ((struct vimoption *) (*option));
9289
9290 /* Hidden option */
9291 if (ret->var == NULL)
9292 {
9293 ret = NULL;
9294 continue;
9295 }
9296
9297 switch (opt_type)
9298 {
9299 case SREQ_GLOBAL:
9300 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9301 ret = NULL;
9302 break;
9303 case SREQ_BUF:
9304 if (!(ret->indir & PV_BUF))
9305 ret = NULL;
9306 break;
9307 case SREQ_WIN:
9308 if (!(ret->indir & PV_WIN))
9309 ret = NULL;
9310 break;
9311 default:
9312 EMSG2(_(e_intern2), "option_iter_next()");
9313 return NULL;
9314 }
9315 }
9316 while (ret == NULL);
9317
9318 return (char_u *)ret->fullname;
9319}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009320#endif
9321
Bram Moolenaar071d4272004-06-13 20:20:40 +00009322/*
9323 * Set the value of option "name".
9324 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009325 *
9326 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009328 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009329set_option_value(
9330 char_u *name,
9331 long number,
9332 char_u *string,
9333 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334{
9335 int opt_idx;
9336 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009337 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338
9339 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009340 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341 EMSG2(_("E355: Unknown option: %s"), name);
9342 else
9343 {
9344 flags = options[opt_idx].flags;
9345#ifdef HAVE_SANDBOX
9346 /* Disallow changing some options in the sandbox */
9347 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009348 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009349 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009350 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009351 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009352#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009353 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009354 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355 else
9356 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009357 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009358 if (varp != NULL) /* hidden option is not changed */
9359 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009360 if (number == 0 && string != NULL)
9361 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009362 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009363
9364 /* Either we are given a string or we are setting option
9365 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009366 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009367 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009368 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009369 {
9370 /* There's another character after zeros or the string
9371 * is empty. In both cases, we are trying to set a
9372 * num option using a string. */
9373 EMSG3(_("E521: Number required: &%s = '%s'"),
9374 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009375 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009376
9377 }
9378 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009380 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009381 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009383 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009384 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009385 }
9386 }
9387 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009388 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009389}
9390
9391/*
9392 * Get the terminal code for a terminal option.
9393 * Returns NULL when not found.
9394 */
9395 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009396get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009397{
9398 int opt_idx;
9399 char_u *varp;
9400
9401 if (tname[0] != 't' || tname[1] != '_' ||
9402 tname[2] == NUL || tname[3] == NUL)
9403 return NULL;
9404 if ((opt_idx = findoption(tname)) >= 0)
9405 {
9406 varp = get_varp(&(options[opt_idx]));
9407 if (varp != NULL)
9408 varp = *(char_u **)(varp);
9409 return varp;
9410 }
9411 return find_termcode(tname + 2);
9412}
9413
9414 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009415get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416{
9417 int i;
9418
9419 i = findoption((char_u *)"hl");
9420 if (i >= 0)
9421 return options[i].def_val[VI_DEFAULT];
9422 return (char_u *)NULL;
9423}
9424
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009425#if defined(FEAT_MBYTE) || defined(PROTO)
9426 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009427get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009428{
9429 int i;
9430
9431 i = findoption((char_u *)"enc");
9432 if (i >= 0)
9433 return options[i].def_val[VI_DEFAULT];
9434 return (char_u *)NULL;
9435}
9436#endif
9437
Bram Moolenaar071d4272004-06-13 20:20:40 +00009438/*
9439 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9440 */
9441 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009442find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443{
9444 int key;
9445 int modifiers;
9446
9447 /*
9448 * Don't use get_special_key_code() for t_xx, we don't want it to call
9449 * add_termcap_entry().
9450 */
9451 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9452 key = TERMCAP2KEY(arg[2], arg[3]);
9453 else
9454 {
9455 --arg; /* put arg at the '<' */
9456 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009457 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009458 if (modifiers) /* can't handle modifiers here */
9459 key = 0;
9460 }
9461 return key;
9462}
9463
9464/*
9465 * if 'all' == 0: show changed options
9466 * if 'all' == 1: show all normal options
9467 * if 'all' == 2: show all terminal options
9468 */
9469 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009470showoptions(
9471 int all,
9472 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009473{
9474 struct vimoption *p;
9475 int col;
9476 int isterm;
9477 char_u *varp;
9478 struct vimoption **items;
9479 int item_count;
9480 int run;
9481 int row, rows;
9482 int cols;
9483 int i;
9484 int len;
9485
9486#define INC 20
9487#define GAP 3
9488
9489 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9490 PARAM_COUNT));
9491 if (items == NULL)
9492 return;
9493
9494 /* Highlight title */
9495 if (all == 2)
9496 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9497 else if (opt_flags & OPT_GLOBAL)
9498 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9499 else if (opt_flags & OPT_LOCAL)
9500 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9501 else
9502 MSG_PUTS_TITLE(_("\n--- Options ---"));
9503
9504 /*
9505 * do the loop two times:
9506 * 1. display the short items
9507 * 2. display the long items (only strings and numbers)
9508 */
9509 for (run = 1; run <= 2 && !got_int; ++run)
9510 {
9511 /*
9512 * collect the items in items[]
9513 */
9514 item_count = 0;
9515 for (p = &options[0]; p->fullname != NULL; p++)
9516 {
9517 varp = NULL;
9518 isterm = istermoption(p);
9519 if (opt_flags != 0)
9520 {
9521 if (p->indir != PV_NONE && !isterm)
9522 varp = get_varp_scope(p, opt_flags);
9523 }
9524 else
9525 varp = get_varp(p);
9526 if (varp != NULL
9527 && ((all == 2 && isterm)
9528 || (all == 1 && !isterm)
9529 || (all == 0 && !optval_default(p, varp))))
9530 {
9531 if (p->flags & P_BOOL)
9532 len = 1; /* a toggle option fits always */
9533 else
9534 {
9535 option_value2string(p, opt_flags);
9536 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9537 }
9538 if ((len <= INC - GAP && run == 1) ||
9539 (len > INC - GAP && run == 2))
9540 items[item_count++] = p;
9541 }
9542 }
9543
9544 /*
9545 * display the items
9546 */
9547 if (run == 1)
9548 {
9549 cols = (Columns + GAP - 3) / INC;
9550 if (cols == 0)
9551 cols = 1;
9552 rows = (item_count + cols - 1) / cols;
9553 }
9554 else /* run == 2 */
9555 rows = item_count;
9556 for (row = 0; row < rows && !got_int; ++row)
9557 {
9558 msg_putchar('\n'); /* go to next line */
9559 if (got_int) /* 'q' typed in more */
9560 break;
9561 col = 0;
9562 for (i = row; i < item_count; i += rows)
9563 {
9564 msg_col = col; /* make columns */
9565 showoneopt(items[i], opt_flags);
9566 col += INC;
9567 }
9568 out_flush();
9569 ui_breakcheck();
9570 }
9571 }
9572 vim_free(items);
9573}
9574
9575/*
9576 * Return TRUE if option "p" has its default value.
9577 */
9578 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009579optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009580{
9581 int dvi;
9582
9583 if (varp == NULL)
9584 return TRUE; /* hidden option is always at default */
9585 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9586 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009587 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009588 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009589 /* the cast to long is required for Manx C, long_i is
9590 * needed for MSVC */
9591 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592 /* P_STRING */
9593 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9594}
9595
9596/*
9597 * showoneopt: show the value of one option
9598 * must not be called with a hidden option!
9599 */
9600 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009601showoneopt(
9602 struct vimoption *p,
9603 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009604{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009605 char_u *varp;
9606 int save_silent = silent_mode;
9607
9608 silent_mode = FALSE;
9609 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009610
9611 varp = get_varp_scope(p, opt_flags);
9612
9613 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9614 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9615 ? !curbufIsChanged() : !*(int *)varp))
9616 MSG_PUTS("no");
9617 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9618 MSG_PUTS("--");
9619 else
9620 MSG_PUTS(" ");
9621 MSG_PUTS(p->fullname);
9622 if (!(p->flags & P_BOOL))
9623 {
9624 msg_putchar('=');
9625 /* put value string in NameBuff */
9626 option_value2string(p, opt_flags);
9627 msg_outtrans(NameBuff);
9628 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009629
9630 silent_mode = save_silent;
9631 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632}
9633
9634/*
9635 * Write modified options as ":set" commands to a file.
9636 *
9637 * There are three values for "opt_flags":
9638 * OPT_GLOBAL: Write global option values and fresh values of
9639 * buffer-local options (used for start of a session
9640 * file).
9641 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9642 * curwin (used for a vimrc file).
9643 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9644 * and local values for window-local options of
9645 * curwin. Local values are also written when at the
9646 * default value, because a modeline or autocommand
9647 * may have set them when doing ":edit file" and the
9648 * user has set them back at the default or fresh
9649 * value.
9650 * When "local_only" is TRUE, don't write fresh
9651 * values, only local values (for ":mkview").
9652 * (fresh value = value used for a new buffer or window for a local option).
9653 *
9654 * Return FAIL on error, OK otherwise.
9655 */
9656 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009657makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009658{
9659 struct vimoption *p;
9660 char_u *varp; /* currently used value */
9661 char_u *varp_fresh; /* local value */
9662 char_u *varp_local = NULL; /* fresh value */
9663 char *cmd;
9664 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009665 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009666
9667 /*
9668 * The options that don't have a default (terminal name, columns, lines)
9669 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009670 * Do the loop over "options[]" twice: once for options with the
9671 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009672 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009673 for (pri = 1; pri >= 0; --pri)
9674 {
9675 for (p = &options[0]; !istermoption(p); p++)
9676 if (!(p->flags & P_NO_MKRC)
9677 && !istermoption(p)
9678 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009679 {
9680 /* skip global option when only doing locals */
9681 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9682 continue;
9683
9684 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9685 * file, they are always buffer-specific. */
9686 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9687 continue;
9688
9689 /* Global values are only written when not at the default value. */
9690 varp = get_varp_scope(p, opt_flags);
9691 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9692 continue;
9693
9694 round = 2;
9695 if (p->indir != PV_NONE)
9696 {
9697 if (p->var == VAR_WIN)
9698 {
9699 /* skip window-local option when only doing globals */
9700 if (!(opt_flags & OPT_LOCAL))
9701 continue;
9702 /* When fresh value of window-local option is not at the
9703 * default, need to write it too. */
9704 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9705 {
9706 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9707 if (!optval_default(p, varp_fresh))
9708 {
9709 round = 1;
9710 varp_local = varp;
9711 varp = varp_fresh;
9712 }
9713 }
9714 }
9715 }
9716
9717 /* Round 1: fresh value for window-local options.
9718 * Round 2: other values */
9719 for ( ; round <= 2; varp = varp_local, ++round)
9720 {
9721 if (round == 1 || (opt_flags & OPT_GLOBAL))
9722 cmd = "set";
9723 else
9724 cmd = "setlocal";
9725
9726 if (p->flags & P_BOOL)
9727 {
9728 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9729 return FAIL;
9730 }
9731 else if (p->flags & P_NUM)
9732 {
9733 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9734 return FAIL;
9735 }
9736 else /* P_STRING */
9737 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009738#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9739 int do_endif = FALSE;
9740
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741 /* Don't set 'syntax' and 'filetype' again if the value is
9742 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009743 if (
9744# if defined(FEAT_SYN_HL)
9745 p->indir == PV_SYN
9746# if defined(FEAT_AUTOCMD)
9747 ||
9748# endif
9749# endif
9750# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009751 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009752# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009753 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009754 {
9755 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9756 *(char_u **)(varp)) < 0
9757 || put_eol(fd) < 0)
9758 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009759 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009761#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9763 (p->flags & P_EXPAND) != 0) == FAIL)
9764 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009765#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9766 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009767 {
9768 if (put_line(fd, "endif") == FAIL)
9769 return FAIL;
9770 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009772 }
9773 }
9774 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009775 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009776 return OK;
9777}
9778
9779#if defined(FEAT_FOLDING) || defined(PROTO)
9780/*
9781 * Generate set commands for the local fold options only. Used when
9782 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9783 */
9784 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009785makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009786{
9787 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9788# ifdef FEAT_EVAL
9789 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9790 == FAIL
9791# endif
9792 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9793 == FAIL
9794 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9795 == FAIL
9796 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9797 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9798 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9799 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9800 )
9801 return FAIL;
9802
9803 return OK;
9804}
9805#endif
9806
9807 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009808put_setstring(
9809 FILE *fd,
9810 char *cmd,
9811 char *name,
9812 char_u **valuep,
9813 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009814{
9815 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009816 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009817
9818 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9819 return FAIL;
9820 if (*valuep != NULL)
9821 {
9822 /* Output 'pastetoggle' as key names. For other
9823 * options some characters have to be escaped with
9824 * CTRL-V or backslash */
9825 if (valuep == &p_pt)
9826 {
9827 s = *valuep;
9828 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009829 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009830 return FAIL;
9831 }
9832 else if (expand)
9833 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009834 buf = alloc(MAXPATHL);
9835 if (buf == NULL)
9836 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009837 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9838 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009839 {
9840 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009841 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009842 }
9843 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009844 }
9845 else if (put_escstr(fd, *valuep, 2) == FAIL)
9846 return FAIL;
9847 }
9848 if (put_eol(fd) < 0)
9849 return FAIL;
9850 return OK;
9851}
9852
9853 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009854put_setnum(
9855 FILE *fd,
9856 char *cmd,
9857 char *name,
9858 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009859{
9860 long wc;
9861
9862 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9863 return FAIL;
9864 if (wc_use_keyname((char_u *)valuep, &wc))
9865 {
9866 /* print 'wildchar' and 'wildcharm' as a key name */
9867 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9868 return FAIL;
9869 }
9870 else if (fprintf(fd, "%ld", *valuep) < 0)
9871 return FAIL;
9872 if (put_eol(fd) < 0)
9873 return FAIL;
9874 return OK;
9875}
9876
9877 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009878put_setbool(
9879 FILE *fd,
9880 char *cmd,
9881 char *name,
9882 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009883{
Bram Moolenaar893de922007-10-02 18:40:57 +00009884 if (value < 0) /* global/local option using global value */
9885 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009886 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9887 || put_eol(fd) < 0)
9888 return FAIL;
9889 return OK;
9890}
9891
9892/*
9893 * Clear all the terminal options.
9894 * If the option has been allocated, free the memory.
9895 * Terminal options are never hidden or indirect.
9896 */
9897 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009898clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009900 /*
9901 * Reset a few things before clearing the old options. This may cause
9902 * outputting a few things that the terminal doesn't understand, but the
9903 * screen will be cleared later, so this is OK.
9904 */
9905#ifdef FEAT_MOUSE_TTY
9906 mch_setmouse(FALSE); /* switch mouse off */
9907#endif
9908#ifdef FEAT_TITLE
9909 mch_restore_title(3); /* restore window titles */
9910#endif
9911#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9912 /* When starting the GUI close the display opened for the clipboard.
9913 * After restoring the title, because that will need the display. */
9914 if (gui.starting)
9915 clear_xterm_clip();
9916#endif
9917#ifdef WIN3264
9918 /*
9919 * Check if this is allowed now.
9920 */
9921 if (can_end_termcap_mode(FALSE) == TRUE)
9922#endif
9923 stoptermcap(); /* stop termcap mode */
9924
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009925 free_termoptions();
9926}
9927
9928 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009929free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009930{
9931 struct vimoption *p;
9932
Bram Moolenaar071d4272004-06-13 20:20:40 +00009933 for (p = &options[0]; p->fullname != NULL; p++)
9934 if (istermoption(p))
9935 {
9936 if (p->flags & P_ALLOCED)
9937 free_string_option(*(char_u **)(p->var));
9938 if (p->flags & P_DEF_ALLOCED)
9939 free_string_option(p->def_val[VI_DEFAULT]);
9940 *(char_u **)(p->var) = empty_option;
9941 p->def_val[VI_DEFAULT] = empty_option;
9942 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9943 }
9944 clear_termcodes();
9945}
9946
9947/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009948 * Free the string for one term option, if it was allocated.
9949 * Set the string to empty_option and clear allocated flag.
9950 * "var" points to the option value.
9951 */
9952 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009953free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009954{
9955 struct vimoption *p;
9956
9957 for (p = &options[0]; p->fullname != NULL; p++)
9958 if (p->var == var)
9959 {
9960 if (p->flags & P_ALLOCED)
9961 free_string_option(*(char_u **)(p->var));
9962 *(char_u **)(p->var) = empty_option;
9963 p->flags &= ~P_ALLOCED;
9964 break;
9965 }
9966}
9967
9968/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009969 * Set the terminal option defaults to the current value.
9970 * Used after setting the terminal name.
9971 */
9972 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009973set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974{
9975 struct vimoption *p;
9976
9977 for (p = &options[0]; p->fullname != NULL; p++)
9978 {
9979 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9980 {
9981 if (p->flags & P_DEF_ALLOCED)
9982 {
9983 free_string_option(p->def_val[VI_DEFAULT]);
9984 p->flags &= ~P_DEF_ALLOCED;
9985 }
9986 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9987 if (p->flags & P_ALLOCED)
9988 {
9989 p->flags |= P_DEF_ALLOCED;
9990 p->flags &= ~P_ALLOCED; /* don't free the value now */
9991 }
9992 }
9993 }
9994}
9995
9996/*
9997 * return TRUE if 'p' starts with 't_'
9998 */
9999 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010000istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010001{
10002 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10003}
10004
10005/*
10006 * Compute columns for ruler and shown command. 'sc_col' is also used to
10007 * decide what the maximum length of a message on the status line can be.
10008 * If there is a status line for the last window, 'sc_col' is independent
10009 * of 'ru_col'.
10010 */
10011
10012#define COL_RULER 17 /* columns needed by standard ruler */
10013
10014 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010015comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016{
10017#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10018 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10019
10020 sc_col = 0;
10021 ru_col = 0;
10022 if (p_ru)
10023 {
10024#ifdef FEAT_STL_OPT
10025 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10026#else
10027 ru_col = COL_RULER + 1;
10028#endif
10029 /* no last status line, adjust sc_col */
10030 if (!last_has_status)
10031 sc_col = ru_col;
10032 }
10033 if (p_sc)
10034 {
10035 sc_col += SHOWCMD_COLS;
10036 if (!p_ru || last_has_status) /* no need for separating space */
10037 ++sc_col;
10038 }
10039 sc_col = Columns - sc_col;
10040 ru_col = Columns - ru_col;
10041 if (sc_col <= 0) /* screen too narrow, will become a mess */
10042 sc_col = 1;
10043 if (ru_col <= 0)
10044 ru_col = 1;
10045#else
10046 sc_col = Columns;
10047 ru_col = Columns;
10048#endif
10049}
10050
10051/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010052 * Unset local option value, similar to ":set opt<".
10053 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010054 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010055unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010056{
10057 struct vimoption *p;
10058 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010059 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010060
10061 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010062 if (opt_idx < 0)
10063 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010064 p = &(options[opt_idx]);
10065
10066 switch ((int)p->indir)
10067 {
10068 /* global option with local value: use local value if it's been set */
10069 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010070 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010071 break;
10072 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010073 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010074 break;
10075 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010076 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010077 break;
10078 case PV_AR:
10079 buf->b_p_ar = -1;
10080 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010081 case PV_BKC:
10082 clear_string_option(&buf->b_p_bkc);
10083 buf->b_bkc_flags = 0;
10084 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010085 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010086 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010087 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010088 case PV_TC:
10089 clear_string_option(&buf->b_p_tc);
10090 buf->b_tc_flags = 0;
10091 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010092#ifdef FEAT_FIND_ID
10093 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010094 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010095 break;
10096 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010097 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010098 break;
10099#endif
10100#ifdef FEAT_INS_EXPAND
10101 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010102 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010103 break;
10104 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010105 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010106 break;
10107#endif
10108#ifdef FEAT_QUICKFIX
10109 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010110 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010111 break;
10112 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010113 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010114 break;
10115 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010116 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010117 break;
10118#endif
10119#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10120 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010121 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010122 break;
10123#endif
10124#if defined(FEAT_CRYPT)
10125 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010126 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010127 break;
10128#endif
10129#ifdef FEAT_STL_OPT
10130 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010131 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010132 break;
10133#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010134 case PV_UL:
10135 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10136 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010137#ifdef FEAT_LISP
10138 case PV_LW:
10139 clear_string_option(&buf->b_p_lw);
10140 break;
10141#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010142 }
10143}
10144
10145/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146 * Get pointer to option variable, depending on local or global scope.
10147 */
10148 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010149get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010150{
10151 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10152 {
10153 if (p->var == VAR_WIN)
10154 return (char_u *)GLOBAL_WO(get_varp(p));
10155 return p->var;
10156 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010157 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010158 {
10159 switch ((int)p->indir)
10160 {
10161#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010162 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10163 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10164 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010165#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010166 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10167 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10168 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010169 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010170 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010171 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010173 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10174 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175#endif
10176#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010177 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10178 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010180#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10181 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10182#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010183#if defined(FEAT_CRYPT)
10184 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10185#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010186#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010187 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010188#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010189 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010190#ifdef FEAT_LISP
10191 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10192#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010193 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194 }
10195 return NULL; /* "cannot happen" */
10196 }
10197 return get_varp(p);
10198}
10199
10200/*
10201 * Get pointer to option variable.
10202 */
10203 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010204get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205{
10206 /* hidden option, always return NULL */
10207 if (p->var == NULL)
10208 return NULL;
10209
10210 switch ((int)p->indir)
10211 {
10212 case PV_NONE: return p->var;
10213
10214 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010215 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010217 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010219 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010221 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010222 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010223 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010224 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010225 case PV_TC: return *curbuf->b_p_tc != NUL
10226 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010227 case PV_BKC: return *curbuf->b_p_bkc != NUL
10228 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010230 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010231 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010232 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10234#endif
10235#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010236 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010237 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010238 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10240#endif
10241#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010242 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010243 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010244 case PV_GP: return *curbuf->b_p_gp != NUL
10245 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10246 case PV_MP: return *curbuf->b_p_mp != NUL
10247 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010249#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10250 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10251 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10252#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010253#if defined(FEAT_CRYPT)
10254 case PV_CM: return *curbuf->b_p_cm != NUL
10255 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10256#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010257#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010258 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010259 ? (char_u *)&(curwin->w_p_stl) : p->var;
10260#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010261 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10262 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010263#ifdef FEAT_LISP
10264 case PV_LW: return *curbuf->b_p_lw != NUL
10265 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10266#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010267
10268#ifdef FEAT_ARABIC
10269 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10270#endif
10271 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010272#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010273 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10274#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010275#ifdef FEAT_SYN_HL
10276 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10277 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010278 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010279#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010280#ifdef FEAT_DIFF
10281 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10282#endif
10283#ifdef FEAT_FOLDING
10284 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10285 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10286 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10287 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10288 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10289 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10290 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10291# ifdef FEAT_EVAL
10292 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10293 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10294# endif
10295 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10296#endif
10297 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010298 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010299#ifdef FEAT_LINEBREAK
10300 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10301#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010302#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010304 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10307 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10308#endif
10309#ifdef FEAT_RIGHTLEFT
10310 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10311 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10312#endif
10313 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10314 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10315#ifdef FEAT_LINEBREAK
10316 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010317 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10318 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319#endif
10320#ifdef FEAT_SCROLLBIND
10321 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10322#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010323#ifdef FEAT_CURSORBIND
10324 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10325#endif
10326#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010327 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10328 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330
10331 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10332 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10333#ifdef FEAT_MBYTE
10334 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10335#endif
10336#if defined(FEAT_QUICKFIX)
10337 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10338 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10339#endif
10340 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10341 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10342#ifdef FEAT_CINDENT
10343 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10344 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10345 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10346#endif
10347#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10348 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10349#endif
10350#ifdef FEAT_COMMENTS
10351 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10352#endif
10353#ifdef FEAT_FOLDING
10354 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10355#endif
10356#ifdef FEAT_INS_EXPAND
10357 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10358#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010359#ifdef FEAT_COMPL_FUNC
10360 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010361 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010362#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010364 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10366#ifdef FEAT_MBYTE
10367 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10368#endif
10369 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10370#ifdef FEAT_AUTOCMD
10371 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10372#endif
10373 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010374 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10376 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10377 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10378 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10379#ifdef FEAT_FIND_ID
10380# ifdef FEAT_EVAL
10381 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10382# endif
10383#endif
10384#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10385 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10386 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10387#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010388#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010389 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010391#ifdef FEAT_CRYPT
10392 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10393#endif
10394#ifdef FEAT_LISP
10395 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10396#endif
10397 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10398 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10399 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10400 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10401 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010403#ifdef FEAT_TEXTOBJ
10404 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10407#ifdef FEAT_SMARTINDENT
10408 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10409#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010410 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010411 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10412#ifdef FEAT_SEARCHPATH
10413 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10414#endif
10415 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10416#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010417 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010418 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10419#endif
10420#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010421 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10422 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10423 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010424#endif
10425 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10426 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10427 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10428 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010429#ifdef FEAT_PERSISTENT_UNDO
10430 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10433#ifdef FEAT_KEYMAP
10434 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10435#endif
10436 default: EMSG(_("E356: get_varp ERROR"));
10437 }
10438 /* always return a valid pointer to avoid a crash! */
10439 return (char_u *)&(curbuf->b_p_wm);
10440}
10441
10442/*
10443 * Get the value of 'equalprg', either the buffer-local one or the global one.
10444 */
10445 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010446get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010447{
10448 if (*curbuf->b_p_ep == NUL)
10449 return p_ep;
10450 return curbuf->b_p_ep;
10451}
10452
10453#if defined(FEAT_WINDOWS) || defined(PROTO)
10454/*
10455 * Copy options from one window to another.
10456 * Used when splitting a window.
10457 */
10458 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010459win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010460{
10461 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10462 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10463# ifdef FEAT_RIGHTLEFT
10464# ifdef FEAT_FKMAP
10465 /* Is this right? */
10466 wp_to->w_farsi = wp_from->w_farsi;
10467# endif
10468# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010469#if defined(FEAT_LINEBREAK)
10470 briopt_check(wp_to);
10471#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472}
10473#endif
10474
10475/*
10476 * Copy the options from one winopt_T to another.
10477 * Doesn't free the old option values in "to", use clear_winopt() for that.
10478 * The 'scroll' option is not copied, because it depends on the window height.
10479 * The 'previewwindow' option is reset, there can be only one preview window.
10480 */
10481 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010482copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483{
10484#ifdef FEAT_ARABIC
10485 to->wo_arab = from->wo_arab;
10486#endif
10487 to->wo_list = from->wo_list;
10488 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010489 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010490#ifdef FEAT_LINEBREAK
10491 to->wo_nuw = from->wo_nuw;
10492#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493#ifdef FEAT_RIGHTLEFT
10494 to->wo_rl = from->wo_rl;
10495 to->wo_rlc = vim_strsave(from->wo_rlc);
10496#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010497#ifdef FEAT_STL_OPT
10498 to->wo_stl = vim_strsave(from->wo_stl);
10499#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010501#ifdef FEAT_DIFF
10502 to->wo_wrap_save = from->wo_wrap_save;
10503#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504#ifdef FEAT_LINEBREAK
10505 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010506 to->wo_bri = from->wo_bri;
10507 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508#endif
10509#ifdef FEAT_SCROLLBIND
10510 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010511 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010513#ifdef FEAT_CURSORBIND
10514 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010515 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010516#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010517#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010518 to->wo_spell = from->wo_spell;
10519#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010520#ifdef FEAT_SYN_HL
10521 to->wo_cuc = from->wo_cuc;
10522 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010523 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010524#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010525#ifdef FEAT_DIFF
10526 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010527 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010529#ifdef FEAT_CONCEAL
10530 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010531 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010532#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533#ifdef FEAT_FOLDING
10534 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010535 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010537 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 to->wo_fdi = vim_strsave(from->wo_fdi);
10539 to->wo_fml = from->wo_fml;
10540 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010541 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010543 to->wo_fdm_save = from->wo_diff_saved
10544 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545 to->wo_fdn = from->wo_fdn;
10546# ifdef FEAT_EVAL
10547 to->wo_fde = vim_strsave(from->wo_fde);
10548 to->wo_fdt = vim_strsave(from->wo_fdt);
10549# endif
10550 to->wo_fmr = vim_strsave(from->wo_fmr);
10551#endif
10552 check_winopt(to); /* don't want NULL pointers */
10553}
10554
10555/*
10556 * Check string options in a window for a NULL value.
10557 */
10558 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010559check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560{
10561 check_winopt(&win->w_onebuf_opt);
10562 check_winopt(&win->w_allbuf_opt);
10563}
10564
10565/*
10566 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10567 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010568 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010569check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010570{
10571#ifdef FEAT_FOLDING
10572 check_string_option(&wop->wo_fdi);
10573 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010574 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575# ifdef FEAT_EVAL
10576 check_string_option(&wop->wo_fde);
10577 check_string_option(&wop->wo_fdt);
10578# endif
10579 check_string_option(&wop->wo_fmr);
10580#endif
10581#ifdef FEAT_RIGHTLEFT
10582 check_string_option(&wop->wo_rlc);
10583#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010584#ifdef FEAT_STL_OPT
10585 check_string_option(&wop->wo_stl);
10586#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010587#ifdef FEAT_SYN_HL
10588 check_string_option(&wop->wo_cc);
10589#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010590#ifdef FEAT_CONCEAL
10591 check_string_option(&wop->wo_cocu);
10592#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010593#ifdef FEAT_LINEBREAK
10594 check_string_option(&wop->wo_briopt);
10595#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596}
10597
10598/*
10599 * Free the allocated memory inside a winopt_T.
10600 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010602clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603{
10604#ifdef FEAT_FOLDING
10605 clear_string_option(&wop->wo_fdi);
10606 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010607 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608# ifdef FEAT_EVAL
10609 clear_string_option(&wop->wo_fde);
10610 clear_string_option(&wop->wo_fdt);
10611# endif
10612 clear_string_option(&wop->wo_fmr);
10613#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010614#ifdef FEAT_LINEBREAK
10615 clear_string_option(&wop->wo_briopt);
10616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617#ifdef FEAT_RIGHTLEFT
10618 clear_string_option(&wop->wo_rlc);
10619#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010620#ifdef FEAT_STL_OPT
10621 clear_string_option(&wop->wo_stl);
10622#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010623#ifdef FEAT_SYN_HL
10624 clear_string_option(&wop->wo_cc);
10625#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010626#ifdef FEAT_CONCEAL
10627 clear_string_option(&wop->wo_cocu);
10628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629}
10630
10631/*
10632 * Copy global option values to local options for one buffer.
10633 * Used when creating a new buffer and sometimes when entering a buffer.
10634 * flags:
10635 * BCO_ENTER We will enter the buf buffer.
10636 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10637 * appropriate.
10638 * BCO_NOHELP Don't copy the values to a help buffer.
10639 */
10640 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010641buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642{
10643 int should_copy = TRUE;
10644 char_u *save_p_isk = NULL; /* init for GCC */
10645 int dont_do_help;
10646 int did_isk = FALSE;
10647
10648 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010649 * Skip this when the option defaults have not been set yet. Happens when
10650 * main() allocates the first buffer.
10651 */
10652 if (p_cpo != NULL)
10653 {
10654 /*
10655 * Always copy when entering and 'cpo' contains 'S'.
10656 * Don't copy when already initialized.
10657 * Don't copy when 'cpo' contains 's' and not entering.
10658 * 'S' BCO_ENTER initialized 's' should_copy
10659 * yes yes X X TRUE
10660 * yes no yes X FALSE
10661 * no X yes X FALSE
10662 * X no no yes FALSE
10663 * X no no no TRUE
10664 * no yes no X TRUE
10665 */
10666 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10667 && (buf->b_p_initialized
10668 || (!(flags & BCO_ENTER)
10669 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10670 should_copy = FALSE;
10671
10672 if (should_copy || (flags & BCO_ALWAYS))
10673 {
10674 /* Don't copy the options specific to a help buffer when
10675 * BCO_NOHELP is given or the options were initialized already
10676 * (jumping back to a help file with CTRL-T or CTRL-O) */
10677 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10678 || buf->b_p_initialized;
10679 if (dont_do_help) /* don't free b_p_isk */
10680 {
10681 save_p_isk = buf->b_p_isk;
10682 buf->b_p_isk = NULL;
10683 }
10684 /*
10685 * Always free the allocated strings.
10686 * If not already initialized, set 'readonly' and copy 'fileformat'.
10687 */
10688 if (!buf->b_p_initialized)
10689 {
10690 free_buf_options(buf, TRUE);
10691 buf->b_p_ro = FALSE; /* don't copy readonly */
10692 buf->b_p_tx = p_tx;
10693#ifdef FEAT_MBYTE
10694 buf->b_p_fenc = vim_strsave(p_fenc);
10695#endif
10696 buf->b_p_ff = vim_strsave(p_ff);
10697#if defined(FEAT_QUICKFIX)
10698 buf->b_p_bh = empty_option;
10699 buf->b_p_bt = empty_option;
10700#endif
10701 }
10702 else
10703 free_buf_options(buf, FALSE);
10704
10705 buf->b_p_ai = p_ai;
10706 buf->b_p_ai_nopaste = p_ai_nopaste;
10707 buf->b_p_sw = p_sw;
10708 buf->b_p_tw = p_tw;
10709 buf->b_p_tw_nopaste = p_tw_nopaste;
10710 buf->b_p_tw_nobin = p_tw_nobin;
10711 buf->b_p_wm = p_wm;
10712 buf->b_p_wm_nopaste = p_wm_nopaste;
10713 buf->b_p_wm_nobin = p_wm_nobin;
10714 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010715#ifdef FEAT_MBYTE
10716 buf->b_p_bomb = p_bomb;
10717#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010718 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719 buf->b_p_et = p_et;
10720 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010721 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010722 buf->b_p_ml = p_ml;
10723 buf->b_p_ml_nobin = p_ml_nobin;
10724 buf->b_p_inf = p_inf;
10725 buf->b_p_swf = p_swf;
10726#ifdef FEAT_INS_EXPAND
10727 buf->b_p_cpt = vim_strsave(p_cpt);
10728#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010729#ifdef FEAT_COMPL_FUNC
10730 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010731 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010732#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010733 buf->b_p_sts = p_sts;
10734 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010736#ifdef FEAT_COMMENTS
10737 buf->b_p_com = vim_strsave(p_com);
10738#endif
10739#ifdef FEAT_FOLDING
10740 buf->b_p_cms = vim_strsave(p_cms);
10741#endif
10742 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010743 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744 buf->b_p_nf = vim_strsave(p_nf);
10745 buf->b_p_mps = vim_strsave(p_mps);
10746#ifdef FEAT_SMARTINDENT
10747 buf->b_p_si = p_si;
10748#endif
10749 buf->b_p_ci = p_ci;
10750#ifdef FEAT_CINDENT
10751 buf->b_p_cin = p_cin;
10752 buf->b_p_cink = vim_strsave(p_cink);
10753 buf->b_p_cino = vim_strsave(p_cino);
10754#endif
10755#ifdef FEAT_AUTOCMD
10756 /* Don't copy 'filetype', it must be detected */
10757 buf->b_p_ft = empty_option;
10758#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759 buf->b_p_pi = p_pi;
10760#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10761 buf->b_p_cinw = vim_strsave(p_cinw);
10762#endif
10763#ifdef FEAT_LISP
10764 buf->b_p_lisp = p_lisp;
10765#endif
10766#ifdef FEAT_SYN_HL
10767 /* Don't copy 'syntax', it must be set */
10768 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010769 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010770 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010771#endif
10772#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010773 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010774 (void)compile_cap_prog(&buf->b_s);
10775 buf->b_s.b_p_spf = vim_strsave(p_spf);
10776 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777#endif
10778#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10779 buf->b_p_inde = vim_strsave(p_inde);
10780 buf->b_p_indk = vim_strsave(p_indk);
10781#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010782#if defined(FEAT_EVAL)
10783 buf->b_p_fex = vim_strsave(p_fex);
10784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785#ifdef FEAT_CRYPT
10786 buf->b_p_key = vim_strsave(p_key);
10787#endif
10788#ifdef FEAT_SEARCHPATH
10789 buf->b_p_sua = vim_strsave(p_sua);
10790#endif
10791#ifdef FEAT_KEYMAP
10792 buf->b_p_keymap = vim_strsave(p_keymap);
10793 buf->b_kmap_state |= KEYMAP_INIT;
10794#endif
10795 /* This isn't really an option, but copying the langmap and IME
10796 * state from the current buffer is better than resetting it. */
10797 buf->b_p_iminsert = p_iminsert;
10798 buf->b_p_imsearch = p_imsearch;
10799
10800 /* options that are normally global but also have a local value
10801 * are not copied, start using the global value */
10802 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010803 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010804 buf->b_p_bkc = empty_option;
10805 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806#ifdef FEAT_QUICKFIX
10807 buf->b_p_gp = empty_option;
10808 buf->b_p_mp = empty_option;
10809 buf->b_p_efm = empty_option;
10810#endif
10811 buf->b_p_ep = empty_option;
10812 buf->b_p_kp = empty_option;
10813 buf->b_p_path = empty_option;
10814 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010815 buf->b_p_tc = empty_option;
10816 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817#ifdef FEAT_FIND_ID
10818 buf->b_p_def = empty_option;
10819 buf->b_p_inc = empty_option;
10820# ifdef FEAT_EVAL
10821 buf->b_p_inex = vim_strsave(p_inex);
10822# endif
10823#endif
10824#ifdef FEAT_INS_EXPAND
10825 buf->b_p_dict = empty_option;
10826 buf->b_p_tsr = empty_option;
10827#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010828#ifdef FEAT_TEXTOBJ
10829 buf->b_p_qe = vim_strsave(p_qe);
10830#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010831#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10832 buf->b_p_bexpr = empty_option;
10833#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010834#if defined(FEAT_CRYPT)
10835 buf->b_p_cm = empty_option;
10836#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010837#ifdef FEAT_PERSISTENT_UNDO
10838 buf->b_p_udf = p_udf;
10839#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010840#ifdef FEAT_LISP
10841 buf->b_p_lw = empty_option;
10842#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010843
10844 /*
10845 * Don't copy the options set by ex_help(), use the saved values,
10846 * when going from a help buffer to a non-help buffer.
10847 * Don't touch these at all when BCO_NOHELP is used and going from
10848 * or to a help buffer.
10849 */
10850 if (dont_do_help)
10851 buf->b_p_isk = save_p_isk;
10852 else
10853 {
10854 buf->b_p_isk = vim_strsave(p_isk);
10855 did_isk = TRUE;
10856 buf->b_p_ts = p_ts;
10857 buf->b_help = FALSE;
10858#ifdef FEAT_QUICKFIX
10859 if (buf->b_p_bt[0] == 'h')
10860 clear_string_option(&buf->b_p_bt);
10861#endif
10862 buf->b_p_ma = p_ma;
10863 }
10864 }
10865
10866 /*
10867 * When the options should be copied (ignoring BCO_ALWAYS), set the
10868 * flag that indicates that the options have been initialized.
10869 */
10870 if (should_copy)
10871 buf->b_p_initialized = TRUE;
10872 }
10873
10874 check_buf_options(buf); /* make sure we don't have NULLs */
10875 if (did_isk)
10876 (void)buf_init_chartab(buf, FALSE);
10877}
10878
10879/*
10880 * Reset the 'modifiable' option and its default value.
10881 */
10882 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010883reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884{
10885 int opt_idx;
10886
10887 curbuf->b_p_ma = FALSE;
10888 p_ma = FALSE;
10889 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010890 if (opt_idx >= 0)
10891 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892}
10893
10894/*
10895 * Set the global value for 'iminsert' to the local value.
10896 */
10897 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010898set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899{
10900 p_iminsert = curbuf->b_p_iminsert;
10901}
10902
10903/*
10904 * Set the global value for 'imsearch' to the local value.
10905 */
10906 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010907set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010908{
10909 p_imsearch = curbuf->b_p_imsearch;
10910}
10911
10912#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10913static int expand_option_idx = -1;
10914static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10915static int expand_option_flags = 0;
10916
10917 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010918set_context_in_set_cmd(
10919 expand_T *xp,
10920 char_u *arg,
10921 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922{
10923 int nextchar;
10924 long_u flags = 0; /* init for GCC */
10925 int opt_idx = 0; /* init for GCC */
10926 char_u *p;
10927 char_u *s;
10928 int is_term_option = FALSE;
10929 int key;
10930
10931 expand_option_flags = opt_flags;
10932
10933 xp->xp_context = EXPAND_SETTINGS;
10934 if (*arg == NUL)
10935 {
10936 xp->xp_pattern = arg;
10937 return;
10938 }
10939 p = arg + STRLEN(arg) - 1;
10940 if (*p == ' ' && *(p - 1) != '\\')
10941 {
10942 xp->xp_pattern = p + 1;
10943 return;
10944 }
10945 while (p > arg)
10946 {
10947 s = p;
10948 /* count number of backslashes before ' ' or ',' */
10949 if (*p == ' ' || *p == ',')
10950 {
10951 while (s > arg && *(s - 1) == '\\')
10952 --s;
10953 }
10954 /* break at a space with an even number of backslashes */
10955 if (*p == ' ' && ((p - s) & 1) == 0)
10956 {
10957 ++p;
10958 break;
10959 }
10960 --p;
10961 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010962 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963 {
10964 xp->xp_context = EXPAND_BOOL_SETTINGS;
10965 p += 2;
10966 }
10967 if (STRNCMP(p, "inv", 3) == 0)
10968 {
10969 xp->xp_context = EXPAND_BOOL_SETTINGS;
10970 p += 3;
10971 }
10972 xp->xp_pattern = arg = p;
10973 if (*arg == '<')
10974 {
10975 while (*p != '>')
10976 if (*p++ == NUL) /* expand terminal option name */
10977 return;
10978 key = get_special_key_code(arg + 1);
10979 if (key == 0) /* unknown name */
10980 {
10981 xp->xp_context = EXPAND_NOTHING;
10982 return;
10983 }
10984 nextchar = *++p;
10985 is_term_option = TRUE;
10986 expand_option_name[2] = KEY2TERMCAP0(key);
10987 expand_option_name[3] = KEY2TERMCAP1(key);
10988 }
10989 else
10990 {
10991 if (p[0] == 't' && p[1] == '_')
10992 {
10993 p += 2;
10994 if (*p != NUL)
10995 ++p;
10996 if (*p == NUL)
10997 return; /* expand option name */
10998 nextchar = *++p;
10999 is_term_option = TRUE;
11000 expand_option_name[2] = p[-2];
11001 expand_option_name[3] = p[-1];
11002 }
11003 else
11004 {
11005 /* Allow * wildcard */
11006 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11007 p++;
11008 if (*p == NUL)
11009 return;
11010 nextchar = *p;
11011 *p = NUL;
11012 opt_idx = findoption(arg);
11013 *p = nextchar;
11014 if (opt_idx == -1 || options[opt_idx].var == NULL)
11015 {
11016 xp->xp_context = EXPAND_NOTHING;
11017 return;
11018 }
11019 flags = options[opt_idx].flags;
11020 if (flags & P_BOOL)
11021 {
11022 xp->xp_context = EXPAND_NOTHING;
11023 return;
11024 }
11025 }
11026 }
11027 /* handle "-=" and "+=" */
11028 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11029 {
11030 ++p;
11031 nextchar = '=';
11032 }
11033 if ((nextchar != '=' && nextchar != ':')
11034 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11035 {
11036 xp->xp_context = EXPAND_UNSUCCESSFUL;
11037 return;
11038 }
11039 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11040 {
11041 xp->xp_context = EXPAND_OLD_SETTING;
11042 if (is_term_option)
11043 expand_option_idx = -1;
11044 else
11045 expand_option_idx = opt_idx;
11046 xp->xp_pattern = p + 1;
11047 return;
11048 }
11049 xp->xp_context = EXPAND_NOTHING;
11050 if (is_term_option || (flags & P_NUM))
11051 return;
11052
11053 xp->xp_pattern = p + 1;
11054
11055 if (flags & P_EXPAND)
11056 {
11057 p = options[opt_idx].var;
11058 if (p == (char_u *)&p_bdir
11059 || p == (char_u *)&p_dir
11060 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011061 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011062 || p == (char_u *)&p_rtp
11063#ifdef FEAT_SEARCHPATH
11064 || p == (char_u *)&p_cdpath
11065#endif
11066#ifdef FEAT_SESSION
11067 || p == (char_u *)&p_vdir
11068#endif
11069 )
11070 {
11071 xp->xp_context = EXPAND_DIRECTORIES;
11072 if (p == (char_u *)&p_path
11073#ifdef FEAT_SEARCHPATH
11074 || p == (char_u *)&p_cdpath
11075#endif
11076 )
11077 xp->xp_backslash = XP_BS_THREE;
11078 else
11079 xp->xp_backslash = XP_BS_ONE;
11080 }
11081 else
11082 {
11083 xp->xp_context = EXPAND_FILES;
11084 /* for 'tags' need three backslashes for a space */
11085 if (p == (char_u *)&p_tags)
11086 xp->xp_backslash = XP_BS_THREE;
11087 else
11088 xp->xp_backslash = XP_BS_ONE;
11089 }
11090 }
11091
11092 /* For an option that is a list of file names, find the start of the
11093 * last file name. */
11094 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11095 {
11096 /* count number of backslashes before ' ' or ',' */
11097 if (*p == ' ' || *p == ',')
11098 {
11099 s = p;
11100 while (s > xp->xp_pattern && *(s - 1) == '\\')
11101 --s;
11102 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11103 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11104 {
11105 xp->xp_pattern = p + 1;
11106 break;
11107 }
11108 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011109
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011110#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011111 /* for 'spellsuggest' start at "file:" */
11112 if (options[opt_idx].var == (char_u *)&p_sps
11113 && STRNCMP(p, "file:", 5) == 0)
11114 {
11115 xp->xp_pattern = p + 5;
11116 break;
11117 }
11118#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011119 }
11120
11121 return;
11122}
11123
11124 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011125ExpandSettings(
11126 expand_T *xp,
11127 regmatch_T *regmatch,
11128 int *num_file,
11129 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011130{
11131 int num_normal = 0; /* Nr of matching non-term-code settings */
11132 int num_term = 0; /* Nr of matching terminal code settings */
11133 int opt_idx;
11134 int match;
11135 int count = 0;
11136 char_u *str;
11137 int loop;
11138 int is_term_opt;
11139 char_u name_buf[MAX_KEY_NAME_LEN];
11140 static char *(names[]) = {"all", "termcap"};
11141 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11142
11143 /* do this loop twice:
11144 * loop == 0: count the number of matching options
11145 * loop == 1: copy the matching options into allocated memory
11146 */
11147 for (loop = 0; loop <= 1; ++loop)
11148 {
11149 regmatch->rm_ic = ic;
11150 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11151 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011152 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11153 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11155 {
11156 if (loop == 0)
11157 num_normal++;
11158 else
11159 (*file)[count++] = vim_strsave((char_u *)names[match]);
11160 }
11161 }
11162 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11163 opt_idx++)
11164 {
11165 if (options[opt_idx].var == NULL)
11166 continue;
11167 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11168 && !(options[opt_idx].flags & P_BOOL))
11169 continue;
11170 is_term_opt = istermoption(&options[opt_idx]);
11171 if (is_term_opt && num_normal > 0)
11172 continue;
11173 match = FALSE;
11174 if (vim_regexec(regmatch, str, (colnr_T)0)
11175 || (options[opt_idx].shortname != NULL
11176 && vim_regexec(regmatch,
11177 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11178 match = TRUE;
11179 else if (is_term_opt)
11180 {
11181 name_buf[0] = '<';
11182 name_buf[1] = 't';
11183 name_buf[2] = '_';
11184 name_buf[3] = str[2];
11185 name_buf[4] = str[3];
11186 name_buf[5] = '>';
11187 name_buf[6] = NUL;
11188 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11189 {
11190 match = TRUE;
11191 str = name_buf;
11192 }
11193 }
11194 if (match)
11195 {
11196 if (loop == 0)
11197 {
11198 if (is_term_opt)
11199 num_term++;
11200 else
11201 num_normal++;
11202 }
11203 else
11204 (*file)[count++] = vim_strsave(str);
11205 }
11206 }
11207 /*
11208 * Check terminal key codes, these are not in the option table
11209 */
11210 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11211 {
11212 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11213 {
11214 if (!isprint(str[0]) || !isprint(str[1]))
11215 continue;
11216
11217 name_buf[0] = 't';
11218 name_buf[1] = '_';
11219 name_buf[2] = str[0];
11220 name_buf[3] = str[1];
11221 name_buf[4] = NUL;
11222
11223 match = FALSE;
11224 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11225 match = TRUE;
11226 else
11227 {
11228 name_buf[0] = '<';
11229 name_buf[1] = 't';
11230 name_buf[2] = '_';
11231 name_buf[3] = str[0];
11232 name_buf[4] = str[1];
11233 name_buf[5] = '>';
11234 name_buf[6] = NUL;
11235
11236 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11237 match = TRUE;
11238 }
11239 if (match)
11240 {
11241 if (loop == 0)
11242 num_term++;
11243 else
11244 (*file)[count++] = vim_strsave(name_buf);
11245 }
11246 }
11247
11248 /*
11249 * Check special key names.
11250 */
11251 regmatch->rm_ic = TRUE; /* ignore case here */
11252 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11253 {
11254 name_buf[0] = '<';
11255 STRCPY(name_buf + 1, str);
11256 STRCAT(name_buf, ">");
11257
11258 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11259 {
11260 if (loop == 0)
11261 num_term++;
11262 else
11263 (*file)[count++] = vim_strsave(name_buf);
11264 }
11265 }
11266 }
11267 if (loop == 0)
11268 {
11269 if (num_normal > 0)
11270 *num_file = num_normal;
11271 else if (num_term > 0)
11272 *num_file = num_term;
11273 else
11274 return OK;
11275 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11276 if (*file == NULL)
11277 {
11278 *file = (char_u **)"";
11279 return FAIL;
11280 }
11281 }
11282 }
11283 return OK;
11284}
11285
11286 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011287ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011288{
11289 char_u *var = NULL; /* init for GCC */
11290 char_u *buf;
11291
11292 *num_file = 0;
11293 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11294 if (*file == NULL)
11295 return FAIL;
11296
11297 /*
11298 * For a terminal key code expand_option_idx is < 0.
11299 */
11300 if (expand_option_idx < 0)
11301 {
11302 var = find_termcode(expand_option_name + 2);
11303 if (var == NULL)
11304 expand_option_idx = findoption(expand_option_name);
11305 }
11306
11307 if (expand_option_idx >= 0)
11308 {
11309 /* put string of option value in NameBuff */
11310 option_value2string(&options[expand_option_idx], expand_option_flags);
11311 var = NameBuff;
11312 }
11313 else if (var == NULL)
11314 var = (char_u *)"";
11315
11316 /* A backslash is required before some characters. This is the reverse of
11317 * what happens in do_set(). */
11318 buf = vim_strsave_escaped(var, escape_chars);
11319
11320 if (buf == NULL)
11321 {
11322 vim_free(*file);
11323 *file = NULL;
11324 return FAIL;
11325 }
11326
11327#ifdef BACKSLASH_IN_FILENAME
11328 /* For MS-Windows et al. we don't double backslashes at the start and
11329 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011330 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331 if (var[0] == '\\' && var[1] == '\\'
11332 && expand_option_idx >= 0
11333 && (options[expand_option_idx].flags & P_EXPAND)
11334 && vim_isfilec(var[2])
11335 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011336 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011337#endif
11338
11339 *file[0] = buf;
11340 *num_file = 1;
11341 return OK;
11342}
11343#endif
11344
11345/*
11346 * Get the value for the numeric or string option *opp in a nice format into
11347 * NameBuff[]. Must not be called with a hidden option!
11348 */
11349 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011350option_value2string(
11351 struct vimoption *opp,
11352 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353{
11354 char_u *varp;
11355
11356 varp = get_varp_scope(opp, opt_flags);
11357
11358 if (opp->flags & P_NUM)
11359 {
11360 long wc = 0;
11361
11362 if (wc_use_keyname(varp, &wc))
11363 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11364 else if (wc != 0)
11365 STRCPY(NameBuff, transchar((int)wc));
11366 else
11367 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11368 }
11369 else /* P_STRING */
11370 {
11371 varp = *(char_u **)(varp);
11372 if (varp == NULL) /* just in case */
11373 NameBuff[0] = NUL;
11374#ifdef FEAT_CRYPT
11375 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011376 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011377 STRCPY(NameBuff, "*****");
11378#endif
11379 else if (opp->flags & P_EXPAND)
11380 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11381 /* Translate 'pastetoggle' into special key names */
11382 else if ((char_u **)opp->var == &p_pt)
11383 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11384 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011385 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011386 }
11387}
11388
11389/*
11390 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11391 * printed as a keyname.
11392 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11393 */
11394 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011395wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011396{
11397 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11398 {
11399 *wcp = *(long *)varp;
11400 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11401 return TRUE;
11402 }
11403 return FALSE;
11404}
11405
Bram Moolenaar01615492015-02-03 13:00:38 +010011406#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011407/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011408 * Any character has an equivalent 'langmap' character. This is used for
11409 * keyboards that have a special language mode that sends characters above
11410 * 128 (although other characters can be translated too). The "to" field is a
11411 * Vim command character. This avoids having to switch the keyboard back to
11412 * ASCII mode when leaving Insert mode.
11413 *
11414 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11415 * commands.
11416 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11417 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11418 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011420# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011421/*
11422 * With multi-byte support use growarray for 'langmap' chars >= 256
11423 */
11424typedef struct
11425{
11426 int from;
11427 int to;
11428} langmap_entry_T;
11429
11430static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011431static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011432
11433/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011434 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11435 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011436 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011437 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011438langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011439{
11440 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011441 int a = 0;
11442 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011443
11444 /* Do a binary search for an existing entry. */
11445 while (a != b)
11446 {
11447 int i = (a + b) / 2;
11448 int d = entries[i].from - from;
11449
11450 if (d == 0)
11451 {
11452 entries[i].to = to;
11453 return;
11454 }
11455 if (d < 0)
11456 a = i + 1;
11457 else
11458 b = i;
11459 }
11460
11461 if (ga_grow(&langmap_mapga, 1) != OK)
11462 return; /* out of memory */
11463
11464 /* insert new entry at position "a" */
11465 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11466 mch_memmove(entries + 1, entries,
11467 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11468 ++langmap_mapga.ga_len;
11469 entries[0].from = from;
11470 entries[0].to = to;
11471}
11472
11473/*
11474 * Apply 'langmap' to multi-byte character "c" and return the result.
11475 */
11476 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011477langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011478{
11479 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11480 int a = 0;
11481 int b = langmap_mapga.ga_len;
11482
11483 while (a != b)
11484 {
11485 int i = (a + b) / 2;
11486 int d = entries[i].from - c;
11487
11488 if (d == 0)
11489 return entries[i].to; /* found matching entry */
11490 if (d < 0)
11491 a = i + 1;
11492 else
11493 b = i;
11494 }
11495 return c; /* no entry found, return "c" unmodified */
11496}
11497# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011498
11499 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011500langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011501{
11502 int i;
11503
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011504 for (i = 0; i < 256; i++)
11505 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11506# ifdef FEAT_MBYTE
11507 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11508# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011509}
11510
11511/*
11512 * Called when langmap option is set; the language map can be
11513 * changed at any time!
11514 */
11515 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011516langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011517{
11518 char_u *p;
11519 char_u *p2;
11520 int from, to;
11521
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011522#ifdef FEAT_MBYTE
11523 ga_clear(&langmap_mapga); /* clear the previous map first */
11524#endif
11525 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526
11527 for (p = p_langmap; p[0] != NUL; )
11528 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011529 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11530 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531 {
11532 if (p2[0] == '\\' && p2[1] != NUL)
11533 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534 }
11535 if (p2[0] == ';')
11536 ++p2; /* abcd;ABCD form, p2 points to A */
11537 else
11538 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11539 while (p[0])
11540 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011541 if (p[0] == ',')
11542 {
11543 ++p;
11544 break;
11545 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546 if (p[0] == '\\' && p[1] != NUL)
11547 ++p;
11548#ifdef FEAT_MBYTE
11549 from = (*mb_ptr2char)(p);
11550#else
11551 from = p[0];
11552#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011553 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011554 if (p2 == NULL)
11555 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011556 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011557 if (p[0] != ',')
11558 {
11559 if (p[0] == '\\')
11560 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011562 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011563#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011564 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011565#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011567 }
11568 else
11569 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011570 if (p2[0] != ',')
11571 {
11572 if (p2[0] == '\\')
11573 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011574#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011575 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011576#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011577 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011578#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011579 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580 }
11581 if (to == NUL)
11582 {
11583 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11584 transchar(from));
11585 return;
11586 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011587
11588#ifdef FEAT_MBYTE
11589 if (from >= 256)
11590 langmap_set_entry(from, to);
11591 else
11592#endif
11593 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011594
11595 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011596 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011597 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011598 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011599 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011600 if (*p == ';')
11601 {
11602 p = p2;
11603 if (p[0] != NUL)
11604 {
11605 if (p[0] != ',')
11606 {
11607 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11608 return;
11609 }
11610 ++p;
11611 }
11612 break;
11613 }
11614 }
11615 }
11616 }
11617}
11618#endif
11619
11620/*
11621 * Return TRUE if format option 'x' is in effect.
11622 * Take care of no formatting when 'paste' is set.
11623 */
11624 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011625has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011626{
11627 if (p_paste)
11628 return FALSE;
11629 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11630}
11631
11632/*
11633 * Return TRUE if "x" is present in 'shortmess' option, or
11634 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11635 */
11636 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011637shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011638{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011639 return p_shm != NULL &&
11640 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011641 || (vim_strchr(p_shm, 'a') != NULL
11642 && vim_strchr((char_u *)SHM_A, x) != NULL));
11643}
11644
11645/*
11646 * paste_option_changed() - Called after p_paste was set or reset.
11647 */
11648 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011649paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011650{
11651 static int old_p_paste = FALSE;
11652 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011653 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011654#ifdef FEAT_CMDL_INFO
11655 static int save_ru = 0;
11656#endif
11657#ifdef FEAT_RIGHTLEFT
11658 static int save_ri = 0;
11659 static int save_hkmap = 0;
11660#endif
11661 buf_T *buf;
11662
11663 if (p_paste)
11664 {
11665 /*
11666 * Paste switched from off to on.
11667 * Save the current values, so they can be restored later.
11668 */
11669 if (!old_p_paste)
11670 {
11671 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011672 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673 {
11674 buf->b_p_tw_nopaste = buf->b_p_tw;
11675 buf->b_p_wm_nopaste = buf->b_p_wm;
11676 buf->b_p_sts_nopaste = buf->b_p_sts;
11677 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011678 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011679 }
11680
11681 /* save global options */
11682 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011683 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011684#ifdef FEAT_CMDL_INFO
11685 save_ru = p_ru;
11686#endif
11687#ifdef FEAT_RIGHTLEFT
11688 save_ri = p_ri;
11689 save_hkmap = p_hkmap;
11690#endif
11691 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011692 p_ai_nopaste = p_ai;
11693 p_et_nopaste = p_et;
11694 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011695 p_tw_nopaste = p_tw;
11696 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011697 }
11698
11699 /*
11700 * Always set the option values, also when 'paste' is set when it is
11701 * already on.
11702 */
11703 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011704 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011705 {
11706 buf->b_p_tw = 0; /* textwidth is 0 */
11707 buf->b_p_wm = 0; /* wrapmargin is 0 */
11708 buf->b_p_sts = 0; /* softtabstop is 0 */
11709 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011710 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011711 }
11712
11713 /* set global options */
11714 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011715 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011716#ifdef FEAT_CMDL_INFO
11717# ifdef FEAT_WINDOWS
11718 if (p_ru)
11719 status_redraw_all(); /* redraw to remove the ruler */
11720# endif
11721 p_ru = 0; /* no ruler */
11722#endif
11723#ifdef FEAT_RIGHTLEFT
11724 p_ri = 0; /* no reverse insert */
11725 p_hkmap = 0; /* no Hebrew keyboard */
11726#endif
11727 /* set global values for local buffer options */
11728 p_tw = 0;
11729 p_wm = 0;
11730 p_sts = 0;
11731 p_ai = 0;
11732 }
11733
11734 /*
11735 * Paste switched from on to off: Restore saved values.
11736 */
11737 else if (old_p_paste)
11738 {
11739 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011740 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741 {
11742 buf->b_p_tw = buf->b_p_tw_nopaste;
11743 buf->b_p_wm = buf->b_p_wm_nopaste;
11744 buf->b_p_sts = buf->b_p_sts_nopaste;
11745 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011746 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011747 }
11748
11749 /* restore global options */
11750 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011751 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752#ifdef FEAT_CMDL_INFO
11753# ifdef FEAT_WINDOWS
11754 if (p_ru != save_ru)
11755 status_redraw_all(); /* redraw to draw the ruler */
11756# endif
11757 p_ru = save_ru;
11758#endif
11759#ifdef FEAT_RIGHTLEFT
11760 p_ri = save_ri;
11761 p_hkmap = save_hkmap;
11762#endif
11763 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011764 p_ai = p_ai_nopaste;
11765 p_et = p_et_nopaste;
11766 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767 p_tw = p_tw_nopaste;
11768 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011769 }
11770
11771 old_p_paste = p_paste;
11772}
11773
11774/*
11775 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11776 *
11777 * Reset 'compatible' and set the values for options that didn't get set yet
11778 * to the Vim defaults.
11779 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011780 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781 */
11782 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011783vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011785 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011786 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011787 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011788
11789 if (!option_was_set((char_u *)"cp"))
11790 {
11791 p_cp = FALSE;
11792 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11793 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11794 set_option_default(opt_idx, OPT_FREE, FALSE);
11795 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011796 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011797 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011798
11799 if (fname != NULL)
11800 {
11801 p = vim_getenv(envname, &dofree);
11802 if (p == NULL)
11803 {
11804 /* Set $MYVIMRC to the first vimrc file found. */
11805 p = FullName_save(fname, FALSE);
11806 if (p != NULL)
11807 {
11808 vim_setenv(envname, p);
11809 vim_free(p);
11810 }
11811 }
11812 else if (dofree)
11813 vim_free(p);
11814 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011815}
11816
11817/*
11818 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11819 */
11820 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011821change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011822{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011823 int opt_idx;
11824
Bram Moolenaar071d4272004-06-13 20:20:40 +000011825 if (p_cp != on)
11826 {
11827 p_cp = on;
11828 compatible_set();
11829 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011830 opt_idx = findoption((char_u *)"cp");
11831 if (opt_idx >= 0)
11832 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011833}
11834
11835/*
11836 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011837 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011838 */
11839 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011840option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011841{
11842 int idx;
11843
11844 idx = findoption(name);
11845 if (idx < 0) /* unknown option */
11846 return FALSE;
11847 if (options[idx].flags & P_WAS_SET)
11848 return TRUE;
11849 return FALSE;
11850}
11851
11852/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011853 * Reset the flag indicating option "name" was set.
11854 */
11855 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011856reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011857{
11858 int idx = findoption(name);
11859
11860 if (idx >= 0)
11861 options[idx].flags &= ~P_WAS_SET;
11862}
11863
11864/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011865 * compatible_set() - Called when 'compatible' has been set or unset.
11866 *
11867 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11868 * flag) to a Vi compatible value.
11869 * When 'compatible' is unset: Set all options that have a different default
11870 * for Vim (without the P_VI_DEF flag) to that default.
11871 */
11872 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011873compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011874{
11875 int opt_idx;
11876
11877 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11878 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11879 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11880 set_option_default(opt_idx, OPT_FREE, p_cp);
11881 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011882 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883}
11884
11885#ifdef FEAT_LINEBREAK
11886
11887# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11888 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011889 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011890# endif
11891
11892/*
11893 * fill_breakat_flags() -- called when 'breakat' changes value.
11894 */
11895 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011896fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011897{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011898 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011899 int i;
11900
11901 for (i = 0; i < 256; i++)
11902 breakat_flags[i] = FALSE;
11903
11904 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011905 for (p = p_breakat; *p; p++)
11906 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011907}
11908
11909# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011910 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011911# endif
11912
11913#endif
11914
11915/*
11916 * Check an option that can be a range of string values.
11917 *
11918 * Return OK for correct value, FAIL otherwise.
11919 * Empty is always OK.
11920 */
11921 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011922check_opt_strings(
11923 char_u *val,
11924 char **values,
11925 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011926{
11927 return opt_strings_flags(val, values, NULL, list);
11928}
11929
11930/*
11931 * Handle an option that can be a range of string values.
11932 * Set a flag in "*flagp" for each string present.
11933 *
11934 * Return OK for correct value, FAIL otherwise.
11935 * Empty is always OK.
11936 */
11937 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011938opt_strings_flags(
11939 char_u *val, /* new value */
11940 char **values, /* array of valid string values */
11941 unsigned *flagp,
11942 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011943{
11944 int i;
11945 int len;
11946 unsigned new_flags = 0;
11947
11948 while (*val)
11949 {
11950 for (i = 0; ; ++i)
11951 {
11952 if (values[i] == NULL) /* val not found in values[] */
11953 return FAIL;
11954
11955 len = (int)STRLEN(values[i]);
11956 if (STRNCMP(values[i], val, len) == 0
11957 && ((list && val[len] == ',') || val[len] == NUL))
11958 {
11959 val += len + (val[len] == ',');
11960 new_flags |= (1 << i);
11961 break; /* check next item in val list */
11962 }
11963 }
11964 }
11965 if (flagp != NULL)
11966 *flagp = new_flags;
11967
11968 return OK;
11969}
11970
11971/*
11972 * Read the 'wildmode' option, fill wim_flags[].
11973 */
11974 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011975check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011976{
11977 char_u new_wim_flags[4];
11978 char_u *p;
11979 int i;
11980 int idx = 0;
11981
11982 for (i = 0; i < 4; ++i)
11983 new_wim_flags[i] = 0;
11984
11985 for (p = p_wim; *p; ++p)
11986 {
11987 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11988 ;
11989 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11990 return FAIL;
11991 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11992 new_wim_flags[idx] |= WIM_LONGEST;
11993 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11994 new_wim_flags[idx] |= WIM_FULL;
11995 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11996 new_wim_flags[idx] |= WIM_LIST;
11997 else
11998 return FAIL;
11999 p += i;
12000 if (*p == NUL)
12001 break;
12002 if (*p == ',')
12003 {
12004 if (idx == 3)
12005 return FAIL;
12006 ++idx;
12007 }
12008 }
12009
12010 /* fill remaining entries with last flag */
12011 while (idx < 3)
12012 {
12013 new_wim_flags[idx + 1] = new_wim_flags[idx];
12014 ++idx;
12015 }
12016
12017 /* only when there are no errors, wim_flags[] is changed */
12018 for (i = 0; i < 4; ++i)
12019 wim_flags[i] = new_wim_flags[i];
12020 return OK;
12021}
12022
12023/*
12024 * Check if backspacing over something is allowed.
12025 */
12026 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012027can_bs(
12028 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029{
12030 switch (*p_bs)
12031 {
12032 case '2': return TRUE;
12033 case '1': return (what != BS_START);
12034 case '0': return FALSE;
12035 }
12036 return vim_strchr(p_bs, what) != NULL;
12037}
12038
12039/*
12040 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12041 * the file must be considered changed when the value is different.
12042 */
12043 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012044save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045{
12046 buf->b_start_ffc = *buf->b_p_ff;
12047 buf->b_start_eol = buf->b_p_eol;
12048#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012049 buf->b_start_bomb = buf->b_p_bomb;
12050
Bram Moolenaar071d4272004-06-13 20:20:40 +000012051 /* Only use free/alloc when necessary, they take time. */
12052 if (buf->b_start_fenc == NULL
12053 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12054 {
12055 vim_free(buf->b_start_fenc);
12056 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12057 }
12058#endif
12059}
12060
12061/*
12062 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12063 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012064 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12065 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012066 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012067 * When "ignore_empty" is true don't consider a new, empty buffer to be
12068 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012069 */
12070 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012071file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012072{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012073 /* In a buffer that was never loaded the options are not valid. */
12074 if (buf->b_flags & BF_NEVERLOADED)
12075 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012076 if (ignore_empty
12077 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078 && buf->b_ml.ml_line_count == 1
12079 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12080 return FALSE;
12081 if (buf->b_start_ffc != *buf->b_p_ff)
12082 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012083 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012084 return TRUE;
12085#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012086 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12087 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012088 if (buf->b_start_fenc == NULL)
12089 return (*buf->b_p_fenc != NUL);
12090 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12091#else
12092 return FALSE;
12093#endif
12094}
12095
12096/*
12097 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12098 */
12099 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012100check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012101{
12102 return check_opt_strings(p, p_ff_values, FALSE);
12103}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012104
12105/*
12106 * Return the effective shiftwidth value for current buffer, using the
12107 * 'tabstop' value when 'shiftwidth' is zero.
12108 */
12109 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012110get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012111{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012112 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012113}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012114
12115/*
12116 * Return the effective softtabstop value for the current buffer, using the
12117 * 'tabstop' value when 'softtabstop' is negative.
12118 */
12119 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012120get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012121{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012122 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012123}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012124
12125/*
12126 * Check matchpairs option for "*initc".
12127 * If there is a match set "*initc" to the matching character and "*findc" to
12128 * the opposite character. Set "*backwards" to the direction.
12129 * When "switchit" is TRUE swap the direction.
12130 */
12131 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012132find_mps_values(
12133 int *initc,
12134 int *findc,
12135 int *backwards,
12136 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012137{
12138 char_u *ptr;
12139
12140 ptr = curbuf->b_p_mps;
12141 while (*ptr != NUL)
12142 {
12143#ifdef FEAT_MBYTE
12144 if (has_mbyte)
12145 {
12146 char_u *prev;
12147
12148 if (mb_ptr2char(ptr) == *initc)
12149 {
12150 if (switchit)
12151 {
12152 *findc = *initc;
12153 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12154 *backwards = TRUE;
12155 }
12156 else
12157 {
12158 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12159 *backwards = FALSE;
12160 }
12161 return;
12162 }
12163 prev = ptr;
12164 ptr += mb_ptr2len(ptr) + 1;
12165 if (mb_ptr2char(ptr) == *initc)
12166 {
12167 if (switchit)
12168 {
12169 *findc = *initc;
12170 *initc = mb_ptr2char(prev);
12171 *backwards = FALSE;
12172 }
12173 else
12174 {
12175 *findc = mb_ptr2char(prev);
12176 *backwards = TRUE;
12177 }
12178 return;
12179 }
12180 ptr += mb_ptr2len(ptr);
12181 }
12182 else
12183#endif
12184 {
12185 if (*ptr == *initc)
12186 {
12187 if (switchit)
12188 {
12189 *backwards = TRUE;
12190 *findc = *initc;
12191 *initc = ptr[2];
12192 }
12193 else
12194 {
12195 *backwards = FALSE;
12196 *findc = ptr[2];
12197 }
12198 return;
12199 }
12200 ptr += 2;
12201 if (*ptr == *initc)
12202 {
12203 if (switchit)
12204 {
12205 *backwards = FALSE;
12206 *findc = *initc;
12207 *initc = ptr[-2];
12208 }
12209 else
12210 {
12211 *backwards = TRUE;
12212 *findc = ptr[-2];
12213 }
12214 return;
12215 }
12216 ++ptr;
12217 }
12218 if (*ptr == ',')
12219 ++ptr;
12220 }
12221}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012222
12223#if defined(FEAT_LINEBREAK) || defined(PROTO)
12224/*
12225 * This is called when 'breakindentopt' is changed and when a window is
12226 * initialized.
12227 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012228 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012229briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012230{
12231 char_u *p;
12232 int bri_shift = 0;
12233 long bri_min = 20;
12234 int bri_sbr = FALSE;
12235
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012236 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012237 while (*p != NUL)
12238 {
12239 if (STRNCMP(p, "shift:", 6) == 0
12240 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12241 {
12242 p += 6;
12243 bri_shift = getdigits(&p);
12244 }
12245 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12246 {
12247 p += 4;
12248 bri_min = getdigits(&p);
12249 }
12250 else if (STRNCMP(p, "sbr", 3) == 0)
12251 {
12252 p += 3;
12253 bri_sbr = TRUE;
12254 }
12255 if (*p != ',' && *p != NUL)
12256 return FAIL;
12257 if (*p == ',')
12258 ++p;
12259 }
12260
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012261 wp->w_p_brishift = bri_shift;
12262 wp->w_p_brimin = bri_min;
12263 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012264
12265 return OK;
12266}
12267#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012268
12269/*
12270 * Get the local or global value of 'backupcopy'.
12271 */
12272 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012273get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012274{
12275 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12276}