blob: 288c01bbaaf258a55543391c13756fcb6f404aa3 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000110#ifdef FEAT_EVAL
111# define PV_FEX OPT_BUF(BV_FEX)
112#endif
113#define PV_FF OPT_BUF(BV_FF)
114#define PV_FLP OPT_BUF(BV_FLP)
115#define PV_FO OPT_BUF(BV_FO)
116#ifdef FEAT_AUTOCMD
117# define PV_FT OPT_BUF(BV_FT)
118#endif
119#define PV_IMI OPT_BUF(BV_IMI)
120#define PV_IMS OPT_BUF(BV_IMS)
121#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
122# define PV_INDE OPT_BUF(BV_INDE)
123# define PV_INDK OPT_BUF(BV_INDK)
124#endif
125#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
126# define PV_INEX OPT_BUF(BV_INEX)
127#endif
128#define PV_INF OPT_BUF(BV_INF)
129#define PV_ISK OPT_BUF(BV_ISK)
130#ifdef FEAT_CRYPT
131# define PV_KEY OPT_BUF(BV_KEY)
132#endif
133#ifdef FEAT_KEYMAP
134# define PV_KMAP OPT_BUF(BV_KMAP)
135#endif
136#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
137#ifdef FEAT_LISP
138# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100139# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000140#endif
141#define PV_MA OPT_BUF(BV_MA)
142#define PV_ML OPT_BUF(BV_ML)
143#define PV_MOD OPT_BUF(BV_MOD)
144#define PV_MPS OPT_BUF(BV_MPS)
145#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100158#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000159#ifdef FEAT_SYN_HL
160# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000161# define PV_SYN OPT_BUF(BV_SYN)
162#endif
163#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164# define PV_SPC OPT_BUF(BV_SPC)
165# define PV_SPF OPT_BUF(BV_SPF)
166# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000167#endif
168#define PV_STS OPT_BUF(BV_STS)
169#ifdef FEAT_SEARCHPATH
170# define PV_SUA OPT_BUF(BV_SUA)
171#endif
172#define PV_SW OPT_BUF(BV_SW)
173#define PV_SWF OPT_BUF(BV_SWF)
174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100175#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200179#ifdef FEAT_PERSISTENT_UNDO
180# define PV_UDF OPT_BUF(BV_UDF)
181#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
221#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
228#ifdef FEAT_SCROLLBIND
229# define PV_SCBIND OPT_WIN(WV_SCBIND)
230#endif
231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_WINDOWS
245# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000246# define PV_WFW OPT_WIN(WV_WFW)
247#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200249#ifdef FEAT_CURSORBIND
250# define PV_CRBIND OPT_WIN(WV_CRBIND)
251#endif
252#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200253# define PV_COCU OPT_WIN(WV_COCU)
254# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200255#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000256
257/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000258typedef enum
259{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000260 PV_NONE = 0,
261 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262} idopt_T;
263
264/*
265 * Options local to a window have a value local to a buffer and global to all
266 * buffers. Indicate this by setting "var" to VAR_WIN.
267 */
268#define VAR_WIN ((char_u *)-1)
269
270/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000271 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000272 * Only to be used in option.c!
273 */
274static int p_ai;
275static int p_bin;
276#ifdef FEAT_MBYTE
277static int p_bomb;
278#endif
279#if defined(FEAT_QUICKFIX)
280static char_u *p_bh;
281static char_u *p_bt;
282#endif
283static int p_bl;
284static int p_ci;
285#ifdef FEAT_CINDENT
286static int p_cin;
287static char_u *p_cink;
288static char_u *p_cino;
289#endif
290#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
291static char_u *p_cinw;
292#endif
293#ifdef FEAT_COMMENTS
294static char_u *p_com;
295#endif
296#ifdef FEAT_FOLDING
297static char_u *p_cms;
298#endif
299#ifdef FEAT_INS_EXPAND
300static char_u *p_cpt;
301#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000302#ifdef FEAT_COMPL_FUNC
303static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000304static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200307static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_et;
309#ifdef FEAT_MBYTE
310static char_u *p_fenc;
311#endif
312static char_u *p_ff;
313static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000314static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315#ifdef FEAT_AUTOCMD
316static char_u *p_ft;
317#endif
318static long p_iminsert;
319static long p_imsearch;
320#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
321static char_u *p_inex;
322#endif
323#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
324static char_u *p_inde;
325static char_u *p_indk;
326#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000327#if defined(FEAT_EVAL)
328static char_u *p_fex;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330static int p_inf;
331static char_u *p_isk;
332#ifdef FEAT_CRYPT
333static char_u *p_key;
334#endif
335#ifdef FEAT_LISP
336static int p_lisp;
337#endif
338static int p_ml;
339static int p_ma;
340static int p_mod;
341static char_u *p_mps;
342static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static long p_sts;
353#if defined(FEAT_SEARCHPATH)
354static char_u *p_sua;
355#endif
356static long p_sw;
357static int p_swf;
358#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000359static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000361#endif
362#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000363static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000364static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000365static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366#endif
367static long p_ts;
368static long p_tw;
369static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200370#ifdef FEAT_PERSISTENT_UNDO
371static int p_udf;
372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373static long p_wm;
374#ifdef FEAT_KEYMAP
375static char_u *p_keymap;
376#endif
377
378/* Saved values for when 'bin' is set. */
379static int p_et_nobin;
380static int p_ml_nobin;
381static long p_tw_nobin;
382static long p_wm_nobin;
383
384/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200385static int p_ai_nopaste;
386static int p_et_nopaste;
387static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388static long p_tw_nopaste;
389static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390
391struct vimoption
392{
393 char *fullname; /* full option name */
394 char *shortname; /* permissible abbreviation */
395 long_u flags; /* see below */
396 char_u *var; /* global option: pointer to variable;
397 * window-local option: VAR_WIN;
398 * buffer-local option: global value */
399 idopt_T indir; /* global option: PV_NONE;
400 * local option: indirect option index */
401 char_u *def_val[2]; /* default values for variable (vi and vim) */
402#ifdef FEAT_EVAL
403 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000404# define SCRIPTID_INIT , 0
405#else
406# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000407#endif
408};
409
410#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
411#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
412
413/*
414 * Flags
415 */
416#define P_BOOL 0x01 /* the option is boolean */
417#define P_NUM 0x02 /* the option is numeric */
418#define P_STRING 0x04 /* the option is a string */
419#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000420 must use free_string_option() when
421 assigning new value. Not set if default is
422 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000423#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
424 never be used for local or hidden options! */
425#define P_NODEFAULT 0x40 /* don't set to default value */
426#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
427 use vim_free() when assigning new value */
428#define P_WAS_SET 0x100 /* option has been set/reset */
429#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
430#define P_VI_DEF 0x400 /* Use Vi default for Vim */
431#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
432
433 /* when option changed, what to display: */
434#define P_RSTAT 0x1000 /* redraw status lines */
435#define P_RWIN 0x2000 /* redraw current window */
436#define P_RBUF 0x4000 /* redraw current buffer */
437#define P_RALL 0x6000 /* redraw all windows */
438#define P_RCLR 0x7000 /* clear and redraw all */
439
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200440#define P_COMMA 0x8000 /* comma separated list */
441#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
442 * commas */
443#define P_NODUP 0x20000L /* don't allow duplicate strings */
444#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200446#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
447#define P_GETTEXT 0x100000L /* expand default value with _() */
448#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
449#define P_NFNAME 0x400000L /* only normal file name chars allowed */
450#define P_INSECURE 0x800000L /* option was set from a modeline */
451#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000452 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_NO_ML 0x2000000L /* not allowed in modeline */
454#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200455 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000457#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
458
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000459/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
460 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100461#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000462# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000463#else
464# define ISP_LATIN1 (char_u *)"@,161-255"
465#endif
466
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100467/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000468#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100469 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200470 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100471# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000472#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100473# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000474#endif
475
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476/*
477 * options[] is initialized here.
478 * The order of the options MUST be alphabetic for ":set all" and findoption().
479 * All option names MUST start with a lowercase letter (for findoption()).
480 * Exception: "t_" options are at the end.
481 * The options with a NULL variable are 'hidden': a set command for them is
482 * ignored and they are not printed.
483 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100484static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000485{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200486 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000487#ifdef FEAT_RIGHTLEFT
488 (char_u *)&p_aleph, PV_NONE,
489#else
490 (char_u *)NULL, PV_NONE,
491#endif
492 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100493#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494 (char_u *)128L,
495#else
496 (char_u *)224L,
497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
500#if defined(FEAT_GUI) && defined(MACOS_X)
501 (char_u *)&p_antialias, PV_NONE,
502 {(char_u *)FALSE, (char_u *)FALSE}
503#else
504 (char_u *)NULL, PV_NONE,
505 {(char_u *)FALSE, (char_u *)FALSE}
506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000507 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200508 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509#ifdef FEAT_ARABIC
510 (char_u *)VAR_WIN, PV_ARAB,
511#else
512 (char_u *)NULL, PV_NONE,
513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
516#ifdef FEAT_ARABIC
517 (char_u *)&p_arshape, PV_NONE,
518#else
519 (char_u *)NULL, PV_NONE,
520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000521 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
523#ifdef FEAT_RIGHTLEFT
524 (char_u *)&p_ari, PV_NONE,
525#else
526 (char_u *)NULL, PV_NONE,
527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000528 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
530#ifdef FEAT_FKMAP
531 (char_u *)&p_altkeymap, PV_NONE,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
537#if defined(FEAT_MBYTE)
538 (char_u *)&p_ambw, PV_NONE,
539 {(char_u *)"single", (char_u *)0L}
540#else
541 (char_u *)NULL, PV_NONE,
542 {(char_u *)0L, (char_u *)0L}
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000545#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"autochdir", "acd", P_BOOL|P_VI_DEF,
547 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549#endif
550 {"autoindent", "ai", P_BOOL|P_VI_DEF,
551 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autoprint", "ap", P_BOOL|P_VI_DEF,
554 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000557 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autowrite", "aw", P_BOOL|P_VI_DEF,
560 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autowriteall","awa", P_BOOL|P_VI_DEF,
563 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
566 (char_u *)&p_bg, PV_NONE,
567 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100568#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 (char_u *)"dark",
570#else
571 (char_u *)"light",
572#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200574 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
578 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200580 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200581 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582#ifdef UNIX
583 {(char_u *)"yes", (char_u *)"auto"}
584#else
585 {(char_u *)"auto", (char_u *)"auto"}
586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200588 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
589 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000591 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000592 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)&p_bex, PV_NONE,
594 {
595#ifdef VMS
596 (char_u *)"_",
597#else
598 (char_u *)"~",
599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200601 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602#ifdef FEAT_WILDIGN
603 (char_u *)&p_bsk, PV_NONE,
604 {(char_u *)"", (char_u *)0L}
605#else
606 (char_u *)NULL, PV_NONE,
607 {(char_u *)0L, (char_u *)0L}
608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000609 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610#ifdef FEAT_BEVAL
611 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
612 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
615 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000617# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000618 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000619 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000621# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622#endif
623 {"beautify", "bf", P_BOOL|P_VI_DEF,
624 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200626 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
627 (char_u *)&p_bo, PV_NONE,
628 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
630 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
636#ifdef FEAT_MBYTE
637 (char_u *)&p_bomb, PV_BOMB,
638#else
639 (char_u *)NULL, PV_NONE,
640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000641 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
643#ifdef FEAT_LINEBREAK
644 (char_u *)&p_breakat, PV_NONE,
645 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
646#else
647 (char_u *)NULL, PV_NONE,
648 {(char_u *)0L, (char_u *)0L}
649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000650 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200651 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
652#ifdef FEAT_LINEBREAK
653 (char_u *)VAR_WIN, PV_BRI,
654 {(char_u *)FALSE, (char_u *)0L}
655#else
656 (char_u *)NULL, PV_NONE,
657 {(char_u *)0L, (char_u *)0L}
658#endif
659 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200660 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
661 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200662#ifdef FEAT_LINEBREAK
663 (char_u *)VAR_WIN, PV_BRIOPT,
664 {(char_u *)"", (char_u *)NULL}
665#else
666 (char_u *)NULL, PV_NONE,
667 {(char_u *)"", (char_u *)NULL}
668#endif
669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
671#ifdef FEAT_BROWSE
672 (char_u *)&p_bsdir, PV_NONE,
673 {(char_u *)"last", (char_u *)0L}
674#else
675 (char_u *)NULL, PV_NONE,
676 {(char_u *)0L, (char_u *)0L}
677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000679 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
680#if defined(FEAT_QUICKFIX)
681 (char_u *)&p_bh, PV_BH,
682 {(char_u *)"", (char_u *)0L}
683#else
684 (char_u *)NULL, PV_NONE,
685 {(char_u *)0L, (char_u *)0L}
686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000687 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000688 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
689 (char_u *)&p_bl, PV_BL,
690 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000691 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
693#if defined(FEAT_QUICKFIX)
694 (char_u *)&p_bt, PV_BT,
695 {(char_u *)"", (char_u *)0L}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)0L, (char_u *)0L}
699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000700 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200701 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000702#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 (char_u *)&p_cmp, PV_NONE,
704 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
711#ifdef FEAT_SEARCHPATH
712 (char_u *)&p_cdpath, PV_NONE,
713 {(char_u *)",,", (char_u *)0L}
714#else
715 (char_u *)NULL, PV_NONE,
716 {(char_u *)0L, (char_u *)0L}
717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"cedit", NULL, P_STRING,
720#ifdef FEAT_CMDWIN
721 (char_u *)&p_cedit, PV_NONE,
722 {(char_u *)"", (char_u *)CTRL_F_STR}
723#else
724 (char_u *)NULL, PV_NONE,
725 {(char_u *)0L, (char_u *)0L}
726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000727 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
729#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
730 (char_u *)&p_ccv, PV_NONE,
731 {(char_u *)"", (char_u *)0L}
732#else
733 (char_u *)NULL, PV_NONE,
734 {(char_u *)0L, (char_u *)0L}
735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000736 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000737 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
738#ifdef FEAT_CINDENT
739 (char_u *)&p_cin, PV_CIN,
740#else
741 (char_u *)NULL, PV_NONE,
742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000743 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200744 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745#ifdef FEAT_CINDENT
746 (char_u *)&p_cink, PV_CINK,
747 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
748#else
749 (char_u *)NULL, PV_NONE,
750 {(char_u *)0L, (char_u *)0L}
751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000752 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200753 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754#ifdef FEAT_CINDENT
755 (char_u *)&p_cino, PV_CINO,
756#else
757 (char_u *)NULL, PV_NONE,
758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000759 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200760 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
762 (char_u *)&p_cinw, PV_CINW,
763 {(char_u *)"if,else,while,do,for,switch",
764 (char_u *)0L}
765#else
766 (char_u *)NULL, PV_NONE,
767 {(char_u *)0L, (char_u *)0L}
768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000769 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200770 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#ifdef FEAT_CLIPBOARD
772 (char_u *)&p_cb, PV_NONE,
773# ifdef FEAT_XCLIPBOARD
774 {(char_u *)"autoselect,exclude:cons\\|linux",
775 (char_u *)0L}
776# else
777 {(char_u *)"", (char_u *)0L}
778# endif
779#else
780 (char_u *)NULL, PV_NONE,
781 {(char_u *)"", (char_u *)0L}
782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000783 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
785 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
788#ifdef FEAT_CMDWIN
789 (char_u *)&p_cwh, PV_NONE,
790#else
791 (char_u *)NULL, PV_NONE,
792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000793 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200794 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200795#ifdef FEAT_SYN_HL
796 (char_u *)VAR_WIN, PV_CC,
797#else
798 (char_u *)NULL, PV_NONE,
799#endif
800 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
802 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000803 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200804 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
805 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806#ifdef FEAT_COMMENTS
807 (char_u *)&p_com, PV_COM,
808 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
809 (char_u *)0L}
810#else
811 (char_u *)NULL, PV_NONE,
812 {(char_u *)0L, (char_u *)0L}
813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200815 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816#ifdef FEAT_FOLDING
817 (char_u *)&p_cms, PV_CMS,
818 {(char_u *)"/*%s*/", (char_u *)0L}
819#else
820 (char_u *)NULL, PV_NONE,
821 {(char_u *)0L, (char_u *)0L}
822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000823 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000824 /* P_PRI_MKRC isn't needed here, optval_default()
825 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000826 {"compatible", "cp", P_BOOL|P_RALL,
827 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000828 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200829 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830#ifdef FEAT_INS_EXPAND
831 (char_u *)&p_cpt, PV_CPT,
832 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
833#else
834 (char_u *)NULL, PV_NONE,
835 {(char_u *)0L, (char_u *)0L}
836#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000837 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200838 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200839#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200840 (char_u *)VAR_WIN, PV_COCU,
841 {(char_u *)"", (char_u *)NULL}
842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)NULL, (char_u *)0L}
845#endif
846 SCRIPTID_INIT},
847 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
848#ifdef FEAT_CONCEAL
849 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200850#else
851 (char_u *)NULL, PV_NONE,
852#endif
853 {(char_u *)0L, (char_u *)0L}
854 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000855 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
856#ifdef FEAT_COMPL_FUNC
857 (char_u *)&p_cfu, PV_CFU,
858 {(char_u *)"", (char_u *)0L}
859#else
860 (char_u *)NULL, PV_NONE,
861 {(char_u *)0L, (char_u *)0L}
862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000863 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200864 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000865#ifdef FEAT_INS_EXPAND
866 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000867 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000868#else
869 (char_u *)NULL, PV_NONE,
870 {(char_u *)0L, (char_u *)0L}
871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000872 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000873 {"confirm", "cf", P_BOOL|P_VI_DEF,
874#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
875 (char_u *)&p_confirm, PV_NONE,
876#else
877 (char_u *)NULL, PV_NONE,
878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000880 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000881 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
884 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
887 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000888 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
889 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200890 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200891#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200892 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200893 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200894#else
895 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200896 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200897#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200898 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
900#ifdef FEAT_CSCOPE
901 (char_u *)&p_cspc, PV_NONE,
902#else
903 (char_u *)NULL, PV_NONE,
904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
907#ifdef FEAT_CSCOPE
908 (char_u *)&p_csprg, PV_NONE,
909 {(char_u *)"cscope", (char_u *)0L}
910#else
911 (char_u *)NULL, PV_NONE,
912 {(char_u *)0L, (char_u *)0L}
913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200915 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
917 (char_u *)&p_csqf, PV_NONE,
918 {(char_u *)"", (char_u *)0L}
919#else
920 (char_u *)NULL, PV_NONE,
921 {(char_u *)0L, (char_u *)0L}
922#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000923 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200924 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
925#ifdef FEAT_CSCOPE
926 (char_u *)&p_csre, PV_NONE,
927#else
928 (char_u *)NULL, PV_NONE,
929#endif
930 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_cst, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csto, PV_NONE,
941#else
942 (char_u *)NULL, PV_NONE,
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csverbose, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200952 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
953#ifdef FEAT_CURSORBIND
954 (char_u *)VAR_WIN, PV_CRBIND,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
958 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000959 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
960#ifdef FEAT_SYN_HL
961 (char_u *)VAR_WIN, PV_CUC,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000966 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
967#ifdef FEAT_SYN_HL
968 (char_u *)VAR_WIN, PV_CUL,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000973 {"debug", NULL, P_STRING|P_VI_DEF,
974 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200976 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000978 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000979 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980#else
981 (char_u *)NULL, PV_NONE,
982 {(char_u *)NULL, (char_u *)0L}
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
986#ifdef FEAT_MBYTE
987 (char_u *)&p_deco, PV_NONE,
988#else
989 (char_u *)NULL, PV_NONE,
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200992 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000994 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#else
996 (char_u *)NULL, PV_NONE,
997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1000#ifdef FEAT_DIFF
1001 (char_u *)VAR_WIN, PV_DIFF,
1002#else
1003 (char_u *)NULL, PV_NONE,
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001006 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1008 (char_u *)&p_dex, PV_NONE,
1009 {(char_u *)"", (char_u *)0L}
1010#else
1011 (char_u *)NULL, PV_NONE,
1012 {(char_u *)0L, (char_u *)0L}
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001015 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1016 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017#ifdef FEAT_DIFF
1018 (char_u *)&p_dip, PV_NONE,
1019 {(char_u *)"filler", (char_u *)NULL}
1020#else
1021 (char_u *)NULL, PV_NONE,
1022 {(char_u *)"", (char_u *)NULL}
1023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1026#ifdef FEAT_DIGRAPHS
1027 (char_u *)&p_dg, PV_NONE,
1028#else
1029 (char_u *)NULL, PV_NONE,
1030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001031 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001032 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1033 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001035 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001036 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001040#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041 (char_u *)&p_ead, PV_NONE,
1042 {(char_u *)"both", (char_u *)0L}
1043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)NULL, (char_u *)0L}
1046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1049 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001051 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1052#if defined(FEAT_MBYTE)
1053 (char_u *)&p_emoji, PV_NONE,
1054 {(char_u *)TRUE, (char_u *)0L}
1055#else
1056 (char_u *)NULL, PV_NONE,
1057 {(char_u *)0L, (char_u *)0L}
1058#endif
1059 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001060 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061#ifdef FEAT_MBYTE
1062 (char_u *)&p_enc, PV_NONE,
1063 {(char_u *)ENC_DFLT, (char_u *)0L}
1064#else
1065 (char_u *)NULL, PV_NONE,
1066 {(char_u *)0L, (char_u *)0L}
1067#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1070 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1073 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001076 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1079 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1082#ifdef FEAT_QUICKFIX
1083 (char_u *)&p_ef, PV_NONE,
1084 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1085#else
1086 (char_u *)NULL, PV_NONE,
1087 {(char_u *)NULL, (char_u *)0L}
1088#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001090 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001092 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094#else
1095 (char_u *)NULL, PV_NONE,
1096 {(char_u *)NULL, (char_u *)0L}
1097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001098 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"esckeys", "ek", P_BOOL|P_VIM,
1100 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001102 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103#ifdef FEAT_AUTOCMD
1104 (char_u *)&p_ei, PV_NONE,
1105#else
1106 (char_u *)NULL, PV_NONE,
1107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1110 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1113 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1116 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117#ifdef FEAT_MBYTE
1118 (char_u *)&p_fenc, PV_FENC,
1119 {(char_u *)"", (char_u *)0L}
1120#else
1121 (char_u *)NULL, PV_NONE,
1122 {(char_u *)0L, (char_u *)0L}
1123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001125 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#ifdef FEAT_MBYTE
1127 (char_u *)&p_fencs, PV_NONE,
1128 {(char_u *)"ucs-bom", (char_u *)0L}
1129#else
1130 (char_u *)NULL, PV_NONE,
1131 {(char_u *)0L, (char_u *)0L}
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1135 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001137 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001138 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1141 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001142 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1143 (char_u *)&p_fic, PV_NONE,
1144 {
1145#ifdef CASE_INSENSITIVE_FILENAME
1146 (char_u *)TRUE,
1147#else
1148 (char_u *)FALSE,
1149#endif
1150 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001151 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152#ifdef FEAT_AUTOCMD
1153 (char_u *)&p_ft, PV_FT,
1154 {(char_u *)"", (char_u *)0L}
1155#else
1156 (char_u *)NULL, PV_NONE,
1157 {(char_u *)0L, (char_u *)0L}
1158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001159 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001160 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1162 (char_u *)&p_fcs, PV_NONE,
1163 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1164#else
1165 (char_u *)NULL, PV_NONE,
1166 {(char_u *)"", (char_u *)0L}
1167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001169 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1170 (char_u *)&p_fixeol, PV_FIXEOL,
1171 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1173#ifdef FEAT_FKMAP
1174 (char_u *)&p_fkmap, PV_NONE,
1175#else
1176 (char_u *)NULL, PV_NONE,
1177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 {"flash", "fl", P_BOOL|P_VI_DEF,
1180 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001183 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1187 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1190 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1193# ifdef FEAT_EVAL
1194 (char_u *)VAR_WIN, PV_FDE,
1195 {(char_u *)"0", (char_u *)NULL}
1196# else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)NULL, (char_u *)0L}
1199# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1202 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1205 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001207 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001211 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)"{{{,}}}", (char_u *)NULL}
1214 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1216 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1219 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001224 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 (char_u *)&p_fdo, PV_NONE,
1226 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1229# ifdef FEAT_EVAL
1230 (char_u *)VAR_WIN, PV_FDT,
1231 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001232# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 (char_u *)NULL, PV_NONE,
1234 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001235# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001238 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001239#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001240 (char_u *)&p_fex, PV_FEX,
1241 {(char_u *)"", (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)0L, (char_u *)0L}
1245#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1248 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1250 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001251 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1252 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001253 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1254 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1256 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001257 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001258 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1259#ifdef HAVE_FSYNC
1260 (char_u *)&p_fs, PV_NONE,
1261 {(char_u *)TRUE, (char_u *)0L}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)FALSE, (char_u *)0L}
1265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1268 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 {"graphic", "gr", P_BOOL|P_VI_DEF,
1271 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001273 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001274#ifdef FEAT_QUICKFIX
1275 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001276 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277#else
1278 (char_u *)NULL, PV_NONE,
1279 {(char_u *)NULL, (char_u *)0L}
1280#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1283#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001284 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285 {
1286# ifdef WIN3264
1287 /* may be changed to "grep -n" in os_win32.c */
1288 (char_u *)"findstr /n",
1289# else
1290# ifdef UNIX
1291 /* Add an extra file name so that grep will always
1292 * insert a file name in the match line. */
1293 (char_u *)"grep -n $* /dev/null",
1294# else
1295# ifdef VMS
1296 (char_u *)"SEARCH/NUMBERS ",
1297# else
1298 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001299# endif
1300# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001302 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303#else
1304 (char_u *)NULL, PV_NONE,
1305 {(char_u *)NULL, (char_u *)0L}
1306#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001307 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001308 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#ifdef CURSOR_SHAPE
1310 (char_u *)&p_guicursor, PV_NONE,
1311 {
1312# ifdef FEAT_GUI
1313 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001314# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1316# endif
1317 (char_u *)0L}
1318#else
1319 (char_u *)NULL, PV_NONE,
1320 {(char_u *)NULL, (char_u *)0L}
1321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001322 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001323 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324#ifdef FEAT_GUI
1325 (char_u *)&p_guifont, PV_NONE,
1326 {(char_u *)"", (char_u *)0L}
1327#else
1328 (char_u *)NULL, PV_NONE,
1329 {(char_u *)NULL, (char_u *)0L}
1330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001332 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1334 (char_u *)&p_guifontset, PV_NONE,
1335 {(char_u *)"", (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)NULL, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001341 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1343 (char_u *)&p_guifontwide, PV_NONE,
1344 {(char_u *)"", (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)NULL, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001351#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352 (char_u *)&p_ghr, PV_NONE,
1353#else
1354 (char_u *)NULL, PV_NONE,
1355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001356 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001358#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 (char_u *)&p_go, PV_NONE,
1360# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001361 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001363 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364# endif
1365#else
1366 (char_u *)NULL, PV_NONE,
1367 {(char_u *)NULL, (char_u *)0L}
1368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001369 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370 {"guipty", NULL, P_BOOL|P_VI_DEF,
1371#if defined(FEAT_GUI)
1372 (char_u *)&p_guipty, PV_NONE,
1373#else
1374 (char_u *)NULL, PV_NONE,
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001377 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001378#if defined(FEAT_GUI_TABLINE)
1379 (char_u *)&p_gtl, PV_NONE,
1380 {(char_u *)"", (char_u *)0L}
1381#else
1382 (char_u *)NULL, PV_NONE,
1383 {(char_u *)NULL, (char_u *)0L}
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001386 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001387#if defined(FEAT_GUI_TABLINE)
1388 (char_u *)&p_gtt, PV_NONE,
1389 {(char_u *)"", (char_u *)0L}
1390#else
1391 (char_u *)NULL, PV_NONE,
1392 {(char_u *)NULL, (char_u *)0L}
1393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1396 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1399 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1401 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402 {"helpheight", "hh", P_NUM|P_VI_DEF,
1403#ifdef FEAT_WINDOWS
1404 (char_u *)&p_hh, PV_NONE,
1405#else
1406 (char_u *)NULL, PV_NONE,
1407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001409 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410#ifdef FEAT_MULTI_LANG
1411 (char_u *)&p_hlg, PV_NONE,
1412 {(char_u *)"", (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)0L, (char_u *)0L}
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 {"hidden", "hid", P_BOOL|P_VI_DEF,
1419 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001420 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001421 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001422 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1424 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 {"history", "hi", P_NUM|P_VIM,
1426 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001427 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1429#ifdef FEAT_RIGHTLEFT
1430 (char_u *)&p_hkmap, PV_NONE,
1431#else
1432 (char_u *)NULL, PV_NONE,
1433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1436#ifdef FEAT_RIGHTLEFT
1437 (char_u *)&p_hkmapp, PV_NONE,
1438#else
1439 (char_u *)NULL, PV_NONE,
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1443 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"icon", NULL, P_BOOL|P_VI_DEF,
1446#ifdef FEAT_TITLE
1447 (char_u *)&p_icon, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"iconstring", NULL, P_STRING|P_VI_DEF,
1453#ifdef FEAT_TITLE
1454 (char_u *)&p_iconstring, PV_NONE,
1455#else
1456 (char_u *)NULL, PV_NONE,
1457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1460 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001462 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1463# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1464 (char_u *)&p_imaf, PV_NONE,
1465 {(char_u *)"", (char_u *)NULL}
1466# else
1467 (char_u *)NULL, PV_NONE,
1468 {(char_u *)NULL, (char_u *)0L}
1469# endif
1470 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001472#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 (char_u *)&p_imak, PV_NONE,
1474#else
1475 (char_u *)NULL, PV_NONE,
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1479#ifdef USE_IM_CONTROL
1480 (char_u *)&p_imcmdline, PV_NONE,
1481#else
1482 (char_u *)NULL, PV_NONE,
1483#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001484 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1486#ifdef USE_IM_CONTROL
1487 (char_u *)&p_imdisable, PV_NONE,
1488#else
1489 (char_u *)NULL, PV_NONE,
1490#endif
1491#ifdef __sgi
1492 {(char_u *)TRUE, (char_u *)0L}
1493#else
1494 {(char_u *)FALSE, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"iminsert", "imi", P_NUM|P_VI_DEF,
1498 (char_u *)&p_iminsert, PV_IMI,
1499#ifdef B_IMODE_IM
1500 {(char_u *)B_IMODE_IM, (char_u *)0L}
1501#else
1502 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"imsearch", "ims", P_NUM|P_VI_DEF,
1506 (char_u *)&p_imsearch, PV_IMS,
1507#ifdef B_IMODE_IM
1508 {(char_u *)B_IMODE_IM, (char_u *)0L}
1509#else
1510 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001512 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001513 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001514# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1515 (char_u *)&p_imsf, PV_NONE,
1516 {(char_u *)"", (char_u *)NULL}
1517# else
1518 (char_u *)NULL, PV_NONE,
1519 {(char_u *)NULL, (char_u *)0L}
1520# endif
1521 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1523#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001524 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1526#else
1527 (char_u *)NULL, PV_NONE,
1528 {(char_u *)0L, (char_u *)0L}
1529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1532#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1533 (char_u *)&p_inex, PV_INEX,
1534 {(char_u *)"", (char_u *)0L}
1535#else
1536 (char_u *)NULL, PV_NONE,
1537 {(char_u *)0L, (char_u *)0L}
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1541 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1544#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1545 (char_u *)&p_inde, PV_INDE,
1546 {(char_u *)"", (char_u *)0L}
1547#else
1548 (char_u *)NULL, PV_NONE,
1549 {(char_u *)0L, (char_u *)0L}
1550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001551 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001552 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1554 (char_u *)&p_indk, PV_INDK,
1555 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1556#else
1557 (char_u *)NULL, PV_NONE,
1558 {(char_u *)0L, (char_u *)0L}
1559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001560 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"infercase", "inf", P_BOOL|P_VI_DEF,
1562 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1565 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1568 (char_u *)&p_isf, PV_NONE,
1569 {
1570#ifdef BACKSLASH_IN_FILENAME
1571 /* Excluded are: & and ^ are special in cmd.exe
1572 * ( and ) are used in text separating fnames */
1573 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1574#else
1575# ifdef AMIGA
1576 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1577# else
1578# ifdef VMS
1579 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1580# else /* UNIX et al. */
1581# ifdef EBCDIC
1582 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1583# else
1584 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1585# endif
1586# endif
1587# endif
1588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001589 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1591 (char_u *)&p_isi, PV_NONE,
1592 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001593#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 (char_u *)"@,48-57,_,128-167,224-235",
1595#else
1596# ifdef EBCDIC
1597 /* TODO: EBCDIC Check this! @ == isalpha()*/
1598 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1599 "112-120,128,140-142,156,158,172,"
1600 "174,186,191,203-207,219-225,235-239,"
1601 "251-254",
1602# else
1603 (char_u *)"@,48-57,_,192-255",
1604# endif
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1608 (char_u *)&p_isk, PV_ISK,
1609 {
1610#ifdef EBCDIC
1611 (char_u *)"@,240-249,_",
1612 /* TODO: EBCDIC Check this! @ == isalpha()*/
1613 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1614 "112-120,128,140-142,156,158,172,"
1615 "174,186,191,203-207,219-225,235-239,"
1616 "251-254",
1617#else
1618 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001619# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 (char_u *)"@,48-57,_,128-167,224-235"
1621# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001622 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623# endif
1624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1627 (char_u *)&p_isp, PV_NONE,
1628 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001629#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 || defined(VMS)
1631 (char_u *)"@,~-255",
1632#else
1633# ifdef EBCDIC
1634 /* all chars above 63 are printable */
1635 (char_u *)"63-255",
1636# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001637 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638# endif
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1642 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1645#ifdef FEAT_CRYPT
1646 (char_u *)&p_key, PV_KEY,
1647 {(char_u *)"", (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)0L, (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001653 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654#ifdef FEAT_KEYMAP
1655 (char_u *)&p_keymap, PV_KMAP,
1656 {(char_u *)"", (char_u *)0L}
1657#else
1658 (char_u *)NULL, PV_NONE,
1659 {(char_u *)"", (char_u *)0L}
1660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001662 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001666 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001668#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669 (char_u *)":help",
1670#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001671# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001673# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001674# ifdef USEMAN_S
1675 (char_u *)"man -s",
1676# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001678# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679# endif
1680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001681 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001682 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683#ifdef FEAT_LANGMAP
1684 (char_u *)&p_langmap, PV_NONE,
1685 {(char_u *)"", /* unmatched } */
1686#else
1687 (char_u *)NULL, PV_NONE,
1688 {(char_u *)NULL,
1689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001690 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001691 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1693 (char_u *)&p_lm, PV_NONE,
1694#else
1695 (char_u *)NULL, PV_NONE,
1696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001697 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001698 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1699#ifdef FEAT_LANGMAP
1700 (char_u *)&p_lnr, PV_NONE,
1701#else
1702 (char_u *)NULL, PV_NONE,
1703#endif
1704 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1706#ifdef FEAT_WINDOWS
1707 (char_u *)&p_ls, PV_NONE,
1708#else
1709 (char_u *)NULL, PV_NONE,
1710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001711 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1713 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1716#ifdef FEAT_LINEBREAK
1717 (char_u *)VAR_WIN, PV_LBR,
1718#else
1719 (char_u *)NULL, PV_NONE,
1720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1723 (char_u *)&Rows, PV_NONE,
1724 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001725#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 (char_u *)25L,
1727#else
1728 (char_u *)24L,
1729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1732#ifdef FEAT_GUI
1733 (char_u *)&p_linespace, PV_NONE,
1734#else
1735 (char_u *)NULL, PV_NONE,
1736#endif
1737#ifdef FEAT_GUI_W32
1738 {(char_u *)1L, (char_u *)0L}
1739#else
1740 {(char_u *)0L, (char_u *)0L}
1741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001742 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 {"lisp", NULL, P_BOOL|P_VI_DEF,
1744#ifdef FEAT_LISP
1745 (char_u *)&p_lisp, PV_LISP,
1746#else
1747 (char_u *)NULL, PV_NONE,
1748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001750 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001752 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1754#else
1755 (char_u *)NULL, PV_NONE,
1756 {(char_u *)"", (char_u *)0L}
1757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001758 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1760 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001761 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001762 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001764 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1766 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001768#if defined(DYNAMIC_LUA)
Bram Moolenaara6e42502016-04-20 16:19:52 +02001769 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001770 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001771 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1772 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001773#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001774#ifdef FEAT_GUI_MAC
1775 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1776 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 {"magic", NULL, P_BOOL|P_VI_DEF,
1780 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001781 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001782 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783#ifdef FEAT_QUICKFIX
1784 (char_u *)&p_mef, PV_NONE,
1785 {(char_u *)"", (char_u *)0L}
1786#else
1787 (char_u *)NULL, PV_NONE,
1788 {(char_u *)NULL, (char_u *)0L}
1789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1792#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001793 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794# ifdef VMS
1795 {(char_u *)"MMS", (char_u *)0L}
1796# else
1797 {(char_u *)"make", (char_u *)0L}
1798# endif
1799#else
1800 (char_u *)NULL, PV_NONE,
1801 {(char_u *)NULL, (char_u *)0L}
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001804 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001806 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1807 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"matchtime", "mat", P_NUM|P_VI_DEF,
1809 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001811 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001812#ifdef FEAT_MBYTE
1813 (char_u *)&p_mco, PV_NONE,
1814#else
1815 (char_u *)NULL, PV_NONE,
1816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1819#ifdef FEAT_EVAL
1820 (char_u *)&p_mfd, PV_NONE,
1821#else
1822 (char_u *)NULL, PV_NONE,
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1826 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"maxmem", "mm", P_NUM|P_VI_DEF,
1829 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1831 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001832 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1838 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"menuitems", "mis", P_NUM|P_VI_DEF,
1840#ifdef FEAT_MENU
1841 (char_u *)&p_mis, PV_NONE,
1842#else
1843 (char_u *)NULL, PV_NONE,
1844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"mesg", NULL, P_BOOL|P_VI_DEF,
1847 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001849 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001850#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001851 (char_u *)&p_msm, PV_NONE,
1852 {(char_u *)"460000,2000,500", (char_u *)0L}
1853#else
1854 (char_u *)NULL, PV_NONE,
1855 {(char_u *)0L, (char_u *)0L}
1856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001857 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {"modeline", "ml", P_BOOL|P_VIM,
1859 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"modelines", "mls", P_NUM|P_VI_DEF,
1862 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1865 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1868 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"more", NULL, P_BOOL|P_VIM,
1871 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1874 (char_u *)&p_mouse, PV_NONE,
1875 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001876#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 (char_u *)"a",
1878#else
1879 (char_u *)"",
1880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1883#ifdef FEAT_GUI
1884 (char_u *)&p_mousef, PV_NONE,
1885#else
1886 (char_u *)NULL, PV_NONE,
1887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1890#ifdef FEAT_GUI
1891 (char_u *)&p_mh, PV_NONE,
1892#else
1893 (char_u *)NULL, PV_NONE,
1894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1897 (char_u *)&p_mousem, PV_NONE,
1898 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001899#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 (char_u *)"popup",
1901#else
1902# if defined(MACOS)
1903 (char_u *)"popup_setpos",
1904# else
1905 (char_u *)"extend",
1906# endif
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001909 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910#ifdef FEAT_MOUSESHAPE
1911 (char_u *)&p_mouseshape, PV_NONE,
1912 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1913#else
1914 (char_u *)NULL, PV_NONE,
1915 {(char_u *)NULL, (char_u *)0L}
1916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1919 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001921 {"mzquantum", "mzq", P_NUM,
1922#ifdef FEAT_MZSCHEME
1923 (char_u *)&p_mzq, PV_NONE,
1924#else
1925 (char_u *)NULL, PV_NONE,
1926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"novice", NULL, P_BOOL|P_VI_DEF,
1929 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001931 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001933 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1936 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001938 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1939#ifdef FEAT_LINEBREAK
1940 (char_u *)VAR_WIN, PV_NUW,
1941#else
1942 (char_u *)NULL, PV_NONE,
1943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001945 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001946#ifdef FEAT_COMPL_FUNC
1947 (char_u *)&p_ofu, PV_OFU,
1948 {(char_u *)"", (char_u *)0L}
1949#else
1950 (char_u *)NULL, PV_NONE,
1951 {(char_u *)0L, (char_u *)0L}
1952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"open", NULL, P_BOOL|P_VI_DEF,
1955 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001957 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001958#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001959 (char_u *)&p_odev, PV_NONE,
1960#else
1961 (char_u *)NULL, PV_NONE,
1962#endif
1963 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001965 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1966 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"optimize", "opt", P_BOOL|P_VI_DEF,
1969 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001973 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001974 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1975 |P_SECURE,
1976 (char_u *)&p_pp, PV_NONE,
1977 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
1978 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"paragraphs", "para", P_STRING|P_VI_DEF,
1980 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001981 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001983 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1987 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1990#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1991 (char_u *)&p_pex, PV_NONE,
1992 {(char_u *)"", (char_u *)0L}
1993#else
1994 (char_u *)NULL, PV_NONE,
1995 {(char_u *)0L, (char_u *)0L}
1996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001998 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002002 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002004#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002005 (char_u *)".,,",
2006#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002009 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002010#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002011 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002012 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002013 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2014 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2017 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002019 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2021 (char_u *)&p_pvh, PV_NONE,
2022#else
2023 (char_u *)NULL, PV_NONE,
2024#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2027#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2028 (char_u *)VAR_WIN, PV_PVW,
2029#else
2030 (char_u *)NULL, PV_NONE,
2031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002033 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034#ifdef FEAT_PRINTER
2035 (char_u *)&p_pdev, PV_NONE,
2036 {(char_u *)"", (char_u *)0L}
2037#else
2038 (char_u *)NULL, PV_NONE,
2039 {(char_u *)NULL, (char_u *)0L}
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"printencoding", "penc", P_STRING|P_VI_DEF,
2043#ifdef FEAT_POSTSCRIPT
2044 (char_u *)&p_penc, PV_NONE,
2045 {(char_u *)"", (char_u *)0L}
2046#else
2047 (char_u *)NULL, PV_NONE,
2048 {(char_u *)NULL, (char_u *)0L}
2049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2052#ifdef FEAT_POSTSCRIPT
2053 (char_u *)&p_pexpr, PV_NONE,
2054 {(char_u *)"", (char_u *)0L}
2055#else
2056 (char_u *)NULL, PV_NONE,
2057 {(char_u *)NULL, (char_u *)0L}
2058#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002060 {"printfont", "pfn", P_STRING|P_VI_DEF,
2061#ifdef FEAT_PRINTER
2062 (char_u *)&p_pfn, PV_NONE,
2063 {
2064# ifdef MSWIN
2065 (char_u *)"Courier_New:h10",
2066# else
2067 (char_u *)"courier",
2068# endif
2069 (char_u *)0L}
2070#else
2071 (char_u *)NULL, PV_NONE,
2072 {(char_u *)NULL, (char_u *)0L}
2073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2076#ifdef FEAT_PRINTER
2077 (char_u *)&p_header, PV_NONE,
2078 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2079#else
2080 (char_u *)NULL, PV_NONE,
2081 {(char_u *)NULL, (char_u *)0L}
2082#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002084 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2085#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2086 (char_u *)&p_pmcs, PV_NONE,
2087 {(char_u *)"", (char_u *)0L}
2088#else
2089 (char_u *)NULL, PV_NONE,
2090 {(char_u *)NULL, (char_u *)0L}
2091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002092 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002093 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2094#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2095 (char_u *)&p_pmfn, PV_NONE,
2096 {(char_u *)"", (char_u *)0L}
2097#else
2098 (char_u *)NULL, PV_NONE,
2099 {(char_u *)NULL, (char_u *)0L}
2100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002101 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002102 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103#ifdef FEAT_PRINTER
2104 (char_u *)&p_popt, PV_NONE,
2105 {(char_u *)"", (char_u *)0L}
2106#else
2107 (char_u *)NULL, PV_NONE,
2108 {(char_u *)NULL, (char_u *)0L}
2109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002110 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002112 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002114 {"pumheight", "ph", P_NUM|P_VI_DEF,
2115#ifdef FEAT_INS_EXPAND
2116 (char_u *)&p_ph, PV_NONE,
2117#else
2118 (char_u *)NULL, PV_NONE,
2119#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002121#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002122 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002123 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002124 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2125 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002126#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002127#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002128 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002129 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002130 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2131 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002132#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002133 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2134#ifdef FEAT_TEXTOBJ
2135 (char_u *)&p_qe, PV_QE,
2136 {(char_u *)"\\", (char_u *)0L}
2137#else
2138 (char_u *)NULL, PV_NONE,
2139 {(char_u *)NULL, (char_u *)0L}
2140#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002141 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2143 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"redraw", NULL, P_BOOL|P_VI_DEF,
2146 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002147 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002148 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2149#ifdef FEAT_RELTIME
2150 (char_u *)&p_rdt, PV_NONE,
2151#else
2152 (char_u *)NULL, PV_NONE,
2153#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002155 {"regexpengine", "re", P_NUM|P_VI_DEF,
2156 (char_u *)&p_re, PV_NONE,
2157 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002158 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2159 (char_u *)VAR_WIN, PV_RNU,
2160 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"remap", NULL, P_BOOL|P_VI_DEF,
2162 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002163 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002164 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002165#ifdef FEAT_RENDER_OPTIONS
2166 (char_u *)&p_rop, PV_NONE,
2167 {(char_u *)"", (char_u *)0L}
2168#else
2169 (char_u *)NULL, PV_NONE,
2170 {(char_u *)NULL, (char_u *)0L}
2171#endif
2172 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 {"report", NULL, P_NUM|P_VI_DEF,
2174 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002175 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2177#ifdef WIN3264
2178 (char_u *)&p_rs, PV_NONE,
2179#else
2180 (char_u *)NULL, PV_NONE,
2181#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002182 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2184#ifdef FEAT_RIGHTLEFT
2185 (char_u *)&p_ri, PV_NONE,
2186#else
2187 (char_u *)NULL, PV_NONE,
2188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002189 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2191#ifdef FEAT_RIGHTLEFT
2192 (char_u *)VAR_WIN, PV_RL,
2193#else
2194 (char_u *)NULL, PV_NONE,
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2198#ifdef FEAT_RIGHTLEFT
2199 (char_u *)VAR_WIN, PV_RLC,
2200 {(char_u *)"search", (char_u *)NULL}
2201#else
2202 (char_u *)NULL, PV_NONE,
2203 {(char_u *)NULL, (char_u *)0L}
2204#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002205 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002206#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002207 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002208 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002209 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2210 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002211#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2213#ifdef FEAT_CMDL_INFO
2214 (char_u *)&p_ru, PV_NONE,
2215#else
2216 (char_u *)NULL, PV_NONE,
2217#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002218 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2220#ifdef FEAT_STL_OPT
2221 (char_u *)&p_ruf, PV_NONE,
2222#else
2223 (char_u *)NULL, PV_NONE,
2224#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002226 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2227 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002228 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2230 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2232 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2235#ifdef FEAT_SCROLLBIND
2236 (char_u *)VAR_WIN, PV_SCBIND,
2237#else
2238 (char_u *)NULL, PV_NONE,
2239#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002240 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2242 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2245 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002247 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002248#ifdef FEAT_SCROLLBIND
2249 (char_u *)&p_sbo, PV_NONE,
2250 {(char_u *)"ver,jump", (char_u *)0L}
2251#else
2252 (char_u *)NULL, PV_NONE,
2253 {(char_u *)0L, (char_u *)0L}
2254#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002256 {"sections", "sect", P_STRING|P_VI_DEF,
2257 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002258 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2259 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2261 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002262 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002264 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 {(char_u *)"inclusive", (char_u *)0L}
2266 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002267 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002269 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002270 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271#ifdef FEAT_SESSION
2272 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002273 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 (char_u *)0L}
2275#else
2276 (char_u *)NULL, PV_NONE,
2277 {(char_u *)0L, (char_u *)0L}
2278#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2281 (char_u *)&p_sh, PV_NONE,
2282 {
2283#ifdef VMS
2284 (char_u *)"-",
2285#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002286# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002288# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290# endif
2291#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2294 (char_u *)&p_shcf, PV_NONE,
2295 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002296#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 (char_u *)"/c",
2298#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2303#ifdef FEAT_QUICKFIX
2304 (char_u *)&p_sp, PV_NONE,
2305 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002306#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308#else
2309 (char_u *)">",
2310#endif
2311 (char_u *)0L}
2312#else
2313 (char_u *)NULL, PV_NONE,
2314 {(char_u *)0L, (char_u *)0L}
2315#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2318 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2321 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2324#ifdef BACKSLASH_IN_FILENAME
2325 (char_u *)&p_ssl, PV_NONE,
2326#else
2327 (char_u *)NULL, PV_NONE,
2328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002330 {"shelltemp", "stmp", P_BOOL,
2331 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"shelltype", "st", P_NUM|P_VI_DEF,
2334#ifdef AMIGA
2335 (char_u *)&p_st, PV_NONE,
2336#else
2337 (char_u *)NULL, PV_NONE,
2338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2341 (char_u *)&p_sxq, PV_NONE,
2342 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002343#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 (char_u *)"\"",
2345#else
2346 (char_u *)"",
2347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002349 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2350 (char_u *)&p_sxe, PV_NONE,
2351 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002352#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002353 (char_u *)"\"&|<>()@^",
2354#else
2355 (char_u *)"",
2356#endif
2357 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2359 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002360 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2362 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2365 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)"", (char_u *)"filnxtToO"}
2367 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2372#ifdef FEAT_LINEBREAK
2373 (char_u *)&p_sbr, PV_NONE,
2374#else
2375 (char_u *)NULL, PV_NONE,
2376#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"showcmd", "sc", P_BOOL|P_VIM,
2379#ifdef FEAT_CMDL_INFO
2380 (char_u *)&p_sc, PV_NONE,
2381#else
2382 (char_u *)NULL, PV_NONE,
2383#endif
2384 {(char_u *)FALSE,
2385#ifdef UNIX
2386 (char_u *)FALSE
2387#else
2388 (char_u *)TRUE
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2392 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2395 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"showmode", "smd", P_BOOL|P_VIM,
2398 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002400 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2401#ifdef FEAT_WINDOWS
2402 (char_u *)&p_stal, PV_NONE,
2403#else
2404 (char_u *)NULL, PV_NONE,
2405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2408 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2411 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2414 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2417 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2420#ifdef FEAT_SMARTINDENT
2421 (char_u *)&p_si, PV_SI,
2422#else
2423 (char_u *)NULL, PV_NONE,
2424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2427 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2430 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2433 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002435 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002436#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002437 (char_u *)VAR_WIN, PV_SPELL,
2438#else
2439 (char_u *)NULL, PV_NONE,
2440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002442 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002443#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002444 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002445 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002446#else
2447 (char_u *)NULL, PV_NONE,
2448 {(char_u *)0L, (char_u *)0L}
2449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002451 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2452 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002453#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002454 (char_u *)&p_spf, PV_SPF,
2455 {(char_u *)"", (char_u *)0L}
2456#else
2457 (char_u *)NULL, PV_NONE,
2458 {(char_u *)0L, (char_u *)0L}
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002461 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2462 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002463#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002464 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002465 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002466#else
2467 (char_u *)NULL, PV_NONE,
2468 {(char_u *)0L, (char_u *)0L}
2469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002471 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002472#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002473 (char_u *)&p_sps, PV_NONE,
2474 {(char_u *)"best", (char_u *)0L}
2475#else
2476 (char_u *)NULL, PV_NONE,
2477 {(char_u *)0L, (char_u *)0L}
2478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002479 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2481#ifdef FEAT_WINDOWS
2482 (char_u *)&p_sb, PV_NONE,
2483#else
2484 (char_u *)NULL, PV_NONE,
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002488#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 (char_u *)&p_spr, PV_NONE,
2490#else
2491 (char_u *)NULL, PV_NONE,
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2495 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2498#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002499 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500#else
2501 (char_u *)NULL, PV_NONE,
2502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002504 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 (char_u *)&p_su, PV_NONE,
2506 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002508 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002509#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 (char_u *)&p_sua, PV_SUA,
2511 {(char_u *)"", (char_u *)0L}
2512#else
2513 (char_u *)NULL, PV_NONE,
2514 {(char_u *)0L, (char_u *)0L}
2515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002516 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2518 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"swapsync", "sws", P_STRING|P_VI_DEF,
2521 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002523 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002526 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2527#ifdef FEAT_SYN_HL
2528 (char_u *)&p_smc, PV_SMC,
2529 {(char_u *)3000L, (char_u *)0L}
2530#else
2531 (char_u *)NULL, PV_NONE,
2532 {(char_u *)0L, (char_u *)0L}
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002535 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536#ifdef FEAT_SYN_HL
2537 (char_u *)&p_syn, PV_SYN,
2538 {(char_u *)"", (char_u *)0L}
2539#else
2540 (char_u *)NULL, PV_NONE,
2541 {(char_u *)0L, (char_u *)0L}
2542#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002544 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2545#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002546 (char_u *)&p_tal, PV_NONE,
2547#else
2548 (char_u *)NULL, PV_NONE,
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002551 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2552#ifdef FEAT_WINDOWS
2553 (char_u *)&p_tpm, PV_NONE,
2554#else
2555 (char_u *)NULL, PV_NONE,
2556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2559 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2562 (char_u *)&p_tbs, PV_NONE,
2563#ifdef VMS /* binary searching doesn't appear to work on VMS */
2564 {(char_u *)0L, (char_u *)0L}
2565#else
2566 {(char_u *)TRUE, (char_u *)0L}
2567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002569 {"tagcase", "tc", P_STRING|P_VIM,
2570 (char_u *)&p_tc, PV_TC,
2571 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"taglength", "tl", P_NUM|P_VI_DEF,
2573 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"tagrelative", "tr", P_BOOL|P_VIM,
2576 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002578 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002579 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {
2581#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2582 (char_u *)"./tags,./TAGS,tags,TAGS",
2583#else
2584 (char_u *)"./tags,tags",
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2588 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002590#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002591 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002592 (char_u *)&p_tcldll, PV_NONE,
2593 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2594 SCRIPTID_INIT},
2595#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2597 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2600#ifdef FEAT_ARABIC
2601 (char_u *)&p_tbidi, PV_NONE,
2602#else
2603 (char_u *)NULL, PV_NONE,
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2607#ifdef FEAT_MBYTE
2608 (char_u *)&p_tenc, PV_NONE,
2609 {(char_u *)"", (char_u *)0L}
2610#else
2611 (char_u *)NULL, PV_NONE,
2612 {(char_u *)0L, (char_u *)0L}
2613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002615 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2616#ifdef FEAT_TERMGUICOLORS
2617 (char_u *)&p_tgc, PV_NONE,
2618 {(char_u *)FALSE, (char_u *)FALSE}
2619#else
2620 (char_u*)NULL, PV_NONE,
2621 {(char_u *)FALSE, (char_u *)FALSE}
2622#endif
2623 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"terse", NULL, P_BOOL|P_VI_DEF,
2625 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 {"textauto", "ta", P_BOOL|P_VIM,
2628 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2630 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2632 (char_u *)&p_tx, PV_TX,
2633 {
2634#ifdef USE_CRNL
2635 (char_u *)TRUE,
2636#else
2637 (char_u *)FALSE,
2638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002640 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002643 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002645 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646#else
2647 (char_u *)NULL, PV_NONE,
2648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2651 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {"timeout", "to", P_BOOL|P_VI_DEF,
2654 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2657 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 {"title", NULL, P_BOOL|P_VI_DEF,
2660#ifdef FEAT_TITLE
2661 (char_u *)&p_title, PV_NONE,
2662#else
2663 (char_u *)NULL, PV_NONE,
2664#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666 {"titlelen", NULL, P_NUM|P_VI_DEF,
2667#ifdef FEAT_TITLE
2668 (char_u *)&p_titlelen, PV_NONE,
2669#else
2670 (char_u *)NULL, PV_NONE,
2671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002673 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674#ifdef FEAT_TITLE
2675 (char_u *)&p_titleold, PV_NONE,
2676 {(char_u *)N_("Thanks for flying Vim"),
2677 (char_u *)0L}
2678#else
2679 (char_u *)NULL, PV_NONE,
2680 {(char_u *)0L, (char_u *)0L}
2681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 {"titlestring", NULL, P_STRING|P_VI_DEF,
2684#ifdef FEAT_TITLE
2685 (char_u *)&p_titlestring, PV_NONE,
2686#else
2687 (char_u *)NULL, PV_NONE,
2688#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002689 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002691 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002693 {(char_u *)"icons,tooltips", (char_u *)0L}
2694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002696#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2698 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700#endif
2701 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2702 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2705 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2708 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002709 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2711 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2714#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2715 (char_u *)&p_ttym, PV_NONE,
2716#else
2717 (char_u *)NULL, PV_NONE,
2718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2721 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2724 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002725 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002726 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2727 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002728#ifdef FEAT_PERSISTENT_UNDO
2729 (char_u *)&p_udir, PV_NONE,
2730 {(char_u *)".", (char_u *)0L}
2731#else
2732 (char_u *)NULL, PV_NONE,
2733 {(char_u *)0L, (char_u *)0L}
2734#endif
2735 SCRIPTID_INIT},
2736 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2737#ifdef FEAT_PERSISTENT_UNDO
2738 (char_u *)&p_udf, PV_UDF,
2739#else
2740 (char_u *)NULL, PV_NONE,
2741#endif
2742 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002744 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002746#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 (char_u *)1000L,
2748#else
2749 (char_u *)100L,
2750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002751 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002752 {"undoreload", "ur", P_NUM|P_VI_DEF,
2753 (char_u *)&p_ur, PV_NONE,
2754 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {"updatecount", "uc", P_NUM|P_VI_DEF,
2756 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002757 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 {"updatetime", "ut", P_NUM|P_VI_DEF,
2759 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002760 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 {"verbose", "vbs", P_NUM|P_VI_DEF,
2762 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002763 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002764 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2765 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2768#ifdef FEAT_SESSION
2769 (char_u *)&p_vdir, PV_NONE,
2770 {(char_u *)DFLT_VDIR, (char_u *)0L}
2771#else
2772 (char_u *)NULL, PV_NONE,
2773 {(char_u *)0L, (char_u *)0L}
2774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002776 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777#ifdef FEAT_SESSION
2778 (char_u *)&p_vop, PV_NONE,
2779 {(char_u *)"folds,options,cursor", (char_u *)0L}
2780#else
2781 (char_u *)NULL, PV_NONE,
2782 {(char_u *)0L, (char_u *)0L}
2783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002785 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786#ifdef FEAT_VIMINFO
2787 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002788#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002789 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790#else
2791# ifdef AMIGA
2792 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002793 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002795 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796# endif
2797#endif
2798#else
2799 (char_u *)NULL, PV_NONE,
2800 {(char_u *)0L, (char_u *)0L}
2801#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002803 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2804 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805#ifdef FEAT_VIRTUALEDIT
2806 (char_u *)&p_ve, PV_NONE,
2807 {(char_u *)"", (char_u *)""}
2808#else
2809 (char_u *)NULL, PV_NONE,
2810 {(char_u *)0L, (char_u *)0L}
2811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2814 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 {"w300", NULL, P_NUM|P_VI_DEF,
2817 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 {"w1200", NULL, P_NUM|P_VI_DEF,
2820 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"w9600", NULL, P_NUM|P_VI_DEF,
2823 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 {"warn", NULL, P_BOOL|P_VI_DEF,
2826 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002827 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2829 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002830 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002831 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"wildchar", "wc", P_NUM|P_VIM,
2835 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2837 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002838 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002841 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842#ifdef FEAT_WILDIGN
2843 (char_u *)&p_wig, PV_NONE,
2844#else
2845 (char_u *)NULL, PV_NONE,
2846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002847 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002848 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2849 (char_u *)&p_wic, PV_NONE,
2850 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2852#ifdef FEAT_WILDMENU
2853 (char_u *)&p_wmnu, PV_NONE,
2854#else
2855 (char_u *)NULL, PV_NONE,
2856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002858 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002861 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2862#ifdef FEAT_CMDL_COMPL
2863 (char_u *)&p_wop, PV_NONE,
2864 {(char_u *)"", (char_u *)0L}
2865#else
2866 (char_u *)NULL, PV_NONE,
2867 {(char_u *)NULL, (char_u *)0L}
2868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2871#ifdef FEAT_WAK
2872 (char_u *)&p_wak, PV_NONE,
2873 {(char_u *)"menu", (char_u *)0L}
2874#else
2875 (char_u *)NULL, PV_NONE,
2876 {(char_u *)NULL, (char_u *)0L}
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002880 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"winheight", "wh", P_NUM|P_VI_DEF,
2883#ifdef FEAT_WINDOWS
2884 (char_u *)&p_wh, PV_NONE,
2885#else
2886 (char_u *)NULL, PV_NONE,
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002890#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 (char_u *)VAR_WIN, PV_WFH,
2892#else
2893 (char_u *)NULL, PV_NONE,
2894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002895 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002896 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002897#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002898 (char_u *)VAR_WIN, PV_WFW,
2899#else
2900 (char_u *)NULL, PV_NONE,
2901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002902 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2904#ifdef FEAT_WINDOWS
2905 (char_u *)&p_wmh, PV_NONE,
2906#else
2907 (char_u *)NULL, PV_NONE,
2908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002911#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 (char_u *)&p_wmw, PV_NONE,
2913#else
2914 (char_u *)NULL, PV_NONE,
2915#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002918#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 (char_u *)&p_wiw, PV_NONE,
2920#else
2921 (char_u *)NULL, PV_NONE,
2922#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002923 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2925 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2928 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2931 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002932 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933 {"write", NULL, P_BOOL|P_VI_DEF,
2934 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 {"writeany", "wa", P_BOOL|P_VI_DEF,
2937 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2940 (char_u *)&p_wb, PV_NONE,
2941 {
2942#ifdef FEAT_WRITEBACKUP
2943 (char_u *)TRUE,
2944#else
2945 (char_u *)FALSE,
2946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 {"writedelay", "wd", P_NUM|P_VI_DEF,
2949 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951
2952/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002953#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002955 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956
2957 p_term("t_AB", T_CAB)
2958 p_term("t_AF", T_CAF)
2959 p_term("t_AL", T_CAL)
2960 p_term("t_al", T_AL)
2961 p_term("t_bc", T_BC)
2962 p_term("t_cd", T_CD)
2963 p_term("t_ce", T_CE)
2964 p_term("t_cl", T_CL)
2965 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002966 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 p_term("t_Co", T_CCO)
2968 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002969 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002971#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 p_term("t_CV", T_CSV)
2973#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 p_term("t_da", T_DA)
2975 p_term("t_db", T_DB)
2976 p_term("t_DL", T_CDL)
2977 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002978 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 p_term("t_fs", T_FS)
2980 p_term("t_IE", T_CIE)
2981 p_term("t_IS", T_CIS)
2982 p_term("t_ke", T_KE)
2983 p_term("t_ks", T_KS)
2984 p_term("t_le", T_LE)
2985 p_term("t_mb", T_MB)
2986 p_term("t_md", T_MD)
2987 p_term("t_me", T_ME)
2988 p_term("t_mr", T_MR)
2989 p_term("t_ms", T_MS)
2990 p_term("t_nd", T_ND)
2991 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002992 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 p_term("t_RI", T_CRI)
2994 p_term("t_RV", T_CRV)
2995 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002997 p_term("t_Sf", T_CSF)
2998 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003000 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 p_term("t_te", T_TE)
3003 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003004 p_term("t_ts", T_TS)
3005 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 p_term("t_ue", T_UE)
3007 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003008 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 p_term("t_vb", T_VB)
3010 p_term("t_ve", T_VE)
3011 p_term("t_vi", T_VI)
3012 p_term("t_vs", T_VS)
3013 p_term("t_WP", T_CWP)
3014 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003015 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 p_term("t_xs", T_XS)
3017 p_term("t_ZH", T_CZH)
3018 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003019 p_term("t_8f", T_8F)
3020 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021
3022/* terminal key codes are not in here */
3023
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 /* end marker */
3025 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026};
3027
3028#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3029
3030#ifdef FEAT_MBYTE
3031static char *(p_ambw_values[]) = {"single", "double", NULL};
3032#endif
3033static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003034static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003036#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003037static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003038#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003039#ifdef FEAT_CMDL_COMPL
3040static char *(p_wop_values[]) = {"tagfile", NULL};
3041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042#ifdef FEAT_WAK
3043static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3044#endif
3045static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3047static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049#ifdef FEAT_BROWSE
3050static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3051#endif
3052#ifdef FEAT_SCROLLBIND
3053static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3054#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003055static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003056#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3058#endif
3059#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003060# ifdef FEAT_AUTOCMD
3061static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3062# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003064# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3066#endif
3067static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3068#ifdef FEAT_FOLDING
3069static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003070# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 NULL};
3074static char *(p_fcl_values[]) = {"all", NULL};
3075#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003076#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003077static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003080static void set_option_default(int, int opt_flags, int compatible);
3081static void set_options_default(int opt_flags);
3082static char_u *term_bg_default(void);
3083static void did_set_option(int opt_idx, int opt_flags, int new_value);
3084static char_u *illegal_char(char_u *, int);
3085static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003087static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088#endif
3089#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003090static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003092static char_u *option_expand(int opt_idx, char_u *val);
3093static void didset_options(void);
3094static void didset_options2(void);
3095static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003096#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003097static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003098#else
3099# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3100#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003101static void set_string_option_global(int opt_idx, char_u **varp);
3102static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3103static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3104static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003105#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003106static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003107#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003109static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003111#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003112static char_u *did_set_spell_option(int is_spellfile);
3113static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003114#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003115#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003116static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003117#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003118static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3119static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3120static void check_redraw(long_u flags);
3121static int findoption(char_u *);
3122static int find_key_option(char_u *);
3123static void showoptions(int all, int opt_flags);
3124static int optval_default(struct vimoption *, char_u *varp);
3125static void showoneopt(struct vimoption *, int opt_flags);
3126static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3127static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3128static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3129static int istermoption(struct vimoption *);
3130static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3131static char_u *get_varp(struct vimoption *);
3132static void option_value2string(struct vimoption *, int opt_flags);
3133static void check_winopt(winopt_T *wop);
3134static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003136static void langmap_init(void);
3137static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003139static void paste_option_changed(void);
3140static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003142static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003144static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3145static int check_opt_strings(char_u *val, char **values, int);
3146static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003147#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003148static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003149#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150
3151/*
3152 * Initialize the options, first part.
3153 *
3154 * Called only once from main(), just after creating the first buffer.
3155 */
3156 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003157set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158{
3159 char_u *p;
3160 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003161 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162
3163#ifdef FEAT_LANGMAP
3164 langmap_init();
3165#endif
3166
3167 /* Be Vi compatible by default */
3168 p_cp = TRUE;
3169
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003170 /* Use POSIX compatibility when $VIM_POSIX is set. */
3171 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003172 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003173 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003174 set_string_default("shm", (char_u *)"A");
3175 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003176
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 /*
3178 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003179 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003181 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003182#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003183 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003185 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186# endif
3187#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003188 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 set_string_default("sh", p);
3190
3191#ifdef FEAT_WILDIGN
3192 /*
3193 * Set the default for 'backupskip' to include environment variables for
3194 * temp files.
3195 */
3196 {
3197# ifdef UNIX
3198 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3199# else
3200 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3201# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003202 int len;
3203 garray_T ga;
3204 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205
3206 ga_init2(&ga, 1, 100);
3207 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3208 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003209 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210# ifdef UNIX
3211 if (*names[n] == NUL)
3212 p = (char_u *)"/tmp";
3213 else
3214# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003215 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 if (p != NULL && *p != NUL)
3217 {
3218 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003219 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220 if (ga_grow(&ga, len) == OK)
3221 {
3222 if (ga.ga_len > 0)
3223 STRCAT(ga.ga_data, ",");
3224 STRCAT(ga.ga_data, p);
3225 add_pathsep(ga.ga_data);
3226 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 ga.ga_len += len;
3228 }
3229 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003230 if (mustfree)
3231 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232 }
3233 if (ga.ga_data != NULL)
3234 {
3235 set_string_default("bsk", ga.ga_data);
3236 vim_free(ga.ga_data);
3237 }
3238 }
3239#endif
3240
3241 /*
3242 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3243 */
3244 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003245 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003247#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3248 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3249#endif
3250 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003252 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003253 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254#else
3255# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003256 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003257 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260# endif
3261#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003263 opt_idx = findoption((char_u *)"maxmem");
3264 if (opt_idx >= 0)
3265 {
3266#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003267 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3268 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003269#endif
3270 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3271 }
3272 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273 }
3274
3275#ifdef FEAT_GUI_W32
3276 /* force 'shortname' for Win32s */
3277 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003278 {
3279 opt_idx = findoption((char_u *)"shortname");
3280 if (opt_idx >= 0)
3281 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3282 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283#endif
3284
3285#ifdef FEAT_SEARCHPATH
3286 {
3287 char_u *cdpath;
3288 char_u *buf;
3289 int i;
3290 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003291 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292
3293 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003294 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295 if (cdpath != NULL)
3296 {
3297 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3298 if (buf != NULL)
3299 {
3300 buf[0] = ','; /* start with ",", current dir first */
3301 j = 1;
3302 for (i = 0; cdpath[i] != NUL; ++i)
3303 {
3304 if (vim_ispathlistsep(cdpath[i]))
3305 buf[j++] = ',';
3306 else
3307 {
3308 if (cdpath[i] == ' ' || cdpath[i] == ',')
3309 buf[j++] = '\\';
3310 buf[j++] = cdpath[i];
3311 }
3312 }
3313 buf[j] = NUL;
3314 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003315 if (opt_idx >= 0)
3316 {
3317 options[opt_idx].def_val[VI_DEFAULT] = buf;
3318 options[opt_idx].flags |= P_DEF_ALLOCED;
3319 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003320 else
3321 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003323 if (mustfree)
3324 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325 }
3326 }
3327#endif
3328
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003329#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330 /* Set print encoding on platforms that don't default to latin1 */
3331 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003332# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 (char_u *)"cp1252"
3334# else
3335# ifdef VMS
3336 (char_u *)"dec-mcs"
3337# else
3338# ifdef EBCDIC
3339 (char_u *)"ebcdic-uk"
3340# else
3341# ifdef MAC
3342 (char_u *)"mac-roman"
3343# else /* HPUX */
3344 (char_u *)"hp-roman8"
3345# endif
3346# endif
3347# endif
3348# endif
3349 );
3350#endif
3351
3352#ifdef FEAT_POSTSCRIPT
3353 /* 'printexpr' must be allocated to be able to evaluate it. */
3354 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003355# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003356 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357# else
3358# ifdef VMS
3359 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3360
3361# else
3362 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3363# endif
3364# endif
3365 );
3366#endif
3367
3368 /*
3369 * Set all the options (except the terminal options) to their default
3370 * value. Also set the global value for local options.
3371 */
3372 set_options_default(0);
3373
3374#ifdef FEAT_GUI
3375 if (found_reverse_arg)
3376 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3377#endif
3378
3379 curbuf->b_p_initialized = TRUE;
3380 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003381 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382 check_buf_options(curbuf);
3383 check_win_options(curwin);
3384 check_options();
3385
3386 /* Must be before option_expand(), because that one needs vim_isIDc() */
3387 didset_options();
3388
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003389#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003390 /* Use the current chartab for the generic chartab. This is not in
3391 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003392 init_spell_chartab();
3393#endif
3394
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 /*
3396 * Expand environment variables and things like "~" for the defaults.
3397 * If option_expand() returns non-NULL the variable is expanded. This can
3398 * only happen for non-indirect options.
3399 * Also set the default to the expanded value, so ":set" does not list
3400 * them.
3401 * Don't set the P_ALLOCED flag, because we don't want to free the
3402 * default.
3403 */
3404 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3405 {
3406 if ((options[opt_idx].flags & P_GETTEXT)
3407 && options[opt_idx].var != NULL)
3408 p = (char_u *)_(*(char **)options[opt_idx].var);
3409 else
3410 p = option_expand(opt_idx, NULL);
3411 if (p != NULL && (p = vim_strsave(p)) != NULL)
3412 {
3413 *(char_u **)options[opt_idx].var = p;
3414 /* VIMEXP
3415 * Defaults for all expanded options are currently the same for Vi
3416 * and Vim. When this changes, add some code here! Also need to
3417 * split P_DEF_ALLOCED in two.
3418 */
3419 if (options[opt_idx].flags & P_DEF_ALLOCED)
3420 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3421 options[opt_idx].def_val[VI_DEFAULT] = p;
3422 options[opt_idx].flags |= P_DEF_ALLOCED;
3423 }
3424 }
3425
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426 save_file_ff(curbuf); /* Buffer is unchanged */
3427
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428#if defined(FEAT_ARABIC)
3429 /* Detect use of mlterm.
3430 * Mlterm is a terminal emulator akin to xterm that has some special
3431 * abilities (bidi namely).
3432 * NOTE: mlterm's author is being asked to 'set' a variable
3433 * instead of an environment variable due to inheritance.
3434 */
3435 if (mch_getenv((char_u *)"MLTERM") != NULL)
3436 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3437#endif
3438
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003439 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440
3441#ifdef FEAT_MBYTE
3442# if defined(WIN3264) && defined(FEAT_GETTEXT)
3443 /*
3444 * If $LANG isn't set, try to get a good value for it. This makes the
3445 * right language be used automatically. Don't do this for English.
3446 */
3447 if (mch_getenv((char_u *)"LANG") == NULL)
3448 {
3449 char buf[20];
3450
3451 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3452 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3453 * only the first two. */
3454 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3455 (LPTSTR)buf, 20);
3456 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3457 {
3458 /* There are a few exceptions (probably more) */
3459 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3460 STRCPY(buf, "zh_TW");
3461 else if (STRNICMP(buf, "chs", 3) == 0
3462 || STRNICMP(buf, "zhc", 3) == 0)
3463 STRCPY(buf, "zh_CN");
3464 else if (STRNICMP(buf, "jp", 2) == 0)
3465 STRCPY(buf, "ja");
3466 else
3467 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003468 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 }
3470 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003471# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003472# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003473 /* Moved to os_mac_conv.c to avoid dependency problems. */
3474 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003475# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476# endif
3477
3478 /* enc_locale() will try to find the encoding of the current locale. */
3479 p = enc_locale();
3480 if (p != NULL)
3481 {
3482 char_u *save_enc;
3483
3484 /* Try setting 'encoding' and check if the value is valid.
3485 * If not, go back to the default "latin1". */
3486 save_enc = p_enc;
3487 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003488 if (STRCMP(p_enc, "gb18030") == 0)
3489 {
3490 /* We don't support "gb18030", but "cp936" is a good substitute
3491 * for practical purposes, thus use that. It's not an alias to
3492 * still support conversion between gb18030 and utf-8. */
3493 p_enc = vim_strsave((char_u *)"cp936");
3494 vim_free(p);
3495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496 if (mb_init() == NULL)
3497 {
3498 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003499 if (opt_idx >= 0)
3500 {
3501 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3502 options[opt_idx].flags |= P_DEF_ALLOCED;
3503 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003505#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003506 if (STRCMP(p_enc, "latin1") == 0
3507# ifdef FEAT_MBYTE
3508 || enc_utf8
3509# endif
3510 )
3511 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003512 /* Adjust the default for 'isprint' and 'iskeyword' to match
3513 * latin1. Also set the defaults for when 'nocompatible' is
3514 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003515 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003516 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003517 set_string_option_direct((char_u *)"isk", -1,
3518 ISK_LATIN1, OPT_FREE, SID_NONE);
3519 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003520 if (opt_idx >= 0)
3521 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003522 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003523 if (opt_idx >= 0)
3524 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003525 (void)init_chartab();
3526 }
3527#endif
3528
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529# if defined(WIN3264) && !defined(FEAT_GUI)
3530 /* Win32 console: When GetACP() returns a different value from
3531 * GetConsoleCP() set 'termencoding'. */
3532 if (GetACP() != GetConsoleCP())
3533 {
3534 char buf[50];
3535
3536 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3537 p_tenc = vim_strsave((char_u *)buf);
3538 if (p_tenc != NULL)
3539 {
3540 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003541 if (opt_idx >= 0)
3542 {
3543 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3544 options[opt_idx].flags |= P_DEF_ALLOCED;
3545 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003546 convert_setup(&input_conv, p_tenc, p_enc);
3547 convert_setup(&output_conv, p_enc, p_tenc);
3548 }
3549 else
3550 p_tenc = empty_option;
3551 }
3552# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003553# if defined(WIN3264) && defined(FEAT_MBYTE)
3554 /* $HOME may have characters in active code page. */
3555 init_homedir();
3556# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557 }
3558 else
3559 {
3560 vim_free(p_enc);
3561 p_enc = save_enc;
3562 }
3563 }
3564#endif
3565
3566#ifdef FEAT_MULTI_LANG
3567 /* Set the default for 'helplang'. */
3568 set_helplang_default(get_mess_lang());
3569#endif
3570}
3571
3572/*
3573 * Set an option to its default value.
3574 * This does not take care of side effects!
3575 */
3576 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003577set_option_default(
3578 int opt_idx,
3579 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3580 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003581{
3582 char_u *varp; /* pointer to variable for current option */
3583 int dvi; /* index in def_val[] */
3584 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003585 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3587
3588 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3589 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003590 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003591 {
3592 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3593 if (flags & P_STRING)
3594 {
3595 /* Use set_string_option_direct() for local options to handle
3596 * freeing and allocating the value. */
3597 if (options[opt_idx].indir != PV_NONE)
3598 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003599 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003600 else
3601 {
3602 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3603 free_string_option(*(char_u **)(varp));
3604 *(char_u **)varp = options[opt_idx].def_val[dvi];
3605 options[opt_idx].flags &= ~P_ALLOCED;
3606 }
3607 }
3608 else if (flags & P_NUM)
3609 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003610 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611 win_comp_scroll(curwin);
3612 else
3613 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003614 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615 /* May also set global value for local option. */
3616 if (both)
3617 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3618 *(long *)varp;
3619 }
3620 }
3621 else /* P_BOOL */
3622 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003623 /* the cast to long is required for Manx C, long_i is needed for
3624 * MSVC */
3625 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003626#ifdef UNIX
3627 /* 'modeline' defaults to off for root */
3628 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3629 *(int *)varp = FALSE;
3630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631 /* May also set global value for local option. */
3632 if (both)
3633 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3634 *(int *)varp;
3635 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003636
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003637 /* The default value is not insecure. */
3638 flagsp = insecure_flag(opt_idx, opt_flags);
3639 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640 }
3641
3642#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003643 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644#endif
3645}
3646
3647/*
3648 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003649 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650 */
3651 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003652set_options_default(
3653 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654{
3655 int i;
3656#ifdef FEAT_WINDOWS
3657 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003658 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003659#endif
3660
3661 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003662 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003663#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003664 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003665 || (TRUE
3666# if defined(FEAT_MBYTE)
3667 && options[i].var != (char_u *)&p_enc
3668# endif
3669# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003670 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003671 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003672# endif
3673 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003674#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003675 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676 set_option_default(i, opt_flags, p_cp);
3677
3678#ifdef FEAT_WINDOWS
3679 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003680 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681 win_comp_scroll(wp);
3682#else
3683 win_comp_scroll(curwin);
3684#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003685#ifdef FEAT_CINDENT
3686 parse_cino(curbuf);
3687#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688}
3689
3690/*
3691 * Set the Vi-default value of a string option.
3692 * Used for 'sh', 'backupskip' and 'term'.
3693 */
3694 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003695set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696{
3697 char_u *p;
3698 int opt_idx;
3699
3700 p = vim_strsave(val);
3701 if (p != NULL) /* we don't want a NULL */
3702 {
3703 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003704 if (opt_idx >= 0)
3705 {
3706 if (options[opt_idx].flags & P_DEF_ALLOCED)
3707 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3708 options[opt_idx].def_val[VI_DEFAULT] = p;
3709 options[opt_idx].flags |= P_DEF_ALLOCED;
3710 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711 }
3712}
3713
3714/*
3715 * Set the Vi-default value of a number option.
3716 * Used for 'lines' and 'columns'.
3717 */
3718 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003719set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003721 int opt_idx;
3722
3723 opt_idx = findoption((char_u *)name);
3724 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003725 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003726}
3727
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003728#if defined(EXITFREE) || defined(PROTO)
3729/*
3730 * Free all options.
3731 */
3732 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003733free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003734{
3735 int i;
3736
3737 for (i = 0; !istermoption(&options[i]); i++)
3738 {
3739 if (options[i].indir == PV_NONE)
3740 {
3741 /* global option: free value and default value. */
3742 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3743 free_string_option(*(char_u **)options[i].var);
3744 if (options[i].flags & P_DEF_ALLOCED)
3745 free_string_option(options[i].def_val[VI_DEFAULT]);
3746 }
3747 else if (options[i].var != VAR_WIN
3748 && (options[i].flags & P_STRING))
3749 /* buffer-local option: free global value */
3750 free_string_option(*(char_u **)options[i].var);
3751 }
3752}
3753#endif
3754
3755
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756/*
3757 * Initialize the options, part two: After getting Rows and Columns and
3758 * setting 'term'.
3759 */
3760 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003761set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003763 int idx;
3764
Bram Moolenaar071d4272004-06-13 20:20:40 +00003765 /*
3766 * 'scroll' defaults to half the window height. Note that this default is
3767 * wrong when the window height changes.
3768 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003769 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003770 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003771 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003772 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 comp_col();
3774
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003775 /*
3776 * 'window' is only for backwards compatibility with Vi.
3777 * Default is Rows - 1.
3778 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003779 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003780 p_window = Rows - 1;
3781 set_number_default("window", Rows - 1);
3782
Bram Moolenaarf740b292006-02-16 22:11:02 +00003783 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003784#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003785 /*
3786 * If 'background' wasn't set by the user, try guessing the value,
3787 * depending on the terminal name. Only need to check for terminals
3788 * with a dark background, that can handle color.
3789 */
3790 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003791 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3792 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003794 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003795 /* don't mark it as set, when starting the GUI it may be
3796 * changed again */
3797 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798 }
3799#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003800
3801#ifdef CURSOR_SHAPE
3802 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3803#endif
3804#ifdef FEAT_MOUSESHAPE
3805 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3806#endif
3807#ifdef FEAT_PRINTER
3808 (void)parse_printoptions(); /* parse 'printoptions' default value */
3809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810}
3811
3812/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003813 * Return "dark" or "light" depending on the kind of terminal.
3814 * This is just guessing! Recognized are:
3815 * "linux" Linux console
3816 * "screen.linux" Linux console with screen
3817 * "cygwin" Cygwin shell
3818 * "putty" Putty program
3819 * We also check the COLORFGBG environment variable, which is set by
3820 * rxvt and derivatives. This variable contains either two or three
3821 * values separated by semicolons; we want the last value in either
3822 * case. If this value is 0-6 or 8, our background is dark.
3823 */
3824 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003825term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003826{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003827#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003828 /* DOS console nearly always black */
3829 return (char_u *)"dark";
3830#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003831 char_u *p;
3832
Bram Moolenaarf740b292006-02-16 22:11:02 +00003833 if (STRCMP(T_NAME, "linux") == 0
3834 || STRCMP(T_NAME, "screen.linux") == 0
3835 || STRCMP(T_NAME, "cygwin") == 0
3836 || STRCMP(T_NAME, "putty") == 0
3837 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3838 && (p = vim_strrchr(p, ';')) != NULL
3839 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3840 && p[2] == NUL))
3841 return (char_u *)"dark";
3842 return (char_u *)"light";
3843#endif
3844}
3845
3846/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847 * Initialize the options, part three: After reading the .vimrc
3848 */
3849 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003850set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003852#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853/*
3854 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3855 * This is done after other initializations, where 'shell' might have been
3856 * set, but only if they have not been set before.
3857 */
3858 char_u *p;
3859 int idx_srr;
3860 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003861# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 int idx_sp;
3863 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003864# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865
3866 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003867 if (idx_srr < 0)
3868 do_srr = FALSE;
3869 else
3870 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003871# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003873 if (idx_sp < 0)
3874 do_sp = FALSE;
3875 else
3876 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003877# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003878 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 if (p != NULL)
3880 {
3881 /*
3882 * Default for p_sp is "| tee", for p_srr is ">".
3883 * For known shells it is changed here to include stderr.
3884 */
3885 if ( fnamecmp(p, "csh") == 0
3886 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003887# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 || fnamecmp(p, "csh.exe") == 0
3889 || fnamecmp(p, "tcsh.exe") == 0
3890# endif
3891 )
3892 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003893# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 if (do_sp)
3895 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003896# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003898# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003899 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003900# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3902 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003903# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904 if (do_srr)
3905 {
3906 p_srr = (char_u *)">&";
3907 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3908 }
3909 }
3910 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003911 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 if ( fnamecmp(p, "sh") == 0
3913 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003914 || fnamecmp(p, "mksh") == 0
3915 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003917 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003919 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003920# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003921 || fnamecmp(p, "cmd") == 0
3922 || fnamecmp(p, "sh.exe") == 0
3923 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003924 || fnamecmp(p, "mksh.exe") == 0
3925 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003927 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 || fnamecmp(p, "bash.exe") == 0
3929 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003931 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003933# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 if (do_sp)
3935 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003936# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003938# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003940# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3942 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003943# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 if (do_srr)
3945 {
3946 p_srr = (char_u *)">%s 2>&1";
3947 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3948 }
3949 }
3950 vim_free(p);
3951 }
3952#endif
3953
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003954#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003956 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3957 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 * This is done after other initializations, where 'shell' might have been
3959 * set, but only if they have not been set before. Default for p_shcf is
3960 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003961 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003963 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 {
3965 int idx3;
3966
3967 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003968 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969 {
3970 p_shcf = (char_u *)"-c";
3971 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3972 }
3973
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003974# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 /* Somehow Win32 requires the quotes around the redirection too */
3976 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003977 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 {
3979 p_sxq = (char_u *)"\"";
3980 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3981 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003982# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003984 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985 {
3986 p_shq = (char_u *)"\"";
3987 options[idx3].def_val[VI_DEFAULT] = p_shq;
3988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989# endif
3990 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003991 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3992 {
3993 int idx3;
3994
3995 /*
3996 * cmd.exe on Windows will strip the first and last double quote given
3997 * on the command line, e.g. most of the time things like:
3998 * cmd /c "my path/to/echo" "my args to echo"
3999 * become:
4000 * my path/to/echo" "my args to echo
4001 * when executed.
4002 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004003 * To avoid this, set shellxquote to surround the command in
4004 * parenthesis. This appears to make most commands work, without
4005 * breaking commands that worked previously, such as
4006 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004007 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004008 idx3 = findoption((char_u *)"sxq");
4009 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4010 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004011 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004012 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4013 }
4014
Bram Moolenaara64ba222012-02-12 23:23:31 +01004015 idx3 = findoption((char_u *)"shcf");
4016 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4017 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004018 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004019 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4020 }
4021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022#endif
4023
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004024 if (bufempty())
4025 {
4026 int idx_ffs = findoption((char_u *)"ffs");
4027
4028 /* Apply the first entry of 'fileformats' to the initial buffer. */
4029 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4030 set_fileformat(default_fileformat(), OPT_LOCAL);
4031 }
4032
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033#ifdef FEAT_TITLE
4034 set_title_defaults();
4035#endif
4036}
4037
4038#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4039/*
4040 * When 'helplang' is still at its default value, set it to "lang".
4041 * Only the first two characters of "lang" are used.
4042 */
4043 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004044set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045{
4046 int idx;
4047
4048 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4049 return;
4050 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004051 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 {
4053 if (options[idx].flags & P_ALLOCED)
4054 free_string_option(p_hlg);
4055 p_hlg = vim_strsave(lang);
4056 if (p_hlg == NULL)
4057 p_hlg = empty_option;
4058 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004059 {
4060 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4061 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4062 {
4063 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4064 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4065 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004067 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 options[idx].flags |= P_ALLOCED;
4069 }
4070}
4071#endif
4072
4073#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004074static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075
4076 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004077gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078{
4079 if (gui_get_lightness(gui.back_pixel) < 127)
4080 return (char_u *)"dark";
4081 return (char_u *)"light";
4082}
4083
4084/*
4085 * Option initializations that can only be done after opening the GUI window.
4086 */
4087 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004088init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089{
4090 /* Set the 'background' option according to the lightness of the
4091 * background color, unless the user has set it already. */
4092 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4093 {
4094 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4095 highlight_changed();
4096 }
4097}
4098#endif
4099
4100#ifdef FEAT_TITLE
4101/*
4102 * 'title' and 'icon' only default to true if they have not been set or reset
4103 * in .vimrc and we can read the old value.
4104 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4105 * they can be reset. This reduces startup time when using X on a remote
4106 * machine.
4107 */
4108 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004109set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110{
4111 int idx1;
4112 long val;
4113
4114 /*
4115 * If GUI is (going to be) used, we can always set the window title and
4116 * icon name. Saves a bit of time, because the X11 display server does
4117 * not need to be contacted.
4118 */
4119 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004120 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 {
4122#ifdef FEAT_GUI
4123 if (gui.starting || gui.in_use)
4124 val = TRUE;
4125 else
4126#endif
4127 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004128 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 p_title = val;
4130 }
4131 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004132 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 {
4134#ifdef FEAT_GUI
4135 if (gui.starting || gui.in_use)
4136 val = TRUE;
4137 else
4138#endif
4139 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004140 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 p_icon = val;
4142 }
4143}
4144#endif
4145
4146/*
4147 * Parse 'arg' for option settings.
4148 *
4149 * 'arg' may be IObuff, but only when no errors can be present and option
4150 * does not need to be expanded with option_expand().
4151 * "opt_flags":
4152 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004153 * OPT_GLOBAL for ":setglobal"
4154 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004156 * OPT_WINONLY to only set window-local options
4157 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158 *
4159 * returns FAIL if an error is detected, OK otherwise
4160 */
4161 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004162do_set(
4163 char_u *arg, /* option string (may be written to!) */
4164 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165{
4166 int opt_idx;
4167 char_u *errmsg;
4168 char_u errbuf[80];
4169 char_u *startarg;
4170 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4171 int nextchar; /* next non-white char after option name */
4172 int afterchar; /* character just after option name */
4173 int len;
4174 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004175 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176 int key;
4177 long_u flags; /* flags for current option */
4178 char_u *varp = NULL; /* pointer to variable for current option */
4179 int did_show = FALSE; /* already showed one value */
4180 int adding; /* "opt+=arg" */
4181 int prepending; /* "opt^=arg" */
4182 int removing; /* "opt-=arg" */
4183 int cp_val = 0;
4184 char_u key_name[2];
4185
4186 if (*arg == NUL)
4187 {
4188 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004189 did_show = TRUE;
4190 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 }
4192
4193 while (*arg != NUL) /* loop to process all options */
4194 {
4195 errmsg = NULL;
4196 startarg = arg; /* remember for error message */
4197
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004198 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4199 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004200 {
4201 /*
4202 * ":set all" show all options.
4203 * ":set all&" set all options to their default value.
4204 */
4205 arg += 3;
4206 if (*arg == '&')
4207 {
4208 ++arg;
4209 /* Only for :set command set global value of local options. */
4210 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004211 didset_options();
4212 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004213 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004214 }
4215 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004216 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004217 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004218 did_show = TRUE;
4219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004220 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004221 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 {
4223 showoptions(2, opt_flags);
4224 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004225 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226 arg += 7;
4227 }
4228 else
4229 {
4230 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004231 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232 {
4233 prefix = 0;
4234 arg += 2;
4235 }
4236 else if (STRNCMP(arg, "inv", 3) == 0)
4237 {
4238 prefix = 2;
4239 arg += 3;
4240 }
4241
4242 /* find end of name */
4243 key = 0;
4244 if (*arg == '<')
4245 {
4246 nextchar = 0;
4247 opt_idx = -1;
4248 /* look out for <t_>;> */
4249 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4250 len = 5;
4251 else
4252 {
4253 len = 1;
4254 while (arg[len] != NUL && arg[len] != '>')
4255 ++len;
4256 }
4257 if (arg[len] != '>')
4258 {
4259 errmsg = e_invarg;
4260 goto skip;
4261 }
4262 arg[len] = NUL; /* put NUL after name */
4263 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4264 opt_idx = findoption(arg + 1);
4265 arg[len++] = '>'; /* restore '>' */
4266 if (opt_idx == -1)
4267 key = find_key_option(arg + 1);
4268 }
4269 else
4270 {
4271 len = 0;
4272 /*
4273 * The two characters after "t_" may not be alphanumeric.
4274 */
4275 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4276 len = 4;
4277 else
4278 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4279 ++len;
4280 nextchar = arg[len];
4281 arg[len] = NUL; /* put NUL after name */
4282 opt_idx = findoption(arg);
4283 arg[len] = nextchar; /* restore nextchar */
4284 if (opt_idx == -1)
4285 key = find_key_option(arg);
4286 }
4287
4288 /* remember character after option name */
4289 afterchar = arg[len];
4290
4291 /* skip white space, allow ":set ai ?" */
4292 while (vim_iswhite(arg[len]))
4293 ++len;
4294
4295 adding = FALSE;
4296 prepending = FALSE;
4297 removing = FALSE;
4298 if (arg[len] != NUL && arg[len + 1] == '=')
4299 {
4300 if (arg[len] == '+')
4301 {
4302 adding = TRUE; /* "+=" */
4303 ++len;
4304 }
4305 else if (arg[len] == '^')
4306 {
4307 prepending = TRUE; /* "^=" */
4308 ++len;
4309 }
4310 else if (arg[len] == '-')
4311 {
4312 removing = TRUE; /* "-=" */
4313 ++len;
4314 }
4315 }
4316 nextchar = arg[len];
4317
4318 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4319 {
4320 errmsg = (char_u *)N_("E518: Unknown option");
4321 goto skip;
4322 }
4323
4324 if (opt_idx >= 0)
4325 {
4326 if (options[opt_idx].var == NULL) /* hidden option: skip */
4327 {
4328 /* Only give an error message when requesting the value of
4329 * a hidden option, ignore setting it. */
4330 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4331 && (!(options[opt_idx].flags & P_BOOL)
4332 || nextchar == '?'))
4333 errmsg = (char_u *)N_("E519: Option not supported");
4334 goto skip;
4335 }
4336
4337 flags = options[opt_idx].flags;
4338 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4339 }
4340 else
4341 {
4342 flags = P_STRING;
4343 if (key < 0)
4344 {
4345 key_name[0] = KEY2TERMCAP0(key);
4346 key_name[1] = KEY2TERMCAP1(key);
4347 }
4348 else
4349 {
4350 key_name[0] = KS_KEY;
4351 key_name[1] = (key & 0xff);
4352 }
4353 }
4354
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004355 /* Skip all options that are not window-local (used when showing
4356 * an already loaded buffer in a window). */
4357 if ((opt_flags & OPT_WINONLY)
4358 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4359 goto skip;
4360
Bram Moolenaara3227e22006-03-08 21:32:40 +00004361 /* Skip all options that are window-local (used for :vimgrep). */
4362 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4363 && options[opt_idx].var == VAR_WIN)
4364 goto skip;
4365
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004366 /* Disallow changing some options from modelines. */
4367 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004368 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004369 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004370 {
4371 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4372 goto skip;
4373 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004374#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004375 /* In diff mode some options are overruled. This avoids that
4376 * 'foldmethod' becomes "marker" instead of "diff" and that
4377 * "wrap" gets set. */
4378 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004379 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004380 && (options[opt_idx].indir == PV_FDM
4381 || options[opt_idx].indir == PV_WRAP))
4382 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384 }
4385
4386#ifdef HAVE_SANDBOX
4387 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004388 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004389 {
4390 errmsg = (char_u *)_(e_sandbox);
4391 goto skip;
4392 }
4393#endif
4394
4395 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4396 {
4397 arg += len;
4398 cp_val = p_cp;
4399 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4400 {
4401 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4402 {
4403 cp_val = FALSE;
4404 arg += 3;
4405 }
4406 else /* "opt&vi": set to Vi default */
4407 {
4408 cp_val = TRUE;
4409 arg += 2;
4410 }
4411 }
4412 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4413 && arg[1] != NUL && !vim_iswhite(arg[1]))
4414 {
4415 errmsg = e_trailing;
4416 goto skip;
4417 }
4418 }
4419
4420 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004421 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4422 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004423 */
4424 if (nextchar == '?'
4425 || (prefix == 1
4426 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4427 && !(flags & P_BOOL)))
4428 {
4429 /*
4430 * print value
4431 */
4432 if (did_show)
4433 msg_putchar('\n'); /* cursor below last one */
4434 else
4435 {
4436 gotocmdline(TRUE); /* cursor at status line */
4437 did_show = TRUE; /* remember that we did a line */
4438 }
4439 if (opt_idx >= 0)
4440 {
4441 showoneopt(&options[opt_idx], opt_flags);
4442#ifdef FEAT_EVAL
4443 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004444 {
4445 /* Mention where the option was last set. */
4446 if (varp == options[opt_idx].var)
4447 last_set_msg(options[opt_idx].scriptID);
4448 else if ((int)options[opt_idx].indir & PV_WIN)
4449 last_set_msg(curwin->w_p_scriptID[
4450 (int)options[opt_idx].indir & PV_MASK]);
4451 else if ((int)options[opt_idx].indir & PV_BUF)
4452 last_set_msg(curbuf->b_p_scriptID[
4453 (int)options[opt_idx].indir & PV_MASK]);
4454 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004455#endif
4456 }
4457 else
4458 {
4459 char_u *p;
4460
4461 p = find_termcode(key_name);
4462 if (p == NULL)
4463 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004464 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004465 goto skip;
4466 }
4467 else
4468 (void)show_one_termcode(key_name, p, TRUE);
4469 }
4470 if (nextchar != '?'
4471 && nextchar != NUL && !vim_iswhite(afterchar))
4472 errmsg = e_trailing;
4473 }
4474 else
4475 {
4476 if (flags & P_BOOL) /* boolean */
4477 {
4478 if (nextchar == '=' || nextchar == ':')
4479 {
4480 errmsg = e_invarg;
4481 goto skip;
4482 }
4483
4484 /*
4485 * ":set opt!": invert
4486 * ":set opt&": reset to default value
4487 * ":set opt<": reset to global value
4488 */
4489 if (nextchar == '!')
4490 value = *(int *)(varp) ^ 1;
4491 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004492 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004493 ((flags & P_VI_DEF) || cp_val)
4494 ? VI_DEFAULT : VIM_DEFAULT];
4495 else if (nextchar == '<')
4496 {
4497 /* For 'autoread' -1 means to use global value. */
4498 if ((int *)varp == &curbuf->b_p_ar
4499 && opt_flags == OPT_LOCAL)
4500 value = -1;
4501 else
4502 value = *(int *)get_varp_scope(&(options[opt_idx]),
4503 OPT_GLOBAL);
4504 }
4505 else
4506 {
4507 /*
4508 * ":set invopt": invert
4509 * ":set opt" or ":set noopt": set or reset
4510 */
4511 if (nextchar != NUL && !vim_iswhite(afterchar))
4512 {
4513 errmsg = e_trailing;
4514 goto skip;
4515 }
4516 if (prefix == 2) /* inv */
4517 value = *(int *)(varp) ^ 1;
4518 else
4519 value = prefix;
4520 }
4521
4522 errmsg = set_bool_option(opt_idx, varp, (int)value,
4523 opt_flags);
4524 }
4525 else /* numeric or string */
4526 {
4527 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4528 || prefix != 1)
4529 {
4530 errmsg = e_invarg;
4531 goto skip;
4532 }
4533
4534 if (flags & P_NUM) /* numeric */
4535 {
4536 /*
4537 * Different ways to set a number option:
4538 * & set to default value
4539 * < set to global value
4540 * <xx> accept special key codes for 'wildchar'
4541 * c accept any non-digit for 'wildchar'
4542 * [-]0-9 set number
4543 * other error
4544 */
4545 ++arg;
4546 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004547 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004548 ((flags & P_VI_DEF) || cp_val)
4549 ? VI_DEFAULT : VIM_DEFAULT];
4550 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004551 {
4552 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4553 * use the global value. */
4554 if ((long *)varp == &curbuf->b_p_ul
4555 && opt_flags == OPT_LOCAL)
4556 value = NO_LOCAL_UNDOLEVEL;
4557 else
4558 value = *(long *)get_varp_scope(
4559 &(options[opt_idx]), OPT_GLOBAL);
4560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004561 else if (((long *)varp == &p_wc
4562 || (long *)varp == &p_wcm)
4563 && (*arg == '<'
4564 || *arg == '^'
4565 || ((!arg[1] || vim_iswhite(arg[1]))
4566 && !VIM_ISDIGIT(*arg))))
4567 {
4568 value = string_to_key(arg);
4569 if (value == 0 && (long *)varp != &p_wcm)
4570 {
4571 errmsg = e_invarg;
4572 goto skip;
4573 }
4574 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004575 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4576 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004577 /* Allow negative (for 'undolevels'), octal and
4578 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004579 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4580 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4582 {
4583 errmsg = e_invarg;
4584 goto skip;
4585 }
4586 }
4587 else
4588 {
4589 errmsg = (char_u *)N_("E521: Number required after =");
4590 goto skip;
4591 }
4592
4593 if (adding)
4594 value = *(long *)varp + value;
4595 if (prepending)
4596 value = *(long *)varp * value;
4597 if (removing)
4598 value = *(long *)varp - value;
4599 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004600 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004601 }
4602 else if (opt_idx >= 0) /* string */
4603 {
4604 char_u *save_arg = NULL;
4605 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004606 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004607 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004608 char_u *origval = NULL;
4609#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4610 char_u *saved_origval = NULL;
4611#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004612 unsigned newlen;
4613 int comma;
4614 int bs;
4615 int new_value_alloced; /* new string option
4616 was allocated */
4617
4618 /* When using ":set opt=val" for a global option
4619 * with a local value the local value will be
4620 * reset, use the global value here. */
4621 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004622 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623 varp = options[opt_idx].var;
4624
4625 /* The old value is kept until we are sure that the
4626 * new value is valid. */
4627 oldval = *(char_u **)varp;
4628 if (nextchar == '&') /* set to default val */
4629 {
4630 newval = options[opt_idx].def_val[
4631 ((flags & P_VI_DEF) || cp_val)
4632 ? VI_DEFAULT : VIM_DEFAULT];
4633 if ((char_u **)varp == &p_bg)
4634 {
4635 /* guess the value of 'background' */
4636#ifdef FEAT_GUI
4637 if (gui.in_use)
4638 newval = gui_bg_default();
4639 else
4640#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004641 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004642 }
4643
4644 /* expand environment variables and ~ (since the
4645 * default value was already expanded, only
4646 * required when an environment variable was set
4647 * later */
4648 if (newval == NULL)
4649 newval = empty_option;
4650 else
4651 {
4652 s = option_expand(opt_idx, newval);
4653 if (s == NULL)
4654 s = newval;
4655 newval = vim_strsave(s);
4656 }
4657 new_value_alloced = TRUE;
4658 }
4659 else if (nextchar == '<') /* set to global val */
4660 {
4661 newval = vim_strsave(*(char_u **)get_varp_scope(
4662 &(options[opt_idx]), OPT_GLOBAL));
4663 new_value_alloced = TRUE;
4664 }
4665 else
4666 {
4667 ++arg; /* jump to after the '=' or ':' */
4668
4669 /*
4670 * Set 'keywordprg' to ":help" if an empty
4671 * value was passed to :set by the user.
4672 * Misuse errbuf[] for the resulting string.
4673 */
4674 if (varp == (char_u *)&p_kp
4675 && (*arg == NUL || *arg == ' '))
4676 {
4677 STRCPY(errbuf, ":help");
4678 save_arg = arg;
4679 arg = errbuf;
4680 }
4681 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004682 * Convert 'backspace' number to string, for
4683 * adding, prepending and removing string.
4684 */
4685 else if (varp == (char_u *)&p_bs
4686 && VIM_ISDIGIT(**(char_u **)varp))
4687 {
4688 i = getdigits((char_u **)varp);
4689 switch (i)
4690 {
4691 case 0:
4692 *(char_u **)varp = empty_option;
4693 break;
4694 case 1:
4695 *(char_u **)varp = vim_strsave(
4696 (char_u *)"indent,eol");
4697 break;
4698 case 2:
4699 *(char_u **)varp = vim_strsave(
4700 (char_u *)"indent,eol,start");
4701 break;
4702 }
4703 vim_free(oldval);
4704 oldval = *(char_u **)varp;
4705 }
4706 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004707 * Convert 'whichwrap' number to string, for
4708 * backwards compatibility with Vim 3.0.
4709 * Misuse errbuf[] for the resulting string.
4710 */
4711 else if (varp == (char_u *)&p_ww
4712 && VIM_ISDIGIT(*arg))
4713 {
4714 *errbuf = NUL;
4715 i = getdigits(&arg);
4716 if (i & 1)
4717 STRCAT(errbuf, "b,");
4718 if (i & 2)
4719 STRCAT(errbuf, "s,");
4720 if (i & 4)
4721 STRCAT(errbuf, "h,l,");
4722 if (i & 8)
4723 STRCAT(errbuf, "<,>,");
4724 if (i & 16)
4725 STRCAT(errbuf, "[,],");
4726 if (*errbuf != NUL) /* remove trailing , */
4727 errbuf[STRLEN(errbuf) - 1] = NUL;
4728 save_arg = arg;
4729 arg = errbuf;
4730 }
4731 /*
4732 * Remove '>' before 'dir' and 'bdir', for
4733 * backwards compatibility with version 3.0
4734 */
4735 else if ( *arg == '>'
4736 && (varp == (char_u *)&p_dir
4737 || varp == (char_u *)&p_bdir))
4738 {
4739 ++arg;
4740 }
4741
4742 /* When setting the local value of a global
4743 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004744 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004745 && (opt_flags & OPT_LOCAL))
4746 origval = *(char_u **)get_varp(
4747 &options[opt_idx]);
4748 else
4749 origval = oldval;
4750
4751 /*
4752 * Copy the new string into allocated memory.
4753 * Can't use set_string_option_direct(), because
4754 * we need to remove the backslashes.
4755 */
4756 /* get a bit too much */
4757 newlen = (unsigned)STRLEN(arg) + 1;
4758 if (adding || prepending || removing)
4759 newlen += (unsigned)STRLEN(origval) + 1;
4760 newval = alloc(newlen);
4761 if (newval == NULL) /* out of mem, don't change */
4762 break;
4763 s = newval;
4764
4765 /*
4766 * Copy the string, skip over escaped chars.
4767 * For MS-DOS and WIN32 backslashes before normal
4768 * file name characters are not removed, and keep
4769 * backslash at start, for "\\machine\path", but
4770 * do remove it for "\\\\machine\\path".
4771 * The reverse is found in ExpandOldSetting().
4772 */
4773 while (*arg && !vim_iswhite(*arg))
4774 {
4775 if (*arg == '\\' && arg[1] != NUL
4776#ifdef BACKSLASH_IN_FILENAME
4777 && !((flags & P_EXPAND)
4778 && vim_isfilec(arg[1])
4779 && (arg[1] != '\\'
4780 || (s == newval
4781 && arg[2] != '\\')))
4782#endif
4783 )
4784 ++arg; /* remove backslash */
4785#ifdef FEAT_MBYTE
4786 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004787 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004788 {
4789 /* copy multibyte char */
4790 mch_memmove(s, arg, (size_t)i);
4791 arg += i;
4792 s += i;
4793 }
4794 else
4795#endif
4796 *s++ = *arg++;
4797 }
4798 *s = NUL;
4799
4800 /*
4801 * Expand environment variables and ~.
4802 * Don't do it when adding without inserting a
4803 * comma.
4804 */
4805 if (!(adding || prepending || removing)
4806 || (flags & P_COMMA))
4807 {
4808 s = option_expand(opt_idx, newval);
4809 if (s != NULL)
4810 {
4811 vim_free(newval);
4812 newlen = (unsigned)STRLEN(s) + 1;
4813 if (adding || prepending || removing)
4814 newlen += (unsigned)STRLEN(origval) + 1;
4815 newval = alloc(newlen);
4816 if (newval == NULL)
4817 break;
4818 STRCPY(newval, s);
4819 }
4820 }
4821
4822 /* locate newval[] in origval[] when removing it
4823 * and when adding to avoid duplicates */
4824 i = 0; /* init for GCC */
4825 if (removing || (flags & P_NODUP))
4826 {
4827 i = (int)STRLEN(newval);
4828 bs = 0;
4829 for (s = origval; *s; ++s)
4830 {
4831 if ((!(flags & P_COMMA)
4832 || s == origval
4833 || (s[-1] == ',' && !(bs & 1)))
4834 && STRNCMP(s, newval, i) == 0
4835 && (!(flags & P_COMMA)
4836 || s[i] == ','
4837 || s[i] == NUL))
4838 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004839 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004840 * even number of backslashes or a single
4841 * backslash preceded by a comma before it
4842 * is recognized as a separator */
4843 if ((s > origval + 1
4844 && s[-1] == '\\'
4845 && s[-2] != ',')
4846 || (s == origval + 1
4847 && s[-1] == '\\'))
4848
Bram Moolenaar071d4272004-06-13 20:20:40 +00004849 ++bs;
4850 else
4851 bs = 0;
4852 }
4853
4854 /* do not add if already there */
4855 if ((adding || prepending) && *s)
4856 {
4857 prepending = FALSE;
4858 adding = FALSE;
4859 STRCPY(newval, origval);
4860 }
4861 }
4862
4863 /* concatenate the two strings; add a ',' if
4864 * needed */
4865 if (adding || prepending)
4866 {
4867 comma = ((flags & P_COMMA) && *origval != NUL
4868 && *newval != NUL);
4869 if (adding)
4870 {
4871 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004872 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004873 if (comma && i > 1
4874 && (flags & P_ONECOMMA) == P_ONECOMMA
4875 && origval[i - 1] == ','
4876 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004877 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004878 mch_memmove(newval + i + comma, newval,
4879 STRLEN(newval) + 1);
4880 mch_memmove(newval, origval, (size_t)i);
4881 }
4882 else
4883 {
4884 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004885 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004886 }
4887 if (comma)
4888 newval[i] = ',';
4889 }
4890
4891 /* Remove newval[] from origval[]. (Note: "i" has
4892 * been set above and is used here). */
4893 if (removing)
4894 {
4895 STRCPY(newval, origval);
4896 if (*s)
4897 {
4898 /* may need to remove a comma */
4899 if (flags & P_COMMA)
4900 {
4901 if (s == origval)
4902 {
4903 /* include comma after string */
4904 if (s[i] == ',')
4905 ++i;
4906 }
4907 else
4908 {
4909 /* include comma before string */
4910 --s;
4911 ++i;
4912 }
4913 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004914 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004915 }
4916 }
4917
4918 if (flags & P_FLAGLIST)
4919 {
4920 /* Remove flags that appear twice. */
4921 for (s = newval; *s; ++s)
4922 if ((!(flags & P_COMMA) || *s != ',')
4923 && vim_strchr(s + 1, *s) != NULL)
4924 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004925 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004926 --s;
4927 }
4928 }
4929
4930 if (save_arg != NULL) /* number for 'whichwrap' */
4931 arg = save_arg;
4932 new_value_alloced = TRUE;
4933 }
4934
4935 /* Set the new value. */
4936 *(char_u **)(varp) = newval;
4937
Bram Moolenaar53744302015-07-17 17:38:22 +02004938#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004939 if (!starting
4940# ifdef FEAT_CRYPT
4941 && options[opt_idx].indir != PV_KEY
4942# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004943 && origval != NULL)
4944 /* origval may be freed by
4945 * did_set_string_option(), make a copy. */
4946 saved_origval = vim_strsave(origval);
4947#endif
4948
Bram Moolenaar071d4272004-06-13 20:20:40 +00004949 /* Handle side effects, and set the global value for
4950 * ":set" on local options. */
4951 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4952 new_value_alloced, oldval, errbuf, opt_flags);
4953
4954 /* If error detected, print the error message. */
4955 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004956 {
4957#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4958 vim_free(saved_origval);
4959#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004960 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004961 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004962#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4963 if (saved_origval != NULL)
4964 {
4965 char_u buf_type[7];
4966
4967 sprintf((char *)buf_type, "%s",
4968 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004969 set_vim_var_string(VV_OPTION_NEW,
4970 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004971 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4972 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4973 apply_autocmds(EVENT_OPTIONSET,
4974 (char_u *)options[opt_idx].fullname,
4975 NULL, FALSE, NULL);
4976 reset_v_option_vars();
4977 vim_free(saved_origval);
4978 }
4979#endif
4980
Bram Moolenaar071d4272004-06-13 20:20:40 +00004981 }
4982 else /* key code option */
4983 {
4984 char_u *p;
4985
4986 if (nextchar == '&')
4987 {
4988 if (add_termcap_entry(key_name, TRUE) == FAIL)
4989 errmsg = (char_u *)N_("E522: Not found in termcap");
4990 }
4991 else
4992 {
4993 ++arg; /* jump to after the '=' or ':' */
4994 for (p = arg; *p && !vim_iswhite(*p); ++p)
4995 if (*p == '\\' && p[1] != NUL)
4996 ++p;
4997 nextchar = *p;
4998 *p = NUL;
4999 add_termcode(key_name, arg, FALSE);
5000 *p = nextchar;
5001 }
5002 if (full_screen)
5003 ttest(FALSE);
5004 redraw_all_later(CLEAR);
5005 }
5006 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005007
Bram Moolenaar071d4272004-06-13 20:20:40 +00005008 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005009 did_set_option(opt_idx, opt_flags,
5010 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005011 }
5012
5013skip:
5014 /*
5015 * Advance to next argument.
5016 * - skip until a blank found, taking care of backslashes
5017 * - skip blanks
5018 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5019 */
5020 for (i = 0; i < 2 ; ++i)
5021 {
5022 while (*arg != NUL && !vim_iswhite(*arg))
5023 if (*arg++ == '\\' && *arg != NUL)
5024 ++arg;
5025 arg = skipwhite(arg);
5026 if (*arg != '=')
5027 break;
5028 }
5029 }
5030
5031 if (errmsg != NULL)
5032 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005033 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005034 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005035 if (i + (arg - startarg) < IOSIZE)
5036 {
5037 /* append the argument with the error */
5038 STRCAT(IObuff, ": ");
5039 mch_memmove(IObuff + i, startarg, (arg - startarg));
5040 IObuff[i + (arg - startarg)] = NUL;
5041 }
5042 /* make sure all characters are printable */
5043 trans_characters(IObuff, IOSIZE);
5044
5045 ++no_wait_return; /* wait_return done later */
5046 emsg(IObuff); /* show error highlighted */
5047 --no_wait_return;
5048
5049 return FAIL;
5050 }
5051
5052 arg = skipwhite(arg);
5053 }
5054
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005055theend:
5056 if (silent_mode && did_show)
5057 {
5058 /* After displaying option values in silent mode. */
5059 silent_mode = FALSE;
5060 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5061 msg_putchar('\n');
5062 cursor_on(); /* msg_start() switches it off */
5063 out_flush();
5064 silent_mode = TRUE;
5065 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5066 }
5067
Bram Moolenaar071d4272004-06-13 20:20:40 +00005068 return OK;
5069}
5070
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005071/*
5072 * Call this when an option has been given a new value through a user command.
5073 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5074 */
5075 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005076did_set_option(
5077 int opt_idx,
5078 int opt_flags, /* possibly with OPT_MODELINE */
5079 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005080{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005081 long_u *p;
5082
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005083 options[opt_idx].flags |= P_WAS_SET;
5084
5085 /* When an option is set in the sandbox, from a modeline or in secure mode
5086 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005087 * flag. */
5088 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005089 if (secure
5090#ifdef HAVE_SANDBOX
5091 || sandbox != 0
5092#endif
5093 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005094 *p = *p | P_INSECURE;
5095 else if (new_value)
5096 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005097}
5098
Bram Moolenaar071d4272004-06-13 20:20:40 +00005099 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005100illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005101{
5102 if (errbuf == NULL)
5103 return (char_u *)"";
5104 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005105 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106 return errbuf;
5107}
5108
5109/*
5110 * Convert a key name or string into a key value.
5111 * Used for 'wildchar' and 'cedit' options.
5112 */
5113 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005114string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005115{
5116 if (*arg == '<')
5117 return find_key_option(arg + 1);
5118 if (*arg == '^')
5119 return Ctrl_chr(arg[1]);
5120 return *arg;
5121}
5122
5123#ifdef FEAT_CMDWIN
5124/*
5125 * Check value of 'cedit' and set cedit_key.
5126 * Returns NULL if value is OK, error message otherwise.
5127 */
5128 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005129check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005130{
5131 int n;
5132
5133 if (*p_cedit == NUL)
5134 cedit_key = -1;
5135 else
5136 {
5137 n = string_to_key(p_cedit);
5138 if (vim_isprintc(n))
5139 return e_invarg;
5140 cedit_key = n;
5141 }
5142 return NULL;
5143}
5144#endif
5145
5146#ifdef FEAT_TITLE
5147/*
5148 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5149 * maketitle() to create and display it.
5150 * When switching the title or icon off, call mch_restore_title() to get
5151 * the old value back.
5152 */
5153 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005154did_set_title(
5155 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005156{
5157 if (starting != NO_SCREEN
5158#ifdef FEAT_GUI
5159 && !gui.starting
5160#endif
5161 )
5162 {
5163 maketitle();
5164 if (icon)
5165 {
5166 if (!p_icon)
5167 mch_restore_title(2);
5168 }
5169 else
5170 {
5171 if (!p_title)
5172 mch_restore_title(1);
5173 }
5174 }
5175}
5176#endif
5177
5178/*
5179 * set_options_bin - called when 'bin' changes value.
5180 */
5181 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005182set_options_bin(
5183 int oldval,
5184 int newval,
5185 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186{
5187 /*
5188 * The option values that are changed when 'bin' changes are
5189 * copied when 'bin is set and restored when 'bin' is reset.
5190 */
5191 if (newval)
5192 {
5193 if (!oldval) /* switched on */
5194 {
5195 if (!(opt_flags & OPT_GLOBAL))
5196 {
5197 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5198 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5199 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5200 curbuf->b_p_et_nobin = curbuf->b_p_et;
5201 }
5202 if (!(opt_flags & OPT_LOCAL))
5203 {
5204 p_tw_nobin = p_tw;
5205 p_wm_nobin = p_wm;
5206 p_ml_nobin = p_ml;
5207 p_et_nobin = p_et;
5208 }
5209 }
5210
5211 if (!(opt_flags & OPT_GLOBAL))
5212 {
5213 curbuf->b_p_tw = 0; /* no automatic line wrap */
5214 curbuf->b_p_wm = 0; /* no automatic line wrap */
5215 curbuf->b_p_ml = 0; /* no modelines */
5216 curbuf->b_p_et = 0; /* no expandtab */
5217 }
5218 if (!(opt_flags & OPT_LOCAL))
5219 {
5220 p_tw = 0;
5221 p_wm = 0;
5222 p_ml = FALSE;
5223 p_et = FALSE;
5224 p_bin = TRUE; /* needed when called for the "-b" argument */
5225 }
5226 }
5227 else if (oldval) /* switched off */
5228 {
5229 if (!(opt_flags & OPT_GLOBAL))
5230 {
5231 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5232 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5233 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5234 curbuf->b_p_et = curbuf->b_p_et_nobin;
5235 }
5236 if (!(opt_flags & OPT_LOCAL))
5237 {
5238 p_tw = p_tw_nobin;
5239 p_wm = p_wm_nobin;
5240 p_ml = p_ml_nobin;
5241 p_et = p_et_nobin;
5242 }
5243 }
5244}
5245
5246#ifdef FEAT_VIMINFO
5247/*
5248 * Find the parameter represented by the given character (eg ', :, ", or /),
5249 * and return its associated value in the 'viminfo' string.
5250 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005251 * If the parameter is not specified in the string or there is no following
5252 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005253 */
5254 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005255get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005256{
5257 char_u *p;
5258
5259 p = find_viminfo_parameter(type);
5260 if (p != NULL && VIM_ISDIGIT(*p))
5261 return atoi((char *)p);
5262 return -1;
5263}
5264
5265/*
5266 * Find the parameter represented by the given character (eg ''', ':', '"', or
5267 * '/') in the 'viminfo' option and return a pointer to the string after it.
5268 * Return NULL if the parameter is not specified in the string.
5269 */
5270 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005271find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005272{
5273 char_u *p;
5274
5275 for (p = p_viminfo; *p; ++p)
5276 {
5277 if (*p == type)
5278 return p + 1;
5279 if (*p == 'n') /* 'n' is always the last one */
5280 break;
5281 p = vim_strchr(p, ','); /* skip until next ',' */
5282 if (p == NULL) /* hit the end without finding parameter */
5283 break;
5284 }
5285 return NULL;
5286}
5287#endif
5288
5289/*
5290 * Expand environment variables for some string options.
5291 * These string options cannot be indirect!
5292 * If "val" is NULL expand the current value of the option.
5293 * Return pointer to NameBuff, or NULL when not expanded.
5294 */
5295 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005296option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005297{
5298 /* if option doesn't need expansion nothing to do */
5299 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5300 return NULL;
5301
5302 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5303 * expand_env() would truncate the string. */
5304 if (val != NULL && STRLEN(val) > MAXPATHL)
5305 return NULL;
5306
5307 if (val == NULL)
5308 val = *(char_u **)options[opt_idx].var;
5309
5310 /*
5311 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5312 * Escape spaces when expanding 'tags', they are used to separate file
5313 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005314 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005315 */
5316 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005317 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005318#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005319 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5320#endif
5321 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5323 return NULL;
5324
5325 return NameBuff;
5326}
5327
5328/*
5329 * After setting various option values: recompute variables that depend on
5330 * option values.
5331 */
5332 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005333didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334{
5335 /* initialize the table for 'iskeyword' et.al. */
5336 (void)init_chartab();
5337
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005338#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005339 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005342 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343#ifdef FEAT_SESSION
5344 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5345 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5346#endif
5347#ifdef FEAT_FOLDING
5348 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5349#endif
5350 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005351 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352#ifdef FEAT_VIRTUALEDIT
5353 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5354#endif
5355#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5356 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5357#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005358#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005359 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005360 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005361 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005362 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005363#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005364#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5365 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5366#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005367#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005368 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5369#endif
5370#ifdef FEAT_CMDWIN
5371 /* set cedit_key */
5372 (void)check_cedit();
5373#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005374#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005375 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005376#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005377#ifdef FEAT_LINEBREAK
5378 /* initialize the table for 'breakat'. */
5379 fill_breakat_flags();
5380#endif
5381
5382}
5383
5384/*
5385 * More side effects of setting options.
5386 */
5387 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005388didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005389{
5390 /* Initialize the highlight_attr[] table. */
5391 (void)highlight_changed();
5392
5393 /* Parse default for 'wildmode' */
5394 check_opt_wim();
5395
5396 (void)set_chars_option(&p_lcs);
5397#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5398 /* Parse default for 'fillchars'. */
5399 (void)set_chars_option(&p_fcs);
5400#endif
5401
5402#ifdef FEAT_CLIPBOARD
5403 /* Parse default for 'clipboard' */
5404 (void)check_clipboard_option();
5405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005406}
5407
5408/*
5409 * Check for string options that are NULL (normally only termcap options).
5410 */
5411 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005412check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005413{
5414 int opt_idx;
5415
5416 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5417 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5418 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5419}
5420
5421/*
5422 * Check string options in a buffer for NULL value.
5423 */
5424 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005425check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005426{
5427#if defined(FEAT_QUICKFIX)
5428 check_string_option(&buf->b_p_bh);
5429 check_string_option(&buf->b_p_bt);
5430#endif
5431#ifdef FEAT_MBYTE
5432 check_string_option(&buf->b_p_fenc);
5433#endif
5434 check_string_option(&buf->b_p_ff);
5435#ifdef FEAT_FIND_ID
5436 check_string_option(&buf->b_p_def);
5437 check_string_option(&buf->b_p_inc);
5438# ifdef FEAT_EVAL
5439 check_string_option(&buf->b_p_inex);
5440# endif
5441#endif
5442#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5443 check_string_option(&buf->b_p_inde);
5444 check_string_option(&buf->b_p_indk);
5445#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005446#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5447 check_string_option(&buf->b_p_bexpr);
5448#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005449#if defined(FEAT_CRYPT)
5450 check_string_option(&buf->b_p_cm);
5451#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005452#if defined(FEAT_EVAL)
5453 check_string_option(&buf->b_p_fex);
5454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005455#ifdef FEAT_CRYPT
5456 check_string_option(&buf->b_p_key);
5457#endif
5458 check_string_option(&buf->b_p_kp);
5459 check_string_option(&buf->b_p_mps);
5460 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005461 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462 check_string_option(&buf->b_p_isk);
5463#ifdef FEAT_COMMENTS
5464 check_string_option(&buf->b_p_com);
5465#endif
5466#ifdef FEAT_FOLDING
5467 check_string_option(&buf->b_p_cms);
5468#endif
5469 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005470#ifdef FEAT_TEXTOBJ
5471 check_string_option(&buf->b_p_qe);
5472#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005473#ifdef FEAT_SYN_HL
5474 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005475 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005476#endif
5477#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005478 check_string_option(&buf->b_s.b_p_spc);
5479 check_string_option(&buf->b_s.b_p_spf);
5480 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005481#endif
5482#ifdef FEAT_SEARCHPATH
5483 check_string_option(&buf->b_p_sua);
5484#endif
5485#ifdef FEAT_CINDENT
5486 check_string_option(&buf->b_p_cink);
5487 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005488 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005489#endif
5490#ifdef FEAT_AUTOCMD
5491 check_string_option(&buf->b_p_ft);
5492#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005493#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5494 check_string_option(&buf->b_p_cinw);
5495#endif
5496#ifdef FEAT_INS_EXPAND
5497 check_string_option(&buf->b_p_cpt);
5498#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005499#ifdef FEAT_COMPL_FUNC
5500 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005501 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005502#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005503#ifdef FEAT_KEYMAP
5504 check_string_option(&buf->b_p_keymap);
5505#endif
5506#ifdef FEAT_QUICKFIX
5507 check_string_option(&buf->b_p_gp);
5508 check_string_option(&buf->b_p_mp);
5509 check_string_option(&buf->b_p_efm);
5510#endif
5511 check_string_option(&buf->b_p_ep);
5512 check_string_option(&buf->b_p_path);
5513 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005514 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005515#ifdef FEAT_INS_EXPAND
5516 check_string_option(&buf->b_p_dict);
5517 check_string_option(&buf->b_p_tsr);
5518#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005519#ifdef FEAT_LISP
5520 check_string_option(&buf->b_p_lw);
5521#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005522 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005523}
5524
5525/*
5526 * Free the string allocated for an option.
5527 * Checks for the string being empty_option. This may happen if we're out of
5528 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5529 * check_options().
5530 * Does NOT check for P_ALLOCED flag!
5531 */
5532 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005533free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005534{
5535 if (p != empty_option)
5536 vim_free(p);
5537}
5538
5539 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005540clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541{
5542 if (*pp != empty_option)
5543 vim_free(*pp);
5544 *pp = empty_option;
5545}
5546
5547 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005548check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549{
5550 if (*pp == NULL)
5551 *pp = empty_option;
5552}
5553
5554/*
5555 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5556 */
5557 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005558set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559{
5560 int opt_idx;
5561
5562 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5563 if (options[opt_idx].var == (char_u *)p)
5564 {
5565 options[opt_idx].flags |= P_ALLOCED;
5566 return;
5567 }
5568 return; /* cannot happen: didn't find it! */
5569}
5570
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005571#if defined(FEAT_EVAL) || defined(PROTO)
5572/*
5573 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5574 * Return FALSE when it wasn't.
5575 * Return -1 for an unknown option.
5576 */
5577 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005578was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005579{
5580 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005581 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005582
5583 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005584 {
5585 flagp = insecure_flag(idx, opt_flags);
5586 return (*flagp & P_INSECURE) != 0;
5587 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005588 EMSG2(_(e_intern2), "was_set_insecurely()");
5589 return -1;
5590}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005591
5592/*
5593 * Get a pointer to the flags used for the P_INSECURE flag of option
5594 * "opt_idx". For some local options a local flags field is used.
5595 */
5596 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005597insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005598{
5599 if (opt_flags & OPT_LOCAL)
5600 switch ((int)options[opt_idx].indir)
5601 {
5602#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005603 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005604#endif
5605#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005606# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005607 case PV_FDE: return &curwin->w_p_fde_flags;
5608 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005609# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005610# ifdef FEAT_BEVAL
5611 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5612# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005613# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005614 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005615# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005616 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005617# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005618 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005619# endif
5620#endif
5621 }
5622
5623 /* Nothing special, return global flags field. */
5624 return &options[opt_idx].flags;
5625}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005626#endif
5627
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005628#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005629static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005630
5631/*
5632 * Redraw the window title and/or tab page text later.
5633 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005634static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005635{
5636 need_maketitle = TRUE;
5637# ifdef FEAT_WINDOWS
5638 redraw_tabline = TRUE;
5639# endif
5640}
5641#endif
5642
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643/*
5644 * Set a string option to a new value (without checking the effect).
5645 * The string is copied into allocated memory.
5646 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005647 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005648 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649 */
5650 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005651set_string_option_direct(
5652 char_u *name,
5653 int opt_idx,
5654 char_u *val,
5655 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5656 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657{
5658 char_u *s;
5659 char_u **varp;
5660 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005661 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662
Bram Moolenaar89d40322006-08-29 15:30:07 +00005663 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005665 idx = findoption(name);
5666 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005667 {
5668 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005669 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005671 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672 }
5673
Bram Moolenaar89d40322006-08-29 15:30:07 +00005674 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675 return;
5676
5677 s = vim_strsave(val);
5678 if (s != NULL)
5679 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005680 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005682 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683 free_string_option(*varp);
5684 *varp = s;
5685
5686 /* For buffer/window local option may also set the global value. */
5687 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005688 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689
Bram Moolenaar89d40322006-08-29 15:30:07 +00005690 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691
5692 /* When setting both values of a global option with a local value,
5693 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005694 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695 {
5696 free_string_option(*varp);
5697 *varp = empty_option;
5698 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005699# ifdef FEAT_EVAL
5700 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005701 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005702 set_sid == 0 ? current_SID : set_sid);
5703# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704 }
5705}
5706
5707/*
5708 * Set global value for string option when it's a local option.
5709 */
5710 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005711set_string_option_global(
5712 int opt_idx, /* option index */
5713 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005714{
5715 char_u **p, *s;
5716
5717 /* the global value is always allocated */
5718 if (options[opt_idx].var == VAR_WIN)
5719 p = (char_u **)GLOBAL_WO(varp);
5720 else
5721 p = (char_u **)options[opt_idx].var;
5722 if (options[opt_idx].indir != PV_NONE
5723 && p != varp
5724 && (s = vim_strsave(*varp)) != NULL)
5725 {
5726 free_string_option(*p);
5727 *p = s;
5728 }
5729}
5730
5731/*
5732 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005733 *
5734 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005736 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005737set_string_option(
5738 int opt_idx,
5739 char_u *value,
5740 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005741{
5742 char_u *s;
5743 char_u **varp;
5744 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005745#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5746 char_u *saved_oldval = NULL;
5747#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005748 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005749
5750 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005751 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005752
5753 s = vim_strsave(value);
5754 if (s != NULL)
5755 {
5756 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5757 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005758 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759 ? OPT_GLOBAL : OPT_LOCAL)
5760 : opt_flags);
5761 oldval = *varp;
5762 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005763
5764#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005765 if (!starting
5766# ifdef FEAT_CRYPT
5767 && options[opt_idx].indir != PV_KEY
5768# endif
5769 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005770 saved_oldval = vim_strsave(oldval);
5771#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005772 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5773 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005774 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005775
5776 /* call autocomamnd after handling side effects */
5777#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5778 if (saved_oldval != NULL)
5779 {
5780 char_u buf_type[7];
5781 sprintf((char *)buf_type, "%s",
5782 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005783 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5784 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005785 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5786 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5787 reset_v_option_vars();
5788 vim_free(saved_oldval);
5789 }
5790#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005791 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005792 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005793}
5794
5795/*
5796 * Handle string options that need some action to perform when changed.
5797 * Returns NULL for success, or an error message for an error.
5798 */
5799 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005800did_set_string_option(
5801 int opt_idx, /* index in options[] table */
5802 char_u **varp, /* pointer to the option variable */
5803 int new_value_alloced, /* new value was allocated */
5804 char_u *oldval, /* previous value of the option */
5805 char_u *errbuf, /* buffer for errors, or NULL */
5806 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005807{
5808 char_u *errmsg = NULL;
5809 char_u *s, *p;
5810 int did_chartab = FALSE;
5811 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005812 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005813#ifdef FEAT_GUI
5814 /* set when changing an option that only requires a redraw in the GUI */
5815 int redraw_gui_only = FALSE;
5816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005817
5818 /* Get the global option to compare with, otherwise we would have to check
5819 * two values for all local options. */
5820 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5821
5822 /* Disallow changing some options from secure mode */
5823 if ((secure
5824#ifdef HAVE_SANDBOX
5825 || sandbox != 0
5826#endif
5827 ) && (options[opt_idx].flags & P_SECURE))
5828 {
5829 errmsg = e_secure;
5830 }
5831
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005832 /* Check for a "normal" file name in some options. Disallow a path
5833 * separator (slash and/or backslash), wildcards and characters that are
5834 * often illegal in a file name. */
5835 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005836 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005837 {
5838 errmsg = e_invarg;
5839 }
5840
Bram Moolenaar071d4272004-06-13 20:20:40 +00005841 /* 'term' */
5842 else if (varp == &T_NAME)
5843 {
5844 if (T_NAME[0] == NUL)
5845 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5846#ifdef FEAT_GUI
5847 if (gui.in_use)
5848 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5849 else if (term_is_gui(T_NAME))
5850 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5851#endif
5852 else if (set_termname(T_NAME) == FAIL)
5853 errmsg = (char_u *)N_("E522: Not found in termcap");
5854 else
5855 /* Screen colors may have changed. */
5856 redraw_later_clear();
5857 }
5858
5859 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005860 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005861 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005862 char_u *bkc = p_bkc;
5863 unsigned int *flags = &bkc_flags;
5864
5865 if (opt_flags & OPT_LOCAL)
5866 {
5867 bkc = curbuf->b_p_bkc;
5868 flags = &curbuf->b_bkc_flags;
5869 }
5870
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005871 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5872 /* make the local value empty: use the global value */
5873 *flags = 0;
5874 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005876 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5877 errmsg = e_invarg;
5878 if ((((int)*flags & BKC_AUTO) != 0)
5879 + (((int)*flags & BKC_YES) != 0)
5880 + (((int)*flags & BKC_NO) != 0) != 1)
5881 {
5882 /* Must have exactly one of "auto", "yes" and "no". */
5883 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5884 errmsg = e_invarg;
5885 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886 }
5887 }
5888
5889 /* 'backupext' and 'patchmode' */
5890 else if (varp == &p_bex || varp == &p_pm)
5891 {
5892 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5893 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5894 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5895 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005896#ifdef FEAT_LINEBREAK
5897 /* 'breakindentopt' */
5898 else if (varp == &curwin->w_p_briopt)
5899 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005900 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005901 errmsg = e_invarg;
5902 }
5903#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904
5905 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005906 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005908 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005909 */
5910 else if ( varp == &p_isi
5911 || varp == &(curbuf->b_p_isk)
5912 || varp == &p_isp
5913 || varp == &p_isf)
5914 {
5915 if (init_chartab() == FAIL)
5916 {
5917 did_chartab = TRUE; /* need to restore it below */
5918 errmsg = e_invarg; /* error in value */
5919 }
5920 }
5921
5922 /* 'helpfile' */
5923 else if (varp == &p_hf)
5924 {
5925 /* May compute new values for $VIM and $VIMRUNTIME */
5926 if (didset_vim)
5927 {
5928 vim_setenv((char_u *)"VIM", (char_u *)"");
5929 didset_vim = FALSE;
5930 }
5931 if (didset_vimruntime)
5932 {
5933 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5934 didset_vimruntime = FALSE;
5935 }
5936 }
5937
Bram Moolenaar1a384422010-07-14 19:53:30 +02005938#ifdef FEAT_SYN_HL
5939 /* 'colorcolumn' */
5940 else if (varp == &curwin->w_p_cc)
5941 errmsg = check_colorcolumn(curwin);
5942#endif
5943
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944#ifdef FEAT_MULTI_LANG
5945 /* 'helplang' */
5946 else if (varp == &p_hlg)
5947 {
5948 /* Check for "", "ab", "ab,cd", etc. */
5949 for (s = p_hlg; *s != NUL; s += 3)
5950 {
5951 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5952 {
5953 errmsg = e_invarg;
5954 break;
5955 }
5956 if (s[2] == NUL)
5957 break;
5958 }
5959 }
5960#endif
5961
5962 /* 'highlight' */
5963 else if (varp == &p_hl)
5964 {
5965 if (highlight_changed() == FAIL)
5966 errmsg = e_invarg; /* invalid flags */
5967 }
5968
5969 /* 'nrformats' */
5970 else if (gvarp == &p_nf)
5971 {
5972 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5973 errmsg = e_invarg;
5974 }
5975
5976#ifdef FEAT_SESSION
5977 /* 'sessionoptions' */
5978 else if (varp == &p_ssop)
5979 {
5980 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5981 errmsg = e_invarg;
5982 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5983 {
5984 /* Don't allow both "sesdir" and "curdir". */
5985 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5986 errmsg = e_invarg;
5987 }
5988 }
5989 /* 'viewoptions' */
5990 else if (varp == &p_vop)
5991 {
5992 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5993 errmsg = e_invarg;
5994 }
5995#endif
5996
5997 /* 'scrollopt' */
5998#ifdef FEAT_SCROLLBIND
5999 else if (varp == &p_sbo)
6000 {
6001 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6002 errmsg = e_invarg;
6003 }
6004#endif
6005
6006 /* 'ambiwidth' */
6007#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006008 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009 {
6010 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6011 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006012 else if (set_chars_option(&p_lcs) != NULL)
6013 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6014# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6015 else if (set_chars_option(&p_fcs) != NULL)
6016 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6017# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006018 }
6019#endif
6020
6021 /* 'background' */
6022 else if (varp == &p_bg)
6023 {
6024 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6025 {
6026#ifdef FEAT_EVAL
6027 int dark = (*p_bg == 'd');
6028#endif
6029
6030 init_highlight(FALSE, FALSE);
6031
6032#ifdef FEAT_EVAL
6033 if (dark != (*p_bg == 'd')
6034 && get_var_value((char_u *)"g:colors_name") != NULL)
6035 {
6036 /* The color scheme must have set 'background' back to another
6037 * value, that's not what we want here. Disable the color
6038 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006039 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006040 free_string_option(p_bg);
6041 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6042 check_string_option(&p_bg);
6043 init_highlight(FALSE, FALSE);
6044 }
6045#endif
6046 }
6047 else
6048 errmsg = e_invarg;
6049 }
6050
6051 /* 'wildmode' */
6052 else if (varp == &p_wim)
6053 {
6054 if (check_opt_wim() == FAIL)
6055 errmsg = e_invarg;
6056 }
6057
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006058#ifdef FEAT_CMDL_COMPL
6059 /* 'wildoptions' */
6060 else if (varp == &p_wop)
6061 {
6062 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6063 errmsg = e_invarg;
6064 }
6065#endif
6066
Bram Moolenaar071d4272004-06-13 20:20:40 +00006067#ifdef FEAT_WAK
6068 /* 'winaltkeys' */
6069 else if (varp == &p_wak)
6070 {
6071 if (*p_wak == NUL
6072 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6073 errmsg = e_invarg;
6074# ifdef FEAT_MENU
6075# ifdef FEAT_GUI_MOTIF
6076 else if (gui.in_use)
6077 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6078# else
6079# ifdef FEAT_GUI_GTK
6080 else if (gui.in_use)
6081 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6082# endif
6083# endif
6084# endif
6085 }
6086#endif
6087
6088#ifdef FEAT_AUTOCMD
6089 /* 'eventignore' */
6090 else if (varp == &p_ei)
6091 {
6092 if (check_ei() == FAIL)
6093 errmsg = e_invarg;
6094 }
6095#endif
6096
6097#ifdef FEAT_MBYTE
6098 /* 'encoding' and 'fileencoding' */
6099 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6100 {
6101 if (gvarp == &p_fenc)
6102 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006103 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006104 errmsg = e_modifiable;
6105 else if (vim_strchr(*varp, ',') != NULL)
6106 /* No comma allowed in 'fileencoding'; catches confusing it
6107 * with 'fileencodings'. */
6108 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006110 {
6111# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006113 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006115 /* Add 'fileencoding' to the swap file. */
6116 ml_setflags(curbuf);
6117 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006118 }
6119 if (errmsg == NULL)
6120 {
6121 /* canonize the value, so that STRCMP() can be used on it */
6122 p = enc_canonize(*varp);
6123 if (p != NULL)
6124 {
6125 vim_free(*varp);
6126 *varp = p;
6127 }
6128 if (varp == &p_enc)
6129 {
6130 errmsg = mb_init();
6131# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006132 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006133# endif
6134 }
6135 }
6136
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006137# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6139 {
6140 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6141 if (STRCMP(p_tenc, "utf-8") != 0)
6142 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6143 }
6144# endif
6145
6146 if (errmsg == NULL)
6147 {
6148# ifdef FEAT_KEYMAP
6149 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6150 * (with another encoding). */
6151 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6152 (void)keymap_init();
6153# endif
6154
6155 /* When 'termencoding' is not empty and 'encoding' changes or when
6156 * 'termencoding' changes, need to setup for keyboard input and
6157 * display output conversion. */
6158 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6159 {
6160 convert_setup(&input_conv, p_tenc, p_enc);
6161 convert_setup(&output_conv, p_enc, p_tenc);
6162 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006163
6164# if defined(WIN3264) && defined(FEAT_MBYTE)
6165 /* $HOME may have characters in active code page. */
6166 if (varp == &p_enc)
6167 init_homedir();
6168# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006169 }
6170 }
6171#endif
6172
6173#if defined(FEAT_POSTSCRIPT)
6174 else if (varp == &p_penc)
6175 {
6176 /* Canonize printencoding if VIM standard one */
6177 p = enc_canonize(p_penc);
6178 if (p != NULL)
6179 {
6180 vim_free(p_penc);
6181 p_penc = p;
6182 }
6183 else
6184 {
6185 /* Ensure lower case and '-' for '_' */
6186 for (s = p_penc; *s != NUL; s++)
6187 {
6188 if (*s == '_')
6189 *s = '-';
6190 else
6191 *s = TOLOWER_ASC(*s);
6192 }
6193 }
6194 }
6195#endif
6196
Bram Moolenaar9372a112005-12-06 19:59:18 +00006197#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006198 else if (varp == &p_imak)
6199 {
6200 if (gui.in_use && !im_xim_isvalid_imactivate())
6201 errmsg = e_invarg;
6202 }
6203#endif
6204
6205#ifdef FEAT_KEYMAP
6206 else if (varp == &curbuf->b_p_keymap)
6207 {
6208 /* load or unload key mapping tables */
6209 errmsg = keymap_init();
6210
Bram Moolenaarfab06232009-03-04 03:13:35 +00006211 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006213 if (*curbuf->b_p_keymap != NUL)
6214 {
6215 /* Installed a new keymap, switch on using it. */
6216 curbuf->b_p_iminsert = B_IMODE_LMAP;
6217 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6218 curbuf->b_p_imsearch = B_IMODE_LMAP;
6219 }
6220 else
6221 {
6222 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6223 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6224 curbuf->b_p_iminsert = B_IMODE_NONE;
6225 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6226 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6227 }
6228 if ((opt_flags & OPT_LOCAL) == 0)
6229 {
6230 set_iminsert_global();
6231 set_imsearch_global();
6232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006233# ifdef FEAT_WINDOWS
6234 status_redraw_curbuf();
6235# endif
6236 }
6237 }
6238#endif
6239
6240 /* 'fileformat' */
6241 else if (gvarp == &p_ff)
6242 {
6243 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6244 errmsg = e_modifiable;
6245 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6246 errmsg = e_invarg;
6247 else
6248 {
6249 /* may also change 'textmode' */
6250 if (get_fileformat(curbuf) == EOL_DOS)
6251 curbuf->b_p_tx = TRUE;
6252 else
6253 curbuf->b_p_tx = FALSE;
6254#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006255 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006256#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006257 /* update flag in swap file */
6258 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006259 /* Redraw needed when switching to/from "mac": a CR in the text
6260 * will be displayed differently. */
6261 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6262 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263 }
6264 }
6265
6266 /* 'fileformats' */
6267 else if (varp == &p_ffs)
6268 {
6269 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6270 errmsg = e_invarg;
6271 else
6272 {
6273 /* also change 'textauto' */
6274 if (*p_ffs == NUL)
6275 p_ta = FALSE;
6276 else
6277 p_ta = TRUE;
6278 }
6279 }
6280
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006281#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006282 /* 'cryptkey' */
6283 else if (gvarp == &p_key)
6284 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006285# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006286 /* Make sure the ":set" command doesn't show the new value in the
6287 * history. */
6288 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006289# endif
6290 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6291 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006292 ml_set_crypt_key(curbuf, oldval,
6293 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006294 }
6295
6296 else if (gvarp == &p_cm)
6297 {
6298 if (opt_flags & OPT_LOCAL)
6299 p = curbuf->b_p_cm;
6300 else
6301 p = p_cm;
6302 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6303 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006304 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006305 errmsg = e_invarg;
6306 else
6307 {
6308 /* When setting the global value to empty, make it "zip". */
6309 if (*p_cm == NUL)
6310 {
6311 if (new_value_alloced)
6312 free_string_option(p_cm);
6313 p_cm = vim_strsave((char_u *)"zip");
6314 new_value_alloced = TRUE;
6315 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006316 /* When using ":set cm=name" the local value is going to be empty.
6317 * Do that here, otherwise the crypt functions will still use the
6318 * local value. */
6319 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6320 {
6321 free_string_option(curbuf->b_p_cm);
6322 curbuf->b_p_cm = empty_option;
6323 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006324
6325 /* Need to update the swapfile when the effective method changed.
6326 * Set "s" to the effective old value, "p" to the effective new
6327 * method and compare. */
6328 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6329 s = p_cm; /* was previously using the global value */
6330 else
6331 s = oldval;
6332 if (*curbuf->b_p_cm == NUL)
6333 p = p_cm; /* is now using the global value */
6334 else
6335 p = curbuf->b_p_cm;
6336 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006337 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006338
6339 /* If the global value changes need to update the swapfile for all
6340 * buffers using that value. */
6341 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6342 {
6343 buf_T *buf;
6344
6345 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6346 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006347 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006348 }
6349 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 }
6351#endif
6352
6353 /* 'matchpairs' */
6354 else if (gvarp == &p_mps)
6355 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006356#ifdef FEAT_MBYTE
6357 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006358 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006359 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006360 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006361 int x2 = -1;
6362 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006363
6364 if (*p != NUL)
6365 p += mb_ptr2len(p);
6366 if (*p != NUL)
6367 x2 = *p++;
6368 if (*p != NUL)
6369 {
6370 x3 = mb_ptr2char(p);
6371 p += mb_ptr2len(p);
6372 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006373 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006374 {
6375 errmsg = e_invarg;
6376 break;
6377 }
6378 if (*p == NUL)
6379 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006381 }
6382 else
6383#endif
6384 {
6385 /* Check for "x:y,x:y" */
6386 for (p = *varp; *p != NUL; p += 4)
6387 {
6388 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6389 {
6390 errmsg = e_invarg;
6391 break;
6392 }
6393 if (p[3] == NUL)
6394 break;
6395 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396 }
6397 }
6398
6399#ifdef FEAT_COMMENTS
6400 /* 'comments' */
6401 else if (gvarp == &p_com)
6402 {
6403 for (s = *varp; *s; )
6404 {
6405 while (*s && *s != ':')
6406 {
6407 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6408 && !VIM_ISDIGIT(*s) && *s != '-')
6409 {
6410 errmsg = illegal_char(errbuf, *s);
6411 break;
6412 }
6413 ++s;
6414 }
6415 if (*s++ == NUL)
6416 errmsg = (char_u *)N_("E524: Missing colon");
6417 else if (*s == ',' || *s == NUL)
6418 errmsg = (char_u *)N_("E525: Zero length string");
6419 if (errmsg != NULL)
6420 break;
6421 while (*s && *s != ',')
6422 {
6423 if (*s == '\\' && s[1] != NUL)
6424 ++s;
6425 ++s;
6426 }
6427 s = skip_to_option_part(s);
6428 }
6429 }
6430#endif
6431
6432 /* 'listchars' */
6433 else if (varp == &p_lcs)
6434 {
6435 errmsg = set_chars_option(varp);
6436 }
6437
6438#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6439 /* 'fillchars' */
6440 else if (varp == &p_fcs)
6441 {
6442 errmsg = set_chars_option(varp);
6443 }
6444#endif
6445
6446#ifdef FEAT_CMDWIN
6447 /* 'cedit' */
6448 else if (varp == &p_cedit)
6449 {
6450 errmsg = check_cedit();
6451 }
6452#endif
6453
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006454 /* 'verbosefile' */
6455 else if (varp == &p_vfile)
6456 {
6457 verbose_stop();
6458 if (*p_vfile != NUL && verbose_open() == FAIL)
6459 errmsg = e_invarg;
6460 }
6461
Bram Moolenaar071d4272004-06-13 20:20:40 +00006462#ifdef FEAT_VIMINFO
6463 /* 'viminfo' */
6464 else if (varp == &p_viminfo)
6465 {
6466 for (s = p_viminfo; *s;)
6467 {
6468 /* Check it's a valid character */
6469 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6470 {
6471 errmsg = illegal_char(errbuf, *s);
6472 break;
6473 }
6474 if (*s == 'n') /* name is always last one */
6475 {
6476 break;
6477 }
6478 else if (*s == 'r') /* skip until next ',' */
6479 {
6480 while (*++s && *s != ',')
6481 ;
6482 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006483 else if (*s == '%')
6484 {
6485 /* optional number */
6486 while (vim_isdigit(*++s))
6487 ;
6488 }
6489 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490 ++s; /* no extra chars */
6491 else /* must have a number */
6492 {
6493 while (vim_isdigit(*++s))
6494 ;
6495
6496 if (!VIM_ISDIGIT(*(s - 1)))
6497 {
6498 if (errbuf != NULL)
6499 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006500 sprintf((char *)errbuf,
6501 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006502 transchar_byte(*(s - 1)));
6503 errmsg = errbuf;
6504 }
6505 else
6506 errmsg = (char_u *)"";
6507 break;
6508 }
6509 }
6510 if (*s == ',')
6511 ++s;
6512 else if (*s)
6513 {
6514 if (errbuf != NULL)
6515 errmsg = (char_u *)N_("E527: Missing comma");
6516 else
6517 errmsg = (char_u *)"";
6518 break;
6519 }
6520 }
6521 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6522 errmsg = (char_u *)N_("E528: Must specify a ' value");
6523 }
6524#endif /* FEAT_VIMINFO */
6525
6526 /* terminal options */
6527 else if (istermoption(&options[opt_idx]) && full_screen)
6528 {
6529 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6530 if (varp == &T_CCO)
6531 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006532 int colors = atoi((char *)T_CCO);
6533
6534 /* Only reinitialize colors if t_Co value has really changed to
6535 * avoid expensive reload of colorscheme if t_Co is set to the
6536 * same value multiple times. */
6537 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006538 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006539 t_colors = colors;
6540 if (t_colors <= 1)
6541 {
6542 if (new_value_alloced)
6543 vim_free(T_CCO);
6544 T_CCO = empty_option;
6545 }
6546 /* We now have a different color setup, initialize it again. */
6547 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549 }
6550 ttest(FALSE);
6551 if (varp == &T_ME)
6552 {
6553 out_str(T_ME);
6554 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006555#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006556 /* Since t_me has been set, this probably means that the user
6557 * wants to use this as default colors. Need to reset default
6558 * background/foreground colors. */
6559 mch_set_normal_colors();
6560#endif
6561 }
6562 }
6563
6564#ifdef FEAT_LINEBREAK
6565 /* 'showbreak' */
6566 else if (varp == &p_sbr)
6567 {
6568 for (s = p_sbr; *s; )
6569 {
6570 if (ptr2cells(s) != 1)
6571 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006572 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006573 }
6574 }
6575#endif
6576
6577#ifdef FEAT_GUI
6578 /* 'guifont' */
6579 else if (varp == &p_guifont)
6580 {
6581 if (gui.in_use)
6582 {
6583 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006584# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006585 /*
6586 * Put up a font dialog and let the user select a new value.
6587 * If this is cancelled go back to the old value but don't
6588 * give an error message.
6589 */
6590 if (STRCMP(p, "*") == 0)
6591 {
6592 p = gui_mch_font_dialog(oldval);
6593
6594 if (new_value_alloced)
6595 free_string_option(p_guifont);
6596
6597 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6598 new_value_alloced = TRUE;
6599 }
6600# endif
6601 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6602 {
6603# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6604 if (STRCMP(p_guifont, "*") == 0)
6605 {
6606 /* Dialog was cancelled: Keep the old value without giving
6607 * an error message. */
6608 if (new_value_alloced)
6609 free_string_option(p_guifont);
6610 p_guifont = vim_strsave(oldval);
6611 new_value_alloced = TRUE;
6612 }
6613 else
6614# endif
6615 errmsg = (char_u *)N_("E596: Invalid font(s)");
6616 }
6617 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006618 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006619 }
6620# ifdef FEAT_XFONTSET
6621 else if (varp == &p_guifontset)
6622 {
6623 if (STRCMP(p_guifontset, "*") == 0)
6624 errmsg = (char_u *)N_("E597: can't select fontset");
6625 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6626 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006627 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006628 }
6629# endif
6630# ifdef FEAT_MBYTE
6631 else if (varp == &p_guifontwide)
6632 {
6633 if (STRCMP(p_guifontwide, "*") == 0)
6634 errmsg = (char_u *)N_("E533: can't select wide font");
6635 else if (gui_get_wide_font() == FAIL)
6636 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006637 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006638 }
6639# endif
6640#endif
6641
6642#ifdef CURSOR_SHAPE
6643 /* 'guicursor' */
6644 else if (varp == &p_guicursor)
6645 errmsg = parse_shape_opt(SHAPE_CURSOR);
6646#endif
6647
6648#ifdef FEAT_MOUSESHAPE
6649 /* 'mouseshape' */
6650 else if (varp == &p_mouseshape)
6651 {
6652 errmsg = parse_shape_opt(SHAPE_MOUSE);
6653 update_mouseshape(-1);
6654 }
6655#endif
6656
6657#ifdef FEAT_PRINTER
6658 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006659 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006660# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006661 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006662 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006663# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006664#endif
6665
6666#ifdef FEAT_LANGMAP
6667 /* 'langmap' */
6668 else if (varp == &p_langmap)
6669 langmap_set();
6670#endif
6671
6672#ifdef FEAT_LINEBREAK
6673 /* 'breakat' */
6674 else if (varp == &p_breakat)
6675 fill_breakat_flags();
6676#endif
6677
6678#ifdef FEAT_TITLE
6679 /* 'titlestring' and 'iconstring' */
6680 else if (varp == &p_titlestring || varp == &p_iconstring)
6681 {
6682# ifdef FEAT_STL_OPT
6683 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6684
6685 /* NULL => statusline syntax */
6686 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6687 stl_syntax |= flagval;
6688 else
6689 stl_syntax &= ~flagval;
6690# endif
6691 did_set_title(varp == &p_iconstring);
6692
6693 }
6694#endif
6695
6696#ifdef FEAT_GUI
6697 /* 'guioptions' */
6698 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006699 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006700 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006701 redraw_gui_only = TRUE;
6702 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006703#endif
6704
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006705#if defined(FEAT_GUI_TABLINE)
6706 /* 'guitablabel' */
6707 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006708 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006709 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006710 redraw_gui_only = TRUE;
6711 }
6712 /* 'guitabtooltip' */
6713 else if (varp == &p_gtt)
6714 {
6715 redraw_gui_only = TRUE;
6716 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006717#endif
6718
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6720 /* 'ttymouse' */
6721 else if (varp == &p_ttym)
6722 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006723 /* Switch the mouse off before changing the escape sequences used for
6724 * that. */
6725 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006726 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6727 errmsg = e_invarg;
6728 else
6729 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006730 if (termcap_active)
6731 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732 }
6733#endif
6734
Bram Moolenaar071d4272004-06-13 20:20:40 +00006735 /* 'selection' */
6736 else if (varp == &p_sel)
6737 {
6738 if (*p_sel == NUL
6739 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6740 errmsg = e_invarg;
6741 }
6742
6743 /* 'selectmode' */
6744 else if (varp == &p_slm)
6745 {
6746 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6747 errmsg = e_invarg;
6748 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749
6750#ifdef FEAT_BROWSE
6751 /* 'browsedir' */
6752 else if (varp == &p_bsdir)
6753 {
6754 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6755 && !mch_isdir(p_bsdir))
6756 errmsg = e_invarg;
6757 }
6758#endif
6759
Bram Moolenaar071d4272004-06-13 20:20:40 +00006760 /* 'keymodel' */
6761 else if (varp == &p_km)
6762 {
6763 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6764 errmsg = e_invarg;
6765 else
6766 {
6767 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6768 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6769 }
6770 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006771
6772 /* 'mousemodel' */
6773 else if (varp == &p_mousem)
6774 {
6775 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6776 errmsg = e_invarg;
6777#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6778 else if (*p_mousem != *oldval)
6779 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6780 * to create or delete the popup menus. */
6781 gui_motif_update_mousemodel(root_menu);
6782#endif
6783 }
6784
6785 /* 'switchbuf' */
6786 else if (varp == &p_swb)
6787 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006788 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006789 errmsg = e_invarg;
6790 }
6791
6792 /* 'debug' */
6793 else if (varp == &p_debug)
6794 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006795 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796 errmsg = e_invarg;
6797 }
6798
6799 /* 'display' */
6800 else if (varp == &p_dy)
6801 {
6802 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6803 errmsg = e_invarg;
6804 else
6805 (void)init_chartab();
6806
6807 }
6808
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006809#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006810 /* 'eadirection' */
6811 else if (varp == &p_ead)
6812 {
6813 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6814 errmsg = e_invarg;
6815 }
6816#endif
6817
6818#ifdef FEAT_CLIPBOARD
6819 /* 'clipboard' */
6820 else if (varp == &p_cb)
6821 errmsg = check_clipboard_option();
6822#endif
6823
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006824#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006825 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6826 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006827 else if (varp == &(curwin->w_s->b_p_spl)
6828 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006829 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006830 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006831 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006832 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006833 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006834 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006835 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006836 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006837 /* 'spellsuggest' */
6838 else if (varp == &p_sps)
6839 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006840 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006841 errmsg = e_invarg;
6842 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006843 /* 'mkspellmem' */
6844 else if (varp == &p_msm)
6845 {
6846 if (spell_check_msm() != OK)
6847 errmsg = e_invarg;
6848 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006849#endif
6850
Bram Moolenaar071d4272004-06-13 20:20:40 +00006851#ifdef FEAT_QUICKFIX
6852 /* When 'bufhidden' is set, check for valid value. */
6853 else if (gvarp == &p_bh)
6854 {
6855 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6856 errmsg = e_invarg;
6857 }
6858
6859 /* When 'buftype' is set, check for valid value. */
6860 else if (gvarp == &p_bt)
6861 {
6862 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6863 errmsg = e_invarg;
6864 else
6865 {
6866# ifdef FEAT_WINDOWS
6867 if (curwin->w_status_height)
6868 {
6869 curwin->w_redr_status = TRUE;
6870 redraw_later(VALID);
6871 }
6872# endif
6873 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006874# ifdef FEAT_TITLE
6875 redraw_titles();
6876# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006877 }
6878 }
6879#endif
6880
6881#ifdef FEAT_STL_OPT
6882 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006883 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 {
6885 int wid;
6886
6887 if (varp == &p_ruf) /* reset ru_wid first */
6888 ru_wid = 0;
6889 s = *varp;
6890 if (varp == &p_ruf && *s == '%')
6891 {
6892 /* set ru_wid if 'ruf' starts with "%99(" */
6893 if (*++s == '-') /* ignore a '-' */
6894 s++;
6895 wid = getdigits(&s);
6896 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6897 ru_wid = wid;
6898 else
6899 errmsg = check_stl_option(p_ruf);
6900 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006901 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006902 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006904 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006905 comp_col();
6906 }
6907#endif
6908
6909#ifdef FEAT_INS_EXPAND
6910 /* check if it is a valid value for 'complete' -- Acevedo */
6911 else if (gvarp == &p_cpt)
6912 {
6913 for (s = *varp; *s;)
6914 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006915 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006916 s++;
6917 if (!*s)
6918 break;
6919 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6920 {
6921 errmsg = illegal_char(errbuf, *s);
6922 break;
6923 }
6924 if (*++s != NUL && *s != ',' && *s != ' ')
6925 {
6926 if (s[-1] == 'k' || s[-1] == 's')
6927 {
6928 /* skip optional filename after 'k' and 's' */
6929 while (*s && *s != ',' && *s != ' ')
6930 {
6931 if (*s == '\\')
6932 ++s;
6933 ++s;
6934 }
6935 }
6936 else
6937 {
6938 if (errbuf != NULL)
6939 {
6940 sprintf((char *)errbuf,
6941 _("E535: Illegal character after <%c>"),
6942 *--s);
6943 errmsg = errbuf;
6944 }
6945 else
6946 errmsg = (char_u *)"";
6947 break;
6948 }
6949 }
6950 }
6951 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006952
6953 /* 'completeopt' */
6954 else if (varp == &p_cot)
6955 {
6956 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6957 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02006958 else
6959 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006960 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961#endif /* FEAT_INS_EXPAND */
6962
6963
6964#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6965 else if (varp == &p_toolbar)
6966 {
6967 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6968 &toolbar_flags, TRUE) != OK)
6969 errmsg = e_invarg;
6970 else
6971 {
6972 out_flush();
6973 gui_mch_show_toolbar((toolbar_flags &
6974 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6975 }
6976 }
6977#endif
6978
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006979#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980 /* 'toolbariconsize': GTK+ 2 only */
6981 else if (varp == &p_tbis)
6982 {
6983 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6984 errmsg = e_invarg;
6985 else
6986 {
6987 out_flush();
6988 gui_mch_show_toolbar((toolbar_flags &
6989 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6990 }
6991 }
6992#endif
6993
6994 /* 'pastetoggle': translate key codes like in a mapping */
6995 else if (varp == &p_pt)
6996 {
6997 if (*p_pt)
6998 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006999 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007000 if (p != NULL)
7001 {
7002 if (new_value_alloced)
7003 free_string_option(p_pt);
7004 p_pt = p;
7005 new_value_alloced = TRUE;
7006 }
7007 }
7008 }
7009
7010 /* 'backspace' */
7011 else if (varp == &p_bs)
7012 {
7013 if (VIM_ISDIGIT(*p_bs))
7014 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007015 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007016 errmsg = e_invarg;
7017 }
7018 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7019 errmsg = e_invarg;
7020 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007021 else if (varp == &p_bo)
7022 {
7023 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7024 errmsg = e_invarg;
7025 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007027 /* 'tagcase' */
7028 else if (gvarp == &p_tc)
7029 {
7030 unsigned int *flags;
7031
7032 if (opt_flags & OPT_LOCAL)
7033 {
7034 p = curbuf->b_p_tc;
7035 flags = &curbuf->b_tc_flags;
7036 }
7037 else
7038 {
7039 p = p_tc;
7040 flags = &tc_flags;
7041 }
7042
7043 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7044 /* make the local value empty: use the global value */
7045 *flags = 0;
7046 else if (*p == NUL
7047 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7048 errmsg = e_invarg;
7049 }
7050
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007051#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007052 /* 'casemap' */
7053 else if (varp == &p_cmp)
7054 {
7055 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7056 errmsg = e_invarg;
7057 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007058#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059
7060#ifdef FEAT_DIFF
7061 /* 'diffopt' */
7062 else if (varp == &p_dip)
7063 {
7064 if (diffopt_changed() == FAIL)
7065 errmsg = e_invarg;
7066 }
7067#endif
7068
7069#ifdef FEAT_FOLDING
7070 /* 'foldmethod' */
7071 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7072 {
7073 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7074 || *curwin->w_p_fdm == NUL)
7075 errmsg = e_invarg;
7076 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007077 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007079 if (foldmethodIsDiff(curwin))
7080 newFoldLevel();
7081 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007082 }
7083# ifdef FEAT_EVAL
7084 /* 'foldexpr' */
7085 else if (varp == &curwin->w_p_fde)
7086 {
7087 if (foldmethodIsExpr(curwin))
7088 foldUpdateAll(curwin);
7089 }
7090# endif
7091 /* 'foldmarker' */
7092 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7093 {
7094 p = vim_strchr(*varp, ',');
7095 if (p == NULL)
7096 errmsg = (char_u *)N_("E536: comma required");
7097 else if (p == *varp || p[1] == NUL)
7098 errmsg = e_invarg;
7099 else if (foldmethodIsMarker(curwin))
7100 foldUpdateAll(curwin);
7101 }
7102 /* 'commentstring' */
7103 else if (gvarp == &p_cms)
7104 {
7105 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7106 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7107 }
7108 /* 'foldopen' */
7109 else if (varp == &p_fdo)
7110 {
7111 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7112 errmsg = e_invarg;
7113 }
7114 /* 'foldclose' */
7115 else if (varp == &p_fcl)
7116 {
7117 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7118 errmsg = e_invarg;
7119 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007120 /* 'foldignore' */
7121 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7122 {
7123 if (foldmethodIsIndent(curwin))
7124 foldUpdateAll(curwin);
7125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007126#endif
7127
7128#ifdef FEAT_VIRTUALEDIT
7129 /* 'virtualedit' */
7130 else if (varp == &p_ve)
7131 {
7132 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7133 errmsg = e_invarg;
7134 else if (STRCMP(p_ve, oldval) != 0)
7135 {
7136 /* Recompute cursor position in case the new 've' setting
7137 * changes something. */
7138 validate_virtcol();
7139 coladvance(curwin->w_virtcol);
7140 }
7141 }
7142#endif
7143
7144#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7145 else if (varp == &p_csqf)
7146 {
7147 if (p_csqf != NULL)
7148 {
7149 p = p_csqf;
7150 while (*p != NUL)
7151 {
7152 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7153 || p[1] == NUL
7154 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7155 || (p[2] != NUL && p[2] != ','))
7156 {
7157 errmsg = e_invarg;
7158 break;
7159 }
7160 else if (p[2] == NUL)
7161 break;
7162 else
7163 p += 3;
7164 }
7165 }
7166 }
7167#endif
7168
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007169#ifdef FEAT_CINDENT
7170 /* 'cinoptions' */
7171 else if (gvarp == &p_cino)
7172 {
7173 /* TODO: recognize errors */
7174 parse_cino(curbuf);
7175 }
7176#endif
7177
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007178#if defined(FEAT_RENDER_OPTIONS)
7179 else if (varp == &p_rop && gui.in_use)
7180 {
7181 if (!gui_mch_set_rendering_options(p_rop))
7182 errmsg = e_invarg;
7183 }
7184#endif
7185
Bram Moolenaar071d4272004-06-13 20:20:40 +00007186 /* Options that are a list of flags. */
7187 else
7188 {
7189 p = NULL;
7190 if (varp == &p_ww)
7191 p = (char_u *)WW_ALL;
7192 if (varp == &p_shm)
7193 p = (char_u *)SHM_ALL;
7194 else if (varp == &(p_cpo))
7195 p = (char_u *)CPO_ALL;
7196 else if (varp == &(curbuf->b_p_fo))
7197 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007198#ifdef FEAT_CONCEAL
7199 else if (varp == &curwin->w_p_cocu)
7200 p = (char_u *)COCU_ALL;
7201#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007202 else if (varp == &p_mouse)
7203 {
7204#ifdef FEAT_MOUSE
7205 p = (char_u *)MOUSE_ALL;
7206#else
7207 if (*p_mouse != NUL)
7208 errmsg = (char_u *)N_("E538: No mouse support");
7209#endif
7210 }
7211#if defined(FEAT_GUI)
7212 else if (varp == &p_go)
7213 p = (char_u *)GO_ALL;
7214#endif
7215 if (p != NULL)
7216 {
7217 for (s = *varp; *s; ++s)
7218 if (vim_strchr(p, *s) == NULL)
7219 {
7220 errmsg = illegal_char(errbuf, *s);
7221 break;
7222 }
7223 }
7224 }
7225
7226 /*
7227 * If error detected, restore the previous value.
7228 */
7229 if (errmsg != NULL)
7230 {
7231 if (new_value_alloced)
7232 free_string_option(*varp);
7233 *varp = oldval;
7234 /*
7235 * When resetting some values, need to act on it.
7236 */
7237 if (did_chartab)
7238 (void)init_chartab();
7239 if (varp == &p_hl)
7240 (void)highlight_changed();
7241 }
7242 else
7243 {
7244#ifdef FEAT_EVAL
7245 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007246 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247#endif
7248 /*
7249 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007250 * Use "free_oldval", because recursiveness may change the flags under
7251 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007252 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007253 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007254 free_string_option(oldval);
7255 if (new_value_alloced)
7256 options[opt_idx].flags |= P_ALLOCED;
7257 else
7258 options[opt_idx].flags &= ~P_ALLOCED;
7259
7260 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007261 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007262 {
7263 /* global option with local value set to use global value; free
7264 * the local value and make it empty */
7265 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7266 free_string_option(*(char_u **)p);
7267 *(char_u **)p = empty_option;
7268 }
7269
7270 /* May set global value for local option. */
7271 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7272 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007273
7274#ifdef FEAT_AUTOCMD
7275 /*
7276 * Trigger the autocommand only after setting the flags.
7277 */
7278# ifdef FEAT_SYN_HL
7279 /* When 'syntax' is set, load the syntax of that name */
7280 if (varp == &(curbuf->b_p_syn))
7281 {
7282 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7283 curbuf->b_fname, TRUE, curbuf);
7284 }
7285# endif
7286 else if (varp == &(curbuf->b_p_ft))
7287 {
7288 /* 'filetype' is set, trigger the FileType autocommand */
7289 did_filetype = TRUE;
7290 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7291 curbuf->b_fname, TRUE, curbuf);
7292 }
7293#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007294#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007295 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007296 {
7297 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007298 char_u *q = curwin->w_s->b_p_spl;
7299
7300 /* Skip the first name if it is "cjk". */
7301 if (STRNCMP(q, "cjk,", 4) == 0)
7302 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007303
7304 /*
7305 * Source the spell/LANG.vim in 'runtimepath'.
7306 * They could set 'spellcapcheck' depending on the language.
7307 * Use the first name in 'spelllang' up to '_region' or
7308 * '.encoding'.
7309 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007310 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007311 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7312 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007313 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007314 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007315 }
7316#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317 }
7318
7319#ifdef FEAT_MOUSE
7320 if (varp == &p_mouse)
7321 {
7322# ifdef FEAT_MOUSE_TTY
7323 if (*p_mouse == NUL)
7324 mch_setmouse(FALSE); /* switch mouse off */
7325 else
7326# endif
7327 setmouse(); /* in case 'mouse' changed */
7328 }
7329#endif
7330
Bram Moolenaar913077c2012-03-28 19:59:04 +02007331 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007332 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007333 curwin->w_set_curswant = TRUE;
7334
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007335#ifdef FEAT_GUI
7336 /* check redraw when it's not a GUI option or the GUI is active. */
7337 if (!redraw_gui_only || gui.in_use)
7338#endif
7339 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007340
7341 return errmsg;
7342}
7343
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007344#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007345/*
7346 * Simple int comparison function for use with qsort()
7347 */
7348 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007349int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007350{
7351 return *(const int *)a - *(const int *)b;
7352}
7353
7354/*
7355 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7356 * Returns error message, NULL if it's OK.
7357 */
7358 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007359check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007360{
7361 char_u *s;
7362 int col;
7363 int count = 0;
7364 int color_cols[256];
7365 int i;
7366 int j = 0;
7367
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007368 if (wp->w_buffer == NULL)
7369 return NULL; /* buffer was closed */
7370
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007371 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007372 {
7373 if (*s == '-' || *s == '+')
7374 {
7375 /* -N and +N: add to 'textwidth' */
7376 col = (*s == '-') ? -1 : 1;
7377 ++s;
7378 if (!VIM_ISDIGIT(*s))
7379 return e_invarg;
7380 col = col * getdigits(&s);
7381 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007382 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007383 col += wp->w_buffer->b_p_tw;
7384 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007385 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007386 }
7387 else if (VIM_ISDIGIT(*s))
7388 col = getdigits(&s);
7389 else
7390 return e_invarg;
7391 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007392skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007393 if (*s == NUL)
7394 break;
7395 if (*s != ',')
7396 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007397 if (*++s == NUL)
7398 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007399 }
7400
7401 vim_free(wp->w_p_cc_cols);
7402 if (count == 0)
7403 wp->w_p_cc_cols = NULL;
7404 else
7405 {
7406 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7407 if (wp->w_p_cc_cols != NULL)
7408 {
7409 /* sort the columns for faster usage on screen redraw inside
7410 * win_line() */
7411 qsort(color_cols, count, sizeof(int), int_cmp);
7412
7413 for (i = 0; i < count; ++i)
7414 /* skip duplicates */
7415 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7416 wp->w_p_cc_cols[j++] = color_cols[i];
7417 wp->w_p_cc_cols[j] = -1; /* end marker */
7418 }
7419 }
7420
7421 return NULL; /* no error */
7422}
7423#endif
7424
Bram Moolenaar071d4272004-06-13 20:20:40 +00007425/*
7426 * Handle setting 'listchars' or 'fillchars'.
7427 * Returns error message, NULL if it's OK.
7428 */
7429 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007430set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007431{
7432 int round, i, len, entries;
7433 char_u *p, *s;
7434 int c1, c2 = 0;
7435 struct charstab
7436 {
7437 int *cp;
7438 char *name;
7439 };
7440#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7441 static struct charstab filltab[] =
7442 {
7443 {&fill_stl, "stl"},
7444 {&fill_stlnc, "stlnc"},
7445 {&fill_vert, "vert"},
7446 {&fill_fold, "fold"},
7447 {&fill_diff, "diff"},
7448 };
7449#endif
7450 static struct charstab lcstab[] =
7451 {
7452 {&lcs_eol, "eol"},
7453 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007454 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007455 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007456 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457 {&lcs_tab2, "tab"},
7458 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007459#ifdef FEAT_CONCEAL
7460 {&lcs_conceal, "conceal"},
7461#else
7462 {NULL, "conceal"},
7463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007464 };
7465 struct charstab *tab;
7466
7467#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7468 if (varp == &p_lcs)
7469#endif
7470 {
7471 tab = lcstab;
7472 entries = sizeof(lcstab) / sizeof(struct charstab);
7473 }
7474#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7475 else
7476 {
7477 tab = filltab;
7478 entries = sizeof(filltab) / sizeof(struct charstab);
7479 }
7480#endif
7481
7482 /* first round: check for valid value, second round: assign values */
7483 for (round = 0; round <= 1; ++round)
7484 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007485 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 {
7487 /* After checking that the value is valid: set defaults: space for
7488 * 'fillchars', NUL for 'listchars' */
7489 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007490 if (tab[i].cp != NULL)
7491 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 if (varp == &p_lcs)
7493 lcs_tab1 = NUL;
7494#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7495 else
7496 fill_diff = '-';
7497#endif
7498 }
7499 p = *varp;
7500 while (*p)
7501 {
7502 for (i = 0; i < entries; ++i)
7503 {
7504 len = (int)STRLEN(tab[i].name);
7505 if (STRNCMP(p, tab[i].name, len) == 0
7506 && p[len] == ':'
7507 && p[len + 1] != NUL)
7508 {
7509 s = p + len + 1;
7510#ifdef FEAT_MBYTE
7511 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007512 if (mb_char2cells(c1) > 1)
7513 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514#else
7515 c1 = *s++;
7516#endif
7517 if (tab[i].cp == &lcs_tab2)
7518 {
7519 if (*s == NUL)
7520 continue;
7521#ifdef FEAT_MBYTE
7522 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007523 if (mb_char2cells(c2) > 1)
7524 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525#else
7526 c2 = *s++;
7527#endif
7528 }
7529 if (*s == ',' || *s == NUL)
7530 {
7531 if (round)
7532 {
7533 if (tab[i].cp == &lcs_tab2)
7534 {
7535 lcs_tab1 = c1;
7536 lcs_tab2 = c2;
7537 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007538 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007539 *(tab[i].cp) = c1;
7540
7541 }
7542 p = s;
7543 break;
7544 }
7545 }
7546 }
7547
7548 if (i == entries)
7549 return e_invarg;
7550 if (*p == ',')
7551 ++p;
7552 }
7553 }
7554
7555 return NULL; /* no error */
7556}
7557
7558#ifdef FEAT_STL_OPT
7559/*
7560 * Check validity of options with the 'statusline' format.
7561 * Return error message or NULL.
7562 */
7563 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007564check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007565{
7566 int itemcnt = 0;
7567 int groupdepth = 0;
7568 static char_u errbuf[80];
7569
7570 while (*s && itemcnt < STL_MAX_ITEM)
7571 {
7572 /* Check for valid keys after % sequences */
7573 while (*s && *s != '%')
7574 s++;
7575 if (!*s)
7576 break;
7577 s++;
7578 if (*s != '%' && *s != ')')
7579 ++itemcnt;
7580 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7581 {
7582 s++;
7583 continue;
7584 }
7585 if (*s == ')')
7586 {
7587 s++;
7588 if (--groupdepth < 0)
7589 break;
7590 continue;
7591 }
7592 if (*s == '-')
7593 s++;
7594 while (VIM_ISDIGIT(*s))
7595 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007596 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007597 continue;
7598 if (*s == '.')
7599 {
7600 s++;
7601 while (*s && VIM_ISDIGIT(*s))
7602 s++;
7603 }
7604 if (*s == '(')
7605 {
7606 groupdepth++;
7607 continue;
7608 }
7609 if (vim_strchr(STL_ALL, *s) == NULL)
7610 {
7611 return illegal_char(errbuf, *s);
7612 }
7613 if (*s == '{')
7614 {
7615 s++;
7616 while (*s != '}' && *s)
7617 s++;
7618 if (*s != '}')
7619 return (char_u *)N_("E540: Unclosed expression sequence");
7620 }
7621 }
7622 if (itemcnt >= STL_MAX_ITEM)
7623 return (char_u *)N_("E541: too many items");
7624 if (groupdepth != 0)
7625 return (char_u *)N_("E542: unbalanced groups");
7626 return NULL;
7627}
7628#endif
7629
7630#ifdef FEAT_CLIPBOARD
7631/*
7632 * Extract the items in the 'clipboard' option and set global values.
7633 */
7634 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007635check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007637 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007638 int new_autoselect_star = FALSE;
7639 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007640 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007641 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007642 regprog_T *new_exclude_prog = NULL;
7643 char_u *errmsg = NULL;
7644 char_u *p;
7645
7646 for (p = p_cb; *p != NUL; )
7647 {
7648 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7649 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007650 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007651 p += 7;
7652 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007653 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007654 && (p[11] == ',' || p[11] == NUL))
7655 {
7656 new_unnamed |= CLIP_UNNAMED_PLUS;
7657 p += 11;
7658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007660 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007662 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007663 p += 10;
7664 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007665 else if (STRNCMP(p, "autoselectplus", 14) == 0
7666 && (p[14] == ',' || p[14] == NUL))
7667 {
7668 new_autoselect_plus = TRUE;
7669 p += 14;
7670 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007671 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007672 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007673 {
7674 new_autoselectml = TRUE;
7675 p += 12;
7676 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007677 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7678 {
7679 new_html = TRUE;
7680 p += 4;
7681 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7683 {
7684 p += 8;
7685 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7686 if (new_exclude_prog == NULL)
7687 errmsg = e_invarg;
7688 break;
7689 }
7690 else
7691 {
7692 errmsg = e_invarg;
7693 break;
7694 }
7695 if (*p == ',')
7696 ++p;
7697 }
7698 if (errmsg == NULL)
7699 {
7700 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007701 clip_autoselect_star = new_autoselect_star;
7702 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007703 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007704 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007705 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007707#ifdef FEAT_GUI_GTK
7708 if (gui.in_use)
7709 {
7710 gui_gtk_set_selection_targets();
7711 gui_gtk_set_dnd_targets();
7712 }
7713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007714 }
7715 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007716 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007717
7718 return errmsg;
7719}
7720#endif
7721
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007722#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007723 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007724did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007725{
7726 char_u *errmsg = NULL;
7727 win_T *wp;
7728 int l;
7729
7730 if (is_spellfile)
7731 {
7732 l = (int)STRLEN(curwin->w_s->b_p_spf);
7733 if (l > 0 && (l < 4
7734 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7735 errmsg = e_invarg;
7736 }
7737
7738 if (errmsg == NULL)
7739 {
7740 FOR_ALL_WINDOWS(wp)
7741 if (wp->w_buffer == curbuf && wp->w_p_spell)
7742 {
7743 errmsg = did_set_spelllang(wp);
7744# ifdef FEAT_WINDOWS
7745 break;
7746# endif
7747 }
7748 }
7749 return errmsg;
7750}
7751
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007752/*
7753 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7754 * Return error message when failed, NULL when OK.
7755 */
7756 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007757compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007758{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007759 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007760 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007761
Bram Moolenaar860cae12010-06-05 23:22:07 +02007762 if (*synblock->b_p_spc == NUL)
7763 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007764 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007765 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007766 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007767 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007768 if (re != NULL)
7769 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007770 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007771 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007772 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007773 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007774 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007775 return e_invarg;
7776 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007777 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007778 }
7779
Bram Moolenaar473de612013-06-08 18:19:48 +02007780 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007781 return NULL;
7782}
7783#endif
7784
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007785#if defined(FEAT_EVAL) || defined(PROTO)
7786/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007787 * Set the scriptID for an option, taking care of setting the buffer- or
7788 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007789 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007790 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007791set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007792{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007793 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7794 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007795
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007796 /* Remember where the option was set. For local options need to do that
7797 * in the buffer or window structure. */
7798 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007799 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007800 if (both || (opt_flags & OPT_LOCAL))
7801 {
7802 if (indir & PV_BUF)
7803 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7804 else if (indir & PV_WIN)
7805 curwin->w_p_scriptID[indir & PV_MASK] = id;
7806 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007807}
7808#endif
7809
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810/*
7811 * Set the value of a boolean option, and take care of side effects.
7812 * Returns NULL for success, or an error message for an error.
7813 */
7814 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007815set_bool_option(
7816 int opt_idx, /* index in options[] table */
7817 char_u *varp, /* pointer to the option variable */
7818 int value, /* new value */
7819 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820{
7821 int old_value = *(int *)varp;
7822
Bram Moolenaar071d4272004-06-13 20:20:40 +00007823 /* Disallow changing some options from secure mode */
7824 if ((secure
7825#ifdef HAVE_SANDBOX
7826 || sandbox != 0
7827#endif
7828 ) && (options[opt_idx].flags & P_SECURE))
7829 return e_secure;
7830
7831 *(int *)varp = value; /* set the new value */
7832#ifdef FEAT_EVAL
7833 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007834 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007835#endif
7836
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007837#ifdef FEAT_GUI
7838 need_mouse_correct = TRUE;
7839#endif
7840
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841 /* May set global value for local option. */
7842 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7843 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7844
7845 /*
7846 * Handle side effects of changing a bool option.
7847 */
7848
7849 /* 'compatible' */
7850 if ((int *)varp == &p_cp)
7851 {
7852 compatible_set();
7853 }
7854
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007855#ifdef FEAT_PERSISTENT_UNDO
7856 /* 'undofile' */
7857 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7858 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007859 /* Only take action when the option was set. When reset we do not
7860 * delete the undo file, the option may be set again without making
7861 * any changes in between. */
7862 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007863 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007864 char_u hash[UNDO_HASH_SIZE];
7865 buf_T *save_curbuf = curbuf;
7866
7867 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007868 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007869 /* When 'undofile' is set globally: for every buffer, otherwise
7870 * only for the current buffer: Try to read in the undofile,
7871 * if one exists, the buffer wasn't changed and the buffer was
7872 * loaded */
7873 if ((curbuf == save_curbuf
7874 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7875 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7876 {
7877 u_compute_hash(hash);
7878 u_read_undo(NULL, hash, curbuf->b_fname);
7879 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007880 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007881 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007882 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007883 }
7884#endif
7885
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886 else if ((int *)varp == &curbuf->b_p_ro)
7887 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007888 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7890 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007891
7892 /* when 'readonly' is set may give W10 again */
7893 if (curbuf->b_p_ro)
7894 curbuf->b_did_warn = FALSE;
7895
Bram Moolenaar071d4272004-06-13 20:20:40 +00007896#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007897 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898#endif
7899 }
7900
Bram Moolenaar9c449722010-07-20 18:44:27 +02007901#ifdef FEAT_GUI
7902 else if ((int *)varp == &p_mh)
7903 {
7904 if (!p_mh)
7905 gui_mch_mousehide(FALSE);
7906 }
7907#endif
7908
Bram Moolenaara539df02010-08-01 14:35:05 +02007909#ifdef FEAT_TITLE
7910 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007912 {
7913 redraw_titles();
7914 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 /* when 'endofline' is changed, redraw the window title */
7916 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007917 {
7918 redraw_titles();
7919 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007920 /* when 'fixeol' is changed, redraw the window title */
7921 else if ((int *)varp == &curbuf->b_p_fixeol)
7922 {
7923 redraw_titles();
7924 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007925# ifdef FEAT_MBYTE
7926 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007927 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007928 {
7929 redraw_titles();
7930 }
7931# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007932#endif
7933
7934 /* when 'bin' is set also set some other options */
7935 else if ((int *)varp == &curbuf->b_p_bin)
7936 {
7937 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7938#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007939 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007940#endif
7941 }
7942
7943#ifdef FEAT_AUTOCMD
7944 /* when 'buflisted' changes, trigger autocommands */
7945 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7946 {
7947 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7948 NULL, NULL, TRUE, curbuf);
7949 }
7950#endif
7951
7952 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7953 else if ((int *)varp == &curbuf->b_p_swf)
7954 {
7955 if (curbuf->b_p_swf && p_uc)
7956 ml_open_file(curbuf); /* create the swap file */
7957 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007958 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7959 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007960 mf_close_file(curbuf, TRUE); /* remove the swap file */
7961 }
7962
7963 /* when 'terse' is set change 'shortmess' */
7964 else if ((int *)varp == &p_terse)
7965 {
7966 char_u *p;
7967
7968 p = vim_strchr(p_shm, SHM_SEARCH);
7969
7970 /* insert 's' in p_shm */
7971 if (p_terse && p == NULL)
7972 {
7973 STRCPY(IObuff, p_shm);
7974 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007975 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976 }
7977 /* remove 's' from p_shm */
7978 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007979 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 }
7981
7982 /* when 'paste' is set or reset also change other options */
7983 else if ((int *)varp == &p_paste)
7984 {
7985 paste_option_changed();
7986 }
7987
7988 /* when 'insertmode' is set from an autocommand need to do work here */
7989 else if ((int *)varp == &p_im)
7990 {
7991 if (p_im)
7992 {
7993 if ((State & INSERT) == 0)
7994 need_start_insertmode = TRUE;
7995 stop_insert_mode = FALSE;
7996 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02007997 /* only reset if it was set previously */
7998 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 {
8000 need_start_insertmode = FALSE;
8001 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008002 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003 clear_cmdline = TRUE; /* remove "(insert)" */
8004 restart_edit = 0;
8005 }
8006 }
8007
8008 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8009 else if ((int *)varp == &p_ic && p_hls)
8010 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008011 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008012 }
8013
8014#ifdef FEAT_SEARCH_EXTRA
8015 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8016 else if ((int *)varp == &p_hls)
8017 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008018 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008019 }
8020#endif
8021
8022#ifdef FEAT_SCROLLBIND
8023 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8024 * at the end of normal_cmd() */
8025 else if ((int *)varp == &curwin->w_p_scb)
8026 {
8027 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008028 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008029 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008030 curwin->w_scbind_pos = curwin->w_topline;
8031 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008032 }
8033#endif
8034
8035#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8036 /* There can be only one window with 'previewwindow' set. */
8037 else if ((int *)varp == &curwin->w_p_pvw)
8038 {
8039 if (curwin->w_p_pvw)
8040 {
8041 win_T *win;
8042
8043 for (win = firstwin; win != NULL; win = win->w_next)
8044 if (win->w_p_pvw && win != curwin)
8045 {
8046 curwin->w_p_pvw = FALSE;
8047 return (char_u *)N_("E590: A preview window already exists");
8048 }
8049 }
8050 }
8051#endif
8052
8053 /* when 'textmode' is set or reset also change 'fileformat' */
8054 else if ((int *)varp == &curbuf->b_p_tx)
8055 {
8056 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8057 }
8058
8059 /* when 'textauto' is set or reset also change 'fileformats' */
8060 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008061 set_string_option_direct((char_u *)"ffs", -1,
8062 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008063 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064
8065 /*
8066 * When 'lisp' option changes include/exclude '-' in
8067 * keyword characters.
8068 */
8069#ifdef FEAT_LISP
8070 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8071 {
8072 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8073 }
8074#endif
8075
8076#ifdef FEAT_TITLE
8077 /* when 'title' changed, may need to change the title; same for 'icon' */
8078 else if ((int *)varp == &p_title)
8079 {
8080 did_set_title(FALSE);
8081 }
8082
8083 else if ((int *)varp == &p_icon)
8084 {
8085 did_set_title(TRUE);
8086 }
8087#endif
8088
8089 else if ((int *)varp == &curbuf->b_changed)
8090 {
8091 if (!value)
8092 save_file_ff(curbuf); /* Buffer is unchanged */
8093#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008094 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095#endif
8096#ifdef FEAT_AUTOCMD
8097 modified_was_set = value;
8098#endif
8099 }
8100
8101#ifdef BACKSLASH_IN_FILENAME
8102 else if ((int *)varp == &p_ssl)
8103 {
8104 if (p_ssl)
8105 {
8106 psepc = '/';
8107 psepcN = '\\';
8108 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008109 }
8110 else
8111 {
8112 psepc = '\\';
8113 psepcN = '/';
8114 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115 }
8116
8117 /* need to adjust the file name arguments and buffer names. */
8118 buflist_slash_adjust();
8119 alist_slash_adjust();
8120# ifdef FEAT_EVAL
8121 scriptnames_slash_adjust();
8122# endif
8123 }
8124#endif
8125
8126 /* If 'wrap' is set, set w_leftcol to zero. */
8127 else if ((int *)varp == &curwin->w_p_wrap)
8128 {
8129 if (curwin->w_p_wrap)
8130 curwin->w_leftcol = 0;
8131 }
8132
8133#ifdef FEAT_WINDOWS
8134 else if ((int *)varp == &p_ea)
8135 {
8136 if (p_ea && !old_value)
8137 win_equal(curwin, FALSE, 0);
8138 }
8139#endif
8140
8141 else if ((int *)varp == &p_wiv)
8142 {
8143 /*
8144 * When 'weirdinvert' changed, set/reset 't_xs'.
8145 * Then set 'weirdinvert' according to value of 't_xs'.
8146 */
8147 if (p_wiv && !old_value)
8148 T_XS = (char_u *)"y";
8149 else if (!p_wiv && old_value)
8150 T_XS = empty_option;
8151 p_wiv = (*T_XS != NUL);
8152 }
8153
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008154#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 else if ((int *)varp == &p_beval)
8156 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008157 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008159 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 gui_mch_disable_beval_area(balloonEval);
8161 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008162#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008164#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 else if ((int *)varp == &p_acd)
8166 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008167 /* Change directories when the 'acd' option is set now. */
8168 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 }
8170#endif
8171
8172#ifdef FEAT_DIFF
8173 /* 'diff' */
8174 else if ((int *)varp == &curwin->w_p_diff)
8175 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008176 /* May add or remove the buffer from the list of diff buffers. */
8177 diff_buf_adjust(curwin);
8178# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008179 if (foldmethodIsDiff(curwin))
8180 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008181# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008182 }
8183#endif
8184
8185#ifdef USE_IM_CONTROL
8186 /* 'imdisable' */
8187 else if ((int *)varp == &p_imdisable)
8188 {
8189 /* Only de-activate it here, it will be enabled when changing mode. */
8190 if (p_imdisable)
8191 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008192 else if (State & INSERT)
8193 /* When the option is set from an autocommand, it may need to take
8194 * effect right away. */
8195 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196 }
8197#endif
8198
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008199#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008200 /* 'spell' */
8201 else if ((int *)varp == &curwin->w_p_spell)
8202 {
8203 if (curwin->w_p_spell)
8204 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008205 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008206 if (errmsg != NULL)
8207 EMSG(_(errmsg));
8208 }
8209 }
8210#endif
8211
Bram Moolenaar071d4272004-06-13 20:20:40 +00008212#ifdef FEAT_FKMAP
8213 else if ((int *)varp == &p_altkeymap)
8214 {
8215 if (old_value != p_altkeymap)
8216 {
8217 if (!p_altkeymap)
8218 {
8219 p_hkmap = p_fkmap;
8220 p_fkmap = 0;
8221 }
8222 else
8223 {
8224 p_fkmap = p_hkmap;
8225 p_hkmap = 0;
8226 }
8227 (void)init_chartab();
8228 }
8229 }
8230
8231 /*
8232 * In case some second language keymapping options have changed, check
8233 * and correct the setting in a consistent way.
8234 */
8235
8236 /*
8237 * If hkmap or fkmap are set, reset Arabic keymapping.
8238 */
8239 if ((p_hkmap || p_fkmap) && p_altkeymap)
8240 {
8241 p_altkeymap = p_fkmap;
8242# ifdef FEAT_ARABIC
8243 curwin->w_p_arab = FALSE;
8244# endif
8245 (void)init_chartab();
8246 }
8247
8248 /*
8249 * If hkmap set, reset Farsi keymapping.
8250 */
8251 if (p_hkmap && p_altkeymap)
8252 {
8253 p_altkeymap = 0;
8254 p_fkmap = 0;
8255# ifdef FEAT_ARABIC
8256 curwin->w_p_arab = FALSE;
8257# endif
8258 (void)init_chartab();
8259 }
8260
8261 /*
8262 * If fkmap set, reset Hebrew keymapping.
8263 */
8264 if (p_fkmap && !p_altkeymap)
8265 {
8266 p_altkeymap = 1;
8267 p_hkmap = 0;
8268# ifdef FEAT_ARABIC
8269 curwin->w_p_arab = FALSE;
8270# endif
8271 (void)init_chartab();
8272 }
8273#endif
8274
8275#ifdef FEAT_ARABIC
8276 if ((int *)varp == &curwin->w_p_arab)
8277 {
8278 if (curwin->w_p_arab)
8279 {
8280 /*
8281 * 'arabic' is set, handle various sub-settings.
8282 */
8283 if (!p_tbidi)
8284 {
8285 /* set rightleft mode */
8286 if (!curwin->w_p_rl)
8287 {
8288 curwin->w_p_rl = TRUE;
8289 changed_window_setting();
8290 }
8291
8292 /* Enable Arabic shaping (major part of what Arabic requires) */
8293 if (!p_arshape)
8294 {
8295 p_arshape = TRUE;
8296 redraw_later_clear();
8297 }
8298 }
8299
8300 /* Arabic requires a utf-8 encoding, inform the user if its not
8301 * set. */
8302 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008303 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008304 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8305
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008306 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008307 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8308#ifdef FEAT_EVAL
8309 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8310#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008311 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008312
8313# ifdef FEAT_MBYTE
8314 /* set 'delcombine' */
8315 p_deco = TRUE;
8316# endif
8317
8318# ifdef FEAT_KEYMAP
8319 /* Force-set the necessary keymap for arabic */
8320 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8321 OPT_LOCAL);
8322# endif
8323# ifdef FEAT_FKMAP
8324 p_altkeymap = 0;
8325 p_hkmap = 0;
8326 p_fkmap = 0;
8327 (void)init_chartab();
8328# endif
8329 }
8330 else
8331 {
8332 /*
8333 * 'arabic' is reset, handle various sub-settings.
8334 */
8335 if (!p_tbidi)
8336 {
8337 /* reset rightleft mode */
8338 if (curwin->w_p_rl)
8339 {
8340 curwin->w_p_rl = FALSE;
8341 changed_window_setting();
8342 }
8343
8344 /* 'arabicshape' isn't reset, it is a global option and
8345 * another window may still need it "on". */
8346 }
8347
8348 /* 'delcombine' isn't reset, it is a global option and another
8349 * window may still want it "on". */
8350
8351# ifdef FEAT_KEYMAP
8352 /* Revert to the default keymap */
8353 curbuf->b_p_iminsert = B_IMODE_NONE;
8354 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8355# endif
8356 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008357 }
8358
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008359#endif
8360
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008361#ifdef FEAT_TERMGUICOLORS
8362 /* 'termguicolors' */
8363 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008364 {
8365# ifdef FEAT_GUI
8366 if (!gui.in_use && !gui.starting)
8367# endif
8368 highlight_gui_started();
8369 }
8370#endif
8371
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372 /*
8373 * End of handling side effects for bool options.
8374 */
8375
Bram Moolenaar53744302015-07-17 17:38:22 +02008376 /* after handling side effects, call autocommand */
8377
Bram Moolenaar071d4272004-06-13 20:20:40 +00008378 options[opt_idx].flags |= P_WAS_SET;
8379
Bram Moolenaar53744302015-07-17 17:38:22 +02008380#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8381 if (!starting)
8382 {
8383 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008384 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8385 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8386 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008387 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8388 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8389 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8390 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8391 reset_v_option_vars();
8392 }
8393#endif
8394
Bram Moolenaar071d4272004-06-13 20:20:40 +00008395 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008396 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008397 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008398 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008399 check_redraw(options[opt_idx].flags);
8400
8401 return NULL;
8402}
8403
8404/*
8405 * Set the value of a number option, and take care of side effects.
8406 * Returns NULL for success, or an error message for an error.
8407 */
8408 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008409set_num_option(
8410 int opt_idx, /* index in options[] table */
8411 char_u *varp, /* pointer to the option variable */
8412 long value, /* new value */
8413 char_u *errbuf, /* buffer for error messages */
8414 size_t errbuflen, /* length of "errbuf" */
8415 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 OPT_MODELINE */
8417{
8418 char_u *errmsg = NULL;
8419 long old_value = *(long *)varp;
8420 long old_Rows = Rows; /* remember old Rows */
8421 long old_Columns = Columns; /* remember old Columns */
8422 long *pp = (long *)varp;
8423
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008424 /* Disallow changing some options from secure mode. */
8425 if ((secure
8426#ifdef HAVE_SANDBOX
8427 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008429 ) && (options[opt_idx].flags & P_SECURE))
8430 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431
8432 *pp = value;
8433#ifdef FEAT_EVAL
8434 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008435 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008437#ifdef FEAT_GUI
8438 need_mouse_correct = TRUE;
8439#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440
Bram Moolenaar14f24742012-08-08 18:01:05 +02008441 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008442 {
8443 errmsg = e_positive;
8444 curbuf->b_p_sw = curbuf->b_p_ts;
8445 }
8446
8447 /*
8448 * Number options that need some action when changed
8449 */
8450#ifdef FEAT_WINDOWS
8451 if (pp == &p_wh || pp == &p_hh)
8452 {
8453 if (p_wh < 1)
8454 {
8455 errmsg = e_positive;
8456 p_wh = 1;
8457 }
8458 if (p_wmh > p_wh)
8459 {
8460 errmsg = e_winheight;
8461 p_wh = p_wmh;
8462 }
8463 if (p_hh < 0)
8464 {
8465 errmsg = e_positive;
8466 p_hh = 0;
8467 }
8468
8469 /* Change window height NOW */
8470 if (lastwin != firstwin)
8471 {
8472 if (pp == &p_wh && curwin->w_height < p_wh)
8473 win_setheight((int)p_wh);
8474 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8475 win_setheight((int)p_hh);
8476 }
8477 }
8478
8479 /* 'winminheight' */
8480 else if (pp == &p_wmh)
8481 {
8482 if (p_wmh < 0)
8483 {
8484 errmsg = e_positive;
8485 p_wmh = 0;
8486 }
8487 if (p_wmh > p_wh)
8488 {
8489 errmsg = e_winheight;
8490 p_wmh = p_wh;
8491 }
8492 win_setminheight();
8493 }
8494
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008495# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008496 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008497 {
8498 if (p_wiw < 1)
8499 {
8500 errmsg = e_positive;
8501 p_wiw = 1;
8502 }
8503 if (p_wmw > p_wiw)
8504 {
8505 errmsg = e_winwidth;
8506 p_wiw = p_wmw;
8507 }
8508
8509 /* Change window width NOW */
8510 if (lastwin != firstwin && curwin->w_width < p_wiw)
8511 win_setwidth((int)p_wiw);
8512 }
8513
8514 /* 'winminwidth' */
8515 else if (pp == &p_wmw)
8516 {
8517 if (p_wmw < 0)
8518 {
8519 errmsg = e_positive;
8520 p_wmw = 0;
8521 }
8522 if (p_wmw > p_wiw)
8523 {
8524 errmsg = e_winwidth;
8525 p_wmw = p_wiw;
8526 }
8527 win_setminheight();
8528 }
8529# endif
8530
8531#endif
8532
8533#ifdef FEAT_WINDOWS
8534 /* (re)set last window status line */
8535 else if (pp == &p_ls)
8536 {
8537 last_status(FALSE);
8538 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008539
8540 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008541 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008542 {
8543 shell_new_rows(); /* recompute window positions and heights */
8544 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545#endif
8546
8547#ifdef FEAT_GUI
8548 else if (pp == &p_linespace)
8549 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008550 /* Recompute gui.char_height and resize the Vim window to keep the
8551 * same number of lines. */
8552 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008553 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008554 }
8555#endif
8556
8557#ifdef FEAT_FOLDING
8558 /* 'foldlevel' */
8559 else if (pp == &curwin->w_p_fdl)
8560 {
8561 if (curwin->w_p_fdl < 0)
8562 curwin->w_p_fdl = 0;
8563 newFoldLevel();
8564 }
8565
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008566 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567 else if (pp == &curwin->w_p_fml)
8568 {
8569 foldUpdateAll(curwin);
8570 }
8571
8572 /* 'foldnestmax' */
8573 else if (pp == &curwin->w_p_fdn)
8574 {
8575 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8576 foldUpdateAll(curwin);
8577 }
8578
8579 /* 'foldcolumn' */
8580 else if (pp == &curwin->w_p_fdc)
8581 {
8582 if (curwin->w_p_fdc < 0)
8583 {
8584 errmsg = e_positive;
8585 curwin->w_p_fdc = 0;
8586 }
8587 else if (curwin->w_p_fdc > 12)
8588 {
8589 errmsg = e_invarg;
8590 curwin->w_p_fdc = 12;
8591 }
8592 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008593#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008594
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008595#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596 /* 'shiftwidth' or 'tabstop' */
8597 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8598 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008599# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008600 if (foldmethodIsIndent(curwin))
8601 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008602# endif
8603# ifdef FEAT_CINDENT
8604 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8605 * parse 'cinoptions'. */
8606 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8607 parse_cino(curbuf);
8608# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008609 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008610#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008611
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008612#ifdef FEAT_MBYTE
8613 /* 'maxcombine' */
8614 else if (pp == &p_mco)
8615 {
8616 if (p_mco > MAX_MCO)
8617 p_mco = MAX_MCO;
8618 else if (p_mco < 0)
8619 p_mco = 0;
8620 screenclear(); /* will re-allocate the screen */
8621 }
8622#endif
8623
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624 else if (pp == &curbuf->b_p_iminsert)
8625 {
8626 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8627 {
8628 errmsg = e_invarg;
8629 curbuf->b_p_iminsert = B_IMODE_NONE;
8630 }
8631 p_iminsert = curbuf->b_p_iminsert;
8632 if (termcap_active) /* don't do this in the alternate screen */
8633 showmode();
8634#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8635 /* Show/unshow value of 'keymap' in status lines. */
8636 status_redraw_curbuf();
8637#endif
8638 }
8639
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008640 else if (pp == &p_window)
8641 {
8642 if (p_window < 1)
8643 p_window = 1;
8644 else if (p_window >= Rows)
8645 p_window = Rows - 1;
8646 }
8647
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 else if (pp == &curbuf->b_p_imsearch)
8649 {
8650 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8651 {
8652 errmsg = e_invarg;
8653 curbuf->b_p_imsearch = B_IMODE_NONE;
8654 }
8655 p_imsearch = curbuf->b_p_imsearch;
8656 }
8657
8658#ifdef FEAT_TITLE
8659 /* if 'titlelen' has changed, redraw the title */
8660 else if (pp == &p_titlelen)
8661 {
8662 if (p_titlelen < 0)
8663 {
8664 errmsg = e_positive;
8665 p_titlelen = 85;
8666 }
8667 if (starting != NO_SCREEN && old_value != p_titlelen)
8668 need_maketitle = TRUE;
8669 }
8670#endif
8671
8672 /* if p_ch changed value, change the command line height */
8673 else if (pp == &p_ch)
8674 {
8675 if (p_ch < 1)
8676 {
8677 errmsg = e_positive;
8678 p_ch = 1;
8679 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008680 if (p_ch > Rows - min_rows() + 1)
8681 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682
8683 /* Only compute the new window layout when startup has been
8684 * completed. Otherwise the frame sizes may be wrong. */
8685 if (p_ch != old_value && full_screen
8686#ifdef FEAT_GUI
8687 && !gui.starting
8688#endif
8689 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008690 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691 }
8692
8693 /* when 'updatecount' changes from zero to non-zero, open swap files */
8694 else if (pp == &p_uc)
8695 {
8696 if (p_uc < 0)
8697 {
8698 errmsg = e_positive;
8699 p_uc = 100;
8700 }
8701 if (p_uc && !old_value)
8702 ml_open_files();
8703 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008704#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008705 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008706 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008707 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008708 {
8709 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008710 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008711 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008712 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008713 {
8714 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008715 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008716 }
8717 }
8718#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008719#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008720 else if (pp == &p_mzq)
8721 mzvim_reset_timer();
8722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723
8724 /* sync undo before 'undolevels' changes */
8725 else if (pp == &p_ul)
8726 {
8727 /* use the old value, otherwise u_sync() may not work properly */
8728 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008729 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008730 p_ul = value;
8731 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008732 else if (pp == &curbuf->b_p_ul)
8733 {
8734 /* use the old value, otherwise u_sync() may not work properly */
8735 curbuf->b_p_ul = old_value;
8736 u_sync(TRUE);
8737 curbuf->b_p_ul = value;
8738 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008739
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008740#ifdef FEAT_LINEBREAK
8741 /* 'numberwidth' must be positive */
8742 else if (pp == &curwin->w_p_nuw)
8743 {
8744 if (curwin->w_p_nuw < 1)
8745 {
8746 errmsg = e_positive;
8747 curwin->w_p_nuw = 1;
8748 }
8749 if (curwin->w_p_nuw > 10)
8750 {
8751 errmsg = e_invarg;
8752 curwin->w_p_nuw = 10;
8753 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008754 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008755 }
8756#endif
8757
Bram Moolenaar1a384422010-07-14 19:53:30 +02008758 else if (pp == &curbuf->b_p_tw)
8759 {
8760 if (curbuf->b_p_tw < 0)
8761 {
8762 errmsg = e_positive;
8763 curbuf->b_p_tw = 0;
8764 }
8765#ifdef FEAT_SYN_HL
8766# ifdef FEAT_WINDOWS
8767 {
8768 win_T *wp;
8769 tabpage_T *tp;
8770
8771 FOR_ALL_TAB_WINDOWS(tp, wp)
8772 check_colorcolumn(wp);
8773 }
8774# else
8775 check_colorcolumn(curwin);
8776# endif
8777#endif
8778 }
8779
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 /*
8781 * Check the bounds for numeric options here
8782 */
8783 if (Rows < min_rows() && full_screen)
8784 {
8785 if (errbuf != NULL)
8786 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008787 vim_snprintf((char *)errbuf, errbuflen,
8788 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008789 errmsg = errbuf;
8790 }
8791 Rows = min_rows();
8792 }
8793 if (Columns < MIN_COLUMNS && full_screen)
8794 {
8795 if (errbuf != NULL)
8796 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008797 vim_snprintf((char *)errbuf, errbuflen,
8798 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008799 errmsg = errbuf;
8800 }
8801 Columns = MIN_COLUMNS;
8802 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008803 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804
Bram Moolenaar071d4272004-06-13 20:20:40 +00008805 /*
8806 * If the screen (shell) height has been changed, assume it is the
8807 * physical screenheight.
8808 */
8809 if (old_Rows != Rows || old_Columns != Columns)
8810 {
8811 /* Changing the screen size is not allowed while updating the screen. */
8812 if (updating_screen)
8813 *pp = old_value;
8814 else if (full_screen
8815#ifdef FEAT_GUI
8816 && !gui.starting
8817#endif
8818 )
8819 set_shellsize((int)Columns, (int)Rows, TRUE);
8820 else
8821 {
8822 /* Postpone the resizing; check the size and cmdline position for
8823 * messages. */
8824 check_shellsize();
8825 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8826 cmdline_row = Rows - p_ch;
8827 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008828 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008829 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830 }
8831
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832 if (curbuf->b_p_ts <= 0)
8833 {
8834 errmsg = e_positive;
8835 curbuf->b_p_ts = 8;
8836 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 if (p_tm < 0)
8838 {
8839 errmsg = e_positive;
8840 p_tm = 0;
8841 }
8842 if ((curwin->w_p_scr <= 0
8843 || (curwin->w_p_scr > curwin->w_height
8844 && curwin->w_height > 0))
8845 && full_screen)
8846 {
8847 if (pp == &(curwin->w_p_scr))
8848 {
8849 if (curwin->w_p_scr != 0)
8850 errmsg = e_scroll;
8851 win_comp_scroll(curwin);
8852 }
8853 /* If 'scroll' became invalid because of a side effect silently adjust
8854 * it. */
8855 else if (curwin->w_p_scr <= 0)
8856 curwin->w_p_scr = 1;
8857 else /* curwin->w_p_scr > curwin->w_height */
8858 curwin->w_p_scr = curwin->w_height;
8859 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008860 if (p_hi < 0)
8861 {
8862 errmsg = e_positive;
8863 p_hi = 0;
8864 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008865 else if (p_hi > 10000)
8866 {
8867 errmsg = e_invarg;
8868 p_hi = 10000;
8869 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008870 if (p_re < 0 || p_re > 2)
8871 {
8872 errmsg = e_invarg;
8873 p_re = 0;
8874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008875 if (p_report < 0)
8876 {
8877 errmsg = e_positive;
8878 p_report = 1;
8879 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008880 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 {
8882 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8883 p_sj = Rows / 2;
8884 else
8885 {
8886 errmsg = e_scroll;
8887 p_sj = 1;
8888 }
8889 }
8890 if (p_so < 0 && full_screen)
8891 {
8892 errmsg = e_scroll;
8893 p_so = 0;
8894 }
8895 if (p_siso < 0 && full_screen)
8896 {
8897 errmsg = e_positive;
8898 p_siso = 0;
8899 }
8900#ifdef FEAT_CMDWIN
8901 if (p_cwh < 1)
8902 {
8903 errmsg = e_positive;
8904 p_cwh = 1;
8905 }
8906#endif
8907 if (p_ut < 0)
8908 {
8909 errmsg = e_positive;
8910 p_ut = 2000;
8911 }
8912 if (p_ss < 0)
8913 {
8914 errmsg = e_positive;
8915 p_ss = 0;
8916 }
8917
8918 /* May set global value for local option. */
8919 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8920 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8921
8922 options[opt_idx].flags |= P_WAS_SET;
8923
Bram Moolenaar53744302015-07-17 17:38:22 +02008924#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8925 if (!starting && errmsg == NULL)
8926 {
8927 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008928 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8929 vim_snprintf((char *)buf_new, 10, "%ld", value);
8930 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008931 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8932 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8933 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8934 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8935 reset_v_option_vars();
8936 }
8937#endif
8938
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008940 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008941 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008942 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008943 check_redraw(options[opt_idx].flags);
8944
8945 return errmsg;
8946}
8947
8948/*
8949 * Called after an option changed: check if something needs to be redrawn.
8950 */
8951 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008952check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008953{
8954 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008955 int doclear = (flags & P_RCLR) == P_RCLR;
8956 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008957
8958#ifdef FEAT_WINDOWS
8959 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8960 status_redraw_all();
8961#endif
8962
8963 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8964 changed_window_setting();
8965 if (flags & P_RBUF)
8966 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008967 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008968 redraw_all_later(CLEAR);
8969 else if (all)
8970 redraw_all_later(NOT_VALID);
8971}
8972
8973/*
8974 * Find index for option 'arg'.
8975 * Return -1 if not found.
8976 */
8977 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008978findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008979{
8980 int opt_idx;
8981 char *s, *p;
8982 static short quick_tab[27] = {0, 0}; /* quick access table */
8983 int is_term_opt;
8984
8985 /*
8986 * For first call: Initialize the quick-access table.
8987 * It contains the index for the first option that starts with a certain
8988 * letter. There are 26 letters, plus the first "t_" option.
8989 */
8990 if (quick_tab[1] == 0)
8991 {
8992 p = options[0].fullname;
8993 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8994 {
8995 if (s[0] != p[0])
8996 {
8997 if (s[0] == 't' && s[1] == '_')
8998 quick_tab[26] = opt_idx;
8999 else
9000 quick_tab[CharOrdLow(s[0])] = opt_idx;
9001 }
9002 p = s;
9003 }
9004 }
9005
9006 /*
9007 * Check for name starting with an illegal character.
9008 */
9009#ifdef EBCDIC
9010 if (!islower(arg[0]))
9011#else
9012 if (arg[0] < 'a' || arg[0] > 'z')
9013#endif
9014 return -1;
9015
9016 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9017 if (is_term_opt)
9018 opt_idx = quick_tab[26];
9019 else
9020 opt_idx = quick_tab[CharOrdLow(arg[0])];
9021 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9022 {
9023 if (STRCMP(arg, s) == 0) /* match full name */
9024 break;
9025 }
9026 if (s == NULL && !is_term_opt)
9027 {
9028 opt_idx = quick_tab[CharOrdLow(arg[0])];
9029 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9030 {
9031 s = options[opt_idx].shortname;
9032 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9033 break;
9034 s = NULL;
9035 }
9036 }
9037 if (s == NULL)
9038 opt_idx = -1;
9039 return opt_idx;
9040}
9041
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009042#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009043/*
9044 * Get the value for an option.
9045 *
9046 * Returns:
9047 * Number or Toggle option: 1, *numval gets value.
9048 * String option: 0, *stringval gets allocated string.
9049 * Hidden Number or Toggle option: -1.
9050 * hidden String option: -2.
9051 * unknown option: -3.
9052 */
9053 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009054get_option_value(
9055 char_u *name,
9056 long *numval,
9057 char_u **stringval, /* NULL when only checking existence */
9058 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059{
9060 int opt_idx;
9061 char_u *varp;
9062
9063 opt_idx = findoption(name);
9064 if (opt_idx < 0) /* unknown option */
9065 return -3;
9066
9067 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9068
9069 if (options[opt_idx].flags & P_STRING)
9070 {
9071 if (varp == NULL) /* hidden option */
9072 return -2;
9073 if (stringval != NULL)
9074 {
9075#ifdef FEAT_CRYPT
9076 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009077 if ((char_u **)varp == &curbuf->b_p_key
9078 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009079 *stringval = vim_strsave((char_u *)"*****");
9080 else
9081#endif
9082 *stringval = vim_strsave(*(char_u **)(varp));
9083 }
9084 return 0;
9085 }
9086
9087 if (varp == NULL) /* hidden option */
9088 return -1;
9089 if (options[opt_idx].flags & P_NUM)
9090 *numval = *(long *)varp;
9091 else
9092 {
9093 /* Special case: 'modified' is b_changed, but we also want to consider
9094 * it set when 'ff' or 'fenc' changed. */
9095 if ((int *)varp == &curbuf->b_changed)
9096 *numval = curbufIsChanged();
9097 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009098 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009099 }
9100 return 1;
9101}
9102#endif
9103
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009104#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009105/*
9106 * Returns the option attributes and its value. Unlike the above function it
9107 * will return either global value or local value of the option depending on
9108 * what was requested, but it will never return global value if it was
9109 * requested to return local one and vice versa. Neither it will return
9110 * buffer-local value if it was requested to return window-local one.
9111 *
9112 * Pretends that option is absent if it is not present in the requested scope
9113 * (i.e. has no global, window-local or buffer-local value depending on
9114 * opt_type). Uses
9115 *
9116 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009117 * 0 hidden or unknown option, also option that does not have requested
9118 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009119 * see SOPT_* in vim.h for other flags
9120 *
9121 * Possible opt_type values: see SREQ_* in vim.h
9122 */
9123 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009124get_option_value_strict(
9125 char_u *name,
9126 long *numval,
9127 char_u **stringval, /* NULL when only obtaining attributes */
9128 int opt_type,
9129 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009130{
9131 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009132 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009133 struct vimoption *p;
9134 int r = 0;
9135
9136 opt_idx = findoption(name);
9137 if (opt_idx < 0)
9138 return 0;
9139
9140 p = &(options[opt_idx]);
9141
9142 /* Hidden option */
9143 if (p->var == NULL)
9144 return 0;
9145
9146 if (p->flags & P_BOOL)
9147 r |= SOPT_BOOL;
9148 else if (p->flags & P_NUM)
9149 r |= SOPT_NUM;
9150 else if (p->flags & P_STRING)
9151 r |= SOPT_STRING;
9152
9153 if (p->indir == PV_NONE)
9154 {
9155 if (opt_type == SREQ_GLOBAL)
9156 r |= SOPT_GLOBAL;
9157 else
9158 return 0; /* Did not request global-only option */
9159 }
9160 else
9161 {
9162 if (p->indir & PV_BOTH)
9163 r |= SOPT_GLOBAL;
9164 else if (opt_type == SREQ_GLOBAL)
9165 return 0; /* Requested global option */
9166
9167 if (p->indir & PV_WIN)
9168 {
9169 if (opt_type == SREQ_BUF)
9170 return 0; /* Did not request window-local option */
9171 else
9172 r |= SOPT_WIN;
9173 }
9174 else if (p->indir & PV_BUF)
9175 {
9176 if (opt_type == SREQ_WIN)
9177 return 0; /* Did not request buffer-local option */
9178 else
9179 r |= SOPT_BUF;
9180 }
9181 }
9182
9183 if (stringval == NULL)
9184 return r;
9185
9186 if (opt_type == SREQ_GLOBAL)
9187 varp = p->var;
9188 else
9189 {
9190 if (opt_type == SREQ_BUF)
9191 {
9192 /* Special case: 'modified' is b_changed, but we also want to
9193 * consider it set when 'ff' or 'fenc' changed. */
9194 if (p->indir == PV_MOD)
9195 {
9196 *numval = bufIsChanged((buf_T *) from);
9197 varp = NULL;
9198 }
9199#ifdef FEAT_CRYPT
9200 else if (p->indir == PV_KEY)
9201 {
9202 /* never return the value of the crypt key */
9203 *stringval = NULL;
9204 varp = NULL;
9205 }
9206#endif
9207 else
9208 {
9209 aco_save_T aco;
9210 aucmd_prepbuf(&aco, (buf_T *) from);
9211 varp = get_varp(p);
9212 aucmd_restbuf(&aco);
9213 }
9214 }
9215 else if (opt_type == SREQ_WIN)
9216 {
9217 win_T *save_curwin;
9218 save_curwin = curwin;
9219 curwin = (win_T *) from;
9220 curbuf = curwin->w_buffer;
9221 varp = get_varp(p);
9222 curwin = save_curwin;
9223 curbuf = curwin->w_buffer;
9224 }
9225 if (varp == p->var)
9226 return (r | SOPT_UNSET);
9227 }
9228
9229 if (varp != NULL)
9230 {
9231 if (p->flags & P_STRING)
9232 *stringval = vim_strsave(*(char_u **)(varp));
9233 else if (p->flags & P_NUM)
9234 *numval = *(long *) varp;
9235 else
9236 *numval = *(int *)varp;
9237 }
9238
9239 return r;
9240}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009241
9242/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009243 * Iterate over options. First argument is a pointer to a pointer to a
9244 * structure inside options[] array, second is option type like in the above
9245 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009246 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009247 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009248 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009249 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009250 * first argument to NULL.
9251 *
9252 * Returns full option name for current option on each call.
9253 */
9254 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009255option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009256{
9257 struct vimoption *ret = NULL;
9258 do
9259 {
9260 if (*option == NULL)
9261 *option = (void *) options;
9262 else if (((struct vimoption *) (*option))->fullname == NULL)
9263 {
9264 *option = NULL;
9265 return NULL;
9266 }
9267 else
9268 *option = (void *) (((struct vimoption *) (*option)) + 1);
9269
9270 ret = ((struct vimoption *) (*option));
9271
9272 /* Hidden option */
9273 if (ret->var == NULL)
9274 {
9275 ret = NULL;
9276 continue;
9277 }
9278
9279 switch (opt_type)
9280 {
9281 case SREQ_GLOBAL:
9282 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9283 ret = NULL;
9284 break;
9285 case SREQ_BUF:
9286 if (!(ret->indir & PV_BUF))
9287 ret = NULL;
9288 break;
9289 case SREQ_WIN:
9290 if (!(ret->indir & PV_WIN))
9291 ret = NULL;
9292 break;
9293 default:
9294 EMSG2(_(e_intern2), "option_iter_next()");
9295 return NULL;
9296 }
9297 }
9298 while (ret == NULL);
9299
9300 return (char_u *)ret->fullname;
9301}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009302#endif
9303
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304/*
9305 * Set the value of option "name".
9306 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009307 *
9308 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009309 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009310 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009311set_option_value(
9312 char_u *name,
9313 long number,
9314 char_u *string,
9315 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009316{
9317 int opt_idx;
9318 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009319 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009320
9321 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009322 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009323 EMSG2(_("E355: Unknown option: %s"), name);
9324 else
9325 {
9326 flags = options[opt_idx].flags;
9327#ifdef HAVE_SANDBOX
9328 /* Disallow changing some options in the sandbox */
9329 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009330 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009332 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009333 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009335 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009336 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337 else
9338 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009339 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009340 if (varp != NULL) /* hidden option is not changed */
9341 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009342 if (number == 0 && string != NULL)
9343 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009344 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009345
9346 /* Either we are given a string or we are setting option
9347 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009348 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009349 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009350 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009351 {
9352 /* There's another character after zeros or the string
9353 * is empty. In both cases, we are trying to set a
9354 * num option using a string. */
9355 EMSG3(_("E521: Number required: &%s = '%s'"),
9356 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009357 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009358
9359 }
9360 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009362 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009363 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009365 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009366 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367 }
9368 }
9369 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009370 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009371}
9372
9373/*
9374 * Get the terminal code for a terminal option.
9375 * Returns NULL when not found.
9376 */
9377 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009378get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379{
9380 int opt_idx;
9381 char_u *varp;
9382
9383 if (tname[0] != 't' || tname[1] != '_' ||
9384 tname[2] == NUL || tname[3] == NUL)
9385 return NULL;
9386 if ((opt_idx = findoption(tname)) >= 0)
9387 {
9388 varp = get_varp(&(options[opt_idx]));
9389 if (varp != NULL)
9390 varp = *(char_u **)(varp);
9391 return varp;
9392 }
9393 return find_termcode(tname + 2);
9394}
9395
9396 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009397get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009398{
9399 int i;
9400
9401 i = findoption((char_u *)"hl");
9402 if (i >= 0)
9403 return options[i].def_val[VI_DEFAULT];
9404 return (char_u *)NULL;
9405}
9406
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009407#if defined(FEAT_MBYTE) || defined(PROTO)
9408 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009409get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009410{
9411 int i;
9412
9413 i = findoption((char_u *)"enc");
9414 if (i >= 0)
9415 return options[i].def_val[VI_DEFAULT];
9416 return (char_u *)NULL;
9417}
9418#endif
9419
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420/*
9421 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9422 */
9423 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009424find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425{
9426 int key;
9427 int modifiers;
9428
9429 /*
9430 * Don't use get_special_key_code() for t_xx, we don't want it to call
9431 * add_termcap_entry().
9432 */
9433 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9434 key = TERMCAP2KEY(arg[2], arg[3]);
9435 else
9436 {
9437 --arg; /* put arg at the '<' */
9438 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009439 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009440 if (modifiers) /* can't handle modifiers here */
9441 key = 0;
9442 }
9443 return key;
9444}
9445
9446/*
9447 * if 'all' == 0: show changed options
9448 * if 'all' == 1: show all normal options
9449 * if 'all' == 2: show all terminal options
9450 */
9451 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009452showoptions(
9453 int all,
9454 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009455{
9456 struct vimoption *p;
9457 int col;
9458 int isterm;
9459 char_u *varp;
9460 struct vimoption **items;
9461 int item_count;
9462 int run;
9463 int row, rows;
9464 int cols;
9465 int i;
9466 int len;
9467
9468#define INC 20
9469#define GAP 3
9470
9471 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9472 PARAM_COUNT));
9473 if (items == NULL)
9474 return;
9475
9476 /* Highlight title */
9477 if (all == 2)
9478 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9479 else if (opt_flags & OPT_GLOBAL)
9480 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9481 else if (opt_flags & OPT_LOCAL)
9482 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9483 else
9484 MSG_PUTS_TITLE(_("\n--- Options ---"));
9485
9486 /*
9487 * do the loop two times:
9488 * 1. display the short items
9489 * 2. display the long items (only strings and numbers)
9490 */
9491 for (run = 1; run <= 2 && !got_int; ++run)
9492 {
9493 /*
9494 * collect the items in items[]
9495 */
9496 item_count = 0;
9497 for (p = &options[0]; p->fullname != NULL; p++)
9498 {
9499 varp = NULL;
9500 isterm = istermoption(p);
9501 if (opt_flags != 0)
9502 {
9503 if (p->indir != PV_NONE && !isterm)
9504 varp = get_varp_scope(p, opt_flags);
9505 }
9506 else
9507 varp = get_varp(p);
9508 if (varp != NULL
9509 && ((all == 2 && isterm)
9510 || (all == 1 && !isterm)
9511 || (all == 0 && !optval_default(p, varp))))
9512 {
9513 if (p->flags & P_BOOL)
9514 len = 1; /* a toggle option fits always */
9515 else
9516 {
9517 option_value2string(p, opt_flags);
9518 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9519 }
9520 if ((len <= INC - GAP && run == 1) ||
9521 (len > INC - GAP && run == 2))
9522 items[item_count++] = p;
9523 }
9524 }
9525
9526 /*
9527 * display the items
9528 */
9529 if (run == 1)
9530 {
9531 cols = (Columns + GAP - 3) / INC;
9532 if (cols == 0)
9533 cols = 1;
9534 rows = (item_count + cols - 1) / cols;
9535 }
9536 else /* run == 2 */
9537 rows = item_count;
9538 for (row = 0; row < rows && !got_int; ++row)
9539 {
9540 msg_putchar('\n'); /* go to next line */
9541 if (got_int) /* 'q' typed in more */
9542 break;
9543 col = 0;
9544 for (i = row; i < item_count; i += rows)
9545 {
9546 msg_col = col; /* make columns */
9547 showoneopt(items[i], opt_flags);
9548 col += INC;
9549 }
9550 out_flush();
9551 ui_breakcheck();
9552 }
9553 }
9554 vim_free(items);
9555}
9556
9557/*
9558 * Return TRUE if option "p" has its default value.
9559 */
9560 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009561optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009562{
9563 int dvi;
9564
9565 if (varp == NULL)
9566 return TRUE; /* hidden option is always at default */
9567 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9568 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009569 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009570 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009571 /* the cast to long is required for Manx C, long_i is
9572 * needed for MSVC */
9573 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009574 /* P_STRING */
9575 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9576}
9577
9578/*
9579 * showoneopt: show the value of one option
9580 * must not be called with a hidden option!
9581 */
9582 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009583showoneopt(
9584 struct vimoption *p,
9585 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009586{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009587 char_u *varp;
9588 int save_silent = silent_mode;
9589
9590 silent_mode = FALSE;
9591 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592
9593 varp = get_varp_scope(p, opt_flags);
9594
9595 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9596 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9597 ? !curbufIsChanged() : !*(int *)varp))
9598 MSG_PUTS("no");
9599 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9600 MSG_PUTS("--");
9601 else
9602 MSG_PUTS(" ");
9603 MSG_PUTS(p->fullname);
9604 if (!(p->flags & P_BOOL))
9605 {
9606 msg_putchar('=');
9607 /* put value string in NameBuff */
9608 option_value2string(p, opt_flags);
9609 msg_outtrans(NameBuff);
9610 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009611
9612 silent_mode = save_silent;
9613 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009614}
9615
9616/*
9617 * Write modified options as ":set" commands to a file.
9618 *
9619 * There are three values for "opt_flags":
9620 * OPT_GLOBAL: Write global option values and fresh values of
9621 * buffer-local options (used for start of a session
9622 * file).
9623 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9624 * curwin (used for a vimrc file).
9625 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9626 * and local values for window-local options of
9627 * curwin. Local values are also written when at the
9628 * default value, because a modeline or autocommand
9629 * may have set them when doing ":edit file" and the
9630 * user has set them back at the default or fresh
9631 * value.
9632 * When "local_only" is TRUE, don't write fresh
9633 * values, only local values (for ":mkview").
9634 * (fresh value = value used for a new buffer or window for a local option).
9635 *
9636 * Return FAIL on error, OK otherwise.
9637 */
9638 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009639makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009640{
9641 struct vimoption *p;
9642 char_u *varp; /* currently used value */
9643 char_u *varp_fresh; /* local value */
9644 char_u *varp_local = NULL; /* fresh value */
9645 char *cmd;
9646 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009647 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009648
9649 /*
9650 * The options that don't have a default (terminal name, columns, lines)
9651 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009652 * Do the loop over "options[]" twice: once for options with the
9653 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009655 for (pri = 1; pri >= 0; --pri)
9656 {
9657 for (p = &options[0]; !istermoption(p); p++)
9658 if (!(p->flags & P_NO_MKRC)
9659 && !istermoption(p)
9660 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009661 {
9662 /* skip global option when only doing locals */
9663 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9664 continue;
9665
9666 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9667 * file, they are always buffer-specific. */
9668 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9669 continue;
9670
9671 /* Global values are only written when not at the default value. */
9672 varp = get_varp_scope(p, opt_flags);
9673 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9674 continue;
9675
9676 round = 2;
9677 if (p->indir != PV_NONE)
9678 {
9679 if (p->var == VAR_WIN)
9680 {
9681 /* skip window-local option when only doing globals */
9682 if (!(opt_flags & OPT_LOCAL))
9683 continue;
9684 /* When fresh value of window-local option is not at the
9685 * default, need to write it too. */
9686 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9687 {
9688 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9689 if (!optval_default(p, varp_fresh))
9690 {
9691 round = 1;
9692 varp_local = varp;
9693 varp = varp_fresh;
9694 }
9695 }
9696 }
9697 }
9698
9699 /* Round 1: fresh value for window-local options.
9700 * Round 2: other values */
9701 for ( ; round <= 2; varp = varp_local, ++round)
9702 {
9703 if (round == 1 || (opt_flags & OPT_GLOBAL))
9704 cmd = "set";
9705 else
9706 cmd = "setlocal";
9707
9708 if (p->flags & P_BOOL)
9709 {
9710 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9711 return FAIL;
9712 }
9713 else if (p->flags & P_NUM)
9714 {
9715 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9716 return FAIL;
9717 }
9718 else /* P_STRING */
9719 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009720#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9721 int do_endif = FALSE;
9722
Bram Moolenaar071d4272004-06-13 20:20:40 +00009723 /* Don't set 'syntax' and 'filetype' again if the value is
9724 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009725 if (
9726# if defined(FEAT_SYN_HL)
9727 p->indir == PV_SYN
9728# if defined(FEAT_AUTOCMD)
9729 ||
9730# endif
9731# endif
9732# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009733 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009734# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009735 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009736 {
9737 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9738 *(char_u **)(varp)) < 0
9739 || put_eol(fd) < 0)
9740 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009741 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009743#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009744 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9745 (p->flags & P_EXPAND) != 0) == FAIL)
9746 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009747#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9748 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749 {
9750 if (put_line(fd, "endif") == FAIL)
9751 return FAIL;
9752 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009753#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009754 }
9755 }
9756 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009757 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758 return OK;
9759}
9760
9761#if defined(FEAT_FOLDING) || defined(PROTO)
9762/*
9763 * Generate set commands for the local fold options only. Used when
9764 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9765 */
9766 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009767makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768{
9769 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9770# ifdef FEAT_EVAL
9771 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9772 == FAIL
9773# endif
9774 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9775 == FAIL
9776 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9777 == FAIL
9778 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9779 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9780 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9781 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9782 )
9783 return FAIL;
9784
9785 return OK;
9786}
9787#endif
9788
9789 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009790put_setstring(
9791 FILE *fd,
9792 char *cmd,
9793 char *name,
9794 char_u **valuep,
9795 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009796{
9797 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009798 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009799
9800 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9801 return FAIL;
9802 if (*valuep != NULL)
9803 {
9804 /* Output 'pastetoggle' as key names. For other
9805 * options some characters have to be escaped with
9806 * CTRL-V or backslash */
9807 if (valuep == &p_pt)
9808 {
9809 s = *valuep;
9810 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009811 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009812 return FAIL;
9813 }
9814 else if (expand)
9815 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009816 buf = alloc(MAXPATHL);
9817 if (buf == NULL)
9818 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009819 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9820 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009821 {
9822 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009823 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009824 }
9825 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009826 }
9827 else if (put_escstr(fd, *valuep, 2) == FAIL)
9828 return FAIL;
9829 }
9830 if (put_eol(fd) < 0)
9831 return FAIL;
9832 return OK;
9833}
9834
9835 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009836put_setnum(
9837 FILE *fd,
9838 char *cmd,
9839 char *name,
9840 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009841{
9842 long wc;
9843
9844 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9845 return FAIL;
9846 if (wc_use_keyname((char_u *)valuep, &wc))
9847 {
9848 /* print 'wildchar' and 'wildcharm' as a key name */
9849 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9850 return FAIL;
9851 }
9852 else if (fprintf(fd, "%ld", *valuep) < 0)
9853 return FAIL;
9854 if (put_eol(fd) < 0)
9855 return FAIL;
9856 return OK;
9857}
9858
9859 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009860put_setbool(
9861 FILE *fd,
9862 char *cmd,
9863 char *name,
9864 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865{
Bram Moolenaar893de922007-10-02 18:40:57 +00009866 if (value < 0) /* global/local option using global value */
9867 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009868 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9869 || put_eol(fd) < 0)
9870 return FAIL;
9871 return OK;
9872}
9873
9874/*
9875 * Clear all the terminal options.
9876 * If the option has been allocated, free the memory.
9877 * Terminal options are never hidden or indirect.
9878 */
9879 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009880clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009881{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009882 /*
9883 * Reset a few things before clearing the old options. This may cause
9884 * outputting a few things that the terminal doesn't understand, but the
9885 * screen will be cleared later, so this is OK.
9886 */
9887#ifdef FEAT_MOUSE_TTY
9888 mch_setmouse(FALSE); /* switch mouse off */
9889#endif
9890#ifdef FEAT_TITLE
9891 mch_restore_title(3); /* restore window titles */
9892#endif
9893#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9894 /* When starting the GUI close the display opened for the clipboard.
9895 * After restoring the title, because that will need the display. */
9896 if (gui.starting)
9897 clear_xterm_clip();
9898#endif
9899#ifdef WIN3264
9900 /*
9901 * Check if this is allowed now.
9902 */
9903 if (can_end_termcap_mode(FALSE) == TRUE)
9904#endif
9905 stoptermcap(); /* stop termcap mode */
9906
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009907 free_termoptions();
9908}
9909
9910 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009911free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009912{
9913 struct vimoption *p;
9914
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915 for (p = &options[0]; p->fullname != NULL; p++)
9916 if (istermoption(p))
9917 {
9918 if (p->flags & P_ALLOCED)
9919 free_string_option(*(char_u **)(p->var));
9920 if (p->flags & P_DEF_ALLOCED)
9921 free_string_option(p->def_val[VI_DEFAULT]);
9922 *(char_u **)(p->var) = empty_option;
9923 p->def_val[VI_DEFAULT] = empty_option;
9924 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9925 }
9926 clear_termcodes();
9927}
9928
9929/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009930 * Free the string for one term option, if it was allocated.
9931 * Set the string to empty_option and clear allocated flag.
9932 * "var" points to the option value.
9933 */
9934 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009935free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009936{
9937 struct vimoption *p;
9938
9939 for (p = &options[0]; p->fullname != NULL; p++)
9940 if (p->var == var)
9941 {
9942 if (p->flags & P_ALLOCED)
9943 free_string_option(*(char_u **)(p->var));
9944 *(char_u **)(p->var) = empty_option;
9945 p->flags &= ~P_ALLOCED;
9946 break;
9947 }
9948}
9949
9950/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009951 * Set the terminal option defaults to the current value.
9952 * Used after setting the terminal name.
9953 */
9954 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009955set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009956{
9957 struct vimoption *p;
9958
9959 for (p = &options[0]; p->fullname != NULL; p++)
9960 {
9961 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9962 {
9963 if (p->flags & P_DEF_ALLOCED)
9964 {
9965 free_string_option(p->def_val[VI_DEFAULT]);
9966 p->flags &= ~P_DEF_ALLOCED;
9967 }
9968 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9969 if (p->flags & P_ALLOCED)
9970 {
9971 p->flags |= P_DEF_ALLOCED;
9972 p->flags &= ~P_ALLOCED; /* don't free the value now */
9973 }
9974 }
9975 }
9976}
9977
9978/*
9979 * return TRUE if 'p' starts with 't_'
9980 */
9981 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009982istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983{
9984 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9985}
9986
9987/*
9988 * Compute columns for ruler and shown command. 'sc_col' is also used to
9989 * decide what the maximum length of a message on the status line can be.
9990 * If there is a status line for the last window, 'sc_col' is independent
9991 * of 'ru_col'.
9992 */
9993
9994#define COL_RULER 17 /* columns needed by standard ruler */
9995
9996 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009997comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998{
9999#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10000 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10001
10002 sc_col = 0;
10003 ru_col = 0;
10004 if (p_ru)
10005 {
10006#ifdef FEAT_STL_OPT
10007 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10008#else
10009 ru_col = COL_RULER + 1;
10010#endif
10011 /* no last status line, adjust sc_col */
10012 if (!last_has_status)
10013 sc_col = ru_col;
10014 }
10015 if (p_sc)
10016 {
10017 sc_col += SHOWCMD_COLS;
10018 if (!p_ru || last_has_status) /* no need for separating space */
10019 ++sc_col;
10020 }
10021 sc_col = Columns - sc_col;
10022 ru_col = Columns - ru_col;
10023 if (sc_col <= 0) /* screen too narrow, will become a mess */
10024 sc_col = 1;
10025 if (ru_col <= 0)
10026 ru_col = 1;
10027#else
10028 sc_col = Columns;
10029 ru_col = Columns;
10030#endif
10031}
10032
10033/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010034 * Unset local option value, similar to ":set opt<".
10035 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010036 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010037unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010038{
10039 struct vimoption *p;
10040 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010041 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010042
10043 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010044 if (opt_idx < 0)
10045 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010046 p = &(options[opt_idx]);
10047
10048 switch ((int)p->indir)
10049 {
10050 /* global option with local value: use local value if it's been set */
10051 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010052 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010053 break;
10054 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010055 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010056 break;
10057 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010058 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010059 break;
10060 case PV_AR:
10061 buf->b_p_ar = -1;
10062 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010063 case PV_BKC:
10064 clear_string_option(&buf->b_p_bkc);
10065 buf->b_bkc_flags = 0;
10066 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010067 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010068 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010069 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010070 case PV_TC:
10071 clear_string_option(&buf->b_p_tc);
10072 buf->b_tc_flags = 0;
10073 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010074#ifdef FEAT_FIND_ID
10075 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010076 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010077 break;
10078 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010079 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080 break;
10081#endif
10082#ifdef FEAT_INS_EXPAND
10083 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010084 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010085 break;
10086 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010087 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010088 break;
10089#endif
10090#ifdef FEAT_QUICKFIX
10091 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010092 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010093 break;
10094 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010095 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010096 break;
10097 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010098 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010099 break;
10100#endif
10101#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10102 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010103 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010104 break;
10105#endif
10106#if defined(FEAT_CRYPT)
10107 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010108 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010109 break;
10110#endif
10111#ifdef FEAT_STL_OPT
10112 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010113 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010114 break;
10115#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010116 case PV_UL:
10117 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10118 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010119#ifdef FEAT_LISP
10120 case PV_LW:
10121 clear_string_option(&buf->b_p_lw);
10122 break;
10123#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010124 }
10125}
10126
10127/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128 * Get pointer to option variable, depending on local or global scope.
10129 */
10130 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010131get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010132{
10133 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10134 {
10135 if (p->var == VAR_WIN)
10136 return (char_u *)GLOBAL_WO(get_varp(p));
10137 return p->var;
10138 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010139 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140 {
10141 switch ((int)p->indir)
10142 {
10143#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010144 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10145 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10146 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010148 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10149 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10150 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010151 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010152 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010153 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010155 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10156 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010157#endif
10158#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010159 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10160 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010162#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10163 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10164#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010165#if defined(FEAT_CRYPT)
10166 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10167#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010168#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010169 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010170#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010171 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010172#ifdef FEAT_LISP
10173 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10174#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010175 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010176 }
10177 return NULL; /* "cannot happen" */
10178 }
10179 return get_varp(p);
10180}
10181
10182/*
10183 * Get pointer to option variable.
10184 */
10185 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010186get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010187{
10188 /* hidden option, always return NULL */
10189 if (p->var == NULL)
10190 return NULL;
10191
10192 switch ((int)p->indir)
10193 {
10194 case PV_NONE: return p->var;
10195
10196 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010197 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010199 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010201 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010203 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010205 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010207 case PV_TC: return *curbuf->b_p_tc != NUL
10208 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010209 case PV_BKC: return *curbuf->b_p_bkc != NUL
10210 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010212 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010213 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010214 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10216#endif
10217#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010218 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010220 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10222#endif
10223#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010224 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010225 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010226 case PV_GP: return *curbuf->b_p_gp != NUL
10227 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10228 case PV_MP: return *curbuf->b_p_mp != NUL
10229 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010230#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010231#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10232 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10233 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10234#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010235#if defined(FEAT_CRYPT)
10236 case PV_CM: return *curbuf->b_p_cm != NUL
10237 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10238#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010239#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010240 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010241 ? (char_u *)&(curwin->w_p_stl) : p->var;
10242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010243 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10244 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010245#ifdef FEAT_LISP
10246 case PV_LW: return *curbuf->b_p_lw != NUL
10247 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010249
10250#ifdef FEAT_ARABIC
10251 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10252#endif
10253 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010254#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010255 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10256#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010257#ifdef FEAT_SYN_HL
10258 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10259 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010260 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010261#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262#ifdef FEAT_DIFF
10263 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10264#endif
10265#ifdef FEAT_FOLDING
10266 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10267 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10268 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10269 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10270 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10271 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10272 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10273# ifdef FEAT_EVAL
10274 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10275 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10276# endif
10277 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10278#endif
10279 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010280 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010281#ifdef FEAT_LINEBREAK
10282 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10283#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010284#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010286 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010288#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10289 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10290#endif
10291#ifdef FEAT_RIGHTLEFT
10292 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10293 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10294#endif
10295 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10296 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10297#ifdef FEAT_LINEBREAK
10298 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010299 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10300 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301#endif
10302#ifdef FEAT_SCROLLBIND
10303 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10304#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010305#ifdef FEAT_CURSORBIND
10306 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10307#endif
10308#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010309 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10310 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010311#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312
10313 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10314 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10315#ifdef FEAT_MBYTE
10316 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10317#endif
10318#if defined(FEAT_QUICKFIX)
10319 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10320 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10321#endif
10322 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10323 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10324#ifdef FEAT_CINDENT
10325 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10326 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10327 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10328#endif
10329#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10330 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10331#endif
10332#ifdef FEAT_COMMENTS
10333 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10334#endif
10335#ifdef FEAT_FOLDING
10336 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10337#endif
10338#ifdef FEAT_INS_EXPAND
10339 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10340#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010341#ifdef FEAT_COMPL_FUNC
10342 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010343 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010346 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10348#ifdef FEAT_MBYTE
10349 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10350#endif
10351 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10352#ifdef FEAT_AUTOCMD
10353 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10354#endif
10355 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010356 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10358 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10359 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10360 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10361#ifdef FEAT_FIND_ID
10362# ifdef FEAT_EVAL
10363 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10364# endif
10365#endif
10366#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10367 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10368 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10369#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010370#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010371 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373#ifdef FEAT_CRYPT
10374 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10375#endif
10376#ifdef FEAT_LISP
10377 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10378#endif
10379 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10380 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10381 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10382 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10383 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010385#ifdef FEAT_TEXTOBJ
10386 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10389#ifdef FEAT_SMARTINDENT
10390 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10391#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010392 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010393 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10394#ifdef FEAT_SEARCHPATH
10395 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10396#endif
10397 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10398#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010399 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010400 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10401#endif
10402#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010403 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10404 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10405 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406#endif
10407 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10408 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10409 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10410 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010411#ifdef FEAT_PERSISTENT_UNDO
10412 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10413#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010414 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10415#ifdef FEAT_KEYMAP
10416 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10417#endif
10418 default: EMSG(_("E356: get_varp ERROR"));
10419 }
10420 /* always return a valid pointer to avoid a crash! */
10421 return (char_u *)&(curbuf->b_p_wm);
10422}
10423
10424/*
10425 * Get the value of 'equalprg', either the buffer-local one or the global one.
10426 */
10427 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010428get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429{
10430 if (*curbuf->b_p_ep == NUL)
10431 return p_ep;
10432 return curbuf->b_p_ep;
10433}
10434
10435#if defined(FEAT_WINDOWS) || defined(PROTO)
10436/*
10437 * Copy options from one window to another.
10438 * Used when splitting a window.
10439 */
10440 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010441win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010442{
10443 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10444 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10445# ifdef FEAT_RIGHTLEFT
10446# ifdef FEAT_FKMAP
10447 /* Is this right? */
10448 wp_to->w_farsi = wp_from->w_farsi;
10449# endif
10450# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010451#if defined(FEAT_LINEBREAK)
10452 briopt_check(wp_to);
10453#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010454}
10455#endif
10456
10457/*
10458 * Copy the options from one winopt_T to another.
10459 * Doesn't free the old option values in "to", use clear_winopt() for that.
10460 * The 'scroll' option is not copied, because it depends on the window height.
10461 * The 'previewwindow' option is reset, there can be only one preview window.
10462 */
10463 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010464copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010465{
10466#ifdef FEAT_ARABIC
10467 to->wo_arab = from->wo_arab;
10468#endif
10469 to->wo_list = from->wo_list;
10470 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010471 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010472#ifdef FEAT_LINEBREAK
10473 to->wo_nuw = from->wo_nuw;
10474#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475#ifdef FEAT_RIGHTLEFT
10476 to->wo_rl = from->wo_rl;
10477 to->wo_rlc = vim_strsave(from->wo_rlc);
10478#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010479#ifdef FEAT_STL_OPT
10480 to->wo_stl = vim_strsave(from->wo_stl);
10481#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010483#ifdef FEAT_DIFF
10484 to->wo_wrap_save = from->wo_wrap_save;
10485#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486#ifdef FEAT_LINEBREAK
10487 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010488 to->wo_bri = from->wo_bri;
10489 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490#endif
10491#ifdef FEAT_SCROLLBIND
10492 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010493 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010495#ifdef FEAT_CURSORBIND
10496 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010497 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010498#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010499#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010500 to->wo_spell = from->wo_spell;
10501#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010502#ifdef FEAT_SYN_HL
10503 to->wo_cuc = from->wo_cuc;
10504 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010505 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010506#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507#ifdef FEAT_DIFF
10508 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010509 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010511#ifdef FEAT_CONCEAL
10512 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010513 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010514#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515#ifdef FEAT_FOLDING
10516 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010517 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010518 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010519 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 to->wo_fdi = vim_strsave(from->wo_fdi);
10521 to->wo_fml = from->wo_fml;
10522 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010523 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010525 to->wo_fdm_save = from->wo_diff_saved
10526 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527 to->wo_fdn = from->wo_fdn;
10528# ifdef FEAT_EVAL
10529 to->wo_fde = vim_strsave(from->wo_fde);
10530 to->wo_fdt = vim_strsave(from->wo_fdt);
10531# endif
10532 to->wo_fmr = vim_strsave(from->wo_fmr);
10533#endif
10534 check_winopt(to); /* don't want NULL pointers */
10535}
10536
10537/*
10538 * Check string options in a window for a NULL value.
10539 */
10540 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010541check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542{
10543 check_winopt(&win->w_onebuf_opt);
10544 check_winopt(&win->w_allbuf_opt);
10545}
10546
10547/*
10548 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10549 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010550 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010551check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552{
10553#ifdef FEAT_FOLDING
10554 check_string_option(&wop->wo_fdi);
10555 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010556 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010557# ifdef FEAT_EVAL
10558 check_string_option(&wop->wo_fde);
10559 check_string_option(&wop->wo_fdt);
10560# endif
10561 check_string_option(&wop->wo_fmr);
10562#endif
10563#ifdef FEAT_RIGHTLEFT
10564 check_string_option(&wop->wo_rlc);
10565#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010566#ifdef FEAT_STL_OPT
10567 check_string_option(&wop->wo_stl);
10568#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010569#ifdef FEAT_SYN_HL
10570 check_string_option(&wop->wo_cc);
10571#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010572#ifdef FEAT_CONCEAL
10573 check_string_option(&wop->wo_cocu);
10574#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010575#ifdef FEAT_LINEBREAK
10576 check_string_option(&wop->wo_briopt);
10577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578}
10579
10580/*
10581 * Free the allocated memory inside a winopt_T.
10582 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010584clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585{
10586#ifdef FEAT_FOLDING
10587 clear_string_option(&wop->wo_fdi);
10588 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010589 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590# ifdef FEAT_EVAL
10591 clear_string_option(&wop->wo_fde);
10592 clear_string_option(&wop->wo_fdt);
10593# endif
10594 clear_string_option(&wop->wo_fmr);
10595#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010596#ifdef FEAT_LINEBREAK
10597 clear_string_option(&wop->wo_briopt);
10598#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599#ifdef FEAT_RIGHTLEFT
10600 clear_string_option(&wop->wo_rlc);
10601#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010602#ifdef FEAT_STL_OPT
10603 clear_string_option(&wop->wo_stl);
10604#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010605#ifdef FEAT_SYN_HL
10606 clear_string_option(&wop->wo_cc);
10607#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010608#ifdef FEAT_CONCEAL
10609 clear_string_option(&wop->wo_cocu);
10610#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611}
10612
10613/*
10614 * Copy global option values to local options for one buffer.
10615 * Used when creating a new buffer and sometimes when entering a buffer.
10616 * flags:
10617 * BCO_ENTER We will enter the buf buffer.
10618 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10619 * appropriate.
10620 * BCO_NOHELP Don't copy the values to a help buffer.
10621 */
10622 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010623buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010624{
10625 int should_copy = TRUE;
10626 char_u *save_p_isk = NULL; /* init for GCC */
10627 int dont_do_help;
10628 int did_isk = FALSE;
10629
10630 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631 * Skip this when the option defaults have not been set yet. Happens when
10632 * main() allocates the first buffer.
10633 */
10634 if (p_cpo != NULL)
10635 {
10636 /*
10637 * Always copy when entering and 'cpo' contains 'S'.
10638 * Don't copy when already initialized.
10639 * Don't copy when 'cpo' contains 's' and not entering.
10640 * 'S' BCO_ENTER initialized 's' should_copy
10641 * yes yes X X TRUE
10642 * yes no yes X FALSE
10643 * no X yes X FALSE
10644 * X no no yes FALSE
10645 * X no no no TRUE
10646 * no yes no X TRUE
10647 */
10648 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10649 && (buf->b_p_initialized
10650 || (!(flags & BCO_ENTER)
10651 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10652 should_copy = FALSE;
10653
10654 if (should_copy || (flags & BCO_ALWAYS))
10655 {
10656 /* Don't copy the options specific to a help buffer when
10657 * BCO_NOHELP is given or the options were initialized already
10658 * (jumping back to a help file with CTRL-T or CTRL-O) */
10659 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10660 || buf->b_p_initialized;
10661 if (dont_do_help) /* don't free b_p_isk */
10662 {
10663 save_p_isk = buf->b_p_isk;
10664 buf->b_p_isk = NULL;
10665 }
10666 /*
10667 * Always free the allocated strings.
10668 * If not already initialized, set 'readonly' and copy 'fileformat'.
10669 */
10670 if (!buf->b_p_initialized)
10671 {
10672 free_buf_options(buf, TRUE);
10673 buf->b_p_ro = FALSE; /* don't copy readonly */
10674 buf->b_p_tx = p_tx;
10675#ifdef FEAT_MBYTE
10676 buf->b_p_fenc = vim_strsave(p_fenc);
10677#endif
10678 buf->b_p_ff = vim_strsave(p_ff);
10679#if defined(FEAT_QUICKFIX)
10680 buf->b_p_bh = empty_option;
10681 buf->b_p_bt = empty_option;
10682#endif
10683 }
10684 else
10685 free_buf_options(buf, FALSE);
10686
10687 buf->b_p_ai = p_ai;
10688 buf->b_p_ai_nopaste = p_ai_nopaste;
10689 buf->b_p_sw = p_sw;
10690 buf->b_p_tw = p_tw;
10691 buf->b_p_tw_nopaste = p_tw_nopaste;
10692 buf->b_p_tw_nobin = p_tw_nobin;
10693 buf->b_p_wm = p_wm;
10694 buf->b_p_wm_nopaste = p_wm_nopaste;
10695 buf->b_p_wm_nobin = p_wm_nobin;
10696 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010697#ifdef FEAT_MBYTE
10698 buf->b_p_bomb = p_bomb;
10699#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010700 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010701 buf->b_p_et = p_et;
10702 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010703 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704 buf->b_p_ml = p_ml;
10705 buf->b_p_ml_nobin = p_ml_nobin;
10706 buf->b_p_inf = p_inf;
10707 buf->b_p_swf = p_swf;
10708#ifdef FEAT_INS_EXPAND
10709 buf->b_p_cpt = vim_strsave(p_cpt);
10710#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010711#ifdef FEAT_COMPL_FUNC
10712 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010713 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010715 buf->b_p_sts = p_sts;
10716 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010717 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718#ifdef FEAT_COMMENTS
10719 buf->b_p_com = vim_strsave(p_com);
10720#endif
10721#ifdef FEAT_FOLDING
10722 buf->b_p_cms = vim_strsave(p_cms);
10723#endif
10724 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010725 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010726 buf->b_p_nf = vim_strsave(p_nf);
10727 buf->b_p_mps = vim_strsave(p_mps);
10728#ifdef FEAT_SMARTINDENT
10729 buf->b_p_si = p_si;
10730#endif
10731 buf->b_p_ci = p_ci;
10732#ifdef FEAT_CINDENT
10733 buf->b_p_cin = p_cin;
10734 buf->b_p_cink = vim_strsave(p_cink);
10735 buf->b_p_cino = vim_strsave(p_cino);
10736#endif
10737#ifdef FEAT_AUTOCMD
10738 /* Don't copy 'filetype', it must be detected */
10739 buf->b_p_ft = empty_option;
10740#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741 buf->b_p_pi = p_pi;
10742#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10743 buf->b_p_cinw = vim_strsave(p_cinw);
10744#endif
10745#ifdef FEAT_LISP
10746 buf->b_p_lisp = p_lisp;
10747#endif
10748#ifdef FEAT_SYN_HL
10749 /* Don't copy 'syntax', it must be set */
10750 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010751 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010752 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010753#endif
10754#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010755 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010756 (void)compile_cap_prog(&buf->b_s);
10757 buf->b_s.b_p_spf = vim_strsave(p_spf);
10758 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759#endif
10760#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10761 buf->b_p_inde = vim_strsave(p_inde);
10762 buf->b_p_indk = vim_strsave(p_indk);
10763#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010764#if defined(FEAT_EVAL)
10765 buf->b_p_fex = vim_strsave(p_fex);
10766#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767#ifdef FEAT_CRYPT
10768 buf->b_p_key = vim_strsave(p_key);
10769#endif
10770#ifdef FEAT_SEARCHPATH
10771 buf->b_p_sua = vim_strsave(p_sua);
10772#endif
10773#ifdef FEAT_KEYMAP
10774 buf->b_p_keymap = vim_strsave(p_keymap);
10775 buf->b_kmap_state |= KEYMAP_INIT;
10776#endif
10777 /* This isn't really an option, but copying the langmap and IME
10778 * state from the current buffer is better than resetting it. */
10779 buf->b_p_iminsert = p_iminsert;
10780 buf->b_p_imsearch = p_imsearch;
10781
10782 /* options that are normally global but also have a local value
10783 * are not copied, start using the global value */
10784 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010785 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010786 buf->b_p_bkc = empty_option;
10787 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788#ifdef FEAT_QUICKFIX
10789 buf->b_p_gp = empty_option;
10790 buf->b_p_mp = empty_option;
10791 buf->b_p_efm = empty_option;
10792#endif
10793 buf->b_p_ep = empty_option;
10794 buf->b_p_kp = empty_option;
10795 buf->b_p_path = empty_option;
10796 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010797 buf->b_p_tc = empty_option;
10798 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799#ifdef FEAT_FIND_ID
10800 buf->b_p_def = empty_option;
10801 buf->b_p_inc = empty_option;
10802# ifdef FEAT_EVAL
10803 buf->b_p_inex = vim_strsave(p_inex);
10804# endif
10805#endif
10806#ifdef FEAT_INS_EXPAND
10807 buf->b_p_dict = empty_option;
10808 buf->b_p_tsr = empty_option;
10809#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010810#ifdef FEAT_TEXTOBJ
10811 buf->b_p_qe = vim_strsave(p_qe);
10812#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010813#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10814 buf->b_p_bexpr = empty_option;
10815#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010816#if defined(FEAT_CRYPT)
10817 buf->b_p_cm = empty_option;
10818#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010819#ifdef FEAT_PERSISTENT_UNDO
10820 buf->b_p_udf = p_udf;
10821#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010822#ifdef FEAT_LISP
10823 buf->b_p_lw = empty_option;
10824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825
10826 /*
10827 * Don't copy the options set by ex_help(), use the saved values,
10828 * when going from a help buffer to a non-help buffer.
10829 * Don't touch these at all when BCO_NOHELP is used and going from
10830 * or to a help buffer.
10831 */
10832 if (dont_do_help)
10833 buf->b_p_isk = save_p_isk;
10834 else
10835 {
10836 buf->b_p_isk = vim_strsave(p_isk);
10837 did_isk = TRUE;
10838 buf->b_p_ts = p_ts;
10839 buf->b_help = FALSE;
10840#ifdef FEAT_QUICKFIX
10841 if (buf->b_p_bt[0] == 'h')
10842 clear_string_option(&buf->b_p_bt);
10843#endif
10844 buf->b_p_ma = p_ma;
10845 }
10846 }
10847
10848 /*
10849 * When the options should be copied (ignoring BCO_ALWAYS), set the
10850 * flag that indicates that the options have been initialized.
10851 */
10852 if (should_copy)
10853 buf->b_p_initialized = TRUE;
10854 }
10855
10856 check_buf_options(buf); /* make sure we don't have NULLs */
10857 if (did_isk)
10858 (void)buf_init_chartab(buf, FALSE);
10859}
10860
10861/*
10862 * Reset the 'modifiable' option and its default value.
10863 */
10864 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010865reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866{
10867 int opt_idx;
10868
10869 curbuf->b_p_ma = FALSE;
10870 p_ma = FALSE;
10871 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010872 if (opt_idx >= 0)
10873 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874}
10875
10876/*
10877 * Set the global value for 'iminsert' to the local value.
10878 */
10879 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010880set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010881{
10882 p_iminsert = curbuf->b_p_iminsert;
10883}
10884
10885/*
10886 * Set the global value for 'imsearch' to the local value.
10887 */
10888 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010889set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890{
10891 p_imsearch = curbuf->b_p_imsearch;
10892}
10893
10894#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10895static int expand_option_idx = -1;
10896static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10897static int expand_option_flags = 0;
10898
10899 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010900set_context_in_set_cmd(
10901 expand_T *xp,
10902 char_u *arg,
10903 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904{
10905 int nextchar;
10906 long_u flags = 0; /* init for GCC */
10907 int opt_idx = 0; /* init for GCC */
10908 char_u *p;
10909 char_u *s;
10910 int is_term_option = FALSE;
10911 int key;
10912
10913 expand_option_flags = opt_flags;
10914
10915 xp->xp_context = EXPAND_SETTINGS;
10916 if (*arg == NUL)
10917 {
10918 xp->xp_pattern = arg;
10919 return;
10920 }
10921 p = arg + STRLEN(arg) - 1;
10922 if (*p == ' ' && *(p - 1) != '\\')
10923 {
10924 xp->xp_pattern = p + 1;
10925 return;
10926 }
10927 while (p > arg)
10928 {
10929 s = p;
10930 /* count number of backslashes before ' ' or ',' */
10931 if (*p == ' ' || *p == ',')
10932 {
10933 while (s > arg && *(s - 1) == '\\')
10934 --s;
10935 }
10936 /* break at a space with an even number of backslashes */
10937 if (*p == ' ' && ((p - s) & 1) == 0)
10938 {
10939 ++p;
10940 break;
10941 }
10942 --p;
10943 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010944 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945 {
10946 xp->xp_context = EXPAND_BOOL_SETTINGS;
10947 p += 2;
10948 }
10949 if (STRNCMP(p, "inv", 3) == 0)
10950 {
10951 xp->xp_context = EXPAND_BOOL_SETTINGS;
10952 p += 3;
10953 }
10954 xp->xp_pattern = arg = p;
10955 if (*arg == '<')
10956 {
10957 while (*p != '>')
10958 if (*p++ == NUL) /* expand terminal option name */
10959 return;
10960 key = get_special_key_code(arg + 1);
10961 if (key == 0) /* unknown name */
10962 {
10963 xp->xp_context = EXPAND_NOTHING;
10964 return;
10965 }
10966 nextchar = *++p;
10967 is_term_option = TRUE;
10968 expand_option_name[2] = KEY2TERMCAP0(key);
10969 expand_option_name[3] = KEY2TERMCAP1(key);
10970 }
10971 else
10972 {
10973 if (p[0] == 't' && p[1] == '_')
10974 {
10975 p += 2;
10976 if (*p != NUL)
10977 ++p;
10978 if (*p == NUL)
10979 return; /* expand option name */
10980 nextchar = *++p;
10981 is_term_option = TRUE;
10982 expand_option_name[2] = p[-2];
10983 expand_option_name[3] = p[-1];
10984 }
10985 else
10986 {
10987 /* Allow * wildcard */
10988 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10989 p++;
10990 if (*p == NUL)
10991 return;
10992 nextchar = *p;
10993 *p = NUL;
10994 opt_idx = findoption(arg);
10995 *p = nextchar;
10996 if (opt_idx == -1 || options[opt_idx].var == NULL)
10997 {
10998 xp->xp_context = EXPAND_NOTHING;
10999 return;
11000 }
11001 flags = options[opt_idx].flags;
11002 if (flags & P_BOOL)
11003 {
11004 xp->xp_context = EXPAND_NOTHING;
11005 return;
11006 }
11007 }
11008 }
11009 /* handle "-=" and "+=" */
11010 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11011 {
11012 ++p;
11013 nextchar = '=';
11014 }
11015 if ((nextchar != '=' && nextchar != ':')
11016 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11017 {
11018 xp->xp_context = EXPAND_UNSUCCESSFUL;
11019 return;
11020 }
11021 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11022 {
11023 xp->xp_context = EXPAND_OLD_SETTING;
11024 if (is_term_option)
11025 expand_option_idx = -1;
11026 else
11027 expand_option_idx = opt_idx;
11028 xp->xp_pattern = p + 1;
11029 return;
11030 }
11031 xp->xp_context = EXPAND_NOTHING;
11032 if (is_term_option || (flags & P_NUM))
11033 return;
11034
11035 xp->xp_pattern = p + 1;
11036
11037 if (flags & P_EXPAND)
11038 {
11039 p = options[opt_idx].var;
11040 if (p == (char_u *)&p_bdir
11041 || p == (char_u *)&p_dir
11042 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011043 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011044 || p == (char_u *)&p_rtp
11045#ifdef FEAT_SEARCHPATH
11046 || p == (char_u *)&p_cdpath
11047#endif
11048#ifdef FEAT_SESSION
11049 || p == (char_u *)&p_vdir
11050#endif
11051 )
11052 {
11053 xp->xp_context = EXPAND_DIRECTORIES;
11054 if (p == (char_u *)&p_path
11055#ifdef FEAT_SEARCHPATH
11056 || p == (char_u *)&p_cdpath
11057#endif
11058 )
11059 xp->xp_backslash = XP_BS_THREE;
11060 else
11061 xp->xp_backslash = XP_BS_ONE;
11062 }
11063 else
11064 {
11065 xp->xp_context = EXPAND_FILES;
11066 /* for 'tags' need three backslashes for a space */
11067 if (p == (char_u *)&p_tags)
11068 xp->xp_backslash = XP_BS_THREE;
11069 else
11070 xp->xp_backslash = XP_BS_ONE;
11071 }
11072 }
11073
11074 /* For an option that is a list of file names, find the start of the
11075 * last file name. */
11076 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11077 {
11078 /* count number of backslashes before ' ' or ',' */
11079 if (*p == ' ' || *p == ',')
11080 {
11081 s = p;
11082 while (s > xp->xp_pattern && *(s - 1) == '\\')
11083 --s;
11084 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11085 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11086 {
11087 xp->xp_pattern = p + 1;
11088 break;
11089 }
11090 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011091
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011092#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011093 /* for 'spellsuggest' start at "file:" */
11094 if (options[opt_idx].var == (char_u *)&p_sps
11095 && STRNCMP(p, "file:", 5) == 0)
11096 {
11097 xp->xp_pattern = p + 5;
11098 break;
11099 }
11100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011101 }
11102
11103 return;
11104}
11105
11106 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011107ExpandSettings(
11108 expand_T *xp,
11109 regmatch_T *regmatch,
11110 int *num_file,
11111 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011112{
11113 int num_normal = 0; /* Nr of matching non-term-code settings */
11114 int num_term = 0; /* Nr of matching terminal code settings */
11115 int opt_idx;
11116 int match;
11117 int count = 0;
11118 char_u *str;
11119 int loop;
11120 int is_term_opt;
11121 char_u name_buf[MAX_KEY_NAME_LEN];
11122 static char *(names[]) = {"all", "termcap"};
11123 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11124
11125 /* do this loop twice:
11126 * loop == 0: count the number of matching options
11127 * loop == 1: copy the matching options into allocated memory
11128 */
11129 for (loop = 0; loop <= 1; ++loop)
11130 {
11131 regmatch->rm_ic = ic;
11132 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11133 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011134 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11135 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011136 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11137 {
11138 if (loop == 0)
11139 num_normal++;
11140 else
11141 (*file)[count++] = vim_strsave((char_u *)names[match]);
11142 }
11143 }
11144 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11145 opt_idx++)
11146 {
11147 if (options[opt_idx].var == NULL)
11148 continue;
11149 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11150 && !(options[opt_idx].flags & P_BOOL))
11151 continue;
11152 is_term_opt = istermoption(&options[opt_idx]);
11153 if (is_term_opt && num_normal > 0)
11154 continue;
11155 match = FALSE;
11156 if (vim_regexec(regmatch, str, (colnr_T)0)
11157 || (options[opt_idx].shortname != NULL
11158 && vim_regexec(regmatch,
11159 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11160 match = TRUE;
11161 else if (is_term_opt)
11162 {
11163 name_buf[0] = '<';
11164 name_buf[1] = 't';
11165 name_buf[2] = '_';
11166 name_buf[3] = str[2];
11167 name_buf[4] = str[3];
11168 name_buf[5] = '>';
11169 name_buf[6] = NUL;
11170 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11171 {
11172 match = TRUE;
11173 str = name_buf;
11174 }
11175 }
11176 if (match)
11177 {
11178 if (loop == 0)
11179 {
11180 if (is_term_opt)
11181 num_term++;
11182 else
11183 num_normal++;
11184 }
11185 else
11186 (*file)[count++] = vim_strsave(str);
11187 }
11188 }
11189 /*
11190 * Check terminal key codes, these are not in the option table
11191 */
11192 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11193 {
11194 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11195 {
11196 if (!isprint(str[0]) || !isprint(str[1]))
11197 continue;
11198
11199 name_buf[0] = 't';
11200 name_buf[1] = '_';
11201 name_buf[2] = str[0];
11202 name_buf[3] = str[1];
11203 name_buf[4] = NUL;
11204
11205 match = FALSE;
11206 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11207 match = TRUE;
11208 else
11209 {
11210 name_buf[0] = '<';
11211 name_buf[1] = 't';
11212 name_buf[2] = '_';
11213 name_buf[3] = str[0];
11214 name_buf[4] = str[1];
11215 name_buf[5] = '>';
11216 name_buf[6] = NUL;
11217
11218 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11219 match = TRUE;
11220 }
11221 if (match)
11222 {
11223 if (loop == 0)
11224 num_term++;
11225 else
11226 (*file)[count++] = vim_strsave(name_buf);
11227 }
11228 }
11229
11230 /*
11231 * Check special key names.
11232 */
11233 regmatch->rm_ic = TRUE; /* ignore case here */
11234 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11235 {
11236 name_buf[0] = '<';
11237 STRCPY(name_buf + 1, str);
11238 STRCAT(name_buf, ">");
11239
11240 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11241 {
11242 if (loop == 0)
11243 num_term++;
11244 else
11245 (*file)[count++] = vim_strsave(name_buf);
11246 }
11247 }
11248 }
11249 if (loop == 0)
11250 {
11251 if (num_normal > 0)
11252 *num_file = num_normal;
11253 else if (num_term > 0)
11254 *num_file = num_term;
11255 else
11256 return OK;
11257 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11258 if (*file == NULL)
11259 {
11260 *file = (char_u **)"";
11261 return FAIL;
11262 }
11263 }
11264 }
11265 return OK;
11266}
11267
11268 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011269ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011270{
11271 char_u *var = NULL; /* init for GCC */
11272 char_u *buf;
11273
11274 *num_file = 0;
11275 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11276 if (*file == NULL)
11277 return FAIL;
11278
11279 /*
11280 * For a terminal key code expand_option_idx is < 0.
11281 */
11282 if (expand_option_idx < 0)
11283 {
11284 var = find_termcode(expand_option_name + 2);
11285 if (var == NULL)
11286 expand_option_idx = findoption(expand_option_name);
11287 }
11288
11289 if (expand_option_idx >= 0)
11290 {
11291 /* put string of option value in NameBuff */
11292 option_value2string(&options[expand_option_idx], expand_option_flags);
11293 var = NameBuff;
11294 }
11295 else if (var == NULL)
11296 var = (char_u *)"";
11297
11298 /* A backslash is required before some characters. This is the reverse of
11299 * what happens in do_set(). */
11300 buf = vim_strsave_escaped(var, escape_chars);
11301
11302 if (buf == NULL)
11303 {
11304 vim_free(*file);
11305 *file = NULL;
11306 return FAIL;
11307 }
11308
11309#ifdef BACKSLASH_IN_FILENAME
11310 /* For MS-Windows et al. we don't double backslashes at the start and
11311 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011312 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011313 if (var[0] == '\\' && var[1] == '\\'
11314 && expand_option_idx >= 0
11315 && (options[expand_option_idx].flags & P_EXPAND)
11316 && vim_isfilec(var[2])
11317 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011318 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319#endif
11320
11321 *file[0] = buf;
11322 *num_file = 1;
11323 return OK;
11324}
11325#endif
11326
11327/*
11328 * Get the value for the numeric or string option *opp in a nice format into
11329 * NameBuff[]. Must not be called with a hidden option!
11330 */
11331 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011332option_value2string(
11333 struct vimoption *opp,
11334 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011335{
11336 char_u *varp;
11337
11338 varp = get_varp_scope(opp, opt_flags);
11339
11340 if (opp->flags & P_NUM)
11341 {
11342 long wc = 0;
11343
11344 if (wc_use_keyname(varp, &wc))
11345 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11346 else if (wc != 0)
11347 STRCPY(NameBuff, transchar((int)wc));
11348 else
11349 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11350 }
11351 else /* P_STRING */
11352 {
11353 varp = *(char_u **)(varp);
11354 if (varp == NULL) /* just in case */
11355 NameBuff[0] = NUL;
11356#ifdef FEAT_CRYPT
11357 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011358 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011359 STRCPY(NameBuff, "*****");
11360#endif
11361 else if (opp->flags & P_EXPAND)
11362 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11363 /* Translate 'pastetoggle' into special key names */
11364 else if ((char_u **)opp->var == &p_pt)
11365 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11366 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011367 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368 }
11369}
11370
11371/*
11372 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11373 * printed as a keyname.
11374 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11375 */
11376 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011377wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011378{
11379 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11380 {
11381 *wcp = *(long *)varp;
11382 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11383 return TRUE;
11384 }
11385 return FALSE;
11386}
11387
Bram Moolenaar01615492015-02-03 13:00:38 +010011388#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011390 * Any character has an equivalent 'langmap' character. This is used for
11391 * keyboards that have a special language mode that sends characters above
11392 * 128 (although other characters can be translated too). The "to" field is a
11393 * Vim command character. This avoids having to switch the keyboard back to
11394 * ASCII mode when leaving Insert mode.
11395 *
11396 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11397 * commands.
11398 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11399 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11400 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011402# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011403/*
11404 * With multi-byte support use growarray for 'langmap' chars >= 256
11405 */
11406typedef struct
11407{
11408 int from;
11409 int to;
11410} langmap_entry_T;
11411
11412static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011413static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414
11415/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011416 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11417 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011418 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011419 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011420langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011421{
11422 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011423 int a = 0;
11424 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011425
11426 /* Do a binary search for an existing entry. */
11427 while (a != b)
11428 {
11429 int i = (a + b) / 2;
11430 int d = entries[i].from - from;
11431
11432 if (d == 0)
11433 {
11434 entries[i].to = to;
11435 return;
11436 }
11437 if (d < 0)
11438 a = i + 1;
11439 else
11440 b = i;
11441 }
11442
11443 if (ga_grow(&langmap_mapga, 1) != OK)
11444 return; /* out of memory */
11445
11446 /* insert new entry at position "a" */
11447 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11448 mch_memmove(entries + 1, entries,
11449 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11450 ++langmap_mapga.ga_len;
11451 entries[0].from = from;
11452 entries[0].to = to;
11453}
11454
11455/*
11456 * Apply 'langmap' to multi-byte character "c" and return the result.
11457 */
11458 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011459langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011460{
11461 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11462 int a = 0;
11463 int b = langmap_mapga.ga_len;
11464
11465 while (a != b)
11466 {
11467 int i = (a + b) / 2;
11468 int d = entries[i].from - c;
11469
11470 if (d == 0)
11471 return entries[i].to; /* found matching entry */
11472 if (d < 0)
11473 a = i + 1;
11474 else
11475 b = i;
11476 }
11477 return c; /* no entry found, return "c" unmodified */
11478}
11479# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011480
11481 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011482langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011483{
11484 int i;
11485
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011486 for (i = 0; i < 256; i++)
11487 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11488# ifdef FEAT_MBYTE
11489 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11490# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491}
11492
11493/*
11494 * Called when langmap option is set; the language map can be
11495 * changed at any time!
11496 */
11497 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011498langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499{
11500 char_u *p;
11501 char_u *p2;
11502 int from, to;
11503
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011504#ifdef FEAT_MBYTE
11505 ga_clear(&langmap_mapga); /* clear the previous map first */
11506#endif
11507 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011508
11509 for (p = p_langmap; p[0] != NUL; )
11510 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011511 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11512 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011513 {
11514 if (p2[0] == '\\' && p2[1] != NUL)
11515 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011516 }
11517 if (p2[0] == ';')
11518 ++p2; /* abcd;ABCD form, p2 points to A */
11519 else
11520 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11521 while (p[0])
11522 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011523 if (p[0] == ',')
11524 {
11525 ++p;
11526 break;
11527 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528 if (p[0] == '\\' && p[1] != NUL)
11529 ++p;
11530#ifdef FEAT_MBYTE
11531 from = (*mb_ptr2char)(p);
11532#else
11533 from = p[0];
11534#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011535 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011536 if (p2 == NULL)
11537 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011538 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011539 if (p[0] != ',')
11540 {
11541 if (p[0] == '\\')
11542 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011543#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011544 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011545#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011546 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011547#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011548 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011549 }
11550 else
11551 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011552 if (p2[0] != ',')
11553 {
11554 if (p2[0] == '\\')
11555 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011556#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011557 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011558#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011559 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011560#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011561 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011562 }
11563 if (to == NUL)
11564 {
11565 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11566 transchar(from));
11567 return;
11568 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011569
11570#ifdef FEAT_MBYTE
11571 if (from >= 256)
11572 langmap_set_entry(from, to);
11573 else
11574#endif
11575 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011576
11577 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011578 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011579 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011581 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011582 if (*p == ';')
11583 {
11584 p = p2;
11585 if (p[0] != NUL)
11586 {
11587 if (p[0] != ',')
11588 {
11589 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11590 return;
11591 }
11592 ++p;
11593 }
11594 break;
11595 }
11596 }
11597 }
11598 }
11599}
11600#endif
11601
11602/*
11603 * Return TRUE if format option 'x' is in effect.
11604 * Take care of no formatting when 'paste' is set.
11605 */
11606 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011607has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011608{
11609 if (p_paste)
11610 return FALSE;
11611 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11612}
11613
11614/*
11615 * Return TRUE if "x" is present in 'shortmess' option, or
11616 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11617 */
11618 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011619shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011620{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011621 return p_shm != NULL &&
11622 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623 || (vim_strchr(p_shm, 'a') != NULL
11624 && vim_strchr((char_u *)SHM_A, x) != NULL));
11625}
11626
11627/*
11628 * paste_option_changed() - Called after p_paste was set or reset.
11629 */
11630 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011631paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011632{
11633 static int old_p_paste = FALSE;
11634 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011635 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011636#ifdef FEAT_CMDL_INFO
11637 static int save_ru = 0;
11638#endif
11639#ifdef FEAT_RIGHTLEFT
11640 static int save_ri = 0;
11641 static int save_hkmap = 0;
11642#endif
11643 buf_T *buf;
11644
11645 if (p_paste)
11646 {
11647 /*
11648 * Paste switched from off to on.
11649 * Save the current values, so they can be restored later.
11650 */
11651 if (!old_p_paste)
11652 {
11653 /* save options for each buffer */
11654 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11655 {
11656 buf->b_p_tw_nopaste = buf->b_p_tw;
11657 buf->b_p_wm_nopaste = buf->b_p_wm;
11658 buf->b_p_sts_nopaste = buf->b_p_sts;
11659 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011660 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011661 }
11662
11663 /* save global options */
11664 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011665 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011666#ifdef FEAT_CMDL_INFO
11667 save_ru = p_ru;
11668#endif
11669#ifdef FEAT_RIGHTLEFT
11670 save_ri = p_ri;
11671 save_hkmap = p_hkmap;
11672#endif
11673 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011674 p_ai_nopaste = p_ai;
11675 p_et_nopaste = p_et;
11676 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011677 p_tw_nopaste = p_tw;
11678 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011679 }
11680
11681 /*
11682 * Always set the option values, also when 'paste' is set when it is
11683 * already on.
11684 */
11685 /* set options for each buffer */
11686 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11687 {
11688 buf->b_p_tw = 0; /* textwidth is 0 */
11689 buf->b_p_wm = 0; /* wrapmargin is 0 */
11690 buf->b_p_sts = 0; /* softtabstop is 0 */
11691 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011692 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011693 }
11694
11695 /* set global options */
11696 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011697 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011698#ifdef FEAT_CMDL_INFO
11699# ifdef FEAT_WINDOWS
11700 if (p_ru)
11701 status_redraw_all(); /* redraw to remove the ruler */
11702# endif
11703 p_ru = 0; /* no ruler */
11704#endif
11705#ifdef FEAT_RIGHTLEFT
11706 p_ri = 0; /* no reverse insert */
11707 p_hkmap = 0; /* no Hebrew keyboard */
11708#endif
11709 /* set global values for local buffer options */
11710 p_tw = 0;
11711 p_wm = 0;
11712 p_sts = 0;
11713 p_ai = 0;
11714 }
11715
11716 /*
11717 * Paste switched from on to off: Restore saved values.
11718 */
11719 else if (old_p_paste)
11720 {
11721 /* restore options for each buffer */
11722 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11723 {
11724 buf->b_p_tw = buf->b_p_tw_nopaste;
11725 buf->b_p_wm = buf->b_p_wm_nopaste;
11726 buf->b_p_sts = buf->b_p_sts_nopaste;
11727 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011728 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011729 }
11730
11731 /* restore global options */
11732 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011733 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011734#ifdef FEAT_CMDL_INFO
11735# ifdef FEAT_WINDOWS
11736 if (p_ru != save_ru)
11737 status_redraw_all(); /* redraw to draw the ruler */
11738# endif
11739 p_ru = save_ru;
11740#endif
11741#ifdef FEAT_RIGHTLEFT
11742 p_ri = save_ri;
11743 p_hkmap = save_hkmap;
11744#endif
11745 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011746 p_ai = p_ai_nopaste;
11747 p_et = p_et_nopaste;
11748 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011749 p_tw = p_tw_nopaste;
11750 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011751 }
11752
11753 old_p_paste = p_paste;
11754}
11755
11756/*
11757 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11758 *
11759 * Reset 'compatible' and set the values for options that didn't get set yet
11760 * to the Vim defaults.
11761 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011762 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011763 */
11764 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011765vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011766{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011767 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011768 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011769 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011770
11771 if (!option_was_set((char_u *)"cp"))
11772 {
11773 p_cp = FALSE;
11774 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11775 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11776 set_option_default(opt_idx, OPT_FREE, FALSE);
11777 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011778 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011779 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011780
11781 if (fname != NULL)
11782 {
11783 p = vim_getenv(envname, &dofree);
11784 if (p == NULL)
11785 {
11786 /* Set $MYVIMRC to the first vimrc file found. */
11787 p = FullName_save(fname, FALSE);
11788 if (p != NULL)
11789 {
11790 vim_setenv(envname, p);
11791 vim_free(p);
11792 }
11793 }
11794 else if (dofree)
11795 vim_free(p);
11796 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011797}
11798
11799/*
11800 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11801 */
11802 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011803change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011804{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011805 int opt_idx;
11806
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807 if (p_cp != on)
11808 {
11809 p_cp = on;
11810 compatible_set();
11811 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011812 opt_idx = findoption((char_u *)"cp");
11813 if (opt_idx >= 0)
11814 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011815}
11816
11817/*
11818 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011819 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820 */
11821 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011822option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823{
11824 int idx;
11825
11826 idx = findoption(name);
11827 if (idx < 0) /* unknown option */
11828 return FALSE;
11829 if (options[idx].flags & P_WAS_SET)
11830 return TRUE;
11831 return FALSE;
11832}
11833
11834/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011835 * Reset the flag indicating option "name" was set.
11836 */
11837 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011838reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011839{
11840 int idx = findoption(name);
11841
11842 if (idx >= 0)
11843 options[idx].flags &= ~P_WAS_SET;
11844}
11845
11846/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011847 * compatible_set() - Called when 'compatible' has been set or unset.
11848 *
11849 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11850 * flag) to a Vi compatible value.
11851 * When 'compatible' is unset: Set all options that have a different default
11852 * for Vim (without the P_VI_DEF flag) to that default.
11853 */
11854 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011855compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856{
11857 int opt_idx;
11858
11859 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11860 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11861 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11862 set_option_default(opt_idx, OPT_FREE, p_cp);
11863 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011864 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011865}
11866
11867#ifdef FEAT_LINEBREAK
11868
11869# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11870 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011871 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011872# endif
11873
11874/*
11875 * fill_breakat_flags() -- called when 'breakat' changes value.
11876 */
11877 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011878fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011879{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011880 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881 int i;
11882
11883 for (i = 0; i < 256; i++)
11884 breakat_flags[i] = FALSE;
11885
11886 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011887 for (p = p_breakat; *p; p++)
11888 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889}
11890
11891# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011892 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893# endif
11894
11895#endif
11896
11897/*
11898 * Check an option that can be a range of string values.
11899 *
11900 * Return OK for correct value, FAIL otherwise.
11901 * Empty is always OK.
11902 */
11903 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011904check_opt_strings(
11905 char_u *val,
11906 char **values,
11907 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011908{
11909 return opt_strings_flags(val, values, NULL, list);
11910}
11911
11912/*
11913 * Handle an option that can be a range of string values.
11914 * Set a flag in "*flagp" for each string present.
11915 *
11916 * Return OK for correct value, FAIL otherwise.
11917 * Empty is always OK.
11918 */
11919 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011920opt_strings_flags(
11921 char_u *val, /* new value */
11922 char **values, /* array of valid string values */
11923 unsigned *flagp,
11924 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011925{
11926 int i;
11927 int len;
11928 unsigned new_flags = 0;
11929
11930 while (*val)
11931 {
11932 for (i = 0; ; ++i)
11933 {
11934 if (values[i] == NULL) /* val not found in values[] */
11935 return FAIL;
11936
11937 len = (int)STRLEN(values[i]);
11938 if (STRNCMP(values[i], val, len) == 0
11939 && ((list && val[len] == ',') || val[len] == NUL))
11940 {
11941 val += len + (val[len] == ',');
11942 new_flags |= (1 << i);
11943 break; /* check next item in val list */
11944 }
11945 }
11946 }
11947 if (flagp != NULL)
11948 *flagp = new_flags;
11949
11950 return OK;
11951}
11952
11953/*
11954 * Read the 'wildmode' option, fill wim_flags[].
11955 */
11956 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011957check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011958{
11959 char_u new_wim_flags[4];
11960 char_u *p;
11961 int i;
11962 int idx = 0;
11963
11964 for (i = 0; i < 4; ++i)
11965 new_wim_flags[i] = 0;
11966
11967 for (p = p_wim; *p; ++p)
11968 {
11969 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11970 ;
11971 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11972 return FAIL;
11973 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11974 new_wim_flags[idx] |= WIM_LONGEST;
11975 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11976 new_wim_flags[idx] |= WIM_FULL;
11977 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11978 new_wim_flags[idx] |= WIM_LIST;
11979 else
11980 return FAIL;
11981 p += i;
11982 if (*p == NUL)
11983 break;
11984 if (*p == ',')
11985 {
11986 if (idx == 3)
11987 return FAIL;
11988 ++idx;
11989 }
11990 }
11991
11992 /* fill remaining entries with last flag */
11993 while (idx < 3)
11994 {
11995 new_wim_flags[idx + 1] = new_wim_flags[idx];
11996 ++idx;
11997 }
11998
11999 /* only when there are no errors, wim_flags[] is changed */
12000 for (i = 0; i < 4; ++i)
12001 wim_flags[i] = new_wim_flags[i];
12002 return OK;
12003}
12004
12005/*
12006 * Check if backspacing over something is allowed.
12007 */
12008 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012009can_bs(
12010 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012011{
12012 switch (*p_bs)
12013 {
12014 case '2': return TRUE;
12015 case '1': return (what != BS_START);
12016 case '0': return FALSE;
12017 }
12018 return vim_strchr(p_bs, what) != NULL;
12019}
12020
12021/*
12022 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12023 * the file must be considered changed when the value is different.
12024 */
12025 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012026save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012027{
12028 buf->b_start_ffc = *buf->b_p_ff;
12029 buf->b_start_eol = buf->b_p_eol;
12030#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012031 buf->b_start_bomb = buf->b_p_bomb;
12032
Bram Moolenaar071d4272004-06-13 20:20:40 +000012033 /* Only use free/alloc when necessary, they take time. */
12034 if (buf->b_start_fenc == NULL
12035 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12036 {
12037 vim_free(buf->b_start_fenc);
12038 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12039 }
12040#endif
12041}
12042
12043/*
12044 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12045 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012046 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12047 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012048 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012049 * When "ignore_empty" is true don't consider a new, empty buffer to be
12050 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012051 */
12052 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012053file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012054{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012055 /* In a buffer that was never loaded the options are not valid. */
12056 if (buf->b_flags & BF_NEVERLOADED)
12057 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012058 if (ignore_empty
12059 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012060 && buf->b_ml.ml_line_count == 1
12061 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12062 return FALSE;
12063 if (buf->b_start_ffc != *buf->b_p_ff)
12064 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012065 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012066 return TRUE;
12067#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012068 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12069 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070 if (buf->b_start_fenc == NULL)
12071 return (*buf->b_p_fenc != NUL);
12072 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12073#else
12074 return FALSE;
12075#endif
12076}
12077
12078/*
12079 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12080 */
12081 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012082check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012083{
12084 return check_opt_strings(p, p_ff_values, FALSE);
12085}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012086
12087/*
12088 * Return the effective shiftwidth value for current buffer, using the
12089 * 'tabstop' value when 'shiftwidth' is zero.
12090 */
12091 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012092get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012093{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012094 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012095}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012096
12097/*
12098 * Return the effective softtabstop value for the current buffer, using the
12099 * 'tabstop' value when 'softtabstop' is negative.
12100 */
12101 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012102get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012103{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012104 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012105}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012106
12107/*
12108 * Check matchpairs option for "*initc".
12109 * If there is a match set "*initc" to the matching character and "*findc" to
12110 * the opposite character. Set "*backwards" to the direction.
12111 * When "switchit" is TRUE swap the direction.
12112 */
12113 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012114find_mps_values(
12115 int *initc,
12116 int *findc,
12117 int *backwards,
12118 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012119{
12120 char_u *ptr;
12121
12122 ptr = curbuf->b_p_mps;
12123 while (*ptr != NUL)
12124 {
12125#ifdef FEAT_MBYTE
12126 if (has_mbyte)
12127 {
12128 char_u *prev;
12129
12130 if (mb_ptr2char(ptr) == *initc)
12131 {
12132 if (switchit)
12133 {
12134 *findc = *initc;
12135 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12136 *backwards = TRUE;
12137 }
12138 else
12139 {
12140 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12141 *backwards = FALSE;
12142 }
12143 return;
12144 }
12145 prev = ptr;
12146 ptr += mb_ptr2len(ptr) + 1;
12147 if (mb_ptr2char(ptr) == *initc)
12148 {
12149 if (switchit)
12150 {
12151 *findc = *initc;
12152 *initc = mb_ptr2char(prev);
12153 *backwards = FALSE;
12154 }
12155 else
12156 {
12157 *findc = mb_ptr2char(prev);
12158 *backwards = TRUE;
12159 }
12160 return;
12161 }
12162 ptr += mb_ptr2len(ptr);
12163 }
12164 else
12165#endif
12166 {
12167 if (*ptr == *initc)
12168 {
12169 if (switchit)
12170 {
12171 *backwards = TRUE;
12172 *findc = *initc;
12173 *initc = ptr[2];
12174 }
12175 else
12176 {
12177 *backwards = FALSE;
12178 *findc = ptr[2];
12179 }
12180 return;
12181 }
12182 ptr += 2;
12183 if (*ptr == *initc)
12184 {
12185 if (switchit)
12186 {
12187 *backwards = FALSE;
12188 *findc = *initc;
12189 *initc = ptr[-2];
12190 }
12191 else
12192 {
12193 *backwards = TRUE;
12194 *findc = ptr[-2];
12195 }
12196 return;
12197 }
12198 ++ptr;
12199 }
12200 if (*ptr == ',')
12201 ++ptr;
12202 }
12203}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012204
12205#if defined(FEAT_LINEBREAK) || defined(PROTO)
12206/*
12207 * This is called when 'breakindentopt' is changed and when a window is
12208 * initialized.
12209 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012210 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012211briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012212{
12213 char_u *p;
12214 int bri_shift = 0;
12215 long bri_min = 20;
12216 int bri_sbr = FALSE;
12217
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012218 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012219 while (*p != NUL)
12220 {
12221 if (STRNCMP(p, "shift:", 6) == 0
12222 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12223 {
12224 p += 6;
12225 bri_shift = getdigits(&p);
12226 }
12227 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12228 {
12229 p += 4;
12230 bri_min = getdigits(&p);
12231 }
12232 else if (STRNCMP(p, "sbr", 3) == 0)
12233 {
12234 p += 3;
12235 bri_sbr = TRUE;
12236 }
12237 if (*p != ',' && *p != NUL)
12238 return FAIL;
12239 if (*p == ',')
12240 ++p;
12241 }
12242
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012243 wp->w_p_brishift = bri_shift;
12244 wp->w_p_brimin = bri_min;
12245 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012246
12247 return OK;
12248}
12249#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012250
12251/*
12252 * Get the local or global value of 'backupcopy'.
12253 */
12254 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012255get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012256{
12257 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12258}