blob: a5b403cf9f2ba2c229f90e6f1eaebaebad4ea9f2 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000110#ifdef FEAT_EVAL
111# define PV_FEX OPT_BUF(BV_FEX)
112#endif
113#define PV_FF OPT_BUF(BV_FF)
114#define PV_FLP OPT_BUF(BV_FLP)
115#define PV_FO OPT_BUF(BV_FO)
116#ifdef FEAT_AUTOCMD
117# define PV_FT OPT_BUF(BV_FT)
118#endif
119#define PV_IMI OPT_BUF(BV_IMI)
120#define PV_IMS OPT_BUF(BV_IMS)
121#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
122# define PV_INDE OPT_BUF(BV_INDE)
123# define PV_INDK OPT_BUF(BV_INDK)
124#endif
125#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
126# define PV_INEX OPT_BUF(BV_INEX)
127#endif
128#define PV_INF OPT_BUF(BV_INF)
129#define PV_ISK OPT_BUF(BV_ISK)
130#ifdef FEAT_CRYPT
131# define PV_KEY OPT_BUF(BV_KEY)
132#endif
133#ifdef FEAT_KEYMAP
134# define PV_KMAP OPT_BUF(BV_KMAP)
135#endif
136#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
137#ifdef FEAT_LISP
138# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100139# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000140#endif
141#define PV_MA OPT_BUF(BV_MA)
142#define PV_ML OPT_BUF(BV_ML)
143#define PV_MOD OPT_BUF(BV_MOD)
144#define PV_MPS OPT_BUF(BV_MPS)
145#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100158#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000159#ifdef FEAT_SYN_HL
160# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000161# define PV_SYN OPT_BUF(BV_SYN)
162#endif
163#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164# define PV_SPC OPT_BUF(BV_SPC)
165# define PV_SPF OPT_BUF(BV_SPF)
166# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000167#endif
168#define PV_STS OPT_BUF(BV_STS)
169#ifdef FEAT_SEARCHPATH
170# define PV_SUA OPT_BUF(BV_SUA)
171#endif
172#define PV_SW OPT_BUF(BV_SW)
173#define PV_SWF OPT_BUF(BV_SWF)
174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100175#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200179#ifdef FEAT_PERSISTENT_UNDO
180# define PV_UDF OPT_BUF(BV_UDF)
181#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
221#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
228#ifdef FEAT_SCROLLBIND
229# define PV_SCBIND OPT_WIN(WV_SCBIND)
230#endif
231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_WINDOWS
245# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000246# define PV_WFW OPT_WIN(WV_WFW)
247#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200249#ifdef FEAT_CURSORBIND
250# define PV_CRBIND OPT_WIN(WV_CRBIND)
251#endif
252#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200253# define PV_COCU OPT_WIN(WV_COCU)
254# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200255#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000256
257/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000258typedef enum
259{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000260 PV_NONE = 0,
261 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262} idopt_T;
263
264/*
265 * Options local to a window have a value local to a buffer and global to all
266 * buffers. Indicate this by setting "var" to VAR_WIN.
267 */
268#define VAR_WIN ((char_u *)-1)
269
270/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000271 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000272 * Only to be used in option.c!
273 */
274static int p_ai;
275static int p_bin;
276#ifdef FEAT_MBYTE
277static int p_bomb;
278#endif
279#if defined(FEAT_QUICKFIX)
280static char_u *p_bh;
281static char_u *p_bt;
282#endif
283static int p_bl;
284static int p_ci;
285#ifdef FEAT_CINDENT
286static int p_cin;
287static char_u *p_cink;
288static char_u *p_cino;
289#endif
290#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
291static char_u *p_cinw;
292#endif
293#ifdef FEAT_COMMENTS
294static char_u *p_com;
295#endif
296#ifdef FEAT_FOLDING
297static char_u *p_cms;
298#endif
299#ifdef FEAT_INS_EXPAND
300static char_u *p_cpt;
301#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000302#ifdef FEAT_COMPL_FUNC
303static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000304static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200307static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_et;
309#ifdef FEAT_MBYTE
310static char_u *p_fenc;
311#endif
312static char_u *p_ff;
313static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000314static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315#ifdef FEAT_AUTOCMD
316static char_u *p_ft;
317#endif
318static long p_iminsert;
319static long p_imsearch;
320#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
321static char_u *p_inex;
322#endif
323#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
324static char_u *p_inde;
325static char_u *p_indk;
326#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000327#if defined(FEAT_EVAL)
328static char_u *p_fex;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330static int p_inf;
331static char_u *p_isk;
332#ifdef FEAT_CRYPT
333static char_u *p_key;
334#endif
335#ifdef FEAT_LISP
336static int p_lisp;
337#endif
338static int p_ml;
339static int p_ma;
340static int p_mod;
341static char_u *p_mps;
342static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static long p_sts;
353#if defined(FEAT_SEARCHPATH)
354static char_u *p_sua;
355#endif
356static long p_sw;
357static int p_swf;
358#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000359static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000361#endif
362#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000363static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000364static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000365static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366#endif
367static long p_ts;
368static long p_tw;
369static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200370#ifdef FEAT_PERSISTENT_UNDO
371static int p_udf;
372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373static long p_wm;
374#ifdef FEAT_KEYMAP
375static char_u *p_keymap;
376#endif
377
378/* Saved values for when 'bin' is set. */
379static int p_et_nobin;
380static int p_ml_nobin;
381static long p_tw_nobin;
382static long p_wm_nobin;
383
384/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200385static int p_ai_nopaste;
386static int p_et_nopaste;
387static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388static long p_tw_nopaste;
389static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390
391struct vimoption
392{
393 char *fullname; /* full option name */
394 char *shortname; /* permissible abbreviation */
395 long_u flags; /* see below */
396 char_u *var; /* global option: pointer to variable;
397 * window-local option: VAR_WIN;
398 * buffer-local option: global value */
399 idopt_T indir; /* global option: PV_NONE;
400 * local option: indirect option index */
401 char_u *def_val[2]; /* default values for variable (vi and vim) */
402#ifdef FEAT_EVAL
403 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000404# define SCRIPTID_INIT , 0
405#else
406# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000407#endif
408};
409
410#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
411#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
412
413/*
414 * Flags
415 */
416#define P_BOOL 0x01 /* the option is boolean */
417#define P_NUM 0x02 /* the option is numeric */
418#define P_STRING 0x04 /* the option is a string */
419#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000420 must use free_string_option() when
421 assigning new value. Not set if default is
422 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000423#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
424 never be used for local or hidden options! */
425#define P_NODEFAULT 0x40 /* don't set to default value */
426#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
427 use vim_free() when assigning new value */
428#define P_WAS_SET 0x100 /* option has been set/reset */
429#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
430#define P_VI_DEF 0x400 /* Use Vi default for Vim */
431#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
432
433 /* when option changed, what to display: */
434#define P_RSTAT 0x1000 /* redraw status lines */
435#define P_RWIN 0x2000 /* redraw current window */
436#define P_RBUF 0x4000 /* redraw current buffer */
437#define P_RALL 0x6000 /* redraw all windows */
438#define P_RCLR 0x7000 /* clear and redraw all */
439
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200440#define P_COMMA 0x8000 /* comma separated list */
441#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
442 * commas */
443#define P_NODUP 0x20000L /* don't allow duplicate strings */
444#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200446#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
447#define P_GETTEXT 0x100000L /* expand default value with _() */
448#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
449#define P_NFNAME 0x400000L /* only normal file name chars allowed */
450#define P_INSECURE 0x800000L /* option was set from a modeline */
451#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000452 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_NO_ML 0x2000000L /* not allowed in modeline */
454#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200455 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000457#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
458
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000459/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
460 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100461#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000462# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000463#else
464# define ISP_LATIN1 (char_u *)"@,161-255"
465#endif
466
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100467/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000468#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100469 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200470 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100471# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000472#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100473# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000474#endif
475
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476/*
477 * options[] is initialized here.
478 * The order of the options MUST be alphabetic for ":set all" and findoption().
479 * All option names MUST start with a lowercase letter (for findoption()).
480 * Exception: "t_" options are at the end.
481 * The options with a NULL variable are 'hidden': a set command for them is
482 * ignored and they are not printed.
483 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100484static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000485{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200486 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000487#ifdef FEAT_RIGHTLEFT
488 (char_u *)&p_aleph, PV_NONE,
489#else
490 (char_u *)NULL, PV_NONE,
491#endif
492 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100493#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494 (char_u *)128L,
495#else
496 (char_u *)224L,
497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
500#if defined(FEAT_GUI) && defined(MACOS_X)
501 (char_u *)&p_antialias, PV_NONE,
502 {(char_u *)FALSE, (char_u *)FALSE}
503#else
504 (char_u *)NULL, PV_NONE,
505 {(char_u *)FALSE, (char_u *)FALSE}
506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000507 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200508 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509#ifdef FEAT_ARABIC
510 (char_u *)VAR_WIN, PV_ARAB,
511#else
512 (char_u *)NULL, PV_NONE,
513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
516#ifdef FEAT_ARABIC
517 (char_u *)&p_arshape, PV_NONE,
518#else
519 (char_u *)NULL, PV_NONE,
520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000521 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
523#ifdef FEAT_RIGHTLEFT
524 (char_u *)&p_ari, PV_NONE,
525#else
526 (char_u *)NULL, PV_NONE,
527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000528 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
530#ifdef FEAT_FKMAP
531 (char_u *)&p_altkeymap, PV_NONE,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
537#if defined(FEAT_MBYTE)
538 (char_u *)&p_ambw, PV_NONE,
539 {(char_u *)"single", (char_u *)0L}
540#else
541 (char_u *)NULL, PV_NONE,
542 {(char_u *)0L, (char_u *)0L}
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000545#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"autochdir", "acd", P_BOOL|P_VI_DEF,
547 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549#endif
550 {"autoindent", "ai", P_BOOL|P_VI_DEF,
551 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autoprint", "ap", P_BOOL|P_VI_DEF,
554 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000557 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autowrite", "aw", P_BOOL|P_VI_DEF,
560 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autowriteall","awa", P_BOOL|P_VI_DEF,
563 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
566 (char_u *)&p_bg, PV_NONE,
567 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100568#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 (char_u *)"dark",
570#else
571 (char_u *)"light",
572#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200574 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
578 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200580 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200581 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582#ifdef UNIX
583 {(char_u *)"yes", (char_u *)"auto"}
584#else
585 {(char_u *)"auto", (char_u *)"auto"}
586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200588 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
589 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000591 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000592 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)&p_bex, PV_NONE,
594 {
595#ifdef VMS
596 (char_u *)"_",
597#else
598 (char_u *)"~",
599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200601 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602#ifdef FEAT_WILDIGN
603 (char_u *)&p_bsk, PV_NONE,
604 {(char_u *)"", (char_u *)0L}
605#else
606 (char_u *)NULL, PV_NONE,
607 {(char_u *)0L, (char_u *)0L}
608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000609 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610#ifdef FEAT_BEVAL
611 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
612 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
615 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000617# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000618 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000619 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000621# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622#endif
623 {"beautify", "bf", P_BOOL|P_VI_DEF,
624 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200626 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
627 (char_u *)&p_bo, PV_NONE,
628 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
630 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
636#ifdef FEAT_MBYTE
637 (char_u *)&p_bomb, PV_BOMB,
638#else
639 (char_u *)NULL, PV_NONE,
640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000641 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
643#ifdef FEAT_LINEBREAK
644 (char_u *)&p_breakat, PV_NONE,
645 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
646#else
647 (char_u *)NULL, PV_NONE,
648 {(char_u *)0L, (char_u *)0L}
649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000650 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200651 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
652#ifdef FEAT_LINEBREAK
653 (char_u *)VAR_WIN, PV_BRI,
654 {(char_u *)FALSE, (char_u *)0L}
655#else
656 (char_u *)NULL, PV_NONE,
657 {(char_u *)0L, (char_u *)0L}
658#endif
659 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200660 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
661 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200662#ifdef FEAT_LINEBREAK
663 (char_u *)VAR_WIN, PV_BRIOPT,
664 {(char_u *)"", (char_u *)NULL}
665#else
666 (char_u *)NULL, PV_NONE,
667 {(char_u *)"", (char_u *)NULL}
668#endif
669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
671#ifdef FEAT_BROWSE
672 (char_u *)&p_bsdir, PV_NONE,
673 {(char_u *)"last", (char_u *)0L}
674#else
675 (char_u *)NULL, PV_NONE,
676 {(char_u *)0L, (char_u *)0L}
677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000679 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
680#if defined(FEAT_QUICKFIX)
681 (char_u *)&p_bh, PV_BH,
682 {(char_u *)"", (char_u *)0L}
683#else
684 (char_u *)NULL, PV_NONE,
685 {(char_u *)0L, (char_u *)0L}
686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000687 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000688 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
689 (char_u *)&p_bl, PV_BL,
690 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000691 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
693#if defined(FEAT_QUICKFIX)
694 (char_u *)&p_bt, PV_BT,
695 {(char_u *)"", (char_u *)0L}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)0L, (char_u *)0L}
699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000700 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200701 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000702#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 (char_u *)&p_cmp, PV_NONE,
704 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
711#ifdef FEAT_SEARCHPATH
712 (char_u *)&p_cdpath, PV_NONE,
713 {(char_u *)",,", (char_u *)0L}
714#else
715 (char_u *)NULL, PV_NONE,
716 {(char_u *)0L, (char_u *)0L}
717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"cedit", NULL, P_STRING,
720#ifdef FEAT_CMDWIN
721 (char_u *)&p_cedit, PV_NONE,
722 {(char_u *)"", (char_u *)CTRL_F_STR}
723#else
724 (char_u *)NULL, PV_NONE,
725 {(char_u *)0L, (char_u *)0L}
726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000727 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
729#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
730 (char_u *)&p_ccv, PV_NONE,
731 {(char_u *)"", (char_u *)0L}
732#else
733 (char_u *)NULL, PV_NONE,
734 {(char_u *)0L, (char_u *)0L}
735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000736 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000737 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
738#ifdef FEAT_CINDENT
739 (char_u *)&p_cin, PV_CIN,
740#else
741 (char_u *)NULL, PV_NONE,
742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000743 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200744 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745#ifdef FEAT_CINDENT
746 (char_u *)&p_cink, PV_CINK,
747 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
748#else
749 (char_u *)NULL, PV_NONE,
750 {(char_u *)0L, (char_u *)0L}
751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000752 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200753 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754#ifdef FEAT_CINDENT
755 (char_u *)&p_cino, PV_CINO,
756#else
757 (char_u *)NULL, PV_NONE,
758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000759 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200760 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
762 (char_u *)&p_cinw, PV_CINW,
763 {(char_u *)"if,else,while,do,for,switch",
764 (char_u *)0L}
765#else
766 (char_u *)NULL, PV_NONE,
767 {(char_u *)0L, (char_u *)0L}
768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000769 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200770 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#ifdef FEAT_CLIPBOARD
772 (char_u *)&p_cb, PV_NONE,
773# ifdef FEAT_XCLIPBOARD
774 {(char_u *)"autoselect,exclude:cons\\|linux",
775 (char_u *)0L}
776# else
777 {(char_u *)"", (char_u *)0L}
778# endif
779#else
780 (char_u *)NULL, PV_NONE,
781 {(char_u *)"", (char_u *)0L}
782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000783 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
785 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
788#ifdef FEAT_CMDWIN
789 (char_u *)&p_cwh, PV_NONE,
790#else
791 (char_u *)NULL, PV_NONE,
792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000793 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200794 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200795#ifdef FEAT_SYN_HL
796 (char_u *)VAR_WIN, PV_CC,
797#else
798 (char_u *)NULL, PV_NONE,
799#endif
800 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
802 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000803 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200804 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
805 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806#ifdef FEAT_COMMENTS
807 (char_u *)&p_com, PV_COM,
808 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
809 (char_u *)0L}
810#else
811 (char_u *)NULL, PV_NONE,
812 {(char_u *)0L, (char_u *)0L}
813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200815 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816#ifdef FEAT_FOLDING
817 (char_u *)&p_cms, PV_CMS,
818 {(char_u *)"/*%s*/", (char_u *)0L}
819#else
820 (char_u *)NULL, PV_NONE,
821 {(char_u *)0L, (char_u *)0L}
822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000823 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000824 /* P_PRI_MKRC isn't needed here, optval_default()
825 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000826 {"compatible", "cp", P_BOOL|P_RALL,
827 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000828 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200829 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830#ifdef FEAT_INS_EXPAND
831 (char_u *)&p_cpt, PV_CPT,
832 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
833#else
834 (char_u *)NULL, PV_NONE,
835 {(char_u *)0L, (char_u *)0L}
836#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000837 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200838 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200839#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200840 (char_u *)VAR_WIN, PV_COCU,
841 {(char_u *)"", (char_u *)NULL}
842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)NULL, (char_u *)0L}
845#endif
846 SCRIPTID_INIT},
847 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
848#ifdef FEAT_CONCEAL
849 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200850#else
851 (char_u *)NULL, PV_NONE,
852#endif
853 {(char_u *)0L, (char_u *)0L}
854 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000855 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
856#ifdef FEAT_COMPL_FUNC
857 (char_u *)&p_cfu, PV_CFU,
858 {(char_u *)"", (char_u *)0L}
859#else
860 (char_u *)NULL, PV_NONE,
861 {(char_u *)0L, (char_u *)0L}
862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000863 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200864 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000865#ifdef FEAT_INS_EXPAND
866 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000867 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000868#else
869 (char_u *)NULL, PV_NONE,
870 {(char_u *)0L, (char_u *)0L}
871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000872 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000873 {"confirm", "cf", P_BOOL|P_VI_DEF,
874#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
875 (char_u *)&p_confirm, PV_NONE,
876#else
877 (char_u *)NULL, PV_NONE,
878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000880 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000881 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
884 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
887 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000888 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
889 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200890 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200891#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200892 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200893 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200894#else
895 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200896 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200897#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200898 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
900#ifdef FEAT_CSCOPE
901 (char_u *)&p_cspc, PV_NONE,
902#else
903 (char_u *)NULL, PV_NONE,
904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
907#ifdef FEAT_CSCOPE
908 (char_u *)&p_csprg, PV_NONE,
909 {(char_u *)"cscope", (char_u *)0L}
910#else
911 (char_u *)NULL, PV_NONE,
912 {(char_u *)0L, (char_u *)0L}
913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200915 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
917 (char_u *)&p_csqf, PV_NONE,
918 {(char_u *)"", (char_u *)0L}
919#else
920 (char_u *)NULL, PV_NONE,
921 {(char_u *)0L, (char_u *)0L}
922#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000923 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200924 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
925#ifdef FEAT_CSCOPE
926 (char_u *)&p_csre, PV_NONE,
927#else
928 (char_u *)NULL, PV_NONE,
929#endif
930 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_cst, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csto, PV_NONE,
941#else
942 (char_u *)NULL, PV_NONE,
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csverbose, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200952 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
953#ifdef FEAT_CURSORBIND
954 (char_u *)VAR_WIN, PV_CRBIND,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
958 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000959 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
960#ifdef FEAT_SYN_HL
961 (char_u *)VAR_WIN, PV_CUC,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000966 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
967#ifdef FEAT_SYN_HL
968 (char_u *)VAR_WIN, PV_CUL,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000973 {"debug", NULL, P_STRING|P_VI_DEF,
974 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200976 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000978 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000979 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980#else
981 (char_u *)NULL, PV_NONE,
982 {(char_u *)NULL, (char_u *)0L}
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
986#ifdef FEAT_MBYTE
987 (char_u *)&p_deco, PV_NONE,
988#else
989 (char_u *)NULL, PV_NONE,
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200992 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000994 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#else
996 (char_u *)NULL, PV_NONE,
997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1000#ifdef FEAT_DIFF
1001 (char_u *)VAR_WIN, PV_DIFF,
1002#else
1003 (char_u *)NULL, PV_NONE,
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001006 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1008 (char_u *)&p_dex, PV_NONE,
1009 {(char_u *)"", (char_u *)0L}
1010#else
1011 (char_u *)NULL, PV_NONE,
1012 {(char_u *)0L, (char_u *)0L}
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001015 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1016 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017#ifdef FEAT_DIFF
1018 (char_u *)&p_dip, PV_NONE,
1019 {(char_u *)"filler", (char_u *)NULL}
1020#else
1021 (char_u *)NULL, PV_NONE,
1022 {(char_u *)"", (char_u *)NULL}
1023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1026#ifdef FEAT_DIGRAPHS
1027 (char_u *)&p_dg, PV_NONE,
1028#else
1029 (char_u *)NULL, PV_NONE,
1030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001031 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001032 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1033 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001036 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001040#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041 (char_u *)&p_ead, PV_NONE,
1042 {(char_u *)"both", (char_u *)0L}
1043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)NULL, (char_u *)0L}
1046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1049 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001051 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1052#if defined(FEAT_MBYTE)
1053 (char_u *)&p_emoji, PV_NONE,
1054 {(char_u *)TRUE, (char_u *)0L}
1055#else
1056 (char_u *)NULL, PV_NONE,
1057 {(char_u *)0L, (char_u *)0L}
1058#endif
1059 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001060 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061#ifdef FEAT_MBYTE
1062 (char_u *)&p_enc, PV_NONE,
1063 {(char_u *)ENC_DFLT, (char_u *)0L}
1064#else
1065 (char_u *)NULL, PV_NONE,
1066 {(char_u *)0L, (char_u *)0L}
1067#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1070 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1073 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001076 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1079 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1082#ifdef FEAT_QUICKFIX
1083 (char_u *)&p_ef, PV_NONE,
1084 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1085#else
1086 (char_u *)NULL, PV_NONE,
1087 {(char_u *)NULL, (char_u *)0L}
1088#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001090 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001092 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094#else
1095 (char_u *)NULL, PV_NONE,
1096 {(char_u *)NULL, (char_u *)0L}
1097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001098 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"esckeys", "ek", P_BOOL|P_VIM,
1100 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001102 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103#ifdef FEAT_AUTOCMD
1104 (char_u *)&p_ei, PV_NONE,
1105#else
1106 (char_u *)NULL, PV_NONE,
1107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1110 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1113 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1116 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117#ifdef FEAT_MBYTE
1118 (char_u *)&p_fenc, PV_FENC,
1119 {(char_u *)"", (char_u *)0L}
1120#else
1121 (char_u *)NULL, PV_NONE,
1122 {(char_u *)0L, (char_u *)0L}
1123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001125 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#ifdef FEAT_MBYTE
1127 (char_u *)&p_fencs, PV_NONE,
1128 {(char_u *)"ucs-bom", (char_u *)0L}
1129#else
1130 (char_u *)NULL, PV_NONE,
1131 {(char_u *)0L, (char_u *)0L}
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1135 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001137 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001138 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1141 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001142 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1143 (char_u *)&p_fic, PV_NONE,
1144 {
1145#ifdef CASE_INSENSITIVE_FILENAME
1146 (char_u *)TRUE,
1147#else
1148 (char_u *)FALSE,
1149#endif
1150 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001151 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152#ifdef FEAT_AUTOCMD
1153 (char_u *)&p_ft, PV_FT,
1154 {(char_u *)"", (char_u *)0L}
1155#else
1156 (char_u *)NULL, PV_NONE,
1157 {(char_u *)0L, (char_u *)0L}
1158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001159 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001160 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1162 (char_u *)&p_fcs, PV_NONE,
1163 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1164#else
1165 (char_u *)NULL, PV_NONE,
1166 {(char_u *)"", (char_u *)0L}
1167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001169 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1170 (char_u *)&p_fixeol, PV_FIXEOL,
1171 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1173#ifdef FEAT_FKMAP
1174 (char_u *)&p_fkmap, PV_NONE,
1175#else
1176 (char_u *)NULL, PV_NONE,
1177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 {"flash", "fl", P_BOOL|P_VI_DEF,
1180 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001183 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1187 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1190 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1193# ifdef FEAT_EVAL
1194 (char_u *)VAR_WIN, PV_FDE,
1195 {(char_u *)"0", (char_u *)NULL}
1196# else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)NULL, (char_u *)0L}
1199# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1202 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1205 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001207 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001211 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)"{{{,}}}", (char_u *)NULL}
1214 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1216 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1219 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001224 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 (char_u *)&p_fdo, PV_NONE,
1226 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1229# ifdef FEAT_EVAL
1230 (char_u *)VAR_WIN, PV_FDT,
1231 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001232# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 (char_u *)NULL, PV_NONE,
1234 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001235# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001238 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001239#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001240 (char_u *)&p_fex, PV_FEX,
1241 {(char_u *)"", (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)0L, (char_u *)0L}
1245#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1248 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1250 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001251 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1252 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001253 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1254 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1256 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001257 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001258 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1259#ifdef HAVE_FSYNC
1260 (char_u *)&p_fs, PV_NONE,
1261 {(char_u *)TRUE, (char_u *)0L}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)FALSE, (char_u *)0L}
1265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1268 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 {"graphic", "gr", P_BOOL|P_VI_DEF,
1271 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001273 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001274#ifdef FEAT_QUICKFIX
1275 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001276 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277#else
1278 (char_u *)NULL, PV_NONE,
1279 {(char_u *)NULL, (char_u *)0L}
1280#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1283#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001284 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285 {
1286# ifdef WIN3264
1287 /* may be changed to "grep -n" in os_win32.c */
1288 (char_u *)"findstr /n",
1289# else
1290# ifdef UNIX
1291 /* Add an extra file name so that grep will always
1292 * insert a file name in the match line. */
1293 (char_u *)"grep -n $* /dev/null",
1294# else
1295# ifdef VMS
1296 (char_u *)"SEARCH/NUMBERS ",
1297# else
1298 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001299# endif
1300# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001302 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303#else
1304 (char_u *)NULL, PV_NONE,
1305 {(char_u *)NULL, (char_u *)0L}
1306#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001307 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001308 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#ifdef CURSOR_SHAPE
1310 (char_u *)&p_guicursor, PV_NONE,
1311 {
1312# ifdef FEAT_GUI
1313 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001314# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1316# endif
1317 (char_u *)0L}
1318#else
1319 (char_u *)NULL, PV_NONE,
1320 {(char_u *)NULL, (char_u *)0L}
1321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001322 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001323 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324#ifdef FEAT_GUI
1325 (char_u *)&p_guifont, PV_NONE,
1326 {(char_u *)"", (char_u *)0L}
1327#else
1328 (char_u *)NULL, PV_NONE,
1329 {(char_u *)NULL, (char_u *)0L}
1330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001332 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1334 (char_u *)&p_guifontset, PV_NONE,
1335 {(char_u *)"", (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)NULL, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001341 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1343 (char_u *)&p_guifontwide, PV_NONE,
1344 {(char_u *)"", (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)NULL, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001351#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352 (char_u *)&p_ghr, PV_NONE,
1353#else
1354 (char_u *)NULL, PV_NONE,
1355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001356 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001358#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 (char_u *)&p_go, PV_NONE,
1360# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001361 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001363 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364# endif
1365#else
1366 (char_u *)NULL, PV_NONE,
1367 {(char_u *)NULL, (char_u *)0L}
1368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001369 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370 {"guipty", NULL, P_BOOL|P_VI_DEF,
1371#if defined(FEAT_GUI)
1372 (char_u *)&p_guipty, PV_NONE,
1373#else
1374 (char_u *)NULL, PV_NONE,
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001377 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001378#if defined(FEAT_GUI_TABLINE)
1379 (char_u *)&p_gtl, PV_NONE,
1380 {(char_u *)"", (char_u *)0L}
1381#else
1382 (char_u *)NULL, PV_NONE,
1383 {(char_u *)NULL, (char_u *)0L}
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001386 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001387#if defined(FEAT_GUI_TABLINE)
1388 (char_u *)&p_gtt, PV_NONE,
1389 {(char_u *)"", (char_u *)0L}
1390#else
1391 (char_u *)NULL, PV_NONE,
1392 {(char_u *)NULL, (char_u *)0L}
1393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1396 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1399 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1401 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402 {"helpheight", "hh", P_NUM|P_VI_DEF,
1403#ifdef FEAT_WINDOWS
1404 (char_u *)&p_hh, PV_NONE,
1405#else
1406 (char_u *)NULL, PV_NONE,
1407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001409 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410#ifdef FEAT_MULTI_LANG
1411 (char_u *)&p_hlg, PV_NONE,
1412 {(char_u *)"", (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)0L, (char_u *)0L}
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 {"hidden", "hid", P_BOOL|P_VI_DEF,
1419 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001420 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001421 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001422 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1424 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 {"history", "hi", P_NUM|P_VIM,
1426 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001427 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1429#ifdef FEAT_RIGHTLEFT
1430 (char_u *)&p_hkmap, PV_NONE,
1431#else
1432 (char_u *)NULL, PV_NONE,
1433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1436#ifdef FEAT_RIGHTLEFT
1437 (char_u *)&p_hkmapp, PV_NONE,
1438#else
1439 (char_u *)NULL, PV_NONE,
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1443 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"icon", NULL, P_BOOL|P_VI_DEF,
1446#ifdef FEAT_TITLE
1447 (char_u *)&p_icon, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"iconstring", NULL, P_STRING|P_VI_DEF,
1453#ifdef FEAT_TITLE
1454 (char_u *)&p_iconstring, PV_NONE,
1455#else
1456 (char_u *)NULL, PV_NONE,
1457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1460 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001462 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1463# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1464 (char_u *)&p_imaf, PV_NONE,
1465 {(char_u *)"", (char_u *)NULL}
1466# else
1467 (char_u *)NULL, PV_NONE,
1468 {(char_u *)NULL, (char_u *)0L}
1469# endif
1470 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001472#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 (char_u *)&p_imak, PV_NONE,
1474#else
1475 (char_u *)NULL, PV_NONE,
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1479#ifdef USE_IM_CONTROL
1480 (char_u *)&p_imcmdline, PV_NONE,
1481#else
1482 (char_u *)NULL, PV_NONE,
1483#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001484 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1486#ifdef USE_IM_CONTROL
1487 (char_u *)&p_imdisable, PV_NONE,
1488#else
1489 (char_u *)NULL, PV_NONE,
1490#endif
1491#ifdef __sgi
1492 {(char_u *)TRUE, (char_u *)0L}
1493#else
1494 {(char_u *)FALSE, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"iminsert", "imi", P_NUM|P_VI_DEF,
1498 (char_u *)&p_iminsert, PV_IMI,
1499#ifdef B_IMODE_IM
1500 {(char_u *)B_IMODE_IM, (char_u *)0L}
1501#else
1502 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"imsearch", "ims", P_NUM|P_VI_DEF,
1506 (char_u *)&p_imsearch, PV_IMS,
1507#ifdef B_IMODE_IM
1508 {(char_u *)B_IMODE_IM, (char_u *)0L}
1509#else
1510 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001512 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001513 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001514# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1515 (char_u *)&p_imsf, PV_NONE,
1516 {(char_u *)"", (char_u *)NULL}
1517# else
1518 (char_u *)NULL, PV_NONE,
1519 {(char_u *)NULL, (char_u *)0L}
1520# endif
1521 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1523#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001524 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1526#else
1527 (char_u *)NULL, PV_NONE,
1528 {(char_u *)0L, (char_u *)0L}
1529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1532#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1533 (char_u *)&p_inex, PV_INEX,
1534 {(char_u *)"", (char_u *)0L}
1535#else
1536 (char_u *)NULL, PV_NONE,
1537 {(char_u *)0L, (char_u *)0L}
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1541 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1544#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1545 (char_u *)&p_inde, PV_INDE,
1546 {(char_u *)"", (char_u *)0L}
1547#else
1548 (char_u *)NULL, PV_NONE,
1549 {(char_u *)0L, (char_u *)0L}
1550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001551 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001552 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1554 (char_u *)&p_indk, PV_INDK,
1555 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1556#else
1557 (char_u *)NULL, PV_NONE,
1558 {(char_u *)0L, (char_u *)0L}
1559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001560 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"infercase", "inf", P_BOOL|P_VI_DEF,
1562 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1565 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1568 (char_u *)&p_isf, PV_NONE,
1569 {
1570#ifdef BACKSLASH_IN_FILENAME
1571 /* Excluded are: & and ^ are special in cmd.exe
1572 * ( and ) are used in text separating fnames */
1573 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1574#else
1575# ifdef AMIGA
1576 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1577# else
1578# ifdef VMS
1579 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1580# else /* UNIX et al. */
1581# ifdef EBCDIC
1582 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1583# else
1584 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1585# endif
1586# endif
1587# endif
1588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001589 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1591 (char_u *)&p_isi, PV_NONE,
1592 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001593#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 (char_u *)"@,48-57,_,128-167,224-235",
1595#else
1596# ifdef EBCDIC
1597 /* TODO: EBCDIC Check this! @ == isalpha()*/
1598 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1599 "112-120,128,140-142,156,158,172,"
1600 "174,186,191,203-207,219-225,235-239,"
1601 "251-254",
1602# else
1603 (char_u *)"@,48-57,_,192-255",
1604# endif
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1608 (char_u *)&p_isk, PV_ISK,
1609 {
1610#ifdef EBCDIC
1611 (char_u *)"@,240-249,_",
1612 /* TODO: EBCDIC Check this! @ == isalpha()*/
1613 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1614 "112-120,128,140-142,156,158,172,"
1615 "174,186,191,203-207,219-225,235-239,"
1616 "251-254",
1617#else
1618 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001619# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 (char_u *)"@,48-57,_,128-167,224-235"
1621# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001622 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623# endif
1624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1627 (char_u *)&p_isp, PV_NONE,
1628 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001629#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 || defined(VMS)
1631 (char_u *)"@,~-255",
1632#else
1633# ifdef EBCDIC
1634 /* all chars above 63 are printable */
1635 (char_u *)"63-255",
1636# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001637 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638# endif
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1642 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1645#ifdef FEAT_CRYPT
1646 (char_u *)&p_key, PV_KEY,
1647 {(char_u *)"", (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)0L, (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001653 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654#ifdef FEAT_KEYMAP
1655 (char_u *)&p_keymap, PV_KMAP,
1656 {(char_u *)"", (char_u *)0L}
1657#else
1658 (char_u *)NULL, PV_NONE,
1659 {(char_u *)"", (char_u *)0L}
1660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001662 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001666 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001668#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669 (char_u *)":help",
1670#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001671# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001673# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001674# ifdef USEMAN_S
1675 (char_u *)"man -s",
1676# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001678# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679# endif
1680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001681 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001682 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683#ifdef FEAT_LANGMAP
1684 (char_u *)&p_langmap, PV_NONE,
1685 {(char_u *)"", /* unmatched } */
1686#else
1687 (char_u *)NULL, PV_NONE,
1688 {(char_u *)NULL,
1689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001690 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001691 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1693 (char_u *)&p_lm, PV_NONE,
1694#else
1695 (char_u *)NULL, PV_NONE,
1696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001697 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001698 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1699#ifdef FEAT_LANGMAP
1700 (char_u *)&p_lnr, PV_NONE,
1701#else
1702 (char_u *)NULL, PV_NONE,
1703#endif
1704 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1706#ifdef FEAT_WINDOWS
1707 (char_u *)&p_ls, PV_NONE,
1708#else
1709 (char_u *)NULL, PV_NONE,
1710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001711 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1713 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1716#ifdef FEAT_LINEBREAK
1717 (char_u *)VAR_WIN, PV_LBR,
1718#else
1719 (char_u *)NULL, PV_NONE,
1720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1723 (char_u *)&Rows, PV_NONE,
1724 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001725#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 (char_u *)25L,
1727#else
1728 (char_u *)24L,
1729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1732#ifdef FEAT_GUI
1733 (char_u *)&p_linespace, PV_NONE,
1734#else
1735 (char_u *)NULL, PV_NONE,
1736#endif
1737#ifdef FEAT_GUI_W32
1738 {(char_u *)1L, (char_u *)0L}
1739#else
1740 {(char_u *)0L, (char_u *)0L}
1741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001742 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 {"lisp", NULL, P_BOOL|P_VI_DEF,
1744#ifdef FEAT_LISP
1745 (char_u *)&p_lisp, PV_LISP,
1746#else
1747 (char_u *)NULL, PV_NONE,
1748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001750 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001752 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1754#else
1755 (char_u *)NULL, PV_NONE,
1756 {(char_u *)"", (char_u *)0L}
1757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001758 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1760 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001761 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001762 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001764 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1766 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001768#if defined(DYNAMIC_LUA)
Bram Moolenaara6e42502016-04-20 16:19:52 +02001769 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001770 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001771 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1772 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001773#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001774#ifdef FEAT_GUI_MAC
1775 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1776 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 {"magic", NULL, P_BOOL|P_VI_DEF,
1780 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001781 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001782 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783#ifdef FEAT_QUICKFIX
1784 (char_u *)&p_mef, PV_NONE,
1785 {(char_u *)"", (char_u *)0L}
1786#else
1787 (char_u *)NULL, PV_NONE,
1788 {(char_u *)NULL, (char_u *)0L}
1789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1792#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001793 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794# ifdef VMS
1795 {(char_u *)"MMS", (char_u *)0L}
1796# else
1797 {(char_u *)"make", (char_u *)0L}
1798# endif
1799#else
1800 (char_u *)NULL, PV_NONE,
1801 {(char_u *)NULL, (char_u *)0L}
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001804 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001806 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1807 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"matchtime", "mat", P_NUM|P_VI_DEF,
1809 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001811 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001812#ifdef FEAT_MBYTE
1813 (char_u *)&p_mco, PV_NONE,
1814#else
1815 (char_u *)NULL, PV_NONE,
1816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1819#ifdef FEAT_EVAL
1820 (char_u *)&p_mfd, PV_NONE,
1821#else
1822 (char_u *)NULL, PV_NONE,
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1826 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"maxmem", "mm", P_NUM|P_VI_DEF,
1829 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1831 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001832 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1838 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"menuitems", "mis", P_NUM|P_VI_DEF,
1840#ifdef FEAT_MENU
1841 (char_u *)&p_mis, PV_NONE,
1842#else
1843 (char_u *)NULL, PV_NONE,
1844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"mesg", NULL, P_BOOL|P_VI_DEF,
1847 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001849 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001850#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001851 (char_u *)&p_msm, PV_NONE,
1852 {(char_u *)"460000,2000,500", (char_u *)0L}
1853#else
1854 (char_u *)NULL, PV_NONE,
1855 {(char_u *)0L, (char_u *)0L}
1856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001857 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {"modeline", "ml", P_BOOL|P_VIM,
1859 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"modelines", "mls", P_NUM|P_VI_DEF,
1862 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1865 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1868 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"more", NULL, P_BOOL|P_VIM,
1871 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1874 (char_u *)&p_mouse, PV_NONE,
1875 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001876#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 (char_u *)"a",
1878#else
1879 (char_u *)"",
1880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1883#ifdef FEAT_GUI
1884 (char_u *)&p_mousef, PV_NONE,
1885#else
1886 (char_u *)NULL, PV_NONE,
1887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1890#ifdef FEAT_GUI
1891 (char_u *)&p_mh, PV_NONE,
1892#else
1893 (char_u *)NULL, PV_NONE,
1894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1897 (char_u *)&p_mousem, PV_NONE,
1898 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001899#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 (char_u *)"popup",
1901#else
1902# if defined(MACOS)
1903 (char_u *)"popup_setpos",
1904# else
1905 (char_u *)"extend",
1906# endif
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001909 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910#ifdef FEAT_MOUSESHAPE
1911 (char_u *)&p_mouseshape, PV_NONE,
1912 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1913#else
1914 (char_u *)NULL, PV_NONE,
1915 {(char_u *)NULL, (char_u *)0L}
1916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1919 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001921 {"mzquantum", "mzq", P_NUM,
1922#ifdef FEAT_MZSCHEME
1923 (char_u *)&p_mzq, PV_NONE,
1924#else
1925 (char_u *)NULL, PV_NONE,
1926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"novice", NULL, P_BOOL|P_VI_DEF,
1929 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001931 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001933 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1936 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001938 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1939#ifdef FEAT_LINEBREAK
1940 (char_u *)VAR_WIN, PV_NUW,
1941#else
1942 (char_u *)NULL, PV_NONE,
1943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001945 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001946#ifdef FEAT_COMPL_FUNC
1947 (char_u *)&p_ofu, PV_OFU,
1948 {(char_u *)"", (char_u *)0L}
1949#else
1950 (char_u *)NULL, PV_NONE,
1951 {(char_u *)0L, (char_u *)0L}
1952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"open", NULL, P_BOOL|P_VI_DEF,
1955 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001957 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001958#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001959 (char_u *)&p_odev, PV_NONE,
1960#else
1961 (char_u *)NULL, PV_NONE,
1962#endif
1963 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001965 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1966 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"optimize", "opt", P_BOOL|P_VI_DEF,
1969 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001973 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001974 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1975 |P_SECURE,
1976 (char_u *)&p_pp, PV_NONE,
1977 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
1978 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"paragraphs", "para", P_STRING|P_VI_DEF,
1980 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001981 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001983 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1987 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1990#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1991 (char_u *)&p_pex, PV_NONE,
1992 {(char_u *)"", (char_u *)0L}
1993#else
1994 (char_u *)NULL, PV_NONE,
1995 {(char_u *)0L, (char_u *)0L}
1996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001998 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002002 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002004#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002005 (char_u *)".,,",
2006#else
2007# if defined(__EMX__)
2008 (char_u *)".,/emx/include,,",
2009# else /* Unix, probably */
2010 (char_u *)".,/usr/include,,",
2011# endif
2012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002013 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002014#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002015 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002016 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002017 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2018 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2021 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002023 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2025 (char_u *)&p_pvh, PV_NONE,
2026#else
2027 (char_u *)NULL, PV_NONE,
2028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2031#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2032 (char_u *)VAR_WIN, PV_PVW,
2033#else
2034 (char_u *)NULL, PV_NONE,
2035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002037 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038#ifdef FEAT_PRINTER
2039 (char_u *)&p_pdev, PV_NONE,
2040 {(char_u *)"", (char_u *)0L}
2041#else
2042 (char_u *)NULL, PV_NONE,
2043 {(char_u *)NULL, (char_u *)0L}
2044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046 {"printencoding", "penc", P_STRING|P_VI_DEF,
2047#ifdef FEAT_POSTSCRIPT
2048 (char_u *)&p_penc, PV_NONE,
2049 {(char_u *)"", (char_u *)0L}
2050#else
2051 (char_u *)NULL, PV_NONE,
2052 {(char_u *)NULL, (char_u *)0L}
2053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2056#ifdef FEAT_POSTSCRIPT
2057 (char_u *)&p_pexpr, PV_NONE,
2058 {(char_u *)"", (char_u *)0L}
2059#else
2060 (char_u *)NULL, PV_NONE,
2061 {(char_u *)NULL, (char_u *)0L}
2062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"printfont", "pfn", P_STRING|P_VI_DEF,
2065#ifdef FEAT_PRINTER
2066 (char_u *)&p_pfn, PV_NONE,
2067 {
2068# ifdef MSWIN
2069 (char_u *)"Courier_New:h10",
2070# else
2071 (char_u *)"courier",
2072# endif
2073 (char_u *)0L}
2074#else
2075 (char_u *)NULL, PV_NONE,
2076 {(char_u *)NULL, (char_u *)0L}
2077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002078 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2080#ifdef FEAT_PRINTER
2081 (char_u *)&p_header, PV_NONE,
2082 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2083#else
2084 (char_u *)NULL, PV_NONE,
2085 {(char_u *)NULL, (char_u *)0L}
2086#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002087 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002088 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2089#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2090 (char_u *)&p_pmcs, PV_NONE,
2091 {(char_u *)"", (char_u *)0L}
2092#else
2093 (char_u *)NULL, PV_NONE,
2094 {(char_u *)NULL, (char_u *)0L}
2095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002097 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2098#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2099 (char_u *)&p_pmfn, PV_NONE,
2100 {(char_u *)"", (char_u *)0L}
2101#else
2102 (char_u *)NULL, PV_NONE,
2103 {(char_u *)NULL, (char_u *)0L}
2104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002106 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107#ifdef FEAT_PRINTER
2108 (char_u *)&p_popt, PV_NONE,
2109 {(char_u *)"", (char_u *)0L}
2110#else
2111 (char_u *)NULL, PV_NONE,
2112 {(char_u *)NULL, (char_u *)0L}
2113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002116 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002118 {"pumheight", "ph", P_NUM|P_VI_DEF,
2119#ifdef FEAT_INS_EXPAND
2120 (char_u *)&p_ph, PV_NONE,
2121#else
2122 (char_u *)NULL, PV_NONE,
2123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002125#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002126 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002127 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002128 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2129 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002130#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002131#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002132 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002134 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2135 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002137 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2138#ifdef FEAT_TEXTOBJ
2139 (char_u *)&p_qe, PV_QE,
2140 {(char_u *)"\\", (char_u *)0L}
2141#else
2142 (char_u *)NULL, PV_NONE,
2143 {(char_u *)NULL, (char_u *)0L}
2144#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2147 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 {"redraw", NULL, P_BOOL|P_VI_DEF,
2150 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002152 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2153#ifdef FEAT_RELTIME
2154 (char_u *)&p_rdt, PV_NONE,
2155#else
2156 (char_u *)NULL, PV_NONE,
2157#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002158 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002159 {"regexpengine", "re", P_NUM|P_VI_DEF,
2160 (char_u *)&p_re, PV_NONE,
2161 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002162 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2163 (char_u *)VAR_WIN, PV_RNU,
2164 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165 {"remap", NULL, P_BOOL|P_VI_DEF,
2166 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002168 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002169#ifdef FEAT_RENDER_OPTIONS
2170 (char_u *)&p_rop, PV_NONE,
2171 {(char_u *)"", (char_u *)0L}
2172#else
2173 (char_u *)NULL, PV_NONE,
2174 {(char_u *)NULL, (char_u *)0L}
2175#endif
2176 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"report", NULL, P_NUM|P_VI_DEF,
2178 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002179 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2181#ifdef WIN3264
2182 (char_u *)&p_rs, PV_NONE,
2183#else
2184 (char_u *)NULL, PV_NONE,
2185#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2188#ifdef FEAT_RIGHTLEFT
2189 (char_u *)&p_ri, PV_NONE,
2190#else
2191 (char_u *)NULL, PV_NONE,
2192#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2195#ifdef FEAT_RIGHTLEFT
2196 (char_u *)VAR_WIN, PV_RL,
2197#else
2198 (char_u *)NULL, PV_NONE,
2199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002200 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002201 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2202#ifdef FEAT_RIGHTLEFT
2203 (char_u *)VAR_WIN, PV_RLC,
2204 {(char_u *)"search", (char_u *)NULL}
2205#else
2206 (char_u *)NULL, PV_NONE,
2207 {(char_u *)NULL, (char_u *)0L}
2208#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002209 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002210#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002211 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002212 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002213 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2214 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2217#ifdef FEAT_CMDL_INFO
2218 (char_u *)&p_ru, PV_NONE,
2219#else
2220 (char_u *)NULL, PV_NONE,
2221#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2224#ifdef FEAT_STL_OPT
2225 (char_u *)&p_ruf, PV_NONE,
2226#else
2227 (char_u *)NULL, PV_NONE,
2228#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002230 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2231 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2234 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002235 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2236 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2239#ifdef FEAT_SCROLLBIND
2240 (char_u *)VAR_WIN, PV_SCBIND,
2241#else
2242 (char_u *)NULL, PV_NONE,
2243#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002244 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002245 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2246 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002247 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002248 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2249 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002250 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002251 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002252#ifdef FEAT_SCROLLBIND
2253 (char_u *)&p_sbo, PV_NONE,
2254 {(char_u *)"ver,jump", (char_u *)0L}
2255#else
2256 (char_u *)NULL, PV_NONE,
2257 {(char_u *)0L, (char_u *)0L}
2258#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002259 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 {"sections", "sect", P_STRING|P_VI_DEF,
2261 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002262 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2263 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002264 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2265 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002266 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002269 {(char_u *)"inclusive", (char_u *)0L}
2270 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002271 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002274 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275#ifdef FEAT_SESSION
2276 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002277 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 (char_u *)0L}
2279#else
2280 (char_u *)NULL, PV_NONE,
2281 {(char_u *)0L, (char_u *)0L}
2282#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002283 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2285 (char_u *)&p_sh, PV_NONE,
2286 {
2287#ifdef VMS
2288 (char_u *)"-",
2289#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002290# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002292# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294# endif
2295#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002296 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2298 (char_u *)&p_shcf, PV_NONE,
2299 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002300#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 (char_u *)"/c",
2302#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002305 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2307#ifdef FEAT_QUICKFIX
2308 (char_u *)&p_sp, PV_NONE,
2309 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002310#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312#else
2313 (char_u *)">",
2314#endif
2315 (char_u *)0L}
2316#else
2317 (char_u *)NULL, PV_NONE,
2318 {(char_u *)0L, (char_u *)0L}
2319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2322 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2325 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2328#ifdef BACKSLASH_IN_FILENAME
2329 (char_u *)&p_ssl, PV_NONE,
2330#else
2331 (char_u *)NULL, PV_NONE,
2332#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002333 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002334 {"shelltemp", "stmp", P_BOOL,
2335 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"shelltype", "st", P_NUM|P_VI_DEF,
2338#ifdef AMIGA
2339 (char_u *)&p_st, PV_NONE,
2340#else
2341 (char_u *)NULL, PV_NONE,
2342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2345 (char_u *)&p_sxq, PV_NONE,
2346 {
2347#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2348 (char_u *)"\"",
2349#else
2350 (char_u *)"",
2351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002353 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2354 (char_u *)&p_sxe, PV_NONE,
2355 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002356#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002357 (char_u *)"\"&|<>()@^",
2358#else
2359 (char_u *)"",
2360#endif
2361 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2363 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2366 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2369 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)"", (char_u *)"filnxtToO"}
2371 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2376#ifdef FEAT_LINEBREAK
2377 (char_u *)&p_sbr, PV_NONE,
2378#else
2379 (char_u *)NULL, PV_NONE,
2380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"showcmd", "sc", P_BOOL|P_VIM,
2383#ifdef FEAT_CMDL_INFO
2384 (char_u *)&p_sc, PV_NONE,
2385#else
2386 (char_u *)NULL, PV_NONE,
2387#endif
2388 {(char_u *)FALSE,
2389#ifdef UNIX
2390 (char_u *)FALSE
2391#else
2392 (char_u *)TRUE
2393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2396 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002397 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2399 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"showmode", "smd", P_BOOL|P_VIM,
2402 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002404 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2405#ifdef FEAT_WINDOWS
2406 (char_u *)&p_stal, PV_NONE,
2407#else
2408 (char_u *)NULL, PV_NONE,
2409#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2412 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2415 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2418 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2421 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2424#ifdef FEAT_SMARTINDENT
2425 (char_u *)&p_si, PV_SI,
2426#else
2427 (char_u *)NULL, PV_NONE,
2428#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2431 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2434 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2437 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002439 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002440#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002441 (char_u *)VAR_WIN, PV_SPELL,
2442#else
2443 (char_u *)NULL, PV_NONE,
2444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002446 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002447#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002448 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002449 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002450#else
2451 (char_u *)NULL, PV_NONE,
2452 {(char_u *)0L, (char_u *)0L}
2453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002455 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2456 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002457#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002458 (char_u *)&p_spf, PV_SPF,
2459 {(char_u *)"", (char_u *)0L}
2460#else
2461 (char_u *)NULL, PV_NONE,
2462 {(char_u *)0L, (char_u *)0L}
2463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002465 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2466 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002467#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002468 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002469 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002470#else
2471 (char_u *)NULL, PV_NONE,
2472 {(char_u *)0L, (char_u *)0L}
2473#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002474 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002475 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002476#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002477 (char_u *)&p_sps, PV_NONE,
2478 {(char_u *)"best", (char_u *)0L}
2479#else
2480 (char_u *)NULL, PV_NONE,
2481 {(char_u *)0L, (char_u *)0L}
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2485#ifdef FEAT_WINDOWS
2486 (char_u *)&p_sb, PV_NONE,
2487#else
2488 (char_u *)NULL, PV_NONE,
2489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002492#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 (char_u *)&p_spr, PV_NONE,
2494#else
2495 (char_u *)NULL, PV_NONE,
2496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2499 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2502#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002503 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504#else
2505 (char_u *)NULL, PV_NONE,
2506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002508 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 (char_u *)&p_su, PV_NONE,
2510 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002512 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002513#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 (char_u *)&p_sua, PV_SUA,
2515 {(char_u *)"", (char_u *)0L}
2516#else
2517 (char_u *)NULL, PV_NONE,
2518 {(char_u *)0L, (char_u *)0L}
2519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2522 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"swapsync", "sws", P_STRING|P_VI_DEF,
2525 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002527 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002530 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2531#ifdef FEAT_SYN_HL
2532 (char_u *)&p_smc, PV_SMC,
2533 {(char_u *)3000L, (char_u *)0L}
2534#else
2535 (char_u *)NULL, PV_NONE,
2536 {(char_u *)0L, (char_u *)0L}
2537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002539 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540#ifdef FEAT_SYN_HL
2541 (char_u *)&p_syn, PV_SYN,
2542 {(char_u *)"", (char_u *)0L}
2543#else
2544 (char_u *)NULL, PV_NONE,
2545 {(char_u *)0L, (char_u *)0L}
2546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002548 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2549#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002550 (char_u *)&p_tal, PV_NONE,
2551#else
2552 (char_u *)NULL, PV_NONE,
2553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002554 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002555 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2556#ifdef FEAT_WINDOWS
2557 (char_u *)&p_tpm, PV_NONE,
2558#else
2559 (char_u *)NULL, PV_NONE,
2560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2563 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2566 (char_u *)&p_tbs, PV_NONE,
2567#ifdef VMS /* binary searching doesn't appear to work on VMS */
2568 {(char_u *)0L, (char_u *)0L}
2569#else
2570 {(char_u *)TRUE, (char_u *)0L}
2571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002573 {"tagcase", "tc", P_STRING|P_VIM,
2574 (char_u *)&p_tc, PV_TC,
2575 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"taglength", "tl", P_NUM|P_VI_DEF,
2577 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"tagrelative", "tr", P_BOOL|P_VIM,
2580 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002582 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002583 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {
2585#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2586 (char_u *)"./tags,./TAGS,tags,TAGS",
2587#else
2588 (char_u *)"./tags,tags",
2589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2592 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002594#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002595 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002596 (char_u *)&p_tcldll, PV_NONE,
2597 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2598 SCRIPTID_INIT},
2599#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2601 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002602 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2604#ifdef FEAT_ARABIC
2605 (char_u *)&p_tbidi, PV_NONE,
2606#else
2607 (char_u *)NULL, PV_NONE,
2608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2611#ifdef FEAT_MBYTE
2612 (char_u *)&p_tenc, PV_NONE,
2613 {(char_u *)"", (char_u *)0L}
2614#else
2615 (char_u *)NULL, PV_NONE,
2616 {(char_u *)0L, (char_u *)0L}
2617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 {"terse", NULL, P_BOOL|P_VI_DEF,
2620 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"textauto", "ta", P_BOOL|P_VIM,
2623 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2625 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2627 (char_u *)&p_tx, PV_TX,
2628 {
2629#ifdef USE_CRNL
2630 (char_u *)TRUE,
2631#else
2632 (char_u *)FALSE,
2633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002635 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002638 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002640 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641#else
2642 (char_u *)NULL, PV_NONE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2646 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"timeout", "to", P_BOOL|P_VI_DEF,
2649 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2652 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"title", NULL, P_BOOL|P_VI_DEF,
2655#ifdef FEAT_TITLE
2656 (char_u *)&p_title, PV_NONE,
2657#else
2658 (char_u *)NULL, PV_NONE,
2659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"titlelen", NULL, P_NUM|P_VI_DEF,
2662#ifdef FEAT_TITLE
2663 (char_u *)&p_titlelen, PV_NONE,
2664#else
2665 (char_u *)NULL, PV_NONE,
2666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002668 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669#ifdef FEAT_TITLE
2670 (char_u *)&p_titleold, PV_NONE,
2671 {(char_u *)N_("Thanks for flying Vim"),
2672 (char_u *)0L}
2673#else
2674 (char_u *)NULL, PV_NONE,
2675 {(char_u *)0L, (char_u *)0L}
2676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"titlestring", NULL, P_STRING|P_VI_DEF,
2679#ifdef FEAT_TITLE
2680 (char_u *)&p_titlestring, PV_NONE,
2681#else
2682 (char_u *)NULL, PV_NONE,
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002686 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002688 {(char_u *)"icons,tooltips", (char_u *)0L}
2689 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002691#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2693 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695#endif
2696 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2697 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2700 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2703 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2706 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2709#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2710 (char_u *)&p_ttym, PV_NONE,
2711#else
2712 (char_u *)NULL, PV_NONE,
2713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2716 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2719 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002721 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2722 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002723#ifdef FEAT_PERSISTENT_UNDO
2724 (char_u *)&p_udir, PV_NONE,
2725 {(char_u *)".", (char_u *)0L}
2726#else
2727 (char_u *)NULL, PV_NONE,
2728 {(char_u *)0L, (char_u *)0L}
2729#endif
2730 SCRIPTID_INIT},
2731 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2732#ifdef FEAT_PERSISTENT_UNDO
2733 (char_u *)&p_udf, PV_UDF,
2734#else
2735 (char_u *)NULL, PV_NONE,
2736#endif
2737 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002739 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002741#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 (char_u *)1000L,
2743#else
2744 (char_u *)100L,
2745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002747 {"undoreload", "ur", P_NUM|P_VI_DEF,
2748 (char_u *)&p_ur, PV_NONE,
2749 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"updatecount", "uc", P_NUM|P_VI_DEF,
2751 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002752 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"updatetime", "ut", P_NUM|P_VI_DEF,
2754 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"verbose", "vbs", P_NUM|P_VI_DEF,
2757 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002759 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2760 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2763#ifdef FEAT_SESSION
2764 (char_u *)&p_vdir, PV_NONE,
2765 {(char_u *)DFLT_VDIR, (char_u *)0L}
2766#else
2767 (char_u *)NULL, PV_NONE,
2768 {(char_u *)0L, (char_u *)0L}
2769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002771 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772#ifdef FEAT_SESSION
2773 (char_u *)&p_vop, PV_NONE,
2774 {(char_u *)"folds,options,cursor", (char_u *)0L}
2775#else
2776 (char_u *)NULL, PV_NONE,
2777 {(char_u *)0L, (char_u *)0L}
2778#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002779 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002780 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781#ifdef FEAT_VIMINFO
2782 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002783#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002784 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785#else
2786# ifdef AMIGA
2787 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002788 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002790 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791# endif
2792#endif
2793#else
2794 (char_u *)NULL, PV_NONE,
2795 {(char_u *)0L, (char_u *)0L}
2796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002798 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2799 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#ifdef FEAT_VIRTUALEDIT
2801 (char_u *)&p_ve, PV_NONE,
2802 {(char_u *)"", (char_u *)""}
2803#else
2804 (char_u *)NULL, PV_NONE,
2805 {(char_u *)0L, (char_u *)0L}
2806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2809 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"w300", NULL, P_NUM|P_VI_DEF,
2812 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"w1200", NULL, P_NUM|P_VI_DEF,
2815 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"w9600", NULL, P_NUM|P_VI_DEF,
2818 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"warn", NULL, P_BOOL|P_VI_DEF,
2821 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2824 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002826 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"wildchar", "wc", P_NUM|P_VIM,
2830 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2832 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002833 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002835 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002836 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837#ifdef FEAT_WILDIGN
2838 (char_u *)&p_wig, PV_NONE,
2839#else
2840 (char_u *)NULL, PV_NONE,
2841#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002843 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2844 (char_u *)&p_wic, PV_NONE,
2845 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2847#ifdef FEAT_WILDMENU
2848 (char_u *)&p_wmnu, PV_NONE,
2849#else
2850 (char_u *)NULL, PV_NONE,
2851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002853 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002856 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2857#ifdef FEAT_CMDL_COMPL
2858 (char_u *)&p_wop, PV_NONE,
2859 {(char_u *)"", (char_u *)0L}
2860#else
2861 (char_u *)NULL, PV_NONE,
2862 {(char_u *)NULL, (char_u *)0L}
2863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002864 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2866#ifdef FEAT_WAK
2867 (char_u *)&p_wak, PV_NONE,
2868 {(char_u *)"menu", (char_u *)0L}
2869#else
2870 (char_u *)NULL, PV_NONE,
2871 {(char_u *)NULL, (char_u *)0L}
2872#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002875 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"winheight", "wh", P_NUM|P_VI_DEF,
2878#ifdef FEAT_WINDOWS
2879 (char_u *)&p_wh, PV_NONE,
2880#else
2881 (char_u *)NULL, PV_NONE,
2882#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002885#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 (char_u *)VAR_WIN, PV_WFH,
2887#else
2888 (char_u *)NULL, PV_NONE,
2889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002891 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002892#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002893 (char_u *)VAR_WIN, PV_WFW,
2894#else
2895 (char_u *)NULL, PV_NONE,
2896#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2899#ifdef FEAT_WINDOWS
2900 (char_u *)&p_wmh, PV_NONE,
2901#else
2902 (char_u *)NULL, PV_NONE,
2903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002904 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002906#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 (char_u *)&p_wmw, PV_NONE,
2908#else
2909 (char_u *)NULL, PV_NONE,
2910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002913#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 (char_u *)&p_wiw, PV_NONE,
2915#else
2916 (char_u *)NULL, PV_NONE,
2917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002918 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2920 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2923 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2926 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"write", NULL, P_BOOL|P_VI_DEF,
2929 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002930 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 {"writeany", "wa", P_BOOL|P_VI_DEF,
2932 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002933 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2935 (char_u *)&p_wb, PV_NONE,
2936 {
2937#ifdef FEAT_WRITEBACKUP
2938 (char_u *)TRUE,
2939#else
2940 (char_u *)FALSE,
2941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002942 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 {"writedelay", "wd", P_NUM|P_VI_DEF,
2944 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002945 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946
2947/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002948#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951
2952 p_term("t_AB", T_CAB)
2953 p_term("t_AF", T_CAF)
2954 p_term("t_AL", T_CAL)
2955 p_term("t_al", T_AL)
2956 p_term("t_bc", T_BC)
2957 p_term("t_cd", T_CD)
2958 p_term("t_ce", T_CE)
2959 p_term("t_cl", T_CL)
2960 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002961 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962 p_term("t_Co", T_CCO)
2963 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002964 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002966#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 p_term("t_CV", T_CSV)
2968#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 p_term("t_da", T_DA)
2970 p_term("t_db", T_DB)
2971 p_term("t_DL", T_CDL)
2972 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002973 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 p_term("t_fs", T_FS)
2975 p_term("t_IE", T_CIE)
2976 p_term("t_IS", T_CIS)
2977 p_term("t_ke", T_KE)
2978 p_term("t_ks", T_KS)
2979 p_term("t_le", T_LE)
2980 p_term("t_mb", T_MB)
2981 p_term("t_md", T_MD)
2982 p_term("t_me", T_ME)
2983 p_term("t_mr", T_MR)
2984 p_term("t_ms", T_MS)
2985 p_term("t_nd", T_ND)
2986 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002987 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 p_term("t_RI", T_CRI)
2989 p_term("t_RV", T_CRV)
2990 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002992 p_term("t_Sf", T_CSF)
2993 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02002995 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 p_term("t_te", T_TE)
2998 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02002999 p_term("t_ts", T_TS)
3000 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 p_term("t_ue", T_UE)
3002 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003003 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 p_term("t_vb", T_VB)
3005 p_term("t_ve", T_VE)
3006 p_term("t_vi", T_VI)
3007 p_term("t_vs", T_VS)
3008 p_term("t_WP", T_CWP)
3009 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003010 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_xs", T_XS)
3012 p_term("t_ZH", T_CZH)
3013 p_term("t_ZR", T_CZR)
3014
3015/* terminal key codes are not in here */
3016
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003017 /* end marker */
3018 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019};
3020
3021#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3022
3023#ifdef FEAT_MBYTE
3024static char *(p_ambw_values[]) = {"single", "double", NULL};
3025#endif
3026static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003027static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003029#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003030static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003031#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003032#ifdef FEAT_CMDL_COMPL
3033static char *(p_wop_values[]) = {"tagfile", NULL};
3034#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035#ifdef FEAT_WAK
3036static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3037#endif
3038static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3040static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042#ifdef FEAT_BROWSE
3043static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3044#endif
3045#ifdef FEAT_SCROLLBIND
3046static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3047#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003048static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003049#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3051#endif
3052#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003053# ifdef FEAT_AUTOCMD
3054static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3055# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003057# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3059#endif
3060static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3061#ifdef FEAT_FOLDING
3062static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003063# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003065# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 NULL};
3067static char *(p_fcl_values[]) = {"all", NULL};
3068#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003069#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003070static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003073static void set_option_default(int, int opt_flags, int compatible);
3074static void set_options_default(int opt_flags);
3075static char_u *term_bg_default(void);
3076static void did_set_option(int opt_idx, int opt_flags, int new_value);
3077static char_u *illegal_char(char_u *, int);
3078static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003080static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081#endif
3082#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003083static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003085static char_u *option_expand(int opt_idx, char_u *val);
3086static void didset_options(void);
3087static void didset_options2(void);
3088static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003089#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003090static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003091#else
3092# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3093#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003094static void set_string_option_global(int opt_idx, char_u **varp);
3095static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3096static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3097static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003098#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003099static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003102static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003104#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003105static char_u *did_set_spell_option(int is_spellfile);
3106static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003108#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003109static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003110#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003111static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3112static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3113static void check_redraw(long_u flags);
3114static int findoption(char_u *);
3115static int find_key_option(char_u *);
3116static void showoptions(int all, int opt_flags);
3117static int optval_default(struct vimoption *, char_u *varp);
3118static void showoneopt(struct vimoption *, int opt_flags);
3119static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3120static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3121static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3122static int istermoption(struct vimoption *);
3123static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3124static char_u *get_varp(struct vimoption *);
3125static void option_value2string(struct vimoption *, int opt_flags);
3126static void check_winopt(winopt_T *wop);
3127static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003129static void langmap_init(void);
3130static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003132static void paste_option_changed(void);
3133static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003135static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003137static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3138static int check_opt_strings(char_u *val, char **values, int);
3139static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003140#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003141static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143
3144/*
3145 * Initialize the options, first part.
3146 *
3147 * Called only once from main(), just after creating the first buffer.
3148 */
3149 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003150set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151{
3152 char_u *p;
3153 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003154 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155
3156#ifdef FEAT_LANGMAP
3157 langmap_init();
3158#endif
3159
3160 /* Be Vi compatible by default */
3161 p_cp = TRUE;
3162
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003163 /* Use POSIX compatibility when $VIM_POSIX is set. */
3164 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003165 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003166 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003167 set_string_default("shm", (char_u *)"A");
3168 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003169
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 /*
3171 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003172 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003174 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003175#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003177 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003179 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003181 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182# endif
3183#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003184 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 set_string_default("sh", p);
3186
3187#ifdef FEAT_WILDIGN
3188 /*
3189 * Set the default for 'backupskip' to include environment variables for
3190 * temp files.
3191 */
3192 {
3193# ifdef UNIX
3194 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3195# else
3196 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3197# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003198 int len;
3199 garray_T ga;
3200 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201
3202 ga_init2(&ga, 1, 100);
3203 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3204 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003205 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206# ifdef UNIX
3207 if (*names[n] == NUL)
3208 p = (char_u *)"/tmp";
3209 else
3210# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003211 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 if (p != NULL && *p != NUL)
3213 {
3214 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003215 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 if (ga_grow(&ga, len) == OK)
3217 {
3218 if (ga.ga_len > 0)
3219 STRCAT(ga.ga_data, ",");
3220 STRCAT(ga.ga_data, p);
3221 add_pathsep(ga.ga_data);
3222 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 ga.ga_len += len;
3224 }
3225 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003226 if (mustfree)
3227 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 }
3229 if (ga.ga_data != NULL)
3230 {
3231 set_string_default("bsk", ga.ga_data);
3232 vim_free(ga.ga_data);
3233 }
3234 }
3235#endif
3236
3237 /*
3238 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3239 */
3240 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003241 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003243#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3244 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3245#endif
3246 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003248 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003249 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250#else
3251# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003252 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003253 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003255 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256# endif
3257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 opt_idx = findoption((char_u *)"maxmem");
3260 if (opt_idx >= 0)
3261 {
3262#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003263 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3264 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003265#endif
3266 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3267 }
3268 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269 }
3270
3271#ifdef FEAT_GUI_W32
3272 /* force 'shortname' for Win32s */
3273 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003274 {
3275 opt_idx = findoption((char_u *)"shortname");
3276 if (opt_idx >= 0)
3277 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3278 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279#endif
3280
3281#ifdef FEAT_SEARCHPATH
3282 {
3283 char_u *cdpath;
3284 char_u *buf;
3285 int i;
3286 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003287 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288
3289 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003290 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291 if (cdpath != NULL)
3292 {
3293 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3294 if (buf != NULL)
3295 {
3296 buf[0] = ','; /* start with ",", current dir first */
3297 j = 1;
3298 for (i = 0; cdpath[i] != NUL; ++i)
3299 {
3300 if (vim_ispathlistsep(cdpath[i]))
3301 buf[j++] = ',';
3302 else
3303 {
3304 if (cdpath[i] == ' ' || cdpath[i] == ',')
3305 buf[j++] = '\\';
3306 buf[j++] = cdpath[i];
3307 }
3308 }
3309 buf[j] = NUL;
3310 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003311 if (opt_idx >= 0)
3312 {
3313 options[opt_idx].def_val[VI_DEFAULT] = buf;
3314 options[opt_idx].flags |= P_DEF_ALLOCED;
3315 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003316 else
3317 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003319 if (mustfree)
3320 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321 }
3322 }
3323#endif
3324
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003325#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326 /* Set print encoding on platforms that don't default to latin1 */
3327 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003328# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329 (char_u *)"cp1252"
3330# else
3331# ifdef VMS
3332 (char_u *)"dec-mcs"
3333# else
3334# ifdef EBCDIC
3335 (char_u *)"ebcdic-uk"
3336# else
3337# ifdef MAC
3338 (char_u *)"mac-roman"
3339# else /* HPUX */
3340 (char_u *)"hp-roman8"
3341# endif
3342# endif
3343# endif
3344# endif
3345 );
3346#endif
3347
3348#ifdef FEAT_POSTSCRIPT
3349 /* 'printexpr' must be allocated to be able to evaluate it. */
3350 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003351# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003352 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353# else
3354# ifdef VMS
3355 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3356
3357# else
3358 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3359# endif
3360# endif
3361 );
3362#endif
3363
3364 /*
3365 * Set all the options (except the terminal options) to their default
3366 * value. Also set the global value for local options.
3367 */
3368 set_options_default(0);
3369
3370#ifdef FEAT_GUI
3371 if (found_reverse_arg)
3372 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3373#endif
3374
3375 curbuf->b_p_initialized = TRUE;
3376 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003377 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 check_buf_options(curbuf);
3379 check_win_options(curwin);
3380 check_options();
3381
3382 /* Must be before option_expand(), because that one needs vim_isIDc() */
3383 didset_options();
3384
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003385#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003386 /* Use the current chartab for the generic chartab. This is not in
3387 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003388 init_spell_chartab();
3389#endif
3390
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391 /*
3392 * Expand environment variables and things like "~" for the defaults.
3393 * If option_expand() returns non-NULL the variable is expanded. This can
3394 * only happen for non-indirect options.
3395 * Also set the default to the expanded value, so ":set" does not list
3396 * them.
3397 * Don't set the P_ALLOCED flag, because we don't want to free the
3398 * default.
3399 */
3400 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3401 {
3402 if ((options[opt_idx].flags & P_GETTEXT)
3403 && options[opt_idx].var != NULL)
3404 p = (char_u *)_(*(char **)options[opt_idx].var);
3405 else
3406 p = option_expand(opt_idx, NULL);
3407 if (p != NULL && (p = vim_strsave(p)) != NULL)
3408 {
3409 *(char_u **)options[opt_idx].var = p;
3410 /* VIMEXP
3411 * Defaults for all expanded options are currently the same for Vi
3412 * and Vim. When this changes, add some code here! Also need to
3413 * split P_DEF_ALLOCED in two.
3414 */
3415 if (options[opt_idx].flags & P_DEF_ALLOCED)
3416 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3417 options[opt_idx].def_val[VI_DEFAULT] = p;
3418 options[opt_idx].flags |= P_DEF_ALLOCED;
3419 }
3420 }
3421
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422 save_file_ff(curbuf); /* Buffer is unchanged */
3423
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424#if defined(FEAT_ARABIC)
3425 /* Detect use of mlterm.
3426 * Mlterm is a terminal emulator akin to xterm that has some special
3427 * abilities (bidi namely).
3428 * NOTE: mlterm's author is being asked to 'set' a variable
3429 * instead of an environment variable due to inheritance.
3430 */
3431 if (mch_getenv((char_u *)"MLTERM") != NULL)
3432 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3433#endif
3434
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003435 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436
3437#ifdef FEAT_MBYTE
3438# if defined(WIN3264) && defined(FEAT_GETTEXT)
3439 /*
3440 * If $LANG isn't set, try to get a good value for it. This makes the
3441 * right language be used automatically. Don't do this for English.
3442 */
3443 if (mch_getenv((char_u *)"LANG") == NULL)
3444 {
3445 char buf[20];
3446
3447 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3448 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3449 * only the first two. */
3450 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3451 (LPTSTR)buf, 20);
3452 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3453 {
3454 /* There are a few exceptions (probably more) */
3455 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3456 STRCPY(buf, "zh_TW");
3457 else if (STRNICMP(buf, "chs", 3) == 0
3458 || STRNICMP(buf, "zhc", 3) == 0)
3459 STRCPY(buf, "zh_CN");
3460 else if (STRNICMP(buf, "jp", 2) == 0)
3461 STRCPY(buf, "ja");
3462 else
3463 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003464 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003465 }
3466 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003467# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003468# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003469 /* Moved to os_mac_conv.c to avoid dependency problems. */
3470 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003471# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472# endif
3473
3474 /* enc_locale() will try to find the encoding of the current locale. */
3475 p = enc_locale();
3476 if (p != NULL)
3477 {
3478 char_u *save_enc;
3479
3480 /* Try setting 'encoding' and check if the value is valid.
3481 * If not, go back to the default "latin1". */
3482 save_enc = p_enc;
3483 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003484 if (STRCMP(p_enc, "gb18030") == 0)
3485 {
3486 /* We don't support "gb18030", but "cp936" is a good substitute
3487 * for practical purposes, thus use that. It's not an alias to
3488 * still support conversion between gb18030 and utf-8. */
3489 p_enc = vim_strsave((char_u *)"cp936");
3490 vim_free(p);
3491 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003492 if (mb_init() == NULL)
3493 {
3494 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003495 if (opt_idx >= 0)
3496 {
3497 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3498 options[opt_idx].flags |= P_DEF_ALLOCED;
3499 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003501#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003502 if (STRCMP(p_enc, "latin1") == 0
3503# ifdef FEAT_MBYTE
3504 || enc_utf8
3505# endif
3506 )
3507 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003508 /* Adjust the default for 'isprint' and 'iskeyword' to match
3509 * latin1. Also set the defaults for when 'nocompatible' is
3510 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003511 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003512 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003513 set_string_option_direct((char_u *)"isk", -1,
3514 ISK_LATIN1, OPT_FREE, SID_NONE);
3515 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003516 if (opt_idx >= 0)
3517 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003518 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003519 if (opt_idx >= 0)
3520 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003521 (void)init_chartab();
3522 }
3523#endif
3524
Bram Moolenaar071d4272004-06-13 20:20:40 +00003525# if defined(WIN3264) && !defined(FEAT_GUI)
3526 /* Win32 console: When GetACP() returns a different value from
3527 * GetConsoleCP() set 'termencoding'. */
3528 if (GetACP() != GetConsoleCP())
3529 {
3530 char buf[50];
3531
3532 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3533 p_tenc = vim_strsave((char_u *)buf);
3534 if (p_tenc != NULL)
3535 {
3536 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003537 if (opt_idx >= 0)
3538 {
3539 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3540 options[opt_idx].flags |= P_DEF_ALLOCED;
3541 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542 convert_setup(&input_conv, p_tenc, p_enc);
3543 convert_setup(&output_conv, p_enc, p_tenc);
3544 }
3545 else
3546 p_tenc = empty_option;
3547 }
3548# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003549# if defined(WIN3264) && defined(FEAT_MBYTE)
3550 /* $HOME may have characters in active code page. */
3551 init_homedir();
3552# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 }
3554 else
3555 {
3556 vim_free(p_enc);
3557 p_enc = save_enc;
3558 }
3559 }
3560#endif
3561
3562#ifdef FEAT_MULTI_LANG
3563 /* Set the default for 'helplang'. */
3564 set_helplang_default(get_mess_lang());
3565#endif
3566}
3567
3568/*
3569 * Set an option to its default value.
3570 * This does not take care of side effects!
3571 */
3572 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003573set_option_default(
3574 int opt_idx,
3575 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3576 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003577{
3578 char_u *varp; /* pointer to variable for current option */
3579 int dvi; /* index in def_val[] */
3580 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003581 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3583
3584 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3585 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003586 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587 {
3588 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3589 if (flags & P_STRING)
3590 {
3591 /* Use set_string_option_direct() for local options to handle
3592 * freeing and allocating the value. */
3593 if (options[opt_idx].indir != PV_NONE)
3594 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003595 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 else
3597 {
3598 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3599 free_string_option(*(char_u **)(varp));
3600 *(char_u **)varp = options[opt_idx].def_val[dvi];
3601 options[opt_idx].flags &= ~P_ALLOCED;
3602 }
3603 }
3604 else if (flags & P_NUM)
3605 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003606 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607 win_comp_scroll(curwin);
3608 else
3609 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003610 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611 /* May also set global value for local option. */
3612 if (both)
3613 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3614 *(long *)varp;
3615 }
3616 }
3617 else /* P_BOOL */
3618 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003619 /* the cast to long is required for Manx C, long_i is needed for
3620 * MSVC */
3621 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003622#ifdef UNIX
3623 /* 'modeline' defaults to off for root */
3624 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3625 *(int *)varp = FALSE;
3626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 /* May also set global value for local option. */
3628 if (both)
3629 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3630 *(int *)varp;
3631 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003632
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003633 /* The default value is not insecure. */
3634 flagsp = insecure_flag(opt_idx, opt_flags);
3635 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 }
3637
3638#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003639 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640#endif
3641}
3642
3643/*
3644 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003645 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 */
3647 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003648set_options_default(
3649 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650{
3651 int i;
3652#ifdef FEAT_WINDOWS
3653 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003654 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655#endif
3656
3657 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003658 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003659#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003660 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003661 || (TRUE
3662# if defined(FEAT_MBYTE)
3663 && options[i].var != (char_u *)&p_enc
3664# endif
3665# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003666 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003667 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003668# endif
3669 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003670#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003671 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003672 set_option_default(i, opt_flags, p_cp);
3673
3674#ifdef FEAT_WINDOWS
3675 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003676 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677 win_comp_scroll(wp);
3678#else
3679 win_comp_scroll(curwin);
3680#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003681#ifdef FEAT_CINDENT
3682 parse_cino(curbuf);
3683#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684}
3685
3686/*
3687 * Set the Vi-default value of a string option.
3688 * Used for 'sh', 'backupskip' and 'term'.
3689 */
3690 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003691set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692{
3693 char_u *p;
3694 int opt_idx;
3695
3696 p = vim_strsave(val);
3697 if (p != NULL) /* we don't want a NULL */
3698 {
3699 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003700 if (opt_idx >= 0)
3701 {
3702 if (options[opt_idx].flags & P_DEF_ALLOCED)
3703 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3704 options[opt_idx].def_val[VI_DEFAULT] = p;
3705 options[opt_idx].flags |= P_DEF_ALLOCED;
3706 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707 }
3708}
3709
3710/*
3711 * Set the Vi-default value of a number option.
3712 * Used for 'lines' and 'columns'.
3713 */
3714 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003715set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003717 int opt_idx;
3718
3719 opt_idx = findoption((char_u *)name);
3720 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003721 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722}
3723
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003724#if defined(EXITFREE) || defined(PROTO)
3725/*
3726 * Free all options.
3727 */
3728 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003729free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003730{
3731 int i;
3732
3733 for (i = 0; !istermoption(&options[i]); i++)
3734 {
3735 if (options[i].indir == PV_NONE)
3736 {
3737 /* global option: free value and default value. */
3738 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3739 free_string_option(*(char_u **)options[i].var);
3740 if (options[i].flags & P_DEF_ALLOCED)
3741 free_string_option(options[i].def_val[VI_DEFAULT]);
3742 }
3743 else if (options[i].var != VAR_WIN
3744 && (options[i].flags & P_STRING))
3745 /* buffer-local option: free global value */
3746 free_string_option(*(char_u **)options[i].var);
3747 }
3748}
3749#endif
3750
3751
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752/*
3753 * Initialize the options, part two: After getting Rows and Columns and
3754 * setting 'term'.
3755 */
3756 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003757set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003759 int idx;
3760
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 /*
3762 * 'scroll' defaults to half the window height. Note that this default is
3763 * wrong when the window height changes.
3764 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003765 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003766 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003767 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003768 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 comp_col();
3770
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003771 /*
3772 * 'window' is only for backwards compatibility with Vi.
3773 * Default is Rows - 1.
3774 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003775 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003776 p_window = Rows - 1;
3777 set_number_default("window", Rows - 1);
3778
Bram Moolenaarf740b292006-02-16 22:11:02 +00003779 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003780#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003781 /*
3782 * If 'background' wasn't set by the user, try guessing the value,
3783 * depending on the terminal name. Only need to check for terminals
3784 * with a dark background, that can handle color.
3785 */
3786 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003787 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3788 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003790 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003791 /* don't mark it as set, when starting the GUI it may be
3792 * changed again */
3793 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 }
3795#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003796
3797#ifdef CURSOR_SHAPE
3798 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3799#endif
3800#ifdef FEAT_MOUSESHAPE
3801 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3802#endif
3803#ifdef FEAT_PRINTER
3804 (void)parse_printoptions(); /* parse 'printoptions' default value */
3805#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806}
3807
3808/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003809 * Return "dark" or "light" depending on the kind of terminal.
3810 * This is just guessing! Recognized are:
3811 * "linux" Linux console
3812 * "screen.linux" Linux console with screen
3813 * "cygwin" Cygwin shell
3814 * "putty" Putty program
3815 * We also check the COLORFGBG environment variable, which is set by
3816 * rxvt and derivatives. This variable contains either two or three
3817 * values separated by semicolons; we want the last value in either
3818 * case. If this value is 0-6 or 8, our background is dark.
3819 */
3820 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003821term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003822{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003823#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003824 /* DOS console nearly always black */
3825 return (char_u *)"dark";
3826#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003827 char_u *p;
3828
Bram Moolenaarf740b292006-02-16 22:11:02 +00003829 if (STRCMP(T_NAME, "linux") == 0
3830 || STRCMP(T_NAME, "screen.linux") == 0
3831 || STRCMP(T_NAME, "cygwin") == 0
3832 || STRCMP(T_NAME, "putty") == 0
3833 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3834 && (p = vim_strrchr(p, ';')) != NULL
3835 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3836 && p[2] == NUL))
3837 return (char_u *)"dark";
3838 return (char_u *)"light";
3839#endif
3840}
3841
3842/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843 * Initialize the options, part three: After reading the .vimrc
3844 */
3845 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003846set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003848#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003849/*
3850 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3851 * This is done after other initializations, where 'shell' might have been
3852 * set, but only if they have not been set before.
3853 */
3854 char_u *p;
3855 int idx_srr;
3856 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003857# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 int idx_sp;
3859 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003860# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861
3862 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003863 if (idx_srr < 0)
3864 do_srr = FALSE;
3865 else
3866 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003867# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003869 if (idx_sp < 0)
3870 do_sp = FALSE;
3871 else
3872 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003873# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003874 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 if (p != NULL)
3876 {
3877 /*
3878 * Default for p_sp is "| tee", for p_srr is ">".
3879 * For known shells it is changed here to include stderr.
3880 */
3881 if ( fnamecmp(p, "csh") == 0
3882 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003883# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 || fnamecmp(p, "csh.exe") == 0
3885 || fnamecmp(p, "tcsh.exe") == 0
3886# endif
3887 )
3888 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003889# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890 if (do_sp)
3891 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003892# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003894# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003896# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3898 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003899# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900 if (do_srr)
3901 {
3902 p_srr = (char_u *)">&";
3903 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3904 }
3905 }
3906 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003907 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 if ( fnamecmp(p, "sh") == 0
3909 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003910 || fnamecmp(p, "mksh") == 0
3911 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003913 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003915 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003916# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 || fnamecmp(p, "cmd") == 0
3918 || fnamecmp(p, "sh.exe") == 0
3919 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003920 || fnamecmp(p, "mksh.exe") == 0
3921 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003923 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 || fnamecmp(p, "bash.exe") == 0
3925 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003927 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003929# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 if (do_sp)
3931 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003932# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003934# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3938 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003939# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 if (do_srr)
3941 {
3942 p_srr = (char_u *)">%s 2>&1";
3943 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3944 }
3945 }
3946 vim_free(p);
3947 }
3948#endif
3949
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003950#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003952 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3953 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 * This is done after other initializations, where 'shell' might have been
3955 * set, but only if they have not been set before. Default for p_shcf is
3956 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003957 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003959 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960 {
3961 int idx3;
3962
3963 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003964 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965 {
3966 p_shcf = (char_u *)"-c";
3967 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3968 }
3969
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003970# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 /* Somehow Win32 requires the quotes around the redirection too */
3972 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003973 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 {
3975 p_sxq = (char_u *)"\"";
3976 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3977 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003978# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003980 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 {
3982 p_shq = (char_u *)"\"";
3983 options[idx3].def_val[VI_DEFAULT] = p_shq;
3984 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985# endif
3986 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003987 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3988 {
3989 int idx3;
3990
3991 /*
3992 * cmd.exe on Windows will strip the first and last double quote given
3993 * on the command line, e.g. most of the time things like:
3994 * cmd /c "my path/to/echo" "my args to echo"
3995 * become:
3996 * my path/to/echo" "my args to echo
3997 * when executed.
3998 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003999 * To avoid this, set shellxquote to surround the command in
4000 * parenthesis. This appears to make most commands work, without
4001 * breaking commands that worked previously, such as
4002 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004003 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004004 idx3 = findoption((char_u *)"sxq");
4005 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4006 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004007 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004008 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4009 }
4010
Bram Moolenaara64ba222012-02-12 23:23:31 +01004011 idx3 = findoption((char_u *)"shcf");
4012 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4013 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004014 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004015 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4016 }
4017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018#endif
4019
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004020 if (bufempty())
4021 {
4022 int idx_ffs = findoption((char_u *)"ffs");
4023
4024 /* Apply the first entry of 'fileformats' to the initial buffer. */
4025 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4026 set_fileformat(default_fileformat(), OPT_LOCAL);
4027 }
4028
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029#ifdef FEAT_TITLE
4030 set_title_defaults();
4031#endif
4032}
4033
4034#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4035/*
4036 * When 'helplang' is still at its default value, set it to "lang".
4037 * Only the first two characters of "lang" are used.
4038 */
4039 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004040set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041{
4042 int idx;
4043
4044 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4045 return;
4046 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004047 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048 {
4049 if (options[idx].flags & P_ALLOCED)
4050 free_string_option(p_hlg);
4051 p_hlg = vim_strsave(lang);
4052 if (p_hlg == NULL)
4053 p_hlg = empty_option;
4054 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004055 {
4056 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4057 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4058 {
4059 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4060 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4061 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004063 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 options[idx].flags |= P_ALLOCED;
4065 }
4066}
4067#endif
4068
4069#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004070static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071
4072 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004073gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074{
4075 if (gui_get_lightness(gui.back_pixel) < 127)
4076 return (char_u *)"dark";
4077 return (char_u *)"light";
4078}
4079
4080/*
4081 * Option initializations that can only be done after opening the GUI window.
4082 */
4083 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004084init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085{
4086 /* Set the 'background' option according to the lightness of the
4087 * background color, unless the user has set it already. */
4088 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4089 {
4090 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4091 highlight_changed();
4092 }
4093}
4094#endif
4095
4096#ifdef FEAT_TITLE
4097/*
4098 * 'title' and 'icon' only default to true if they have not been set or reset
4099 * in .vimrc and we can read the old value.
4100 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4101 * they can be reset. This reduces startup time when using X on a remote
4102 * machine.
4103 */
4104 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004105set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106{
4107 int idx1;
4108 long val;
4109
4110 /*
4111 * If GUI is (going to be) used, we can always set the window title and
4112 * icon name. Saves a bit of time, because the X11 display server does
4113 * not need to be contacted.
4114 */
4115 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004116 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 {
4118#ifdef FEAT_GUI
4119 if (gui.starting || gui.in_use)
4120 val = TRUE;
4121 else
4122#endif
4123 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004124 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 p_title = val;
4126 }
4127 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004128 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 {
4130#ifdef FEAT_GUI
4131 if (gui.starting || gui.in_use)
4132 val = TRUE;
4133 else
4134#endif
4135 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004136 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 p_icon = val;
4138 }
4139}
4140#endif
4141
4142/*
4143 * Parse 'arg' for option settings.
4144 *
4145 * 'arg' may be IObuff, but only when no errors can be present and option
4146 * does not need to be expanded with option_expand().
4147 * "opt_flags":
4148 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004149 * OPT_GLOBAL for ":setglobal"
4150 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004152 * OPT_WINONLY to only set window-local options
4153 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 *
4155 * returns FAIL if an error is detected, OK otherwise
4156 */
4157 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004158do_set(
4159 char_u *arg, /* option string (may be written to!) */
4160 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161{
4162 int opt_idx;
4163 char_u *errmsg;
4164 char_u errbuf[80];
4165 char_u *startarg;
4166 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4167 int nextchar; /* next non-white char after option name */
4168 int afterchar; /* character just after option name */
4169 int len;
4170 int i;
4171 long value;
4172 int key;
4173 long_u flags; /* flags for current option */
4174 char_u *varp = NULL; /* pointer to variable for current option */
4175 int did_show = FALSE; /* already showed one value */
4176 int adding; /* "opt+=arg" */
4177 int prepending; /* "opt^=arg" */
4178 int removing; /* "opt-=arg" */
4179 int cp_val = 0;
4180 char_u key_name[2];
4181
4182 if (*arg == NUL)
4183 {
4184 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004185 did_show = TRUE;
4186 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 }
4188
4189 while (*arg != NUL) /* loop to process all options */
4190 {
4191 errmsg = NULL;
4192 startarg = arg; /* remember for error message */
4193
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004194 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4195 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004196 {
4197 /*
4198 * ":set all" show all options.
4199 * ":set all&" set all options to their default value.
4200 */
4201 arg += 3;
4202 if (*arg == '&')
4203 {
4204 ++arg;
4205 /* Only for :set command set global value of local options. */
4206 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004207 didset_options();
4208 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004209 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210 }
4211 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004212 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004213 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004214 did_show = TRUE;
4215 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004216 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004217 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004218 {
4219 showoptions(2, opt_flags);
4220 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004221 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 arg += 7;
4223 }
4224 else
4225 {
4226 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004227 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004228 {
4229 prefix = 0;
4230 arg += 2;
4231 }
4232 else if (STRNCMP(arg, "inv", 3) == 0)
4233 {
4234 prefix = 2;
4235 arg += 3;
4236 }
4237
4238 /* find end of name */
4239 key = 0;
4240 if (*arg == '<')
4241 {
4242 nextchar = 0;
4243 opt_idx = -1;
4244 /* look out for <t_>;> */
4245 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4246 len = 5;
4247 else
4248 {
4249 len = 1;
4250 while (arg[len] != NUL && arg[len] != '>')
4251 ++len;
4252 }
4253 if (arg[len] != '>')
4254 {
4255 errmsg = e_invarg;
4256 goto skip;
4257 }
4258 arg[len] = NUL; /* put NUL after name */
4259 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4260 opt_idx = findoption(arg + 1);
4261 arg[len++] = '>'; /* restore '>' */
4262 if (opt_idx == -1)
4263 key = find_key_option(arg + 1);
4264 }
4265 else
4266 {
4267 len = 0;
4268 /*
4269 * The two characters after "t_" may not be alphanumeric.
4270 */
4271 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4272 len = 4;
4273 else
4274 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4275 ++len;
4276 nextchar = arg[len];
4277 arg[len] = NUL; /* put NUL after name */
4278 opt_idx = findoption(arg);
4279 arg[len] = nextchar; /* restore nextchar */
4280 if (opt_idx == -1)
4281 key = find_key_option(arg);
4282 }
4283
4284 /* remember character after option name */
4285 afterchar = arg[len];
4286
4287 /* skip white space, allow ":set ai ?" */
4288 while (vim_iswhite(arg[len]))
4289 ++len;
4290
4291 adding = FALSE;
4292 prepending = FALSE;
4293 removing = FALSE;
4294 if (arg[len] != NUL && arg[len + 1] == '=')
4295 {
4296 if (arg[len] == '+')
4297 {
4298 adding = TRUE; /* "+=" */
4299 ++len;
4300 }
4301 else if (arg[len] == '^')
4302 {
4303 prepending = TRUE; /* "^=" */
4304 ++len;
4305 }
4306 else if (arg[len] == '-')
4307 {
4308 removing = TRUE; /* "-=" */
4309 ++len;
4310 }
4311 }
4312 nextchar = arg[len];
4313
4314 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4315 {
4316 errmsg = (char_u *)N_("E518: Unknown option");
4317 goto skip;
4318 }
4319
4320 if (opt_idx >= 0)
4321 {
4322 if (options[opt_idx].var == NULL) /* hidden option: skip */
4323 {
4324 /* Only give an error message when requesting the value of
4325 * a hidden option, ignore setting it. */
4326 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4327 && (!(options[opt_idx].flags & P_BOOL)
4328 || nextchar == '?'))
4329 errmsg = (char_u *)N_("E519: Option not supported");
4330 goto skip;
4331 }
4332
4333 flags = options[opt_idx].flags;
4334 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4335 }
4336 else
4337 {
4338 flags = P_STRING;
4339 if (key < 0)
4340 {
4341 key_name[0] = KEY2TERMCAP0(key);
4342 key_name[1] = KEY2TERMCAP1(key);
4343 }
4344 else
4345 {
4346 key_name[0] = KS_KEY;
4347 key_name[1] = (key & 0xff);
4348 }
4349 }
4350
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004351 /* Skip all options that are not window-local (used when showing
4352 * an already loaded buffer in a window). */
4353 if ((opt_flags & OPT_WINONLY)
4354 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4355 goto skip;
4356
Bram Moolenaara3227e22006-03-08 21:32:40 +00004357 /* Skip all options that are window-local (used for :vimgrep). */
4358 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4359 && options[opt_idx].var == VAR_WIN)
4360 goto skip;
4361
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004362 /* Disallow changing some options from modelines. */
4363 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004364 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004365 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004366 {
4367 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4368 goto skip;
4369 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004370#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004371 /* In diff mode some options are overruled. This avoids that
4372 * 'foldmethod' becomes "marker" instead of "diff" and that
4373 * "wrap" gets set. */
4374 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004375 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004376 && (options[opt_idx].indir == PV_FDM
4377 || options[opt_idx].indir == PV_WRAP))
4378 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004380 }
4381
4382#ifdef HAVE_SANDBOX
4383 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004384 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 {
4386 errmsg = (char_u *)_(e_sandbox);
4387 goto skip;
4388 }
4389#endif
4390
4391 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4392 {
4393 arg += len;
4394 cp_val = p_cp;
4395 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4396 {
4397 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4398 {
4399 cp_val = FALSE;
4400 arg += 3;
4401 }
4402 else /* "opt&vi": set to Vi default */
4403 {
4404 cp_val = TRUE;
4405 arg += 2;
4406 }
4407 }
4408 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4409 && arg[1] != NUL && !vim_iswhite(arg[1]))
4410 {
4411 errmsg = e_trailing;
4412 goto skip;
4413 }
4414 }
4415
4416 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004417 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4418 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004419 */
4420 if (nextchar == '?'
4421 || (prefix == 1
4422 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4423 && !(flags & P_BOOL)))
4424 {
4425 /*
4426 * print value
4427 */
4428 if (did_show)
4429 msg_putchar('\n'); /* cursor below last one */
4430 else
4431 {
4432 gotocmdline(TRUE); /* cursor at status line */
4433 did_show = TRUE; /* remember that we did a line */
4434 }
4435 if (opt_idx >= 0)
4436 {
4437 showoneopt(&options[opt_idx], opt_flags);
4438#ifdef FEAT_EVAL
4439 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004440 {
4441 /* Mention where the option was last set. */
4442 if (varp == options[opt_idx].var)
4443 last_set_msg(options[opt_idx].scriptID);
4444 else if ((int)options[opt_idx].indir & PV_WIN)
4445 last_set_msg(curwin->w_p_scriptID[
4446 (int)options[opt_idx].indir & PV_MASK]);
4447 else if ((int)options[opt_idx].indir & PV_BUF)
4448 last_set_msg(curbuf->b_p_scriptID[
4449 (int)options[opt_idx].indir & PV_MASK]);
4450 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004451#endif
4452 }
4453 else
4454 {
4455 char_u *p;
4456
4457 p = find_termcode(key_name);
4458 if (p == NULL)
4459 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004460 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004461 goto skip;
4462 }
4463 else
4464 (void)show_one_termcode(key_name, p, TRUE);
4465 }
4466 if (nextchar != '?'
4467 && nextchar != NUL && !vim_iswhite(afterchar))
4468 errmsg = e_trailing;
4469 }
4470 else
4471 {
4472 if (flags & P_BOOL) /* boolean */
4473 {
4474 if (nextchar == '=' || nextchar == ':')
4475 {
4476 errmsg = e_invarg;
4477 goto skip;
4478 }
4479
4480 /*
4481 * ":set opt!": invert
4482 * ":set opt&": reset to default value
4483 * ":set opt<": reset to global value
4484 */
4485 if (nextchar == '!')
4486 value = *(int *)(varp) ^ 1;
4487 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004488 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004489 ((flags & P_VI_DEF) || cp_val)
4490 ? VI_DEFAULT : VIM_DEFAULT];
4491 else if (nextchar == '<')
4492 {
4493 /* For 'autoread' -1 means to use global value. */
4494 if ((int *)varp == &curbuf->b_p_ar
4495 && opt_flags == OPT_LOCAL)
4496 value = -1;
4497 else
4498 value = *(int *)get_varp_scope(&(options[opt_idx]),
4499 OPT_GLOBAL);
4500 }
4501 else
4502 {
4503 /*
4504 * ":set invopt": invert
4505 * ":set opt" or ":set noopt": set or reset
4506 */
4507 if (nextchar != NUL && !vim_iswhite(afterchar))
4508 {
4509 errmsg = e_trailing;
4510 goto skip;
4511 }
4512 if (prefix == 2) /* inv */
4513 value = *(int *)(varp) ^ 1;
4514 else
4515 value = prefix;
4516 }
4517
4518 errmsg = set_bool_option(opt_idx, varp, (int)value,
4519 opt_flags);
4520 }
4521 else /* numeric or string */
4522 {
4523 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4524 || prefix != 1)
4525 {
4526 errmsg = e_invarg;
4527 goto skip;
4528 }
4529
4530 if (flags & P_NUM) /* numeric */
4531 {
4532 /*
4533 * Different ways to set a number option:
4534 * & set to default value
4535 * < set to global value
4536 * <xx> accept special key codes for 'wildchar'
4537 * c accept any non-digit for 'wildchar'
4538 * [-]0-9 set number
4539 * other error
4540 */
4541 ++arg;
4542 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004543 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004544 ((flags & P_VI_DEF) || cp_val)
4545 ? VI_DEFAULT : VIM_DEFAULT];
4546 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004547 {
4548 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4549 * use the global value. */
4550 if ((long *)varp == &curbuf->b_p_ul
4551 && opt_flags == OPT_LOCAL)
4552 value = NO_LOCAL_UNDOLEVEL;
4553 else
4554 value = *(long *)get_varp_scope(
4555 &(options[opt_idx]), OPT_GLOBAL);
4556 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004557 else if (((long *)varp == &p_wc
4558 || (long *)varp == &p_wcm)
4559 && (*arg == '<'
4560 || *arg == '^'
4561 || ((!arg[1] || vim_iswhite(arg[1]))
4562 && !VIM_ISDIGIT(*arg))))
4563 {
4564 value = string_to_key(arg);
4565 if (value == 0 && (long *)varp != &p_wcm)
4566 {
4567 errmsg = e_invarg;
4568 goto skip;
4569 }
4570 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004571 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4572 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004573 /* Allow negative (for 'undolevels'), octal and
4574 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004575 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4576 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004577 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4578 {
4579 errmsg = e_invarg;
4580 goto skip;
4581 }
4582 }
4583 else
4584 {
4585 errmsg = (char_u *)N_("E521: Number required after =");
4586 goto skip;
4587 }
4588
4589 if (adding)
4590 value = *(long *)varp + value;
4591 if (prepending)
4592 value = *(long *)varp * value;
4593 if (removing)
4594 value = *(long *)varp - value;
4595 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004596 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004597 }
4598 else if (opt_idx >= 0) /* string */
4599 {
4600 char_u *save_arg = NULL;
4601 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004602 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004603 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004604 char_u *origval = NULL;
4605#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4606 char_u *saved_origval = NULL;
4607#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004608 unsigned newlen;
4609 int comma;
4610 int bs;
4611 int new_value_alloced; /* new string option
4612 was allocated */
4613
4614 /* When using ":set opt=val" for a global option
4615 * with a local value the local value will be
4616 * reset, use the global value here. */
4617 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004618 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004619 varp = options[opt_idx].var;
4620
4621 /* The old value is kept until we are sure that the
4622 * new value is valid. */
4623 oldval = *(char_u **)varp;
4624 if (nextchar == '&') /* set to default val */
4625 {
4626 newval = options[opt_idx].def_val[
4627 ((flags & P_VI_DEF) || cp_val)
4628 ? VI_DEFAULT : VIM_DEFAULT];
4629 if ((char_u **)varp == &p_bg)
4630 {
4631 /* guess the value of 'background' */
4632#ifdef FEAT_GUI
4633 if (gui.in_use)
4634 newval = gui_bg_default();
4635 else
4636#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004637 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004638 }
4639
4640 /* expand environment variables and ~ (since the
4641 * default value was already expanded, only
4642 * required when an environment variable was set
4643 * later */
4644 if (newval == NULL)
4645 newval = empty_option;
4646 else
4647 {
4648 s = option_expand(opt_idx, newval);
4649 if (s == NULL)
4650 s = newval;
4651 newval = vim_strsave(s);
4652 }
4653 new_value_alloced = TRUE;
4654 }
4655 else if (nextchar == '<') /* set to global val */
4656 {
4657 newval = vim_strsave(*(char_u **)get_varp_scope(
4658 &(options[opt_idx]), OPT_GLOBAL));
4659 new_value_alloced = TRUE;
4660 }
4661 else
4662 {
4663 ++arg; /* jump to after the '=' or ':' */
4664
4665 /*
4666 * Set 'keywordprg' to ":help" if an empty
4667 * value was passed to :set by the user.
4668 * Misuse errbuf[] for the resulting string.
4669 */
4670 if (varp == (char_u *)&p_kp
4671 && (*arg == NUL || *arg == ' '))
4672 {
4673 STRCPY(errbuf, ":help");
4674 save_arg = arg;
4675 arg = errbuf;
4676 }
4677 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004678 * Convert 'backspace' number to string, for
4679 * adding, prepending and removing string.
4680 */
4681 else if (varp == (char_u *)&p_bs
4682 && VIM_ISDIGIT(**(char_u **)varp))
4683 {
4684 i = getdigits((char_u **)varp);
4685 switch (i)
4686 {
4687 case 0:
4688 *(char_u **)varp = empty_option;
4689 break;
4690 case 1:
4691 *(char_u **)varp = vim_strsave(
4692 (char_u *)"indent,eol");
4693 break;
4694 case 2:
4695 *(char_u **)varp = vim_strsave(
4696 (char_u *)"indent,eol,start");
4697 break;
4698 }
4699 vim_free(oldval);
4700 oldval = *(char_u **)varp;
4701 }
4702 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004703 * Convert 'whichwrap' number to string, for
4704 * backwards compatibility with Vim 3.0.
4705 * Misuse errbuf[] for the resulting string.
4706 */
4707 else if (varp == (char_u *)&p_ww
4708 && VIM_ISDIGIT(*arg))
4709 {
4710 *errbuf = NUL;
4711 i = getdigits(&arg);
4712 if (i & 1)
4713 STRCAT(errbuf, "b,");
4714 if (i & 2)
4715 STRCAT(errbuf, "s,");
4716 if (i & 4)
4717 STRCAT(errbuf, "h,l,");
4718 if (i & 8)
4719 STRCAT(errbuf, "<,>,");
4720 if (i & 16)
4721 STRCAT(errbuf, "[,],");
4722 if (*errbuf != NUL) /* remove trailing , */
4723 errbuf[STRLEN(errbuf) - 1] = NUL;
4724 save_arg = arg;
4725 arg = errbuf;
4726 }
4727 /*
4728 * Remove '>' before 'dir' and 'bdir', for
4729 * backwards compatibility with version 3.0
4730 */
4731 else if ( *arg == '>'
4732 && (varp == (char_u *)&p_dir
4733 || varp == (char_u *)&p_bdir))
4734 {
4735 ++arg;
4736 }
4737
4738 /* When setting the local value of a global
4739 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004740 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004741 && (opt_flags & OPT_LOCAL))
4742 origval = *(char_u **)get_varp(
4743 &options[opt_idx]);
4744 else
4745 origval = oldval;
4746
4747 /*
4748 * Copy the new string into allocated memory.
4749 * Can't use set_string_option_direct(), because
4750 * we need to remove the backslashes.
4751 */
4752 /* get a bit too much */
4753 newlen = (unsigned)STRLEN(arg) + 1;
4754 if (adding || prepending || removing)
4755 newlen += (unsigned)STRLEN(origval) + 1;
4756 newval = alloc(newlen);
4757 if (newval == NULL) /* out of mem, don't change */
4758 break;
4759 s = newval;
4760
4761 /*
4762 * Copy the string, skip over escaped chars.
4763 * For MS-DOS and WIN32 backslashes before normal
4764 * file name characters are not removed, and keep
4765 * backslash at start, for "\\machine\path", but
4766 * do remove it for "\\\\machine\\path".
4767 * The reverse is found in ExpandOldSetting().
4768 */
4769 while (*arg && !vim_iswhite(*arg))
4770 {
4771 if (*arg == '\\' && arg[1] != NUL
4772#ifdef BACKSLASH_IN_FILENAME
4773 && !((flags & P_EXPAND)
4774 && vim_isfilec(arg[1])
4775 && (arg[1] != '\\'
4776 || (s == newval
4777 && arg[2] != '\\')))
4778#endif
4779 )
4780 ++arg; /* remove backslash */
4781#ifdef FEAT_MBYTE
4782 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004783 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004784 {
4785 /* copy multibyte char */
4786 mch_memmove(s, arg, (size_t)i);
4787 arg += i;
4788 s += i;
4789 }
4790 else
4791#endif
4792 *s++ = *arg++;
4793 }
4794 *s = NUL;
4795
4796 /*
4797 * Expand environment variables and ~.
4798 * Don't do it when adding without inserting a
4799 * comma.
4800 */
4801 if (!(adding || prepending || removing)
4802 || (flags & P_COMMA))
4803 {
4804 s = option_expand(opt_idx, newval);
4805 if (s != NULL)
4806 {
4807 vim_free(newval);
4808 newlen = (unsigned)STRLEN(s) + 1;
4809 if (adding || prepending || removing)
4810 newlen += (unsigned)STRLEN(origval) + 1;
4811 newval = alloc(newlen);
4812 if (newval == NULL)
4813 break;
4814 STRCPY(newval, s);
4815 }
4816 }
4817
4818 /* locate newval[] in origval[] when removing it
4819 * and when adding to avoid duplicates */
4820 i = 0; /* init for GCC */
4821 if (removing || (flags & P_NODUP))
4822 {
4823 i = (int)STRLEN(newval);
4824 bs = 0;
4825 for (s = origval; *s; ++s)
4826 {
4827 if ((!(flags & P_COMMA)
4828 || s == origval
4829 || (s[-1] == ',' && !(bs & 1)))
4830 && STRNCMP(s, newval, i) == 0
4831 && (!(flags & P_COMMA)
4832 || s[i] == ','
4833 || s[i] == NUL))
4834 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004835 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004836 * even number of backslashes or a single
4837 * backslash preceded by a comma before it
4838 * is recognized as a separator */
4839 if ((s > origval + 1
4840 && s[-1] == '\\'
4841 && s[-2] != ',')
4842 || (s == origval + 1
4843 && s[-1] == '\\'))
4844
Bram Moolenaar071d4272004-06-13 20:20:40 +00004845 ++bs;
4846 else
4847 bs = 0;
4848 }
4849
4850 /* do not add if already there */
4851 if ((adding || prepending) && *s)
4852 {
4853 prepending = FALSE;
4854 adding = FALSE;
4855 STRCPY(newval, origval);
4856 }
4857 }
4858
4859 /* concatenate the two strings; add a ',' if
4860 * needed */
4861 if (adding || prepending)
4862 {
4863 comma = ((flags & P_COMMA) && *origval != NUL
4864 && *newval != NUL);
4865 if (adding)
4866 {
4867 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004868 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004869 if (comma && i > 1
4870 && (flags & P_ONECOMMA) == P_ONECOMMA
4871 && origval[i - 1] == ','
4872 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004873 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004874 mch_memmove(newval + i + comma, newval,
4875 STRLEN(newval) + 1);
4876 mch_memmove(newval, origval, (size_t)i);
4877 }
4878 else
4879 {
4880 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004881 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004882 }
4883 if (comma)
4884 newval[i] = ',';
4885 }
4886
4887 /* Remove newval[] from origval[]. (Note: "i" has
4888 * been set above and is used here). */
4889 if (removing)
4890 {
4891 STRCPY(newval, origval);
4892 if (*s)
4893 {
4894 /* may need to remove a comma */
4895 if (flags & P_COMMA)
4896 {
4897 if (s == origval)
4898 {
4899 /* include comma after string */
4900 if (s[i] == ',')
4901 ++i;
4902 }
4903 else
4904 {
4905 /* include comma before string */
4906 --s;
4907 ++i;
4908 }
4909 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004910 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004911 }
4912 }
4913
4914 if (flags & P_FLAGLIST)
4915 {
4916 /* Remove flags that appear twice. */
4917 for (s = newval; *s; ++s)
4918 if ((!(flags & P_COMMA) || *s != ',')
4919 && vim_strchr(s + 1, *s) != NULL)
4920 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004921 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004922 --s;
4923 }
4924 }
4925
4926 if (save_arg != NULL) /* number for 'whichwrap' */
4927 arg = save_arg;
4928 new_value_alloced = TRUE;
4929 }
4930
4931 /* Set the new value. */
4932 *(char_u **)(varp) = newval;
4933
Bram Moolenaar53744302015-07-17 17:38:22 +02004934#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004935 if (!starting
4936# ifdef FEAT_CRYPT
4937 && options[opt_idx].indir != PV_KEY
4938# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004939 && origval != NULL)
4940 /* origval may be freed by
4941 * did_set_string_option(), make a copy. */
4942 saved_origval = vim_strsave(origval);
4943#endif
4944
Bram Moolenaar071d4272004-06-13 20:20:40 +00004945 /* Handle side effects, and set the global value for
4946 * ":set" on local options. */
4947 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4948 new_value_alloced, oldval, errbuf, opt_flags);
4949
4950 /* If error detected, print the error message. */
4951 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004952 {
4953#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4954 vim_free(saved_origval);
4955#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004956 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004957 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004958#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4959 if (saved_origval != NULL)
4960 {
4961 char_u buf_type[7];
4962
4963 sprintf((char *)buf_type, "%s",
4964 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004965 set_vim_var_string(VV_OPTION_NEW,
4966 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004967 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4968 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4969 apply_autocmds(EVENT_OPTIONSET,
4970 (char_u *)options[opt_idx].fullname,
4971 NULL, FALSE, NULL);
4972 reset_v_option_vars();
4973 vim_free(saved_origval);
4974 }
4975#endif
4976
Bram Moolenaar071d4272004-06-13 20:20:40 +00004977 }
4978 else /* key code option */
4979 {
4980 char_u *p;
4981
4982 if (nextchar == '&')
4983 {
4984 if (add_termcap_entry(key_name, TRUE) == FAIL)
4985 errmsg = (char_u *)N_("E522: Not found in termcap");
4986 }
4987 else
4988 {
4989 ++arg; /* jump to after the '=' or ':' */
4990 for (p = arg; *p && !vim_iswhite(*p); ++p)
4991 if (*p == '\\' && p[1] != NUL)
4992 ++p;
4993 nextchar = *p;
4994 *p = NUL;
4995 add_termcode(key_name, arg, FALSE);
4996 *p = nextchar;
4997 }
4998 if (full_screen)
4999 ttest(FALSE);
5000 redraw_all_later(CLEAR);
5001 }
5002 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005003
Bram Moolenaar071d4272004-06-13 20:20:40 +00005004 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005005 did_set_option(opt_idx, opt_flags,
5006 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005007 }
5008
5009skip:
5010 /*
5011 * Advance to next argument.
5012 * - skip until a blank found, taking care of backslashes
5013 * - skip blanks
5014 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5015 */
5016 for (i = 0; i < 2 ; ++i)
5017 {
5018 while (*arg != NUL && !vim_iswhite(*arg))
5019 if (*arg++ == '\\' && *arg != NUL)
5020 ++arg;
5021 arg = skipwhite(arg);
5022 if (*arg != '=')
5023 break;
5024 }
5025 }
5026
5027 if (errmsg != NULL)
5028 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005029 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005030 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005031 if (i + (arg - startarg) < IOSIZE)
5032 {
5033 /* append the argument with the error */
5034 STRCAT(IObuff, ": ");
5035 mch_memmove(IObuff + i, startarg, (arg - startarg));
5036 IObuff[i + (arg - startarg)] = NUL;
5037 }
5038 /* make sure all characters are printable */
5039 trans_characters(IObuff, IOSIZE);
5040
5041 ++no_wait_return; /* wait_return done later */
5042 emsg(IObuff); /* show error highlighted */
5043 --no_wait_return;
5044
5045 return FAIL;
5046 }
5047
5048 arg = skipwhite(arg);
5049 }
5050
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005051theend:
5052 if (silent_mode && did_show)
5053 {
5054 /* After displaying option values in silent mode. */
5055 silent_mode = FALSE;
5056 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5057 msg_putchar('\n');
5058 cursor_on(); /* msg_start() switches it off */
5059 out_flush();
5060 silent_mode = TRUE;
5061 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5062 }
5063
Bram Moolenaar071d4272004-06-13 20:20:40 +00005064 return OK;
5065}
5066
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005067/*
5068 * Call this when an option has been given a new value through a user command.
5069 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5070 */
5071 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005072did_set_option(
5073 int opt_idx,
5074 int opt_flags, /* possibly with OPT_MODELINE */
5075 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005076{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005077 long_u *p;
5078
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005079 options[opt_idx].flags |= P_WAS_SET;
5080
5081 /* When an option is set in the sandbox, from a modeline or in secure mode
5082 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005083 * flag. */
5084 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005085 if (secure
5086#ifdef HAVE_SANDBOX
5087 || sandbox != 0
5088#endif
5089 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005090 *p = *p | P_INSECURE;
5091 else if (new_value)
5092 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005093}
5094
Bram Moolenaar071d4272004-06-13 20:20:40 +00005095 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005096illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005097{
5098 if (errbuf == NULL)
5099 return (char_u *)"";
5100 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005101 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005102 return errbuf;
5103}
5104
5105/*
5106 * Convert a key name or string into a key value.
5107 * Used for 'wildchar' and 'cedit' options.
5108 */
5109 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005110string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111{
5112 if (*arg == '<')
5113 return find_key_option(arg + 1);
5114 if (*arg == '^')
5115 return Ctrl_chr(arg[1]);
5116 return *arg;
5117}
5118
5119#ifdef FEAT_CMDWIN
5120/*
5121 * Check value of 'cedit' and set cedit_key.
5122 * Returns NULL if value is OK, error message otherwise.
5123 */
5124 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005125check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005126{
5127 int n;
5128
5129 if (*p_cedit == NUL)
5130 cedit_key = -1;
5131 else
5132 {
5133 n = string_to_key(p_cedit);
5134 if (vim_isprintc(n))
5135 return e_invarg;
5136 cedit_key = n;
5137 }
5138 return NULL;
5139}
5140#endif
5141
5142#ifdef FEAT_TITLE
5143/*
5144 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5145 * maketitle() to create and display it.
5146 * When switching the title or icon off, call mch_restore_title() to get
5147 * the old value back.
5148 */
5149 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005150did_set_title(
5151 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152{
5153 if (starting != NO_SCREEN
5154#ifdef FEAT_GUI
5155 && !gui.starting
5156#endif
5157 )
5158 {
5159 maketitle();
5160 if (icon)
5161 {
5162 if (!p_icon)
5163 mch_restore_title(2);
5164 }
5165 else
5166 {
5167 if (!p_title)
5168 mch_restore_title(1);
5169 }
5170 }
5171}
5172#endif
5173
5174/*
5175 * set_options_bin - called when 'bin' changes value.
5176 */
5177 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005178set_options_bin(
5179 int oldval,
5180 int newval,
5181 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005182{
5183 /*
5184 * The option values that are changed when 'bin' changes are
5185 * copied when 'bin is set and restored when 'bin' is reset.
5186 */
5187 if (newval)
5188 {
5189 if (!oldval) /* switched on */
5190 {
5191 if (!(opt_flags & OPT_GLOBAL))
5192 {
5193 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5194 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5195 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5196 curbuf->b_p_et_nobin = curbuf->b_p_et;
5197 }
5198 if (!(opt_flags & OPT_LOCAL))
5199 {
5200 p_tw_nobin = p_tw;
5201 p_wm_nobin = p_wm;
5202 p_ml_nobin = p_ml;
5203 p_et_nobin = p_et;
5204 }
5205 }
5206
5207 if (!(opt_flags & OPT_GLOBAL))
5208 {
5209 curbuf->b_p_tw = 0; /* no automatic line wrap */
5210 curbuf->b_p_wm = 0; /* no automatic line wrap */
5211 curbuf->b_p_ml = 0; /* no modelines */
5212 curbuf->b_p_et = 0; /* no expandtab */
5213 }
5214 if (!(opt_flags & OPT_LOCAL))
5215 {
5216 p_tw = 0;
5217 p_wm = 0;
5218 p_ml = FALSE;
5219 p_et = FALSE;
5220 p_bin = TRUE; /* needed when called for the "-b" argument */
5221 }
5222 }
5223 else if (oldval) /* switched off */
5224 {
5225 if (!(opt_flags & OPT_GLOBAL))
5226 {
5227 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5228 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5229 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5230 curbuf->b_p_et = curbuf->b_p_et_nobin;
5231 }
5232 if (!(opt_flags & OPT_LOCAL))
5233 {
5234 p_tw = p_tw_nobin;
5235 p_wm = p_wm_nobin;
5236 p_ml = p_ml_nobin;
5237 p_et = p_et_nobin;
5238 }
5239 }
5240}
5241
5242#ifdef FEAT_VIMINFO
5243/*
5244 * Find the parameter represented by the given character (eg ', :, ", or /),
5245 * and return its associated value in the 'viminfo' string.
5246 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005247 * If the parameter is not specified in the string or there is no following
5248 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005249 */
5250 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005251get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005252{
5253 char_u *p;
5254
5255 p = find_viminfo_parameter(type);
5256 if (p != NULL && VIM_ISDIGIT(*p))
5257 return atoi((char *)p);
5258 return -1;
5259}
5260
5261/*
5262 * Find the parameter represented by the given character (eg ''', ':', '"', or
5263 * '/') in the 'viminfo' option and return a pointer to the string after it.
5264 * Return NULL if the parameter is not specified in the string.
5265 */
5266 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005267find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005268{
5269 char_u *p;
5270
5271 for (p = p_viminfo; *p; ++p)
5272 {
5273 if (*p == type)
5274 return p + 1;
5275 if (*p == 'n') /* 'n' is always the last one */
5276 break;
5277 p = vim_strchr(p, ','); /* skip until next ',' */
5278 if (p == NULL) /* hit the end without finding parameter */
5279 break;
5280 }
5281 return NULL;
5282}
5283#endif
5284
5285/*
5286 * Expand environment variables for some string options.
5287 * These string options cannot be indirect!
5288 * If "val" is NULL expand the current value of the option.
5289 * Return pointer to NameBuff, or NULL when not expanded.
5290 */
5291 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005292option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005293{
5294 /* if option doesn't need expansion nothing to do */
5295 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5296 return NULL;
5297
5298 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5299 * expand_env() would truncate the string. */
5300 if (val != NULL && STRLEN(val) > MAXPATHL)
5301 return NULL;
5302
5303 if (val == NULL)
5304 val = *(char_u **)options[opt_idx].var;
5305
5306 /*
5307 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5308 * Escape spaces when expanding 'tags', they are used to separate file
5309 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005310 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005311 */
5312 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005313 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005314#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005315 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5316#endif
5317 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005318 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5319 return NULL;
5320
5321 return NameBuff;
5322}
5323
5324/*
5325 * After setting various option values: recompute variables that depend on
5326 * option values.
5327 */
5328 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005329didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330{
5331 /* initialize the table for 'iskeyword' et.al. */
5332 (void)init_chartab();
5333
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005334#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005338 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005339#ifdef FEAT_SESSION
5340 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5341 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5342#endif
5343#ifdef FEAT_FOLDING
5344 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5345#endif
5346 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005347 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348#ifdef FEAT_VIRTUALEDIT
5349 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5350#endif
5351#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5352 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5353#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005354#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005355 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005356 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005357 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005358 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5361 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5362#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005363#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005364 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5365#endif
5366#ifdef FEAT_CMDWIN
5367 /* set cedit_key */
5368 (void)check_cedit();
5369#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005370#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005371 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005372#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005373#ifdef FEAT_LINEBREAK
5374 /* initialize the table for 'breakat'. */
5375 fill_breakat_flags();
5376#endif
5377
5378}
5379
5380/*
5381 * More side effects of setting options.
5382 */
5383 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005384didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005385{
5386 /* Initialize the highlight_attr[] table. */
5387 (void)highlight_changed();
5388
5389 /* Parse default for 'wildmode' */
5390 check_opt_wim();
5391
5392 (void)set_chars_option(&p_lcs);
5393#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5394 /* Parse default for 'fillchars'. */
5395 (void)set_chars_option(&p_fcs);
5396#endif
5397
5398#ifdef FEAT_CLIPBOARD
5399 /* Parse default for 'clipboard' */
5400 (void)check_clipboard_option();
5401#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005402}
5403
5404/*
5405 * Check for string options that are NULL (normally only termcap options).
5406 */
5407 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005408check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005409{
5410 int opt_idx;
5411
5412 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5413 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5414 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5415}
5416
5417/*
5418 * Check string options in a buffer for NULL value.
5419 */
5420 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005421check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005422{
5423#if defined(FEAT_QUICKFIX)
5424 check_string_option(&buf->b_p_bh);
5425 check_string_option(&buf->b_p_bt);
5426#endif
5427#ifdef FEAT_MBYTE
5428 check_string_option(&buf->b_p_fenc);
5429#endif
5430 check_string_option(&buf->b_p_ff);
5431#ifdef FEAT_FIND_ID
5432 check_string_option(&buf->b_p_def);
5433 check_string_option(&buf->b_p_inc);
5434# ifdef FEAT_EVAL
5435 check_string_option(&buf->b_p_inex);
5436# endif
5437#endif
5438#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5439 check_string_option(&buf->b_p_inde);
5440 check_string_option(&buf->b_p_indk);
5441#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005442#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5443 check_string_option(&buf->b_p_bexpr);
5444#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005445#if defined(FEAT_CRYPT)
5446 check_string_option(&buf->b_p_cm);
5447#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005448#if defined(FEAT_EVAL)
5449 check_string_option(&buf->b_p_fex);
5450#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005451#ifdef FEAT_CRYPT
5452 check_string_option(&buf->b_p_key);
5453#endif
5454 check_string_option(&buf->b_p_kp);
5455 check_string_option(&buf->b_p_mps);
5456 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005457 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005458 check_string_option(&buf->b_p_isk);
5459#ifdef FEAT_COMMENTS
5460 check_string_option(&buf->b_p_com);
5461#endif
5462#ifdef FEAT_FOLDING
5463 check_string_option(&buf->b_p_cms);
5464#endif
5465 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005466#ifdef FEAT_TEXTOBJ
5467 check_string_option(&buf->b_p_qe);
5468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469#ifdef FEAT_SYN_HL
5470 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005471 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005472#endif
5473#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005474 check_string_option(&buf->b_s.b_p_spc);
5475 check_string_option(&buf->b_s.b_p_spf);
5476 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005477#endif
5478#ifdef FEAT_SEARCHPATH
5479 check_string_option(&buf->b_p_sua);
5480#endif
5481#ifdef FEAT_CINDENT
5482 check_string_option(&buf->b_p_cink);
5483 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005484 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005485#endif
5486#ifdef FEAT_AUTOCMD
5487 check_string_option(&buf->b_p_ft);
5488#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005489#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5490 check_string_option(&buf->b_p_cinw);
5491#endif
5492#ifdef FEAT_INS_EXPAND
5493 check_string_option(&buf->b_p_cpt);
5494#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005495#ifdef FEAT_COMPL_FUNC
5496 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005497 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499#ifdef FEAT_KEYMAP
5500 check_string_option(&buf->b_p_keymap);
5501#endif
5502#ifdef FEAT_QUICKFIX
5503 check_string_option(&buf->b_p_gp);
5504 check_string_option(&buf->b_p_mp);
5505 check_string_option(&buf->b_p_efm);
5506#endif
5507 check_string_option(&buf->b_p_ep);
5508 check_string_option(&buf->b_p_path);
5509 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005510 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511#ifdef FEAT_INS_EXPAND
5512 check_string_option(&buf->b_p_dict);
5513 check_string_option(&buf->b_p_tsr);
5514#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005515#ifdef FEAT_LISP
5516 check_string_option(&buf->b_p_lw);
5517#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005518 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005519}
5520
5521/*
5522 * Free the string allocated for an option.
5523 * Checks for the string being empty_option. This may happen if we're out of
5524 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5525 * check_options().
5526 * Does NOT check for P_ALLOCED flag!
5527 */
5528 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005529free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005530{
5531 if (p != empty_option)
5532 vim_free(p);
5533}
5534
5535 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005536clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537{
5538 if (*pp != empty_option)
5539 vim_free(*pp);
5540 *pp = empty_option;
5541}
5542
5543 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005544check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545{
5546 if (*pp == NULL)
5547 *pp = empty_option;
5548}
5549
5550/*
5551 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5552 */
5553 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005554set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555{
5556 int opt_idx;
5557
5558 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5559 if (options[opt_idx].var == (char_u *)p)
5560 {
5561 options[opt_idx].flags |= P_ALLOCED;
5562 return;
5563 }
5564 return; /* cannot happen: didn't find it! */
5565}
5566
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005567#if defined(FEAT_EVAL) || defined(PROTO)
5568/*
5569 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5570 * Return FALSE when it wasn't.
5571 * Return -1 for an unknown option.
5572 */
5573 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005574was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005575{
5576 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005577 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005578
5579 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005580 {
5581 flagp = insecure_flag(idx, opt_flags);
5582 return (*flagp & P_INSECURE) != 0;
5583 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005584 EMSG2(_(e_intern2), "was_set_insecurely()");
5585 return -1;
5586}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005587
5588/*
5589 * Get a pointer to the flags used for the P_INSECURE flag of option
5590 * "opt_idx". For some local options a local flags field is used.
5591 */
5592 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005593insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005594{
5595 if (opt_flags & OPT_LOCAL)
5596 switch ((int)options[opt_idx].indir)
5597 {
5598#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005599 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005600#endif
5601#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005602# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005603 case PV_FDE: return &curwin->w_p_fde_flags;
5604 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005605# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005606# ifdef FEAT_BEVAL
5607 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5608# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005609# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005610 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005611# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005612 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005613# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005614 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005615# endif
5616#endif
5617 }
5618
5619 /* Nothing special, return global flags field. */
5620 return &options[opt_idx].flags;
5621}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005622#endif
5623
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005624#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005625static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005626
5627/*
5628 * Redraw the window title and/or tab page text later.
5629 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005630static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005631{
5632 need_maketitle = TRUE;
5633# ifdef FEAT_WINDOWS
5634 redraw_tabline = TRUE;
5635# endif
5636}
5637#endif
5638
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639/*
5640 * Set a string option to a new value (without checking the effect).
5641 * The string is copied into allocated memory.
5642 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005643 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005644 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645 */
5646 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005647set_string_option_direct(
5648 char_u *name,
5649 int opt_idx,
5650 char_u *val,
5651 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5652 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005653{
5654 char_u *s;
5655 char_u **varp;
5656 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005657 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005658
Bram Moolenaar89d40322006-08-29 15:30:07 +00005659 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005660 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005661 idx = findoption(name);
5662 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005663 {
5664 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005665 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005667 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668 }
5669
Bram Moolenaar89d40322006-08-29 15:30:07 +00005670 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671 return;
5672
5673 s = vim_strsave(val);
5674 if (s != NULL)
5675 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005676 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005678 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005679 free_string_option(*varp);
5680 *varp = s;
5681
5682 /* For buffer/window local option may also set the global value. */
5683 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005684 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685
Bram Moolenaar89d40322006-08-29 15:30:07 +00005686 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005687
5688 /* When setting both values of a global option with a local value,
5689 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005690 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691 {
5692 free_string_option(*varp);
5693 *varp = empty_option;
5694 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005695# ifdef FEAT_EVAL
5696 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005697 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005698 set_sid == 0 ? current_SID : set_sid);
5699# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700 }
5701}
5702
5703/*
5704 * Set global value for string option when it's a local option.
5705 */
5706 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005707set_string_option_global(
5708 int opt_idx, /* option index */
5709 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710{
5711 char_u **p, *s;
5712
5713 /* the global value is always allocated */
5714 if (options[opt_idx].var == VAR_WIN)
5715 p = (char_u **)GLOBAL_WO(varp);
5716 else
5717 p = (char_u **)options[opt_idx].var;
5718 if (options[opt_idx].indir != PV_NONE
5719 && p != varp
5720 && (s = vim_strsave(*varp)) != NULL)
5721 {
5722 free_string_option(*p);
5723 *p = s;
5724 }
5725}
5726
5727/*
5728 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005729 *
5730 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005732 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005733set_string_option(
5734 int opt_idx,
5735 char_u *value,
5736 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737{
5738 char_u *s;
5739 char_u **varp;
5740 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005741#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5742 char_u *saved_oldval = NULL;
5743#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005744 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745
5746 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005747 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005748
5749 s = vim_strsave(value);
5750 if (s != NULL)
5751 {
5752 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5753 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005754 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755 ? OPT_GLOBAL : OPT_LOCAL)
5756 : opt_flags);
5757 oldval = *varp;
5758 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005759
5760#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005761 if (!starting
5762# ifdef FEAT_CRYPT
5763 && options[opt_idx].indir != PV_KEY
5764# endif
5765 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005766 saved_oldval = vim_strsave(oldval);
5767#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005768 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5769 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005770 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005771
5772 /* call autocomamnd after handling side effects */
5773#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5774 if (saved_oldval != NULL)
5775 {
5776 char_u buf_type[7];
5777 sprintf((char *)buf_type, "%s",
5778 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005779 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5780 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005781 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5782 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5783 reset_v_option_vars();
5784 vim_free(saved_oldval);
5785 }
5786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005787 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005788 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005789}
5790
5791/*
5792 * Handle string options that need some action to perform when changed.
5793 * Returns NULL for success, or an error message for an error.
5794 */
5795 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005796did_set_string_option(
5797 int opt_idx, /* index in options[] table */
5798 char_u **varp, /* pointer to the option variable */
5799 int new_value_alloced, /* new value was allocated */
5800 char_u *oldval, /* previous value of the option */
5801 char_u *errbuf, /* buffer for errors, or NULL */
5802 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005803{
5804 char_u *errmsg = NULL;
5805 char_u *s, *p;
5806 int did_chartab = FALSE;
5807 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005808 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005809#ifdef FEAT_GUI
5810 /* set when changing an option that only requires a redraw in the GUI */
5811 int redraw_gui_only = FALSE;
5812#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005813
5814 /* Get the global option to compare with, otherwise we would have to check
5815 * two values for all local options. */
5816 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5817
5818 /* Disallow changing some options from secure mode */
5819 if ((secure
5820#ifdef HAVE_SANDBOX
5821 || sandbox != 0
5822#endif
5823 ) && (options[opt_idx].flags & P_SECURE))
5824 {
5825 errmsg = e_secure;
5826 }
5827
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005828 /* Check for a "normal" file name in some options. Disallow a path
5829 * separator (slash and/or backslash), wildcards and characters that are
5830 * often illegal in a file name. */
5831 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005832 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005833 {
5834 errmsg = e_invarg;
5835 }
5836
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837 /* 'term' */
5838 else if (varp == &T_NAME)
5839 {
5840 if (T_NAME[0] == NUL)
5841 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5842#ifdef FEAT_GUI
5843 if (gui.in_use)
5844 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5845 else if (term_is_gui(T_NAME))
5846 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5847#endif
5848 else if (set_termname(T_NAME) == FAIL)
5849 errmsg = (char_u *)N_("E522: Not found in termcap");
5850 else
5851 /* Screen colors may have changed. */
5852 redraw_later_clear();
5853 }
5854
5855 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005856 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005857 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005858 char_u *bkc = p_bkc;
5859 unsigned int *flags = &bkc_flags;
5860
5861 if (opt_flags & OPT_LOCAL)
5862 {
5863 bkc = curbuf->b_p_bkc;
5864 flags = &curbuf->b_bkc_flags;
5865 }
5866
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005867 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5868 /* make the local value empty: use the global value */
5869 *flags = 0;
5870 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005872 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5873 errmsg = e_invarg;
5874 if ((((int)*flags & BKC_AUTO) != 0)
5875 + (((int)*flags & BKC_YES) != 0)
5876 + (((int)*flags & BKC_NO) != 0) != 1)
5877 {
5878 /* Must have exactly one of "auto", "yes" and "no". */
5879 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5880 errmsg = e_invarg;
5881 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005882 }
5883 }
5884
5885 /* 'backupext' and 'patchmode' */
5886 else if (varp == &p_bex || varp == &p_pm)
5887 {
5888 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5889 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5890 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5891 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005892#ifdef FEAT_LINEBREAK
5893 /* 'breakindentopt' */
5894 else if (varp == &curwin->w_p_briopt)
5895 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005896 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005897 errmsg = e_invarg;
5898 }
5899#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005900
5901 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005902 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005903 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005904 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905 */
5906 else if ( varp == &p_isi
5907 || varp == &(curbuf->b_p_isk)
5908 || varp == &p_isp
5909 || varp == &p_isf)
5910 {
5911 if (init_chartab() == FAIL)
5912 {
5913 did_chartab = TRUE; /* need to restore it below */
5914 errmsg = e_invarg; /* error in value */
5915 }
5916 }
5917
5918 /* 'helpfile' */
5919 else if (varp == &p_hf)
5920 {
5921 /* May compute new values for $VIM and $VIMRUNTIME */
5922 if (didset_vim)
5923 {
5924 vim_setenv((char_u *)"VIM", (char_u *)"");
5925 didset_vim = FALSE;
5926 }
5927 if (didset_vimruntime)
5928 {
5929 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5930 didset_vimruntime = FALSE;
5931 }
5932 }
5933
Bram Moolenaar1a384422010-07-14 19:53:30 +02005934#ifdef FEAT_SYN_HL
5935 /* 'colorcolumn' */
5936 else if (varp == &curwin->w_p_cc)
5937 errmsg = check_colorcolumn(curwin);
5938#endif
5939
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940#ifdef FEAT_MULTI_LANG
5941 /* 'helplang' */
5942 else if (varp == &p_hlg)
5943 {
5944 /* Check for "", "ab", "ab,cd", etc. */
5945 for (s = p_hlg; *s != NUL; s += 3)
5946 {
5947 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5948 {
5949 errmsg = e_invarg;
5950 break;
5951 }
5952 if (s[2] == NUL)
5953 break;
5954 }
5955 }
5956#endif
5957
5958 /* 'highlight' */
5959 else if (varp == &p_hl)
5960 {
5961 if (highlight_changed() == FAIL)
5962 errmsg = e_invarg; /* invalid flags */
5963 }
5964
5965 /* 'nrformats' */
5966 else if (gvarp == &p_nf)
5967 {
5968 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5969 errmsg = e_invarg;
5970 }
5971
5972#ifdef FEAT_SESSION
5973 /* 'sessionoptions' */
5974 else if (varp == &p_ssop)
5975 {
5976 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5977 errmsg = e_invarg;
5978 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5979 {
5980 /* Don't allow both "sesdir" and "curdir". */
5981 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5982 errmsg = e_invarg;
5983 }
5984 }
5985 /* 'viewoptions' */
5986 else if (varp == &p_vop)
5987 {
5988 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5989 errmsg = e_invarg;
5990 }
5991#endif
5992
5993 /* 'scrollopt' */
5994#ifdef FEAT_SCROLLBIND
5995 else if (varp == &p_sbo)
5996 {
5997 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5998 errmsg = e_invarg;
5999 }
6000#endif
6001
6002 /* 'ambiwidth' */
6003#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006004 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005 {
6006 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6007 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006008 else if (set_chars_option(&p_lcs) != NULL)
6009 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6010# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6011 else if (set_chars_option(&p_fcs) != NULL)
6012 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6013# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014 }
6015#endif
6016
6017 /* 'background' */
6018 else if (varp == &p_bg)
6019 {
6020 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6021 {
6022#ifdef FEAT_EVAL
6023 int dark = (*p_bg == 'd');
6024#endif
6025
6026 init_highlight(FALSE, FALSE);
6027
6028#ifdef FEAT_EVAL
6029 if (dark != (*p_bg == 'd')
6030 && get_var_value((char_u *)"g:colors_name") != NULL)
6031 {
6032 /* The color scheme must have set 'background' back to another
6033 * value, that's not what we want here. Disable the color
6034 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006035 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006036 free_string_option(p_bg);
6037 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6038 check_string_option(&p_bg);
6039 init_highlight(FALSE, FALSE);
6040 }
6041#endif
6042 }
6043 else
6044 errmsg = e_invarg;
6045 }
6046
6047 /* 'wildmode' */
6048 else if (varp == &p_wim)
6049 {
6050 if (check_opt_wim() == FAIL)
6051 errmsg = e_invarg;
6052 }
6053
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006054#ifdef FEAT_CMDL_COMPL
6055 /* 'wildoptions' */
6056 else if (varp == &p_wop)
6057 {
6058 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6059 errmsg = e_invarg;
6060 }
6061#endif
6062
Bram Moolenaar071d4272004-06-13 20:20:40 +00006063#ifdef FEAT_WAK
6064 /* 'winaltkeys' */
6065 else if (varp == &p_wak)
6066 {
6067 if (*p_wak == NUL
6068 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6069 errmsg = e_invarg;
6070# ifdef FEAT_MENU
6071# ifdef FEAT_GUI_MOTIF
6072 else if (gui.in_use)
6073 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6074# else
6075# ifdef FEAT_GUI_GTK
6076 else if (gui.in_use)
6077 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6078# endif
6079# endif
6080# endif
6081 }
6082#endif
6083
6084#ifdef FEAT_AUTOCMD
6085 /* 'eventignore' */
6086 else if (varp == &p_ei)
6087 {
6088 if (check_ei() == FAIL)
6089 errmsg = e_invarg;
6090 }
6091#endif
6092
6093#ifdef FEAT_MBYTE
6094 /* 'encoding' and 'fileencoding' */
6095 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6096 {
6097 if (gvarp == &p_fenc)
6098 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006099 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006100 errmsg = e_modifiable;
6101 else if (vim_strchr(*varp, ',') != NULL)
6102 /* No comma allowed in 'fileencoding'; catches confusing it
6103 * with 'fileencodings'. */
6104 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006106 {
6107# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006108 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006109 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006111 /* Add 'fileencoding' to the swap file. */
6112 ml_setflags(curbuf);
6113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114 }
6115 if (errmsg == NULL)
6116 {
6117 /* canonize the value, so that STRCMP() can be used on it */
6118 p = enc_canonize(*varp);
6119 if (p != NULL)
6120 {
6121 vim_free(*varp);
6122 *varp = p;
6123 }
6124 if (varp == &p_enc)
6125 {
6126 errmsg = mb_init();
6127# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006128 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129# endif
6130 }
6131 }
6132
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006133# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6135 {
6136 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6137 if (STRCMP(p_tenc, "utf-8") != 0)
6138 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6139 }
6140# endif
6141
6142 if (errmsg == NULL)
6143 {
6144# ifdef FEAT_KEYMAP
6145 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6146 * (with another encoding). */
6147 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6148 (void)keymap_init();
6149# endif
6150
6151 /* When 'termencoding' is not empty and 'encoding' changes or when
6152 * 'termencoding' changes, need to setup for keyboard input and
6153 * display output conversion. */
6154 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6155 {
6156 convert_setup(&input_conv, p_tenc, p_enc);
6157 convert_setup(&output_conv, p_enc, p_tenc);
6158 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006159
6160# if defined(WIN3264) && defined(FEAT_MBYTE)
6161 /* $HOME may have characters in active code page. */
6162 if (varp == &p_enc)
6163 init_homedir();
6164# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006165 }
6166 }
6167#endif
6168
6169#if defined(FEAT_POSTSCRIPT)
6170 else if (varp == &p_penc)
6171 {
6172 /* Canonize printencoding if VIM standard one */
6173 p = enc_canonize(p_penc);
6174 if (p != NULL)
6175 {
6176 vim_free(p_penc);
6177 p_penc = p;
6178 }
6179 else
6180 {
6181 /* Ensure lower case and '-' for '_' */
6182 for (s = p_penc; *s != NUL; s++)
6183 {
6184 if (*s == '_')
6185 *s = '-';
6186 else
6187 *s = TOLOWER_ASC(*s);
6188 }
6189 }
6190 }
6191#endif
6192
Bram Moolenaar9372a112005-12-06 19:59:18 +00006193#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006194 else if (varp == &p_imak)
6195 {
6196 if (gui.in_use && !im_xim_isvalid_imactivate())
6197 errmsg = e_invarg;
6198 }
6199#endif
6200
6201#ifdef FEAT_KEYMAP
6202 else if (varp == &curbuf->b_p_keymap)
6203 {
6204 /* load or unload key mapping tables */
6205 errmsg = keymap_init();
6206
Bram Moolenaarfab06232009-03-04 03:13:35 +00006207 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006208 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006209 if (*curbuf->b_p_keymap != NUL)
6210 {
6211 /* Installed a new keymap, switch on using it. */
6212 curbuf->b_p_iminsert = B_IMODE_LMAP;
6213 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6214 curbuf->b_p_imsearch = B_IMODE_LMAP;
6215 }
6216 else
6217 {
6218 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6219 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6220 curbuf->b_p_iminsert = B_IMODE_NONE;
6221 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6222 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6223 }
6224 if ((opt_flags & OPT_LOCAL) == 0)
6225 {
6226 set_iminsert_global();
6227 set_imsearch_global();
6228 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006229# ifdef FEAT_WINDOWS
6230 status_redraw_curbuf();
6231# endif
6232 }
6233 }
6234#endif
6235
6236 /* 'fileformat' */
6237 else if (gvarp == &p_ff)
6238 {
6239 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6240 errmsg = e_modifiable;
6241 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6242 errmsg = e_invarg;
6243 else
6244 {
6245 /* may also change 'textmode' */
6246 if (get_fileformat(curbuf) == EOL_DOS)
6247 curbuf->b_p_tx = TRUE;
6248 else
6249 curbuf->b_p_tx = FALSE;
6250#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006251 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006252#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006253 /* update flag in swap file */
6254 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006255 /* Redraw needed when switching to/from "mac": a CR in the text
6256 * will be displayed differently. */
6257 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6258 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006259 }
6260 }
6261
6262 /* 'fileformats' */
6263 else if (varp == &p_ffs)
6264 {
6265 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6266 errmsg = e_invarg;
6267 else
6268 {
6269 /* also change 'textauto' */
6270 if (*p_ffs == NUL)
6271 p_ta = FALSE;
6272 else
6273 p_ta = TRUE;
6274 }
6275 }
6276
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006277#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006278 /* 'cryptkey' */
6279 else if (gvarp == &p_key)
6280 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006281# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006282 /* Make sure the ":set" command doesn't show the new value in the
6283 * history. */
6284 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006285# endif
6286 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6287 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006288 ml_set_crypt_key(curbuf, oldval,
6289 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006290 }
6291
6292 else if (gvarp == &p_cm)
6293 {
6294 if (opt_flags & OPT_LOCAL)
6295 p = curbuf->b_p_cm;
6296 else
6297 p = p_cm;
6298 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6299 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006300 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006301 errmsg = e_invarg;
6302 else
6303 {
6304 /* When setting the global value to empty, make it "zip". */
6305 if (*p_cm == NUL)
6306 {
6307 if (new_value_alloced)
6308 free_string_option(p_cm);
6309 p_cm = vim_strsave((char_u *)"zip");
6310 new_value_alloced = TRUE;
6311 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006312 /* When using ":set cm=name" the local value is going to be empty.
6313 * Do that here, otherwise the crypt functions will still use the
6314 * local value. */
6315 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6316 {
6317 free_string_option(curbuf->b_p_cm);
6318 curbuf->b_p_cm = empty_option;
6319 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006320
6321 /* Need to update the swapfile when the effective method changed.
6322 * Set "s" to the effective old value, "p" to the effective new
6323 * method and compare. */
6324 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6325 s = p_cm; /* was previously using the global value */
6326 else
6327 s = oldval;
6328 if (*curbuf->b_p_cm == NUL)
6329 p = p_cm; /* is now using the global value */
6330 else
6331 p = curbuf->b_p_cm;
6332 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006333 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006334
6335 /* If the global value changes need to update the swapfile for all
6336 * buffers using that value. */
6337 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6338 {
6339 buf_T *buf;
6340
6341 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6342 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006343 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006344 }
6345 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006346 }
6347#endif
6348
6349 /* 'matchpairs' */
6350 else if (gvarp == &p_mps)
6351 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006352#ifdef FEAT_MBYTE
6353 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006355 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006356 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006357 int x2 = -1;
6358 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006359
6360 if (*p != NUL)
6361 p += mb_ptr2len(p);
6362 if (*p != NUL)
6363 x2 = *p++;
6364 if (*p != NUL)
6365 {
6366 x3 = mb_ptr2char(p);
6367 p += mb_ptr2len(p);
6368 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006369 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006370 {
6371 errmsg = e_invarg;
6372 break;
6373 }
6374 if (*p == NUL)
6375 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006376 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006377 }
6378 else
6379#endif
6380 {
6381 /* Check for "x:y,x:y" */
6382 for (p = *varp; *p != NUL; p += 4)
6383 {
6384 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6385 {
6386 errmsg = e_invarg;
6387 break;
6388 }
6389 if (p[3] == NUL)
6390 break;
6391 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 }
6393 }
6394
6395#ifdef FEAT_COMMENTS
6396 /* 'comments' */
6397 else if (gvarp == &p_com)
6398 {
6399 for (s = *varp; *s; )
6400 {
6401 while (*s && *s != ':')
6402 {
6403 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6404 && !VIM_ISDIGIT(*s) && *s != '-')
6405 {
6406 errmsg = illegal_char(errbuf, *s);
6407 break;
6408 }
6409 ++s;
6410 }
6411 if (*s++ == NUL)
6412 errmsg = (char_u *)N_("E524: Missing colon");
6413 else if (*s == ',' || *s == NUL)
6414 errmsg = (char_u *)N_("E525: Zero length string");
6415 if (errmsg != NULL)
6416 break;
6417 while (*s && *s != ',')
6418 {
6419 if (*s == '\\' && s[1] != NUL)
6420 ++s;
6421 ++s;
6422 }
6423 s = skip_to_option_part(s);
6424 }
6425 }
6426#endif
6427
6428 /* 'listchars' */
6429 else if (varp == &p_lcs)
6430 {
6431 errmsg = set_chars_option(varp);
6432 }
6433
6434#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6435 /* 'fillchars' */
6436 else if (varp == &p_fcs)
6437 {
6438 errmsg = set_chars_option(varp);
6439 }
6440#endif
6441
6442#ifdef FEAT_CMDWIN
6443 /* 'cedit' */
6444 else if (varp == &p_cedit)
6445 {
6446 errmsg = check_cedit();
6447 }
6448#endif
6449
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006450 /* 'verbosefile' */
6451 else if (varp == &p_vfile)
6452 {
6453 verbose_stop();
6454 if (*p_vfile != NUL && verbose_open() == FAIL)
6455 errmsg = e_invarg;
6456 }
6457
Bram Moolenaar071d4272004-06-13 20:20:40 +00006458#ifdef FEAT_VIMINFO
6459 /* 'viminfo' */
6460 else if (varp == &p_viminfo)
6461 {
6462 for (s = p_viminfo; *s;)
6463 {
6464 /* Check it's a valid character */
6465 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6466 {
6467 errmsg = illegal_char(errbuf, *s);
6468 break;
6469 }
6470 if (*s == 'n') /* name is always last one */
6471 {
6472 break;
6473 }
6474 else if (*s == 'r') /* skip until next ',' */
6475 {
6476 while (*++s && *s != ',')
6477 ;
6478 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006479 else if (*s == '%')
6480 {
6481 /* optional number */
6482 while (vim_isdigit(*++s))
6483 ;
6484 }
6485 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006486 ++s; /* no extra chars */
6487 else /* must have a number */
6488 {
6489 while (vim_isdigit(*++s))
6490 ;
6491
6492 if (!VIM_ISDIGIT(*(s - 1)))
6493 {
6494 if (errbuf != NULL)
6495 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006496 sprintf((char *)errbuf,
6497 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 transchar_byte(*(s - 1)));
6499 errmsg = errbuf;
6500 }
6501 else
6502 errmsg = (char_u *)"";
6503 break;
6504 }
6505 }
6506 if (*s == ',')
6507 ++s;
6508 else if (*s)
6509 {
6510 if (errbuf != NULL)
6511 errmsg = (char_u *)N_("E527: Missing comma");
6512 else
6513 errmsg = (char_u *)"";
6514 break;
6515 }
6516 }
6517 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6518 errmsg = (char_u *)N_("E528: Must specify a ' value");
6519 }
6520#endif /* FEAT_VIMINFO */
6521
6522 /* terminal options */
6523 else if (istermoption(&options[opt_idx]) && full_screen)
6524 {
6525 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6526 if (varp == &T_CCO)
6527 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006528 int colors = atoi((char *)T_CCO);
6529
6530 /* Only reinitialize colors if t_Co value has really changed to
6531 * avoid expensive reload of colorscheme if t_Co is set to the
6532 * same value multiple times. */
6533 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006535 t_colors = colors;
6536 if (t_colors <= 1)
6537 {
6538 if (new_value_alloced)
6539 vim_free(T_CCO);
6540 T_CCO = empty_option;
6541 }
6542 /* We now have a different color setup, initialize it again. */
6543 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006545 }
6546 ttest(FALSE);
6547 if (varp == &T_ME)
6548 {
6549 out_str(T_ME);
6550 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006551#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006552 /* Since t_me has been set, this probably means that the user
6553 * wants to use this as default colors. Need to reset default
6554 * background/foreground colors. */
6555 mch_set_normal_colors();
6556#endif
6557 }
6558 }
6559
6560#ifdef FEAT_LINEBREAK
6561 /* 'showbreak' */
6562 else if (varp == &p_sbr)
6563 {
6564 for (s = p_sbr; *s; )
6565 {
6566 if (ptr2cells(s) != 1)
6567 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006568 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006569 }
6570 }
6571#endif
6572
6573#ifdef FEAT_GUI
6574 /* 'guifont' */
6575 else if (varp == &p_guifont)
6576 {
6577 if (gui.in_use)
6578 {
6579 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006580# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 /*
6582 * Put up a font dialog and let the user select a new value.
6583 * If this is cancelled go back to the old value but don't
6584 * give an error message.
6585 */
6586 if (STRCMP(p, "*") == 0)
6587 {
6588 p = gui_mch_font_dialog(oldval);
6589
6590 if (new_value_alloced)
6591 free_string_option(p_guifont);
6592
6593 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6594 new_value_alloced = TRUE;
6595 }
6596# endif
6597 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6598 {
6599# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6600 if (STRCMP(p_guifont, "*") == 0)
6601 {
6602 /* Dialog was cancelled: Keep the old value without giving
6603 * an error message. */
6604 if (new_value_alloced)
6605 free_string_option(p_guifont);
6606 p_guifont = vim_strsave(oldval);
6607 new_value_alloced = TRUE;
6608 }
6609 else
6610# endif
6611 errmsg = (char_u *)N_("E596: Invalid font(s)");
6612 }
6613 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006614 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006615 }
6616# ifdef FEAT_XFONTSET
6617 else if (varp == &p_guifontset)
6618 {
6619 if (STRCMP(p_guifontset, "*") == 0)
6620 errmsg = (char_u *)N_("E597: can't select fontset");
6621 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6622 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006623 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 }
6625# endif
6626# ifdef FEAT_MBYTE
6627 else if (varp == &p_guifontwide)
6628 {
6629 if (STRCMP(p_guifontwide, "*") == 0)
6630 errmsg = (char_u *)N_("E533: can't select wide font");
6631 else if (gui_get_wide_font() == FAIL)
6632 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006633 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 }
6635# endif
6636#endif
6637
6638#ifdef CURSOR_SHAPE
6639 /* 'guicursor' */
6640 else if (varp == &p_guicursor)
6641 errmsg = parse_shape_opt(SHAPE_CURSOR);
6642#endif
6643
6644#ifdef FEAT_MOUSESHAPE
6645 /* 'mouseshape' */
6646 else if (varp == &p_mouseshape)
6647 {
6648 errmsg = parse_shape_opt(SHAPE_MOUSE);
6649 update_mouseshape(-1);
6650 }
6651#endif
6652
6653#ifdef FEAT_PRINTER
6654 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006655 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006656# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006657 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006658 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006659# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006660#endif
6661
6662#ifdef FEAT_LANGMAP
6663 /* 'langmap' */
6664 else if (varp == &p_langmap)
6665 langmap_set();
6666#endif
6667
6668#ifdef FEAT_LINEBREAK
6669 /* 'breakat' */
6670 else if (varp == &p_breakat)
6671 fill_breakat_flags();
6672#endif
6673
6674#ifdef FEAT_TITLE
6675 /* 'titlestring' and 'iconstring' */
6676 else if (varp == &p_titlestring || varp == &p_iconstring)
6677 {
6678# ifdef FEAT_STL_OPT
6679 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6680
6681 /* NULL => statusline syntax */
6682 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6683 stl_syntax |= flagval;
6684 else
6685 stl_syntax &= ~flagval;
6686# endif
6687 did_set_title(varp == &p_iconstring);
6688
6689 }
6690#endif
6691
6692#ifdef FEAT_GUI
6693 /* 'guioptions' */
6694 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006695 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006696 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006697 redraw_gui_only = TRUE;
6698 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006699#endif
6700
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006701#if defined(FEAT_GUI_TABLINE)
6702 /* 'guitablabel' */
6703 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006704 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006705 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006706 redraw_gui_only = TRUE;
6707 }
6708 /* 'guitabtooltip' */
6709 else if (varp == &p_gtt)
6710 {
6711 redraw_gui_only = TRUE;
6712 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006713#endif
6714
Bram Moolenaar071d4272004-06-13 20:20:40 +00006715#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6716 /* 'ttymouse' */
6717 else if (varp == &p_ttym)
6718 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006719 /* Switch the mouse off before changing the escape sequences used for
6720 * that. */
6721 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6723 errmsg = e_invarg;
6724 else
6725 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006726 if (termcap_active)
6727 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006728 }
6729#endif
6730
Bram Moolenaar071d4272004-06-13 20:20:40 +00006731 /* 'selection' */
6732 else if (varp == &p_sel)
6733 {
6734 if (*p_sel == NUL
6735 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6736 errmsg = e_invarg;
6737 }
6738
6739 /* 'selectmode' */
6740 else if (varp == &p_slm)
6741 {
6742 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6743 errmsg = e_invarg;
6744 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745
6746#ifdef FEAT_BROWSE
6747 /* 'browsedir' */
6748 else if (varp == &p_bsdir)
6749 {
6750 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6751 && !mch_isdir(p_bsdir))
6752 errmsg = e_invarg;
6753 }
6754#endif
6755
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 /* 'keymodel' */
6757 else if (varp == &p_km)
6758 {
6759 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6760 errmsg = e_invarg;
6761 else
6762 {
6763 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6764 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6765 }
6766 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006767
6768 /* 'mousemodel' */
6769 else if (varp == &p_mousem)
6770 {
6771 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6772 errmsg = e_invarg;
6773#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6774 else if (*p_mousem != *oldval)
6775 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6776 * to create or delete the popup menus. */
6777 gui_motif_update_mousemodel(root_menu);
6778#endif
6779 }
6780
6781 /* 'switchbuf' */
6782 else if (varp == &p_swb)
6783 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006784 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785 errmsg = e_invarg;
6786 }
6787
6788 /* 'debug' */
6789 else if (varp == &p_debug)
6790 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006791 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792 errmsg = e_invarg;
6793 }
6794
6795 /* 'display' */
6796 else if (varp == &p_dy)
6797 {
6798 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6799 errmsg = e_invarg;
6800 else
6801 (void)init_chartab();
6802
6803 }
6804
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006805#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006806 /* 'eadirection' */
6807 else if (varp == &p_ead)
6808 {
6809 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6810 errmsg = e_invarg;
6811 }
6812#endif
6813
6814#ifdef FEAT_CLIPBOARD
6815 /* 'clipboard' */
6816 else if (varp == &p_cb)
6817 errmsg = check_clipboard_option();
6818#endif
6819
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006820#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006821 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6822 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006823 else if (varp == &(curwin->w_s->b_p_spl)
6824 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006825 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006826 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006827 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006828 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006829 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006830 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006831 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006832 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006833 /* 'spellsuggest' */
6834 else if (varp == &p_sps)
6835 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006836 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006837 errmsg = e_invarg;
6838 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006839 /* 'mkspellmem' */
6840 else if (varp == &p_msm)
6841 {
6842 if (spell_check_msm() != OK)
6843 errmsg = e_invarg;
6844 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006845#endif
6846
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847#ifdef FEAT_QUICKFIX
6848 /* When 'bufhidden' is set, check for valid value. */
6849 else if (gvarp == &p_bh)
6850 {
6851 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6852 errmsg = e_invarg;
6853 }
6854
6855 /* When 'buftype' is set, check for valid value. */
6856 else if (gvarp == &p_bt)
6857 {
6858 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6859 errmsg = e_invarg;
6860 else
6861 {
6862# ifdef FEAT_WINDOWS
6863 if (curwin->w_status_height)
6864 {
6865 curwin->w_redr_status = TRUE;
6866 redraw_later(VALID);
6867 }
6868# endif
6869 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006870# ifdef FEAT_TITLE
6871 redraw_titles();
6872# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873 }
6874 }
6875#endif
6876
6877#ifdef FEAT_STL_OPT
6878 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006879 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880 {
6881 int wid;
6882
6883 if (varp == &p_ruf) /* reset ru_wid first */
6884 ru_wid = 0;
6885 s = *varp;
6886 if (varp == &p_ruf && *s == '%')
6887 {
6888 /* set ru_wid if 'ruf' starts with "%99(" */
6889 if (*++s == '-') /* ignore a '-' */
6890 s++;
6891 wid = getdigits(&s);
6892 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6893 ru_wid = wid;
6894 else
6895 errmsg = check_stl_option(p_ruf);
6896 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006897 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006898 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006900 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006901 comp_col();
6902 }
6903#endif
6904
6905#ifdef FEAT_INS_EXPAND
6906 /* check if it is a valid value for 'complete' -- Acevedo */
6907 else if (gvarp == &p_cpt)
6908 {
6909 for (s = *varp; *s;)
6910 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006911 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006912 s++;
6913 if (!*s)
6914 break;
6915 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6916 {
6917 errmsg = illegal_char(errbuf, *s);
6918 break;
6919 }
6920 if (*++s != NUL && *s != ',' && *s != ' ')
6921 {
6922 if (s[-1] == 'k' || s[-1] == 's')
6923 {
6924 /* skip optional filename after 'k' and 's' */
6925 while (*s && *s != ',' && *s != ' ')
6926 {
6927 if (*s == '\\')
6928 ++s;
6929 ++s;
6930 }
6931 }
6932 else
6933 {
6934 if (errbuf != NULL)
6935 {
6936 sprintf((char *)errbuf,
6937 _("E535: Illegal character after <%c>"),
6938 *--s);
6939 errmsg = errbuf;
6940 }
6941 else
6942 errmsg = (char_u *)"";
6943 break;
6944 }
6945 }
6946 }
6947 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006948
6949 /* 'completeopt' */
6950 else if (varp == &p_cot)
6951 {
6952 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6953 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02006954 else
6955 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006956 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957#endif /* FEAT_INS_EXPAND */
6958
6959
6960#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6961 else if (varp == &p_toolbar)
6962 {
6963 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6964 &toolbar_flags, TRUE) != OK)
6965 errmsg = e_invarg;
6966 else
6967 {
6968 out_flush();
6969 gui_mch_show_toolbar((toolbar_flags &
6970 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6971 }
6972 }
6973#endif
6974
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006975#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006976 /* 'toolbariconsize': GTK+ 2 only */
6977 else if (varp == &p_tbis)
6978 {
6979 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6980 errmsg = e_invarg;
6981 else
6982 {
6983 out_flush();
6984 gui_mch_show_toolbar((toolbar_flags &
6985 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6986 }
6987 }
6988#endif
6989
6990 /* 'pastetoggle': translate key codes like in a mapping */
6991 else if (varp == &p_pt)
6992 {
6993 if (*p_pt)
6994 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006995 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006996 if (p != NULL)
6997 {
6998 if (new_value_alloced)
6999 free_string_option(p_pt);
7000 p_pt = p;
7001 new_value_alloced = TRUE;
7002 }
7003 }
7004 }
7005
7006 /* 'backspace' */
7007 else if (varp == &p_bs)
7008 {
7009 if (VIM_ISDIGIT(*p_bs))
7010 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007011 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007012 errmsg = e_invarg;
7013 }
7014 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7015 errmsg = e_invarg;
7016 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007017 else if (varp == &p_bo)
7018 {
7019 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7020 errmsg = e_invarg;
7021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007022
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007023 /* 'tagcase' */
7024 else if (gvarp == &p_tc)
7025 {
7026 unsigned int *flags;
7027
7028 if (opt_flags & OPT_LOCAL)
7029 {
7030 p = curbuf->b_p_tc;
7031 flags = &curbuf->b_tc_flags;
7032 }
7033 else
7034 {
7035 p = p_tc;
7036 flags = &tc_flags;
7037 }
7038
7039 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7040 /* make the local value empty: use the global value */
7041 *flags = 0;
7042 else if (*p == NUL
7043 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7044 errmsg = e_invarg;
7045 }
7046
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007047#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048 /* 'casemap' */
7049 else if (varp == &p_cmp)
7050 {
7051 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7052 errmsg = e_invarg;
7053 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007054#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007055
7056#ifdef FEAT_DIFF
7057 /* 'diffopt' */
7058 else if (varp == &p_dip)
7059 {
7060 if (diffopt_changed() == FAIL)
7061 errmsg = e_invarg;
7062 }
7063#endif
7064
7065#ifdef FEAT_FOLDING
7066 /* 'foldmethod' */
7067 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7068 {
7069 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7070 || *curwin->w_p_fdm == NUL)
7071 errmsg = e_invarg;
7072 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007073 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007074 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007075 if (foldmethodIsDiff(curwin))
7076 newFoldLevel();
7077 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 }
7079# ifdef FEAT_EVAL
7080 /* 'foldexpr' */
7081 else if (varp == &curwin->w_p_fde)
7082 {
7083 if (foldmethodIsExpr(curwin))
7084 foldUpdateAll(curwin);
7085 }
7086# endif
7087 /* 'foldmarker' */
7088 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7089 {
7090 p = vim_strchr(*varp, ',');
7091 if (p == NULL)
7092 errmsg = (char_u *)N_("E536: comma required");
7093 else if (p == *varp || p[1] == NUL)
7094 errmsg = e_invarg;
7095 else if (foldmethodIsMarker(curwin))
7096 foldUpdateAll(curwin);
7097 }
7098 /* 'commentstring' */
7099 else if (gvarp == &p_cms)
7100 {
7101 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7102 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7103 }
7104 /* 'foldopen' */
7105 else if (varp == &p_fdo)
7106 {
7107 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7108 errmsg = e_invarg;
7109 }
7110 /* 'foldclose' */
7111 else if (varp == &p_fcl)
7112 {
7113 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7114 errmsg = e_invarg;
7115 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007116 /* 'foldignore' */
7117 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7118 {
7119 if (foldmethodIsIndent(curwin))
7120 foldUpdateAll(curwin);
7121 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122#endif
7123
7124#ifdef FEAT_VIRTUALEDIT
7125 /* 'virtualedit' */
7126 else if (varp == &p_ve)
7127 {
7128 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7129 errmsg = e_invarg;
7130 else if (STRCMP(p_ve, oldval) != 0)
7131 {
7132 /* Recompute cursor position in case the new 've' setting
7133 * changes something. */
7134 validate_virtcol();
7135 coladvance(curwin->w_virtcol);
7136 }
7137 }
7138#endif
7139
7140#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7141 else if (varp == &p_csqf)
7142 {
7143 if (p_csqf != NULL)
7144 {
7145 p = p_csqf;
7146 while (*p != NUL)
7147 {
7148 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7149 || p[1] == NUL
7150 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7151 || (p[2] != NUL && p[2] != ','))
7152 {
7153 errmsg = e_invarg;
7154 break;
7155 }
7156 else if (p[2] == NUL)
7157 break;
7158 else
7159 p += 3;
7160 }
7161 }
7162 }
7163#endif
7164
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007165#ifdef FEAT_CINDENT
7166 /* 'cinoptions' */
7167 else if (gvarp == &p_cino)
7168 {
7169 /* TODO: recognize errors */
7170 parse_cino(curbuf);
7171 }
7172#endif
7173
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007174#if defined(FEAT_RENDER_OPTIONS)
7175 else if (varp == &p_rop && gui.in_use)
7176 {
7177 if (!gui_mch_set_rendering_options(p_rop))
7178 errmsg = e_invarg;
7179 }
7180#endif
7181
Bram Moolenaar071d4272004-06-13 20:20:40 +00007182 /* Options that are a list of flags. */
7183 else
7184 {
7185 p = NULL;
7186 if (varp == &p_ww)
7187 p = (char_u *)WW_ALL;
7188 if (varp == &p_shm)
7189 p = (char_u *)SHM_ALL;
7190 else if (varp == &(p_cpo))
7191 p = (char_u *)CPO_ALL;
7192 else if (varp == &(curbuf->b_p_fo))
7193 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007194#ifdef FEAT_CONCEAL
7195 else if (varp == &curwin->w_p_cocu)
7196 p = (char_u *)COCU_ALL;
7197#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198 else if (varp == &p_mouse)
7199 {
7200#ifdef FEAT_MOUSE
7201 p = (char_u *)MOUSE_ALL;
7202#else
7203 if (*p_mouse != NUL)
7204 errmsg = (char_u *)N_("E538: No mouse support");
7205#endif
7206 }
7207#if defined(FEAT_GUI)
7208 else if (varp == &p_go)
7209 p = (char_u *)GO_ALL;
7210#endif
7211 if (p != NULL)
7212 {
7213 for (s = *varp; *s; ++s)
7214 if (vim_strchr(p, *s) == NULL)
7215 {
7216 errmsg = illegal_char(errbuf, *s);
7217 break;
7218 }
7219 }
7220 }
7221
7222 /*
7223 * If error detected, restore the previous value.
7224 */
7225 if (errmsg != NULL)
7226 {
7227 if (new_value_alloced)
7228 free_string_option(*varp);
7229 *varp = oldval;
7230 /*
7231 * When resetting some values, need to act on it.
7232 */
7233 if (did_chartab)
7234 (void)init_chartab();
7235 if (varp == &p_hl)
7236 (void)highlight_changed();
7237 }
7238 else
7239 {
7240#ifdef FEAT_EVAL
7241 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007242 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007243#endif
7244 /*
7245 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007246 * Use "free_oldval", because recursiveness may change the flags under
7247 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007248 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007249 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007250 free_string_option(oldval);
7251 if (new_value_alloced)
7252 options[opt_idx].flags |= P_ALLOCED;
7253 else
7254 options[opt_idx].flags &= ~P_ALLOCED;
7255
7256 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007257 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007258 {
7259 /* global option with local value set to use global value; free
7260 * the local value and make it empty */
7261 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7262 free_string_option(*(char_u **)p);
7263 *(char_u **)p = empty_option;
7264 }
7265
7266 /* May set global value for local option. */
7267 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7268 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007269
7270#ifdef FEAT_AUTOCMD
7271 /*
7272 * Trigger the autocommand only after setting the flags.
7273 */
7274# ifdef FEAT_SYN_HL
7275 /* When 'syntax' is set, load the syntax of that name */
7276 if (varp == &(curbuf->b_p_syn))
7277 {
7278 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7279 curbuf->b_fname, TRUE, curbuf);
7280 }
7281# endif
7282 else if (varp == &(curbuf->b_p_ft))
7283 {
7284 /* 'filetype' is set, trigger the FileType autocommand */
7285 did_filetype = TRUE;
7286 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7287 curbuf->b_fname, TRUE, curbuf);
7288 }
7289#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007290#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007291 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007292 {
7293 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007294 char_u *q = curwin->w_s->b_p_spl;
7295
7296 /* Skip the first name if it is "cjk". */
7297 if (STRNCMP(q, "cjk,", 4) == 0)
7298 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007299
7300 /*
7301 * Source the spell/LANG.vim in 'runtimepath'.
7302 * They could set 'spellcapcheck' depending on the language.
7303 * Use the first name in 'spelllang' up to '_region' or
7304 * '.encoding'.
7305 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007306 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007307 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7308 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007309 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007310 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007311 }
7312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313 }
7314
7315#ifdef FEAT_MOUSE
7316 if (varp == &p_mouse)
7317 {
7318# ifdef FEAT_MOUSE_TTY
7319 if (*p_mouse == NUL)
7320 mch_setmouse(FALSE); /* switch mouse off */
7321 else
7322# endif
7323 setmouse(); /* in case 'mouse' changed */
7324 }
7325#endif
7326
Bram Moolenaar913077c2012-03-28 19:59:04 +02007327 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007328 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007329 curwin->w_set_curswant = TRUE;
7330
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007331#ifdef FEAT_GUI
7332 /* check redraw when it's not a GUI option or the GUI is active. */
7333 if (!redraw_gui_only || gui.in_use)
7334#endif
7335 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336
7337 return errmsg;
7338}
7339
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007340#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007341/*
7342 * Simple int comparison function for use with qsort()
7343 */
7344 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007345int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007346{
7347 return *(const int *)a - *(const int *)b;
7348}
7349
7350/*
7351 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7352 * Returns error message, NULL if it's OK.
7353 */
7354 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007355check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007356{
7357 char_u *s;
7358 int col;
7359 int count = 0;
7360 int color_cols[256];
7361 int i;
7362 int j = 0;
7363
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007364 if (wp->w_buffer == NULL)
7365 return NULL; /* buffer was closed */
7366
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007367 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007368 {
7369 if (*s == '-' || *s == '+')
7370 {
7371 /* -N and +N: add to 'textwidth' */
7372 col = (*s == '-') ? -1 : 1;
7373 ++s;
7374 if (!VIM_ISDIGIT(*s))
7375 return e_invarg;
7376 col = col * getdigits(&s);
7377 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007378 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007379 col += wp->w_buffer->b_p_tw;
7380 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007381 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007382 }
7383 else if (VIM_ISDIGIT(*s))
7384 col = getdigits(&s);
7385 else
7386 return e_invarg;
7387 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007388skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007389 if (*s == NUL)
7390 break;
7391 if (*s != ',')
7392 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007393 if (*++s == NUL)
7394 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007395 }
7396
7397 vim_free(wp->w_p_cc_cols);
7398 if (count == 0)
7399 wp->w_p_cc_cols = NULL;
7400 else
7401 {
7402 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7403 if (wp->w_p_cc_cols != NULL)
7404 {
7405 /* sort the columns for faster usage on screen redraw inside
7406 * win_line() */
7407 qsort(color_cols, count, sizeof(int), int_cmp);
7408
7409 for (i = 0; i < count; ++i)
7410 /* skip duplicates */
7411 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7412 wp->w_p_cc_cols[j++] = color_cols[i];
7413 wp->w_p_cc_cols[j] = -1; /* end marker */
7414 }
7415 }
7416
7417 return NULL; /* no error */
7418}
7419#endif
7420
Bram Moolenaar071d4272004-06-13 20:20:40 +00007421/*
7422 * Handle setting 'listchars' or 'fillchars'.
7423 * Returns error message, NULL if it's OK.
7424 */
7425 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007426set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007427{
7428 int round, i, len, entries;
7429 char_u *p, *s;
7430 int c1, c2 = 0;
7431 struct charstab
7432 {
7433 int *cp;
7434 char *name;
7435 };
7436#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7437 static struct charstab filltab[] =
7438 {
7439 {&fill_stl, "stl"},
7440 {&fill_stlnc, "stlnc"},
7441 {&fill_vert, "vert"},
7442 {&fill_fold, "fold"},
7443 {&fill_diff, "diff"},
7444 };
7445#endif
7446 static struct charstab lcstab[] =
7447 {
7448 {&lcs_eol, "eol"},
7449 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007450 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007451 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007452 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007453 {&lcs_tab2, "tab"},
7454 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007455#ifdef FEAT_CONCEAL
7456 {&lcs_conceal, "conceal"},
7457#else
7458 {NULL, "conceal"},
7459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460 };
7461 struct charstab *tab;
7462
7463#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7464 if (varp == &p_lcs)
7465#endif
7466 {
7467 tab = lcstab;
7468 entries = sizeof(lcstab) / sizeof(struct charstab);
7469 }
7470#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7471 else
7472 {
7473 tab = filltab;
7474 entries = sizeof(filltab) / sizeof(struct charstab);
7475 }
7476#endif
7477
7478 /* first round: check for valid value, second round: assign values */
7479 for (round = 0; round <= 1; ++round)
7480 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007481 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 {
7483 /* After checking that the value is valid: set defaults: space for
7484 * 'fillchars', NUL for 'listchars' */
7485 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007486 if (tab[i].cp != NULL)
7487 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488 if (varp == &p_lcs)
7489 lcs_tab1 = NUL;
7490#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7491 else
7492 fill_diff = '-';
7493#endif
7494 }
7495 p = *varp;
7496 while (*p)
7497 {
7498 for (i = 0; i < entries; ++i)
7499 {
7500 len = (int)STRLEN(tab[i].name);
7501 if (STRNCMP(p, tab[i].name, len) == 0
7502 && p[len] == ':'
7503 && p[len + 1] != NUL)
7504 {
7505 s = p + len + 1;
7506#ifdef FEAT_MBYTE
7507 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007508 if (mb_char2cells(c1) > 1)
7509 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510#else
7511 c1 = *s++;
7512#endif
7513 if (tab[i].cp == &lcs_tab2)
7514 {
7515 if (*s == NUL)
7516 continue;
7517#ifdef FEAT_MBYTE
7518 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007519 if (mb_char2cells(c2) > 1)
7520 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521#else
7522 c2 = *s++;
7523#endif
7524 }
7525 if (*s == ',' || *s == NUL)
7526 {
7527 if (round)
7528 {
7529 if (tab[i].cp == &lcs_tab2)
7530 {
7531 lcs_tab1 = c1;
7532 lcs_tab2 = c2;
7533 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007534 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007535 *(tab[i].cp) = c1;
7536
7537 }
7538 p = s;
7539 break;
7540 }
7541 }
7542 }
7543
7544 if (i == entries)
7545 return e_invarg;
7546 if (*p == ',')
7547 ++p;
7548 }
7549 }
7550
7551 return NULL; /* no error */
7552}
7553
7554#ifdef FEAT_STL_OPT
7555/*
7556 * Check validity of options with the 'statusline' format.
7557 * Return error message or NULL.
7558 */
7559 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007560check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007561{
7562 int itemcnt = 0;
7563 int groupdepth = 0;
7564 static char_u errbuf[80];
7565
7566 while (*s && itemcnt < STL_MAX_ITEM)
7567 {
7568 /* Check for valid keys after % sequences */
7569 while (*s && *s != '%')
7570 s++;
7571 if (!*s)
7572 break;
7573 s++;
7574 if (*s != '%' && *s != ')')
7575 ++itemcnt;
7576 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7577 {
7578 s++;
7579 continue;
7580 }
7581 if (*s == ')')
7582 {
7583 s++;
7584 if (--groupdepth < 0)
7585 break;
7586 continue;
7587 }
7588 if (*s == '-')
7589 s++;
7590 while (VIM_ISDIGIT(*s))
7591 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007592 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007593 continue;
7594 if (*s == '.')
7595 {
7596 s++;
7597 while (*s && VIM_ISDIGIT(*s))
7598 s++;
7599 }
7600 if (*s == '(')
7601 {
7602 groupdepth++;
7603 continue;
7604 }
7605 if (vim_strchr(STL_ALL, *s) == NULL)
7606 {
7607 return illegal_char(errbuf, *s);
7608 }
7609 if (*s == '{')
7610 {
7611 s++;
7612 while (*s != '}' && *s)
7613 s++;
7614 if (*s != '}')
7615 return (char_u *)N_("E540: Unclosed expression sequence");
7616 }
7617 }
7618 if (itemcnt >= STL_MAX_ITEM)
7619 return (char_u *)N_("E541: too many items");
7620 if (groupdepth != 0)
7621 return (char_u *)N_("E542: unbalanced groups");
7622 return NULL;
7623}
7624#endif
7625
7626#ifdef FEAT_CLIPBOARD
7627/*
7628 * Extract the items in the 'clipboard' option and set global values.
7629 */
7630 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007631check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007632{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007633 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007634 int new_autoselect_star = FALSE;
7635 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007637 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007638 regprog_T *new_exclude_prog = NULL;
7639 char_u *errmsg = NULL;
7640 char_u *p;
7641
7642 for (p = p_cb; *p != NUL; )
7643 {
7644 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7645 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007646 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647 p += 7;
7648 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007649 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007650 && (p[11] == ',' || p[11] == NUL))
7651 {
7652 new_unnamed |= CLIP_UNNAMED_PLUS;
7653 p += 11;
7654 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007655 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007656 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007657 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007658 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 p += 10;
7660 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007661 else if (STRNCMP(p, "autoselectplus", 14) == 0
7662 && (p[14] == ',' || p[14] == NUL))
7663 {
7664 new_autoselect_plus = TRUE;
7665 p += 14;
7666 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007667 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007668 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007669 {
7670 new_autoselectml = TRUE;
7671 p += 12;
7672 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007673 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7674 {
7675 new_html = TRUE;
7676 p += 4;
7677 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007678 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7679 {
7680 p += 8;
7681 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7682 if (new_exclude_prog == NULL)
7683 errmsg = e_invarg;
7684 break;
7685 }
7686 else
7687 {
7688 errmsg = e_invarg;
7689 break;
7690 }
7691 if (*p == ',')
7692 ++p;
7693 }
7694 if (errmsg == NULL)
7695 {
7696 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007697 clip_autoselect_star = new_autoselect_star;
7698 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007699 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007700 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007701 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007702 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007703#ifdef FEAT_GUI_GTK
7704 if (gui.in_use)
7705 {
7706 gui_gtk_set_selection_targets();
7707 gui_gtk_set_dnd_targets();
7708 }
7709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710 }
7711 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007712 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713
7714 return errmsg;
7715}
7716#endif
7717
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007718#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007719 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007720did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007721{
7722 char_u *errmsg = NULL;
7723 win_T *wp;
7724 int l;
7725
7726 if (is_spellfile)
7727 {
7728 l = (int)STRLEN(curwin->w_s->b_p_spf);
7729 if (l > 0 && (l < 4
7730 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7731 errmsg = e_invarg;
7732 }
7733
7734 if (errmsg == NULL)
7735 {
7736 FOR_ALL_WINDOWS(wp)
7737 if (wp->w_buffer == curbuf && wp->w_p_spell)
7738 {
7739 errmsg = did_set_spelllang(wp);
7740# ifdef FEAT_WINDOWS
7741 break;
7742# endif
7743 }
7744 }
7745 return errmsg;
7746}
7747
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007748/*
7749 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7750 * Return error message when failed, NULL when OK.
7751 */
7752 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007753compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007754{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007755 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007756 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007757
Bram Moolenaar860cae12010-06-05 23:22:07 +02007758 if (*synblock->b_p_spc == NUL)
7759 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007760 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007761 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007762 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007763 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007764 if (re != NULL)
7765 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007766 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007767 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007768 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007769 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007770 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007771 return e_invarg;
7772 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007773 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007774 }
7775
Bram Moolenaar473de612013-06-08 18:19:48 +02007776 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007777 return NULL;
7778}
7779#endif
7780
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007781#if defined(FEAT_EVAL) || defined(PROTO)
7782/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007783 * Set the scriptID for an option, taking care of setting the buffer- or
7784 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007785 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007786 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007787set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007788{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007789 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7790 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007791
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007792 /* Remember where the option was set. For local options need to do that
7793 * in the buffer or window structure. */
7794 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007795 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007796 if (both || (opt_flags & OPT_LOCAL))
7797 {
7798 if (indir & PV_BUF)
7799 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7800 else if (indir & PV_WIN)
7801 curwin->w_p_scriptID[indir & PV_MASK] = id;
7802 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007803}
7804#endif
7805
Bram Moolenaar071d4272004-06-13 20:20:40 +00007806/*
7807 * Set the value of a boolean option, and take care of side effects.
7808 * Returns NULL for success, or an error message for an error.
7809 */
7810 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007811set_bool_option(
7812 int opt_idx, /* index in options[] table */
7813 char_u *varp, /* pointer to the option variable */
7814 int value, /* new value */
7815 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816{
7817 int old_value = *(int *)varp;
7818
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819 /* Disallow changing some options from secure mode */
7820 if ((secure
7821#ifdef HAVE_SANDBOX
7822 || sandbox != 0
7823#endif
7824 ) && (options[opt_idx].flags & P_SECURE))
7825 return e_secure;
7826
7827 *(int *)varp = value; /* set the new value */
7828#ifdef FEAT_EVAL
7829 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007830 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007831#endif
7832
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007833#ifdef FEAT_GUI
7834 need_mouse_correct = TRUE;
7835#endif
7836
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837 /* May set global value for local option. */
7838 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7839 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7840
7841 /*
7842 * Handle side effects of changing a bool option.
7843 */
7844
7845 /* 'compatible' */
7846 if ((int *)varp == &p_cp)
7847 {
7848 compatible_set();
7849 }
7850
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007851#ifdef FEAT_PERSISTENT_UNDO
7852 /* 'undofile' */
7853 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7854 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007855 /* Only take action when the option was set. When reset we do not
7856 * delete the undo file, the option may be set again without making
7857 * any changes in between. */
7858 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007859 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007860 char_u hash[UNDO_HASH_SIZE];
7861 buf_T *save_curbuf = curbuf;
7862
7863 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007864 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007865 /* When 'undofile' is set globally: for every buffer, otherwise
7866 * only for the current buffer: Try to read in the undofile,
7867 * if one exists, the buffer wasn't changed and the buffer was
7868 * loaded */
7869 if ((curbuf == save_curbuf
7870 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7871 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7872 {
7873 u_compute_hash(hash);
7874 u_read_undo(NULL, hash, curbuf->b_fname);
7875 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007876 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007877 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007878 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007879 }
7880#endif
7881
Bram Moolenaar071d4272004-06-13 20:20:40 +00007882 else if ((int *)varp == &curbuf->b_p_ro)
7883 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007884 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007885 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7886 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007887
7888 /* when 'readonly' is set may give W10 again */
7889 if (curbuf->b_p_ro)
7890 curbuf->b_did_warn = FALSE;
7891
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007893 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894#endif
7895 }
7896
Bram Moolenaar9c449722010-07-20 18:44:27 +02007897#ifdef FEAT_GUI
7898 else if ((int *)varp == &p_mh)
7899 {
7900 if (!p_mh)
7901 gui_mch_mousehide(FALSE);
7902 }
7903#endif
7904
Bram Moolenaara539df02010-08-01 14:35:05 +02007905#ifdef FEAT_TITLE
7906 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007908 {
7909 redraw_titles();
7910 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911 /* when 'endofline' is changed, redraw the window title */
7912 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007913 {
7914 redraw_titles();
7915 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007916 /* when 'fixeol' is changed, redraw the window title */
7917 else if ((int *)varp == &curbuf->b_p_fixeol)
7918 {
7919 redraw_titles();
7920 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007921# ifdef FEAT_MBYTE
7922 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007923 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007924 {
7925 redraw_titles();
7926 }
7927# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928#endif
7929
7930 /* when 'bin' is set also set some other options */
7931 else if ((int *)varp == &curbuf->b_p_bin)
7932 {
7933 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7934#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007935 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936#endif
7937 }
7938
7939#ifdef FEAT_AUTOCMD
7940 /* when 'buflisted' changes, trigger autocommands */
7941 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7942 {
7943 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7944 NULL, NULL, TRUE, curbuf);
7945 }
7946#endif
7947
7948 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7949 else if ((int *)varp == &curbuf->b_p_swf)
7950 {
7951 if (curbuf->b_p_swf && p_uc)
7952 ml_open_file(curbuf); /* create the swap file */
7953 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007954 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7955 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 mf_close_file(curbuf, TRUE); /* remove the swap file */
7957 }
7958
7959 /* when 'terse' is set change 'shortmess' */
7960 else if ((int *)varp == &p_terse)
7961 {
7962 char_u *p;
7963
7964 p = vim_strchr(p_shm, SHM_SEARCH);
7965
7966 /* insert 's' in p_shm */
7967 if (p_terse && p == NULL)
7968 {
7969 STRCPY(IObuff, p_shm);
7970 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007971 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 }
7973 /* remove 's' from p_shm */
7974 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007975 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976 }
7977
7978 /* when 'paste' is set or reset also change other options */
7979 else if ((int *)varp == &p_paste)
7980 {
7981 paste_option_changed();
7982 }
7983
7984 /* when 'insertmode' is set from an autocommand need to do work here */
7985 else if ((int *)varp == &p_im)
7986 {
7987 if (p_im)
7988 {
7989 if ((State & INSERT) == 0)
7990 need_start_insertmode = TRUE;
7991 stop_insert_mode = FALSE;
7992 }
7993 else
7994 {
7995 need_start_insertmode = FALSE;
7996 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007997 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007998 clear_cmdline = TRUE; /* remove "(insert)" */
7999 restart_edit = 0;
8000 }
8001 }
8002
8003 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8004 else if ((int *)varp == &p_ic && p_hls)
8005 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008006 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 }
8008
8009#ifdef FEAT_SEARCH_EXTRA
8010 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8011 else if ((int *)varp == &p_hls)
8012 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008013 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014 }
8015#endif
8016
8017#ifdef FEAT_SCROLLBIND
8018 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8019 * at the end of normal_cmd() */
8020 else if ((int *)varp == &curwin->w_p_scb)
8021 {
8022 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008023 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008024 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008025 curwin->w_scbind_pos = curwin->w_topline;
8026 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008027 }
8028#endif
8029
8030#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8031 /* There can be only one window with 'previewwindow' set. */
8032 else if ((int *)varp == &curwin->w_p_pvw)
8033 {
8034 if (curwin->w_p_pvw)
8035 {
8036 win_T *win;
8037
8038 for (win = firstwin; win != NULL; win = win->w_next)
8039 if (win->w_p_pvw && win != curwin)
8040 {
8041 curwin->w_p_pvw = FALSE;
8042 return (char_u *)N_("E590: A preview window already exists");
8043 }
8044 }
8045 }
8046#endif
8047
8048 /* when 'textmode' is set or reset also change 'fileformat' */
8049 else if ((int *)varp == &curbuf->b_p_tx)
8050 {
8051 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8052 }
8053
8054 /* when 'textauto' is set or reset also change 'fileformats' */
8055 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 set_string_option_direct((char_u *)"ffs", -1,
8057 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008058 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008059
8060 /*
8061 * When 'lisp' option changes include/exclude '-' in
8062 * keyword characters.
8063 */
8064#ifdef FEAT_LISP
8065 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8066 {
8067 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8068 }
8069#endif
8070
8071#ifdef FEAT_TITLE
8072 /* when 'title' changed, may need to change the title; same for 'icon' */
8073 else if ((int *)varp == &p_title)
8074 {
8075 did_set_title(FALSE);
8076 }
8077
8078 else if ((int *)varp == &p_icon)
8079 {
8080 did_set_title(TRUE);
8081 }
8082#endif
8083
8084 else if ((int *)varp == &curbuf->b_changed)
8085 {
8086 if (!value)
8087 save_file_ff(curbuf); /* Buffer is unchanged */
8088#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008089 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008090#endif
8091#ifdef FEAT_AUTOCMD
8092 modified_was_set = value;
8093#endif
8094 }
8095
8096#ifdef BACKSLASH_IN_FILENAME
8097 else if ((int *)varp == &p_ssl)
8098 {
8099 if (p_ssl)
8100 {
8101 psepc = '/';
8102 psepcN = '\\';
8103 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 }
8105 else
8106 {
8107 psepc = '\\';
8108 psepcN = '/';
8109 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008110 }
8111
8112 /* need to adjust the file name arguments and buffer names. */
8113 buflist_slash_adjust();
8114 alist_slash_adjust();
8115# ifdef FEAT_EVAL
8116 scriptnames_slash_adjust();
8117# endif
8118 }
8119#endif
8120
8121 /* If 'wrap' is set, set w_leftcol to zero. */
8122 else if ((int *)varp == &curwin->w_p_wrap)
8123 {
8124 if (curwin->w_p_wrap)
8125 curwin->w_leftcol = 0;
8126 }
8127
8128#ifdef FEAT_WINDOWS
8129 else if ((int *)varp == &p_ea)
8130 {
8131 if (p_ea && !old_value)
8132 win_equal(curwin, FALSE, 0);
8133 }
8134#endif
8135
8136 else if ((int *)varp == &p_wiv)
8137 {
8138 /*
8139 * When 'weirdinvert' changed, set/reset 't_xs'.
8140 * Then set 'weirdinvert' according to value of 't_xs'.
8141 */
8142 if (p_wiv && !old_value)
8143 T_XS = (char_u *)"y";
8144 else if (!p_wiv && old_value)
8145 T_XS = empty_option;
8146 p_wiv = (*T_XS != NUL);
8147 }
8148
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008149#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 else if ((int *)varp == &p_beval)
8151 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008152 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008154 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 gui_mch_disable_beval_area(balloonEval);
8156 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008159#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 else if ((int *)varp == &p_acd)
8161 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008162 /* Change directories when the 'acd' option is set now. */
8163 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164 }
8165#endif
8166
8167#ifdef FEAT_DIFF
8168 /* 'diff' */
8169 else if ((int *)varp == &curwin->w_p_diff)
8170 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008171 /* May add or remove the buffer from the list of diff buffers. */
8172 diff_buf_adjust(curwin);
8173# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008174 if (foldmethodIsDiff(curwin))
8175 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008176# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008177 }
8178#endif
8179
8180#ifdef USE_IM_CONTROL
8181 /* 'imdisable' */
8182 else if ((int *)varp == &p_imdisable)
8183 {
8184 /* Only de-activate it here, it will be enabled when changing mode. */
8185 if (p_imdisable)
8186 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008187 else if (State & INSERT)
8188 /* When the option is set from an autocommand, it may need to take
8189 * effect right away. */
8190 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008191 }
8192#endif
8193
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008194#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008195 /* 'spell' */
8196 else if ((int *)varp == &curwin->w_p_spell)
8197 {
8198 if (curwin->w_p_spell)
8199 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008200 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008201 if (errmsg != NULL)
8202 EMSG(_(errmsg));
8203 }
8204 }
8205#endif
8206
Bram Moolenaar071d4272004-06-13 20:20:40 +00008207#ifdef FEAT_FKMAP
8208 else if ((int *)varp == &p_altkeymap)
8209 {
8210 if (old_value != p_altkeymap)
8211 {
8212 if (!p_altkeymap)
8213 {
8214 p_hkmap = p_fkmap;
8215 p_fkmap = 0;
8216 }
8217 else
8218 {
8219 p_fkmap = p_hkmap;
8220 p_hkmap = 0;
8221 }
8222 (void)init_chartab();
8223 }
8224 }
8225
8226 /*
8227 * In case some second language keymapping options have changed, check
8228 * and correct the setting in a consistent way.
8229 */
8230
8231 /*
8232 * If hkmap or fkmap are set, reset Arabic keymapping.
8233 */
8234 if ((p_hkmap || p_fkmap) && p_altkeymap)
8235 {
8236 p_altkeymap = p_fkmap;
8237# ifdef FEAT_ARABIC
8238 curwin->w_p_arab = FALSE;
8239# endif
8240 (void)init_chartab();
8241 }
8242
8243 /*
8244 * If hkmap set, reset Farsi keymapping.
8245 */
8246 if (p_hkmap && p_altkeymap)
8247 {
8248 p_altkeymap = 0;
8249 p_fkmap = 0;
8250# ifdef FEAT_ARABIC
8251 curwin->w_p_arab = FALSE;
8252# endif
8253 (void)init_chartab();
8254 }
8255
8256 /*
8257 * If fkmap set, reset Hebrew keymapping.
8258 */
8259 if (p_fkmap && !p_altkeymap)
8260 {
8261 p_altkeymap = 1;
8262 p_hkmap = 0;
8263# ifdef FEAT_ARABIC
8264 curwin->w_p_arab = FALSE;
8265# endif
8266 (void)init_chartab();
8267 }
8268#endif
8269
8270#ifdef FEAT_ARABIC
8271 if ((int *)varp == &curwin->w_p_arab)
8272 {
8273 if (curwin->w_p_arab)
8274 {
8275 /*
8276 * 'arabic' is set, handle various sub-settings.
8277 */
8278 if (!p_tbidi)
8279 {
8280 /* set rightleft mode */
8281 if (!curwin->w_p_rl)
8282 {
8283 curwin->w_p_rl = TRUE;
8284 changed_window_setting();
8285 }
8286
8287 /* Enable Arabic shaping (major part of what Arabic requires) */
8288 if (!p_arshape)
8289 {
8290 p_arshape = TRUE;
8291 redraw_later_clear();
8292 }
8293 }
8294
8295 /* Arabic requires a utf-8 encoding, inform the user if its not
8296 * set. */
8297 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008298 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008299 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8300
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008301 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008302 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8303#ifdef FEAT_EVAL
8304 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8305#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008306 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008307
8308# ifdef FEAT_MBYTE
8309 /* set 'delcombine' */
8310 p_deco = TRUE;
8311# endif
8312
8313# ifdef FEAT_KEYMAP
8314 /* Force-set the necessary keymap for arabic */
8315 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8316 OPT_LOCAL);
8317# endif
8318# ifdef FEAT_FKMAP
8319 p_altkeymap = 0;
8320 p_hkmap = 0;
8321 p_fkmap = 0;
8322 (void)init_chartab();
8323# endif
8324 }
8325 else
8326 {
8327 /*
8328 * 'arabic' is reset, handle various sub-settings.
8329 */
8330 if (!p_tbidi)
8331 {
8332 /* reset rightleft mode */
8333 if (curwin->w_p_rl)
8334 {
8335 curwin->w_p_rl = FALSE;
8336 changed_window_setting();
8337 }
8338
8339 /* 'arabicshape' isn't reset, it is a global option and
8340 * another window may still need it "on". */
8341 }
8342
8343 /* 'delcombine' isn't reset, it is a global option and another
8344 * window may still want it "on". */
8345
8346# ifdef FEAT_KEYMAP
8347 /* Revert to the default keymap */
8348 curbuf->b_p_iminsert = B_IMODE_NONE;
8349 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8350# endif
8351 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008352 }
8353
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008354#endif
8355
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356 /*
8357 * End of handling side effects for bool options.
8358 */
8359
Bram Moolenaar53744302015-07-17 17:38:22 +02008360 /* after handling side effects, call autocommand */
8361
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362 options[opt_idx].flags |= P_WAS_SET;
8363
Bram Moolenaar53744302015-07-17 17:38:22 +02008364#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8365 if (!starting)
8366 {
8367 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008368 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8369 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8370 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008371 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8372 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8373 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8374 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8375 reset_v_option_vars();
8376 }
8377#endif
8378
Bram Moolenaar071d4272004-06-13 20:20:40 +00008379 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008380 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008381 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008382 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 check_redraw(options[opt_idx].flags);
8384
8385 return NULL;
8386}
8387
8388/*
8389 * Set the value of a number option, and take care of side effects.
8390 * Returns NULL for success, or an error message for an error.
8391 */
8392 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008393set_num_option(
8394 int opt_idx, /* index in options[] table */
8395 char_u *varp, /* pointer to the option variable */
8396 long value, /* new value */
8397 char_u *errbuf, /* buffer for error messages */
8398 size_t errbuflen, /* length of "errbuf" */
8399 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400 OPT_MODELINE */
8401{
8402 char_u *errmsg = NULL;
8403 long old_value = *(long *)varp;
8404 long old_Rows = Rows; /* remember old Rows */
8405 long old_Columns = Columns; /* remember old Columns */
8406 long *pp = (long *)varp;
8407
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008408 /* Disallow changing some options from secure mode. */
8409 if ((secure
8410#ifdef HAVE_SANDBOX
8411 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008413 ) && (options[opt_idx].flags & P_SECURE))
8414 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415
8416 *pp = value;
8417#ifdef FEAT_EVAL
8418 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008419 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008421#ifdef FEAT_GUI
8422 need_mouse_correct = TRUE;
8423#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424
Bram Moolenaar14f24742012-08-08 18:01:05 +02008425 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008426 {
8427 errmsg = e_positive;
8428 curbuf->b_p_sw = curbuf->b_p_ts;
8429 }
8430
8431 /*
8432 * Number options that need some action when changed
8433 */
8434#ifdef FEAT_WINDOWS
8435 if (pp == &p_wh || pp == &p_hh)
8436 {
8437 if (p_wh < 1)
8438 {
8439 errmsg = e_positive;
8440 p_wh = 1;
8441 }
8442 if (p_wmh > p_wh)
8443 {
8444 errmsg = e_winheight;
8445 p_wh = p_wmh;
8446 }
8447 if (p_hh < 0)
8448 {
8449 errmsg = e_positive;
8450 p_hh = 0;
8451 }
8452
8453 /* Change window height NOW */
8454 if (lastwin != firstwin)
8455 {
8456 if (pp == &p_wh && curwin->w_height < p_wh)
8457 win_setheight((int)p_wh);
8458 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8459 win_setheight((int)p_hh);
8460 }
8461 }
8462
8463 /* 'winminheight' */
8464 else if (pp == &p_wmh)
8465 {
8466 if (p_wmh < 0)
8467 {
8468 errmsg = e_positive;
8469 p_wmh = 0;
8470 }
8471 if (p_wmh > p_wh)
8472 {
8473 errmsg = e_winheight;
8474 p_wmh = p_wh;
8475 }
8476 win_setminheight();
8477 }
8478
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008479# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008480 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008481 {
8482 if (p_wiw < 1)
8483 {
8484 errmsg = e_positive;
8485 p_wiw = 1;
8486 }
8487 if (p_wmw > p_wiw)
8488 {
8489 errmsg = e_winwidth;
8490 p_wiw = p_wmw;
8491 }
8492
8493 /* Change window width NOW */
8494 if (lastwin != firstwin && curwin->w_width < p_wiw)
8495 win_setwidth((int)p_wiw);
8496 }
8497
8498 /* 'winminwidth' */
8499 else if (pp == &p_wmw)
8500 {
8501 if (p_wmw < 0)
8502 {
8503 errmsg = e_positive;
8504 p_wmw = 0;
8505 }
8506 if (p_wmw > p_wiw)
8507 {
8508 errmsg = e_winwidth;
8509 p_wmw = p_wiw;
8510 }
8511 win_setminheight();
8512 }
8513# endif
8514
8515#endif
8516
8517#ifdef FEAT_WINDOWS
8518 /* (re)set last window status line */
8519 else if (pp == &p_ls)
8520 {
8521 last_status(FALSE);
8522 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008523
8524 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008525 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008526 {
8527 shell_new_rows(); /* recompute window positions and heights */
8528 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529#endif
8530
8531#ifdef FEAT_GUI
8532 else if (pp == &p_linespace)
8533 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008534 /* Recompute gui.char_height and resize the Vim window to keep the
8535 * same number of lines. */
8536 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008537 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538 }
8539#endif
8540
8541#ifdef FEAT_FOLDING
8542 /* 'foldlevel' */
8543 else if (pp == &curwin->w_p_fdl)
8544 {
8545 if (curwin->w_p_fdl < 0)
8546 curwin->w_p_fdl = 0;
8547 newFoldLevel();
8548 }
8549
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008550 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551 else if (pp == &curwin->w_p_fml)
8552 {
8553 foldUpdateAll(curwin);
8554 }
8555
8556 /* 'foldnestmax' */
8557 else if (pp == &curwin->w_p_fdn)
8558 {
8559 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8560 foldUpdateAll(curwin);
8561 }
8562
8563 /* 'foldcolumn' */
8564 else if (pp == &curwin->w_p_fdc)
8565 {
8566 if (curwin->w_p_fdc < 0)
8567 {
8568 errmsg = e_positive;
8569 curwin->w_p_fdc = 0;
8570 }
8571 else if (curwin->w_p_fdc > 12)
8572 {
8573 errmsg = e_invarg;
8574 curwin->w_p_fdc = 12;
8575 }
8576 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008577#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008578
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008579#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008580 /* 'shiftwidth' or 'tabstop' */
8581 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8582 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008583# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008584 if (foldmethodIsIndent(curwin))
8585 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008586# endif
8587# ifdef FEAT_CINDENT
8588 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8589 * parse 'cinoptions'. */
8590 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8591 parse_cino(curbuf);
8592# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008593 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008594#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008595
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008596#ifdef FEAT_MBYTE
8597 /* 'maxcombine' */
8598 else if (pp == &p_mco)
8599 {
8600 if (p_mco > MAX_MCO)
8601 p_mco = MAX_MCO;
8602 else if (p_mco < 0)
8603 p_mco = 0;
8604 screenclear(); /* will re-allocate the screen */
8605 }
8606#endif
8607
Bram Moolenaar071d4272004-06-13 20:20:40 +00008608 else if (pp == &curbuf->b_p_iminsert)
8609 {
8610 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8611 {
8612 errmsg = e_invarg;
8613 curbuf->b_p_iminsert = B_IMODE_NONE;
8614 }
8615 p_iminsert = curbuf->b_p_iminsert;
8616 if (termcap_active) /* don't do this in the alternate screen */
8617 showmode();
8618#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8619 /* Show/unshow value of 'keymap' in status lines. */
8620 status_redraw_curbuf();
8621#endif
8622 }
8623
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008624 else if (pp == &p_window)
8625 {
8626 if (p_window < 1)
8627 p_window = 1;
8628 else if (p_window >= Rows)
8629 p_window = Rows - 1;
8630 }
8631
Bram Moolenaar071d4272004-06-13 20:20:40 +00008632 else if (pp == &curbuf->b_p_imsearch)
8633 {
8634 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8635 {
8636 errmsg = e_invarg;
8637 curbuf->b_p_imsearch = B_IMODE_NONE;
8638 }
8639 p_imsearch = curbuf->b_p_imsearch;
8640 }
8641
8642#ifdef FEAT_TITLE
8643 /* if 'titlelen' has changed, redraw the title */
8644 else if (pp == &p_titlelen)
8645 {
8646 if (p_titlelen < 0)
8647 {
8648 errmsg = e_positive;
8649 p_titlelen = 85;
8650 }
8651 if (starting != NO_SCREEN && old_value != p_titlelen)
8652 need_maketitle = TRUE;
8653 }
8654#endif
8655
8656 /* if p_ch changed value, change the command line height */
8657 else if (pp == &p_ch)
8658 {
8659 if (p_ch < 1)
8660 {
8661 errmsg = e_positive;
8662 p_ch = 1;
8663 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008664 if (p_ch > Rows - min_rows() + 1)
8665 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008666
8667 /* Only compute the new window layout when startup has been
8668 * completed. Otherwise the frame sizes may be wrong. */
8669 if (p_ch != old_value && full_screen
8670#ifdef FEAT_GUI
8671 && !gui.starting
8672#endif
8673 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008674 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008675 }
8676
8677 /* when 'updatecount' changes from zero to non-zero, open swap files */
8678 else if (pp == &p_uc)
8679 {
8680 if (p_uc < 0)
8681 {
8682 errmsg = e_positive;
8683 p_uc = 100;
8684 }
8685 if (p_uc && !old_value)
8686 ml_open_files();
8687 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008688#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008689 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008690 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008691 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008692 {
8693 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008694 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008695 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008696 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008697 {
8698 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008699 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008700 }
8701 }
8702#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008703#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008704 else if (pp == &p_mzq)
8705 mzvim_reset_timer();
8706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008707
8708 /* sync undo before 'undolevels' changes */
8709 else if (pp == &p_ul)
8710 {
8711 /* use the old value, otherwise u_sync() may not work properly */
8712 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008713 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714 p_ul = value;
8715 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008716 else if (pp == &curbuf->b_p_ul)
8717 {
8718 /* use the old value, otherwise u_sync() may not work properly */
8719 curbuf->b_p_ul = old_value;
8720 u_sync(TRUE);
8721 curbuf->b_p_ul = value;
8722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008724#ifdef FEAT_LINEBREAK
8725 /* 'numberwidth' must be positive */
8726 else if (pp == &curwin->w_p_nuw)
8727 {
8728 if (curwin->w_p_nuw < 1)
8729 {
8730 errmsg = e_positive;
8731 curwin->w_p_nuw = 1;
8732 }
8733 if (curwin->w_p_nuw > 10)
8734 {
8735 errmsg = e_invarg;
8736 curwin->w_p_nuw = 10;
8737 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008738 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008739 }
8740#endif
8741
Bram Moolenaar1a384422010-07-14 19:53:30 +02008742 else if (pp == &curbuf->b_p_tw)
8743 {
8744 if (curbuf->b_p_tw < 0)
8745 {
8746 errmsg = e_positive;
8747 curbuf->b_p_tw = 0;
8748 }
8749#ifdef FEAT_SYN_HL
8750# ifdef FEAT_WINDOWS
8751 {
8752 win_T *wp;
8753 tabpage_T *tp;
8754
8755 FOR_ALL_TAB_WINDOWS(tp, wp)
8756 check_colorcolumn(wp);
8757 }
8758# else
8759 check_colorcolumn(curwin);
8760# endif
8761#endif
8762 }
8763
Bram Moolenaar071d4272004-06-13 20:20:40 +00008764 /*
8765 * Check the bounds for numeric options here
8766 */
8767 if (Rows < min_rows() && full_screen)
8768 {
8769 if (errbuf != NULL)
8770 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008771 vim_snprintf((char *)errbuf, errbuflen,
8772 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773 errmsg = errbuf;
8774 }
8775 Rows = min_rows();
8776 }
8777 if (Columns < MIN_COLUMNS && full_screen)
8778 {
8779 if (errbuf != NULL)
8780 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008781 vim_snprintf((char *)errbuf, errbuflen,
8782 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008783 errmsg = errbuf;
8784 }
8785 Columns = MIN_COLUMNS;
8786 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008787 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008788
Bram Moolenaar071d4272004-06-13 20:20:40 +00008789 /*
8790 * If the screen (shell) height has been changed, assume it is the
8791 * physical screenheight.
8792 */
8793 if (old_Rows != Rows || old_Columns != Columns)
8794 {
8795 /* Changing the screen size is not allowed while updating the screen. */
8796 if (updating_screen)
8797 *pp = old_value;
8798 else if (full_screen
8799#ifdef FEAT_GUI
8800 && !gui.starting
8801#endif
8802 )
8803 set_shellsize((int)Columns, (int)Rows, TRUE);
8804 else
8805 {
8806 /* Postpone the resizing; check the size and cmdline position for
8807 * messages. */
8808 check_shellsize();
8809 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8810 cmdline_row = Rows - p_ch;
8811 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008812 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008813 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008814 }
8815
Bram Moolenaar071d4272004-06-13 20:20:40 +00008816 if (curbuf->b_p_ts <= 0)
8817 {
8818 errmsg = e_positive;
8819 curbuf->b_p_ts = 8;
8820 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008821 if (p_tm < 0)
8822 {
8823 errmsg = e_positive;
8824 p_tm = 0;
8825 }
8826 if ((curwin->w_p_scr <= 0
8827 || (curwin->w_p_scr > curwin->w_height
8828 && curwin->w_height > 0))
8829 && full_screen)
8830 {
8831 if (pp == &(curwin->w_p_scr))
8832 {
8833 if (curwin->w_p_scr != 0)
8834 errmsg = e_scroll;
8835 win_comp_scroll(curwin);
8836 }
8837 /* If 'scroll' became invalid because of a side effect silently adjust
8838 * it. */
8839 else if (curwin->w_p_scr <= 0)
8840 curwin->w_p_scr = 1;
8841 else /* curwin->w_p_scr > curwin->w_height */
8842 curwin->w_p_scr = curwin->w_height;
8843 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008844 if (p_hi < 0)
8845 {
8846 errmsg = e_positive;
8847 p_hi = 0;
8848 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008849 else if (p_hi > 10000)
8850 {
8851 errmsg = e_invarg;
8852 p_hi = 10000;
8853 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008854 if (p_re < 0 || p_re > 2)
8855 {
8856 errmsg = e_invarg;
8857 p_re = 0;
8858 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008859 if (p_report < 0)
8860 {
8861 errmsg = e_positive;
8862 p_report = 1;
8863 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008864 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 {
8866 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8867 p_sj = Rows / 2;
8868 else
8869 {
8870 errmsg = e_scroll;
8871 p_sj = 1;
8872 }
8873 }
8874 if (p_so < 0 && full_screen)
8875 {
8876 errmsg = e_scroll;
8877 p_so = 0;
8878 }
8879 if (p_siso < 0 && full_screen)
8880 {
8881 errmsg = e_positive;
8882 p_siso = 0;
8883 }
8884#ifdef FEAT_CMDWIN
8885 if (p_cwh < 1)
8886 {
8887 errmsg = e_positive;
8888 p_cwh = 1;
8889 }
8890#endif
8891 if (p_ut < 0)
8892 {
8893 errmsg = e_positive;
8894 p_ut = 2000;
8895 }
8896 if (p_ss < 0)
8897 {
8898 errmsg = e_positive;
8899 p_ss = 0;
8900 }
8901
8902 /* May set global value for local option. */
8903 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8904 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8905
8906 options[opt_idx].flags |= P_WAS_SET;
8907
Bram Moolenaar53744302015-07-17 17:38:22 +02008908#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8909 if (!starting && errmsg == NULL)
8910 {
8911 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008912 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8913 vim_snprintf((char *)buf_new, 10, "%ld", value);
8914 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008915 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8916 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8917 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8918 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8919 reset_v_option_vars();
8920 }
8921#endif
8922
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008924 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008925 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008926 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008927 check_redraw(options[opt_idx].flags);
8928
8929 return errmsg;
8930}
8931
8932/*
8933 * Called after an option changed: check if something needs to be redrawn.
8934 */
8935 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008936check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937{
8938 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008939 int doclear = (flags & P_RCLR) == P_RCLR;
8940 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941
8942#ifdef FEAT_WINDOWS
8943 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8944 status_redraw_all();
8945#endif
8946
8947 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8948 changed_window_setting();
8949 if (flags & P_RBUF)
8950 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008951 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952 redraw_all_later(CLEAR);
8953 else if (all)
8954 redraw_all_later(NOT_VALID);
8955}
8956
8957/*
8958 * Find index for option 'arg'.
8959 * Return -1 if not found.
8960 */
8961 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008962findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008963{
8964 int opt_idx;
8965 char *s, *p;
8966 static short quick_tab[27] = {0, 0}; /* quick access table */
8967 int is_term_opt;
8968
8969 /*
8970 * For first call: Initialize the quick-access table.
8971 * It contains the index for the first option that starts with a certain
8972 * letter. There are 26 letters, plus the first "t_" option.
8973 */
8974 if (quick_tab[1] == 0)
8975 {
8976 p = options[0].fullname;
8977 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8978 {
8979 if (s[0] != p[0])
8980 {
8981 if (s[0] == 't' && s[1] == '_')
8982 quick_tab[26] = opt_idx;
8983 else
8984 quick_tab[CharOrdLow(s[0])] = opt_idx;
8985 }
8986 p = s;
8987 }
8988 }
8989
8990 /*
8991 * Check for name starting with an illegal character.
8992 */
8993#ifdef EBCDIC
8994 if (!islower(arg[0]))
8995#else
8996 if (arg[0] < 'a' || arg[0] > 'z')
8997#endif
8998 return -1;
8999
9000 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9001 if (is_term_opt)
9002 opt_idx = quick_tab[26];
9003 else
9004 opt_idx = quick_tab[CharOrdLow(arg[0])];
9005 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9006 {
9007 if (STRCMP(arg, s) == 0) /* match full name */
9008 break;
9009 }
9010 if (s == NULL && !is_term_opt)
9011 {
9012 opt_idx = quick_tab[CharOrdLow(arg[0])];
9013 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9014 {
9015 s = options[opt_idx].shortname;
9016 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9017 break;
9018 s = NULL;
9019 }
9020 }
9021 if (s == NULL)
9022 opt_idx = -1;
9023 return opt_idx;
9024}
9025
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009026#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009027/*
9028 * Get the value for an option.
9029 *
9030 * Returns:
9031 * Number or Toggle option: 1, *numval gets value.
9032 * String option: 0, *stringval gets allocated string.
9033 * Hidden Number or Toggle option: -1.
9034 * hidden String option: -2.
9035 * unknown option: -3.
9036 */
9037 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009038get_option_value(
9039 char_u *name,
9040 long *numval,
9041 char_u **stringval, /* NULL when only checking existence */
9042 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009043{
9044 int opt_idx;
9045 char_u *varp;
9046
9047 opt_idx = findoption(name);
9048 if (opt_idx < 0) /* unknown option */
9049 return -3;
9050
9051 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9052
9053 if (options[opt_idx].flags & P_STRING)
9054 {
9055 if (varp == NULL) /* hidden option */
9056 return -2;
9057 if (stringval != NULL)
9058 {
9059#ifdef FEAT_CRYPT
9060 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009061 if ((char_u **)varp == &curbuf->b_p_key
9062 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009063 *stringval = vim_strsave((char_u *)"*****");
9064 else
9065#endif
9066 *stringval = vim_strsave(*(char_u **)(varp));
9067 }
9068 return 0;
9069 }
9070
9071 if (varp == NULL) /* hidden option */
9072 return -1;
9073 if (options[opt_idx].flags & P_NUM)
9074 *numval = *(long *)varp;
9075 else
9076 {
9077 /* Special case: 'modified' is b_changed, but we also want to consider
9078 * it set when 'ff' or 'fenc' changed. */
9079 if ((int *)varp == &curbuf->b_changed)
9080 *numval = curbufIsChanged();
9081 else
9082 *numval = *(int *)varp;
9083 }
9084 return 1;
9085}
9086#endif
9087
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009088#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009089/*
9090 * Returns the option attributes and its value. Unlike the above function it
9091 * will return either global value or local value of the option depending on
9092 * what was requested, but it will never return global value if it was
9093 * requested to return local one and vice versa. Neither it will return
9094 * buffer-local value if it was requested to return window-local one.
9095 *
9096 * Pretends that option is absent if it is not present in the requested scope
9097 * (i.e. has no global, window-local or buffer-local value depending on
9098 * opt_type). Uses
9099 *
9100 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009101 * 0 hidden or unknown option, also option that does not have requested
9102 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009103 * see SOPT_* in vim.h for other flags
9104 *
9105 * Possible opt_type values: see SREQ_* in vim.h
9106 */
9107 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009108get_option_value_strict(
9109 char_u *name,
9110 long *numval,
9111 char_u **stringval, /* NULL when only obtaining attributes */
9112 int opt_type,
9113 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009114{
9115 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009116 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009117 struct vimoption *p;
9118 int r = 0;
9119
9120 opt_idx = findoption(name);
9121 if (opt_idx < 0)
9122 return 0;
9123
9124 p = &(options[opt_idx]);
9125
9126 /* Hidden option */
9127 if (p->var == NULL)
9128 return 0;
9129
9130 if (p->flags & P_BOOL)
9131 r |= SOPT_BOOL;
9132 else if (p->flags & P_NUM)
9133 r |= SOPT_NUM;
9134 else if (p->flags & P_STRING)
9135 r |= SOPT_STRING;
9136
9137 if (p->indir == PV_NONE)
9138 {
9139 if (opt_type == SREQ_GLOBAL)
9140 r |= SOPT_GLOBAL;
9141 else
9142 return 0; /* Did not request global-only option */
9143 }
9144 else
9145 {
9146 if (p->indir & PV_BOTH)
9147 r |= SOPT_GLOBAL;
9148 else if (opt_type == SREQ_GLOBAL)
9149 return 0; /* Requested global option */
9150
9151 if (p->indir & PV_WIN)
9152 {
9153 if (opt_type == SREQ_BUF)
9154 return 0; /* Did not request window-local option */
9155 else
9156 r |= SOPT_WIN;
9157 }
9158 else if (p->indir & PV_BUF)
9159 {
9160 if (opt_type == SREQ_WIN)
9161 return 0; /* Did not request buffer-local option */
9162 else
9163 r |= SOPT_BUF;
9164 }
9165 }
9166
9167 if (stringval == NULL)
9168 return r;
9169
9170 if (opt_type == SREQ_GLOBAL)
9171 varp = p->var;
9172 else
9173 {
9174 if (opt_type == SREQ_BUF)
9175 {
9176 /* Special case: 'modified' is b_changed, but we also want to
9177 * consider it set when 'ff' or 'fenc' changed. */
9178 if (p->indir == PV_MOD)
9179 {
9180 *numval = bufIsChanged((buf_T *) from);
9181 varp = NULL;
9182 }
9183#ifdef FEAT_CRYPT
9184 else if (p->indir == PV_KEY)
9185 {
9186 /* never return the value of the crypt key */
9187 *stringval = NULL;
9188 varp = NULL;
9189 }
9190#endif
9191 else
9192 {
9193 aco_save_T aco;
9194 aucmd_prepbuf(&aco, (buf_T *) from);
9195 varp = get_varp(p);
9196 aucmd_restbuf(&aco);
9197 }
9198 }
9199 else if (opt_type == SREQ_WIN)
9200 {
9201 win_T *save_curwin;
9202 save_curwin = curwin;
9203 curwin = (win_T *) from;
9204 curbuf = curwin->w_buffer;
9205 varp = get_varp(p);
9206 curwin = save_curwin;
9207 curbuf = curwin->w_buffer;
9208 }
9209 if (varp == p->var)
9210 return (r | SOPT_UNSET);
9211 }
9212
9213 if (varp != NULL)
9214 {
9215 if (p->flags & P_STRING)
9216 *stringval = vim_strsave(*(char_u **)(varp));
9217 else if (p->flags & P_NUM)
9218 *numval = *(long *) varp;
9219 else
9220 *numval = *(int *)varp;
9221 }
9222
9223 return r;
9224}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009225
9226/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009227 * Iterate over options. First argument is a pointer to a pointer to a
9228 * structure inside options[] array, second is option type like in the above
9229 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009230 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009231 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009232 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009233 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009234 * first argument to NULL.
9235 *
9236 * Returns full option name for current option on each call.
9237 */
9238 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009239option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009240{
9241 struct vimoption *ret = NULL;
9242 do
9243 {
9244 if (*option == NULL)
9245 *option = (void *) options;
9246 else if (((struct vimoption *) (*option))->fullname == NULL)
9247 {
9248 *option = NULL;
9249 return NULL;
9250 }
9251 else
9252 *option = (void *) (((struct vimoption *) (*option)) + 1);
9253
9254 ret = ((struct vimoption *) (*option));
9255
9256 /* Hidden option */
9257 if (ret->var == NULL)
9258 {
9259 ret = NULL;
9260 continue;
9261 }
9262
9263 switch (opt_type)
9264 {
9265 case SREQ_GLOBAL:
9266 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9267 ret = NULL;
9268 break;
9269 case SREQ_BUF:
9270 if (!(ret->indir & PV_BUF))
9271 ret = NULL;
9272 break;
9273 case SREQ_WIN:
9274 if (!(ret->indir & PV_WIN))
9275 ret = NULL;
9276 break;
9277 default:
9278 EMSG2(_(e_intern2), "option_iter_next()");
9279 return NULL;
9280 }
9281 }
9282 while (ret == NULL);
9283
9284 return (char_u *)ret->fullname;
9285}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009286#endif
9287
Bram Moolenaar071d4272004-06-13 20:20:40 +00009288/*
9289 * Set the value of option "name".
9290 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009291 *
9292 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009293 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009294 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009295set_option_value(
9296 char_u *name,
9297 long number,
9298 char_u *string,
9299 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009300{
9301 int opt_idx;
9302 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009303 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304
9305 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009306 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 EMSG2(_("E355: Unknown option: %s"), name);
9308 else
9309 {
9310 flags = options[opt_idx].flags;
9311#ifdef HAVE_SANDBOX
9312 /* Disallow changing some options in the sandbox */
9313 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009314 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009315 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009316 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009317 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009318#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009319 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009320 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009321 else
9322 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009323 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009324 if (varp != NULL) /* hidden option is not changed */
9325 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009326 if (number == 0 && string != NULL)
9327 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009328 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009329
9330 /* Either we are given a string or we are setting option
9331 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009332 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009333 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009334 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009335 {
9336 /* There's another character after zeros or the string
9337 * is empty. In both cases, we are trying to set a
9338 * num option using a string. */
9339 EMSG3(_("E521: Number required: &%s = '%s'"),
9340 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009341 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009342
9343 }
9344 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009346 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009347 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009348 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009349 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009350 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009351 }
9352 }
9353 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009354 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355}
9356
9357/*
9358 * Get the terminal code for a terminal option.
9359 * Returns NULL when not found.
9360 */
9361 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009362get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009363{
9364 int opt_idx;
9365 char_u *varp;
9366
9367 if (tname[0] != 't' || tname[1] != '_' ||
9368 tname[2] == NUL || tname[3] == NUL)
9369 return NULL;
9370 if ((opt_idx = findoption(tname)) >= 0)
9371 {
9372 varp = get_varp(&(options[opt_idx]));
9373 if (varp != NULL)
9374 varp = *(char_u **)(varp);
9375 return varp;
9376 }
9377 return find_termcode(tname + 2);
9378}
9379
9380 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009381get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382{
9383 int i;
9384
9385 i = findoption((char_u *)"hl");
9386 if (i >= 0)
9387 return options[i].def_val[VI_DEFAULT];
9388 return (char_u *)NULL;
9389}
9390
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009391#if defined(FEAT_MBYTE) || defined(PROTO)
9392 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009393get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009394{
9395 int i;
9396
9397 i = findoption((char_u *)"enc");
9398 if (i >= 0)
9399 return options[i].def_val[VI_DEFAULT];
9400 return (char_u *)NULL;
9401}
9402#endif
9403
Bram Moolenaar071d4272004-06-13 20:20:40 +00009404/*
9405 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9406 */
9407 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009408find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009409{
9410 int key;
9411 int modifiers;
9412
9413 /*
9414 * Don't use get_special_key_code() for t_xx, we don't want it to call
9415 * add_termcap_entry().
9416 */
9417 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9418 key = TERMCAP2KEY(arg[2], arg[3]);
9419 else
9420 {
9421 --arg; /* put arg at the '<' */
9422 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009423 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009424 if (modifiers) /* can't handle modifiers here */
9425 key = 0;
9426 }
9427 return key;
9428}
9429
9430/*
9431 * if 'all' == 0: show changed options
9432 * if 'all' == 1: show all normal options
9433 * if 'all' == 2: show all terminal options
9434 */
9435 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009436showoptions(
9437 int all,
9438 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009439{
9440 struct vimoption *p;
9441 int col;
9442 int isterm;
9443 char_u *varp;
9444 struct vimoption **items;
9445 int item_count;
9446 int run;
9447 int row, rows;
9448 int cols;
9449 int i;
9450 int len;
9451
9452#define INC 20
9453#define GAP 3
9454
9455 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9456 PARAM_COUNT));
9457 if (items == NULL)
9458 return;
9459
9460 /* Highlight title */
9461 if (all == 2)
9462 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9463 else if (opt_flags & OPT_GLOBAL)
9464 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9465 else if (opt_flags & OPT_LOCAL)
9466 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9467 else
9468 MSG_PUTS_TITLE(_("\n--- Options ---"));
9469
9470 /*
9471 * do the loop two times:
9472 * 1. display the short items
9473 * 2. display the long items (only strings and numbers)
9474 */
9475 for (run = 1; run <= 2 && !got_int; ++run)
9476 {
9477 /*
9478 * collect the items in items[]
9479 */
9480 item_count = 0;
9481 for (p = &options[0]; p->fullname != NULL; p++)
9482 {
9483 varp = NULL;
9484 isterm = istermoption(p);
9485 if (opt_flags != 0)
9486 {
9487 if (p->indir != PV_NONE && !isterm)
9488 varp = get_varp_scope(p, opt_flags);
9489 }
9490 else
9491 varp = get_varp(p);
9492 if (varp != NULL
9493 && ((all == 2 && isterm)
9494 || (all == 1 && !isterm)
9495 || (all == 0 && !optval_default(p, varp))))
9496 {
9497 if (p->flags & P_BOOL)
9498 len = 1; /* a toggle option fits always */
9499 else
9500 {
9501 option_value2string(p, opt_flags);
9502 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9503 }
9504 if ((len <= INC - GAP && run == 1) ||
9505 (len > INC - GAP && run == 2))
9506 items[item_count++] = p;
9507 }
9508 }
9509
9510 /*
9511 * display the items
9512 */
9513 if (run == 1)
9514 {
9515 cols = (Columns + GAP - 3) / INC;
9516 if (cols == 0)
9517 cols = 1;
9518 rows = (item_count + cols - 1) / cols;
9519 }
9520 else /* run == 2 */
9521 rows = item_count;
9522 for (row = 0; row < rows && !got_int; ++row)
9523 {
9524 msg_putchar('\n'); /* go to next line */
9525 if (got_int) /* 'q' typed in more */
9526 break;
9527 col = 0;
9528 for (i = row; i < item_count; i += rows)
9529 {
9530 msg_col = col; /* make columns */
9531 showoneopt(items[i], opt_flags);
9532 col += INC;
9533 }
9534 out_flush();
9535 ui_breakcheck();
9536 }
9537 }
9538 vim_free(items);
9539}
9540
9541/*
9542 * Return TRUE if option "p" has its default value.
9543 */
9544 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009545optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009546{
9547 int dvi;
9548
9549 if (varp == NULL)
9550 return TRUE; /* hidden option is always at default */
9551 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9552 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009553 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009554 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009555 /* the cast to long is required for Manx C, long_i is
9556 * needed for MSVC */
9557 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009558 /* P_STRING */
9559 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9560}
9561
9562/*
9563 * showoneopt: show the value of one option
9564 * must not be called with a hidden option!
9565 */
9566 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009567showoneopt(
9568 struct vimoption *p,
9569 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009570{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009571 char_u *varp;
9572 int save_silent = silent_mode;
9573
9574 silent_mode = FALSE;
9575 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576
9577 varp = get_varp_scope(p, opt_flags);
9578
9579 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9580 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9581 ? !curbufIsChanged() : !*(int *)varp))
9582 MSG_PUTS("no");
9583 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9584 MSG_PUTS("--");
9585 else
9586 MSG_PUTS(" ");
9587 MSG_PUTS(p->fullname);
9588 if (!(p->flags & P_BOOL))
9589 {
9590 msg_putchar('=');
9591 /* put value string in NameBuff */
9592 option_value2string(p, opt_flags);
9593 msg_outtrans(NameBuff);
9594 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009595
9596 silent_mode = save_silent;
9597 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009598}
9599
9600/*
9601 * Write modified options as ":set" commands to a file.
9602 *
9603 * There are three values for "opt_flags":
9604 * OPT_GLOBAL: Write global option values and fresh values of
9605 * buffer-local options (used for start of a session
9606 * file).
9607 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9608 * curwin (used for a vimrc file).
9609 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9610 * and local values for window-local options of
9611 * curwin. Local values are also written when at the
9612 * default value, because a modeline or autocommand
9613 * may have set them when doing ":edit file" and the
9614 * user has set them back at the default or fresh
9615 * value.
9616 * When "local_only" is TRUE, don't write fresh
9617 * values, only local values (for ":mkview").
9618 * (fresh value = value used for a new buffer or window for a local option).
9619 *
9620 * Return FAIL on error, OK otherwise.
9621 */
9622 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009623makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009624{
9625 struct vimoption *p;
9626 char_u *varp; /* currently used value */
9627 char_u *varp_fresh; /* local value */
9628 char_u *varp_local = NULL; /* fresh value */
9629 char *cmd;
9630 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009631 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632
9633 /*
9634 * The options that don't have a default (terminal name, columns, lines)
9635 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009636 * Do the loop over "options[]" twice: once for options with the
9637 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009638 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009639 for (pri = 1; pri >= 0; --pri)
9640 {
9641 for (p = &options[0]; !istermoption(p); p++)
9642 if (!(p->flags & P_NO_MKRC)
9643 && !istermoption(p)
9644 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645 {
9646 /* skip global option when only doing locals */
9647 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9648 continue;
9649
9650 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9651 * file, they are always buffer-specific. */
9652 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9653 continue;
9654
9655 /* Global values are only written when not at the default value. */
9656 varp = get_varp_scope(p, opt_flags);
9657 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9658 continue;
9659
9660 round = 2;
9661 if (p->indir != PV_NONE)
9662 {
9663 if (p->var == VAR_WIN)
9664 {
9665 /* skip window-local option when only doing globals */
9666 if (!(opt_flags & OPT_LOCAL))
9667 continue;
9668 /* When fresh value of window-local option is not at the
9669 * default, need to write it too. */
9670 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9671 {
9672 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9673 if (!optval_default(p, varp_fresh))
9674 {
9675 round = 1;
9676 varp_local = varp;
9677 varp = varp_fresh;
9678 }
9679 }
9680 }
9681 }
9682
9683 /* Round 1: fresh value for window-local options.
9684 * Round 2: other values */
9685 for ( ; round <= 2; varp = varp_local, ++round)
9686 {
9687 if (round == 1 || (opt_flags & OPT_GLOBAL))
9688 cmd = "set";
9689 else
9690 cmd = "setlocal";
9691
9692 if (p->flags & P_BOOL)
9693 {
9694 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9695 return FAIL;
9696 }
9697 else if (p->flags & P_NUM)
9698 {
9699 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9700 return FAIL;
9701 }
9702 else /* P_STRING */
9703 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009704#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9705 int do_endif = FALSE;
9706
Bram Moolenaar071d4272004-06-13 20:20:40 +00009707 /* Don't set 'syntax' and 'filetype' again if the value is
9708 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009709 if (
9710# if defined(FEAT_SYN_HL)
9711 p->indir == PV_SYN
9712# if defined(FEAT_AUTOCMD)
9713 ||
9714# endif
9715# endif
9716# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009717 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009718# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009719 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009720 {
9721 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9722 *(char_u **)(varp)) < 0
9723 || put_eol(fd) < 0)
9724 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009725 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009727#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009728 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9729 (p->flags & P_EXPAND) != 0) == FAIL)
9730 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009731#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9732 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009733 {
9734 if (put_line(fd, "endif") == FAIL)
9735 return FAIL;
9736 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009737#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009738 }
9739 }
9740 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009741 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742 return OK;
9743}
9744
9745#if defined(FEAT_FOLDING) || defined(PROTO)
9746/*
9747 * Generate set commands for the local fold options only. Used when
9748 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9749 */
9750 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009751makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752{
9753 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9754# ifdef FEAT_EVAL
9755 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9756 == FAIL
9757# endif
9758 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9759 == FAIL
9760 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9761 == FAIL
9762 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9763 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9764 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9765 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9766 )
9767 return FAIL;
9768
9769 return OK;
9770}
9771#endif
9772
9773 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009774put_setstring(
9775 FILE *fd,
9776 char *cmd,
9777 char *name,
9778 char_u **valuep,
9779 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009780{
9781 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009782 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783
9784 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9785 return FAIL;
9786 if (*valuep != NULL)
9787 {
9788 /* Output 'pastetoggle' as key names. For other
9789 * options some characters have to be escaped with
9790 * CTRL-V or backslash */
9791 if (valuep == &p_pt)
9792 {
9793 s = *valuep;
9794 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009795 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009796 return FAIL;
9797 }
9798 else if (expand)
9799 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009800 buf = alloc(MAXPATHL);
9801 if (buf == NULL)
9802 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009803 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9804 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009805 {
9806 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009807 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009808 }
9809 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810 }
9811 else if (put_escstr(fd, *valuep, 2) == FAIL)
9812 return FAIL;
9813 }
9814 if (put_eol(fd) < 0)
9815 return FAIL;
9816 return OK;
9817}
9818
9819 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009820put_setnum(
9821 FILE *fd,
9822 char *cmd,
9823 char *name,
9824 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009825{
9826 long wc;
9827
9828 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9829 return FAIL;
9830 if (wc_use_keyname((char_u *)valuep, &wc))
9831 {
9832 /* print 'wildchar' and 'wildcharm' as a key name */
9833 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9834 return FAIL;
9835 }
9836 else if (fprintf(fd, "%ld", *valuep) < 0)
9837 return FAIL;
9838 if (put_eol(fd) < 0)
9839 return FAIL;
9840 return OK;
9841}
9842
9843 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009844put_setbool(
9845 FILE *fd,
9846 char *cmd,
9847 char *name,
9848 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009849{
Bram Moolenaar893de922007-10-02 18:40:57 +00009850 if (value < 0) /* global/local option using global value */
9851 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009852 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9853 || put_eol(fd) < 0)
9854 return FAIL;
9855 return OK;
9856}
9857
9858/*
9859 * Clear all the terminal options.
9860 * If the option has been allocated, free the memory.
9861 * Terminal options are never hidden or indirect.
9862 */
9863 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009864clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009866 /*
9867 * Reset a few things before clearing the old options. This may cause
9868 * outputting a few things that the terminal doesn't understand, but the
9869 * screen will be cleared later, so this is OK.
9870 */
9871#ifdef FEAT_MOUSE_TTY
9872 mch_setmouse(FALSE); /* switch mouse off */
9873#endif
9874#ifdef FEAT_TITLE
9875 mch_restore_title(3); /* restore window titles */
9876#endif
9877#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9878 /* When starting the GUI close the display opened for the clipboard.
9879 * After restoring the title, because that will need the display. */
9880 if (gui.starting)
9881 clear_xterm_clip();
9882#endif
9883#ifdef WIN3264
9884 /*
9885 * Check if this is allowed now.
9886 */
9887 if (can_end_termcap_mode(FALSE) == TRUE)
9888#endif
9889 stoptermcap(); /* stop termcap mode */
9890
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009891 free_termoptions();
9892}
9893
9894 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009895free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009896{
9897 struct vimoption *p;
9898
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899 for (p = &options[0]; p->fullname != NULL; p++)
9900 if (istermoption(p))
9901 {
9902 if (p->flags & P_ALLOCED)
9903 free_string_option(*(char_u **)(p->var));
9904 if (p->flags & P_DEF_ALLOCED)
9905 free_string_option(p->def_val[VI_DEFAULT]);
9906 *(char_u **)(p->var) = empty_option;
9907 p->def_val[VI_DEFAULT] = empty_option;
9908 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9909 }
9910 clear_termcodes();
9911}
9912
9913/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009914 * Free the string for one term option, if it was allocated.
9915 * Set the string to empty_option and clear allocated flag.
9916 * "var" points to the option value.
9917 */
9918 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009919free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009920{
9921 struct vimoption *p;
9922
9923 for (p = &options[0]; p->fullname != NULL; p++)
9924 if (p->var == var)
9925 {
9926 if (p->flags & P_ALLOCED)
9927 free_string_option(*(char_u **)(p->var));
9928 *(char_u **)(p->var) = empty_option;
9929 p->flags &= ~P_ALLOCED;
9930 break;
9931 }
9932}
9933
9934/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009935 * Set the terminal option defaults to the current value.
9936 * Used after setting the terminal name.
9937 */
9938 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009939set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940{
9941 struct vimoption *p;
9942
9943 for (p = &options[0]; p->fullname != NULL; p++)
9944 {
9945 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9946 {
9947 if (p->flags & P_DEF_ALLOCED)
9948 {
9949 free_string_option(p->def_val[VI_DEFAULT]);
9950 p->flags &= ~P_DEF_ALLOCED;
9951 }
9952 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9953 if (p->flags & P_ALLOCED)
9954 {
9955 p->flags |= P_DEF_ALLOCED;
9956 p->flags &= ~P_ALLOCED; /* don't free the value now */
9957 }
9958 }
9959 }
9960}
9961
9962/*
9963 * return TRUE if 'p' starts with 't_'
9964 */
9965 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009966istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009967{
9968 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9969}
9970
9971/*
9972 * Compute columns for ruler and shown command. 'sc_col' is also used to
9973 * decide what the maximum length of a message on the status line can be.
9974 * If there is a status line for the last window, 'sc_col' is independent
9975 * of 'ru_col'.
9976 */
9977
9978#define COL_RULER 17 /* columns needed by standard ruler */
9979
9980 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009981comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009982{
9983#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9984 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9985
9986 sc_col = 0;
9987 ru_col = 0;
9988 if (p_ru)
9989 {
9990#ifdef FEAT_STL_OPT
9991 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9992#else
9993 ru_col = COL_RULER + 1;
9994#endif
9995 /* no last status line, adjust sc_col */
9996 if (!last_has_status)
9997 sc_col = ru_col;
9998 }
9999 if (p_sc)
10000 {
10001 sc_col += SHOWCMD_COLS;
10002 if (!p_ru || last_has_status) /* no need for separating space */
10003 ++sc_col;
10004 }
10005 sc_col = Columns - sc_col;
10006 ru_col = Columns - ru_col;
10007 if (sc_col <= 0) /* screen too narrow, will become a mess */
10008 sc_col = 1;
10009 if (ru_col <= 0)
10010 ru_col = 1;
10011#else
10012 sc_col = Columns;
10013 ru_col = Columns;
10014#endif
10015}
10016
10017/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010018 * Unset local option value, similar to ":set opt<".
10019 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010020 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010021unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010022{
10023 struct vimoption *p;
10024 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010025 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010026
10027 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010028 if (opt_idx < 0)
10029 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010030 p = &(options[opt_idx]);
10031
10032 switch ((int)p->indir)
10033 {
10034 /* global option with local value: use local value if it's been set */
10035 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010036 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010037 break;
10038 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010039 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010040 break;
10041 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010042 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010043 break;
10044 case PV_AR:
10045 buf->b_p_ar = -1;
10046 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010047 case PV_BKC:
10048 clear_string_option(&buf->b_p_bkc);
10049 buf->b_bkc_flags = 0;
10050 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010051 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010052 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010053 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010054 case PV_TC:
10055 clear_string_option(&buf->b_p_tc);
10056 buf->b_tc_flags = 0;
10057 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010058#ifdef FEAT_FIND_ID
10059 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010060 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010061 break;
10062 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010063 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010064 break;
10065#endif
10066#ifdef FEAT_INS_EXPAND
10067 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010068 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010069 break;
10070 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010071 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010072 break;
10073#endif
10074#ifdef FEAT_QUICKFIX
10075 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010076 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010077 break;
10078 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010079 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080 break;
10081 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010082 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010083 break;
10084#endif
10085#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10086 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010087 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010088 break;
10089#endif
10090#if defined(FEAT_CRYPT)
10091 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010092 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010093 break;
10094#endif
10095#ifdef FEAT_STL_OPT
10096 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010097 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010098 break;
10099#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010100 case PV_UL:
10101 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10102 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010103#ifdef FEAT_LISP
10104 case PV_LW:
10105 clear_string_option(&buf->b_p_lw);
10106 break;
10107#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010108 }
10109}
10110
10111/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010112 * Get pointer to option variable, depending on local or global scope.
10113 */
10114 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010115get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116{
10117 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10118 {
10119 if (p->var == VAR_WIN)
10120 return (char_u *)GLOBAL_WO(get_varp(p));
10121 return p->var;
10122 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010123 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124 {
10125 switch ((int)p->indir)
10126 {
10127#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010128 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10129 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10130 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010132 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10133 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10134 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010135 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010136 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010137 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010138#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010139 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10140 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141#endif
10142#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010143 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10144 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010146#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10147 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10148#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010149#if defined(FEAT_CRYPT)
10150 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10151#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010152#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010153 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010154#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010155 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010156#ifdef FEAT_LISP
10157 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10158#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010159 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160 }
10161 return NULL; /* "cannot happen" */
10162 }
10163 return get_varp(p);
10164}
10165
10166/*
10167 * Get pointer to option variable.
10168 */
10169 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010170get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171{
10172 /* hidden option, always return NULL */
10173 if (p->var == NULL)
10174 return NULL;
10175
10176 switch ((int)p->indir)
10177 {
10178 case PV_NONE: return p->var;
10179
10180 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010181 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010183 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010185 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010187 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010189 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010191 case PV_TC: return *curbuf->b_p_tc != NUL
10192 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010193 case PV_BKC: return *curbuf->b_p_bkc != NUL
10194 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010196 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010198 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10200#endif
10201#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010202 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010204 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10206#endif
10207#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010208 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010209 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010210 case PV_GP: return *curbuf->b_p_gp != NUL
10211 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10212 case PV_MP: return *curbuf->b_p_mp != NUL
10213 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010214#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010215#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10216 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10217 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10218#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010219#if defined(FEAT_CRYPT)
10220 case PV_CM: return *curbuf->b_p_cm != NUL
10221 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10222#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010223#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010224 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010225 ? (char_u *)&(curwin->w_p_stl) : p->var;
10226#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010227 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10228 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010229#ifdef FEAT_LISP
10230 case PV_LW: return *curbuf->b_p_lw != NUL
10231 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10232#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233
10234#ifdef FEAT_ARABIC
10235 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10236#endif
10237 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010238#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010239 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10240#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010241#ifdef FEAT_SYN_HL
10242 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10243 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010244 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246#ifdef FEAT_DIFF
10247 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10248#endif
10249#ifdef FEAT_FOLDING
10250 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10251 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10252 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10253 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10254 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10255 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10256 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10257# ifdef FEAT_EVAL
10258 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10259 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10260# endif
10261 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10262#endif
10263 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010264 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010265#ifdef FEAT_LINEBREAK
10266 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10267#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010268#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010270 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10271#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10273 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10274#endif
10275#ifdef FEAT_RIGHTLEFT
10276 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10277 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10278#endif
10279 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10280 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10281#ifdef FEAT_LINEBREAK
10282 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010283 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10284 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285#endif
10286#ifdef FEAT_SCROLLBIND
10287 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10288#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010289#ifdef FEAT_CURSORBIND
10290 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10291#endif
10292#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010293 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10294 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010295#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010296
10297 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10298 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10299#ifdef FEAT_MBYTE
10300 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10301#endif
10302#if defined(FEAT_QUICKFIX)
10303 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10304 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10305#endif
10306 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10307 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10308#ifdef FEAT_CINDENT
10309 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10310 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10311 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10312#endif
10313#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10314 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10315#endif
10316#ifdef FEAT_COMMENTS
10317 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10318#endif
10319#ifdef FEAT_FOLDING
10320 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10321#endif
10322#ifdef FEAT_INS_EXPAND
10323 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10324#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010325#ifdef FEAT_COMPL_FUNC
10326 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010327 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010328#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010330 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10332#ifdef FEAT_MBYTE
10333 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10334#endif
10335 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10336#ifdef FEAT_AUTOCMD
10337 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10338#endif
10339 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010340 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10342 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10343 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10344 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10345#ifdef FEAT_FIND_ID
10346# ifdef FEAT_EVAL
10347 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10348# endif
10349#endif
10350#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10351 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10352 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10353#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010354#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010355 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10356#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357#ifdef FEAT_CRYPT
10358 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10359#endif
10360#ifdef FEAT_LISP
10361 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10362#endif
10363 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10364 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10365 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10366 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10367 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010368 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010369#ifdef FEAT_TEXTOBJ
10370 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10373#ifdef FEAT_SMARTINDENT
10374 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010376 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010377 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10378#ifdef FEAT_SEARCHPATH
10379 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10380#endif
10381 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10382#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010383 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010384 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10385#endif
10386#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010387 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10388 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10389 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010390#endif
10391 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10392 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10393 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10394 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010395#ifdef FEAT_PERSISTENT_UNDO
10396 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10399#ifdef FEAT_KEYMAP
10400 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10401#endif
10402 default: EMSG(_("E356: get_varp ERROR"));
10403 }
10404 /* always return a valid pointer to avoid a crash! */
10405 return (char_u *)&(curbuf->b_p_wm);
10406}
10407
10408/*
10409 * Get the value of 'equalprg', either the buffer-local one or the global one.
10410 */
10411 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010412get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413{
10414 if (*curbuf->b_p_ep == NUL)
10415 return p_ep;
10416 return curbuf->b_p_ep;
10417}
10418
10419#if defined(FEAT_WINDOWS) || defined(PROTO)
10420/*
10421 * Copy options from one window to another.
10422 * Used when splitting a window.
10423 */
10424 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010425win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426{
10427 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10428 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10429# ifdef FEAT_RIGHTLEFT
10430# ifdef FEAT_FKMAP
10431 /* Is this right? */
10432 wp_to->w_farsi = wp_from->w_farsi;
10433# endif
10434# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010435#if defined(FEAT_LINEBREAK)
10436 briopt_check(wp_to);
10437#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438}
10439#endif
10440
10441/*
10442 * Copy the options from one winopt_T to another.
10443 * Doesn't free the old option values in "to", use clear_winopt() for that.
10444 * The 'scroll' option is not copied, because it depends on the window height.
10445 * The 'previewwindow' option is reset, there can be only one preview window.
10446 */
10447 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010448copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010449{
10450#ifdef FEAT_ARABIC
10451 to->wo_arab = from->wo_arab;
10452#endif
10453 to->wo_list = from->wo_list;
10454 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010455 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010456#ifdef FEAT_LINEBREAK
10457 to->wo_nuw = from->wo_nuw;
10458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459#ifdef FEAT_RIGHTLEFT
10460 to->wo_rl = from->wo_rl;
10461 to->wo_rlc = vim_strsave(from->wo_rlc);
10462#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010463#ifdef FEAT_STL_OPT
10464 to->wo_stl = vim_strsave(from->wo_stl);
10465#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010466 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010467#ifdef FEAT_DIFF
10468 to->wo_wrap_save = from->wo_wrap_save;
10469#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010470#ifdef FEAT_LINEBREAK
10471 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010472 to->wo_bri = from->wo_bri;
10473 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010474#endif
10475#ifdef FEAT_SCROLLBIND
10476 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010477 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010478#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010479#ifdef FEAT_CURSORBIND
10480 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010481 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010482#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010483#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010484 to->wo_spell = from->wo_spell;
10485#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010486#ifdef FEAT_SYN_HL
10487 to->wo_cuc = from->wo_cuc;
10488 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010489 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010490#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491#ifdef FEAT_DIFF
10492 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010493 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010495#ifdef FEAT_CONCEAL
10496 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010497 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499#ifdef FEAT_FOLDING
10500 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010501 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010503 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504 to->wo_fdi = vim_strsave(from->wo_fdi);
10505 to->wo_fml = from->wo_fml;
10506 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010507 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010509 to->wo_fdm_save = from->wo_diff_saved
10510 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511 to->wo_fdn = from->wo_fdn;
10512# ifdef FEAT_EVAL
10513 to->wo_fde = vim_strsave(from->wo_fde);
10514 to->wo_fdt = vim_strsave(from->wo_fdt);
10515# endif
10516 to->wo_fmr = vim_strsave(from->wo_fmr);
10517#endif
10518 check_winopt(to); /* don't want NULL pointers */
10519}
10520
10521/*
10522 * Check string options in a window for a NULL value.
10523 */
10524 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010525check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526{
10527 check_winopt(&win->w_onebuf_opt);
10528 check_winopt(&win->w_allbuf_opt);
10529}
10530
10531/*
10532 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10533 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010534 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010535check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536{
10537#ifdef FEAT_FOLDING
10538 check_string_option(&wop->wo_fdi);
10539 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010540 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541# ifdef FEAT_EVAL
10542 check_string_option(&wop->wo_fde);
10543 check_string_option(&wop->wo_fdt);
10544# endif
10545 check_string_option(&wop->wo_fmr);
10546#endif
10547#ifdef FEAT_RIGHTLEFT
10548 check_string_option(&wop->wo_rlc);
10549#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010550#ifdef FEAT_STL_OPT
10551 check_string_option(&wop->wo_stl);
10552#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010553#ifdef FEAT_SYN_HL
10554 check_string_option(&wop->wo_cc);
10555#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010556#ifdef FEAT_CONCEAL
10557 check_string_option(&wop->wo_cocu);
10558#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010559#ifdef FEAT_LINEBREAK
10560 check_string_option(&wop->wo_briopt);
10561#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562}
10563
10564/*
10565 * Free the allocated memory inside a winopt_T.
10566 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010568clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569{
10570#ifdef FEAT_FOLDING
10571 clear_string_option(&wop->wo_fdi);
10572 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010573 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574# ifdef FEAT_EVAL
10575 clear_string_option(&wop->wo_fde);
10576 clear_string_option(&wop->wo_fdt);
10577# endif
10578 clear_string_option(&wop->wo_fmr);
10579#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010580#ifdef FEAT_LINEBREAK
10581 clear_string_option(&wop->wo_briopt);
10582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583#ifdef FEAT_RIGHTLEFT
10584 clear_string_option(&wop->wo_rlc);
10585#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010586#ifdef FEAT_STL_OPT
10587 clear_string_option(&wop->wo_stl);
10588#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010589#ifdef FEAT_SYN_HL
10590 clear_string_option(&wop->wo_cc);
10591#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010592#ifdef FEAT_CONCEAL
10593 clear_string_option(&wop->wo_cocu);
10594#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595}
10596
10597/*
10598 * Copy global option values to local options for one buffer.
10599 * Used when creating a new buffer and sometimes when entering a buffer.
10600 * flags:
10601 * BCO_ENTER We will enter the buf buffer.
10602 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10603 * appropriate.
10604 * BCO_NOHELP Don't copy the values to a help buffer.
10605 */
10606 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010607buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608{
10609 int should_copy = TRUE;
10610 char_u *save_p_isk = NULL; /* init for GCC */
10611 int dont_do_help;
10612 int did_isk = FALSE;
10613
10614 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010615 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616 */
10617 if (buf == NULL || !buf_valid(buf))
10618 return;
10619
10620 /*
10621 * Skip this when the option defaults have not been set yet. Happens when
10622 * main() allocates the first buffer.
10623 */
10624 if (p_cpo != NULL)
10625 {
10626 /*
10627 * Always copy when entering and 'cpo' contains 'S'.
10628 * Don't copy when already initialized.
10629 * Don't copy when 'cpo' contains 's' and not entering.
10630 * 'S' BCO_ENTER initialized 's' should_copy
10631 * yes yes X X TRUE
10632 * yes no yes X FALSE
10633 * no X yes X FALSE
10634 * X no no yes FALSE
10635 * X no no no TRUE
10636 * no yes no X TRUE
10637 */
10638 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10639 && (buf->b_p_initialized
10640 || (!(flags & BCO_ENTER)
10641 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10642 should_copy = FALSE;
10643
10644 if (should_copy || (flags & BCO_ALWAYS))
10645 {
10646 /* Don't copy the options specific to a help buffer when
10647 * BCO_NOHELP is given or the options were initialized already
10648 * (jumping back to a help file with CTRL-T or CTRL-O) */
10649 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10650 || buf->b_p_initialized;
10651 if (dont_do_help) /* don't free b_p_isk */
10652 {
10653 save_p_isk = buf->b_p_isk;
10654 buf->b_p_isk = NULL;
10655 }
10656 /*
10657 * Always free the allocated strings.
10658 * If not already initialized, set 'readonly' and copy 'fileformat'.
10659 */
10660 if (!buf->b_p_initialized)
10661 {
10662 free_buf_options(buf, TRUE);
10663 buf->b_p_ro = FALSE; /* don't copy readonly */
10664 buf->b_p_tx = p_tx;
10665#ifdef FEAT_MBYTE
10666 buf->b_p_fenc = vim_strsave(p_fenc);
10667#endif
10668 buf->b_p_ff = vim_strsave(p_ff);
10669#if defined(FEAT_QUICKFIX)
10670 buf->b_p_bh = empty_option;
10671 buf->b_p_bt = empty_option;
10672#endif
10673 }
10674 else
10675 free_buf_options(buf, FALSE);
10676
10677 buf->b_p_ai = p_ai;
10678 buf->b_p_ai_nopaste = p_ai_nopaste;
10679 buf->b_p_sw = p_sw;
10680 buf->b_p_tw = p_tw;
10681 buf->b_p_tw_nopaste = p_tw_nopaste;
10682 buf->b_p_tw_nobin = p_tw_nobin;
10683 buf->b_p_wm = p_wm;
10684 buf->b_p_wm_nopaste = p_wm_nopaste;
10685 buf->b_p_wm_nobin = p_wm_nobin;
10686 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010687#ifdef FEAT_MBYTE
10688 buf->b_p_bomb = p_bomb;
10689#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010690 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691 buf->b_p_et = p_et;
10692 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010693 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010694 buf->b_p_ml = p_ml;
10695 buf->b_p_ml_nobin = p_ml_nobin;
10696 buf->b_p_inf = p_inf;
10697 buf->b_p_swf = p_swf;
10698#ifdef FEAT_INS_EXPAND
10699 buf->b_p_cpt = vim_strsave(p_cpt);
10700#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010701#ifdef FEAT_COMPL_FUNC
10702 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010703 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010705 buf->b_p_sts = p_sts;
10706 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708#ifdef FEAT_COMMENTS
10709 buf->b_p_com = vim_strsave(p_com);
10710#endif
10711#ifdef FEAT_FOLDING
10712 buf->b_p_cms = vim_strsave(p_cms);
10713#endif
10714 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010715 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716 buf->b_p_nf = vim_strsave(p_nf);
10717 buf->b_p_mps = vim_strsave(p_mps);
10718#ifdef FEAT_SMARTINDENT
10719 buf->b_p_si = p_si;
10720#endif
10721 buf->b_p_ci = p_ci;
10722#ifdef FEAT_CINDENT
10723 buf->b_p_cin = p_cin;
10724 buf->b_p_cink = vim_strsave(p_cink);
10725 buf->b_p_cino = vim_strsave(p_cino);
10726#endif
10727#ifdef FEAT_AUTOCMD
10728 /* Don't copy 'filetype', it must be detected */
10729 buf->b_p_ft = empty_option;
10730#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010731 buf->b_p_pi = p_pi;
10732#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10733 buf->b_p_cinw = vim_strsave(p_cinw);
10734#endif
10735#ifdef FEAT_LISP
10736 buf->b_p_lisp = p_lisp;
10737#endif
10738#ifdef FEAT_SYN_HL
10739 /* Don't copy 'syntax', it must be set */
10740 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010741 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010742 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010743#endif
10744#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010745 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010746 (void)compile_cap_prog(&buf->b_s);
10747 buf->b_s.b_p_spf = vim_strsave(p_spf);
10748 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010749#endif
10750#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10751 buf->b_p_inde = vim_strsave(p_inde);
10752 buf->b_p_indk = vim_strsave(p_indk);
10753#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010754#if defined(FEAT_EVAL)
10755 buf->b_p_fex = vim_strsave(p_fex);
10756#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757#ifdef FEAT_CRYPT
10758 buf->b_p_key = vim_strsave(p_key);
10759#endif
10760#ifdef FEAT_SEARCHPATH
10761 buf->b_p_sua = vim_strsave(p_sua);
10762#endif
10763#ifdef FEAT_KEYMAP
10764 buf->b_p_keymap = vim_strsave(p_keymap);
10765 buf->b_kmap_state |= KEYMAP_INIT;
10766#endif
10767 /* This isn't really an option, but copying the langmap and IME
10768 * state from the current buffer is better than resetting it. */
10769 buf->b_p_iminsert = p_iminsert;
10770 buf->b_p_imsearch = p_imsearch;
10771
10772 /* options that are normally global but also have a local value
10773 * are not copied, start using the global value */
10774 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010775 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010776 buf->b_p_bkc = empty_option;
10777 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778#ifdef FEAT_QUICKFIX
10779 buf->b_p_gp = empty_option;
10780 buf->b_p_mp = empty_option;
10781 buf->b_p_efm = empty_option;
10782#endif
10783 buf->b_p_ep = empty_option;
10784 buf->b_p_kp = empty_option;
10785 buf->b_p_path = empty_option;
10786 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010787 buf->b_p_tc = empty_option;
10788 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789#ifdef FEAT_FIND_ID
10790 buf->b_p_def = empty_option;
10791 buf->b_p_inc = empty_option;
10792# ifdef FEAT_EVAL
10793 buf->b_p_inex = vim_strsave(p_inex);
10794# endif
10795#endif
10796#ifdef FEAT_INS_EXPAND
10797 buf->b_p_dict = empty_option;
10798 buf->b_p_tsr = empty_option;
10799#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010800#ifdef FEAT_TEXTOBJ
10801 buf->b_p_qe = vim_strsave(p_qe);
10802#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010803#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10804 buf->b_p_bexpr = empty_option;
10805#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010806#if defined(FEAT_CRYPT)
10807 buf->b_p_cm = empty_option;
10808#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010809#ifdef FEAT_PERSISTENT_UNDO
10810 buf->b_p_udf = p_udf;
10811#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010812#ifdef FEAT_LISP
10813 buf->b_p_lw = empty_option;
10814#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010815
10816 /*
10817 * Don't copy the options set by ex_help(), use the saved values,
10818 * when going from a help buffer to a non-help buffer.
10819 * Don't touch these at all when BCO_NOHELP is used and going from
10820 * or to a help buffer.
10821 */
10822 if (dont_do_help)
10823 buf->b_p_isk = save_p_isk;
10824 else
10825 {
10826 buf->b_p_isk = vim_strsave(p_isk);
10827 did_isk = TRUE;
10828 buf->b_p_ts = p_ts;
10829 buf->b_help = FALSE;
10830#ifdef FEAT_QUICKFIX
10831 if (buf->b_p_bt[0] == 'h')
10832 clear_string_option(&buf->b_p_bt);
10833#endif
10834 buf->b_p_ma = p_ma;
10835 }
10836 }
10837
10838 /*
10839 * When the options should be copied (ignoring BCO_ALWAYS), set the
10840 * flag that indicates that the options have been initialized.
10841 */
10842 if (should_copy)
10843 buf->b_p_initialized = TRUE;
10844 }
10845
10846 check_buf_options(buf); /* make sure we don't have NULLs */
10847 if (did_isk)
10848 (void)buf_init_chartab(buf, FALSE);
10849}
10850
10851/*
10852 * Reset the 'modifiable' option and its default value.
10853 */
10854 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010855reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856{
10857 int opt_idx;
10858
10859 curbuf->b_p_ma = FALSE;
10860 p_ma = FALSE;
10861 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010862 if (opt_idx >= 0)
10863 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864}
10865
10866/*
10867 * Set the global value for 'iminsert' to the local value.
10868 */
10869 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010870set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871{
10872 p_iminsert = curbuf->b_p_iminsert;
10873}
10874
10875/*
10876 * Set the global value for 'imsearch' to the local value.
10877 */
10878 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010879set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880{
10881 p_imsearch = curbuf->b_p_imsearch;
10882}
10883
10884#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10885static int expand_option_idx = -1;
10886static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10887static int expand_option_flags = 0;
10888
10889 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010890set_context_in_set_cmd(
10891 expand_T *xp,
10892 char_u *arg,
10893 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894{
10895 int nextchar;
10896 long_u flags = 0; /* init for GCC */
10897 int opt_idx = 0; /* init for GCC */
10898 char_u *p;
10899 char_u *s;
10900 int is_term_option = FALSE;
10901 int key;
10902
10903 expand_option_flags = opt_flags;
10904
10905 xp->xp_context = EXPAND_SETTINGS;
10906 if (*arg == NUL)
10907 {
10908 xp->xp_pattern = arg;
10909 return;
10910 }
10911 p = arg + STRLEN(arg) - 1;
10912 if (*p == ' ' && *(p - 1) != '\\')
10913 {
10914 xp->xp_pattern = p + 1;
10915 return;
10916 }
10917 while (p > arg)
10918 {
10919 s = p;
10920 /* count number of backslashes before ' ' or ',' */
10921 if (*p == ' ' || *p == ',')
10922 {
10923 while (s > arg && *(s - 1) == '\\')
10924 --s;
10925 }
10926 /* break at a space with an even number of backslashes */
10927 if (*p == ' ' && ((p - s) & 1) == 0)
10928 {
10929 ++p;
10930 break;
10931 }
10932 --p;
10933 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010934 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935 {
10936 xp->xp_context = EXPAND_BOOL_SETTINGS;
10937 p += 2;
10938 }
10939 if (STRNCMP(p, "inv", 3) == 0)
10940 {
10941 xp->xp_context = EXPAND_BOOL_SETTINGS;
10942 p += 3;
10943 }
10944 xp->xp_pattern = arg = p;
10945 if (*arg == '<')
10946 {
10947 while (*p != '>')
10948 if (*p++ == NUL) /* expand terminal option name */
10949 return;
10950 key = get_special_key_code(arg + 1);
10951 if (key == 0) /* unknown name */
10952 {
10953 xp->xp_context = EXPAND_NOTHING;
10954 return;
10955 }
10956 nextchar = *++p;
10957 is_term_option = TRUE;
10958 expand_option_name[2] = KEY2TERMCAP0(key);
10959 expand_option_name[3] = KEY2TERMCAP1(key);
10960 }
10961 else
10962 {
10963 if (p[0] == 't' && p[1] == '_')
10964 {
10965 p += 2;
10966 if (*p != NUL)
10967 ++p;
10968 if (*p == NUL)
10969 return; /* expand option name */
10970 nextchar = *++p;
10971 is_term_option = TRUE;
10972 expand_option_name[2] = p[-2];
10973 expand_option_name[3] = p[-1];
10974 }
10975 else
10976 {
10977 /* Allow * wildcard */
10978 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10979 p++;
10980 if (*p == NUL)
10981 return;
10982 nextchar = *p;
10983 *p = NUL;
10984 opt_idx = findoption(arg);
10985 *p = nextchar;
10986 if (opt_idx == -1 || options[opt_idx].var == NULL)
10987 {
10988 xp->xp_context = EXPAND_NOTHING;
10989 return;
10990 }
10991 flags = options[opt_idx].flags;
10992 if (flags & P_BOOL)
10993 {
10994 xp->xp_context = EXPAND_NOTHING;
10995 return;
10996 }
10997 }
10998 }
10999 /* handle "-=" and "+=" */
11000 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11001 {
11002 ++p;
11003 nextchar = '=';
11004 }
11005 if ((nextchar != '=' && nextchar != ':')
11006 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11007 {
11008 xp->xp_context = EXPAND_UNSUCCESSFUL;
11009 return;
11010 }
11011 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11012 {
11013 xp->xp_context = EXPAND_OLD_SETTING;
11014 if (is_term_option)
11015 expand_option_idx = -1;
11016 else
11017 expand_option_idx = opt_idx;
11018 xp->xp_pattern = p + 1;
11019 return;
11020 }
11021 xp->xp_context = EXPAND_NOTHING;
11022 if (is_term_option || (flags & P_NUM))
11023 return;
11024
11025 xp->xp_pattern = p + 1;
11026
11027 if (flags & P_EXPAND)
11028 {
11029 p = options[opt_idx].var;
11030 if (p == (char_u *)&p_bdir
11031 || p == (char_u *)&p_dir
11032 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011033 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011034 || p == (char_u *)&p_rtp
11035#ifdef FEAT_SEARCHPATH
11036 || p == (char_u *)&p_cdpath
11037#endif
11038#ifdef FEAT_SESSION
11039 || p == (char_u *)&p_vdir
11040#endif
11041 )
11042 {
11043 xp->xp_context = EXPAND_DIRECTORIES;
11044 if (p == (char_u *)&p_path
11045#ifdef FEAT_SEARCHPATH
11046 || p == (char_u *)&p_cdpath
11047#endif
11048 )
11049 xp->xp_backslash = XP_BS_THREE;
11050 else
11051 xp->xp_backslash = XP_BS_ONE;
11052 }
11053 else
11054 {
11055 xp->xp_context = EXPAND_FILES;
11056 /* for 'tags' need three backslashes for a space */
11057 if (p == (char_u *)&p_tags)
11058 xp->xp_backslash = XP_BS_THREE;
11059 else
11060 xp->xp_backslash = XP_BS_ONE;
11061 }
11062 }
11063
11064 /* For an option that is a list of file names, find the start of the
11065 * last file name. */
11066 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11067 {
11068 /* count number of backslashes before ' ' or ',' */
11069 if (*p == ' ' || *p == ',')
11070 {
11071 s = p;
11072 while (s > xp->xp_pattern && *(s - 1) == '\\')
11073 --s;
11074 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11075 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11076 {
11077 xp->xp_pattern = p + 1;
11078 break;
11079 }
11080 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011081
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011082#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011083 /* for 'spellsuggest' start at "file:" */
11084 if (options[opt_idx].var == (char_u *)&p_sps
11085 && STRNCMP(p, "file:", 5) == 0)
11086 {
11087 xp->xp_pattern = p + 5;
11088 break;
11089 }
11090#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 }
11092
11093 return;
11094}
11095
11096 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011097ExpandSettings(
11098 expand_T *xp,
11099 regmatch_T *regmatch,
11100 int *num_file,
11101 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102{
11103 int num_normal = 0; /* Nr of matching non-term-code settings */
11104 int num_term = 0; /* Nr of matching terminal code settings */
11105 int opt_idx;
11106 int match;
11107 int count = 0;
11108 char_u *str;
11109 int loop;
11110 int is_term_opt;
11111 char_u name_buf[MAX_KEY_NAME_LEN];
11112 static char *(names[]) = {"all", "termcap"};
11113 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11114
11115 /* do this loop twice:
11116 * loop == 0: count the number of matching options
11117 * loop == 1: copy the matching options into allocated memory
11118 */
11119 for (loop = 0; loop <= 1; ++loop)
11120 {
11121 regmatch->rm_ic = ic;
11122 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11123 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011124 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11125 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011126 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11127 {
11128 if (loop == 0)
11129 num_normal++;
11130 else
11131 (*file)[count++] = vim_strsave((char_u *)names[match]);
11132 }
11133 }
11134 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11135 opt_idx++)
11136 {
11137 if (options[opt_idx].var == NULL)
11138 continue;
11139 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11140 && !(options[opt_idx].flags & P_BOOL))
11141 continue;
11142 is_term_opt = istermoption(&options[opt_idx]);
11143 if (is_term_opt && num_normal > 0)
11144 continue;
11145 match = FALSE;
11146 if (vim_regexec(regmatch, str, (colnr_T)0)
11147 || (options[opt_idx].shortname != NULL
11148 && vim_regexec(regmatch,
11149 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11150 match = TRUE;
11151 else if (is_term_opt)
11152 {
11153 name_buf[0] = '<';
11154 name_buf[1] = 't';
11155 name_buf[2] = '_';
11156 name_buf[3] = str[2];
11157 name_buf[4] = str[3];
11158 name_buf[5] = '>';
11159 name_buf[6] = NUL;
11160 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11161 {
11162 match = TRUE;
11163 str = name_buf;
11164 }
11165 }
11166 if (match)
11167 {
11168 if (loop == 0)
11169 {
11170 if (is_term_opt)
11171 num_term++;
11172 else
11173 num_normal++;
11174 }
11175 else
11176 (*file)[count++] = vim_strsave(str);
11177 }
11178 }
11179 /*
11180 * Check terminal key codes, these are not in the option table
11181 */
11182 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11183 {
11184 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11185 {
11186 if (!isprint(str[0]) || !isprint(str[1]))
11187 continue;
11188
11189 name_buf[0] = 't';
11190 name_buf[1] = '_';
11191 name_buf[2] = str[0];
11192 name_buf[3] = str[1];
11193 name_buf[4] = NUL;
11194
11195 match = FALSE;
11196 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11197 match = TRUE;
11198 else
11199 {
11200 name_buf[0] = '<';
11201 name_buf[1] = 't';
11202 name_buf[2] = '_';
11203 name_buf[3] = str[0];
11204 name_buf[4] = str[1];
11205 name_buf[5] = '>';
11206 name_buf[6] = NUL;
11207
11208 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11209 match = TRUE;
11210 }
11211 if (match)
11212 {
11213 if (loop == 0)
11214 num_term++;
11215 else
11216 (*file)[count++] = vim_strsave(name_buf);
11217 }
11218 }
11219
11220 /*
11221 * Check special key names.
11222 */
11223 regmatch->rm_ic = TRUE; /* ignore case here */
11224 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11225 {
11226 name_buf[0] = '<';
11227 STRCPY(name_buf + 1, str);
11228 STRCAT(name_buf, ">");
11229
11230 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11231 {
11232 if (loop == 0)
11233 num_term++;
11234 else
11235 (*file)[count++] = vim_strsave(name_buf);
11236 }
11237 }
11238 }
11239 if (loop == 0)
11240 {
11241 if (num_normal > 0)
11242 *num_file = num_normal;
11243 else if (num_term > 0)
11244 *num_file = num_term;
11245 else
11246 return OK;
11247 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11248 if (*file == NULL)
11249 {
11250 *file = (char_u **)"";
11251 return FAIL;
11252 }
11253 }
11254 }
11255 return OK;
11256}
11257
11258 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011259ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011260{
11261 char_u *var = NULL; /* init for GCC */
11262 char_u *buf;
11263
11264 *num_file = 0;
11265 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11266 if (*file == NULL)
11267 return FAIL;
11268
11269 /*
11270 * For a terminal key code expand_option_idx is < 0.
11271 */
11272 if (expand_option_idx < 0)
11273 {
11274 var = find_termcode(expand_option_name + 2);
11275 if (var == NULL)
11276 expand_option_idx = findoption(expand_option_name);
11277 }
11278
11279 if (expand_option_idx >= 0)
11280 {
11281 /* put string of option value in NameBuff */
11282 option_value2string(&options[expand_option_idx], expand_option_flags);
11283 var = NameBuff;
11284 }
11285 else if (var == NULL)
11286 var = (char_u *)"";
11287
11288 /* A backslash is required before some characters. This is the reverse of
11289 * what happens in do_set(). */
11290 buf = vim_strsave_escaped(var, escape_chars);
11291
11292 if (buf == NULL)
11293 {
11294 vim_free(*file);
11295 *file = NULL;
11296 return FAIL;
11297 }
11298
11299#ifdef BACKSLASH_IN_FILENAME
11300 /* For MS-Windows et al. we don't double backslashes at the start and
11301 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011302 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011303 if (var[0] == '\\' && var[1] == '\\'
11304 && expand_option_idx >= 0
11305 && (options[expand_option_idx].flags & P_EXPAND)
11306 && vim_isfilec(var[2])
11307 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011308 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011309#endif
11310
11311 *file[0] = buf;
11312 *num_file = 1;
11313 return OK;
11314}
11315#endif
11316
11317/*
11318 * Get the value for the numeric or string option *opp in a nice format into
11319 * NameBuff[]. Must not be called with a hidden option!
11320 */
11321 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011322option_value2string(
11323 struct vimoption *opp,
11324 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011325{
11326 char_u *varp;
11327
11328 varp = get_varp_scope(opp, opt_flags);
11329
11330 if (opp->flags & P_NUM)
11331 {
11332 long wc = 0;
11333
11334 if (wc_use_keyname(varp, &wc))
11335 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11336 else if (wc != 0)
11337 STRCPY(NameBuff, transchar((int)wc));
11338 else
11339 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11340 }
11341 else /* P_STRING */
11342 {
11343 varp = *(char_u **)(varp);
11344 if (varp == NULL) /* just in case */
11345 NameBuff[0] = NUL;
11346#ifdef FEAT_CRYPT
11347 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011348 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349 STRCPY(NameBuff, "*****");
11350#endif
11351 else if (opp->flags & P_EXPAND)
11352 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11353 /* Translate 'pastetoggle' into special key names */
11354 else if ((char_u **)opp->var == &p_pt)
11355 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11356 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011357 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011358 }
11359}
11360
11361/*
11362 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11363 * printed as a keyname.
11364 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11365 */
11366 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011367wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368{
11369 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11370 {
11371 *wcp = *(long *)varp;
11372 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11373 return TRUE;
11374 }
11375 return FALSE;
11376}
11377
Bram Moolenaar01615492015-02-03 13:00:38 +010011378#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011380 * Any character has an equivalent 'langmap' character. This is used for
11381 * keyboards that have a special language mode that sends characters above
11382 * 128 (although other characters can be translated too). The "to" field is a
11383 * Vim command character. This avoids having to switch the keyboard back to
11384 * ASCII mode when leaving Insert mode.
11385 *
11386 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11387 * commands.
11388 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11389 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11390 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011392# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011393/*
11394 * With multi-byte support use growarray for 'langmap' chars >= 256
11395 */
11396typedef struct
11397{
11398 int from;
11399 int to;
11400} langmap_entry_T;
11401
11402static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011403static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011404
11405/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011406 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11407 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011409 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011410langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011411{
11412 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011413 int a = 0;
11414 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011415
11416 /* Do a binary search for an existing entry. */
11417 while (a != b)
11418 {
11419 int i = (a + b) / 2;
11420 int d = entries[i].from - from;
11421
11422 if (d == 0)
11423 {
11424 entries[i].to = to;
11425 return;
11426 }
11427 if (d < 0)
11428 a = i + 1;
11429 else
11430 b = i;
11431 }
11432
11433 if (ga_grow(&langmap_mapga, 1) != OK)
11434 return; /* out of memory */
11435
11436 /* insert new entry at position "a" */
11437 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11438 mch_memmove(entries + 1, entries,
11439 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11440 ++langmap_mapga.ga_len;
11441 entries[0].from = from;
11442 entries[0].to = to;
11443}
11444
11445/*
11446 * Apply 'langmap' to multi-byte character "c" and return the result.
11447 */
11448 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011449langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011450{
11451 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11452 int a = 0;
11453 int b = langmap_mapga.ga_len;
11454
11455 while (a != b)
11456 {
11457 int i = (a + b) / 2;
11458 int d = entries[i].from - c;
11459
11460 if (d == 0)
11461 return entries[i].to; /* found matching entry */
11462 if (d < 0)
11463 a = i + 1;
11464 else
11465 b = i;
11466 }
11467 return c; /* no entry found, return "c" unmodified */
11468}
11469# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011470
11471 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011472langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011473{
11474 int i;
11475
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011476 for (i = 0; i < 256; i++)
11477 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11478# ifdef FEAT_MBYTE
11479 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11480# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011481}
11482
11483/*
11484 * Called when langmap option is set; the language map can be
11485 * changed at any time!
11486 */
11487 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011488langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011489{
11490 char_u *p;
11491 char_u *p2;
11492 int from, to;
11493
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011494#ifdef FEAT_MBYTE
11495 ga_clear(&langmap_mapga); /* clear the previous map first */
11496#endif
11497 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011498
11499 for (p = p_langmap; p[0] != NUL; )
11500 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011501 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11502 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011503 {
11504 if (p2[0] == '\\' && p2[1] != NUL)
11505 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011506 }
11507 if (p2[0] == ';')
11508 ++p2; /* abcd;ABCD form, p2 points to A */
11509 else
11510 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11511 while (p[0])
11512 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011513 if (p[0] == ',')
11514 {
11515 ++p;
11516 break;
11517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011518 if (p[0] == '\\' && p[1] != NUL)
11519 ++p;
11520#ifdef FEAT_MBYTE
11521 from = (*mb_ptr2char)(p);
11522#else
11523 from = p[0];
11524#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011525 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526 if (p2 == NULL)
11527 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011528 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011529 if (p[0] != ',')
11530 {
11531 if (p[0] == '\\')
11532 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011534 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011536 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011537#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011538 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011539 }
11540 else
11541 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011542 if (p2[0] != ',')
11543 {
11544 if (p2[0] == '\\')
11545 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011547 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011548#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011549 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011550#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011551 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011552 }
11553 if (to == NUL)
11554 {
11555 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11556 transchar(from));
11557 return;
11558 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011559
11560#ifdef FEAT_MBYTE
11561 if (from >= 256)
11562 langmap_set_entry(from, to);
11563 else
11564#endif
11565 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566
11567 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011568 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011569 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011570 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011571 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011572 if (*p == ';')
11573 {
11574 p = p2;
11575 if (p[0] != NUL)
11576 {
11577 if (p[0] != ',')
11578 {
11579 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11580 return;
11581 }
11582 ++p;
11583 }
11584 break;
11585 }
11586 }
11587 }
11588 }
11589}
11590#endif
11591
11592/*
11593 * Return TRUE if format option 'x' is in effect.
11594 * Take care of no formatting when 'paste' is set.
11595 */
11596 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011597has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011598{
11599 if (p_paste)
11600 return FALSE;
11601 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11602}
11603
11604/*
11605 * Return TRUE if "x" is present in 'shortmess' option, or
11606 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11607 */
11608 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011609shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011611 return p_shm != NULL &&
11612 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011613 || (vim_strchr(p_shm, 'a') != NULL
11614 && vim_strchr((char_u *)SHM_A, x) != NULL));
11615}
11616
11617/*
11618 * paste_option_changed() - Called after p_paste was set or reset.
11619 */
11620 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011621paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622{
11623 static int old_p_paste = FALSE;
11624 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011625 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011626#ifdef FEAT_CMDL_INFO
11627 static int save_ru = 0;
11628#endif
11629#ifdef FEAT_RIGHTLEFT
11630 static int save_ri = 0;
11631 static int save_hkmap = 0;
11632#endif
11633 buf_T *buf;
11634
11635 if (p_paste)
11636 {
11637 /*
11638 * Paste switched from off to on.
11639 * Save the current values, so they can be restored later.
11640 */
11641 if (!old_p_paste)
11642 {
11643 /* save options for each buffer */
11644 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11645 {
11646 buf->b_p_tw_nopaste = buf->b_p_tw;
11647 buf->b_p_wm_nopaste = buf->b_p_wm;
11648 buf->b_p_sts_nopaste = buf->b_p_sts;
11649 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011650 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011651 }
11652
11653 /* save global options */
11654 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011655 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011656#ifdef FEAT_CMDL_INFO
11657 save_ru = p_ru;
11658#endif
11659#ifdef FEAT_RIGHTLEFT
11660 save_ri = p_ri;
11661 save_hkmap = p_hkmap;
11662#endif
11663 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011664 p_ai_nopaste = p_ai;
11665 p_et_nopaste = p_et;
11666 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011667 p_tw_nopaste = p_tw;
11668 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011669 }
11670
11671 /*
11672 * Always set the option values, also when 'paste' is set when it is
11673 * already on.
11674 */
11675 /* set options for each buffer */
11676 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11677 {
11678 buf->b_p_tw = 0; /* textwidth is 0 */
11679 buf->b_p_wm = 0; /* wrapmargin is 0 */
11680 buf->b_p_sts = 0; /* softtabstop is 0 */
11681 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011682 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011683 }
11684
11685 /* set global options */
11686 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011687 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011688#ifdef FEAT_CMDL_INFO
11689# ifdef FEAT_WINDOWS
11690 if (p_ru)
11691 status_redraw_all(); /* redraw to remove the ruler */
11692# endif
11693 p_ru = 0; /* no ruler */
11694#endif
11695#ifdef FEAT_RIGHTLEFT
11696 p_ri = 0; /* no reverse insert */
11697 p_hkmap = 0; /* no Hebrew keyboard */
11698#endif
11699 /* set global values for local buffer options */
11700 p_tw = 0;
11701 p_wm = 0;
11702 p_sts = 0;
11703 p_ai = 0;
11704 }
11705
11706 /*
11707 * Paste switched from on to off: Restore saved values.
11708 */
11709 else if (old_p_paste)
11710 {
11711 /* restore options for each buffer */
11712 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11713 {
11714 buf->b_p_tw = buf->b_p_tw_nopaste;
11715 buf->b_p_wm = buf->b_p_wm_nopaste;
11716 buf->b_p_sts = buf->b_p_sts_nopaste;
11717 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011718 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011719 }
11720
11721 /* restore global options */
11722 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011723 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011724#ifdef FEAT_CMDL_INFO
11725# ifdef FEAT_WINDOWS
11726 if (p_ru != save_ru)
11727 status_redraw_all(); /* redraw to draw the ruler */
11728# endif
11729 p_ru = save_ru;
11730#endif
11731#ifdef FEAT_RIGHTLEFT
11732 p_ri = save_ri;
11733 p_hkmap = save_hkmap;
11734#endif
11735 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011736 p_ai = p_ai_nopaste;
11737 p_et = p_et_nopaste;
11738 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011739 p_tw = p_tw_nopaste;
11740 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741 }
11742
11743 old_p_paste = p_paste;
11744}
11745
11746/*
11747 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11748 *
11749 * Reset 'compatible' and set the values for options that didn't get set yet
11750 * to the Vim defaults.
11751 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011752 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011753 */
11754 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011755vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011756{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011757 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011758 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011759 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011760
11761 if (!option_was_set((char_u *)"cp"))
11762 {
11763 p_cp = FALSE;
11764 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11765 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11766 set_option_default(opt_idx, OPT_FREE, FALSE);
11767 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011768 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011769 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011770
11771 if (fname != NULL)
11772 {
11773 p = vim_getenv(envname, &dofree);
11774 if (p == NULL)
11775 {
11776 /* Set $MYVIMRC to the first vimrc file found. */
11777 p = FullName_save(fname, FALSE);
11778 if (p != NULL)
11779 {
11780 vim_setenv(envname, p);
11781 vim_free(p);
11782 }
11783 }
11784 else if (dofree)
11785 vim_free(p);
11786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011787}
11788
11789/*
11790 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11791 */
11792 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011793change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011795 int opt_idx;
11796
Bram Moolenaar071d4272004-06-13 20:20:40 +000011797 if (p_cp != on)
11798 {
11799 p_cp = on;
11800 compatible_set();
11801 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011802 opt_idx = findoption((char_u *)"cp");
11803 if (opt_idx >= 0)
11804 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805}
11806
11807/*
11808 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011809 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011810 */
11811 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011812option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011813{
11814 int idx;
11815
11816 idx = findoption(name);
11817 if (idx < 0) /* unknown option */
11818 return FALSE;
11819 if (options[idx].flags & P_WAS_SET)
11820 return TRUE;
11821 return FALSE;
11822}
11823
11824/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011825 * Reset the flag indicating option "name" was set.
11826 */
11827 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011828reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011829{
11830 int idx = findoption(name);
11831
11832 if (idx >= 0)
11833 options[idx].flags &= ~P_WAS_SET;
11834}
11835
11836/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837 * compatible_set() - Called when 'compatible' has been set or unset.
11838 *
11839 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11840 * flag) to a Vi compatible value.
11841 * When 'compatible' is unset: Set all options that have a different default
11842 * for Vim (without the P_VI_DEF flag) to that default.
11843 */
11844 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011845compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011846{
11847 int opt_idx;
11848
11849 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11850 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11851 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11852 set_option_default(opt_idx, OPT_FREE, p_cp);
11853 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011854 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855}
11856
11857#ifdef FEAT_LINEBREAK
11858
11859# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11860 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011861 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011862# endif
11863
11864/*
11865 * fill_breakat_flags() -- called when 'breakat' changes value.
11866 */
11867 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011868fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011870 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011871 int i;
11872
11873 for (i = 0; i < 256; i++)
11874 breakat_flags[i] = FALSE;
11875
11876 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011877 for (p = p_breakat; *p; p++)
11878 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011879}
11880
11881# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011882 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883# endif
11884
11885#endif
11886
11887/*
11888 * Check an option that can be a range of string values.
11889 *
11890 * Return OK for correct value, FAIL otherwise.
11891 * Empty is always OK.
11892 */
11893 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011894check_opt_strings(
11895 char_u *val,
11896 char **values,
11897 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011898{
11899 return opt_strings_flags(val, values, NULL, list);
11900}
11901
11902/*
11903 * Handle an option that can be a range of string values.
11904 * Set a flag in "*flagp" for each string present.
11905 *
11906 * Return OK for correct value, FAIL otherwise.
11907 * Empty is always OK.
11908 */
11909 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011910opt_strings_flags(
11911 char_u *val, /* new value */
11912 char **values, /* array of valid string values */
11913 unsigned *flagp,
11914 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915{
11916 int i;
11917 int len;
11918 unsigned new_flags = 0;
11919
11920 while (*val)
11921 {
11922 for (i = 0; ; ++i)
11923 {
11924 if (values[i] == NULL) /* val not found in values[] */
11925 return FAIL;
11926
11927 len = (int)STRLEN(values[i]);
11928 if (STRNCMP(values[i], val, len) == 0
11929 && ((list && val[len] == ',') || val[len] == NUL))
11930 {
11931 val += len + (val[len] == ',');
11932 new_flags |= (1 << i);
11933 break; /* check next item in val list */
11934 }
11935 }
11936 }
11937 if (flagp != NULL)
11938 *flagp = new_flags;
11939
11940 return OK;
11941}
11942
11943/*
11944 * Read the 'wildmode' option, fill wim_flags[].
11945 */
11946 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011947check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011948{
11949 char_u new_wim_flags[4];
11950 char_u *p;
11951 int i;
11952 int idx = 0;
11953
11954 for (i = 0; i < 4; ++i)
11955 new_wim_flags[i] = 0;
11956
11957 for (p = p_wim; *p; ++p)
11958 {
11959 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11960 ;
11961 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11962 return FAIL;
11963 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11964 new_wim_flags[idx] |= WIM_LONGEST;
11965 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11966 new_wim_flags[idx] |= WIM_FULL;
11967 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11968 new_wim_flags[idx] |= WIM_LIST;
11969 else
11970 return FAIL;
11971 p += i;
11972 if (*p == NUL)
11973 break;
11974 if (*p == ',')
11975 {
11976 if (idx == 3)
11977 return FAIL;
11978 ++idx;
11979 }
11980 }
11981
11982 /* fill remaining entries with last flag */
11983 while (idx < 3)
11984 {
11985 new_wim_flags[idx + 1] = new_wim_flags[idx];
11986 ++idx;
11987 }
11988
11989 /* only when there are no errors, wim_flags[] is changed */
11990 for (i = 0; i < 4; ++i)
11991 wim_flags[i] = new_wim_flags[i];
11992 return OK;
11993}
11994
11995/*
11996 * Check if backspacing over something is allowed.
11997 */
11998 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011999can_bs(
12000 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001{
12002 switch (*p_bs)
12003 {
12004 case '2': return TRUE;
12005 case '1': return (what != BS_START);
12006 case '0': return FALSE;
12007 }
12008 return vim_strchr(p_bs, what) != NULL;
12009}
12010
12011/*
12012 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12013 * the file must be considered changed when the value is different.
12014 */
12015 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012016save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012017{
12018 buf->b_start_ffc = *buf->b_p_ff;
12019 buf->b_start_eol = buf->b_p_eol;
12020#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012021 buf->b_start_bomb = buf->b_p_bomb;
12022
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023 /* Only use free/alloc when necessary, they take time. */
12024 if (buf->b_start_fenc == NULL
12025 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12026 {
12027 vim_free(buf->b_start_fenc);
12028 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12029 }
12030#endif
12031}
12032
12033/*
12034 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12035 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012036 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12037 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012038 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012039 * When "ignore_empty" is true don't consider a new, empty buffer to be
12040 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012041 */
12042 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012043file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012044{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012045 /* In a buffer that was never loaded the options are not valid. */
12046 if (buf->b_flags & BF_NEVERLOADED)
12047 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012048 if (ignore_empty
12049 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 && buf->b_ml.ml_line_count == 1
12051 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12052 return FALSE;
12053 if (buf->b_start_ffc != *buf->b_p_ff)
12054 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012055 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056 return TRUE;
12057#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012058 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12059 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012060 if (buf->b_start_fenc == NULL)
12061 return (*buf->b_p_fenc != NUL);
12062 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12063#else
12064 return FALSE;
12065#endif
12066}
12067
12068/*
12069 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12070 */
12071 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012072check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012073{
12074 return check_opt_strings(p, p_ff_values, FALSE);
12075}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012076
12077/*
12078 * Return the effective shiftwidth value for current buffer, using the
12079 * 'tabstop' value when 'shiftwidth' is zero.
12080 */
12081 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012082get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012083{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012084 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012085}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012086
12087/*
12088 * Return the effective softtabstop value for the current buffer, using the
12089 * 'tabstop' value when 'softtabstop' is negative.
12090 */
12091 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012092get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012093{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012094 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012095}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012096
12097/*
12098 * Check matchpairs option for "*initc".
12099 * If there is a match set "*initc" to the matching character and "*findc" to
12100 * the opposite character. Set "*backwards" to the direction.
12101 * When "switchit" is TRUE swap the direction.
12102 */
12103 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012104find_mps_values(
12105 int *initc,
12106 int *findc,
12107 int *backwards,
12108 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012109{
12110 char_u *ptr;
12111
12112 ptr = curbuf->b_p_mps;
12113 while (*ptr != NUL)
12114 {
12115#ifdef FEAT_MBYTE
12116 if (has_mbyte)
12117 {
12118 char_u *prev;
12119
12120 if (mb_ptr2char(ptr) == *initc)
12121 {
12122 if (switchit)
12123 {
12124 *findc = *initc;
12125 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12126 *backwards = TRUE;
12127 }
12128 else
12129 {
12130 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12131 *backwards = FALSE;
12132 }
12133 return;
12134 }
12135 prev = ptr;
12136 ptr += mb_ptr2len(ptr) + 1;
12137 if (mb_ptr2char(ptr) == *initc)
12138 {
12139 if (switchit)
12140 {
12141 *findc = *initc;
12142 *initc = mb_ptr2char(prev);
12143 *backwards = FALSE;
12144 }
12145 else
12146 {
12147 *findc = mb_ptr2char(prev);
12148 *backwards = TRUE;
12149 }
12150 return;
12151 }
12152 ptr += mb_ptr2len(ptr);
12153 }
12154 else
12155#endif
12156 {
12157 if (*ptr == *initc)
12158 {
12159 if (switchit)
12160 {
12161 *backwards = TRUE;
12162 *findc = *initc;
12163 *initc = ptr[2];
12164 }
12165 else
12166 {
12167 *backwards = FALSE;
12168 *findc = ptr[2];
12169 }
12170 return;
12171 }
12172 ptr += 2;
12173 if (*ptr == *initc)
12174 {
12175 if (switchit)
12176 {
12177 *backwards = FALSE;
12178 *findc = *initc;
12179 *initc = ptr[-2];
12180 }
12181 else
12182 {
12183 *backwards = TRUE;
12184 *findc = ptr[-2];
12185 }
12186 return;
12187 }
12188 ++ptr;
12189 }
12190 if (*ptr == ',')
12191 ++ptr;
12192 }
12193}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012194
12195#if defined(FEAT_LINEBREAK) || defined(PROTO)
12196/*
12197 * This is called when 'breakindentopt' is changed and when a window is
12198 * initialized.
12199 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012200 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012201briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012202{
12203 char_u *p;
12204 int bri_shift = 0;
12205 long bri_min = 20;
12206 int bri_sbr = FALSE;
12207
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012208 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012209 while (*p != NUL)
12210 {
12211 if (STRNCMP(p, "shift:", 6) == 0
12212 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12213 {
12214 p += 6;
12215 bri_shift = getdigits(&p);
12216 }
12217 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12218 {
12219 p += 4;
12220 bri_min = getdigits(&p);
12221 }
12222 else if (STRNCMP(p, "sbr", 3) == 0)
12223 {
12224 p += 3;
12225 bri_sbr = TRUE;
12226 }
12227 if (*p != ',' && *p != NUL)
12228 return FAIL;
12229 if (*p == ',')
12230 ++p;
12231 }
12232
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012233 wp->w_p_brishift = bri_shift;
12234 wp->w_p_brimin = bri_min;
12235 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012236
12237 return OK;
12238}
12239#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012240
12241/*
12242 * Get the local or global value of 'backupcopy'.
12243 */
12244 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012245get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012246{
12247 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12248}