blob: 7146503eb392130edcf9af631e915a6af53b9474 [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 Moolenaar95ec9d62016-08-12 18:29:59 +0200256#ifdef FEAT_SIGNS
257# define PV_SCL OPT_WIN(WV_SCL)
258#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000259
260/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261typedef enum
262{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000263 PV_NONE = 0,
264 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265} idopt_T;
266
267/*
268 * Options local to a window have a value local to a buffer and global to all
269 * buffers. Indicate this by setting "var" to VAR_WIN.
270 */
271#define VAR_WIN ((char_u *)-1)
272
273/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000274 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275 * Only to be used in option.c!
276 */
277static int p_ai;
278static int p_bin;
279#ifdef FEAT_MBYTE
280static int p_bomb;
281#endif
282#if defined(FEAT_QUICKFIX)
283static char_u *p_bh;
284static char_u *p_bt;
285#endif
286static int p_bl;
287static int p_ci;
288#ifdef FEAT_CINDENT
289static int p_cin;
290static char_u *p_cink;
291static char_u *p_cino;
292#endif
293#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
294static char_u *p_cinw;
295#endif
296#ifdef FEAT_COMMENTS
297static char_u *p_com;
298#endif
299#ifdef FEAT_FOLDING
300static char_u *p_cms;
301#endif
302#ifdef FEAT_INS_EXPAND
303static char_u *p_cpt;
304#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#ifdef FEAT_COMPL_FUNC
306static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000307static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200310static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311static int p_et;
312#ifdef FEAT_MBYTE
313static char_u *p_fenc;
314#endif
315static char_u *p_ff;
316static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000317static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318#ifdef FEAT_AUTOCMD
319static char_u *p_ft;
320#endif
321static long p_iminsert;
322static long p_imsearch;
323#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
324static char_u *p_inex;
325#endif
326#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
327static char_u *p_inde;
328static char_u *p_indk;
329#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000330#if defined(FEAT_EVAL)
331static char_u *p_fex;
332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000333static int p_inf;
334static char_u *p_isk;
335#ifdef FEAT_CRYPT
336static char_u *p_key;
337#endif
338#ifdef FEAT_LISP
339static int p_lisp;
340#endif
341static int p_ml;
342static int p_ma;
343static int p_mod;
344static char_u *p_mps;
345static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000347#ifdef FEAT_TEXTOBJ
348static char_u *p_qe;
349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_ro;
351#ifdef FEAT_SMARTINDENT
352static int p_si;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static long p_sts;
356#if defined(FEAT_SEARCHPATH)
357static char_u *p_sua;
358#endif
359static long p_sw;
360static int p_swf;
361#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000362static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000364#endif
365#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000366static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000367static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000368static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369#endif
370static long p_ts;
371static long p_tw;
372static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200373#ifdef FEAT_PERSISTENT_UNDO
374static int p_udf;
375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376static long p_wm;
377#ifdef FEAT_KEYMAP
378static char_u *p_keymap;
379#endif
380
381/* Saved values for when 'bin' is set. */
382static int p_et_nobin;
383static int p_ml_nobin;
384static long p_tw_nobin;
385static long p_wm_nobin;
386
387/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200388static int p_ai_nopaste;
389static int p_et_nopaste;
390static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000391static long p_tw_nopaste;
392static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000393
394struct vimoption
395{
396 char *fullname; /* full option name */
397 char *shortname; /* permissible abbreviation */
398 long_u flags; /* see below */
399 char_u *var; /* global option: pointer to variable;
400 * window-local option: VAR_WIN;
401 * buffer-local option: global value */
402 idopt_T indir; /* global option: PV_NONE;
403 * local option: indirect option index */
404 char_u *def_val[2]; /* default values for variable (vi and vim) */
405#ifdef FEAT_EVAL
406 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000407# define SCRIPTID_INIT , 0
408#else
409# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410#endif
411};
412
413#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
414#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
415
416/*
417 * Flags
418 */
419#define P_BOOL 0x01 /* the option is boolean */
420#define P_NUM 0x02 /* the option is numeric */
421#define P_STRING 0x04 /* the option is a string */
422#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000423 must use free_string_option() when
424 assigning new value. Not set if default is
425 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
427 never be used for local or hidden options! */
428#define P_NODEFAULT 0x40 /* don't set to default value */
429#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
430 use vim_free() when assigning new value */
431#define P_WAS_SET 0x100 /* option has been set/reset */
432#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
433#define P_VI_DEF 0x400 /* Use Vi default for Vim */
434#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
435
436 /* when option changed, what to display: */
437#define P_RSTAT 0x1000 /* redraw status lines */
438#define P_RWIN 0x2000 /* redraw current window */
439#define P_RBUF 0x4000 /* redraw current buffer */
440#define P_RALL 0x6000 /* redraw all windows */
441#define P_RCLR 0x7000 /* clear and redraw all */
442
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200443#define P_COMMA 0x8000 /* comma separated list */
444#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
445 * commas */
446#define P_NODUP 0x20000L /* don't allow duplicate strings */
447#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000448
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200449#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
450#define P_GETTEXT 0x100000L /* expand default value with _() */
451#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
452#define P_NFNAME 0x400000L /* only normal file name chars allowed */
453#define P_INSECURE 0x800000L /* option was set from a modeline */
454#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000455 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200456#define P_NO_ML 0x2000000L /* not allowed in modeline */
457#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200458 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000459
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000460#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
461
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000462/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
463 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100464#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000465# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000466#else
467# define ISP_LATIN1 (char_u *)"@,161-255"
468#endif
469
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100470/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000471#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100472 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200473 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100474# 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 +0000475#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100476# 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 +0000477#endif
478
Bram Moolenaar071d4272004-06-13 20:20:40 +0000479/*
480 * options[] is initialized here.
481 * The order of the options MUST be alphabetic for ":set all" and findoption().
482 * All option names MUST start with a lowercase letter (for findoption()).
483 * Exception: "t_" options are at the end.
484 * The options with a NULL variable are 'hidden': a set command for them is
485 * ignored and they are not printed.
486 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100487static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000488{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200489 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000490#ifdef FEAT_RIGHTLEFT
491 (char_u *)&p_aleph, PV_NONE,
492#else
493 (char_u *)NULL, PV_NONE,
494#endif
495 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100496#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497 (char_u *)128L,
498#else
499 (char_u *)224L,
500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000501 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
503#if defined(FEAT_GUI) && defined(MACOS_X)
504 (char_u *)&p_antialias, PV_NONE,
505 {(char_u *)FALSE, (char_u *)FALSE}
506#else
507 (char_u *)NULL, PV_NONE,
508 {(char_u *)FALSE, (char_u *)FALSE}
509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000510 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200511 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512#ifdef FEAT_ARABIC
513 (char_u *)VAR_WIN, PV_ARAB,
514#else
515 (char_u *)NULL, PV_NONE,
516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000517 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
519#ifdef FEAT_ARABIC
520 (char_u *)&p_arshape, PV_NONE,
521#else
522 (char_u *)NULL, PV_NONE,
523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000524 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
526#ifdef FEAT_RIGHTLEFT
527 (char_u *)&p_ari, PV_NONE,
528#else
529 (char_u *)NULL, PV_NONE,
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
533#ifdef FEAT_FKMAP
534 (char_u *)&p_altkeymap, PV_NONE,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000538 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
540#if defined(FEAT_MBYTE)
541 (char_u *)&p_ambw, PV_NONE,
542 {(char_u *)"single", (char_u *)0L}
543#else
544 (char_u *)NULL, PV_NONE,
545 {(char_u *)0L, (char_u *)0L}
546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000547 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000548#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"autochdir", "acd", P_BOOL|P_VI_DEF,
550 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552#endif
553 {"autoindent", "ai", P_BOOL|P_VI_DEF,
554 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autoprint", "ap", P_BOOL|P_VI_DEF,
557 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000560 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autowrite", "aw", P_BOOL|P_VI_DEF,
563 (char_u *)&p_aw, 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 {"autowriteall","awa", P_BOOL|P_VI_DEF,
566 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
569 (char_u *)&p_bg, PV_NONE,
570 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100571#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 (char_u *)"dark",
573#else
574 (char_u *)"light",
575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200577 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
581 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200583 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200584 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585#ifdef UNIX
586 {(char_u *)"yes", (char_u *)"auto"}
587#else
588 {(char_u *)"auto", (char_u *)"auto"}
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
592 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000595 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 (char_u *)&p_bex, PV_NONE,
597 {
598#ifdef VMS
599 (char_u *)"_",
600#else
601 (char_u *)"~",
602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200604 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605#ifdef FEAT_WILDIGN
606 (char_u *)&p_bsk, PV_NONE,
607 {(char_u *)"", (char_u *)0L}
608#else
609 (char_u *)NULL, PV_NONE,
610 {(char_u *)0L, (char_u *)0L}
611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613#ifdef FEAT_BEVAL
614 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
615 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
618 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000620# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000621 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000622 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625#endif
626 {"beautify", "bf", P_BOOL|P_VI_DEF,
627 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200629 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
630 (char_u *)&p_bo, PV_NONE,
631 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
633 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
639#ifdef FEAT_MBYTE
640 (char_u *)&p_bomb, PV_BOMB,
641#else
642 (char_u *)NULL, PV_NONE,
643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000644 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
646#ifdef FEAT_LINEBREAK
647 (char_u *)&p_breakat, PV_NONE,
648 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000653 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200654 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
655#ifdef FEAT_LINEBREAK
656 (char_u *)VAR_WIN, PV_BRI,
657 {(char_u *)FALSE, (char_u *)0L}
658#else
659 (char_u *)NULL, PV_NONE,
660 {(char_u *)0L, (char_u *)0L}
661#endif
662 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200663 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
664 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200665#ifdef FEAT_LINEBREAK
666 (char_u *)VAR_WIN, PV_BRIOPT,
667 {(char_u *)"", (char_u *)NULL}
668#else
669 (char_u *)NULL, PV_NONE,
670 {(char_u *)"", (char_u *)NULL}
671#endif
672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
674#ifdef FEAT_BROWSE
675 (char_u *)&p_bsdir, PV_NONE,
676 {(char_u *)"last", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
683#if defined(FEAT_QUICKFIX)
684 (char_u *)&p_bh, PV_BH,
685 {(char_u *)"", (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
692 (char_u *)&p_bl, PV_BL,
693 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
696#if defined(FEAT_QUICKFIX)
697 (char_u *)&p_bt, PV_BT,
698 {(char_u *)"", (char_u *)0L}
699#else
700 (char_u *)NULL, PV_NONE,
701 {(char_u *)0L, (char_u *)0L}
702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000703 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200704 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000705#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 (char_u *)&p_cmp, PV_NONE,
707 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000708#else
709 (char_u *)NULL, PV_NONE,
710 {(char_u *)0L, (char_u *)0L}
711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
714#ifdef FEAT_SEARCHPATH
715 (char_u *)&p_cdpath, PV_NONE,
716 {(char_u *)",,", (char_u *)0L}
717#else
718 (char_u *)NULL, PV_NONE,
719 {(char_u *)0L, (char_u *)0L}
720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"cedit", NULL, P_STRING,
723#ifdef FEAT_CMDWIN
724 (char_u *)&p_cedit, PV_NONE,
725 {(char_u *)"", (char_u *)CTRL_F_STR}
726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
732#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
733 (char_u *)&p_ccv, PV_NONE,
734 {(char_u *)"", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
741#ifdef FEAT_CINDENT
742 (char_u *)&p_cin, PV_CIN,
743#else
744 (char_u *)NULL, PV_NONE,
745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200747 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748#ifdef FEAT_CINDENT
749 (char_u *)&p_cink, PV_CINK,
750 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
751#else
752 (char_u *)NULL, PV_NONE,
753 {(char_u *)0L, (char_u *)0L}
754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000755 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200756 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757#ifdef FEAT_CINDENT
758 (char_u *)&p_cino, PV_CINO,
759#else
760 (char_u *)NULL, PV_NONE,
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200763 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
765 (char_u *)&p_cinw, PV_CINW,
766 {(char_u *)"if,else,while,do,for,switch",
767 (char_u *)0L}
768#else
769 (char_u *)NULL, PV_NONE,
770 {(char_u *)0L, (char_u *)0L}
771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000772 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200773 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774#ifdef FEAT_CLIPBOARD
775 (char_u *)&p_cb, PV_NONE,
776# ifdef FEAT_XCLIPBOARD
777 {(char_u *)"autoselect,exclude:cons\\|linux",
778 (char_u *)0L}
779# else
780 {(char_u *)"", (char_u *)0L}
781# endif
782#else
783 (char_u *)NULL, PV_NONE,
784 {(char_u *)"", (char_u *)0L}
785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
788 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
791#ifdef FEAT_CMDWIN
792 (char_u *)&p_cwh, PV_NONE,
793#else
794 (char_u *)NULL, PV_NONE,
795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000796 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200797 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200798#ifdef FEAT_SYN_HL
799 (char_u *)VAR_WIN, PV_CC,
800#else
801 (char_u *)NULL, PV_NONE,
802#endif
803 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
805 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000806 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200807 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
808 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809#ifdef FEAT_COMMENTS
810 (char_u *)&p_com, PV_COM,
811 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
812 (char_u *)0L}
813#else
814 (char_u *)NULL, PV_NONE,
815 {(char_u *)0L, (char_u *)0L}
816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200818 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819#ifdef FEAT_FOLDING
820 (char_u *)&p_cms, PV_CMS,
821 {(char_u *)"/*%s*/", (char_u *)0L}
822#else
823 (char_u *)NULL, PV_NONE,
824 {(char_u *)0L, (char_u *)0L}
825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000826 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000827 /* P_PRI_MKRC isn't needed here, optval_default()
828 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829 {"compatible", "cp", P_BOOL|P_RALL,
830 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200832 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833#ifdef FEAT_INS_EXPAND
834 (char_u *)&p_cpt, PV_CPT,
835 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
836#else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000840 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200841 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200842#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200843 (char_u *)VAR_WIN, PV_COCU,
844 {(char_u *)"", (char_u *)NULL}
845#else
846 (char_u *)NULL, PV_NONE,
847 {(char_u *)NULL, (char_u *)0L}
848#endif
849 SCRIPTID_INIT},
850 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
851#ifdef FEAT_CONCEAL
852 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200853#else
854 (char_u *)NULL, PV_NONE,
855#endif
856 {(char_u *)0L, (char_u *)0L}
857 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000858 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
859#ifdef FEAT_COMPL_FUNC
860 (char_u *)&p_cfu, PV_CFU,
861 {(char_u *)"", (char_u *)0L}
862#else
863 (char_u *)NULL, PV_NONE,
864 {(char_u *)0L, (char_u *)0L}
865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200867 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000868#ifdef FEAT_INS_EXPAND
869 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000870 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000871#else
872 (char_u *)NULL, PV_NONE,
873 {(char_u *)0L, (char_u *)0L}
874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000875 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000876 {"confirm", "cf", P_BOOL|P_VI_DEF,
877#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
878 (char_u *)&p_confirm, PV_NONE,
879#else
880 (char_u *)NULL, PV_NONE,
881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000884 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
887 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
890 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000891 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
892 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200893 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200894#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200895 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200896 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200897#else
898 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200899 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200900#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200901 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
903#ifdef FEAT_CSCOPE
904 (char_u *)&p_cspc, PV_NONE,
905#else
906 (char_u *)NULL, PV_NONE,
907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000908 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
910#ifdef FEAT_CSCOPE
911 (char_u *)&p_csprg, PV_NONE,
912 {(char_u *)"cscope", (char_u *)0L}
913#else
914 (char_u *)NULL, PV_NONE,
915 {(char_u *)0L, (char_u *)0L}
916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200918 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
920 (char_u *)&p_csqf, PV_NONE,
921 {(char_u *)"", (char_u *)0L}
922#else
923 (char_u *)NULL, PV_NONE,
924 {(char_u *)0L, (char_u *)0L}
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200927 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
928#ifdef FEAT_CSCOPE
929 (char_u *)&p_csre, PV_NONE,
930#else
931 (char_u *)NULL, PV_NONE,
932#endif
933 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
935#ifdef FEAT_CSCOPE
936 (char_u *)&p_cst, PV_NONE,
937#else
938 (char_u *)NULL, PV_NONE,
939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000940 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000941 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
942#ifdef FEAT_CSCOPE
943 (char_u *)&p_csto, PV_NONE,
944#else
945 (char_u *)NULL, PV_NONE,
946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000947 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
949#ifdef FEAT_CSCOPE
950 (char_u *)&p_csverbose, PV_NONE,
951#else
952 (char_u *)NULL, PV_NONE,
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200955 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
956#ifdef FEAT_CURSORBIND
957 (char_u *)VAR_WIN, PV_CRBIND,
958#else
959 (char_u *)NULL, PV_NONE,
960#endif
961 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000962 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
963#ifdef FEAT_SYN_HL
964 (char_u *)VAR_WIN, PV_CUC,
965#else
966 (char_u *)NULL, PV_NONE,
967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000969 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
970#ifdef FEAT_SYN_HL
971 (char_u *)VAR_WIN, PV_CUL,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"debug", NULL, P_STRING|P_VI_DEF,
977 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000978 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200979 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000981 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000982 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983#else
984 (char_u *)NULL, PV_NONE,
985 {(char_u *)NULL, (char_u *)0L}
986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
989#ifdef FEAT_MBYTE
990 (char_u *)&p_deco, PV_NONE,
991#else
992 (char_u *)NULL, PV_NONE,
993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200995 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000997 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#else
999 (char_u *)NULL, PV_NONE,
1000#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001001 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1003#ifdef FEAT_DIFF
1004 (char_u *)VAR_WIN, PV_DIFF,
1005#else
1006 (char_u *)NULL, PV_NONE,
1007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001009 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1011 (char_u *)&p_dex, PV_NONE,
1012 {(char_u *)"", (char_u *)0L}
1013#else
1014 (char_u *)NULL, PV_NONE,
1015 {(char_u *)0L, (char_u *)0L}
1016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001018 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1019 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020#ifdef FEAT_DIFF
1021 (char_u *)&p_dip, PV_NONE,
1022 {(char_u *)"filler", (char_u *)NULL}
1023#else
1024 (char_u *)NULL, PV_NONE,
1025 {(char_u *)"", (char_u *)NULL}
1026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1029#ifdef FEAT_DIGRAPHS
1030 (char_u *)&p_dg, PV_NONE,
1031#else
1032 (char_u *)NULL, PV_NONE,
1033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001034 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001035 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1036 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001039 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001043#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 (char_u *)&p_ead, PV_NONE,
1045 {(char_u *)"both", (char_u *)0L}
1046#else
1047 (char_u *)NULL, PV_NONE,
1048 {(char_u *)NULL, (char_u *)0L}
1049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1052 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001054 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1055#if defined(FEAT_MBYTE)
1056 (char_u *)&p_emoji, PV_NONE,
1057 {(char_u *)TRUE, (char_u *)0L}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)0L, (char_u *)0L}
1061#endif
1062 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001063 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064#ifdef FEAT_MBYTE
1065 (char_u *)&p_enc, PV_NONE,
1066 {(char_u *)ENC_DFLT, (char_u *)0L}
1067#else
1068 (char_u *)NULL, PV_NONE,
1069 {(char_u *)0L, (char_u *)0L}
1070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1073 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1076 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001079 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1082 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1085#ifdef FEAT_QUICKFIX
1086 (char_u *)&p_ef, PV_NONE,
1087 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1088#else
1089 (char_u *)NULL, PV_NONE,
1090 {(char_u *)NULL, (char_u *)0L}
1091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001092 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001093 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001095 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097#else
1098 (char_u *)NULL, PV_NONE,
1099 {(char_u *)NULL, (char_u *)0L}
1100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 {"esckeys", "ek", P_BOOL|P_VIM,
1103 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001105 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106#ifdef FEAT_AUTOCMD
1107 (char_u *)&p_ei, PV_NONE,
1108#else
1109 (char_u *)NULL, PV_NONE,
1110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1113 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1116 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001118 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1119 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120#ifdef FEAT_MBYTE
1121 (char_u *)&p_fenc, PV_FENC,
1122 {(char_u *)"", (char_u *)0L}
1123#else
1124 (char_u *)NULL, PV_NONE,
1125 {(char_u *)0L, (char_u *)0L}
1126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001128 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129#ifdef FEAT_MBYTE
1130 (char_u *)&p_fencs, PV_NONE,
1131 {(char_u *)"ucs-bom", (char_u *)0L}
1132#else
1133 (char_u *)NULL, PV_NONE,
1134 {(char_u *)0L, (char_u *)0L}
1135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001137 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1138 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001141 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1144 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001145 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1146 (char_u *)&p_fic, PV_NONE,
1147 {
1148#ifdef CASE_INSENSITIVE_FILENAME
1149 (char_u *)TRUE,
1150#else
1151 (char_u *)FALSE,
1152#endif
1153 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001154 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155#ifdef FEAT_AUTOCMD
1156 (char_u *)&p_ft, PV_FT,
1157 {(char_u *)"", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)0L, (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1165 (char_u *)&p_fcs, PV_NONE,
1166 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1167#else
1168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)"", (char_u *)0L}
1170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001172 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1173 (char_u *)&p_fixeol, PV_FIXEOL,
1174 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001175 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1176#ifdef FEAT_FKMAP
1177 (char_u *)&p_fkmap, PV_NONE,
1178#else
1179 (char_u *)NULL, PV_NONE,
1180#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"flash", "fl", P_BOOL|P_VI_DEF,
1183 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001185#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001186 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1190 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1193 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1196# ifdef FEAT_EVAL
1197 (char_u *)VAR_WIN, PV_FDE,
1198 {(char_u *)"0", (char_u *)NULL}
1199# else
1200 (char_u *)NULL, PV_NONE,
1201 {(char_u *)NULL, (char_u *)0L}
1202# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1205 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1208 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001210 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001214 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)"{{{,}}}", (char_u *)NULL}
1217 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1219 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1225 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001227 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 (char_u *)&p_fdo, PV_NONE,
1229 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1232# ifdef FEAT_EVAL
1233 (char_u *)VAR_WIN, PV_FDT,
1234 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001235# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236 (char_u *)NULL, PV_NONE,
1237 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001238# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001239 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001240#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001241 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001242#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001243 (char_u *)&p_fex, PV_FEX,
1244 {(char_u *)"", (char_u *)0L}
1245#else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)0L, (char_u *)0L}
1248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1251 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001252 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1253 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001254 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1255 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1257 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1259 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001261 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1262#ifdef HAVE_FSYNC
1263 (char_u *)&p_fs, PV_NONE,
1264 {(char_u *)TRUE, (char_u *)0L}
1265#else
1266 (char_u *)NULL, PV_NONE,
1267 {(char_u *)FALSE, (char_u *)0L}
1268#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1271 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 {"graphic", "gr", P_BOOL|P_VI_DEF,
1274 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001276 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277#ifdef FEAT_QUICKFIX
1278 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001279 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280#else
1281 (char_u *)NULL, PV_NONE,
1282 {(char_u *)NULL, (char_u *)0L}
1283#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1286#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001287 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 {
1289# ifdef WIN3264
1290 /* may be changed to "grep -n" in os_win32.c */
1291 (char_u *)"findstr /n",
1292# else
1293# ifdef UNIX
1294 /* Add an extra file name so that grep will always
1295 * insert a file name in the match line. */
1296 (char_u *)"grep -n $* /dev/null",
1297# else
1298# ifdef VMS
1299 (char_u *)"SEARCH/NUMBERS ",
1300# else
1301 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001302# endif
1303# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001305 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306#else
1307 (char_u *)NULL, PV_NONE,
1308 {(char_u *)NULL, (char_u *)0L}
1309#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001310 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001311 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001312#ifdef CURSOR_SHAPE
1313 (char_u *)&p_guicursor, PV_NONE,
1314 {
1315# ifdef FEAT_GUI
1316 (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 +01001317# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1319# endif
1320 (char_u *)0L}
1321#else
1322 (char_u *)NULL, PV_NONE,
1323 {(char_u *)NULL, (char_u *)0L}
1324#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001325 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001326 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327#ifdef FEAT_GUI
1328 (char_u *)&p_guifont, PV_NONE,
1329 {(char_u *)"", (char_u *)0L}
1330#else
1331 (char_u *)NULL, PV_NONE,
1332 {(char_u *)NULL, (char_u *)0L}
1333#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001334 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001335 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1337 (char_u *)&p_guifontset, PV_NONE,
1338 {(char_u *)"", (char_u *)0L}
1339#else
1340 (char_u *)NULL, PV_NONE,
1341 {(char_u *)NULL, (char_u *)0L}
1342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001344 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001345#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1346 (char_u *)&p_guifontwide, PV_NONE,
1347 {(char_u *)"", (char_u *)0L}
1348#else
1349 (char_u *)NULL, PV_NONE,
1350 {(char_u *)NULL, (char_u *)0L}
1351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001354#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001355 (char_u *)&p_ghr, PV_NONE,
1356#else
1357 (char_u *)NULL, PV_NONE,
1358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001361#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 (char_u *)&p_go, PV_NONE,
1363# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001364 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001366 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367# endif
1368#else
1369 (char_u *)NULL, PV_NONE,
1370 {(char_u *)NULL, (char_u *)0L}
1371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001372 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373 {"guipty", NULL, P_BOOL|P_VI_DEF,
1374#if defined(FEAT_GUI)
1375 (char_u *)&p_guipty, PV_NONE,
1376#else
1377 (char_u *)NULL, PV_NONE,
1378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001380 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001381#if defined(FEAT_GUI_TABLINE)
1382 (char_u *)&p_gtl, PV_NONE,
1383 {(char_u *)"", (char_u *)0L}
1384#else
1385 (char_u *)NULL, PV_NONE,
1386 {(char_u *)NULL, (char_u *)0L}
1387#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001389 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001390#if defined(FEAT_GUI_TABLINE)
1391 (char_u *)&p_gtt, PV_NONE,
1392 {(char_u *)"", (char_u *)0L}
1393#else
1394 (char_u *)NULL, PV_NONE,
1395 {(char_u *)NULL, (char_u *)0L}
1396#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1399 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1402 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1404 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 {"helpheight", "hh", P_NUM|P_VI_DEF,
1406#ifdef FEAT_WINDOWS
1407 (char_u *)&p_hh, PV_NONE,
1408#else
1409 (char_u *)NULL, PV_NONE,
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001412 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413#ifdef FEAT_MULTI_LANG
1414 (char_u *)&p_hlg, PV_NONE,
1415 {(char_u *)"", (char_u *)0L}
1416#else
1417 (char_u *)NULL, PV_NONE,
1418 {(char_u *)0L, (char_u *)0L}
1419#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001420 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001421 {"hidden", "hid", P_BOOL|P_VI_DEF,
1422 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001424 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1427 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"history", "hi", P_NUM|P_VIM,
1429 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001430 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1432#ifdef FEAT_RIGHTLEFT
1433 (char_u *)&p_hkmap, PV_NONE,
1434#else
1435 (char_u *)NULL, PV_NONE,
1436#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1439#ifdef FEAT_RIGHTLEFT
1440 (char_u *)&p_hkmapp, PV_NONE,
1441#else
1442 (char_u *)NULL, PV_NONE,
1443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1446 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"icon", NULL, P_BOOL|P_VI_DEF,
1449#ifdef FEAT_TITLE
1450 (char_u *)&p_icon, PV_NONE,
1451#else
1452 (char_u *)NULL, PV_NONE,
1453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001454 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"iconstring", NULL, P_STRING|P_VI_DEF,
1456#ifdef FEAT_TITLE
1457 (char_u *)&p_iconstring, PV_NONE,
1458#else
1459 (char_u *)NULL, PV_NONE,
1460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1463 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001465 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1466# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1467 (char_u *)&p_imaf, PV_NONE,
1468 {(char_u *)"", (char_u *)NULL}
1469# else
1470 (char_u *)NULL, PV_NONE,
1471 {(char_u *)NULL, (char_u *)0L}
1472# endif
1473 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001475#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 (char_u *)&p_imak, PV_NONE,
1477#else
1478 (char_u *)NULL, PV_NONE,
1479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1482#ifdef USE_IM_CONTROL
1483 (char_u *)&p_imcmdline, PV_NONE,
1484#else
1485 (char_u *)NULL, PV_NONE,
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1489#ifdef USE_IM_CONTROL
1490 (char_u *)&p_imdisable, PV_NONE,
1491#else
1492 (char_u *)NULL, PV_NONE,
1493#endif
1494#ifdef __sgi
1495 {(char_u *)TRUE, (char_u *)0L}
1496#else
1497 {(char_u *)FALSE, (char_u *)0L}
1498#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"iminsert", "imi", P_NUM|P_VI_DEF,
1501 (char_u *)&p_iminsert, PV_IMI,
1502#ifdef B_IMODE_IM
1503 {(char_u *)B_IMODE_IM, (char_u *)0L}
1504#else
1505 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001507 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"imsearch", "ims", P_NUM|P_VI_DEF,
1509 (char_u *)&p_imsearch, PV_IMS,
1510#ifdef B_IMODE_IM
1511 {(char_u *)B_IMODE_IM, (char_u *)0L}
1512#else
1513 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001516 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001517# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1518 (char_u *)&p_imsf, PV_NONE,
1519 {(char_u *)"", (char_u *)NULL}
1520# else
1521 (char_u *)NULL, PV_NONE,
1522 {(char_u *)NULL, (char_u *)0L}
1523# endif
1524 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1526#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001527 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1529#else
1530 (char_u *)NULL, PV_NONE,
1531 {(char_u *)0L, (char_u *)0L}
1532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001533 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001534 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1535#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1536 (char_u *)&p_inex, PV_INEX,
1537 {(char_u *)"", (char_u *)0L}
1538#else
1539 (char_u *)NULL, PV_NONE,
1540 {(char_u *)0L, (char_u *)0L}
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1544 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1547#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1548 (char_u *)&p_inde, PV_INDE,
1549 {(char_u *)"", (char_u *)0L}
1550#else
1551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)0L, (char_u *)0L}
1553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001555 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001556#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1557 (char_u *)&p_indk, PV_INDK,
1558 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1559#else
1560 (char_u *)NULL, PV_NONE,
1561 {(char_u *)0L, (char_u *)0L}
1562#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"infercase", "inf", P_BOOL|P_VI_DEF,
1565 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1568 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1571 (char_u *)&p_isf, PV_NONE,
1572 {
1573#ifdef BACKSLASH_IN_FILENAME
1574 /* Excluded are: & and ^ are special in cmd.exe
1575 * ( and ) are used in text separating fnames */
1576 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1577#else
1578# ifdef AMIGA
1579 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1580# else
1581# ifdef VMS
1582 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1583# else /* UNIX et al. */
1584# ifdef EBCDIC
1585 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1586# else
1587 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1588# endif
1589# endif
1590# endif
1591#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001592 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1594 (char_u *)&p_isi, PV_NONE,
1595 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001596#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001597 (char_u *)"@,48-57,_,128-167,224-235",
1598#else
1599# ifdef EBCDIC
1600 /* TODO: EBCDIC Check this! @ == isalpha()*/
1601 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1602 "112-120,128,140-142,156,158,172,"
1603 "174,186,191,203-207,219-225,235-239,"
1604 "251-254",
1605# else
1606 (char_u *)"@,48-57,_,192-255",
1607# endif
1608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001609 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001610 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1611 (char_u *)&p_isk, PV_ISK,
1612 {
1613#ifdef EBCDIC
1614 (char_u *)"@,240-249,_",
1615 /* TODO: EBCDIC Check this! @ == isalpha()*/
1616 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1617 "112-120,128,140-142,156,158,172,"
1618 "174,186,191,203-207,219-225,235-239,"
1619 "251-254",
1620#else
1621 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001622# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 (char_u *)"@,48-57,_,128-167,224-235"
1624# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001625 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626# endif
1627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001628 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1630 (char_u *)&p_isp, PV_NONE,
1631 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001632#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633 || defined(VMS)
1634 (char_u *)"@,~-255",
1635#else
1636# ifdef EBCDIC
1637 /* all chars above 63 are printable */
1638 (char_u *)"63-255",
1639# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001640 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641# endif
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1645 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1648#ifdef FEAT_CRYPT
1649 (char_u *)&p_key, PV_KEY,
1650 {(char_u *)"", (char_u *)0L}
1651#else
1652 (char_u *)NULL, PV_NONE,
1653 {(char_u *)0L, (char_u *)0L}
1654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001656 {"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 +00001657#ifdef FEAT_KEYMAP
1658 (char_u *)&p_keymap, PV_KMAP,
1659 {(char_u *)"", (char_u *)0L}
1660#else
1661 (char_u *)NULL, PV_NONE,
1662 {(char_u *)"", (char_u *)0L}
1663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001665 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001669 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001671#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 (char_u *)":help",
1673#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001674# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001676# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001677# ifdef USEMAN_S
1678 (char_u *)"man -s",
1679# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001680 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001681# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682# endif
1683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001684 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001685 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686#ifdef FEAT_LANGMAP
1687 (char_u *)&p_langmap, PV_NONE,
1688 {(char_u *)"", /* unmatched } */
1689#else
1690 (char_u *)NULL, PV_NONE,
1691 {(char_u *)NULL,
1692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001693 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001694 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1696 (char_u *)&p_lm, PV_NONE,
1697#else
1698 (char_u *)NULL, PV_NONE,
1699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001700 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001701 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1702#ifdef FEAT_LANGMAP
1703 (char_u *)&p_lnr, PV_NONE,
1704#else
1705 (char_u *)NULL, PV_NONE,
1706#endif
1707 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1709#ifdef FEAT_WINDOWS
1710 (char_u *)&p_ls, PV_NONE,
1711#else
1712 (char_u *)NULL, PV_NONE,
1713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1716 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001717 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1719#ifdef FEAT_LINEBREAK
1720 (char_u *)VAR_WIN, PV_LBR,
1721#else
1722 (char_u *)NULL, PV_NONE,
1723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1726 (char_u *)&Rows, PV_NONE,
1727 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001728#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 (char_u *)25L,
1730#else
1731 (char_u *)24L,
1732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001733 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1735#ifdef FEAT_GUI
1736 (char_u *)&p_linespace, PV_NONE,
1737#else
1738 (char_u *)NULL, PV_NONE,
1739#endif
1740#ifdef FEAT_GUI_W32
1741 {(char_u *)1L, (char_u *)0L}
1742#else
1743 {(char_u *)0L, (char_u *)0L}
1744#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"lisp", NULL, P_BOOL|P_VI_DEF,
1747#ifdef FEAT_LISP
1748 (char_u *)&p_lisp, PV_LISP,
1749#else
1750 (char_u *)NULL, PV_NONE,
1751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001753 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001755 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1757#else
1758 (char_u *)NULL, PV_NONE,
1759 {(char_u *)"", (char_u *)0L}
1760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001761 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1763 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001765 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1769 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001771#if defined(DYNAMIC_LUA)
Bram Moolenaara6e42502016-04-20 16:19:52 +02001772 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001773 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001774 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1775 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001776#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001777#ifdef FEAT_GUI_MAC
1778 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1779 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001781#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {"magic", NULL, P_BOOL|P_VI_DEF,
1783 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001785 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786#ifdef FEAT_QUICKFIX
1787 (char_u *)&p_mef, PV_NONE,
1788 {(char_u *)"", (char_u *)0L}
1789#else
1790 (char_u *)NULL, PV_NONE,
1791 {(char_u *)NULL, (char_u *)0L}
1792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1795#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001796 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797# ifdef VMS
1798 {(char_u *)"MMS", (char_u *)0L}
1799# else
1800 {(char_u *)"make", (char_u *)0L}
1801# endif
1802#else
1803 (char_u *)NULL, PV_NONE,
1804 {(char_u *)NULL, (char_u *)0L}
1805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001806 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001807 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001809 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1810 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {"matchtime", "mat", P_NUM|P_VI_DEF,
1812 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001814 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001815#ifdef FEAT_MBYTE
1816 (char_u *)&p_mco, PV_NONE,
1817#else
1818 (char_u *)NULL, PV_NONE,
1819#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1822#ifdef FEAT_EVAL
1823 (char_u *)&p_mfd, PV_NONE,
1824#else
1825 (char_u *)NULL, PV_NONE,
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1829 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 {"maxmem", "mm", P_NUM|P_VI_DEF,
1832 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001833 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1834 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001835 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001838 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1839 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1841 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"menuitems", "mis", P_NUM|P_VI_DEF,
1843#ifdef FEAT_MENU
1844 (char_u *)&p_mis, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"mesg", NULL, P_BOOL|P_VI_DEF,
1850 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001852 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001853#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001854 (char_u *)&p_msm, PV_NONE,
1855 {(char_u *)"460000,2000,500", (char_u *)0L}
1856#else
1857 (char_u *)NULL, PV_NONE,
1858 {(char_u *)0L, (char_u *)0L}
1859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"modeline", "ml", P_BOOL|P_VIM,
1862 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"modelines", "mls", P_NUM|P_VI_DEF,
1865 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1868 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1871 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"more", NULL, P_BOOL|P_VIM,
1874 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1877 (char_u *)&p_mouse, PV_NONE,
1878 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001879#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 (char_u *)"a",
1881#else
1882 (char_u *)"",
1883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001884 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1886#ifdef FEAT_GUI
1887 (char_u *)&p_mousef, PV_NONE,
1888#else
1889 (char_u *)NULL, PV_NONE,
1890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1893#ifdef FEAT_GUI
1894 (char_u *)&p_mh, PV_NONE,
1895#else
1896 (char_u *)NULL, PV_NONE,
1897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1900 (char_u *)&p_mousem, PV_NONE,
1901 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001902#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 (char_u *)"popup",
1904#else
1905# if defined(MACOS)
1906 (char_u *)"popup_setpos",
1907# else
1908 (char_u *)"extend",
1909# endif
1910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001912 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913#ifdef FEAT_MOUSESHAPE
1914 (char_u *)&p_mouseshape, PV_NONE,
1915 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1916#else
1917 (char_u *)NULL, PV_NONE,
1918 {(char_u *)NULL, (char_u *)0L}
1919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1922 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001923 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001924 {"mzquantum", "mzq", P_NUM,
1925#ifdef FEAT_MZSCHEME
1926 (char_u *)&p_mzq, PV_NONE,
1927#else
1928 (char_u *)NULL, PV_NONE,
1929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"novice", NULL, P_BOOL|P_VI_DEF,
1932 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001933 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001934 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001936 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1939 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001941 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1942#ifdef FEAT_LINEBREAK
1943 (char_u *)VAR_WIN, PV_NUW,
1944#else
1945 (char_u *)NULL, PV_NONE,
1946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001948 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001949#ifdef FEAT_COMPL_FUNC
1950 (char_u *)&p_ofu, PV_OFU,
1951 {(char_u *)"", (char_u *)0L}
1952#else
1953 (char_u *)NULL, PV_NONE,
1954 {(char_u *)0L, (char_u *)0L}
1955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 {"open", NULL, P_BOOL|P_VI_DEF,
1958 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001960 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001961#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001962 (char_u *)&p_odev, PV_NONE,
1963#else
1964 (char_u *)NULL, PV_NONE,
1965#endif
1966 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001968 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1969 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"optimize", "opt", P_BOOL|P_VI_DEF,
1972 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001973 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001976 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001977 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1978 |P_SECURE,
1979 (char_u *)&p_pp, PV_NONE,
1980 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
1981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"paragraphs", "para", P_STRING|P_VI_DEF,
1983 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001984 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001986 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1990 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1993#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1994 (char_u *)&p_pex, PV_NONE,
1995 {(char_u *)"", (char_u *)0L}
1996#else
1997 (char_u *)NULL, PV_NONE,
1998 {(char_u *)0L, (char_u *)0L}
1999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002001 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002003 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002005 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002007#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 (char_u *)".,,",
2009#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002013#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002014 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002015 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002016 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2017 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002018#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002019 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2020 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002022 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2024 (char_u *)&p_pvh, PV_NONE,
2025#else
2026 (char_u *)NULL, PV_NONE,
2027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002028 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2030#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2031 (char_u *)VAR_WIN, PV_PVW,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002036 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037#ifdef FEAT_PRINTER
2038 (char_u *)&p_pdev, PV_NONE,
2039 {(char_u *)"", (char_u *)0L}
2040#else
2041 (char_u *)NULL, PV_NONE,
2042 {(char_u *)NULL, (char_u *)0L}
2043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 {"printencoding", "penc", P_STRING|P_VI_DEF,
2046#ifdef FEAT_POSTSCRIPT
2047 (char_u *)&p_penc, PV_NONE,
2048 {(char_u *)"", (char_u *)0L}
2049#else
2050 (char_u *)NULL, PV_NONE,
2051 {(char_u *)NULL, (char_u *)0L}
2052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2055#ifdef FEAT_POSTSCRIPT
2056 (char_u *)&p_pexpr, PV_NONE,
2057 {(char_u *)"", (char_u *)0L}
2058#else
2059 (char_u *)NULL, PV_NONE,
2060 {(char_u *)NULL, (char_u *)0L}
2061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002063 {"printfont", "pfn", P_STRING|P_VI_DEF,
2064#ifdef FEAT_PRINTER
2065 (char_u *)&p_pfn, PV_NONE,
2066 {
2067# ifdef MSWIN
2068 (char_u *)"Courier_New:h10",
2069# else
2070 (char_u *)"courier",
2071# endif
2072 (char_u *)0L}
2073#else
2074 (char_u *)NULL, PV_NONE,
2075 {(char_u *)NULL, (char_u *)0L}
2076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2079#ifdef FEAT_PRINTER
2080 (char_u *)&p_header, PV_NONE,
2081 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2082#else
2083 (char_u *)NULL, PV_NONE,
2084 {(char_u *)NULL, (char_u *)0L}
2085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002087 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2088#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2089 (char_u *)&p_pmcs, PV_NONE,
2090 {(char_u *)"", (char_u *)0L}
2091#else
2092 (char_u *)NULL, PV_NONE,
2093 {(char_u *)NULL, (char_u *)0L}
2094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002096 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2097#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2098 (char_u *)&p_pmfn, PV_NONE,
2099 {(char_u *)"", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)NULL, (char_u *)0L}
2103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002105 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106#ifdef FEAT_PRINTER
2107 (char_u *)&p_popt, PV_NONE,
2108 {(char_u *)"", (char_u *)0L}
2109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)NULL, (char_u *)0L}
2112#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002115 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002117 {"pumheight", "ph", P_NUM|P_VI_DEF,
2118#ifdef FEAT_INS_EXPAND
2119 (char_u *)&p_ph, PV_NONE,
2120#else
2121 (char_u *)NULL, PV_NONE,
2122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002124#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002125 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002126 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002127 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2128 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002129#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002130#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002131 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002132 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002133 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2134 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002135#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002136 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2137#ifdef FEAT_TEXTOBJ
2138 (char_u *)&p_qe, PV_QE,
2139 {(char_u *)"\\", (char_u *)0L}
2140#else
2141 (char_u *)NULL, PV_NONE,
2142 {(char_u *)NULL, (char_u *)0L}
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2146 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002147 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 {"redraw", NULL, P_BOOL|P_VI_DEF,
2149 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002150 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002151 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2152#ifdef FEAT_RELTIME
2153 (char_u *)&p_rdt, PV_NONE,
2154#else
2155 (char_u *)NULL, PV_NONE,
2156#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002158 {"regexpengine", "re", P_NUM|P_VI_DEF,
2159 (char_u *)&p_re, PV_NONE,
2160 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002161 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2162 (char_u *)VAR_WIN, PV_RNU,
2163 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164 {"remap", NULL, P_BOOL|P_VI_DEF,
2165 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002166 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002167 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002168#ifdef FEAT_RENDER_OPTIONS
2169 (char_u *)&p_rop, PV_NONE,
2170 {(char_u *)"", (char_u *)0L}
2171#else
2172 (char_u *)NULL, PV_NONE,
2173 {(char_u *)NULL, (char_u *)0L}
2174#endif
2175 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 {"report", NULL, P_NUM|P_VI_DEF,
2177 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2180#ifdef WIN3264
2181 (char_u *)&p_rs, PV_NONE,
2182#else
2183 (char_u *)NULL, PV_NONE,
2184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2187#ifdef FEAT_RIGHTLEFT
2188 (char_u *)&p_ri, PV_NONE,
2189#else
2190 (char_u *)NULL, PV_NONE,
2191#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2194#ifdef FEAT_RIGHTLEFT
2195 (char_u *)VAR_WIN, PV_RL,
2196#else
2197 (char_u *)NULL, PV_NONE,
2198#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002199 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2201#ifdef FEAT_RIGHTLEFT
2202 (char_u *)VAR_WIN, PV_RLC,
2203 {(char_u *)"search", (char_u *)NULL}
2204#else
2205 (char_u *)NULL, PV_NONE,
2206 {(char_u *)NULL, (char_u *)0L}
2207#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002208 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002209#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002210 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002211 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002212 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2213 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002214#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2216#ifdef FEAT_CMDL_INFO
2217 (char_u *)&p_ru, PV_NONE,
2218#else
2219 (char_u *)NULL, PV_NONE,
2220#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2223#ifdef FEAT_STL_OPT
2224 (char_u *)&p_ruf, PV_NONE,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002229 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2230 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002232 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2233 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2235 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2238#ifdef FEAT_SCROLLBIND
2239 (char_u *)VAR_WIN, PV_SCBIND,
2240#else
2241 (char_u *)NULL, PV_NONE,
2242#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2245 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2248 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002249 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002250 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251#ifdef FEAT_SCROLLBIND
2252 (char_u *)&p_sbo, PV_NONE,
2253 {(char_u *)"ver,jump", (char_u *)0L}
2254#else
2255 (char_u *)NULL, PV_NONE,
2256 {(char_u *)0L, (char_u *)0L}
2257#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002258 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002259 {"sections", "sect", P_STRING|P_VI_DEF,
2260 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002261 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2262 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2264 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)"inclusive", (char_u *)0L}
2269 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002270 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002273 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274#ifdef FEAT_SESSION
2275 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002276 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 (char_u *)0L}
2278#else
2279 (char_u *)NULL, PV_NONE,
2280 {(char_u *)0L, (char_u *)0L}
2281#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2284 (char_u *)&p_sh, PV_NONE,
2285 {
2286#ifdef VMS
2287 (char_u *)"-",
2288#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002289# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002291# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293# endif
2294#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2297 (char_u *)&p_shcf, PV_NONE,
2298 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002299#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 (char_u *)"/c",
2301#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2306#ifdef FEAT_QUICKFIX
2307 (char_u *)&p_sp, PV_NONE,
2308 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002309#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311#else
2312 (char_u *)">",
2313#endif
2314 (char_u *)0L}
2315#else
2316 (char_u *)NULL, PV_NONE,
2317 {(char_u *)0L, (char_u *)0L}
2318#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2321 (char_u *)&p_shq, 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 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2324 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002325 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2327#ifdef BACKSLASH_IN_FILENAME
2328 (char_u *)&p_ssl, PV_NONE,
2329#else
2330 (char_u *)NULL, PV_NONE,
2331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002333 {"shelltemp", "stmp", P_BOOL,
2334 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"shelltype", "st", P_NUM|P_VI_DEF,
2337#ifdef AMIGA
2338 (char_u *)&p_st, PV_NONE,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2344 (char_u *)&p_sxq, PV_NONE,
2345 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002346#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 (char_u *)"\"",
2348#else
2349 (char_u *)"",
2350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002352 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2353 (char_u *)&p_sxe, PV_NONE,
2354 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002355#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002356 (char_u *)"\"&|<>()@^",
2357#else
2358 (char_u *)"",
2359#endif
2360 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2362 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2365 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2368 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)"", (char_u *)"filnxtToO"}
2370 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2375#ifdef FEAT_LINEBREAK
2376 (char_u *)&p_sbr, PV_NONE,
2377#else
2378 (char_u *)NULL, PV_NONE,
2379#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"showcmd", "sc", P_BOOL|P_VIM,
2382#ifdef FEAT_CMDL_INFO
2383 (char_u *)&p_sc, PV_NONE,
2384#else
2385 (char_u *)NULL, PV_NONE,
2386#endif
2387 {(char_u *)FALSE,
2388#ifdef UNIX
2389 (char_u *)FALSE
2390#else
2391 (char_u *)TRUE
2392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2395 (char_u *)&p_sft, 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 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2398 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"showmode", "smd", P_BOOL|P_VIM,
2401 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002403 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2404#ifdef FEAT_WINDOWS
2405 (char_u *)&p_stal, PV_NONE,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2411 (char_u *)&p_ss, 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 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2414 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002416 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2417#ifdef FEAT_SIGNS
2418 (char_u *)VAR_WIN, PV_SCL,
2419 {(char_u *)"auto", (char_u *)0L} SCRIPTID_INIT},
2420#else
2421 (char_u *)NULL, PV_NONE,
2422 {(char_u *)NULL, (char_u *)0L}
2423#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2425 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2428 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2431#ifdef FEAT_SMARTINDENT
2432 (char_u *)&p_si, PV_SI,
2433#else
2434 (char_u *)NULL, PV_NONE,
2435#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2438 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2441 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2444 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002446 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002447#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002448 (char_u *)VAR_WIN, PV_SPELL,
2449#else
2450 (char_u *)NULL, PV_NONE,
2451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002453 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002454#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002455 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002456 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002457#else
2458 (char_u *)NULL, PV_NONE,
2459 {(char_u *)0L, (char_u *)0L}
2460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002462 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2463 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002464#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002465 (char_u *)&p_spf, PV_SPF,
2466 {(char_u *)"", (char_u *)0L}
2467#else
2468 (char_u *)NULL, PV_NONE,
2469 {(char_u *)0L, (char_u *)0L}
2470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002471 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002472 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2473 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002474#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002475 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002476 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002477#else
2478 (char_u *)NULL, PV_NONE,
2479 {(char_u *)0L, (char_u *)0L}
2480#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002482 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002483#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002484 (char_u *)&p_sps, PV_NONE,
2485 {(char_u *)"best", (char_u *)0L}
2486#else
2487 (char_u *)NULL, PV_NONE,
2488 {(char_u *)0L, (char_u *)0L}
2489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002490 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2492#ifdef FEAT_WINDOWS
2493 (char_u *)&p_sb, PV_NONE,
2494#else
2495 (char_u *)NULL, PV_NONE,
2496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002499#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 (char_u *)&p_spr, PV_NONE,
2501#else
2502 (char_u *)NULL, PV_NONE,
2503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2506 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2509#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002510 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511#else
2512 (char_u *)NULL, PV_NONE,
2513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002515 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 (char_u *)&p_su, PV_NONE,
2517 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002519 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002520#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 (char_u *)&p_sua, PV_SUA,
2522 {(char_u *)"", (char_u *)0L}
2523#else
2524 (char_u *)NULL, PV_NONE,
2525 {(char_u *)0L, (char_u *)0L}
2526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2529 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002530 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"swapsync", "sws", P_STRING|P_VI_DEF,
2532 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002534 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002537 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2538#ifdef FEAT_SYN_HL
2539 (char_u *)&p_smc, PV_SMC,
2540 {(char_u *)3000L, (char_u *)0L}
2541#else
2542 (char_u *)NULL, PV_NONE,
2543 {(char_u *)0L, (char_u *)0L}
2544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002546 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547#ifdef FEAT_SYN_HL
2548 (char_u *)&p_syn, PV_SYN,
2549 {(char_u *)"", (char_u *)0L}
2550#else
2551 (char_u *)NULL, PV_NONE,
2552 {(char_u *)0L, (char_u *)0L}
2553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002554 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002555 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2556#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002557 (char_u *)&p_tal, PV_NONE,
2558#else
2559 (char_u *)NULL, PV_NONE,
2560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002562 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2563#ifdef FEAT_WINDOWS
2564 (char_u *)&p_tpm, PV_NONE,
2565#else
2566 (char_u *)NULL, PV_NONE,
2567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2570 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2573 (char_u *)&p_tbs, PV_NONE,
2574#ifdef VMS /* binary searching doesn't appear to work on VMS */
2575 {(char_u *)0L, (char_u *)0L}
2576#else
2577 {(char_u *)TRUE, (char_u *)0L}
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002580 {"tagcase", "tc", P_STRING|P_VIM,
2581 (char_u *)&p_tc, PV_TC,
2582 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"taglength", "tl", P_NUM|P_VI_DEF,
2584 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"tagrelative", "tr", P_BOOL|P_VIM,
2587 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002589 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002590 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {
2592#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2593 (char_u *)"./tags,./TAGS,tags,TAGS",
2594#else
2595 (char_u *)"./tags,tags",
2596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2599 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002601#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002602 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002603 (char_u *)&p_tcldll, PV_NONE,
2604 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2605 SCRIPTID_INIT},
2606#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2608 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2611#ifdef FEAT_ARABIC
2612 (char_u *)&p_tbidi, PV_NONE,
2613#else
2614 (char_u *)NULL, PV_NONE,
2615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2618#ifdef FEAT_MBYTE
2619 (char_u *)&p_tenc, PV_NONE,
2620 {(char_u *)"", (char_u *)0L}
2621#else
2622 (char_u *)NULL, PV_NONE,
2623 {(char_u *)0L, (char_u *)0L}
2624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002625 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002626 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2627#ifdef FEAT_TERMGUICOLORS
2628 (char_u *)&p_tgc, PV_NONE,
2629 {(char_u *)FALSE, (char_u *)FALSE}
2630#else
2631 (char_u*)NULL, PV_NONE,
2632 {(char_u *)FALSE, (char_u *)FALSE}
2633#endif
2634 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 {"terse", NULL, P_BOOL|P_VI_DEF,
2636 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 {"textauto", "ta", P_BOOL|P_VIM,
2639 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002640 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2641 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2643 (char_u *)&p_tx, PV_TX,
2644 {
2645#ifdef USE_CRNL
2646 (char_u *)TRUE,
2647#else
2648 (char_u *)FALSE,
2649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002651 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002654 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002656 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657#else
2658 (char_u *)NULL, PV_NONE,
2659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2662 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"timeout", "to", P_BOOL|P_VI_DEF,
2665 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002666 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2668 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"title", NULL, P_BOOL|P_VI_DEF,
2671#ifdef FEAT_TITLE
2672 (char_u *)&p_title, PV_NONE,
2673#else
2674 (char_u *)NULL, PV_NONE,
2675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"titlelen", NULL, P_NUM|P_VI_DEF,
2678#ifdef FEAT_TITLE
2679 (char_u *)&p_titlelen, PV_NONE,
2680#else
2681 (char_u *)NULL, PV_NONE,
2682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002684 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685#ifdef FEAT_TITLE
2686 (char_u *)&p_titleold, PV_NONE,
2687 {(char_u *)N_("Thanks for flying Vim"),
2688 (char_u *)0L}
2689#else
2690 (char_u *)NULL, PV_NONE,
2691 {(char_u *)0L, (char_u *)0L}
2692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002693 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 {"titlestring", NULL, P_STRING|P_VI_DEF,
2695#ifdef FEAT_TITLE
2696 (char_u *)&p_titlestring, PV_NONE,
2697#else
2698 (char_u *)NULL, PV_NONE,
2699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002700 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002702 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)"icons,tooltips", (char_u *)0L}
2705 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002707#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2709 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711#endif
2712 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2713 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2716 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2719 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2722 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2725#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2726 (char_u *)&p_ttym, PV_NONE,
2727#else
2728 (char_u *)NULL, PV_NONE,
2729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2732 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002733 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2735 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002736 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002737 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2738 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002739#ifdef FEAT_PERSISTENT_UNDO
2740 (char_u *)&p_udir, PV_NONE,
2741 {(char_u *)".", (char_u *)0L}
2742#else
2743 (char_u *)NULL, PV_NONE,
2744 {(char_u *)0L, (char_u *)0L}
2745#endif
2746 SCRIPTID_INIT},
2747 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2748#ifdef FEAT_PERSISTENT_UNDO
2749 (char_u *)&p_udf, PV_UDF,
2750#else
2751 (char_u *)NULL, PV_NONE,
2752#endif
2753 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002755 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002757#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 (char_u *)1000L,
2759#else
2760 (char_u *)100L,
2761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002762 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002763 {"undoreload", "ur", P_NUM|P_VI_DEF,
2764 (char_u *)&p_ur, PV_NONE,
2765 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 {"updatecount", "uc", P_NUM|P_VI_DEF,
2767 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 {"updatetime", "ut", P_NUM|P_VI_DEF,
2770 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"verbose", "vbs", P_NUM|P_VI_DEF,
2773 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002774 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002775 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2776 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2779#ifdef FEAT_SESSION
2780 (char_u *)&p_vdir, PV_NONE,
2781 {(char_u *)DFLT_VDIR, (char_u *)0L}
2782#else
2783 (char_u *)NULL, PV_NONE,
2784 {(char_u *)0L, (char_u *)0L}
2785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002787 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788#ifdef FEAT_SESSION
2789 (char_u *)&p_vop, PV_NONE,
2790 {(char_u *)"folds,options,cursor", (char_u *)0L}
2791#else
2792 (char_u *)NULL, PV_NONE,
2793 {(char_u *)0L, (char_u *)0L}
2794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002796 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797#ifdef FEAT_VIMINFO
2798 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002799#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002800 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801#else
2802# ifdef AMIGA
2803 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002804 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002806 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807# endif
2808#endif
2809#else
2810 (char_u *)NULL, PV_NONE,
2811 {(char_u *)0L, (char_u *)0L}
2812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002814 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2815 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816#ifdef FEAT_VIRTUALEDIT
2817 (char_u *)&p_ve, PV_NONE,
2818 {(char_u *)"", (char_u *)""}
2819#else
2820 (char_u *)NULL, PV_NONE,
2821 {(char_u *)0L, (char_u *)0L}
2822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002823 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2825 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"w300", NULL, P_NUM|P_VI_DEF,
2828 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"w1200", NULL, P_NUM|P_VI_DEF,
2831 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"w9600", NULL, P_NUM|P_VI_DEF,
2834 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002835 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"warn", NULL, P_BOOL|P_VI_DEF,
2837 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2840 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002842 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 {"wildchar", "wc", P_NUM|P_VIM,
2846 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002847 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2848 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002849 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002851 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002852 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853#ifdef FEAT_WILDIGN
2854 (char_u *)&p_wig, PV_NONE,
2855#else
2856 (char_u *)NULL, PV_NONE,
2857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002859 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2860 (char_u *)&p_wic, PV_NONE,
2861 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2863#ifdef FEAT_WILDMENU
2864 (char_u *)&p_wmnu, PV_NONE,
2865#else
2866 (char_u *)NULL, PV_NONE,
2867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002868 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002869 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002872 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2873#ifdef FEAT_CMDL_COMPL
2874 (char_u *)&p_wop, PV_NONE,
2875 {(char_u *)"", (char_u *)0L}
2876#else
2877 (char_u *)NULL, PV_NONE,
2878 {(char_u *)NULL, (char_u *)0L}
2879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002880 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2882#ifdef FEAT_WAK
2883 (char_u *)&p_wak, PV_NONE,
2884 {(char_u *)"menu", (char_u *)0L}
2885#else
2886 (char_u *)NULL, PV_NONE,
2887 {(char_u *)NULL, (char_u *)0L}
2888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002889 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002891 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002892 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 {"winheight", "wh", P_NUM|P_VI_DEF,
2894#ifdef FEAT_WINDOWS
2895 (char_u *)&p_wh, PV_NONE,
2896#else
2897 (char_u *)NULL, PV_NONE,
2898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002899 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002901#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902 (char_u *)VAR_WIN, PV_WFH,
2903#else
2904 (char_u *)NULL, PV_NONE,
2905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002907 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002908#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002909 (char_u *)VAR_WIN, PV_WFW,
2910#else
2911 (char_u *)NULL, PV_NONE,
2912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002913 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2915#ifdef FEAT_WINDOWS
2916 (char_u *)&p_wmh, PV_NONE,
2917#else
2918 (char_u *)NULL, PV_NONE,
2919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002922#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 (char_u *)&p_wmw, PV_NONE,
2924#else
2925 (char_u *)NULL, PV_NONE,
2926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002929#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 (char_u *)&p_wiw, PV_NONE,
2931#else
2932 (char_u *)NULL, PV_NONE,
2933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2936 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002937 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2939 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002940 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2942 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002943 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 {"write", NULL, P_BOOL|P_VI_DEF,
2945 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002946 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 {"writeany", "wa", P_BOOL|P_VI_DEF,
2948 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002949 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2951 (char_u *)&p_wb, PV_NONE,
2952 {
2953#ifdef FEAT_WRITEBACKUP
2954 (char_u *)TRUE,
2955#else
2956 (char_u *)FALSE,
2957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002958 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959 {"writedelay", "wd", P_NUM|P_VI_DEF,
2960 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002961 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962
2963/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002964#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002966 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967
2968 p_term("t_AB", T_CAB)
2969 p_term("t_AF", T_CAF)
2970 p_term("t_AL", T_CAL)
2971 p_term("t_al", T_AL)
2972 p_term("t_bc", T_BC)
2973 p_term("t_cd", T_CD)
2974 p_term("t_ce", T_CE)
2975 p_term("t_cl", T_CL)
2976 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002977 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978 p_term("t_Co", T_CCO)
2979 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002980 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002982#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 p_term("t_CV", T_CSV)
2984#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 p_term("t_da", T_DA)
2986 p_term("t_db", T_DB)
2987 p_term("t_DL", T_CDL)
2988 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002989 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 p_term("t_fs", T_FS)
2991 p_term("t_IE", T_CIE)
2992 p_term("t_IS", T_CIS)
2993 p_term("t_ke", T_KE)
2994 p_term("t_ks", T_KS)
2995 p_term("t_le", T_LE)
2996 p_term("t_mb", T_MB)
2997 p_term("t_md", T_MD)
2998 p_term("t_me", T_ME)
2999 p_term("t_mr", T_MR)
3000 p_term("t_ms", T_MS)
3001 p_term("t_nd", T_ND)
3002 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003003 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 p_term("t_RI", T_CRI)
3005 p_term("t_RV", T_CRV)
3006 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003008 p_term("t_Sf", T_CSF)
3009 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003011 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013 p_term("t_te", T_TE)
3014 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003015 p_term("t_ts", T_TS)
3016 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 p_term("t_ue", T_UE)
3018 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003019 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 p_term("t_vb", T_VB)
3021 p_term("t_ve", T_VE)
3022 p_term("t_vi", T_VI)
3023 p_term("t_vs", T_VS)
3024 p_term("t_WP", T_CWP)
3025 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003026 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 p_term("t_xs", T_XS)
3028 p_term("t_ZH", T_CZH)
3029 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003030 p_term("t_8f", T_8F)
3031 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032
3033/* terminal key codes are not in here */
3034
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003035 /* end marker */
3036 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037};
3038
3039#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3040
3041#ifdef FEAT_MBYTE
3042static char *(p_ambw_values[]) = {"single", "double", NULL};
3043#endif
3044static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003045static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003047#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003048static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003049#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003050#ifdef FEAT_CMDL_COMPL
3051static char *(p_wop_values[]) = {"tagfile", NULL};
3052#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053#ifdef FEAT_WAK
3054static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3055#endif
3056static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3058static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060#ifdef FEAT_BROWSE
3061static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3062#endif
3063#ifdef FEAT_SCROLLBIND
3064static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3065#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003066static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003067#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3069#endif
3070#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003071# ifdef FEAT_AUTOCMD
3072static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3073# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003075# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3077#endif
3078static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3079#ifdef FEAT_FOLDING
3080static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003081# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003083# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 NULL};
3085static char *(p_fcl_values[]) = {"all", NULL};
3086#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003087#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003088static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003089#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003090#ifdef FEAT_SIGNS
3091static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3092#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003094static void set_option_default(int, int opt_flags, int compatible);
3095static void set_options_default(int opt_flags);
3096static char_u *term_bg_default(void);
3097static void did_set_option(int opt_idx, int opt_flags, int new_value);
3098static char_u *illegal_char(char_u *, int);
3099static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003101static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102#endif
3103#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003104static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003106static char_u *option_expand(int opt_idx, char_u *val);
3107static void didset_options(void);
3108static void didset_options2(void);
3109static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003110#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003111static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003112#else
3113# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3114#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003115static void set_string_option_global(int opt_idx, char_u **varp);
3116static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3117static 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);
3118static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003119#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003120static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003121#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003123static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003125#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003126static char_u *did_set_spell_option(int is_spellfile);
3127static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003128#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003129#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003130static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003131#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003132static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3133static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3134static void check_redraw(long_u flags);
3135static int findoption(char_u *);
3136static int find_key_option(char_u *);
3137static void showoptions(int all, int opt_flags);
3138static int optval_default(struct vimoption *, char_u *varp);
3139static void showoneopt(struct vimoption *, int opt_flags);
3140static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3141static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3142static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3143static int istermoption(struct vimoption *);
3144static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3145static char_u *get_varp(struct vimoption *);
3146static void option_value2string(struct vimoption *, int opt_flags);
3147static void check_winopt(winopt_T *wop);
3148static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003150static void langmap_init(void);
3151static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003153static void paste_option_changed(void);
3154static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003156static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003158static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3159static int check_opt_strings(char_u *val, char **values, int);
3160static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003161#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003162static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164
3165/*
3166 * Initialize the options, first part.
3167 *
3168 * Called only once from main(), just after creating the first buffer.
3169 */
3170 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003171set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172{
3173 char_u *p;
3174 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003175 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176
3177#ifdef FEAT_LANGMAP
3178 langmap_init();
3179#endif
3180
3181 /* Be Vi compatible by default */
3182 p_cp = TRUE;
3183
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003184 /* Use POSIX compatibility when $VIM_POSIX is set. */
3185 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003186 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003187 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003188 set_string_default("shm", (char_u *)"A");
3189 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003190
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 /*
3192 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003193 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003195 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003196#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003197 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003199 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200# endif
3201#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003202 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203 set_string_default("sh", p);
3204
3205#ifdef FEAT_WILDIGN
3206 /*
3207 * Set the default for 'backupskip' to include environment variables for
3208 * temp files.
3209 */
3210 {
3211# ifdef UNIX
3212 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3213# else
3214 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3215# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003216 int len;
3217 garray_T ga;
3218 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219
3220 ga_init2(&ga, 1, 100);
3221 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3222 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003223 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224# ifdef UNIX
3225 if (*names[n] == NUL)
3226 p = (char_u *)"/tmp";
3227 else
3228# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003229 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230 if (p != NULL && *p != NUL)
3231 {
3232 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003233 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234 if (ga_grow(&ga, len) == OK)
3235 {
3236 if (ga.ga_len > 0)
3237 STRCAT(ga.ga_data, ",");
3238 STRCAT(ga.ga_data, p);
3239 add_pathsep(ga.ga_data);
3240 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241 ga.ga_len += len;
3242 }
3243 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003244 if (mustfree)
3245 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 }
3247 if (ga.ga_data != NULL)
3248 {
3249 set_string_default("bsk", ga.ga_data);
3250 vim_free(ga.ga_data);
3251 }
3252 }
3253#endif
3254
3255 /*
3256 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3257 */
3258 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003261#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3262 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3263#endif
3264 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003266 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003267 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268#else
3269# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003270 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003271 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003273 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274# endif
3275#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003277 opt_idx = findoption((char_u *)"maxmem");
3278 if (opt_idx >= 0)
3279 {
3280#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003281 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3282 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003283#endif
3284 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3285 }
3286 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287 }
3288
3289#ifdef FEAT_GUI_W32
3290 /* force 'shortname' for Win32s */
3291 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003292 {
3293 opt_idx = findoption((char_u *)"shortname");
3294 if (opt_idx >= 0)
3295 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3296 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297#endif
3298
3299#ifdef FEAT_SEARCHPATH
3300 {
3301 char_u *cdpath;
3302 char_u *buf;
3303 int i;
3304 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003305 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306
3307 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003308 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309 if (cdpath != NULL)
3310 {
3311 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3312 if (buf != NULL)
3313 {
3314 buf[0] = ','; /* start with ",", current dir first */
3315 j = 1;
3316 for (i = 0; cdpath[i] != NUL; ++i)
3317 {
3318 if (vim_ispathlistsep(cdpath[i]))
3319 buf[j++] = ',';
3320 else
3321 {
3322 if (cdpath[i] == ' ' || cdpath[i] == ',')
3323 buf[j++] = '\\';
3324 buf[j++] = cdpath[i];
3325 }
3326 }
3327 buf[j] = NUL;
3328 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003329 if (opt_idx >= 0)
3330 {
3331 options[opt_idx].def_val[VI_DEFAULT] = buf;
3332 options[opt_idx].flags |= P_DEF_ALLOCED;
3333 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003334 else
3335 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003337 if (mustfree)
3338 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 }
3340 }
3341#endif
3342
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003343#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 /* Set print encoding on platforms that don't default to latin1 */
3345 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003346# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 (char_u *)"cp1252"
3348# else
3349# ifdef VMS
3350 (char_u *)"dec-mcs"
3351# else
3352# ifdef EBCDIC
3353 (char_u *)"ebcdic-uk"
3354# else
3355# ifdef MAC
3356 (char_u *)"mac-roman"
3357# else /* HPUX */
3358 (char_u *)"hp-roman8"
3359# endif
3360# endif
3361# endif
3362# endif
3363 );
3364#endif
3365
3366#ifdef FEAT_POSTSCRIPT
3367 /* 'printexpr' must be allocated to be able to evaluate it. */
3368 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003369# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003370 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371# else
3372# ifdef VMS
3373 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3374
3375# else
3376 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3377# endif
3378# endif
3379 );
3380#endif
3381
3382 /*
3383 * Set all the options (except the terminal options) to their default
3384 * value. Also set the global value for local options.
3385 */
3386 set_options_default(0);
3387
3388#ifdef FEAT_GUI
3389 if (found_reverse_arg)
3390 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3391#endif
3392
3393 curbuf->b_p_initialized = TRUE;
3394 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003395 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396 check_buf_options(curbuf);
3397 check_win_options(curwin);
3398 check_options();
3399
3400 /* Must be before option_expand(), because that one needs vim_isIDc() */
3401 didset_options();
3402
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003403#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003404 /* Use the current chartab for the generic chartab. This is not in
3405 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003406 init_spell_chartab();
3407#endif
3408
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409 /*
3410 * Expand environment variables and things like "~" for the defaults.
3411 * If option_expand() returns non-NULL the variable is expanded. This can
3412 * only happen for non-indirect options.
3413 * Also set the default to the expanded value, so ":set" does not list
3414 * them.
3415 * Don't set the P_ALLOCED flag, because we don't want to free the
3416 * default.
3417 */
3418 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3419 {
3420 if ((options[opt_idx].flags & P_GETTEXT)
3421 && options[opt_idx].var != NULL)
3422 p = (char_u *)_(*(char **)options[opt_idx].var);
3423 else
3424 p = option_expand(opt_idx, NULL);
3425 if (p != NULL && (p = vim_strsave(p)) != NULL)
3426 {
3427 *(char_u **)options[opt_idx].var = p;
3428 /* VIMEXP
3429 * Defaults for all expanded options are currently the same for Vi
3430 * and Vim. When this changes, add some code here! Also need to
3431 * split P_DEF_ALLOCED in two.
3432 */
3433 if (options[opt_idx].flags & P_DEF_ALLOCED)
3434 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3435 options[opt_idx].def_val[VI_DEFAULT] = p;
3436 options[opt_idx].flags |= P_DEF_ALLOCED;
3437 }
3438 }
3439
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 save_file_ff(curbuf); /* Buffer is unchanged */
3441
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442#if defined(FEAT_ARABIC)
3443 /* Detect use of mlterm.
3444 * Mlterm is a terminal emulator akin to xterm that has some special
3445 * abilities (bidi namely).
3446 * NOTE: mlterm's author is being asked to 'set' a variable
3447 * instead of an environment variable due to inheritance.
3448 */
3449 if (mch_getenv((char_u *)"MLTERM") != NULL)
3450 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3451#endif
3452
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003453 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454
3455#ifdef FEAT_MBYTE
3456# if defined(WIN3264) && defined(FEAT_GETTEXT)
3457 /*
3458 * If $LANG isn't set, try to get a good value for it. This makes the
3459 * right language be used automatically. Don't do this for English.
3460 */
3461 if (mch_getenv((char_u *)"LANG") == NULL)
3462 {
3463 char buf[20];
3464
3465 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3466 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3467 * only the first two. */
3468 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3469 (LPTSTR)buf, 20);
3470 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3471 {
3472 /* There are a few exceptions (probably more) */
3473 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3474 STRCPY(buf, "zh_TW");
3475 else if (STRNICMP(buf, "chs", 3) == 0
3476 || STRNICMP(buf, "zhc", 3) == 0)
3477 STRCPY(buf, "zh_CN");
3478 else if (STRNICMP(buf, "jp", 2) == 0)
3479 STRCPY(buf, "ja");
3480 else
3481 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003482 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 }
3484 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003485# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003486# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003487 /* Moved to os_mac_conv.c to avoid dependency problems. */
3488 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003489# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490# endif
3491
3492 /* enc_locale() will try to find the encoding of the current locale. */
3493 p = enc_locale();
3494 if (p != NULL)
3495 {
3496 char_u *save_enc;
3497
3498 /* Try setting 'encoding' and check if the value is valid.
3499 * If not, go back to the default "latin1". */
3500 save_enc = p_enc;
3501 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003502 if (STRCMP(p_enc, "gb18030") == 0)
3503 {
3504 /* We don't support "gb18030", but "cp936" is a good substitute
3505 * for practical purposes, thus use that. It's not an alias to
3506 * still support conversion between gb18030 and utf-8. */
3507 p_enc = vim_strsave((char_u *)"cp936");
3508 vim_free(p);
3509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510 if (mb_init() == NULL)
3511 {
3512 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003513 if (opt_idx >= 0)
3514 {
3515 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3516 options[opt_idx].flags |= P_DEF_ALLOCED;
3517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003518
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003519#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003520 if (STRCMP(p_enc, "latin1") == 0
3521# ifdef FEAT_MBYTE
3522 || enc_utf8
3523# endif
3524 )
3525 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003526 /* Adjust the default for 'isprint' and 'iskeyword' to match
3527 * latin1. Also set the defaults for when 'nocompatible' is
3528 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003529 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003530 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003531 set_string_option_direct((char_u *)"isk", -1,
3532 ISK_LATIN1, OPT_FREE, SID_NONE);
3533 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003534 if (opt_idx >= 0)
3535 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003536 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003537 if (opt_idx >= 0)
3538 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003539 (void)init_chartab();
3540 }
3541#endif
3542
Bram Moolenaar071d4272004-06-13 20:20:40 +00003543# if defined(WIN3264) && !defined(FEAT_GUI)
3544 /* Win32 console: When GetACP() returns a different value from
3545 * GetConsoleCP() set 'termencoding'. */
3546 if (GetACP() != GetConsoleCP())
3547 {
3548 char buf[50];
3549
3550 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3551 p_tenc = vim_strsave((char_u *)buf);
3552 if (p_tenc != NULL)
3553 {
3554 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003555 if (opt_idx >= 0)
3556 {
3557 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3558 options[opt_idx].flags |= P_DEF_ALLOCED;
3559 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003560 convert_setup(&input_conv, p_tenc, p_enc);
3561 convert_setup(&output_conv, p_enc, p_tenc);
3562 }
3563 else
3564 p_tenc = empty_option;
3565 }
3566# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003567# if defined(WIN3264) && defined(FEAT_MBYTE)
3568 /* $HOME may have characters in active code page. */
3569 init_homedir();
3570# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571 }
3572 else
3573 {
3574 vim_free(p_enc);
3575 p_enc = save_enc;
3576 }
3577 }
3578#endif
3579
3580#ifdef FEAT_MULTI_LANG
3581 /* Set the default for 'helplang'. */
3582 set_helplang_default(get_mess_lang());
3583#endif
3584}
3585
3586/*
3587 * Set an option to its default value.
3588 * This does not take care of side effects!
3589 */
3590 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003591set_option_default(
3592 int opt_idx,
3593 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3594 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003595{
3596 char_u *varp; /* pointer to variable for current option */
3597 int dvi; /* index in def_val[] */
3598 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003599 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003600 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3601
3602 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3603 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003604 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605 {
3606 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3607 if (flags & P_STRING)
3608 {
3609 /* Use set_string_option_direct() for local options to handle
3610 * freeing and allocating the value. */
3611 if (options[opt_idx].indir != PV_NONE)
3612 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003613 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003614 else
3615 {
3616 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3617 free_string_option(*(char_u **)(varp));
3618 *(char_u **)varp = options[opt_idx].def_val[dvi];
3619 options[opt_idx].flags &= ~P_ALLOCED;
3620 }
3621 }
3622 else if (flags & P_NUM)
3623 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003624 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625 win_comp_scroll(curwin);
3626 else
3627 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003628 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629 /* May also set global value for local option. */
3630 if (both)
3631 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3632 *(long *)varp;
3633 }
3634 }
3635 else /* P_BOOL */
3636 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003637 /* the cast to long is required for Manx C, long_i is needed for
3638 * MSVC */
3639 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003640#ifdef UNIX
3641 /* 'modeline' defaults to off for root */
3642 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3643 *(int *)varp = FALSE;
3644#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003645 /* May also set global value for local option. */
3646 if (both)
3647 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3648 *(int *)varp;
3649 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003650
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003651 /* The default value is not insecure. */
3652 flagsp = insecure_flag(opt_idx, opt_flags);
3653 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 }
3655
3656#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003657 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658#endif
3659}
3660
3661/*
3662 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003663 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003664 */
3665 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003666set_options_default(
3667 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003668{
3669 int i;
3670#ifdef FEAT_WINDOWS
3671 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003672 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003673#endif
3674
3675 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003676 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003677#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003678 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003679 || (TRUE
3680# if defined(FEAT_MBYTE)
3681 && options[i].var != (char_u *)&p_enc
3682# endif
3683# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003684 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003685 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003686# endif
3687 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003688#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003689 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690 set_option_default(i, opt_flags, p_cp);
3691
3692#ifdef FEAT_WINDOWS
3693 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003694 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695 win_comp_scroll(wp);
3696#else
3697 win_comp_scroll(curwin);
3698#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003699#ifdef FEAT_CINDENT
3700 parse_cino(curbuf);
3701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702}
3703
3704/*
3705 * Set the Vi-default value of a string option.
3706 * Used for 'sh', 'backupskip' and 'term'.
3707 */
3708 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003709set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710{
3711 char_u *p;
3712 int opt_idx;
3713
3714 p = vim_strsave(val);
3715 if (p != NULL) /* we don't want a NULL */
3716 {
3717 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003718 if (opt_idx >= 0)
3719 {
3720 if (options[opt_idx].flags & P_DEF_ALLOCED)
3721 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3722 options[opt_idx].def_val[VI_DEFAULT] = p;
3723 options[opt_idx].flags |= P_DEF_ALLOCED;
3724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725 }
3726}
3727
3728/*
3729 * Set the Vi-default value of a number option.
3730 * Used for 'lines' and 'columns'.
3731 */
3732 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003733set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003735 int opt_idx;
3736
3737 opt_idx = findoption((char_u *)name);
3738 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003739 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740}
3741
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003742#if defined(EXITFREE) || defined(PROTO)
3743/*
3744 * Free all options.
3745 */
3746 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003747free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003748{
3749 int i;
3750
3751 for (i = 0; !istermoption(&options[i]); i++)
3752 {
3753 if (options[i].indir == PV_NONE)
3754 {
3755 /* global option: free value and default value. */
3756 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3757 free_string_option(*(char_u **)options[i].var);
3758 if (options[i].flags & P_DEF_ALLOCED)
3759 free_string_option(options[i].def_val[VI_DEFAULT]);
3760 }
3761 else if (options[i].var != VAR_WIN
3762 && (options[i].flags & P_STRING))
3763 /* buffer-local option: free global value */
3764 free_string_option(*(char_u **)options[i].var);
3765 }
3766}
3767#endif
3768
3769
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770/*
3771 * Initialize the options, part two: After getting Rows and Columns and
3772 * setting 'term'.
3773 */
3774 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003775set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003777 int idx;
3778
Bram Moolenaar071d4272004-06-13 20:20:40 +00003779 /*
3780 * 'scroll' defaults to half the window height. Note that this default is
3781 * wrong when the window height changes.
3782 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003783 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003784 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003785 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003786 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 comp_col();
3788
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003789 /*
3790 * 'window' is only for backwards compatibility with Vi.
3791 * Default is Rows - 1.
3792 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003793 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003794 p_window = Rows - 1;
3795 set_number_default("window", Rows - 1);
3796
Bram Moolenaarf740b292006-02-16 22:11:02 +00003797 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003798#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003799 /*
3800 * If 'background' wasn't set by the user, try guessing the value,
3801 * depending on the terminal name. Only need to check for terminals
3802 * with a dark background, that can handle color.
3803 */
3804 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003805 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3806 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003808 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003809 /* don't mark it as set, when starting the GUI it may be
3810 * changed again */
3811 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812 }
3813#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003814
3815#ifdef CURSOR_SHAPE
3816 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3817#endif
3818#ifdef FEAT_MOUSESHAPE
3819 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3820#endif
3821#ifdef FEAT_PRINTER
3822 (void)parse_printoptions(); /* parse 'printoptions' default value */
3823#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824}
3825
3826/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003827 * Return "dark" or "light" depending on the kind of terminal.
3828 * This is just guessing! Recognized are:
3829 * "linux" Linux console
3830 * "screen.linux" Linux console with screen
3831 * "cygwin" Cygwin shell
3832 * "putty" Putty program
3833 * We also check the COLORFGBG environment variable, which is set by
3834 * rxvt and derivatives. This variable contains either two or three
3835 * values separated by semicolons; we want the last value in either
3836 * case. If this value is 0-6 or 8, our background is dark.
3837 */
3838 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003839term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003840{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003841#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003842 /* DOS console nearly always black */
3843 return (char_u *)"dark";
3844#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003845 char_u *p;
3846
Bram Moolenaarf740b292006-02-16 22:11:02 +00003847 if (STRCMP(T_NAME, "linux") == 0
3848 || STRCMP(T_NAME, "screen.linux") == 0
3849 || STRCMP(T_NAME, "cygwin") == 0
3850 || STRCMP(T_NAME, "putty") == 0
3851 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3852 && (p = vim_strrchr(p, ';')) != NULL
3853 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3854 && p[2] == NUL))
3855 return (char_u *)"dark";
3856 return (char_u *)"light";
3857#endif
3858}
3859
3860/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861 * Initialize the options, part three: After reading the .vimrc
3862 */
3863 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003864set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003866#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867/*
3868 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3869 * This is done after other initializations, where 'shell' might have been
3870 * set, but only if they have not been set before.
3871 */
3872 char_u *p;
3873 int idx_srr;
3874 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003875# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876 int idx_sp;
3877 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003878# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879
3880 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003881 if (idx_srr < 0)
3882 do_srr = FALSE;
3883 else
3884 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003885# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003887 if (idx_sp < 0)
3888 do_sp = FALSE;
3889 else
3890 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003891# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003892 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 if (p != NULL)
3894 {
3895 /*
3896 * Default for p_sp is "| tee", for p_srr is ">".
3897 * For known shells it is changed here to include stderr.
3898 */
3899 if ( fnamecmp(p, "csh") == 0
3900 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003901# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902 || fnamecmp(p, "csh.exe") == 0
3903 || fnamecmp(p, "tcsh.exe") == 0
3904# endif
3905 )
3906 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003907# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 if (do_sp)
3909 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003910# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003912# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003914# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3916 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003917# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 if (do_srr)
3919 {
3920 p_srr = (char_u *)">&";
3921 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3922 }
3923 }
3924 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003925 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926 if ( fnamecmp(p, "sh") == 0
3927 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003928 || fnamecmp(p, "mksh") == 0
3929 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003931 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003933 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003934# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 || fnamecmp(p, "cmd") == 0
3936 || fnamecmp(p, "sh.exe") == 0
3937 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003938 || fnamecmp(p, "mksh.exe") == 0
3939 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003941 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 || fnamecmp(p, "bash.exe") == 0
3943 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003945 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003947# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 if (do_sp)
3949 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003950# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003952# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003954# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3956 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003957# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 if (do_srr)
3959 {
3960 p_srr = (char_u *)">%s 2>&1";
3961 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3962 }
3963 }
3964 vim_free(p);
3965 }
3966#endif
3967
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003968#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003970 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3971 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972 * This is done after other initializations, where 'shell' might have been
3973 * set, but only if they have not been set before. Default for p_shcf is
3974 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003975 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003977 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 {
3979 int idx3;
3980
3981 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003982 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983 {
3984 p_shcf = (char_u *)"-c";
3985 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3986 }
3987
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003988# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989 /* Somehow Win32 requires the quotes around the redirection too */
3990 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003991 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003992 {
3993 p_sxq = (char_u *)"\"";
3994 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3995 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003996# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003997 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003998 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003999 {
4000 p_shq = (char_u *)"\"";
4001 options[idx3].def_val[VI_DEFAULT] = p_shq;
4002 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003# endif
4004 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004005 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4006 {
4007 int idx3;
4008
4009 /*
4010 * cmd.exe on Windows will strip the first and last double quote given
4011 * on the command line, e.g. most of the time things like:
4012 * cmd /c "my path/to/echo" "my args to echo"
4013 * become:
4014 * my path/to/echo" "my args to echo
4015 * when executed.
4016 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004017 * To avoid this, set shellxquote to surround the command in
4018 * parenthesis. This appears to make most commands work, without
4019 * breaking commands that worked previously, such as
4020 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004021 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004022 idx3 = findoption((char_u *)"sxq");
4023 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4024 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004025 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004026 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4027 }
4028
Bram Moolenaara64ba222012-02-12 23:23:31 +01004029 idx3 = findoption((char_u *)"shcf");
4030 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4031 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004032 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004033 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4034 }
4035 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004036#endif
4037
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004038 if (bufempty())
4039 {
4040 int idx_ffs = findoption((char_u *)"ffs");
4041
4042 /* Apply the first entry of 'fileformats' to the initial buffer. */
4043 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4044 set_fileformat(default_fileformat(), OPT_LOCAL);
4045 }
4046
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047#ifdef FEAT_TITLE
4048 set_title_defaults();
4049#endif
4050}
4051
4052#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4053/*
4054 * When 'helplang' is still at its default value, set it to "lang".
4055 * Only the first two characters of "lang" are used.
4056 */
4057 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004058set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059{
4060 int idx;
4061
4062 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4063 return;
4064 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004065 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 {
4067 if (options[idx].flags & P_ALLOCED)
4068 free_string_option(p_hlg);
4069 p_hlg = vim_strsave(lang);
4070 if (p_hlg == NULL)
4071 p_hlg = empty_option;
4072 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004073 {
4074 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4075 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4076 {
4077 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4078 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4079 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004081 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 options[idx].flags |= P_ALLOCED;
4083 }
4084}
4085#endif
4086
4087#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004088static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089
4090 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004091gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092{
4093 if (gui_get_lightness(gui.back_pixel) < 127)
4094 return (char_u *)"dark";
4095 return (char_u *)"light";
4096}
4097
4098/*
4099 * Option initializations that can only be done after opening the GUI window.
4100 */
4101 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004102init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103{
4104 /* Set the 'background' option according to the lightness of the
4105 * background color, unless the user has set it already. */
4106 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4107 {
4108 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4109 highlight_changed();
4110 }
4111}
4112#endif
4113
4114#ifdef FEAT_TITLE
4115/*
4116 * 'title' and 'icon' only default to true if they have not been set or reset
4117 * in .vimrc and we can read the old value.
4118 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4119 * they can be reset. This reduces startup time when using X on a remote
4120 * machine.
4121 */
4122 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004123set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124{
4125 int idx1;
4126 long val;
4127
4128 /*
4129 * If GUI is (going to be) used, we can always set the window title and
4130 * icon name. Saves a bit of time, because the X11 display server does
4131 * not need to be contacted.
4132 */
4133 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004134 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 {
4136#ifdef FEAT_GUI
4137 if (gui.starting || gui.in_use)
4138 val = TRUE;
4139 else
4140#endif
4141 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004142 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 p_title = val;
4144 }
4145 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004146 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 {
4148#ifdef FEAT_GUI
4149 if (gui.starting || gui.in_use)
4150 val = TRUE;
4151 else
4152#endif
4153 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004154 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 p_icon = val;
4156 }
4157}
4158#endif
4159
4160/*
4161 * Parse 'arg' for option settings.
4162 *
4163 * 'arg' may be IObuff, but only when no errors can be present and option
4164 * does not need to be expanded with option_expand().
4165 * "opt_flags":
4166 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004167 * OPT_GLOBAL for ":setglobal"
4168 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004170 * OPT_WINONLY to only set window-local options
4171 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 *
4173 * returns FAIL if an error is detected, OK otherwise
4174 */
4175 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004176do_set(
4177 char_u *arg, /* option string (may be written to!) */
4178 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179{
4180 int opt_idx;
4181 char_u *errmsg;
4182 char_u errbuf[80];
4183 char_u *startarg;
4184 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4185 int nextchar; /* next non-white char after option name */
4186 int afterchar; /* character just after option name */
4187 int len;
4188 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004189 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190 int key;
4191 long_u flags; /* flags for current option */
4192 char_u *varp = NULL; /* pointer to variable for current option */
4193 int did_show = FALSE; /* already showed one value */
4194 int adding; /* "opt+=arg" */
4195 int prepending; /* "opt^=arg" */
4196 int removing; /* "opt-=arg" */
4197 int cp_val = 0;
4198 char_u key_name[2];
4199
4200 if (*arg == NUL)
4201 {
4202 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004203 did_show = TRUE;
4204 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004205 }
4206
4207 while (*arg != NUL) /* loop to process all options */
4208 {
4209 errmsg = NULL;
4210 startarg = arg; /* remember for error message */
4211
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004212 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4213 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004214 {
4215 /*
4216 * ":set all" show all options.
4217 * ":set all&" set all options to their default value.
4218 */
4219 arg += 3;
4220 if (*arg == '&')
4221 {
4222 ++arg;
4223 /* Only for :set command set global value of local options. */
4224 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004225 didset_options();
4226 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004227 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004228 }
4229 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004230 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004231 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004232 did_show = TRUE;
4233 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004235 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 {
4237 showoptions(2, opt_flags);
4238 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004239 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240 arg += 7;
4241 }
4242 else
4243 {
4244 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004245 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246 {
4247 prefix = 0;
4248 arg += 2;
4249 }
4250 else if (STRNCMP(arg, "inv", 3) == 0)
4251 {
4252 prefix = 2;
4253 arg += 3;
4254 }
4255
4256 /* find end of name */
4257 key = 0;
4258 if (*arg == '<')
4259 {
4260 nextchar = 0;
4261 opt_idx = -1;
4262 /* look out for <t_>;> */
4263 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4264 len = 5;
4265 else
4266 {
4267 len = 1;
4268 while (arg[len] != NUL && arg[len] != '>')
4269 ++len;
4270 }
4271 if (arg[len] != '>')
4272 {
4273 errmsg = e_invarg;
4274 goto skip;
4275 }
4276 arg[len] = NUL; /* put NUL after name */
4277 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4278 opt_idx = findoption(arg + 1);
4279 arg[len++] = '>'; /* restore '>' */
4280 if (opt_idx == -1)
4281 key = find_key_option(arg + 1);
4282 }
4283 else
4284 {
4285 len = 0;
4286 /*
4287 * The two characters after "t_" may not be alphanumeric.
4288 */
4289 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4290 len = 4;
4291 else
4292 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4293 ++len;
4294 nextchar = arg[len];
4295 arg[len] = NUL; /* put NUL after name */
4296 opt_idx = findoption(arg);
4297 arg[len] = nextchar; /* restore nextchar */
4298 if (opt_idx == -1)
4299 key = find_key_option(arg);
4300 }
4301
4302 /* remember character after option name */
4303 afterchar = arg[len];
4304
4305 /* skip white space, allow ":set ai ?" */
4306 while (vim_iswhite(arg[len]))
4307 ++len;
4308
4309 adding = FALSE;
4310 prepending = FALSE;
4311 removing = FALSE;
4312 if (arg[len] != NUL && arg[len + 1] == '=')
4313 {
4314 if (arg[len] == '+')
4315 {
4316 adding = TRUE; /* "+=" */
4317 ++len;
4318 }
4319 else if (arg[len] == '^')
4320 {
4321 prepending = TRUE; /* "^=" */
4322 ++len;
4323 }
4324 else if (arg[len] == '-')
4325 {
4326 removing = TRUE; /* "-=" */
4327 ++len;
4328 }
4329 }
4330 nextchar = arg[len];
4331
4332 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4333 {
4334 errmsg = (char_u *)N_("E518: Unknown option");
4335 goto skip;
4336 }
4337
4338 if (opt_idx >= 0)
4339 {
4340 if (options[opt_idx].var == NULL) /* hidden option: skip */
4341 {
4342 /* Only give an error message when requesting the value of
4343 * a hidden option, ignore setting it. */
4344 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4345 && (!(options[opt_idx].flags & P_BOOL)
4346 || nextchar == '?'))
4347 errmsg = (char_u *)N_("E519: Option not supported");
4348 goto skip;
4349 }
4350
4351 flags = options[opt_idx].flags;
4352 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4353 }
4354 else
4355 {
4356 flags = P_STRING;
4357 if (key < 0)
4358 {
4359 key_name[0] = KEY2TERMCAP0(key);
4360 key_name[1] = KEY2TERMCAP1(key);
4361 }
4362 else
4363 {
4364 key_name[0] = KS_KEY;
4365 key_name[1] = (key & 0xff);
4366 }
4367 }
4368
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004369 /* Skip all options that are not window-local (used when showing
4370 * an already loaded buffer in a window). */
4371 if ((opt_flags & OPT_WINONLY)
4372 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4373 goto skip;
4374
Bram Moolenaara3227e22006-03-08 21:32:40 +00004375 /* Skip all options that are window-local (used for :vimgrep). */
4376 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4377 && options[opt_idx].var == VAR_WIN)
4378 goto skip;
4379
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004380 /* Disallow changing some options from modelines. */
4381 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004382 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004383 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004384 {
4385 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4386 goto skip;
4387 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004388#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004389 /* In diff mode some options are overruled. This avoids that
4390 * 'foldmethod' becomes "marker" instead of "diff" and that
4391 * "wrap" gets set. */
4392 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004393 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004394 && (options[opt_idx].indir == PV_FDM
4395 || options[opt_idx].indir == PV_WRAP))
4396 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004398 }
4399
4400#ifdef HAVE_SANDBOX
4401 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004402 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403 {
4404 errmsg = (char_u *)_(e_sandbox);
4405 goto skip;
4406 }
4407#endif
4408
4409 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4410 {
4411 arg += len;
4412 cp_val = p_cp;
4413 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4414 {
4415 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4416 {
4417 cp_val = FALSE;
4418 arg += 3;
4419 }
4420 else /* "opt&vi": set to Vi default */
4421 {
4422 cp_val = TRUE;
4423 arg += 2;
4424 }
4425 }
4426 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4427 && arg[1] != NUL && !vim_iswhite(arg[1]))
4428 {
4429 errmsg = e_trailing;
4430 goto skip;
4431 }
4432 }
4433
4434 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004435 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4436 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004437 */
4438 if (nextchar == '?'
4439 || (prefix == 1
4440 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4441 && !(flags & P_BOOL)))
4442 {
4443 /*
4444 * print value
4445 */
4446 if (did_show)
4447 msg_putchar('\n'); /* cursor below last one */
4448 else
4449 {
4450 gotocmdline(TRUE); /* cursor at status line */
4451 did_show = TRUE; /* remember that we did a line */
4452 }
4453 if (opt_idx >= 0)
4454 {
4455 showoneopt(&options[opt_idx], opt_flags);
4456#ifdef FEAT_EVAL
4457 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004458 {
4459 /* Mention where the option was last set. */
4460 if (varp == options[opt_idx].var)
4461 last_set_msg(options[opt_idx].scriptID);
4462 else if ((int)options[opt_idx].indir & PV_WIN)
4463 last_set_msg(curwin->w_p_scriptID[
4464 (int)options[opt_idx].indir & PV_MASK]);
4465 else if ((int)options[opt_idx].indir & PV_BUF)
4466 last_set_msg(curbuf->b_p_scriptID[
4467 (int)options[opt_idx].indir & PV_MASK]);
4468 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004469#endif
4470 }
4471 else
4472 {
4473 char_u *p;
4474
4475 p = find_termcode(key_name);
4476 if (p == NULL)
4477 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004478 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004479 goto skip;
4480 }
4481 else
4482 (void)show_one_termcode(key_name, p, TRUE);
4483 }
4484 if (nextchar != '?'
4485 && nextchar != NUL && !vim_iswhite(afterchar))
4486 errmsg = e_trailing;
4487 }
4488 else
4489 {
4490 if (flags & P_BOOL) /* boolean */
4491 {
4492 if (nextchar == '=' || nextchar == ':')
4493 {
4494 errmsg = e_invarg;
4495 goto skip;
4496 }
4497
4498 /*
4499 * ":set opt!": invert
4500 * ":set opt&": reset to default value
4501 * ":set opt<": reset to global value
4502 */
4503 if (nextchar == '!')
4504 value = *(int *)(varp) ^ 1;
4505 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004506 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004507 ((flags & P_VI_DEF) || cp_val)
4508 ? VI_DEFAULT : VIM_DEFAULT];
4509 else if (nextchar == '<')
4510 {
4511 /* For 'autoread' -1 means to use global value. */
4512 if ((int *)varp == &curbuf->b_p_ar
4513 && opt_flags == OPT_LOCAL)
4514 value = -1;
4515 else
4516 value = *(int *)get_varp_scope(&(options[opt_idx]),
4517 OPT_GLOBAL);
4518 }
4519 else
4520 {
4521 /*
4522 * ":set invopt": invert
4523 * ":set opt" or ":set noopt": set or reset
4524 */
4525 if (nextchar != NUL && !vim_iswhite(afterchar))
4526 {
4527 errmsg = e_trailing;
4528 goto skip;
4529 }
4530 if (prefix == 2) /* inv */
4531 value = *(int *)(varp) ^ 1;
4532 else
4533 value = prefix;
4534 }
4535
4536 errmsg = set_bool_option(opt_idx, varp, (int)value,
4537 opt_flags);
4538 }
4539 else /* numeric or string */
4540 {
4541 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4542 || prefix != 1)
4543 {
4544 errmsg = e_invarg;
4545 goto skip;
4546 }
4547
4548 if (flags & P_NUM) /* numeric */
4549 {
4550 /*
4551 * Different ways to set a number option:
4552 * & set to default value
4553 * < set to global value
4554 * <xx> accept special key codes for 'wildchar'
4555 * c accept any non-digit for 'wildchar'
4556 * [-]0-9 set number
4557 * other error
4558 */
4559 ++arg;
4560 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004561 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 ((flags & P_VI_DEF) || cp_val)
4563 ? VI_DEFAULT : VIM_DEFAULT];
4564 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004565 {
4566 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4567 * use the global value. */
4568 if ((long *)varp == &curbuf->b_p_ul
4569 && opt_flags == OPT_LOCAL)
4570 value = NO_LOCAL_UNDOLEVEL;
4571 else
4572 value = *(long *)get_varp_scope(
4573 &(options[opt_idx]), OPT_GLOBAL);
4574 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004575 else if (((long *)varp == &p_wc
4576 || (long *)varp == &p_wcm)
4577 && (*arg == '<'
4578 || *arg == '^'
4579 || ((!arg[1] || vim_iswhite(arg[1]))
4580 && !VIM_ISDIGIT(*arg))))
4581 {
4582 value = string_to_key(arg);
4583 if (value == 0 && (long *)varp != &p_wcm)
4584 {
4585 errmsg = e_invarg;
4586 goto skip;
4587 }
4588 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004589 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4590 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004591 /* Allow negative (for 'undolevels'), octal and
4592 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004593 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4594 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004595 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4596 {
4597 errmsg = e_invarg;
4598 goto skip;
4599 }
4600 }
4601 else
4602 {
4603 errmsg = (char_u *)N_("E521: Number required after =");
4604 goto skip;
4605 }
4606
4607 if (adding)
4608 value = *(long *)varp + value;
4609 if (prepending)
4610 value = *(long *)varp * value;
4611 if (removing)
4612 value = *(long *)varp - value;
4613 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004614 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 }
4616 else if (opt_idx >= 0) /* string */
4617 {
4618 char_u *save_arg = NULL;
4619 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004620 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004621 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004622 char_u *origval = NULL;
4623#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4624 char_u *saved_origval = NULL;
4625#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004626 unsigned newlen;
4627 int comma;
4628 int bs;
4629 int new_value_alloced; /* new string option
4630 was allocated */
4631
4632 /* When using ":set opt=val" for a global option
4633 * with a local value the local value will be
4634 * reset, use the global value here. */
4635 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004636 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004637 varp = options[opt_idx].var;
4638
4639 /* The old value is kept until we are sure that the
4640 * new value is valid. */
4641 oldval = *(char_u **)varp;
4642 if (nextchar == '&') /* set to default val */
4643 {
4644 newval = options[opt_idx].def_val[
4645 ((flags & P_VI_DEF) || cp_val)
4646 ? VI_DEFAULT : VIM_DEFAULT];
4647 if ((char_u **)varp == &p_bg)
4648 {
4649 /* guess the value of 'background' */
4650#ifdef FEAT_GUI
4651 if (gui.in_use)
4652 newval = gui_bg_default();
4653 else
4654#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004655 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004656 }
4657
4658 /* expand environment variables and ~ (since the
4659 * default value was already expanded, only
4660 * required when an environment variable was set
4661 * later */
4662 if (newval == NULL)
4663 newval = empty_option;
4664 else
4665 {
4666 s = option_expand(opt_idx, newval);
4667 if (s == NULL)
4668 s = newval;
4669 newval = vim_strsave(s);
4670 }
4671 new_value_alloced = TRUE;
4672 }
4673 else if (nextchar == '<') /* set to global val */
4674 {
4675 newval = vim_strsave(*(char_u **)get_varp_scope(
4676 &(options[opt_idx]), OPT_GLOBAL));
4677 new_value_alloced = TRUE;
4678 }
4679 else
4680 {
4681 ++arg; /* jump to after the '=' or ':' */
4682
4683 /*
4684 * Set 'keywordprg' to ":help" if an empty
4685 * value was passed to :set by the user.
4686 * Misuse errbuf[] for the resulting string.
4687 */
4688 if (varp == (char_u *)&p_kp
4689 && (*arg == NUL || *arg == ' '))
4690 {
4691 STRCPY(errbuf, ":help");
4692 save_arg = arg;
4693 arg = errbuf;
4694 }
4695 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004696 * Convert 'backspace' number to string, for
4697 * adding, prepending and removing string.
4698 */
4699 else if (varp == (char_u *)&p_bs
4700 && VIM_ISDIGIT(**(char_u **)varp))
4701 {
4702 i = getdigits((char_u **)varp);
4703 switch (i)
4704 {
4705 case 0:
4706 *(char_u **)varp = empty_option;
4707 break;
4708 case 1:
4709 *(char_u **)varp = vim_strsave(
4710 (char_u *)"indent,eol");
4711 break;
4712 case 2:
4713 *(char_u **)varp = vim_strsave(
4714 (char_u *)"indent,eol,start");
4715 break;
4716 }
4717 vim_free(oldval);
4718 oldval = *(char_u **)varp;
4719 }
4720 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004721 * Convert 'whichwrap' number to string, for
4722 * backwards compatibility with Vim 3.0.
4723 * Misuse errbuf[] for the resulting string.
4724 */
4725 else if (varp == (char_u *)&p_ww
4726 && VIM_ISDIGIT(*arg))
4727 {
4728 *errbuf = NUL;
4729 i = getdigits(&arg);
4730 if (i & 1)
4731 STRCAT(errbuf, "b,");
4732 if (i & 2)
4733 STRCAT(errbuf, "s,");
4734 if (i & 4)
4735 STRCAT(errbuf, "h,l,");
4736 if (i & 8)
4737 STRCAT(errbuf, "<,>,");
4738 if (i & 16)
4739 STRCAT(errbuf, "[,],");
4740 if (*errbuf != NUL) /* remove trailing , */
4741 errbuf[STRLEN(errbuf) - 1] = NUL;
4742 save_arg = arg;
4743 arg = errbuf;
4744 }
4745 /*
4746 * Remove '>' before 'dir' and 'bdir', for
4747 * backwards compatibility with version 3.0
4748 */
4749 else if ( *arg == '>'
4750 && (varp == (char_u *)&p_dir
4751 || varp == (char_u *)&p_bdir))
4752 {
4753 ++arg;
4754 }
4755
4756 /* When setting the local value of a global
4757 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004758 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 && (opt_flags & OPT_LOCAL))
4760 origval = *(char_u **)get_varp(
4761 &options[opt_idx]);
4762 else
4763 origval = oldval;
4764
4765 /*
4766 * Copy the new string into allocated memory.
4767 * Can't use set_string_option_direct(), because
4768 * we need to remove the backslashes.
4769 */
4770 /* get a bit too much */
4771 newlen = (unsigned)STRLEN(arg) + 1;
4772 if (adding || prepending || removing)
4773 newlen += (unsigned)STRLEN(origval) + 1;
4774 newval = alloc(newlen);
4775 if (newval == NULL) /* out of mem, don't change */
4776 break;
4777 s = newval;
4778
4779 /*
4780 * Copy the string, skip over escaped chars.
4781 * For MS-DOS and WIN32 backslashes before normal
4782 * file name characters are not removed, and keep
4783 * backslash at start, for "\\machine\path", but
4784 * do remove it for "\\\\machine\\path".
4785 * The reverse is found in ExpandOldSetting().
4786 */
4787 while (*arg && !vim_iswhite(*arg))
4788 {
4789 if (*arg == '\\' && arg[1] != NUL
4790#ifdef BACKSLASH_IN_FILENAME
4791 && !((flags & P_EXPAND)
4792 && vim_isfilec(arg[1])
4793 && (arg[1] != '\\'
4794 || (s == newval
4795 && arg[2] != '\\')))
4796#endif
4797 )
4798 ++arg; /* remove backslash */
4799#ifdef FEAT_MBYTE
4800 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004801 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004802 {
4803 /* copy multibyte char */
4804 mch_memmove(s, arg, (size_t)i);
4805 arg += i;
4806 s += i;
4807 }
4808 else
4809#endif
4810 *s++ = *arg++;
4811 }
4812 *s = NUL;
4813
4814 /*
4815 * Expand environment variables and ~.
4816 * Don't do it when adding without inserting a
4817 * comma.
4818 */
4819 if (!(adding || prepending || removing)
4820 || (flags & P_COMMA))
4821 {
4822 s = option_expand(opt_idx, newval);
4823 if (s != NULL)
4824 {
4825 vim_free(newval);
4826 newlen = (unsigned)STRLEN(s) + 1;
4827 if (adding || prepending || removing)
4828 newlen += (unsigned)STRLEN(origval) + 1;
4829 newval = alloc(newlen);
4830 if (newval == NULL)
4831 break;
4832 STRCPY(newval, s);
4833 }
4834 }
4835
4836 /* locate newval[] in origval[] when removing it
4837 * and when adding to avoid duplicates */
4838 i = 0; /* init for GCC */
4839 if (removing || (flags & P_NODUP))
4840 {
4841 i = (int)STRLEN(newval);
4842 bs = 0;
4843 for (s = origval; *s; ++s)
4844 {
4845 if ((!(flags & P_COMMA)
4846 || s == origval
4847 || (s[-1] == ',' && !(bs & 1)))
4848 && STRNCMP(s, newval, i) == 0
4849 && (!(flags & P_COMMA)
4850 || s[i] == ','
4851 || s[i] == NUL))
4852 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004853 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004854 * even number of backslashes or a single
4855 * backslash preceded by a comma before it
4856 * is recognized as a separator */
4857 if ((s > origval + 1
4858 && s[-1] == '\\'
4859 && s[-2] != ',')
4860 || (s == origval + 1
4861 && s[-1] == '\\'))
4862
Bram Moolenaar071d4272004-06-13 20:20:40 +00004863 ++bs;
4864 else
4865 bs = 0;
4866 }
4867
4868 /* do not add if already there */
4869 if ((adding || prepending) && *s)
4870 {
4871 prepending = FALSE;
4872 adding = FALSE;
4873 STRCPY(newval, origval);
4874 }
4875 }
4876
4877 /* concatenate the two strings; add a ',' if
4878 * needed */
4879 if (adding || prepending)
4880 {
4881 comma = ((flags & P_COMMA) && *origval != NUL
4882 && *newval != NUL);
4883 if (adding)
4884 {
4885 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004886 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004887 if (comma && i > 1
4888 && (flags & P_ONECOMMA) == P_ONECOMMA
4889 && origval[i - 1] == ','
4890 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004891 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004892 mch_memmove(newval + i + comma, newval,
4893 STRLEN(newval) + 1);
4894 mch_memmove(newval, origval, (size_t)i);
4895 }
4896 else
4897 {
4898 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004899 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004900 }
4901 if (comma)
4902 newval[i] = ',';
4903 }
4904
4905 /* Remove newval[] from origval[]. (Note: "i" has
4906 * been set above and is used here). */
4907 if (removing)
4908 {
4909 STRCPY(newval, origval);
4910 if (*s)
4911 {
4912 /* may need to remove a comma */
4913 if (flags & P_COMMA)
4914 {
4915 if (s == origval)
4916 {
4917 /* include comma after string */
4918 if (s[i] == ',')
4919 ++i;
4920 }
4921 else
4922 {
4923 /* include comma before string */
4924 --s;
4925 ++i;
4926 }
4927 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004928 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004929 }
4930 }
4931
4932 if (flags & P_FLAGLIST)
4933 {
4934 /* Remove flags that appear twice. */
4935 for (s = newval; *s; ++s)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004936 {
4937 /* if options have P_FLAGLIST and
4938 * P_ONECOMMA such as 'whichwrap' */
4939 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004940 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004941 if (*s != ',' && *(s + 1) == ','
4942 && vim_strchr(s + 2, *s) != NULL)
4943 {
4944 /* Remove the duplicated value and
4945 * the next comma. */
4946 STRMOVE(s, s + 2);
4947 s -= 2;
4948 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004949 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004950 else
4951 {
4952 if ((!(flags & P_COMMA) || *s != ',')
4953 && vim_strchr(s + 1, *s) != NULL)
4954 {
4955 STRMOVE(s, s + 1);
4956 --s;
4957 }
4958 }
4959 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004960 }
4961
4962 if (save_arg != NULL) /* number for 'whichwrap' */
4963 arg = save_arg;
4964 new_value_alloced = TRUE;
4965 }
4966
4967 /* Set the new value. */
4968 *(char_u **)(varp) = newval;
4969
Bram Moolenaar53744302015-07-17 17:38:22 +02004970#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004971 if (!starting
4972# ifdef FEAT_CRYPT
4973 && options[opt_idx].indir != PV_KEY
4974# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004975 && origval != NULL)
4976 /* origval may be freed by
4977 * did_set_string_option(), make a copy. */
4978 saved_origval = vim_strsave(origval);
4979#endif
4980
Bram Moolenaar071d4272004-06-13 20:20:40 +00004981 /* Handle side effects, and set the global value for
4982 * ":set" on local options. */
4983 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4984 new_value_alloced, oldval, errbuf, opt_flags);
4985
4986 /* If error detected, print the error message. */
4987 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004988 {
4989#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4990 vim_free(saved_origval);
4991#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004992 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004993 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004994#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4995 if (saved_origval != NULL)
4996 {
4997 char_u buf_type[7];
4998
4999 sprintf((char *)buf_type, "%s",
5000 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005001 set_vim_var_string(VV_OPTION_NEW,
5002 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005003 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5004 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5005 apply_autocmds(EVENT_OPTIONSET,
5006 (char_u *)options[opt_idx].fullname,
5007 NULL, FALSE, NULL);
5008 reset_v_option_vars();
5009 vim_free(saved_origval);
5010 }
5011#endif
5012
Bram Moolenaar071d4272004-06-13 20:20:40 +00005013 }
5014 else /* key code option */
5015 {
5016 char_u *p;
5017
5018 if (nextchar == '&')
5019 {
5020 if (add_termcap_entry(key_name, TRUE) == FAIL)
5021 errmsg = (char_u *)N_("E522: Not found in termcap");
5022 }
5023 else
5024 {
5025 ++arg; /* jump to after the '=' or ':' */
5026 for (p = arg; *p && !vim_iswhite(*p); ++p)
5027 if (*p == '\\' && p[1] != NUL)
5028 ++p;
5029 nextchar = *p;
5030 *p = NUL;
5031 add_termcode(key_name, arg, FALSE);
5032 *p = nextchar;
5033 }
5034 if (full_screen)
5035 ttest(FALSE);
5036 redraw_all_later(CLEAR);
5037 }
5038 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005039
Bram Moolenaar071d4272004-06-13 20:20:40 +00005040 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005041 did_set_option(opt_idx, opt_flags,
5042 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005043 }
5044
5045skip:
5046 /*
5047 * Advance to next argument.
5048 * - skip until a blank found, taking care of backslashes
5049 * - skip blanks
5050 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5051 */
5052 for (i = 0; i < 2 ; ++i)
5053 {
5054 while (*arg != NUL && !vim_iswhite(*arg))
5055 if (*arg++ == '\\' && *arg != NUL)
5056 ++arg;
5057 arg = skipwhite(arg);
5058 if (*arg != '=')
5059 break;
5060 }
5061 }
5062
5063 if (errmsg != NULL)
5064 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005065 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005066 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005067 if (i + (arg - startarg) < IOSIZE)
5068 {
5069 /* append the argument with the error */
5070 STRCAT(IObuff, ": ");
5071 mch_memmove(IObuff + i, startarg, (arg - startarg));
5072 IObuff[i + (arg - startarg)] = NUL;
5073 }
5074 /* make sure all characters are printable */
5075 trans_characters(IObuff, IOSIZE);
5076
5077 ++no_wait_return; /* wait_return done later */
5078 emsg(IObuff); /* show error highlighted */
5079 --no_wait_return;
5080
5081 return FAIL;
5082 }
5083
5084 arg = skipwhite(arg);
5085 }
5086
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005087theend:
5088 if (silent_mode && did_show)
5089 {
5090 /* After displaying option values in silent mode. */
5091 silent_mode = FALSE;
5092 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5093 msg_putchar('\n');
5094 cursor_on(); /* msg_start() switches it off */
5095 out_flush();
5096 silent_mode = TRUE;
5097 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5098 }
5099
Bram Moolenaar071d4272004-06-13 20:20:40 +00005100 return OK;
5101}
5102
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005103/*
5104 * Call this when an option has been given a new value through a user command.
5105 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5106 */
5107 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005108did_set_option(
5109 int opt_idx,
5110 int opt_flags, /* possibly with OPT_MODELINE */
5111 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005112{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005113 long_u *p;
5114
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005115 options[opt_idx].flags |= P_WAS_SET;
5116
5117 /* When an option is set in the sandbox, from a modeline or in secure mode
5118 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005119 * flag. */
5120 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005121 if (secure
5122#ifdef HAVE_SANDBOX
5123 || sandbox != 0
5124#endif
5125 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005126 *p = *p | P_INSECURE;
5127 else if (new_value)
5128 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005129}
5130
Bram Moolenaar071d4272004-06-13 20:20:40 +00005131 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005132illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005133{
5134 if (errbuf == NULL)
5135 return (char_u *)"";
5136 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005137 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005138 return errbuf;
5139}
5140
5141/*
5142 * Convert a key name or string into a key value.
5143 * Used for 'wildchar' and 'cedit' options.
5144 */
5145 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005146string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005147{
5148 if (*arg == '<')
5149 return find_key_option(arg + 1);
5150 if (*arg == '^')
5151 return Ctrl_chr(arg[1]);
5152 return *arg;
5153}
5154
5155#ifdef FEAT_CMDWIN
5156/*
5157 * Check value of 'cedit' and set cedit_key.
5158 * Returns NULL if value is OK, error message otherwise.
5159 */
5160 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005161check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005162{
5163 int n;
5164
5165 if (*p_cedit == NUL)
5166 cedit_key = -1;
5167 else
5168 {
5169 n = string_to_key(p_cedit);
5170 if (vim_isprintc(n))
5171 return e_invarg;
5172 cedit_key = n;
5173 }
5174 return NULL;
5175}
5176#endif
5177
5178#ifdef FEAT_TITLE
5179/*
5180 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5181 * maketitle() to create and display it.
5182 * When switching the title or icon off, call mch_restore_title() to get
5183 * the old value back.
5184 */
5185 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005186did_set_title(
5187 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005188{
5189 if (starting != NO_SCREEN
5190#ifdef FEAT_GUI
5191 && !gui.starting
5192#endif
5193 )
5194 {
5195 maketitle();
5196 if (icon)
5197 {
5198 if (!p_icon)
5199 mch_restore_title(2);
5200 }
5201 else
5202 {
5203 if (!p_title)
5204 mch_restore_title(1);
5205 }
5206 }
5207}
5208#endif
5209
5210/*
5211 * set_options_bin - called when 'bin' changes value.
5212 */
5213 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005214set_options_bin(
5215 int oldval,
5216 int newval,
5217 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005218{
5219 /*
5220 * The option values that are changed when 'bin' changes are
5221 * copied when 'bin is set and restored when 'bin' is reset.
5222 */
5223 if (newval)
5224 {
5225 if (!oldval) /* switched on */
5226 {
5227 if (!(opt_flags & OPT_GLOBAL))
5228 {
5229 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5230 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5231 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5232 curbuf->b_p_et_nobin = curbuf->b_p_et;
5233 }
5234 if (!(opt_flags & OPT_LOCAL))
5235 {
5236 p_tw_nobin = p_tw;
5237 p_wm_nobin = p_wm;
5238 p_ml_nobin = p_ml;
5239 p_et_nobin = p_et;
5240 }
5241 }
5242
5243 if (!(opt_flags & OPT_GLOBAL))
5244 {
5245 curbuf->b_p_tw = 0; /* no automatic line wrap */
5246 curbuf->b_p_wm = 0; /* no automatic line wrap */
5247 curbuf->b_p_ml = 0; /* no modelines */
5248 curbuf->b_p_et = 0; /* no expandtab */
5249 }
5250 if (!(opt_flags & OPT_LOCAL))
5251 {
5252 p_tw = 0;
5253 p_wm = 0;
5254 p_ml = FALSE;
5255 p_et = FALSE;
5256 p_bin = TRUE; /* needed when called for the "-b" argument */
5257 }
5258 }
5259 else if (oldval) /* switched off */
5260 {
5261 if (!(opt_flags & OPT_GLOBAL))
5262 {
5263 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5264 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5265 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5266 curbuf->b_p_et = curbuf->b_p_et_nobin;
5267 }
5268 if (!(opt_flags & OPT_LOCAL))
5269 {
5270 p_tw = p_tw_nobin;
5271 p_wm = p_wm_nobin;
5272 p_ml = p_ml_nobin;
5273 p_et = p_et_nobin;
5274 }
5275 }
5276}
5277
5278#ifdef FEAT_VIMINFO
5279/*
5280 * Find the parameter represented by the given character (eg ', :, ", or /),
5281 * and return its associated value in the 'viminfo' string.
5282 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005283 * If the parameter is not specified in the string or there is no following
5284 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285 */
5286 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005287get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005288{
5289 char_u *p;
5290
5291 p = find_viminfo_parameter(type);
5292 if (p != NULL && VIM_ISDIGIT(*p))
5293 return atoi((char *)p);
5294 return -1;
5295}
5296
5297/*
5298 * Find the parameter represented by the given character (eg ''', ':', '"', or
5299 * '/') in the 'viminfo' option and return a pointer to the string after it.
5300 * Return NULL if the parameter is not specified in the string.
5301 */
5302 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005303find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005304{
5305 char_u *p;
5306
5307 for (p = p_viminfo; *p; ++p)
5308 {
5309 if (*p == type)
5310 return p + 1;
5311 if (*p == 'n') /* 'n' is always the last one */
5312 break;
5313 p = vim_strchr(p, ','); /* skip until next ',' */
5314 if (p == NULL) /* hit the end without finding parameter */
5315 break;
5316 }
5317 return NULL;
5318}
5319#endif
5320
5321/*
5322 * Expand environment variables for some string options.
5323 * These string options cannot be indirect!
5324 * If "val" is NULL expand the current value of the option.
5325 * Return pointer to NameBuff, or NULL when not expanded.
5326 */
5327 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005328option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005329{
5330 /* if option doesn't need expansion nothing to do */
5331 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5332 return NULL;
5333
5334 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5335 * expand_env() would truncate the string. */
5336 if (val != NULL && STRLEN(val) > MAXPATHL)
5337 return NULL;
5338
5339 if (val == NULL)
5340 val = *(char_u **)options[opt_idx].var;
5341
5342 /*
5343 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5344 * Escape spaces when expanding 'tags', they are used to separate file
5345 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005346 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005347 */
5348 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005349 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005350#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005351 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5352#endif
5353 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5355 return NULL;
5356
5357 return NameBuff;
5358}
5359
5360/*
5361 * After setting various option values: recompute variables that depend on
5362 * option values.
5363 */
5364 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005365didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005366{
5367 /* initialize the table for 'iskeyword' et.al. */
5368 (void)init_chartab();
5369
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005370#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005371 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005374 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375#ifdef FEAT_SESSION
5376 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5377 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5378#endif
5379#ifdef FEAT_FOLDING
5380 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5381#endif
5382 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005383 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005384#ifdef FEAT_VIRTUALEDIT
5385 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5386#endif
5387#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5388 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5389#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005390#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005391 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005392 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005393 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005394 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005396#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5397 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5398#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005399#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005400 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5401#endif
5402#ifdef FEAT_CMDWIN
5403 /* set cedit_key */
5404 (void)check_cedit();
5405#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005406#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005407 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005408#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005409#ifdef FEAT_LINEBREAK
5410 /* initialize the table for 'breakat'. */
5411 fill_breakat_flags();
5412#endif
5413
5414}
5415
5416/*
5417 * More side effects of setting options.
5418 */
5419 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005420didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005421{
5422 /* Initialize the highlight_attr[] table. */
5423 (void)highlight_changed();
5424
5425 /* Parse default for 'wildmode' */
5426 check_opt_wim();
5427
5428 (void)set_chars_option(&p_lcs);
5429#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5430 /* Parse default for 'fillchars'. */
5431 (void)set_chars_option(&p_fcs);
5432#endif
5433
5434#ifdef FEAT_CLIPBOARD
5435 /* Parse default for 'clipboard' */
5436 (void)check_clipboard_option();
5437#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005438}
5439
5440/*
5441 * Check for string options that are NULL (normally only termcap options).
5442 */
5443 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005444check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005445{
5446 int opt_idx;
5447
5448 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5449 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5450 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5451}
5452
5453/*
5454 * Check string options in a buffer for NULL value.
5455 */
5456 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005457check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005458{
5459#if defined(FEAT_QUICKFIX)
5460 check_string_option(&buf->b_p_bh);
5461 check_string_option(&buf->b_p_bt);
5462#endif
5463#ifdef FEAT_MBYTE
5464 check_string_option(&buf->b_p_fenc);
5465#endif
5466 check_string_option(&buf->b_p_ff);
5467#ifdef FEAT_FIND_ID
5468 check_string_option(&buf->b_p_def);
5469 check_string_option(&buf->b_p_inc);
5470# ifdef FEAT_EVAL
5471 check_string_option(&buf->b_p_inex);
5472# endif
5473#endif
5474#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5475 check_string_option(&buf->b_p_inde);
5476 check_string_option(&buf->b_p_indk);
5477#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005478#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5479 check_string_option(&buf->b_p_bexpr);
5480#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005481#if defined(FEAT_CRYPT)
5482 check_string_option(&buf->b_p_cm);
5483#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005484#if defined(FEAT_EVAL)
5485 check_string_option(&buf->b_p_fex);
5486#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005487#ifdef FEAT_CRYPT
5488 check_string_option(&buf->b_p_key);
5489#endif
5490 check_string_option(&buf->b_p_kp);
5491 check_string_option(&buf->b_p_mps);
5492 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005493 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494 check_string_option(&buf->b_p_isk);
5495#ifdef FEAT_COMMENTS
5496 check_string_option(&buf->b_p_com);
5497#endif
5498#ifdef FEAT_FOLDING
5499 check_string_option(&buf->b_p_cms);
5500#endif
5501 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005502#ifdef FEAT_TEXTOBJ
5503 check_string_option(&buf->b_p_qe);
5504#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005505#ifdef FEAT_SYN_HL
5506 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005507 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005508#endif
5509#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005510 check_string_option(&buf->b_s.b_p_spc);
5511 check_string_option(&buf->b_s.b_p_spf);
5512 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513#endif
5514#ifdef FEAT_SEARCHPATH
5515 check_string_option(&buf->b_p_sua);
5516#endif
5517#ifdef FEAT_CINDENT
5518 check_string_option(&buf->b_p_cink);
5519 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005520 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521#endif
5522#ifdef FEAT_AUTOCMD
5523 check_string_option(&buf->b_p_ft);
5524#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005525#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5526 check_string_option(&buf->b_p_cinw);
5527#endif
5528#ifdef FEAT_INS_EXPAND
5529 check_string_option(&buf->b_p_cpt);
5530#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005531#ifdef FEAT_COMPL_FUNC
5532 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005533 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535#ifdef FEAT_KEYMAP
5536 check_string_option(&buf->b_p_keymap);
5537#endif
5538#ifdef FEAT_QUICKFIX
5539 check_string_option(&buf->b_p_gp);
5540 check_string_option(&buf->b_p_mp);
5541 check_string_option(&buf->b_p_efm);
5542#endif
5543 check_string_option(&buf->b_p_ep);
5544 check_string_option(&buf->b_p_path);
5545 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005546 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547#ifdef FEAT_INS_EXPAND
5548 check_string_option(&buf->b_p_dict);
5549 check_string_option(&buf->b_p_tsr);
5550#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005551#ifdef FEAT_LISP
5552 check_string_option(&buf->b_p_lw);
5553#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005554 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555}
5556
5557/*
5558 * Free the string allocated for an option.
5559 * Checks for the string being empty_option. This may happen if we're out of
5560 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5561 * check_options().
5562 * Does NOT check for P_ALLOCED flag!
5563 */
5564 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005565free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566{
5567 if (p != empty_option)
5568 vim_free(p);
5569}
5570
5571 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005572clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573{
5574 if (*pp != empty_option)
5575 vim_free(*pp);
5576 *pp = empty_option;
5577}
5578
5579 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005580check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581{
5582 if (*pp == NULL)
5583 *pp = empty_option;
5584}
5585
5586/*
5587 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5588 */
5589 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005590set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591{
5592 int opt_idx;
5593
5594 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5595 if (options[opt_idx].var == (char_u *)p)
5596 {
5597 options[opt_idx].flags |= P_ALLOCED;
5598 return;
5599 }
5600 return; /* cannot happen: didn't find it! */
5601}
5602
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005603#if defined(FEAT_EVAL) || defined(PROTO)
5604/*
5605 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5606 * Return FALSE when it wasn't.
5607 * Return -1 for an unknown option.
5608 */
5609 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005610was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005611{
5612 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005613 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005614
5615 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005616 {
5617 flagp = insecure_flag(idx, opt_flags);
5618 return (*flagp & P_INSECURE) != 0;
5619 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005620 EMSG2(_(e_intern2), "was_set_insecurely()");
5621 return -1;
5622}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005623
5624/*
5625 * Get a pointer to the flags used for the P_INSECURE flag of option
5626 * "opt_idx". For some local options a local flags field is used.
5627 */
5628 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005629insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005630{
5631 if (opt_flags & OPT_LOCAL)
5632 switch ((int)options[opt_idx].indir)
5633 {
5634#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005635 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005636#endif
5637#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005638# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005639 case PV_FDE: return &curwin->w_p_fde_flags;
5640 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005641# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005642# ifdef FEAT_BEVAL
5643 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5644# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005645# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005646 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005647# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005648 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005649# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005650 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005651# endif
5652#endif
5653 }
5654
5655 /* Nothing special, return global flags field. */
5656 return &options[opt_idx].flags;
5657}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005658#endif
5659
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005660#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005661static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005662
5663/*
5664 * Redraw the window title and/or tab page text later.
5665 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005666static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005667{
5668 need_maketitle = TRUE;
5669# ifdef FEAT_WINDOWS
5670 redraw_tabline = TRUE;
5671# endif
5672}
5673#endif
5674
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675/*
5676 * Set a string option to a new value (without checking the effect).
5677 * The string is copied into allocated memory.
5678 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005679 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005680 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681 */
5682 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005683set_string_option_direct(
5684 char_u *name,
5685 int opt_idx,
5686 char_u *val,
5687 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5688 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689{
5690 char_u *s;
5691 char_u **varp;
5692 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005693 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694
Bram Moolenaar89d40322006-08-29 15:30:07 +00005695 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005697 idx = findoption(name);
5698 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005699 {
5700 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005701 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704 }
5705
Bram Moolenaar89d40322006-08-29 15:30:07 +00005706 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707 return;
5708
5709 s = vim_strsave(val);
5710 if (s != NULL)
5711 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005712 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005714 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715 free_string_option(*varp);
5716 *varp = s;
5717
5718 /* For buffer/window local option may also set the global value. */
5719 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005720 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005721
Bram Moolenaar89d40322006-08-29 15:30:07 +00005722 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005723
5724 /* When setting both values of a global option with a local value,
5725 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005726 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727 {
5728 free_string_option(*varp);
5729 *varp = empty_option;
5730 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005731# ifdef FEAT_EVAL
5732 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005733 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005734 set_sid == 0 ? current_SID : set_sid);
5735# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736 }
5737}
5738
5739/*
5740 * Set global value for string option when it's a local option.
5741 */
5742 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005743set_string_option_global(
5744 int opt_idx, /* option index */
5745 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746{
5747 char_u **p, *s;
5748
5749 /* the global value is always allocated */
5750 if (options[opt_idx].var == VAR_WIN)
5751 p = (char_u **)GLOBAL_WO(varp);
5752 else
5753 p = (char_u **)options[opt_idx].var;
5754 if (options[opt_idx].indir != PV_NONE
5755 && p != varp
5756 && (s = vim_strsave(*varp)) != NULL)
5757 {
5758 free_string_option(*p);
5759 *p = s;
5760 }
5761}
5762
5763/*
5764 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005765 *
5766 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005767 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005768 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005769set_string_option(
5770 int opt_idx,
5771 char_u *value,
5772 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005773{
5774 char_u *s;
5775 char_u **varp;
5776 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005777#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5778 char_u *saved_oldval = NULL;
5779#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005780 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005781
5782 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005783 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005784
5785 s = vim_strsave(value);
5786 if (s != NULL)
5787 {
5788 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5789 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005790 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005791 ? OPT_GLOBAL : OPT_LOCAL)
5792 : opt_flags);
5793 oldval = *varp;
5794 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005795
5796#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005797 if (!starting
5798# ifdef FEAT_CRYPT
5799 && options[opt_idx].indir != PV_KEY
5800# endif
5801 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005802 saved_oldval = vim_strsave(oldval);
5803#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005804 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5805 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005806 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005807
5808 /* call autocomamnd after handling side effects */
5809#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5810 if (saved_oldval != NULL)
5811 {
5812 char_u buf_type[7];
5813 sprintf((char *)buf_type, "%s",
5814 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005815 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5816 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005817 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5818 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5819 reset_v_option_vars();
5820 vim_free(saved_oldval);
5821 }
5822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005823 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005824 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005825}
5826
5827/*
5828 * Handle string options that need some action to perform when changed.
5829 * Returns NULL for success, or an error message for an error.
5830 */
5831 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005832did_set_string_option(
5833 int opt_idx, /* index in options[] table */
5834 char_u **varp, /* pointer to the option variable */
5835 int new_value_alloced, /* new value was allocated */
5836 char_u *oldval, /* previous value of the option */
5837 char_u *errbuf, /* buffer for errors, or NULL */
5838 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005839{
5840 char_u *errmsg = NULL;
5841 char_u *s, *p;
5842 int did_chartab = FALSE;
5843 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005844 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005845#ifdef FEAT_GUI
5846 /* set when changing an option that only requires a redraw in the GUI */
5847 int redraw_gui_only = FALSE;
5848#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849
5850 /* Get the global option to compare with, otherwise we would have to check
5851 * two values for all local options. */
5852 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5853
5854 /* Disallow changing some options from secure mode */
5855 if ((secure
5856#ifdef HAVE_SANDBOX
5857 || sandbox != 0
5858#endif
5859 ) && (options[opt_idx].flags & P_SECURE))
5860 {
5861 errmsg = e_secure;
5862 }
5863
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005864 /* Check for a "normal" file name in some options. Disallow a path
5865 * separator (slash and/or backslash), wildcards and characters that are
5866 * often illegal in a file name. */
5867 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005868 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005869 {
5870 errmsg = e_invarg;
5871 }
5872
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873 /* 'term' */
5874 else if (varp == &T_NAME)
5875 {
5876 if (T_NAME[0] == NUL)
5877 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5878#ifdef FEAT_GUI
5879 if (gui.in_use)
5880 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5881 else if (term_is_gui(T_NAME))
5882 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5883#endif
5884 else if (set_termname(T_NAME) == FAIL)
5885 errmsg = (char_u *)N_("E522: Not found in termcap");
5886 else
5887 /* Screen colors may have changed. */
5888 redraw_later_clear();
5889 }
5890
5891 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005892 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005894 char_u *bkc = p_bkc;
5895 unsigned int *flags = &bkc_flags;
5896
5897 if (opt_flags & OPT_LOCAL)
5898 {
5899 bkc = curbuf->b_p_bkc;
5900 flags = &curbuf->b_bkc_flags;
5901 }
5902
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005903 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5904 /* make the local value empty: use the global value */
5905 *flags = 0;
5906 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005908 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5909 errmsg = e_invarg;
5910 if ((((int)*flags & BKC_AUTO) != 0)
5911 + (((int)*flags & BKC_YES) != 0)
5912 + (((int)*flags & BKC_NO) != 0) != 1)
5913 {
5914 /* Must have exactly one of "auto", "yes" and "no". */
5915 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5916 errmsg = e_invarg;
5917 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 }
5919 }
5920
5921 /* 'backupext' and 'patchmode' */
5922 else if (varp == &p_bex || varp == &p_pm)
5923 {
5924 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5925 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5926 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5927 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005928#ifdef FEAT_LINEBREAK
5929 /* 'breakindentopt' */
5930 else if (varp == &curwin->w_p_briopt)
5931 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005932 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005933 errmsg = e_invarg;
5934 }
5935#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005936
5937 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005938 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005939 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005940 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941 */
5942 else if ( varp == &p_isi
5943 || varp == &(curbuf->b_p_isk)
5944 || varp == &p_isp
5945 || varp == &p_isf)
5946 {
5947 if (init_chartab() == FAIL)
5948 {
5949 did_chartab = TRUE; /* need to restore it below */
5950 errmsg = e_invarg; /* error in value */
5951 }
5952 }
5953
5954 /* 'helpfile' */
5955 else if (varp == &p_hf)
5956 {
5957 /* May compute new values for $VIM and $VIMRUNTIME */
5958 if (didset_vim)
5959 {
5960 vim_setenv((char_u *)"VIM", (char_u *)"");
5961 didset_vim = FALSE;
5962 }
5963 if (didset_vimruntime)
5964 {
5965 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5966 didset_vimruntime = FALSE;
5967 }
5968 }
5969
Bram Moolenaar1a384422010-07-14 19:53:30 +02005970#ifdef FEAT_SYN_HL
5971 /* 'colorcolumn' */
5972 else if (varp == &curwin->w_p_cc)
5973 errmsg = check_colorcolumn(curwin);
5974#endif
5975
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976#ifdef FEAT_MULTI_LANG
5977 /* 'helplang' */
5978 else if (varp == &p_hlg)
5979 {
5980 /* Check for "", "ab", "ab,cd", etc. */
5981 for (s = p_hlg; *s != NUL; s += 3)
5982 {
5983 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5984 {
5985 errmsg = e_invarg;
5986 break;
5987 }
5988 if (s[2] == NUL)
5989 break;
5990 }
5991 }
5992#endif
5993
5994 /* 'highlight' */
5995 else if (varp == &p_hl)
5996 {
5997 if (highlight_changed() == FAIL)
5998 errmsg = e_invarg; /* invalid flags */
5999 }
6000
6001 /* 'nrformats' */
6002 else if (gvarp == &p_nf)
6003 {
6004 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6005 errmsg = e_invarg;
6006 }
6007
6008#ifdef FEAT_SESSION
6009 /* 'sessionoptions' */
6010 else if (varp == &p_ssop)
6011 {
6012 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6013 errmsg = e_invarg;
6014 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6015 {
6016 /* Don't allow both "sesdir" and "curdir". */
6017 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6018 errmsg = e_invarg;
6019 }
6020 }
6021 /* 'viewoptions' */
6022 else if (varp == &p_vop)
6023 {
6024 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6025 errmsg = e_invarg;
6026 }
6027#endif
6028
6029 /* 'scrollopt' */
6030#ifdef FEAT_SCROLLBIND
6031 else if (varp == &p_sbo)
6032 {
6033 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6034 errmsg = e_invarg;
6035 }
6036#endif
6037
6038 /* 'ambiwidth' */
6039#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006040 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006041 {
6042 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6043 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006044 else if (set_chars_option(&p_lcs) != NULL)
6045 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6046# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6047 else if (set_chars_option(&p_fcs) != NULL)
6048 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6049# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006050 }
6051#endif
6052
6053 /* 'background' */
6054 else if (varp == &p_bg)
6055 {
6056 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6057 {
6058#ifdef FEAT_EVAL
6059 int dark = (*p_bg == 'd');
6060#endif
6061
6062 init_highlight(FALSE, FALSE);
6063
6064#ifdef FEAT_EVAL
6065 if (dark != (*p_bg == 'd')
6066 && get_var_value((char_u *)"g:colors_name") != NULL)
6067 {
6068 /* The color scheme must have set 'background' back to another
6069 * value, that's not what we want here. Disable the color
6070 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006071 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006072 free_string_option(p_bg);
6073 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6074 check_string_option(&p_bg);
6075 init_highlight(FALSE, FALSE);
6076 }
6077#endif
6078 }
6079 else
6080 errmsg = e_invarg;
6081 }
6082
6083 /* 'wildmode' */
6084 else if (varp == &p_wim)
6085 {
6086 if (check_opt_wim() == FAIL)
6087 errmsg = e_invarg;
6088 }
6089
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006090#ifdef FEAT_CMDL_COMPL
6091 /* 'wildoptions' */
6092 else if (varp == &p_wop)
6093 {
6094 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6095 errmsg = e_invarg;
6096 }
6097#endif
6098
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099#ifdef FEAT_WAK
6100 /* 'winaltkeys' */
6101 else if (varp == &p_wak)
6102 {
6103 if (*p_wak == NUL
6104 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6105 errmsg = e_invarg;
6106# ifdef FEAT_MENU
6107# ifdef FEAT_GUI_MOTIF
6108 else if (gui.in_use)
6109 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6110# else
6111# ifdef FEAT_GUI_GTK
6112 else if (gui.in_use)
6113 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6114# endif
6115# endif
6116# endif
6117 }
6118#endif
6119
6120#ifdef FEAT_AUTOCMD
6121 /* 'eventignore' */
6122 else if (varp == &p_ei)
6123 {
6124 if (check_ei() == FAIL)
6125 errmsg = e_invarg;
6126 }
6127#endif
6128
6129#ifdef FEAT_MBYTE
6130 /* 'encoding' and 'fileencoding' */
6131 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6132 {
6133 if (gvarp == &p_fenc)
6134 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006135 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136 errmsg = e_modifiable;
6137 else if (vim_strchr(*varp, ',') != NULL)
6138 /* No comma allowed in 'fileencoding'; catches confusing it
6139 * with 'fileencodings'. */
6140 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006141 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006142 {
6143# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006145 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006146# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006147 /* Add 'fileencoding' to the swap file. */
6148 ml_setflags(curbuf);
6149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150 }
6151 if (errmsg == NULL)
6152 {
6153 /* canonize the value, so that STRCMP() can be used on it */
6154 p = enc_canonize(*varp);
6155 if (p != NULL)
6156 {
6157 vim_free(*varp);
6158 *varp = p;
6159 }
6160 if (varp == &p_enc)
6161 {
6162 errmsg = mb_init();
6163# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006164 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006165# endif
6166 }
6167 }
6168
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006169# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006170 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6171 {
6172 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6173 if (STRCMP(p_tenc, "utf-8") != 0)
6174 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6175 }
6176# endif
6177
6178 if (errmsg == NULL)
6179 {
6180# ifdef FEAT_KEYMAP
6181 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6182 * (with another encoding). */
6183 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6184 (void)keymap_init();
6185# endif
6186
6187 /* When 'termencoding' is not empty and 'encoding' changes or when
6188 * 'termencoding' changes, need to setup for keyboard input and
6189 * display output conversion. */
6190 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6191 {
6192 convert_setup(&input_conv, p_tenc, p_enc);
6193 convert_setup(&output_conv, p_enc, p_tenc);
6194 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006195
6196# if defined(WIN3264) && defined(FEAT_MBYTE)
6197 /* $HOME may have characters in active code page. */
6198 if (varp == &p_enc)
6199 init_homedir();
6200# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006201 }
6202 }
6203#endif
6204
6205#if defined(FEAT_POSTSCRIPT)
6206 else if (varp == &p_penc)
6207 {
6208 /* Canonize printencoding if VIM standard one */
6209 p = enc_canonize(p_penc);
6210 if (p != NULL)
6211 {
6212 vim_free(p_penc);
6213 p_penc = p;
6214 }
6215 else
6216 {
6217 /* Ensure lower case and '-' for '_' */
6218 for (s = p_penc; *s != NUL; s++)
6219 {
6220 if (*s == '_')
6221 *s = '-';
6222 else
6223 *s = TOLOWER_ASC(*s);
6224 }
6225 }
6226 }
6227#endif
6228
Bram Moolenaar9372a112005-12-06 19:59:18 +00006229#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006230 else if (varp == &p_imak)
6231 {
6232 if (gui.in_use && !im_xim_isvalid_imactivate())
6233 errmsg = e_invarg;
6234 }
6235#endif
6236
6237#ifdef FEAT_KEYMAP
6238 else if (varp == &curbuf->b_p_keymap)
6239 {
6240 /* load or unload key mapping tables */
6241 errmsg = keymap_init();
6242
Bram Moolenaarfab06232009-03-04 03:13:35 +00006243 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006244 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006245 if (*curbuf->b_p_keymap != NUL)
6246 {
6247 /* Installed a new keymap, switch on using it. */
6248 curbuf->b_p_iminsert = B_IMODE_LMAP;
6249 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6250 curbuf->b_p_imsearch = B_IMODE_LMAP;
6251 }
6252 else
6253 {
6254 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6255 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6256 curbuf->b_p_iminsert = B_IMODE_NONE;
6257 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6258 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6259 }
6260 if ((opt_flags & OPT_LOCAL) == 0)
6261 {
6262 set_iminsert_global();
6263 set_imsearch_global();
6264 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265# ifdef FEAT_WINDOWS
6266 status_redraw_curbuf();
6267# endif
6268 }
6269 }
6270#endif
6271
6272 /* 'fileformat' */
6273 else if (gvarp == &p_ff)
6274 {
6275 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6276 errmsg = e_modifiable;
6277 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6278 errmsg = e_invarg;
6279 else
6280 {
6281 /* may also change 'textmode' */
6282 if (get_fileformat(curbuf) == EOL_DOS)
6283 curbuf->b_p_tx = TRUE;
6284 else
6285 curbuf->b_p_tx = FALSE;
6286#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006287 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006288#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006289 /* update flag in swap file */
6290 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006291 /* Redraw needed when switching to/from "mac": a CR in the text
6292 * will be displayed differently. */
6293 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6294 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006295 }
6296 }
6297
6298 /* 'fileformats' */
6299 else if (varp == &p_ffs)
6300 {
6301 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6302 errmsg = e_invarg;
6303 else
6304 {
6305 /* also change 'textauto' */
6306 if (*p_ffs == NUL)
6307 p_ta = FALSE;
6308 else
6309 p_ta = TRUE;
6310 }
6311 }
6312
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006313#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314 /* 'cryptkey' */
6315 else if (gvarp == &p_key)
6316 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006317# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006318 /* Make sure the ":set" command doesn't show the new value in the
6319 * history. */
6320 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006321# endif
6322 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6323 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006324 ml_set_crypt_key(curbuf, oldval,
6325 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006326 }
6327
6328 else if (gvarp == &p_cm)
6329 {
6330 if (opt_flags & OPT_LOCAL)
6331 p = curbuf->b_p_cm;
6332 else
6333 p = p_cm;
6334 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6335 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006336 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006337 errmsg = e_invarg;
6338 else
6339 {
6340 /* When setting the global value to empty, make it "zip". */
6341 if (*p_cm == NUL)
6342 {
6343 if (new_value_alloced)
6344 free_string_option(p_cm);
6345 p_cm = vim_strsave((char_u *)"zip");
6346 new_value_alloced = TRUE;
6347 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006348 /* When using ":set cm=name" the local value is going to be empty.
6349 * Do that here, otherwise the crypt functions will still use the
6350 * local value. */
6351 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6352 {
6353 free_string_option(curbuf->b_p_cm);
6354 curbuf->b_p_cm = empty_option;
6355 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006356
6357 /* Need to update the swapfile when the effective method changed.
6358 * Set "s" to the effective old value, "p" to the effective new
6359 * method and compare. */
6360 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6361 s = p_cm; /* was previously using the global value */
6362 else
6363 s = oldval;
6364 if (*curbuf->b_p_cm == NUL)
6365 p = p_cm; /* is now using the global value */
6366 else
6367 p = curbuf->b_p_cm;
6368 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006369 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006370
6371 /* If the global value changes need to update the swapfile for all
6372 * buffers using that value. */
6373 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6374 {
6375 buf_T *buf;
6376
Bram Moolenaar29323592016-07-24 22:04:11 +02006377 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006378 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006379 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006380 }
6381 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006382 }
6383#endif
6384
6385 /* 'matchpairs' */
6386 else if (gvarp == &p_mps)
6387 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006388#ifdef FEAT_MBYTE
6389 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006390 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006391 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006393 int x2 = -1;
6394 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006395
6396 if (*p != NUL)
6397 p += mb_ptr2len(p);
6398 if (*p != NUL)
6399 x2 = *p++;
6400 if (*p != NUL)
6401 {
6402 x3 = mb_ptr2char(p);
6403 p += mb_ptr2len(p);
6404 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006405 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006406 {
6407 errmsg = e_invarg;
6408 break;
6409 }
6410 if (*p == NUL)
6411 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006412 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006413 }
6414 else
6415#endif
6416 {
6417 /* Check for "x:y,x:y" */
6418 for (p = *varp; *p != NUL; p += 4)
6419 {
6420 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6421 {
6422 errmsg = e_invarg;
6423 break;
6424 }
6425 if (p[3] == NUL)
6426 break;
6427 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006428 }
6429 }
6430
6431#ifdef FEAT_COMMENTS
6432 /* 'comments' */
6433 else if (gvarp == &p_com)
6434 {
6435 for (s = *varp; *s; )
6436 {
6437 while (*s && *s != ':')
6438 {
6439 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6440 && !VIM_ISDIGIT(*s) && *s != '-')
6441 {
6442 errmsg = illegal_char(errbuf, *s);
6443 break;
6444 }
6445 ++s;
6446 }
6447 if (*s++ == NUL)
6448 errmsg = (char_u *)N_("E524: Missing colon");
6449 else if (*s == ',' || *s == NUL)
6450 errmsg = (char_u *)N_("E525: Zero length string");
6451 if (errmsg != NULL)
6452 break;
6453 while (*s && *s != ',')
6454 {
6455 if (*s == '\\' && s[1] != NUL)
6456 ++s;
6457 ++s;
6458 }
6459 s = skip_to_option_part(s);
6460 }
6461 }
6462#endif
6463
6464 /* 'listchars' */
6465 else if (varp == &p_lcs)
6466 {
6467 errmsg = set_chars_option(varp);
6468 }
6469
6470#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6471 /* 'fillchars' */
6472 else if (varp == &p_fcs)
6473 {
6474 errmsg = set_chars_option(varp);
6475 }
6476#endif
6477
6478#ifdef FEAT_CMDWIN
6479 /* 'cedit' */
6480 else if (varp == &p_cedit)
6481 {
6482 errmsg = check_cedit();
6483 }
6484#endif
6485
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006486 /* 'verbosefile' */
6487 else if (varp == &p_vfile)
6488 {
6489 verbose_stop();
6490 if (*p_vfile != NUL && verbose_open() == FAIL)
6491 errmsg = e_invarg;
6492 }
6493
Bram Moolenaar071d4272004-06-13 20:20:40 +00006494#ifdef FEAT_VIMINFO
6495 /* 'viminfo' */
6496 else if (varp == &p_viminfo)
6497 {
6498 for (s = p_viminfo; *s;)
6499 {
6500 /* Check it's a valid character */
6501 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6502 {
6503 errmsg = illegal_char(errbuf, *s);
6504 break;
6505 }
6506 if (*s == 'n') /* name is always last one */
6507 {
6508 break;
6509 }
6510 else if (*s == 'r') /* skip until next ',' */
6511 {
6512 while (*++s && *s != ',')
6513 ;
6514 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006515 else if (*s == '%')
6516 {
6517 /* optional number */
6518 while (vim_isdigit(*++s))
6519 ;
6520 }
6521 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 ++s; /* no extra chars */
6523 else /* must have a number */
6524 {
6525 while (vim_isdigit(*++s))
6526 ;
6527
6528 if (!VIM_ISDIGIT(*(s - 1)))
6529 {
6530 if (errbuf != NULL)
6531 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006532 sprintf((char *)errbuf,
6533 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534 transchar_byte(*(s - 1)));
6535 errmsg = errbuf;
6536 }
6537 else
6538 errmsg = (char_u *)"";
6539 break;
6540 }
6541 }
6542 if (*s == ',')
6543 ++s;
6544 else if (*s)
6545 {
6546 if (errbuf != NULL)
6547 errmsg = (char_u *)N_("E527: Missing comma");
6548 else
6549 errmsg = (char_u *)"";
6550 break;
6551 }
6552 }
6553 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6554 errmsg = (char_u *)N_("E528: Must specify a ' value");
6555 }
6556#endif /* FEAT_VIMINFO */
6557
6558 /* terminal options */
6559 else if (istermoption(&options[opt_idx]) && full_screen)
6560 {
6561 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6562 if (varp == &T_CCO)
6563 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006564 int colors = atoi((char *)T_CCO);
6565
6566 /* Only reinitialize colors if t_Co value has really changed to
6567 * avoid expensive reload of colorscheme if t_Co is set to the
6568 * same value multiple times. */
6569 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006570 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006571 t_colors = colors;
6572 if (t_colors <= 1)
6573 {
6574 if (new_value_alloced)
6575 vim_free(T_CCO);
6576 T_CCO = empty_option;
6577 }
6578 /* We now have a different color setup, initialize it again. */
6579 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 }
6582 ttest(FALSE);
6583 if (varp == &T_ME)
6584 {
6585 out_str(T_ME);
6586 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006587#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006588 /* Since t_me has been set, this probably means that the user
6589 * wants to use this as default colors. Need to reset default
6590 * background/foreground colors. */
6591 mch_set_normal_colors();
6592#endif
6593 }
6594 }
6595
6596#ifdef FEAT_LINEBREAK
6597 /* 'showbreak' */
6598 else if (varp == &p_sbr)
6599 {
6600 for (s = p_sbr; *s; )
6601 {
6602 if (ptr2cells(s) != 1)
6603 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006604 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006605 }
6606 }
6607#endif
6608
6609#ifdef FEAT_GUI
6610 /* 'guifont' */
6611 else if (varp == &p_guifont)
6612 {
6613 if (gui.in_use)
6614 {
6615 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006616# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006617 /*
6618 * Put up a font dialog and let the user select a new value.
6619 * If this is cancelled go back to the old value but don't
6620 * give an error message.
6621 */
6622 if (STRCMP(p, "*") == 0)
6623 {
6624 p = gui_mch_font_dialog(oldval);
6625
6626 if (new_value_alloced)
6627 free_string_option(p_guifont);
6628
6629 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6630 new_value_alloced = TRUE;
6631 }
6632# endif
6633 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6634 {
6635# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6636 if (STRCMP(p_guifont, "*") == 0)
6637 {
6638 /* Dialog was cancelled: Keep the old value without giving
6639 * an error message. */
6640 if (new_value_alloced)
6641 free_string_option(p_guifont);
6642 p_guifont = vim_strsave(oldval);
6643 new_value_alloced = TRUE;
6644 }
6645 else
6646# endif
6647 errmsg = (char_u *)N_("E596: Invalid font(s)");
6648 }
6649 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006650 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006651 }
6652# ifdef FEAT_XFONTSET
6653 else if (varp == &p_guifontset)
6654 {
6655 if (STRCMP(p_guifontset, "*") == 0)
6656 errmsg = (char_u *)N_("E597: can't select fontset");
6657 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6658 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006659 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006660 }
6661# endif
6662# ifdef FEAT_MBYTE
6663 else if (varp == &p_guifontwide)
6664 {
6665 if (STRCMP(p_guifontwide, "*") == 0)
6666 errmsg = (char_u *)N_("E533: can't select wide font");
6667 else if (gui_get_wide_font() == FAIL)
6668 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006669 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670 }
6671# endif
6672#endif
6673
6674#ifdef CURSOR_SHAPE
6675 /* 'guicursor' */
6676 else if (varp == &p_guicursor)
6677 errmsg = parse_shape_opt(SHAPE_CURSOR);
6678#endif
6679
6680#ifdef FEAT_MOUSESHAPE
6681 /* 'mouseshape' */
6682 else if (varp == &p_mouseshape)
6683 {
6684 errmsg = parse_shape_opt(SHAPE_MOUSE);
6685 update_mouseshape(-1);
6686 }
6687#endif
6688
6689#ifdef FEAT_PRINTER
6690 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006691 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006692# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006693 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006694 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006695# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006696#endif
6697
6698#ifdef FEAT_LANGMAP
6699 /* 'langmap' */
6700 else if (varp == &p_langmap)
6701 langmap_set();
6702#endif
6703
6704#ifdef FEAT_LINEBREAK
6705 /* 'breakat' */
6706 else if (varp == &p_breakat)
6707 fill_breakat_flags();
6708#endif
6709
6710#ifdef FEAT_TITLE
6711 /* 'titlestring' and 'iconstring' */
6712 else if (varp == &p_titlestring || varp == &p_iconstring)
6713 {
6714# ifdef FEAT_STL_OPT
6715 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6716
6717 /* NULL => statusline syntax */
6718 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6719 stl_syntax |= flagval;
6720 else
6721 stl_syntax &= ~flagval;
6722# endif
6723 did_set_title(varp == &p_iconstring);
6724
6725 }
6726#endif
6727
6728#ifdef FEAT_GUI
6729 /* 'guioptions' */
6730 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006731 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006733 redraw_gui_only = TRUE;
6734 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006735#endif
6736
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006737#if defined(FEAT_GUI_TABLINE)
6738 /* 'guitablabel' */
6739 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006740 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006741 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006742 redraw_gui_only = TRUE;
6743 }
6744 /* 'guitabtooltip' */
6745 else if (varp == &p_gtt)
6746 {
6747 redraw_gui_only = TRUE;
6748 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006749#endif
6750
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6752 /* 'ttymouse' */
6753 else if (varp == &p_ttym)
6754 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006755 /* Switch the mouse off before changing the escape sequences used for
6756 * that. */
6757 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6759 errmsg = e_invarg;
6760 else
6761 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006762 if (termcap_active)
6763 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006764 }
6765#endif
6766
Bram Moolenaar071d4272004-06-13 20:20:40 +00006767 /* 'selection' */
6768 else if (varp == &p_sel)
6769 {
6770 if (*p_sel == NUL
6771 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6772 errmsg = e_invarg;
6773 }
6774
6775 /* 'selectmode' */
6776 else if (varp == &p_slm)
6777 {
6778 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6779 errmsg = e_invarg;
6780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781
6782#ifdef FEAT_BROWSE
6783 /* 'browsedir' */
6784 else if (varp == &p_bsdir)
6785 {
6786 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6787 && !mch_isdir(p_bsdir))
6788 errmsg = e_invarg;
6789 }
6790#endif
6791
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792 /* 'keymodel' */
6793 else if (varp == &p_km)
6794 {
6795 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6796 errmsg = e_invarg;
6797 else
6798 {
6799 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6800 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6801 }
6802 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006803
6804 /* 'mousemodel' */
6805 else if (varp == &p_mousem)
6806 {
6807 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6808 errmsg = e_invarg;
6809#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6810 else if (*p_mousem != *oldval)
6811 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6812 * to create or delete the popup menus. */
6813 gui_motif_update_mousemodel(root_menu);
6814#endif
6815 }
6816
6817 /* 'switchbuf' */
6818 else if (varp == &p_swb)
6819 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006820 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821 errmsg = e_invarg;
6822 }
6823
6824 /* 'debug' */
6825 else if (varp == &p_debug)
6826 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006827 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 errmsg = e_invarg;
6829 }
6830
6831 /* 'display' */
6832 else if (varp == &p_dy)
6833 {
6834 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6835 errmsg = e_invarg;
6836 else
6837 (void)init_chartab();
6838
6839 }
6840
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006841#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006842 /* 'eadirection' */
6843 else if (varp == &p_ead)
6844 {
6845 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6846 errmsg = e_invarg;
6847 }
6848#endif
6849
6850#ifdef FEAT_CLIPBOARD
6851 /* 'clipboard' */
6852 else if (varp == &p_cb)
6853 errmsg = check_clipboard_option();
6854#endif
6855
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006856#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006857 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6858 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006859 else if (varp == &(curwin->w_s->b_p_spl)
6860 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006861 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006862 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006863 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006864 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006865 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006866 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006867 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006868 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006869 /* 'spellsuggest' */
6870 else if (varp == &p_sps)
6871 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006872 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006873 errmsg = e_invarg;
6874 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006875 /* 'mkspellmem' */
6876 else if (varp == &p_msm)
6877 {
6878 if (spell_check_msm() != OK)
6879 errmsg = e_invarg;
6880 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006881#endif
6882
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883#ifdef FEAT_QUICKFIX
6884 /* When 'bufhidden' is set, check for valid value. */
6885 else if (gvarp == &p_bh)
6886 {
6887 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6888 errmsg = e_invarg;
6889 }
6890
6891 /* When 'buftype' is set, check for valid value. */
6892 else if (gvarp == &p_bt)
6893 {
6894 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6895 errmsg = e_invarg;
6896 else
6897 {
6898# ifdef FEAT_WINDOWS
6899 if (curwin->w_status_height)
6900 {
6901 curwin->w_redr_status = TRUE;
6902 redraw_later(VALID);
6903 }
6904# endif
6905 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006906# ifdef FEAT_TITLE
6907 redraw_titles();
6908# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909 }
6910 }
6911#endif
6912
6913#ifdef FEAT_STL_OPT
6914 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006915 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006916 {
6917 int wid;
6918
6919 if (varp == &p_ruf) /* reset ru_wid first */
6920 ru_wid = 0;
6921 s = *varp;
6922 if (varp == &p_ruf && *s == '%')
6923 {
6924 /* set ru_wid if 'ruf' starts with "%99(" */
6925 if (*++s == '-') /* ignore a '-' */
6926 s++;
6927 wid = getdigits(&s);
6928 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6929 ru_wid = wid;
6930 else
6931 errmsg = check_stl_option(p_ruf);
6932 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006933 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006934 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006935 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006936 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006937 comp_col();
6938 }
6939#endif
6940
6941#ifdef FEAT_INS_EXPAND
6942 /* check if it is a valid value for 'complete' -- Acevedo */
6943 else if (gvarp == &p_cpt)
6944 {
6945 for (s = *varp; *s;)
6946 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006947 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006948 s++;
6949 if (!*s)
6950 break;
6951 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6952 {
6953 errmsg = illegal_char(errbuf, *s);
6954 break;
6955 }
6956 if (*++s != NUL && *s != ',' && *s != ' ')
6957 {
6958 if (s[-1] == 'k' || s[-1] == 's')
6959 {
6960 /* skip optional filename after 'k' and 's' */
6961 while (*s && *s != ',' && *s != ' ')
6962 {
6963 if (*s == '\\')
6964 ++s;
6965 ++s;
6966 }
6967 }
6968 else
6969 {
6970 if (errbuf != NULL)
6971 {
6972 sprintf((char *)errbuf,
6973 _("E535: Illegal character after <%c>"),
6974 *--s);
6975 errmsg = errbuf;
6976 }
6977 else
6978 errmsg = (char_u *)"";
6979 break;
6980 }
6981 }
6982 }
6983 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006984
6985 /* 'completeopt' */
6986 else if (varp == &p_cot)
6987 {
6988 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6989 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02006990 else
6991 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993#endif /* FEAT_INS_EXPAND */
6994
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02006995#ifdef FEAT_SIGNS
6996 /* 'signcolumn' */
6997 else if (varp == &curwin->w_p_scl)
6998 {
6999 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7000 errmsg = e_invarg;
7001 }
7002#endif
7003
Bram Moolenaar071d4272004-06-13 20:20:40 +00007004
7005#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
7006 else if (varp == &p_toolbar)
7007 {
7008 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7009 &toolbar_flags, TRUE) != OK)
7010 errmsg = e_invarg;
7011 else
7012 {
7013 out_flush();
7014 gui_mch_show_toolbar((toolbar_flags &
7015 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7016 }
7017 }
7018#endif
7019
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007020#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007021 /* 'toolbariconsize': GTK+ 2 only */
7022 else if (varp == &p_tbis)
7023 {
7024 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7025 errmsg = e_invarg;
7026 else
7027 {
7028 out_flush();
7029 gui_mch_show_toolbar((toolbar_flags &
7030 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7031 }
7032 }
7033#endif
7034
7035 /* 'pastetoggle': translate key codes like in a mapping */
7036 else if (varp == &p_pt)
7037 {
7038 if (*p_pt)
7039 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007040 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041 if (p != NULL)
7042 {
7043 if (new_value_alloced)
7044 free_string_option(p_pt);
7045 p_pt = p;
7046 new_value_alloced = TRUE;
7047 }
7048 }
7049 }
7050
7051 /* 'backspace' */
7052 else if (varp == &p_bs)
7053 {
7054 if (VIM_ISDIGIT(*p_bs))
7055 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007056 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007057 errmsg = e_invarg;
7058 }
7059 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7060 errmsg = e_invarg;
7061 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007062 else if (varp == &p_bo)
7063 {
7064 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7065 errmsg = e_invarg;
7066 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007068 /* 'tagcase' */
7069 else if (gvarp == &p_tc)
7070 {
7071 unsigned int *flags;
7072
7073 if (opt_flags & OPT_LOCAL)
7074 {
7075 p = curbuf->b_p_tc;
7076 flags = &curbuf->b_tc_flags;
7077 }
7078 else
7079 {
7080 p = p_tc;
7081 flags = &tc_flags;
7082 }
7083
7084 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7085 /* make the local value empty: use the global value */
7086 *flags = 0;
7087 else if (*p == NUL
7088 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7089 errmsg = e_invarg;
7090 }
7091
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007092#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007093 /* 'casemap' */
7094 else if (varp == &p_cmp)
7095 {
7096 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7097 errmsg = e_invarg;
7098 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007099#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100
7101#ifdef FEAT_DIFF
7102 /* 'diffopt' */
7103 else if (varp == &p_dip)
7104 {
7105 if (diffopt_changed() == FAIL)
7106 errmsg = e_invarg;
7107 }
7108#endif
7109
7110#ifdef FEAT_FOLDING
7111 /* 'foldmethod' */
7112 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7113 {
7114 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7115 || *curwin->w_p_fdm == NUL)
7116 errmsg = e_invarg;
7117 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007118 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007120 if (foldmethodIsDiff(curwin))
7121 newFoldLevel();
7122 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007123 }
7124# ifdef FEAT_EVAL
7125 /* 'foldexpr' */
7126 else if (varp == &curwin->w_p_fde)
7127 {
7128 if (foldmethodIsExpr(curwin))
7129 foldUpdateAll(curwin);
7130 }
7131# endif
7132 /* 'foldmarker' */
7133 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7134 {
7135 p = vim_strchr(*varp, ',');
7136 if (p == NULL)
7137 errmsg = (char_u *)N_("E536: comma required");
7138 else if (p == *varp || p[1] == NUL)
7139 errmsg = e_invarg;
7140 else if (foldmethodIsMarker(curwin))
7141 foldUpdateAll(curwin);
7142 }
7143 /* 'commentstring' */
7144 else if (gvarp == &p_cms)
7145 {
7146 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7147 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7148 }
7149 /* 'foldopen' */
7150 else if (varp == &p_fdo)
7151 {
7152 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7153 errmsg = e_invarg;
7154 }
7155 /* 'foldclose' */
7156 else if (varp == &p_fcl)
7157 {
7158 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7159 errmsg = e_invarg;
7160 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007161 /* 'foldignore' */
7162 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7163 {
7164 if (foldmethodIsIndent(curwin))
7165 foldUpdateAll(curwin);
7166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007167#endif
7168
7169#ifdef FEAT_VIRTUALEDIT
7170 /* 'virtualedit' */
7171 else if (varp == &p_ve)
7172 {
7173 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7174 errmsg = e_invarg;
7175 else if (STRCMP(p_ve, oldval) != 0)
7176 {
7177 /* Recompute cursor position in case the new 've' setting
7178 * changes something. */
7179 validate_virtcol();
7180 coladvance(curwin->w_virtcol);
7181 }
7182 }
7183#endif
7184
7185#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7186 else if (varp == &p_csqf)
7187 {
7188 if (p_csqf != NULL)
7189 {
7190 p = p_csqf;
7191 while (*p != NUL)
7192 {
7193 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7194 || p[1] == NUL
7195 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7196 || (p[2] != NUL && p[2] != ','))
7197 {
7198 errmsg = e_invarg;
7199 break;
7200 }
7201 else if (p[2] == NUL)
7202 break;
7203 else
7204 p += 3;
7205 }
7206 }
7207 }
7208#endif
7209
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007210#ifdef FEAT_CINDENT
7211 /* 'cinoptions' */
7212 else if (gvarp == &p_cino)
7213 {
7214 /* TODO: recognize errors */
7215 parse_cino(curbuf);
7216 }
7217#endif
7218
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007219#if defined(FEAT_RENDER_OPTIONS)
7220 else if (varp == &p_rop && gui.in_use)
7221 {
7222 if (!gui_mch_set_rendering_options(p_rop))
7223 errmsg = e_invarg;
7224 }
7225#endif
7226
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227 /* Options that are a list of flags. */
7228 else
7229 {
7230 p = NULL;
7231 if (varp == &p_ww)
7232 p = (char_u *)WW_ALL;
7233 if (varp == &p_shm)
7234 p = (char_u *)SHM_ALL;
7235 else if (varp == &(p_cpo))
7236 p = (char_u *)CPO_ALL;
7237 else if (varp == &(curbuf->b_p_fo))
7238 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007239#ifdef FEAT_CONCEAL
7240 else if (varp == &curwin->w_p_cocu)
7241 p = (char_u *)COCU_ALL;
7242#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007243 else if (varp == &p_mouse)
7244 {
7245#ifdef FEAT_MOUSE
7246 p = (char_u *)MOUSE_ALL;
7247#else
7248 if (*p_mouse != NUL)
7249 errmsg = (char_u *)N_("E538: No mouse support");
7250#endif
7251 }
7252#if defined(FEAT_GUI)
7253 else if (varp == &p_go)
7254 p = (char_u *)GO_ALL;
7255#endif
7256 if (p != NULL)
7257 {
7258 for (s = *varp; *s; ++s)
7259 if (vim_strchr(p, *s) == NULL)
7260 {
7261 errmsg = illegal_char(errbuf, *s);
7262 break;
7263 }
7264 }
7265 }
7266
7267 /*
7268 * If error detected, restore the previous value.
7269 */
7270 if (errmsg != NULL)
7271 {
7272 if (new_value_alloced)
7273 free_string_option(*varp);
7274 *varp = oldval;
7275 /*
7276 * When resetting some values, need to act on it.
7277 */
7278 if (did_chartab)
7279 (void)init_chartab();
7280 if (varp == &p_hl)
7281 (void)highlight_changed();
7282 }
7283 else
7284 {
7285#ifdef FEAT_EVAL
7286 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007287 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007288#endif
7289 /*
7290 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007291 * Use "free_oldval", because recursiveness may change the flags under
7292 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007293 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007294 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007295 free_string_option(oldval);
7296 if (new_value_alloced)
7297 options[opt_idx].flags |= P_ALLOCED;
7298 else
7299 options[opt_idx].flags &= ~P_ALLOCED;
7300
7301 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007302 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007303 {
7304 /* global option with local value set to use global value; free
7305 * the local value and make it empty */
7306 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7307 free_string_option(*(char_u **)p);
7308 *(char_u **)p = empty_option;
7309 }
7310
7311 /* May set global value for local option. */
7312 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7313 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007314
7315#ifdef FEAT_AUTOCMD
7316 /*
7317 * Trigger the autocommand only after setting the flags.
7318 */
7319# ifdef FEAT_SYN_HL
7320 /* When 'syntax' is set, load the syntax of that name */
7321 if (varp == &(curbuf->b_p_syn))
7322 {
7323 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7324 curbuf->b_fname, TRUE, curbuf);
7325 }
7326# endif
7327 else if (varp == &(curbuf->b_p_ft))
7328 {
7329 /* 'filetype' is set, trigger the FileType autocommand */
7330 did_filetype = TRUE;
7331 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7332 curbuf->b_fname, TRUE, curbuf);
7333 }
7334#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007335#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007336 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007337 {
7338 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007339 char_u *q = curwin->w_s->b_p_spl;
7340
7341 /* Skip the first name if it is "cjk". */
7342 if (STRNCMP(q, "cjk,", 4) == 0)
7343 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007344
7345 /*
7346 * Source the spell/LANG.vim in 'runtimepath'.
7347 * They could set 'spellcapcheck' depending on the language.
7348 * Use the first name in 'spelllang' up to '_region' or
7349 * '.encoding'.
7350 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007351 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007352 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7353 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007354 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007355 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007356 }
7357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358 }
7359
7360#ifdef FEAT_MOUSE
7361 if (varp == &p_mouse)
7362 {
7363# ifdef FEAT_MOUSE_TTY
7364 if (*p_mouse == NUL)
7365 mch_setmouse(FALSE); /* switch mouse off */
7366 else
7367# endif
7368 setmouse(); /* in case 'mouse' changed */
7369 }
7370#endif
7371
Bram Moolenaar913077c2012-03-28 19:59:04 +02007372 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007373 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007374 curwin->w_set_curswant = TRUE;
7375
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007376#ifdef FEAT_GUI
7377 /* check redraw when it's not a GUI option or the GUI is active. */
7378 if (!redraw_gui_only || gui.in_use)
7379#endif
7380 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007381
7382 return errmsg;
7383}
7384
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007385#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007386/*
7387 * Simple int comparison function for use with qsort()
7388 */
7389 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007390int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007391{
7392 return *(const int *)a - *(const int *)b;
7393}
7394
7395/*
7396 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7397 * Returns error message, NULL if it's OK.
7398 */
7399 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007400check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007401{
7402 char_u *s;
7403 int col;
7404 int count = 0;
7405 int color_cols[256];
7406 int i;
7407 int j = 0;
7408
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007409 if (wp->w_buffer == NULL)
7410 return NULL; /* buffer was closed */
7411
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007412 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007413 {
7414 if (*s == '-' || *s == '+')
7415 {
7416 /* -N and +N: add to 'textwidth' */
7417 col = (*s == '-') ? -1 : 1;
7418 ++s;
7419 if (!VIM_ISDIGIT(*s))
7420 return e_invarg;
7421 col = col * getdigits(&s);
7422 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007423 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007424 col += wp->w_buffer->b_p_tw;
7425 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007426 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007427 }
7428 else if (VIM_ISDIGIT(*s))
7429 col = getdigits(&s);
7430 else
7431 return e_invarg;
7432 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007433skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007434 if (*s == NUL)
7435 break;
7436 if (*s != ',')
7437 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007438 if (*++s == NUL)
7439 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007440 }
7441
7442 vim_free(wp->w_p_cc_cols);
7443 if (count == 0)
7444 wp->w_p_cc_cols = NULL;
7445 else
7446 {
7447 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7448 if (wp->w_p_cc_cols != NULL)
7449 {
7450 /* sort the columns for faster usage on screen redraw inside
7451 * win_line() */
7452 qsort(color_cols, count, sizeof(int), int_cmp);
7453
7454 for (i = 0; i < count; ++i)
7455 /* skip duplicates */
7456 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7457 wp->w_p_cc_cols[j++] = color_cols[i];
7458 wp->w_p_cc_cols[j] = -1; /* end marker */
7459 }
7460 }
7461
7462 return NULL; /* no error */
7463}
7464#endif
7465
Bram Moolenaar071d4272004-06-13 20:20:40 +00007466/*
7467 * Handle setting 'listchars' or 'fillchars'.
7468 * Returns error message, NULL if it's OK.
7469 */
7470 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007471set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007472{
7473 int round, i, len, entries;
7474 char_u *p, *s;
7475 int c1, c2 = 0;
7476 struct charstab
7477 {
7478 int *cp;
7479 char *name;
7480 };
7481#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7482 static struct charstab filltab[] =
7483 {
7484 {&fill_stl, "stl"},
7485 {&fill_stlnc, "stlnc"},
7486 {&fill_vert, "vert"},
7487 {&fill_fold, "fold"},
7488 {&fill_diff, "diff"},
7489 };
7490#endif
7491 static struct charstab lcstab[] =
7492 {
7493 {&lcs_eol, "eol"},
7494 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007495 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007497 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 {&lcs_tab2, "tab"},
7499 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007500#ifdef FEAT_CONCEAL
7501 {&lcs_conceal, "conceal"},
7502#else
7503 {NULL, "conceal"},
7504#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007505 };
7506 struct charstab *tab;
7507
7508#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7509 if (varp == &p_lcs)
7510#endif
7511 {
7512 tab = lcstab;
7513 entries = sizeof(lcstab) / sizeof(struct charstab);
7514 }
7515#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7516 else
7517 {
7518 tab = filltab;
7519 entries = sizeof(filltab) / sizeof(struct charstab);
7520 }
7521#endif
7522
7523 /* first round: check for valid value, second round: assign values */
7524 for (round = 0; round <= 1; ++round)
7525 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007526 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 {
7528 /* After checking that the value is valid: set defaults: space for
7529 * 'fillchars', NUL for 'listchars' */
7530 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007531 if (tab[i].cp != NULL)
7532 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007533 if (varp == &p_lcs)
7534 lcs_tab1 = NUL;
7535#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7536 else
7537 fill_diff = '-';
7538#endif
7539 }
7540 p = *varp;
7541 while (*p)
7542 {
7543 for (i = 0; i < entries; ++i)
7544 {
7545 len = (int)STRLEN(tab[i].name);
7546 if (STRNCMP(p, tab[i].name, len) == 0
7547 && p[len] == ':'
7548 && p[len + 1] != NUL)
7549 {
7550 s = p + len + 1;
7551#ifdef FEAT_MBYTE
7552 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007553 if (mb_char2cells(c1) > 1)
7554 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007555#else
7556 c1 = *s++;
7557#endif
7558 if (tab[i].cp == &lcs_tab2)
7559 {
7560 if (*s == NUL)
7561 continue;
7562#ifdef FEAT_MBYTE
7563 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007564 if (mb_char2cells(c2) > 1)
7565 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007566#else
7567 c2 = *s++;
7568#endif
7569 }
7570 if (*s == ',' || *s == NUL)
7571 {
7572 if (round)
7573 {
7574 if (tab[i].cp == &lcs_tab2)
7575 {
7576 lcs_tab1 = c1;
7577 lcs_tab2 = c2;
7578 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007579 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007580 *(tab[i].cp) = c1;
7581
7582 }
7583 p = s;
7584 break;
7585 }
7586 }
7587 }
7588
7589 if (i == entries)
7590 return e_invarg;
7591 if (*p == ',')
7592 ++p;
7593 }
7594 }
7595
7596 return NULL; /* no error */
7597}
7598
7599#ifdef FEAT_STL_OPT
7600/*
7601 * Check validity of options with the 'statusline' format.
7602 * Return error message or NULL.
7603 */
7604 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007605check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007606{
7607 int itemcnt = 0;
7608 int groupdepth = 0;
7609 static char_u errbuf[80];
7610
7611 while (*s && itemcnt < STL_MAX_ITEM)
7612 {
7613 /* Check for valid keys after % sequences */
7614 while (*s && *s != '%')
7615 s++;
7616 if (!*s)
7617 break;
7618 s++;
7619 if (*s != '%' && *s != ')')
7620 ++itemcnt;
7621 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7622 {
7623 s++;
7624 continue;
7625 }
7626 if (*s == ')')
7627 {
7628 s++;
7629 if (--groupdepth < 0)
7630 break;
7631 continue;
7632 }
7633 if (*s == '-')
7634 s++;
7635 while (VIM_ISDIGIT(*s))
7636 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007637 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007638 continue;
7639 if (*s == '.')
7640 {
7641 s++;
7642 while (*s && VIM_ISDIGIT(*s))
7643 s++;
7644 }
7645 if (*s == '(')
7646 {
7647 groupdepth++;
7648 continue;
7649 }
7650 if (vim_strchr(STL_ALL, *s) == NULL)
7651 {
7652 return illegal_char(errbuf, *s);
7653 }
7654 if (*s == '{')
7655 {
7656 s++;
7657 while (*s != '}' && *s)
7658 s++;
7659 if (*s != '}')
7660 return (char_u *)N_("E540: Unclosed expression sequence");
7661 }
7662 }
7663 if (itemcnt >= STL_MAX_ITEM)
7664 return (char_u *)N_("E541: too many items");
7665 if (groupdepth != 0)
7666 return (char_u *)N_("E542: unbalanced groups");
7667 return NULL;
7668}
7669#endif
7670
7671#ifdef FEAT_CLIPBOARD
7672/*
7673 * Extract the items in the 'clipboard' option and set global values.
7674 */
7675 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007676check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007677{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007678 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007679 int new_autoselect_star = FALSE;
7680 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007682 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007683 regprog_T *new_exclude_prog = NULL;
7684 char_u *errmsg = NULL;
7685 char_u *p;
7686
7687 for (p = p_cb; *p != NUL; )
7688 {
7689 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7690 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007691 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007692 p += 7;
7693 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007694 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007695 && (p[11] == ',' || p[11] == NUL))
7696 {
7697 new_unnamed |= CLIP_UNNAMED_PLUS;
7698 p += 11;
7699 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007700 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007701 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007702 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007703 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 p += 10;
7705 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007706 else if (STRNCMP(p, "autoselectplus", 14) == 0
7707 && (p[14] == ',' || p[14] == NUL))
7708 {
7709 new_autoselect_plus = TRUE;
7710 p += 14;
7711 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007713 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007714 {
7715 new_autoselectml = TRUE;
7716 p += 12;
7717 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007718 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7719 {
7720 new_html = TRUE;
7721 p += 4;
7722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7724 {
7725 p += 8;
7726 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7727 if (new_exclude_prog == NULL)
7728 errmsg = e_invarg;
7729 break;
7730 }
7731 else
7732 {
7733 errmsg = e_invarg;
7734 break;
7735 }
7736 if (*p == ',')
7737 ++p;
7738 }
7739 if (errmsg == NULL)
7740 {
7741 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007742 clip_autoselect_star = new_autoselect_star;
7743 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007744 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007745 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007746 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007748#ifdef FEAT_GUI_GTK
7749 if (gui.in_use)
7750 {
7751 gui_gtk_set_selection_targets();
7752 gui_gtk_set_dnd_targets();
7753 }
7754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 }
7756 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007757 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758
7759 return errmsg;
7760}
7761#endif
7762
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007763#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007764 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007765did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007766{
7767 char_u *errmsg = NULL;
7768 win_T *wp;
7769 int l;
7770
7771 if (is_spellfile)
7772 {
7773 l = (int)STRLEN(curwin->w_s->b_p_spf);
7774 if (l > 0 && (l < 4
7775 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7776 errmsg = e_invarg;
7777 }
7778
7779 if (errmsg == NULL)
7780 {
7781 FOR_ALL_WINDOWS(wp)
7782 if (wp->w_buffer == curbuf && wp->w_p_spell)
7783 {
7784 errmsg = did_set_spelllang(wp);
7785# ifdef FEAT_WINDOWS
7786 break;
7787# endif
7788 }
7789 }
7790 return errmsg;
7791}
7792
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007793/*
7794 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7795 * Return error message when failed, NULL when OK.
7796 */
7797 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007798compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007799{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007800 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007801 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007802
Bram Moolenaar860cae12010-06-05 23:22:07 +02007803 if (*synblock->b_p_spc == NUL)
7804 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007805 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007806 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007807 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007808 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007809 if (re != NULL)
7810 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007811 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007812 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007813 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007814 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007815 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007816 return e_invarg;
7817 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007818 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007819 }
7820
Bram Moolenaar473de612013-06-08 18:19:48 +02007821 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007822 return NULL;
7823}
7824#endif
7825
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007826#if defined(FEAT_EVAL) || defined(PROTO)
7827/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007828 * Set the scriptID for an option, taking care of setting the buffer- or
7829 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007830 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007831 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007832set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007833{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007834 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7835 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007836
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007837 /* Remember where the option was set. For local options need to do that
7838 * in the buffer or window structure. */
7839 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007840 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007841 if (both || (opt_flags & OPT_LOCAL))
7842 {
7843 if (indir & PV_BUF)
7844 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7845 else if (indir & PV_WIN)
7846 curwin->w_p_scriptID[indir & PV_MASK] = id;
7847 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007848}
7849#endif
7850
Bram Moolenaar071d4272004-06-13 20:20:40 +00007851/*
7852 * Set the value of a boolean option, and take care of side effects.
7853 * Returns NULL for success, or an error message for an error.
7854 */
7855 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007856set_bool_option(
7857 int opt_idx, /* index in options[] table */
7858 char_u *varp, /* pointer to the option variable */
7859 int value, /* new value */
7860 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861{
7862 int old_value = *(int *)varp;
7863
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864 /* Disallow changing some options from secure mode */
7865 if ((secure
7866#ifdef HAVE_SANDBOX
7867 || sandbox != 0
7868#endif
7869 ) && (options[opt_idx].flags & P_SECURE))
7870 return e_secure;
7871
7872 *(int *)varp = value; /* set the new value */
7873#ifdef FEAT_EVAL
7874 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007875 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007876#endif
7877
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007878#ifdef FEAT_GUI
7879 need_mouse_correct = TRUE;
7880#endif
7881
Bram Moolenaar071d4272004-06-13 20:20:40 +00007882 /* May set global value for local option. */
7883 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7884 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7885
7886 /*
7887 * Handle side effects of changing a bool option.
7888 */
7889
7890 /* 'compatible' */
7891 if ((int *)varp == &p_cp)
7892 {
7893 compatible_set();
7894 }
7895
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007896#ifdef FEAT_PERSISTENT_UNDO
7897 /* 'undofile' */
7898 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7899 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007900 /* Only take action when the option was set. When reset we do not
7901 * delete the undo file, the option may be set again without making
7902 * any changes in between. */
7903 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007904 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007905 char_u hash[UNDO_HASH_SIZE];
7906 buf_T *save_curbuf = curbuf;
7907
Bram Moolenaar29323592016-07-24 22:04:11 +02007908 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007909 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007910 /* When 'undofile' is set globally: for every buffer, otherwise
7911 * only for the current buffer: Try to read in the undofile,
7912 * if one exists, the buffer wasn't changed and the buffer was
7913 * loaded */
7914 if ((curbuf == save_curbuf
7915 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7916 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7917 {
7918 u_compute_hash(hash);
7919 u_read_undo(NULL, hash, curbuf->b_fname);
7920 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007921 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007922 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007923 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007924 }
7925#endif
7926
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 else if ((int *)varp == &curbuf->b_p_ro)
7928 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007929 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007930 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7931 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007932
7933 /* when 'readonly' is set may give W10 again */
7934 if (curbuf->b_p_ro)
7935 curbuf->b_did_warn = FALSE;
7936
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007938 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939#endif
7940 }
7941
Bram Moolenaar9c449722010-07-20 18:44:27 +02007942#ifdef FEAT_GUI
7943 else if ((int *)varp == &p_mh)
7944 {
7945 if (!p_mh)
7946 gui_mch_mousehide(FALSE);
7947 }
7948#endif
7949
Bram Moolenaara539df02010-08-01 14:35:05 +02007950#ifdef FEAT_TITLE
7951 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007953 {
7954 redraw_titles();
7955 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 /* when 'endofline' is changed, redraw the window title */
7957 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007958 {
7959 redraw_titles();
7960 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007961 /* when 'fixeol' is changed, redraw the window title */
7962 else if ((int *)varp == &curbuf->b_p_fixeol)
7963 {
7964 redraw_titles();
7965 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007966# ifdef FEAT_MBYTE
7967 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007968 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007969 {
7970 redraw_titles();
7971 }
7972# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973#endif
7974
7975 /* when 'bin' is set also set some other options */
7976 else if ((int *)varp == &curbuf->b_p_bin)
7977 {
7978 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7979#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007980 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981#endif
7982 }
7983
7984#ifdef FEAT_AUTOCMD
7985 /* when 'buflisted' changes, trigger autocommands */
7986 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7987 {
7988 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7989 NULL, NULL, TRUE, curbuf);
7990 }
7991#endif
7992
7993 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7994 else if ((int *)varp == &curbuf->b_p_swf)
7995 {
7996 if (curbuf->b_p_swf && p_uc)
7997 ml_open_file(curbuf); /* create the swap file */
7998 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007999 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8000 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001 mf_close_file(curbuf, TRUE); /* remove the swap file */
8002 }
8003
8004 /* when 'terse' is set change 'shortmess' */
8005 else if ((int *)varp == &p_terse)
8006 {
8007 char_u *p;
8008
8009 p = vim_strchr(p_shm, SHM_SEARCH);
8010
8011 /* insert 's' in p_shm */
8012 if (p_terse && p == NULL)
8013 {
8014 STRCPY(IObuff, p_shm);
8015 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008016 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 }
8018 /* remove 's' from p_shm */
8019 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008020 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 }
8022
8023 /* when 'paste' is set or reset also change other options */
8024 else if ((int *)varp == &p_paste)
8025 {
8026 paste_option_changed();
8027 }
8028
8029 /* when 'insertmode' is set from an autocommand need to do work here */
8030 else if ((int *)varp == &p_im)
8031 {
8032 if (p_im)
8033 {
8034 if ((State & INSERT) == 0)
8035 need_start_insertmode = TRUE;
8036 stop_insert_mode = FALSE;
8037 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008038 /* only reset if it was set previously */
8039 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008040 {
8041 need_start_insertmode = FALSE;
8042 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008043 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008044 clear_cmdline = TRUE; /* remove "(insert)" */
8045 restart_edit = 0;
8046 }
8047 }
8048
8049 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8050 else if ((int *)varp == &p_ic && p_hls)
8051 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008052 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008053 }
8054
8055#ifdef FEAT_SEARCH_EXTRA
8056 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8057 else if ((int *)varp == &p_hls)
8058 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008059 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008060 }
8061#endif
8062
8063#ifdef FEAT_SCROLLBIND
8064 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8065 * at the end of normal_cmd() */
8066 else if ((int *)varp == &curwin->w_p_scb)
8067 {
8068 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008069 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008071 curwin->w_scbind_pos = curwin->w_topline;
8072 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008073 }
8074#endif
8075
8076#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8077 /* There can be only one window with 'previewwindow' set. */
8078 else if ((int *)varp == &curwin->w_p_pvw)
8079 {
8080 if (curwin->w_p_pvw)
8081 {
8082 win_T *win;
8083
Bram Moolenaar29323592016-07-24 22:04:11 +02008084 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 if (win->w_p_pvw && win != curwin)
8086 {
8087 curwin->w_p_pvw = FALSE;
8088 return (char_u *)N_("E590: A preview window already exists");
8089 }
8090 }
8091 }
8092#endif
8093
8094 /* when 'textmode' is set or reset also change 'fileformat' */
8095 else if ((int *)varp == &curbuf->b_p_tx)
8096 {
8097 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8098 }
8099
8100 /* when 'textauto' is set or reset also change 'fileformats' */
8101 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008102 set_string_option_direct((char_u *)"ffs", -1,
8103 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008104 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008105
8106 /*
8107 * When 'lisp' option changes include/exclude '-' in
8108 * keyword characters.
8109 */
8110#ifdef FEAT_LISP
8111 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8112 {
8113 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8114 }
8115#endif
8116
8117#ifdef FEAT_TITLE
8118 /* when 'title' changed, may need to change the title; same for 'icon' */
8119 else if ((int *)varp == &p_title)
8120 {
8121 did_set_title(FALSE);
8122 }
8123
8124 else if ((int *)varp == &p_icon)
8125 {
8126 did_set_title(TRUE);
8127 }
8128#endif
8129
8130 else if ((int *)varp == &curbuf->b_changed)
8131 {
8132 if (!value)
8133 save_file_ff(curbuf); /* Buffer is unchanged */
8134#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008135 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136#endif
8137#ifdef FEAT_AUTOCMD
8138 modified_was_set = value;
8139#endif
8140 }
8141
8142#ifdef BACKSLASH_IN_FILENAME
8143 else if ((int *)varp == &p_ssl)
8144 {
8145 if (p_ssl)
8146 {
8147 psepc = '/';
8148 psepcN = '\\';
8149 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 }
8151 else
8152 {
8153 psepc = '\\';
8154 psepcN = '/';
8155 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156 }
8157
8158 /* need to adjust the file name arguments and buffer names. */
8159 buflist_slash_adjust();
8160 alist_slash_adjust();
8161# ifdef FEAT_EVAL
8162 scriptnames_slash_adjust();
8163# endif
8164 }
8165#endif
8166
8167 /* If 'wrap' is set, set w_leftcol to zero. */
8168 else if ((int *)varp == &curwin->w_p_wrap)
8169 {
8170 if (curwin->w_p_wrap)
8171 curwin->w_leftcol = 0;
8172 }
8173
8174#ifdef FEAT_WINDOWS
8175 else if ((int *)varp == &p_ea)
8176 {
8177 if (p_ea && !old_value)
8178 win_equal(curwin, FALSE, 0);
8179 }
8180#endif
8181
8182 else if ((int *)varp == &p_wiv)
8183 {
8184 /*
8185 * When 'weirdinvert' changed, set/reset 't_xs'.
8186 * Then set 'weirdinvert' according to value of 't_xs'.
8187 */
8188 if (p_wiv && !old_value)
8189 T_XS = (char_u *)"y";
8190 else if (!p_wiv && old_value)
8191 T_XS = empty_option;
8192 p_wiv = (*T_XS != NUL);
8193 }
8194
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008195#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196 else if ((int *)varp == &p_beval)
8197 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008198 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008200 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008201 gui_mch_disable_beval_area(balloonEval);
8202 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008203#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008204
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008205#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206 else if ((int *)varp == &p_acd)
8207 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008208 /* Change directories when the 'acd' option is set now. */
8209 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008210 }
8211#endif
8212
8213#ifdef FEAT_DIFF
8214 /* 'diff' */
8215 else if ((int *)varp == &curwin->w_p_diff)
8216 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008217 /* May add or remove the buffer from the list of diff buffers. */
8218 diff_buf_adjust(curwin);
8219# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220 if (foldmethodIsDiff(curwin))
8221 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008222# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008223 }
8224#endif
8225
8226#ifdef USE_IM_CONTROL
8227 /* 'imdisable' */
8228 else if ((int *)varp == &p_imdisable)
8229 {
8230 /* Only de-activate it here, it will be enabled when changing mode. */
8231 if (p_imdisable)
8232 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008233 else if (State & INSERT)
8234 /* When the option is set from an autocommand, it may need to take
8235 * effect right away. */
8236 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237 }
8238#endif
8239
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008240#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008241 /* 'spell' */
8242 else if ((int *)varp == &curwin->w_p_spell)
8243 {
8244 if (curwin->w_p_spell)
8245 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008246 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008247 if (errmsg != NULL)
8248 EMSG(_(errmsg));
8249 }
8250 }
8251#endif
8252
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253#ifdef FEAT_FKMAP
8254 else if ((int *)varp == &p_altkeymap)
8255 {
8256 if (old_value != p_altkeymap)
8257 {
8258 if (!p_altkeymap)
8259 {
8260 p_hkmap = p_fkmap;
8261 p_fkmap = 0;
8262 }
8263 else
8264 {
8265 p_fkmap = p_hkmap;
8266 p_hkmap = 0;
8267 }
8268 (void)init_chartab();
8269 }
8270 }
8271
8272 /*
8273 * In case some second language keymapping options have changed, check
8274 * and correct the setting in a consistent way.
8275 */
8276
8277 /*
8278 * If hkmap or fkmap are set, reset Arabic keymapping.
8279 */
8280 if ((p_hkmap || p_fkmap) && p_altkeymap)
8281 {
8282 p_altkeymap = p_fkmap;
8283# ifdef FEAT_ARABIC
8284 curwin->w_p_arab = FALSE;
8285# endif
8286 (void)init_chartab();
8287 }
8288
8289 /*
8290 * If hkmap set, reset Farsi keymapping.
8291 */
8292 if (p_hkmap && p_altkeymap)
8293 {
8294 p_altkeymap = 0;
8295 p_fkmap = 0;
8296# ifdef FEAT_ARABIC
8297 curwin->w_p_arab = FALSE;
8298# endif
8299 (void)init_chartab();
8300 }
8301
8302 /*
8303 * If fkmap set, reset Hebrew keymapping.
8304 */
8305 if (p_fkmap && !p_altkeymap)
8306 {
8307 p_altkeymap = 1;
8308 p_hkmap = 0;
8309# ifdef FEAT_ARABIC
8310 curwin->w_p_arab = FALSE;
8311# endif
8312 (void)init_chartab();
8313 }
8314#endif
8315
8316#ifdef FEAT_ARABIC
8317 if ((int *)varp == &curwin->w_p_arab)
8318 {
8319 if (curwin->w_p_arab)
8320 {
8321 /*
8322 * 'arabic' is set, handle various sub-settings.
8323 */
8324 if (!p_tbidi)
8325 {
8326 /* set rightleft mode */
8327 if (!curwin->w_p_rl)
8328 {
8329 curwin->w_p_rl = TRUE;
8330 changed_window_setting();
8331 }
8332
8333 /* Enable Arabic shaping (major part of what Arabic requires) */
8334 if (!p_arshape)
8335 {
8336 p_arshape = TRUE;
8337 redraw_later_clear();
8338 }
8339 }
8340
8341 /* Arabic requires a utf-8 encoding, inform the user if its not
8342 * set. */
8343 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008344 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008345 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8346
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008347 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008348 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8349#ifdef FEAT_EVAL
8350 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8351#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008352 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353
8354# ifdef FEAT_MBYTE
8355 /* set 'delcombine' */
8356 p_deco = TRUE;
8357# endif
8358
8359# ifdef FEAT_KEYMAP
8360 /* Force-set the necessary keymap for arabic */
8361 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8362 OPT_LOCAL);
8363# endif
8364# ifdef FEAT_FKMAP
8365 p_altkeymap = 0;
8366 p_hkmap = 0;
8367 p_fkmap = 0;
8368 (void)init_chartab();
8369# endif
8370 }
8371 else
8372 {
8373 /*
8374 * 'arabic' is reset, handle various sub-settings.
8375 */
8376 if (!p_tbidi)
8377 {
8378 /* reset rightleft mode */
8379 if (curwin->w_p_rl)
8380 {
8381 curwin->w_p_rl = FALSE;
8382 changed_window_setting();
8383 }
8384
8385 /* 'arabicshape' isn't reset, it is a global option and
8386 * another window may still need it "on". */
8387 }
8388
8389 /* 'delcombine' isn't reset, it is a global option and another
8390 * window may still want it "on". */
8391
8392# ifdef FEAT_KEYMAP
8393 /* Revert to the default keymap */
8394 curbuf->b_p_iminsert = B_IMODE_NONE;
8395 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8396# endif
8397 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008398 }
8399
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008400#endif
8401
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008402#ifdef FEAT_TERMGUICOLORS
8403 /* 'termguicolors' */
8404 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008405 {
8406# ifdef FEAT_GUI
8407 if (!gui.in_use && !gui.starting)
8408# endif
8409 highlight_gui_started();
8410 }
8411#endif
8412
Bram Moolenaar071d4272004-06-13 20:20:40 +00008413 /*
8414 * End of handling side effects for bool options.
8415 */
8416
Bram Moolenaar53744302015-07-17 17:38:22 +02008417 /* after handling side effects, call autocommand */
8418
Bram Moolenaar071d4272004-06-13 20:20:40 +00008419 options[opt_idx].flags |= P_WAS_SET;
8420
Bram Moolenaar53744302015-07-17 17:38:22 +02008421#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8422 if (!starting)
8423 {
8424 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008425 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8426 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8427 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008428 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8429 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8430 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8431 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8432 reset_v_option_vars();
8433 }
8434#endif
8435
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008437 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008438 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008439 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 check_redraw(options[opt_idx].flags);
8441
8442 return NULL;
8443}
8444
8445/*
8446 * Set the value of a number option, and take care of side effects.
8447 * Returns NULL for success, or an error message for an error.
8448 */
8449 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008450set_num_option(
8451 int opt_idx, /* index in options[] table */
8452 char_u *varp, /* pointer to the option variable */
8453 long value, /* new value */
8454 char_u *errbuf, /* buffer for error messages */
8455 size_t errbuflen, /* length of "errbuf" */
8456 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457 OPT_MODELINE */
8458{
8459 char_u *errmsg = NULL;
8460 long old_value = *(long *)varp;
8461 long old_Rows = Rows; /* remember old Rows */
8462 long old_Columns = Columns; /* remember old Columns */
8463 long *pp = (long *)varp;
8464
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008465 /* Disallow changing some options from secure mode. */
8466 if ((secure
8467#ifdef HAVE_SANDBOX
8468 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008469#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008470 ) && (options[opt_idx].flags & P_SECURE))
8471 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008472
8473 *pp = value;
8474#ifdef FEAT_EVAL
8475 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008476 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008478#ifdef FEAT_GUI
8479 need_mouse_correct = TRUE;
8480#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008481
Bram Moolenaar14f24742012-08-08 18:01:05 +02008482 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 {
8484 errmsg = e_positive;
8485 curbuf->b_p_sw = curbuf->b_p_ts;
8486 }
8487
8488 /*
8489 * Number options that need some action when changed
8490 */
8491#ifdef FEAT_WINDOWS
8492 if (pp == &p_wh || pp == &p_hh)
8493 {
8494 if (p_wh < 1)
8495 {
8496 errmsg = e_positive;
8497 p_wh = 1;
8498 }
8499 if (p_wmh > p_wh)
8500 {
8501 errmsg = e_winheight;
8502 p_wh = p_wmh;
8503 }
8504 if (p_hh < 0)
8505 {
8506 errmsg = e_positive;
8507 p_hh = 0;
8508 }
8509
8510 /* Change window height NOW */
8511 if (lastwin != firstwin)
8512 {
8513 if (pp == &p_wh && curwin->w_height < p_wh)
8514 win_setheight((int)p_wh);
8515 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8516 win_setheight((int)p_hh);
8517 }
8518 }
8519
8520 /* 'winminheight' */
8521 else if (pp == &p_wmh)
8522 {
8523 if (p_wmh < 0)
8524 {
8525 errmsg = e_positive;
8526 p_wmh = 0;
8527 }
8528 if (p_wmh > p_wh)
8529 {
8530 errmsg = e_winheight;
8531 p_wmh = p_wh;
8532 }
8533 win_setminheight();
8534 }
8535
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008536# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008537 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538 {
8539 if (p_wiw < 1)
8540 {
8541 errmsg = e_positive;
8542 p_wiw = 1;
8543 }
8544 if (p_wmw > p_wiw)
8545 {
8546 errmsg = e_winwidth;
8547 p_wiw = p_wmw;
8548 }
8549
8550 /* Change window width NOW */
8551 if (lastwin != firstwin && curwin->w_width < p_wiw)
8552 win_setwidth((int)p_wiw);
8553 }
8554
8555 /* 'winminwidth' */
8556 else if (pp == &p_wmw)
8557 {
8558 if (p_wmw < 0)
8559 {
8560 errmsg = e_positive;
8561 p_wmw = 0;
8562 }
8563 if (p_wmw > p_wiw)
8564 {
8565 errmsg = e_winwidth;
8566 p_wmw = p_wiw;
8567 }
8568 win_setminheight();
8569 }
8570# endif
8571
8572#endif
8573
8574#ifdef FEAT_WINDOWS
8575 /* (re)set last window status line */
8576 else if (pp == &p_ls)
8577 {
8578 last_status(FALSE);
8579 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008580
8581 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008582 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008583 {
8584 shell_new_rows(); /* recompute window positions and heights */
8585 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586#endif
8587
8588#ifdef FEAT_GUI
8589 else if (pp == &p_linespace)
8590 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008591 /* Recompute gui.char_height and resize the Vim window to keep the
8592 * same number of lines. */
8593 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008594 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008595 }
8596#endif
8597
8598#ifdef FEAT_FOLDING
8599 /* 'foldlevel' */
8600 else if (pp == &curwin->w_p_fdl)
8601 {
8602 if (curwin->w_p_fdl < 0)
8603 curwin->w_p_fdl = 0;
8604 newFoldLevel();
8605 }
8606
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008607 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008608 else if (pp == &curwin->w_p_fml)
8609 {
8610 foldUpdateAll(curwin);
8611 }
8612
8613 /* 'foldnestmax' */
8614 else if (pp == &curwin->w_p_fdn)
8615 {
8616 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8617 foldUpdateAll(curwin);
8618 }
8619
8620 /* 'foldcolumn' */
8621 else if (pp == &curwin->w_p_fdc)
8622 {
8623 if (curwin->w_p_fdc < 0)
8624 {
8625 errmsg = e_positive;
8626 curwin->w_p_fdc = 0;
8627 }
8628 else if (curwin->w_p_fdc > 12)
8629 {
8630 errmsg = e_invarg;
8631 curwin->w_p_fdc = 12;
8632 }
8633 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008634#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008636#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008637 /* 'shiftwidth' or 'tabstop' */
8638 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8639 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008640# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 if (foldmethodIsIndent(curwin))
8642 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008643# endif
8644# ifdef FEAT_CINDENT
8645 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8646 * parse 'cinoptions'. */
8647 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8648 parse_cino(curbuf);
8649# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008650 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008651#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008653#ifdef FEAT_MBYTE
8654 /* 'maxcombine' */
8655 else if (pp == &p_mco)
8656 {
8657 if (p_mco > MAX_MCO)
8658 p_mco = MAX_MCO;
8659 else if (p_mco < 0)
8660 p_mco = 0;
8661 screenclear(); /* will re-allocate the screen */
8662 }
8663#endif
8664
Bram Moolenaar071d4272004-06-13 20:20:40 +00008665 else if (pp == &curbuf->b_p_iminsert)
8666 {
8667 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8668 {
8669 errmsg = e_invarg;
8670 curbuf->b_p_iminsert = B_IMODE_NONE;
8671 }
8672 p_iminsert = curbuf->b_p_iminsert;
8673 if (termcap_active) /* don't do this in the alternate screen */
8674 showmode();
8675#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8676 /* Show/unshow value of 'keymap' in status lines. */
8677 status_redraw_curbuf();
8678#endif
8679 }
8680
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008681 else if (pp == &p_window)
8682 {
8683 if (p_window < 1)
8684 p_window = 1;
8685 else if (p_window >= Rows)
8686 p_window = Rows - 1;
8687 }
8688
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689 else if (pp == &curbuf->b_p_imsearch)
8690 {
8691 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8692 {
8693 errmsg = e_invarg;
8694 curbuf->b_p_imsearch = B_IMODE_NONE;
8695 }
8696 p_imsearch = curbuf->b_p_imsearch;
8697 }
8698
8699#ifdef FEAT_TITLE
8700 /* if 'titlelen' has changed, redraw the title */
8701 else if (pp == &p_titlelen)
8702 {
8703 if (p_titlelen < 0)
8704 {
8705 errmsg = e_positive;
8706 p_titlelen = 85;
8707 }
8708 if (starting != NO_SCREEN && old_value != p_titlelen)
8709 need_maketitle = TRUE;
8710 }
8711#endif
8712
8713 /* if p_ch changed value, change the command line height */
8714 else if (pp == &p_ch)
8715 {
8716 if (p_ch < 1)
8717 {
8718 errmsg = e_positive;
8719 p_ch = 1;
8720 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008721 if (p_ch > Rows - min_rows() + 1)
8722 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723
8724 /* Only compute the new window layout when startup has been
8725 * completed. Otherwise the frame sizes may be wrong. */
8726 if (p_ch != old_value && full_screen
8727#ifdef FEAT_GUI
8728 && !gui.starting
8729#endif
8730 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008731 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732 }
8733
8734 /* when 'updatecount' changes from zero to non-zero, open swap files */
8735 else if (pp == &p_uc)
8736 {
8737 if (p_uc < 0)
8738 {
8739 errmsg = e_positive;
8740 p_uc = 100;
8741 }
8742 if (p_uc && !old_value)
8743 ml_open_files();
8744 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008745#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008746 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008747 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008748 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008749 {
8750 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008751 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008752 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008753 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008754 {
8755 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008756 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008757 }
8758 }
8759#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008760#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008761 else if (pp == &p_mzq)
8762 mzvim_reset_timer();
8763#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008764
8765 /* sync undo before 'undolevels' changes */
8766 else if (pp == &p_ul)
8767 {
8768 /* use the old value, otherwise u_sync() may not work properly */
8769 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008770 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771 p_ul = value;
8772 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008773 else if (pp == &curbuf->b_p_ul)
8774 {
8775 /* use the old value, otherwise u_sync() may not work properly */
8776 curbuf->b_p_ul = old_value;
8777 u_sync(TRUE);
8778 curbuf->b_p_ul = value;
8779 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008781#ifdef FEAT_LINEBREAK
8782 /* 'numberwidth' must be positive */
8783 else if (pp == &curwin->w_p_nuw)
8784 {
8785 if (curwin->w_p_nuw < 1)
8786 {
8787 errmsg = e_positive;
8788 curwin->w_p_nuw = 1;
8789 }
8790 if (curwin->w_p_nuw > 10)
8791 {
8792 errmsg = e_invarg;
8793 curwin->w_p_nuw = 10;
8794 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008795 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008796 }
8797#endif
8798
Bram Moolenaar1a384422010-07-14 19:53:30 +02008799 else if (pp == &curbuf->b_p_tw)
8800 {
8801 if (curbuf->b_p_tw < 0)
8802 {
8803 errmsg = e_positive;
8804 curbuf->b_p_tw = 0;
8805 }
8806#ifdef FEAT_SYN_HL
8807# ifdef FEAT_WINDOWS
8808 {
8809 win_T *wp;
8810 tabpage_T *tp;
8811
8812 FOR_ALL_TAB_WINDOWS(tp, wp)
8813 check_colorcolumn(wp);
8814 }
8815# else
8816 check_colorcolumn(curwin);
8817# endif
8818#endif
8819 }
8820
Bram Moolenaar071d4272004-06-13 20:20:40 +00008821 /*
8822 * Check the bounds for numeric options here
8823 */
8824 if (Rows < min_rows() && full_screen)
8825 {
8826 if (errbuf != NULL)
8827 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008828 vim_snprintf((char *)errbuf, errbuflen,
8829 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830 errmsg = errbuf;
8831 }
8832 Rows = min_rows();
8833 }
8834 if (Columns < MIN_COLUMNS && full_screen)
8835 {
8836 if (errbuf != NULL)
8837 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008838 vim_snprintf((char *)errbuf, errbuflen,
8839 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 errmsg = errbuf;
8841 }
8842 Columns = MIN_COLUMNS;
8843 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008844 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846 /*
8847 * If the screen (shell) height has been changed, assume it is the
8848 * physical screenheight.
8849 */
8850 if (old_Rows != Rows || old_Columns != Columns)
8851 {
8852 /* Changing the screen size is not allowed while updating the screen. */
8853 if (updating_screen)
8854 *pp = old_value;
8855 else if (full_screen
8856#ifdef FEAT_GUI
8857 && !gui.starting
8858#endif
8859 )
8860 set_shellsize((int)Columns, (int)Rows, TRUE);
8861 else
8862 {
8863 /* Postpone the resizing; check the size and cmdline position for
8864 * messages. */
8865 check_shellsize();
8866 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8867 cmdline_row = Rows - p_ch;
8868 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008869 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008870 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008871 }
8872
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873 if (curbuf->b_p_ts <= 0)
8874 {
8875 errmsg = e_positive;
8876 curbuf->b_p_ts = 8;
8877 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008878 if (p_tm < 0)
8879 {
8880 errmsg = e_positive;
8881 p_tm = 0;
8882 }
8883 if ((curwin->w_p_scr <= 0
8884 || (curwin->w_p_scr > curwin->w_height
8885 && curwin->w_height > 0))
8886 && full_screen)
8887 {
8888 if (pp == &(curwin->w_p_scr))
8889 {
8890 if (curwin->w_p_scr != 0)
8891 errmsg = e_scroll;
8892 win_comp_scroll(curwin);
8893 }
8894 /* If 'scroll' became invalid because of a side effect silently adjust
8895 * it. */
8896 else if (curwin->w_p_scr <= 0)
8897 curwin->w_p_scr = 1;
8898 else /* curwin->w_p_scr > curwin->w_height */
8899 curwin->w_p_scr = curwin->w_height;
8900 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008901 if (p_hi < 0)
8902 {
8903 errmsg = e_positive;
8904 p_hi = 0;
8905 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008906 else if (p_hi > 10000)
8907 {
8908 errmsg = e_invarg;
8909 p_hi = 10000;
8910 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008911 if (p_re < 0 || p_re > 2)
8912 {
8913 errmsg = e_invarg;
8914 p_re = 0;
8915 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008916 if (p_report < 0)
8917 {
8918 errmsg = e_positive;
8919 p_report = 1;
8920 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008921 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 {
8923 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8924 p_sj = Rows / 2;
8925 else
8926 {
8927 errmsg = e_scroll;
8928 p_sj = 1;
8929 }
8930 }
8931 if (p_so < 0 && full_screen)
8932 {
8933 errmsg = e_scroll;
8934 p_so = 0;
8935 }
8936 if (p_siso < 0 && full_screen)
8937 {
8938 errmsg = e_positive;
8939 p_siso = 0;
8940 }
8941#ifdef FEAT_CMDWIN
8942 if (p_cwh < 1)
8943 {
8944 errmsg = e_positive;
8945 p_cwh = 1;
8946 }
8947#endif
8948 if (p_ut < 0)
8949 {
8950 errmsg = e_positive;
8951 p_ut = 2000;
8952 }
8953 if (p_ss < 0)
8954 {
8955 errmsg = e_positive;
8956 p_ss = 0;
8957 }
8958
8959 /* May set global value for local option. */
8960 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8961 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8962
8963 options[opt_idx].flags |= P_WAS_SET;
8964
Bram Moolenaar53744302015-07-17 17:38:22 +02008965#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8966 if (!starting && errmsg == NULL)
8967 {
8968 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008969 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8970 vim_snprintf((char *)buf_new, 10, "%ld", value);
8971 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008972 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8973 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8974 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8975 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8976 reset_v_option_vars();
8977 }
8978#endif
8979
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008981 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008982 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008983 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008984 check_redraw(options[opt_idx].flags);
8985
8986 return errmsg;
8987}
8988
8989/*
8990 * Called after an option changed: check if something needs to be redrawn.
8991 */
8992 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008993check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994{
8995 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008996 int doclear = (flags & P_RCLR) == P_RCLR;
8997 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008998
8999#ifdef FEAT_WINDOWS
9000 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9001 status_redraw_all();
9002#endif
9003
9004 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9005 changed_window_setting();
9006 if (flags & P_RBUF)
9007 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009008 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009009 redraw_all_later(CLEAR);
9010 else if (all)
9011 redraw_all_later(NOT_VALID);
9012}
9013
9014/*
9015 * Find index for option 'arg'.
9016 * Return -1 if not found.
9017 */
9018 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009019findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009020{
9021 int opt_idx;
9022 char *s, *p;
9023 static short quick_tab[27] = {0, 0}; /* quick access table */
9024 int is_term_opt;
9025
9026 /*
9027 * For first call: Initialize the quick-access table.
9028 * It contains the index for the first option that starts with a certain
9029 * letter. There are 26 letters, plus the first "t_" option.
9030 */
9031 if (quick_tab[1] == 0)
9032 {
9033 p = options[0].fullname;
9034 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9035 {
9036 if (s[0] != p[0])
9037 {
9038 if (s[0] == 't' && s[1] == '_')
9039 quick_tab[26] = opt_idx;
9040 else
9041 quick_tab[CharOrdLow(s[0])] = opt_idx;
9042 }
9043 p = s;
9044 }
9045 }
9046
9047 /*
9048 * Check for name starting with an illegal character.
9049 */
9050#ifdef EBCDIC
9051 if (!islower(arg[0]))
9052#else
9053 if (arg[0] < 'a' || arg[0] > 'z')
9054#endif
9055 return -1;
9056
9057 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9058 if (is_term_opt)
9059 opt_idx = quick_tab[26];
9060 else
9061 opt_idx = quick_tab[CharOrdLow(arg[0])];
9062 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9063 {
9064 if (STRCMP(arg, s) == 0) /* match full name */
9065 break;
9066 }
9067 if (s == NULL && !is_term_opt)
9068 {
9069 opt_idx = quick_tab[CharOrdLow(arg[0])];
9070 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9071 {
9072 s = options[opt_idx].shortname;
9073 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9074 break;
9075 s = NULL;
9076 }
9077 }
9078 if (s == NULL)
9079 opt_idx = -1;
9080 return opt_idx;
9081}
9082
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009083#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009084/*
9085 * Get the value for an option.
9086 *
9087 * Returns:
9088 * Number or Toggle option: 1, *numval gets value.
9089 * String option: 0, *stringval gets allocated string.
9090 * Hidden Number or Toggle option: -1.
9091 * hidden String option: -2.
9092 * unknown option: -3.
9093 */
9094 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009095get_option_value(
9096 char_u *name,
9097 long *numval,
9098 char_u **stringval, /* NULL when only checking existence */
9099 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009100{
9101 int opt_idx;
9102 char_u *varp;
9103
9104 opt_idx = findoption(name);
9105 if (opt_idx < 0) /* unknown option */
9106 return -3;
9107
9108 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9109
9110 if (options[opt_idx].flags & P_STRING)
9111 {
9112 if (varp == NULL) /* hidden option */
9113 return -2;
9114 if (stringval != NULL)
9115 {
9116#ifdef FEAT_CRYPT
9117 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009118 if ((char_u **)varp == &curbuf->b_p_key
9119 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009120 *stringval = vim_strsave((char_u *)"*****");
9121 else
9122#endif
9123 *stringval = vim_strsave(*(char_u **)(varp));
9124 }
9125 return 0;
9126 }
9127
9128 if (varp == NULL) /* hidden option */
9129 return -1;
9130 if (options[opt_idx].flags & P_NUM)
9131 *numval = *(long *)varp;
9132 else
9133 {
9134 /* Special case: 'modified' is b_changed, but we also want to consider
9135 * it set when 'ff' or 'fenc' changed. */
9136 if ((int *)varp == &curbuf->b_changed)
9137 *numval = curbufIsChanged();
9138 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009139 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009140 }
9141 return 1;
9142}
9143#endif
9144
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009145#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009146/*
9147 * Returns the option attributes and its value. Unlike the above function it
9148 * will return either global value or local value of the option depending on
9149 * what was requested, but it will never return global value if it was
9150 * requested to return local one and vice versa. Neither it will return
9151 * buffer-local value if it was requested to return window-local one.
9152 *
9153 * Pretends that option is absent if it is not present in the requested scope
9154 * (i.e. has no global, window-local or buffer-local value depending on
9155 * opt_type). Uses
9156 *
9157 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009158 * 0 hidden or unknown option, also option that does not have requested
9159 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009160 * see SOPT_* in vim.h for other flags
9161 *
9162 * Possible opt_type values: see SREQ_* in vim.h
9163 */
9164 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009165get_option_value_strict(
9166 char_u *name,
9167 long *numval,
9168 char_u **stringval, /* NULL when only obtaining attributes */
9169 int opt_type,
9170 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009171{
9172 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009173 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009174 struct vimoption *p;
9175 int r = 0;
9176
9177 opt_idx = findoption(name);
9178 if (opt_idx < 0)
9179 return 0;
9180
9181 p = &(options[opt_idx]);
9182
9183 /* Hidden option */
9184 if (p->var == NULL)
9185 return 0;
9186
9187 if (p->flags & P_BOOL)
9188 r |= SOPT_BOOL;
9189 else if (p->flags & P_NUM)
9190 r |= SOPT_NUM;
9191 else if (p->flags & P_STRING)
9192 r |= SOPT_STRING;
9193
9194 if (p->indir == PV_NONE)
9195 {
9196 if (opt_type == SREQ_GLOBAL)
9197 r |= SOPT_GLOBAL;
9198 else
9199 return 0; /* Did not request global-only option */
9200 }
9201 else
9202 {
9203 if (p->indir & PV_BOTH)
9204 r |= SOPT_GLOBAL;
9205 else if (opt_type == SREQ_GLOBAL)
9206 return 0; /* Requested global option */
9207
9208 if (p->indir & PV_WIN)
9209 {
9210 if (opt_type == SREQ_BUF)
9211 return 0; /* Did not request window-local option */
9212 else
9213 r |= SOPT_WIN;
9214 }
9215 else if (p->indir & PV_BUF)
9216 {
9217 if (opt_type == SREQ_WIN)
9218 return 0; /* Did not request buffer-local option */
9219 else
9220 r |= SOPT_BUF;
9221 }
9222 }
9223
9224 if (stringval == NULL)
9225 return r;
9226
9227 if (opt_type == SREQ_GLOBAL)
9228 varp = p->var;
9229 else
9230 {
9231 if (opt_type == SREQ_BUF)
9232 {
9233 /* Special case: 'modified' is b_changed, but we also want to
9234 * consider it set when 'ff' or 'fenc' changed. */
9235 if (p->indir == PV_MOD)
9236 {
9237 *numval = bufIsChanged((buf_T *) from);
9238 varp = NULL;
9239 }
9240#ifdef FEAT_CRYPT
9241 else if (p->indir == PV_KEY)
9242 {
9243 /* never return the value of the crypt key */
9244 *stringval = NULL;
9245 varp = NULL;
9246 }
9247#endif
9248 else
9249 {
9250 aco_save_T aco;
9251 aucmd_prepbuf(&aco, (buf_T *) from);
9252 varp = get_varp(p);
9253 aucmd_restbuf(&aco);
9254 }
9255 }
9256 else if (opt_type == SREQ_WIN)
9257 {
9258 win_T *save_curwin;
9259 save_curwin = curwin;
9260 curwin = (win_T *) from;
9261 curbuf = curwin->w_buffer;
9262 varp = get_varp(p);
9263 curwin = save_curwin;
9264 curbuf = curwin->w_buffer;
9265 }
9266 if (varp == p->var)
9267 return (r | SOPT_UNSET);
9268 }
9269
9270 if (varp != NULL)
9271 {
9272 if (p->flags & P_STRING)
9273 *stringval = vim_strsave(*(char_u **)(varp));
9274 else if (p->flags & P_NUM)
9275 *numval = *(long *) varp;
9276 else
9277 *numval = *(int *)varp;
9278 }
9279
9280 return r;
9281}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009282
9283/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009284 * Iterate over options. First argument is a pointer to a pointer to a
9285 * structure inside options[] array, second is option type like in the above
9286 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009287 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009288 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009289 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009290 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009291 * first argument to NULL.
9292 *
9293 * Returns full option name for current option on each call.
9294 */
9295 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009296option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009297{
9298 struct vimoption *ret = NULL;
9299 do
9300 {
9301 if (*option == NULL)
9302 *option = (void *) options;
9303 else if (((struct vimoption *) (*option))->fullname == NULL)
9304 {
9305 *option = NULL;
9306 return NULL;
9307 }
9308 else
9309 *option = (void *) (((struct vimoption *) (*option)) + 1);
9310
9311 ret = ((struct vimoption *) (*option));
9312
9313 /* Hidden option */
9314 if (ret->var == NULL)
9315 {
9316 ret = NULL;
9317 continue;
9318 }
9319
9320 switch (opt_type)
9321 {
9322 case SREQ_GLOBAL:
9323 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9324 ret = NULL;
9325 break;
9326 case SREQ_BUF:
9327 if (!(ret->indir & PV_BUF))
9328 ret = NULL;
9329 break;
9330 case SREQ_WIN:
9331 if (!(ret->indir & PV_WIN))
9332 ret = NULL;
9333 break;
9334 default:
9335 EMSG2(_(e_intern2), "option_iter_next()");
9336 return NULL;
9337 }
9338 }
9339 while (ret == NULL);
9340
9341 return (char_u *)ret->fullname;
9342}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009343#endif
9344
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345/*
9346 * Set the value of option "name".
9347 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009348 *
9349 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009351 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009352set_option_value(
9353 char_u *name,
9354 long number,
9355 char_u *string,
9356 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357{
9358 int opt_idx;
9359 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009360 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361
9362 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009363 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 EMSG2(_("E355: Unknown option: %s"), name);
9365 else
9366 {
9367 flags = options[opt_idx].flags;
9368#ifdef HAVE_SANDBOX
9369 /* Disallow changing some options in the sandbox */
9370 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009371 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009372 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009373 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009374 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009375#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009376 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009377 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009378 else
9379 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009380 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009381 if (varp != NULL) /* hidden option is not changed */
9382 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009383 if (number == 0 && string != NULL)
9384 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009385 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009386
9387 /* Either we are given a string or we are setting option
9388 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009389 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009390 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009391 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009392 {
9393 /* There's another character after zeros or the string
9394 * is empty. In both cases, we are trying to set a
9395 * num option using a string. */
9396 EMSG3(_("E521: Number required: &%s = '%s'"),
9397 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009398 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009399
9400 }
9401 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009402 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009403 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009404 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009405 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009406 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009407 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009408 }
9409 }
9410 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009411 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009412}
9413
9414/*
9415 * Get the terminal code for a terminal option.
9416 * Returns NULL when not found.
9417 */
9418 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009419get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420{
9421 int opt_idx;
9422 char_u *varp;
9423
9424 if (tname[0] != 't' || tname[1] != '_' ||
9425 tname[2] == NUL || tname[3] == NUL)
9426 return NULL;
9427 if ((opt_idx = findoption(tname)) >= 0)
9428 {
9429 varp = get_varp(&(options[opt_idx]));
9430 if (varp != NULL)
9431 varp = *(char_u **)(varp);
9432 return varp;
9433 }
9434 return find_termcode(tname + 2);
9435}
9436
9437 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009438get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009439{
9440 int i;
9441
9442 i = findoption((char_u *)"hl");
9443 if (i >= 0)
9444 return options[i].def_val[VI_DEFAULT];
9445 return (char_u *)NULL;
9446}
9447
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009448#if defined(FEAT_MBYTE) || defined(PROTO)
9449 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009450get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009451{
9452 int i;
9453
9454 i = findoption((char_u *)"enc");
9455 if (i >= 0)
9456 return options[i].def_val[VI_DEFAULT];
9457 return (char_u *)NULL;
9458}
9459#endif
9460
Bram Moolenaar071d4272004-06-13 20:20:40 +00009461/*
9462 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9463 */
9464 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009465find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009466{
9467 int key;
9468 int modifiers;
9469
9470 /*
9471 * Don't use get_special_key_code() for t_xx, we don't want it to call
9472 * add_termcap_entry().
9473 */
9474 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9475 key = TERMCAP2KEY(arg[2], arg[3]);
9476 else
9477 {
9478 --arg; /* put arg at the '<' */
9479 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009480 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009481 if (modifiers) /* can't handle modifiers here */
9482 key = 0;
9483 }
9484 return key;
9485}
9486
9487/*
9488 * if 'all' == 0: show changed options
9489 * if 'all' == 1: show all normal options
9490 * if 'all' == 2: show all terminal options
9491 */
9492 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009493showoptions(
9494 int all,
9495 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009496{
9497 struct vimoption *p;
9498 int col;
9499 int isterm;
9500 char_u *varp;
9501 struct vimoption **items;
9502 int item_count;
9503 int run;
9504 int row, rows;
9505 int cols;
9506 int i;
9507 int len;
9508
9509#define INC 20
9510#define GAP 3
9511
9512 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9513 PARAM_COUNT));
9514 if (items == NULL)
9515 return;
9516
9517 /* Highlight title */
9518 if (all == 2)
9519 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9520 else if (opt_flags & OPT_GLOBAL)
9521 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9522 else if (opt_flags & OPT_LOCAL)
9523 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9524 else
9525 MSG_PUTS_TITLE(_("\n--- Options ---"));
9526
9527 /*
9528 * do the loop two times:
9529 * 1. display the short items
9530 * 2. display the long items (only strings and numbers)
9531 */
9532 for (run = 1; run <= 2 && !got_int; ++run)
9533 {
9534 /*
9535 * collect the items in items[]
9536 */
9537 item_count = 0;
9538 for (p = &options[0]; p->fullname != NULL; p++)
9539 {
9540 varp = NULL;
9541 isterm = istermoption(p);
9542 if (opt_flags != 0)
9543 {
9544 if (p->indir != PV_NONE && !isterm)
9545 varp = get_varp_scope(p, opt_flags);
9546 }
9547 else
9548 varp = get_varp(p);
9549 if (varp != NULL
9550 && ((all == 2 && isterm)
9551 || (all == 1 && !isterm)
9552 || (all == 0 && !optval_default(p, varp))))
9553 {
9554 if (p->flags & P_BOOL)
9555 len = 1; /* a toggle option fits always */
9556 else
9557 {
9558 option_value2string(p, opt_flags);
9559 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9560 }
9561 if ((len <= INC - GAP && run == 1) ||
9562 (len > INC - GAP && run == 2))
9563 items[item_count++] = p;
9564 }
9565 }
9566
9567 /*
9568 * display the items
9569 */
9570 if (run == 1)
9571 {
9572 cols = (Columns + GAP - 3) / INC;
9573 if (cols == 0)
9574 cols = 1;
9575 rows = (item_count + cols - 1) / cols;
9576 }
9577 else /* run == 2 */
9578 rows = item_count;
9579 for (row = 0; row < rows && !got_int; ++row)
9580 {
9581 msg_putchar('\n'); /* go to next line */
9582 if (got_int) /* 'q' typed in more */
9583 break;
9584 col = 0;
9585 for (i = row; i < item_count; i += rows)
9586 {
9587 msg_col = col; /* make columns */
9588 showoneopt(items[i], opt_flags);
9589 col += INC;
9590 }
9591 out_flush();
9592 ui_breakcheck();
9593 }
9594 }
9595 vim_free(items);
9596}
9597
9598/*
9599 * Return TRUE if option "p" has its default value.
9600 */
9601 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009602optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009603{
9604 int dvi;
9605
9606 if (varp == NULL)
9607 return TRUE; /* hidden option is always at default */
9608 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9609 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009610 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009612 /* the cast to long is required for Manx C, long_i is
9613 * needed for MSVC */
9614 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009615 /* P_STRING */
9616 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9617}
9618
9619/*
9620 * showoneopt: show the value of one option
9621 * must not be called with a hidden option!
9622 */
9623 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009624showoneopt(
9625 struct vimoption *p,
9626 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009627{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009628 char_u *varp;
9629 int save_silent = silent_mode;
9630
9631 silent_mode = FALSE;
9632 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009633
9634 varp = get_varp_scope(p, opt_flags);
9635
9636 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9637 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9638 ? !curbufIsChanged() : !*(int *)varp))
9639 MSG_PUTS("no");
9640 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9641 MSG_PUTS("--");
9642 else
9643 MSG_PUTS(" ");
9644 MSG_PUTS(p->fullname);
9645 if (!(p->flags & P_BOOL))
9646 {
9647 msg_putchar('=');
9648 /* put value string in NameBuff */
9649 option_value2string(p, opt_flags);
9650 msg_outtrans(NameBuff);
9651 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009652
9653 silent_mode = save_silent;
9654 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009655}
9656
9657/*
9658 * Write modified options as ":set" commands to a file.
9659 *
9660 * There are three values for "opt_flags":
9661 * OPT_GLOBAL: Write global option values and fresh values of
9662 * buffer-local options (used for start of a session
9663 * file).
9664 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9665 * curwin (used for a vimrc file).
9666 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9667 * and local values for window-local options of
9668 * curwin. Local values are also written when at the
9669 * default value, because a modeline or autocommand
9670 * may have set them when doing ":edit file" and the
9671 * user has set them back at the default or fresh
9672 * value.
9673 * When "local_only" is TRUE, don't write fresh
9674 * values, only local values (for ":mkview").
9675 * (fresh value = value used for a new buffer or window for a local option).
9676 *
9677 * Return FAIL on error, OK otherwise.
9678 */
9679 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009680makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681{
9682 struct vimoption *p;
9683 char_u *varp; /* currently used value */
9684 char_u *varp_fresh; /* local value */
9685 char_u *varp_local = NULL; /* fresh value */
9686 char *cmd;
9687 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009688 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009689
9690 /*
9691 * The options that don't have a default (terminal name, columns, lines)
9692 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009693 * Do the loop over "options[]" twice: once for options with the
9694 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009695 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009696 for (pri = 1; pri >= 0; --pri)
9697 {
9698 for (p = &options[0]; !istermoption(p); p++)
9699 if (!(p->flags & P_NO_MKRC)
9700 && !istermoption(p)
9701 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009702 {
9703 /* skip global option when only doing locals */
9704 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9705 continue;
9706
9707 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9708 * file, they are always buffer-specific. */
9709 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9710 continue;
9711
9712 /* Global values are only written when not at the default value. */
9713 varp = get_varp_scope(p, opt_flags);
9714 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9715 continue;
9716
9717 round = 2;
9718 if (p->indir != PV_NONE)
9719 {
9720 if (p->var == VAR_WIN)
9721 {
9722 /* skip window-local option when only doing globals */
9723 if (!(opt_flags & OPT_LOCAL))
9724 continue;
9725 /* When fresh value of window-local option is not at the
9726 * default, need to write it too. */
9727 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9728 {
9729 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9730 if (!optval_default(p, varp_fresh))
9731 {
9732 round = 1;
9733 varp_local = varp;
9734 varp = varp_fresh;
9735 }
9736 }
9737 }
9738 }
9739
9740 /* Round 1: fresh value for window-local options.
9741 * Round 2: other values */
9742 for ( ; round <= 2; varp = varp_local, ++round)
9743 {
9744 if (round == 1 || (opt_flags & OPT_GLOBAL))
9745 cmd = "set";
9746 else
9747 cmd = "setlocal";
9748
9749 if (p->flags & P_BOOL)
9750 {
9751 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9752 return FAIL;
9753 }
9754 else if (p->flags & P_NUM)
9755 {
9756 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9757 return FAIL;
9758 }
9759 else /* P_STRING */
9760 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009761#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9762 int do_endif = FALSE;
9763
Bram Moolenaar071d4272004-06-13 20:20:40 +00009764 /* Don't set 'syntax' and 'filetype' again if the value is
9765 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009766 if (
9767# if defined(FEAT_SYN_HL)
9768 p->indir == PV_SYN
9769# if defined(FEAT_AUTOCMD)
9770 ||
9771# endif
9772# endif
9773# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009774 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009775# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009776 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009777 {
9778 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9779 *(char_u **)(varp)) < 0
9780 || put_eol(fd) < 0)
9781 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009782 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009785 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9786 (p->flags & P_EXPAND) != 0) == FAIL)
9787 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009788#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9789 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790 {
9791 if (put_line(fd, "endif") == FAIL)
9792 return FAIL;
9793 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009794#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795 }
9796 }
9797 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009798 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009799 return OK;
9800}
9801
9802#if defined(FEAT_FOLDING) || defined(PROTO)
9803/*
9804 * Generate set commands for the local fold options only. Used when
9805 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9806 */
9807 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009808makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009809{
9810 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9811# ifdef FEAT_EVAL
9812 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9813 == FAIL
9814# endif
9815 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9816 == FAIL
9817 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9818 == FAIL
9819 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9820 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9821 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9822 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9823 )
9824 return FAIL;
9825
9826 return OK;
9827}
9828#endif
9829
9830 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009831put_setstring(
9832 FILE *fd,
9833 char *cmd,
9834 char *name,
9835 char_u **valuep,
9836 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009837{
9838 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009839 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009840
9841 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9842 return FAIL;
9843 if (*valuep != NULL)
9844 {
9845 /* Output 'pastetoggle' as key names. For other
9846 * options some characters have to be escaped with
9847 * CTRL-V or backslash */
9848 if (valuep == &p_pt)
9849 {
9850 s = *valuep;
9851 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009852 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009853 return FAIL;
9854 }
9855 else if (expand)
9856 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009857 buf = alloc(MAXPATHL);
9858 if (buf == NULL)
9859 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009860 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9861 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009862 {
9863 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009864 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009865 }
9866 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009867 }
9868 else if (put_escstr(fd, *valuep, 2) == FAIL)
9869 return FAIL;
9870 }
9871 if (put_eol(fd) < 0)
9872 return FAIL;
9873 return OK;
9874}
9875
9876 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009877put_setnum(
9878 FILE *fd,
9879 char *cmd,
9880 char *name,
9881 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009882{
9883 long wc;
9884
9885 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9886 return FAIL;
9887 if (wc_use_keyname((char_u *)valuep, &wc))
9888 {
9889 /* print 'wildchar' and 'wildcharm' as a key name */
9890 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9891 return FAIL;
9892 }
9893 else if (fprintf(fd, "%ld", *valuep) < 0)
9894 return FAIL;
9895 if (put_eol(fd) < 0)
9896 return FAIL;
9897 return OK;
9898}
9899
9900 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009901put_setbool(
9902 FILE *fd,
9903 char *cmd,
9904 char *name,
9905 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009906{
Bram Moolenaar893de922007-10-02 18:40:57 +00009907 if (value < 0) /* global/local option using global value */
9908 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9910 || put_eol(fd) < 0)
9911 return FAIL;
9912 return OK;
9913}
9914
9915/*
9916 * Clear all the terminal options.
9917 * If the option has been allocated, free the memory.
9918 * Terminal options are never hidden or indirect.
9919 */
9920 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009921clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009922{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923 /*
9924 * Reset a few things before clearing the old options. This may cause
9925 * outputting a few things that the terminal doesn't understand, but the
9926 * screen will be cleared later, so this is OK.
9927 */
9928#ifdef FEAT_MOUSE_TTY
9929 mch_setmouse(FALSE); /* switch mouse off */
9930#endif
9931#ifdef FEAT_TITLE
9932 mch_restore_title(3); /* restore window titles */
9933#endif
9934#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9935 /* When starting the GUI close the display opened for the clipboard.
9936 * After restoring the title, because that will need the display. */
9937 if (gui.starting)
9938 clear_xterm_clip();
9939#endif
9940#ifdef WIN3264
9941 /*
9942 * Check if this is allowed now.
9943 */
9944 if (can_end_termcap_mode(FALSE) == TRUE)
9945#endif
9946 stoptermcap(); /* stop termcap mode */
9947
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009948 free_termoptions();
9949}
9950
9951 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009952free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009953{
9954 struct vimoption *p;
9955
Bram Moolenaar071d4272004-06-13 20:20:40 +00009956 for (p = &options[0]; p->fullname != NULL; p++)
9957 if (istermoption(p))
9958 {
9959 if (p->flags & P_ALLOCED)
9960 free_string_option(*(char_u **)(p->var));
9961 if (p->flags & P_DEF_ALLOCED)
9962 free_string_option(p->def_val[VI_DEFAULT]);
9963 *(char_u **)(p->var) = empty_option;
9964 p->def_val[VI_DEFAULT] = empty_option;
9965 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9966 }
9967 clear_termcodes();
9968}
9969
9970/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009971 * Free the string for one term option, if it was allocated.
9972 * Set the string to empty_option and clear allocated flag.
9973 * "var" points to the option value.
9974 */
9975 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009976free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009977{
9978 struct vimoption *p;
9979
9980 for (p = &options[0]; p->fullname != NULL; p++)
9981 if (p->var == var)
9982 {
9983 if (p->flags & P_ALLOCED)
9984 free_string_option(*(char_u **)(p->var));
9985 *(char_u **)(p->var) = empty_option;
9986 p->flags &= ~P_ALLOCED;
9987 break;
9988 }
9989}
9990
9991/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992 * Set the terminal option defaults to the current value.
9993 * Used after setting the terminal name.
9994 */
9995 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009996set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009997{
9998 struct vimoption *p;
9999
10000 for (p = &options[0]; p->fullname != NULL; p++)
10001 {
10002 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10003 {
10004 if (p->flags & P_DEF_ALLOCED)
10005 {
10006 free_string_option(p->def_val[VI_DEFAULT]);
10007 p->flags &= ~P_DEF_ALLOCED;
10008 }
10009 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10010 if (p->flags & P_ALLOCED)
10011 {
10012 p->flags |= P_DEF_ALLOCED;
10013 p->flags &= ~P_ALLOCED; /* don't free the value now */
10014 }
10015 }
10016 }
10017}
10018
10019/*
10020 * return TRUE if 'p' starts with 't_'
10021 */
10022 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010023istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010024{
10025 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10026}
10027
10028/*
10029 * Compute columns for ruler and shown command. 'sc_col' is also used to
10030 * decide what the maximum length of a message on the status line can be.
10031 * If there is a status line for the last window, 'sc_col' is independent
10032 * of 'ru_col'.
10033 */
10034
10035#define COL_RULER 17 /* columns needed by standard ruler */
10036
10037 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010038comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010039{
10040#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10041 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10042
10043 sc_col = 0;
10044 ru_col = 0;
10045 if (p_ru)
10046 {
10047#ifdef FEAT_STL_OPT
10048 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10049#else
10050 ru_col = COL_RULER + 1;
10051#endif
10052 /* no last status line, adjust sc_col */
10053 if (!last_has_status)
10054 sc_col = ru_col;
10055 }
10056 if (p_sc)
10057 {
10058 sc_col += SHOWCMD_COLS;
10059 if (!p_ru || last_has_status) /* no need for separating space */
10060 ++sc_col;
10061 }
10062 sc_col = Columns - sc_col;
10063 ru_col = Columns - ru_col;
10064 if (sc_col <= 0) /* screen too narrow, will become a mess */
10065 sc_col = 1;
10066 if (ru_col <= 0)
10067 ru_col = 1;
10068#else
10069 sc_col = Columns;
10070 ru_col = Columns;
10071#endif
10072}
10073
10074/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010075 * Unset local option value, similar to ":set opt<".
10076 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010077 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010078unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010079{
10080 struct vimoption *p;
10081 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010082 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010083
10084 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010085 if (opt_idx < 0)
10086 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010087 p = &(options[opt_idx]);
10088
10089 switch ((int)p->indir)
10090 {
10091 /* global option with local value: use local value if it's been set */
10092 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010093 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010094 break;
10095 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010096 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097 break;
10098 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010099 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010100 break;
10101 case PV_AR:
10102 buf->b_p_ar = -1;
10103 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010104 case PV_BKC:
10105 clear_string_option(&buf->b_p_bkc);
10106 buf->b_bkc_flags = 0;
10107 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010108 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010109 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010110 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010111 case PV_TC:
10112 clear_string_option(&buf->b_p_tc);
10113 buf->b_tc_flags = 0;
10114 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010115#ifdef FEAT_FIND_ID
10116 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010117 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010118 break;
10119 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010120 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010121 break;
10122#endif
10123#ifdef FEAT_INS_EXPAND
10124 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010125 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010126 break;
10127 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010128 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010129 break;
10130#endif
10131#ifdef FEAT_QUICKFIX
10132 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010133 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010134 break;
10135 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010136 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010137 break;
10138 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010139 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010140 break;
10141#endif
10142#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10143 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010144 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010145 break;
10146#endif
10147#if defined(FEAT_CRYPT)
10148 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010149 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010150 break;
10151#endif
10152#ifdef FEAT_STL_OPT
10153 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010154 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010155 break;
10156#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010157 case PV_UL:
10158 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10159 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010160#ifdef FEAT_LISP
10161 case PV_LW:
10162 clear_string_option(&buf->b_p_lw);
10163 break;
10164#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010165 }
10166}
10167
10168/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169 * Get pointer to option variable, depending on local or global scope.
10170 */
10171 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010172get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173{
10174 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10175 {
10176 if (p->var == VAR_WIN)
10177 return (char_u *)GLOBAL_WO(get_varp(p));
10178 return p->var;
10179 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010180 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010181 {
10182 switch ((int)p->indir)
10183 {
10184#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010185 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10186 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10187 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010189 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10190 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10191 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010192 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010193 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010194 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010196 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10197 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198#endif
10199#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010200 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10201 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010203#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10204 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10205#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010206#if defined(FEAT_CRYPT)
10207 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10208#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010209#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010210 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010211#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010212 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010213#ifdef FEAT_LISP
10214 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10215#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010216 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010217 }
10218 return NULL; /* "cannot happen" */
10219 }
10220 return get_varp(p);
10221}
10222
10223/*
10224 * Get pointer to option variable.
10225 */
10226 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010227get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228{
10229 /* hidden option, always return NULL */
10230 if (p->var == NULL)
10231 return NULL;
10232
10233 switch ((int)p->indir)
10234 {
10235 case PV_NONE: return p->var;
10236
10237 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010238 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010240 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010242 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010243 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010244 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010245 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010246 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010248 case PV_TC: return *curbuf->b_p_tc != NUL
10249 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010250 case PV_BKC: return *curbuf->b_p_bkc != NUL
10251 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010253 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010254 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010255 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10257#endif
10258#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010259 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010261 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10263#endif
10264#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010265 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010267 case PV_GP: return *curbuf->b_p_gp != NUL
10268 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10269 case PV_MP: return *curbuf->b_p_mp != NUL
10270 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010272#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10273 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10274 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10275#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010276#if defined(FEAT_CRYPT)
10277 case PV_CM: return *curbuf->b_p_cm != NUL
10278 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10279#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010280#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010281 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010282 ? (char_u *)&(curwin->w_p_stl) : p->var;
10283#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010284 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10285 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010286#ifdef FEAT_LISP
10287 case PV_LW: return *curbuf->b_p_lw != NUL
10288 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290
10291#ifdef FEAT_ARABIC
10292 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10293#endif
10294 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010295#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010296 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10297#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010298#ifdef FEAT_SYN_HL
10299 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10300 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010301 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010302#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303#ifdef FEAT_DIFF
10304 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10305#endif
10306#ifdef FEAT_FOLDING
10307 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10308 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10309 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10310 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10311 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10312 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10313 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10314# ifdef FEAT_EVAL
10315 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10316 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10317# endif
10318 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10319#endif
10320 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010321 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010322#ifdef FEAT_LINEBREAK
10323 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10324#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010325#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010327 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10328#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10330 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10331#endif
10332#ifdef FEAT_RIGHTLEFT
10333 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10334 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10335#endif
10336 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10337 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10338#ifdef FEAT_LINEBREAK
10339 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010340 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10341 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342#endif
10343#ifdef FEAT_SCROLLBIND
10344 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10345#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010346#ifdef FEAT_CURSORBIND
10347 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10348#endif
10349#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010350 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10351 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353
10354 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10355 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10356#ifdef FEAT_MBYTE
10357 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10358#endif
10359#if defined(FEAT_QUICKFIX)
10360 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10361 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10362#endif
10363 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10364 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10365#ifdef FEAT_CINDENT
10366 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10367 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10368 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10369#endif
10370#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10371 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10372#endif
10373#ifdef FEAT_COMMENTS
10374 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10375#endif
10376#ifdef FEAT_FOLDING
10377 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10378#endif
10379#ifdef FEAT_INS_EXPAND
10380 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10381#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010382#ifdef FEAT_COMPL_FUNC
10383 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010384 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010386 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010387 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10389#ifdef FEAT_MBYTE
10390 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10391#endif
10392 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10393#ifdef FEAT_AUTOCMD
10394 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10395#endif
10396 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010397 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10399 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10400 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10401 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10402#ifdef FEAT_FIND_ID
10403# ifdef FEAT_EVAL
10404 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10405# endif
10406#endif
10407#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10408 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10409 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10410#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010411#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010412 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10413#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010414#ifdef FEAT_CRYPT
10415 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10416#endif
10417#ifdef FEAT_LISP
10418 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10419#endif
10420 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10421 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10422 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10423 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10424 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010425 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010426#ifdef FEAT_TEXTOBJ
10427 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10428#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10430#ifdef FEAT_SMARTINDENT
10431 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010433 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10435#ifdef FEAT_SEARCHPATH
10436 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10437#endif
10438 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10439#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010440 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010441 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10442#endif
10443#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010444 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10445 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10446 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010447#endif
10448 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10449 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10450 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10451 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010452#ifdef FEAT_PERSISTENT_UNDO
10453 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010455 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10456#ifdef FEAT_KEYMAP
10457 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10458#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010459#ifdef FEAT_SIGNS
10460 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10461#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010462 default: EMSG(_("E356: get_varp ERROR"));
10463 }
10464 /* always return a valid pointer to avoid a crash! */
10465 return (char_u *)&(curbuf->b_p_wm);
10466}
10467
10468/*
10469 * Get the value of 'equalprg', either the buffer-local one or the global one.
10470 */
10471 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010472get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010473{
10474 if (*curbuf->b_p_ep == NUL)
10475 return p_ep;
10476 return curbuf->b_p_ep;
10477}
10478
10479#if defined(FEAT_WINDOWS) || defined(PROTO)
10480/*
10481 * Copy options from one window to another.
10482 * Used when splitting a window.
10483 */
10484 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010485win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486{
10487 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10488 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10489# ifdef FEAT_RIGHTLEFT
10490# ifdef FEAT_FKMAP
10491 /* Is this right? */
10492 wp_to->w_farsi = wp_from->w_farsi;
10493# endif
10494# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010495#if defined(FEAT_LINEBREAK)
10496 briopt_check(wp_to);
10497#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010498}
10499#endif
10500
10501/*
10502 * Copy the options from one winopt_T to another.
10503 * Doesn't free the old option values in "to", use clear_winopt() for that.
10504 * The 'scroll' option is not copied, because it depends on the window height.
10505 * The 'previewwindow' option is reset, there can be only one preview window.
10506 */
10507 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010508copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509{
10510#ifdef FEAT_ARABIC
10511 to->wo_arab = from->wo_arab;
10512#endif
10513 to->wo_list = from->wo_list;
10514 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010515 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010516#ifdef FEAT_LINEBREAK
10517 to->wo_nuw = from->wo_nuw;
10518#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519#ifdef FEAT_RIGHTLEFT
10520 to->wo_rl = from->wo_rl;
10521 to->wo_rlc = vim_strsave(from->wo_rlc);
10522#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010523#ifdef FEAT_STL_OPT
10524 to->wo_stl = vim_strsave(from->wo_stl);
10525#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010527#ifdef FEAT_DIFF
10528 to->wo_wrap_save = from->wo_wrap_save;
10529#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530#ifdef FEAT_LINEBREAK
10531 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010532 to->wo_bri = from->wo_bri;
10533 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534#endif
10535#ifdef FEAT_SCROLLBIND
10536 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010537 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010539#ifdef FEAT_CURSORBIND
10540 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010541 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010542#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010543#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010544 to->wo_spell = from->wo_spell;
10545#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010546#ifdef FEAT_SYN_HL
10547 to->wo_cuc = from->wo_cuc;
10548 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010549 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551#ifdef FEAT_DIFF
10552 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010553 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010555#ifdef FEAT_CONCEAL
10556 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010557 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010558#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010559#ifdef FEAT_FOLDING
10560 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010561 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010563 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564 to->wo_fdi = vim_strsave(from->wo_fdi);
10565 to->wo_fml = from->wo_fml;
10566 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010567 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010569 to->wo_fdm_save = from->wo_diff_saved
10570 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571 to->wo_fdn = from->wo_fdn;
10572# ifdef FEAT_EVAL
10573 to->wo_fde = vim_strsave(from->wo_fde);
10574 to->wo_fdt = vim_strsave(from->wo_fdt);
10575# endif
10576 to->wo_fmr = vim_strsave(from->wo_fmr);
10577#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010578#ifdef FEAT_SIGNS
10579 to->wo_scl = vim_strsave(from->wo_scl);
10580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 check_winopt(to); /* don't want NULL pointers */
10582}
10583
10584/*
10585 * Check string options in a window for a NULL value.
10586 */
10587 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010588check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589{
10590 check_winopt(&win->w_onebuf_opt);
10591 check_winopt(&win->w_allbuf_opt);
10592}
10593
10594/*
10595 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10596 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010597 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010598check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599{
10600#ifdef FEAT_FOLDING
10601 check_string_option(&wop->wo_fdi);
10602 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010603 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604# ifdef FEAT_EVAL
10605 check_string_option(&wop->wo_fde);
10606 check_string_option(&wop->wo_fdt);
10607# endif
10608 check_string_option(&wop->wo_fmr);
10609#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010610#ifdef FEAT_SIGNS
10611 check_string_option(&wop->wo_scl);
10612#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613#ifdef FEAT_RIGHTLEFT
10614 check_string_option(&wop->wo_rlc);
10615#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010616#ifdef FEAT_STL_OPT
10617 check_string_option(&wop->wo_stl);
10618#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010619#ifdef FEAT_SYN_HL
10620 check_string_option(&wop->wo_cc);
10621#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010622#ifdef FEAT_CONCEAL
10623 check_string_option(&wop->wo_cocu);
10624#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010625#ifdef FEAT_LINEBREAK
10626 check_string_option(&wop->wo_briopt);
10627#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628}
10629
10630/*
10631 * Free the allocated memory inside a winopt_T.
10632 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010634clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010635{
10636#ifdef FEAT_FOLDING
10637 clear_string_option(&wop->wo_fdi);
10638 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010639 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010640# ifdef FEAT_EVAL
10641 clear_string_option(&wop->wo_fde);
10642 clear_string_option(&wop->wo_fdt);
10643# endif
10644 clear_string_option(&wop->wo_fmr);
10645#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010646#ifdef FEAT_SIGNS
10647 clear_string_option(&wop->wo_scl);
10648#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010649#ifdef FEAT_LINEBREAK
10650 clear_string_option(&wop->wo_briopt);
10651#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010652#ifdef FEAT_RIGHTLEFT
10653 clear_string_option(&wop->wo_rlc);
10654#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010655#ifdef FEAT_STL_OPT
10656 clear_string_option(&wop->wo_stl);
10657#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010658#ifdef FEAT_SYN_HL
10659 clear_string_option(&wop->wo_cc);
10660#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010661#ifdef FEAT_CONCEAL
10662 clear_string_option(&wop->wo_cocu);
10663#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010664}
10665
10666/*
10667 * Copy global option values to local options for one buffer.
10668 * Used when creating a new buffer and sometimes when entering a buffer.
10669 * flags:
10670 * BCO_ENTER We will enter the buf buffer.
10671 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10672 * appropriate.
10673 * BCO_NOHELP Don't copy the values to a help buffer.
10674 */
10675 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010676buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010677{
10678 int should_copy = TRUE;
10679 char_u *save_p_isk = NULL; /* init for GCC */
10680 int dont_do_help;
10681 int did_isk = FALSE;
10682
10683 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010684 * Skip this when the option defaults have not been set yet. Happens when
10685 * main() allocates the first buffer.
10686 */
10687 if (p_cpo != NULL)
10688 {
10689 /*
10690 * Always copy when entering and 'cpo' contains 'S'.
10691 * Don't copy when already initialized.
10692 * Don't copy when 'cpo' contains 's' and not entering.
10693 * 'S' BCO_ENTER initialized 's' should_copy
10694 * yes yes X X TRUE
10695 * yes no yes X FALSE
10696 * no X yes X FALSE
10697 * X no no yes FALSE
10698 * X no no no TRUE
10699 * no yes no X TRUE
10700 */
10701 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10702 && (buf->b_p_initialized
10703 || (!(flags & BCO_ENTER)
10704 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10705 should_copy = FALSE;
10706
10707 if (should_copy || (flags & BCO_ALWAYS))
10708 {
10709 /* Don't copy the options specific to a help buffer when
10710 * BCO_NOHELP is given or the options were initialized already
10711 * (jumping back to a help file with CTRL-T or CTRL-O) */
10712 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10713 || buf->b_p_initialized;
10714 if (dont_do_help) /* don't free b_p_isk */
10715 {
10716 save_p_isk = buf->b_p_isk;
10717 buf->b_p_isk = NULL;
10718 }
10719 /*
10720 * Always free the allocated strings.
10721 * If not already initialized, set 'readonly' and copy 'fileformat'.
10722 */
10723 if (!buf->b_p_initialized)
10724 {
10725 free_buf_options(buf, TRUE);
10726 buf->b_p_ro = FALSE; /* don't copy readonly */
10727 buf->b_p_tx = p_tx;
10728#ifdef FEAT_MBYTE
10729 buf->b_p_fenc = vim_strsave(p_fenc);
10730#endif
10731 buf->b_p_ff = vim_strsave(p_ff);
10732#if defined(FEAT_QUICKFIX)
10733 buf->b_p_bh = empty_option;
10734 buf->b_p_bt = empty_option;
10735#endif
10736 }
10737 else
10738 free_buf_options(buf, FALSE);
10739
10740 buf->b_p_ai = p_ai;
10741 buf->b_p_ai_nopaste = p_ai_nopaste;
10742 buf->b_p_sw = p_sw;
10743 buf->b_p_tw = p_tw;
10744 buf->b_p_tw_nopaste = p_tw_nopaste;
10745 buf->b_p_tw_nobin = p_tw_nobin;
10746 buf->b_p_wm = p_wm;
10747 buf->b_p_wm_nopaste = p_wm_nopaste;
10748 buf->b_p_wm_nobin = p_wm_nobin;
10749 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010750#ifdef FEAT_MBYTE
10751 buf->b_p_bomb = p_bomb;
10752#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010753 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754 buf->b_p_et = p_et;
10755 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010756 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757 buf->b_p_ml = p_ml;
10758 buf->b_p_ml_nobin = p_ml_nobin;
10759 buf->b_p_inf = p_inf;
10760 buf->b_p_swf = p_swf;
10761#ifdef FEAT_INS_EXPAND
10762 buf->b_p_cpt = vim_strsave(p_cpt);
10763#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010764#ifdef FEAT_COMPL_FUNC
10765 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010766 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010767#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768 buf->b_p_sts = p_sts;
10769 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771#ifdef FEAT_COMMENTS
10772 buf->b_p_com = vim_strsave(p_com);
10773#endif
10774#ifdef FEAT_FOLDING
10775 buf->b_p_cms = vim_strsave(p_cms);
10776#endif
10777 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010778 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779 buf->b_p_nf = vim_strsave(p_nf);
10780 buf->b_p_mps = vim_strsave(p_mps);
10781#ifdef FEAT_SMARTINDENT
10782 buf->b_p_si = p_si;
10783#endif
10784 buf->b_p_ci = p_ci;
10785#ifdef FEAT_CINDENT
10786 buf->b_p_cin = p_cin;
10787 buf->b_p_cink = vim_strsave(p_cink);
10788 buf->b_p_cino = vim_strsave(p_cino);
10789#endif
10790#ifdef FEAT_AUTOCMD
10791 /* Don't copy 'filetype', it must be detected */
10792 buf->b_p_ft = empty_option;
10793#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010794 buf->b_p_pi = p_pi;
10795#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10796 buf->b_p_cinw = vim_strsave(p_cinw);
10797#endif
10798#ifdef FEAT_LISP
10799 buf->b_p_lisp = p_lisp;
10800#endif
10801#ifdef FEAT_SYN_HL
10802 /* Don't copy 'syntax', it must be set */
10803 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010804 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010805 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010806#endif
10807#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010808 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010809 (void)compile_cap_prog(&buf->b_s);
10810 buf->b_s.b_p_spf = vim_strsave(p_spf);
10811 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010812#endif
10813#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10814 buf->b_p_inde = vim_strsave(p_inde);
10815 buf->b_p_indk = vim_strsave(p_indk);
10816#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010817#if defined(FEAT_EVAL)
10818 buf->b_p_fex = vim_strsave(p_fex);
10819#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820#ifdef FEAT_CRYPT
10821 buf->b_p_key = vim_strsave(p_key);
10822#endif
10823#ifdef FEAT_SEARCHPATH
10824 buf->b_p_sua = vim_strsave(p_sua);
10825#endif
10826#ifdef FEAT_KEYMAP
10827 buf->b_p_keymap = vim_strsave(p_keymap);
10828 buf->b_kmap_state |= KEYMAP_INIT;
10829#endif
10830 /* This isn't really an option, but copying the langmap and IME
10831 * state from the current buffer is better than resetting it. */
10832 buf->b_p_iminsert = p_iminsert;
10833 buf->b_p_imsearch = p_imsearch;
10834
10835 /* options that are normally global but also have a local value
10836 * are not copied, start using the global value */
10837 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010838 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010839 buf->b_p_bkc = empty_option;
10840 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010841#ifdef FEAT_QUICKFIX
10842 buf->b_p_gp = empty_option;
10843 buf->b_p_mp = empty_option;
10844 buf->b_p_efm = empty_option;
10845#endif
10846 buf->b_p_ep = empty_option;
10847 buf->b_p_kp = empty_option;
10848 buf->b_p_path = empty_option;
10849 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010850 buf->b_p_tc = empty_option;
10851 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852#ifdef FEAT_FIND_ID
10853 buf->b_p_def = empty_option;
10854 buf->b_p_inc = empty_option;
10855# ifdef FEAT_EVAL
10856 buf->b_p_inex = vim_strsave(p_inex);
10857# endif
10858#endif
10859#ifdef FEAT_INS_EXPAND
10860 buf->b_p_dict = empty_option;
10861 buf->b_p_tsr = empty_option;
10862#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010863#ifdef FEAT_TEXTOBJ
10864 buf->b_p_qe = vim_strsave(p_qe);
10865#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010866#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10867 buf->b_p_bexpr = empty_option;
10868#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010869#if defined(FEAT_CRYPT)
10870 buf->b_p_cm = empty_option;
10871#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010872#ifdef FEAT_PERSISTENT_UNDO
10873 buf->b_p_udf = p_udf;
10874#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010875#ifdef FEAT_LISP
10876 buf->b_p_lw = empty_option;
10877#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878
10879 /*
10880 * Don't copy the options set by ex_help(), use the saved values,
10881 * when going from a help buffer to a non-help buffer.
10882 * Don't touch these at all when BCO_NOHELP is used and going from
10883 * or to a help buffer.
10884 */
10885 if (dont_do_help)
10886 buf->b_p_isk = save_p_isk;
10887 else
10888 {
10889 buf->b_p_isk = vim_strsave(p_isk);
10890 did_isk = TRUE;
10891 buf->b_p_ts = p_ts;
10892 buf->b_help = FALSE;
10893#ifdef FEAT_QUICKFIX
10894 if (buf->b_p_bt[0] == 'h')
10895 clear_string_option(&buf->b_p_bt);
10896#endif
10897 buf->b_p_ma = p_ma;
10898 }
10899 }
10900
10901 /*
10902 * When the options should be copied (ignoring BCO_ALWAYS), set the
10903 * flag that indicates that the options have been initialized.
10904 */
10905 if (should_copy)
10906 buf->b_p_initialized = TRUE;
10907 }
10908
10909 check_buf_options(buf); /* make sure we don't have NULLs */
10910 if (did_isk)
10911 (void)buf_init_chartab(buf, FALSE);
10912}
10913
10914/*
10915 * Reset the 'modifiable' option and its default value.
10916 */
10917 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010918reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010919{
10920 int opt_idx;
10921
10922 curbuf->b_p_ma = FALSE;
10923 p_ma = FALSE;
10924 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010925 if (opt_idx >= 0)
10926 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010927}
10928
10929/*
10930 * Set the global value for 'iminsert' to the local value.
10931 */
10932 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010933set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010934{
10935 p_iminsert = curbuf->b_p_iminsert;
10936}
10937
10938/*
10939 * Set the global value for 'imsearch' to the local value.
10940 */
10941 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010942set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943{
10944 p_imsearch = curbuf->b_p_imsearch;
10945}
10946
10947#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10948static int expand_option_idx = -1;
10949static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10950static int expand_option_flags = 0;
10951
10952 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010953set_context_in_set_cmd(
10954 expand_T *xp,
10955 char_u *arg,
10956 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957{
10958 int nextchar;
10959 long_u flags = 0; /* init for GCC */
10960 int opt_idx = 0; /* init for GCC */
10961 char_u *p;
10962 char_u *s;
10963 int is_term_option = FALSE;
10964 int key;
10965
10966 expand_option_flags = opt_flags;
10967
10968 xp->xp_context = EXPAND_SETTINGS;
10969 if (*arg == NUL)
10970 {
10971 xp->xp_pattern = arg;
10972 return;
10973 }
10974 p = arg + STRLEN(arg) - 1;
10975 if (*p == ' ' && *(p - 1) != '\\')
10976 {
10977 xp->xp_pattern = p + 1;
10978 return;
10979 }
10980 while (p > arg)
10981 {
10982 s = p;
10983 /* count number of backslashes before ' ' or ',' */
10984 if (*p == ' ' || *p == ',')
10985 {
10986 while (s > arg && *(s - 1) == '\\')
10987 --s;
10988 }
10989 /* break at a space with an even number of backslashes */
10990 if (*p == ' ' && ((p - s) & 1) == 0)
10991 {
10992 ++p;
10993 break;
10994 }
10995 --p;
10996 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010997 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010998 {
10999 xp->xp_context = EXPAND_BOOL_SETTINGS;
11000 p += 2;
11001 }
11002 if (STRNCMP(p, "inv", 3) == 0)
11003 {
11004 xp->xp_context = EXPAND_BOOL_SETTINGS;
11005 p += 3;
11006 }
11007 xp->xp_pattern = arg = p;
11008 if (*arg == '<')
11009 {
11010 while (*p != '>')
11011 if (*p++ == NUL) /* expand terminal option name */
11012 return;
11013 key = get_special_key_code(arg + 1);
11014 if (key == 0) /* unknown name */
11015 {
11016 xp->xp_context = EXPAND_NOTHING;
11017 return;
11018 }
11019 nextchar = *++p;
11020 is_term_option = TRUE;
11021 expand_option_name[2] = KEY2TERMCAP0(key);
11022 expand_option_name[3] = KEY2TERMCAP1(key);
11023 }
11024 else
11025 {
11026 if (p[0] == 't' && p[1] == '_')
11027 {
11028 p += 2;
11029 if (*p != NUL)
11030 ++p;
11031 if (*p == NUL)
11032 return; /* expand option name */
11033 nextchar = *++p;
11034 is_term_option = TRUE;
11035 expand_option_name[2] = p[-2];
11036 expand_option_name[3] = p[-1];
11037 }
11038 else
11039 {
11040 /* Allow * wildcard */
11041 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11042 p++;
11043 if (*p == NUL)
11044 return;
11045 nextchar = *p;
11046 *p = NUL;
11047 opt_idx = findoption(arg);
11048 *p = nextchar;
11049 if (opt_idx == -1 || options[opt_idx].var == NULL)
11050 {
11051 xp->xp_context = EXPAND_NOTHING;
11052 return;
11053 }
11054 flags = options[opt_idx].flags;
11055 if (flags & P_BOOL)
11056 {
11057 xp->xp_context = EXPAND_NOTHING;
11058 return;
11059 }
11060 }
11061 }
11062 /* handle "-=" and "+=" */
11063 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11064 {
11065 ++p;
11066 nextchar = '=';
11067 }
11068 if ((nextchar != '=' && nextchar != ':')
11069 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11070 {
11071 xp->xp_context = EXPAND_UNSUCCESSFUL;
11072 return;
11073 }
11074 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11075 {
11076 xp->xp_context = EXPAND_OLD_SETTING;
11077 if (is_term_option)
11078 expand_option_idx = -1;
11079 else
11080 expand_option_idx = opt_idx;
11081 xp->xp_pattern = p + 1;
11082 return;
11083 }
11084 xp->xp_context = EXPAND_NOTHING;
11085 if (is_term_option || (flags & P_NUM))
11086 return;
11087
11088 xp->xp_pattern = p + 1;
11089
11090 if (flags & P_EXPAND)
11091 {
11092 p = options[opt_idx].var;
11093 if (p == (char_u *)&p_bdir
11094 || p == (char_u *)&p_dir
11095 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011096 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097 || p == (char_u *)&p_rtp
11098#ifdef FEAT_SEARCHPATH
11099 || p == (char_u *)&p_cdpath
11100#endif
11101#ifdef FEAT_SESSION
11102 || p == (char_u *)&p_vdir
11103#endif
11104 )
11105 {
11106 xp->xp_context = EXPAND_DIRECTORIES;
11107 if (p == (char_u *)&p_path
11108#ifdef FEAT_SEARCHPATH
11109 || p == (char_u *)&p_cdpath
11110#endif
11111 )
11112 xp->xp_backslash = XP_BS_THREE;
11113 else
11114 xp->xp_backslash = XP_BS_ONE;
11115 }
11116 else
11117 {
11118 xp->xp_context = EXPAND_FILES;
11119 /* for 'tags' need three backslashes for a space */
11120 if (p == (char_u *)&p_tags)
11121 xp->xp_backslash = XP_BS_THREE;
11122 else
11123 xp->xp_backslash = XP_BS_ONE;
11124 }
11125 }
11126
11127 /* For an option that is a list of file names, find the start of the
11128 * last file name. */
11129 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11130 {
11131 /* count number of backslashes before ' ' or ',' */
11132 if (*p == ' ' || *p == ',')
11133 {
11134 s = p;
11135 while (s > xp->xp_pattern && *(s - 1) == '\\')
11136 --s;
11137 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11138 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11139 {
11140 xp->xp_pattern = p + 1;
11141 break;
11142 }
11143 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011144
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011145#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011146 /* for 'spellsuggest' start at "file:" */
11147 if (options[opt_idx].var == (char_u *)&p_sps
11148 && STRNCMP(p, "file:", 5) == 0)
11149 {
11150 xp->xp_pattern = p + 5;
11151 break;
11152 }
11153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154 }
11155
11156 return;
11157}
11158
11159 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011160ExpandSettings(
11161 expand_T *xp,
11162 regmatch_T *regmatch,
11163 int *num_file,
11164 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011165{
11166 int num_normal = 0; /* Nr of matching non-term-code settings */
11167 int num_term = 0; /* Nr of matching terminal code settings */
11168 int opt_idx;
11169 int match;
11170 int count = 0;
11171 char_u *str;
11172 int loop;
11173 int is_term_opt;
11174 char_u name_buf[MAX_KEY_NAME_LEN];
11175 static char *(names[]) = {"all", "termcap"};
11176 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11177
11178 /* do this loop twice:
11179 * loop == 0: count the number of matching options
11180 * loop == 1: copy the matching options into allocated memory
11181 */
11182 for (loop = 0; loop <= 1; ++loop)
11183 {
11184 regmatch->rm_ic = ic;
11185 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11186 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011187 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11188 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011189 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11190 {
11191 if (loop == 0)
11192 num_normal++;
11193 else
11194 (*file)[count++] = vim_strsave((char_u *)names[match]);
11195 }
11196 }
11197 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11198 opt_idx++)
11199 {
11200 if (options[opt_idx].var == NULL)
11201 continue;
11202 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11203 && !(options[opt_idx].flags & P_BOOL))
11204 continue;
11205 is_term_opt = istermoption(&options[opt_idx]);
11206 if (is_term_opt && num_normal > 0)
11207 continue;
11208 match = FALSE;
11209 if (vim_regexec(regmatch, str, (colnr_T)0)
11210 || (options[opt_idx].shortname != NULL
11211 && vim_regexec(regmatch,
11212 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11213 match = TRUE;
11214 else if (is_term_opt)
11215 {
11216 name_buf[0] = '<';
11217 name_buf[1] = 't';
11218 name_buf[2] = '_';
11219 name_buf[3] = str[2];
11220 name_buf[4] = str[3];
11221 name_buf[5] = '>';
11222 name_buf[6] = NUL;
11223 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11224 {
11225 match = TRUE;
11226 str = name_buf;
11227 }
11228 }
11229 if (match)
11230 {
11231 if (loop == 0)
11232 {
11233 if (is_term_opt)
11234 num_term++;
11235 else
11236 num_normal++;
11237 }
11238 else
11239 (*file)[count++] = vim_strsave(str);
11240 }
11241 }
11242 /*
11243 * Check terminal key codes, these are not in the option table
11244 */
11245 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11246 {
11247 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11248 {
11249 if (!isprint(str[0]) || !isprint(str[1]))
11250 continue;
11251
11252 name_buf[0] = 't';
11253 name_buf[1] = '_';
11254 name_buf[2] = str[0];
11255 name_buf[3] = str[1];
11256 name_buf[4] = NUL;
11257
11258 match = FALSE;
11259 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11260 match = TRUE;
11261 else
11262 {
11263 name_buf[0] = '<';
11264 name_buf[1] = 't';
11265 name_buf[2] = '_';
11266 name_buf[3] = str[0];
11267 name_buf[4] = str[1];
11268 name_buf[5] = '>';
11269 name_buf[6] = NUL;
11270
11271 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11272 match = TRUE;
11273 }
11274 if (match)
11275 {
11276 if (loop == 0)
11277 num_term++;
11278 else
11279 (*file)[count++] = vim_strsave(name_buf);
11280 }
11281 }
11282
11283 /*
11284 * Check special key names.
11285 */
11286 regmatch->rm_ic = TRUE; /* ignore case here */
11287 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11288 {
11289 name_buf[0] = '<';
11290 STRCPY(name_buf + 1, str);
11291 STRCAT(name_buf, ">");
11292
11293 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11294 {
11295 if (loop == 0)
11296 num_term++;
11297 else
11298 (*file)[count++] = vim_strsave(name_buf);
11299 }
11300 }
11301 }
11302 if (loop == 0)
11303 {
11304 if (num_normal > 0)
11305 *num_file = num_normal;
11306 else if (num_term > 0)
11307 *num_file = num_term;
11308 else
11309 return OK;
11310 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11311 if (*file == NULL)
11312 {
11313 *file = (char_u **)"";
11314 return FAIL;
11315 }
11316 }
11317 }
11318 return OK;
11319}
11320
11321 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011322ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323{
11324 char_u *var = NULL; /* init for GCC */
11325 char_u *buf;
11326
11327 *num_file = 0;
11328 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11329 if (*file == NULL)
11330 return FAIL;
11331
11332 /*
11333 * For a terminal key code expand_option_idx is < 0.
11334 */
11335 if (expand_option_idx < 0)
11336 {
11337 var = find_termcode(expand_option_name + 2);
11338 if (var == NULL)
11339 expand_option_idx = findoption(expand_option_name);
11340 }
11341
11342 if (expand_option_idx >= 0)
11343 {
11344 /* put string of option value in NameBuff */
11345 option_value2string(&options[expand_option_idx], expand_option_flags);
11346 var = NameBuff;
11347 }
11348 else if (var == NULL)
11349 var = (char_u *)"";
11350
11351 /* A backslash is required before some characters. This is the reverse of
11352 * what happens in do_set(). */
11353 buf = vim_strsave_escaped(var, escape_chars);
11354
11355 if (buf == NULL)
11356 {
11357 vim_free(*file);
11358 *file = NULL;
11359 return FAIL;
11360 }
11361
11362#ifdef BACKSLASH_IN_FILENAME
11363 /* For MS-Windows et al. we don't double backslashes at the start and
11364 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011365 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366 if (var[0] == '\\' && var[1] == '\\'
11367 && expand_option_idx >= 0
11368 && (options[expand_option_idx].flags & P_EXPAND)
11369 && vim_isfilec(var[2])
11370 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011371 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372#endif
11373
11374 *file[0] = buf;
11375 *num_file = 1;
11376 return OK;
11377}
11378#endif
11379
11380/*
11381 * Get the value for the numeric or string option *opp in a nice format into
11382 * NameBuff[]. Must not be called with a hidden option!
11383 */
11384 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011385option_value2string(
11386 struct vimoption *opp,
11387 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388{
11389 char_u *varp;
11390
11391 varp = get_varp_scope(opp, opt_flags);
11392
11393 if (opp->flags & P_NUM)
11394 {
11395 long wc = 0;
11396
11397 if (wc_use_keyname(varp, &wc))
11398 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11399 else if (wc != 0)
11400 STRCPY(NameBuff, transchar((int)wc));
11401 else
11402 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11403 }
11404 else /* P_STRING */
11405 {
11406 varp = *(char_u **)(varp);
11407 if (varp == NULL) /* just in case */
11408 NameBuff[0] = NUL;
11409#ifdef FEAT_CRYPT
11410 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011411 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011412 STRCPY(NameBuff, "*****");
11413#endif
11414 else if (opp->flags & P_EXPAND)
11415 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11416 /* Translate 'pastetoggle' into special key names */
11417 else if ((char_u **)opp->var == &p_pt)
11418 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11419 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011420 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011421 }
11422}
11423
11424/*
11425 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11426 * printed as a keyname.
11427 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11428 */
11429 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011430wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431{
11432 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11433 {
11434 *wcp = *(long *)varp;
11435 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11436 return TRUE;
11437 }
11438 return FALSE;
11439}
11440
Bram Moolenaar01615492015-02-03 13:00:38 +010011441#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011442/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011443 * Any character has an equivalent 'langmap' character. This is used for
11444 * keyboards that have a special language mode that sends characters above
11445 * 128 (although other characters can be translated too). The "to" field is a
11446 * Vim command character. This avoids having to switch the keyboard back to
11447 * ASCII mode when leaving Insert mode.
11448 *
11449 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11450 * commands.
11451 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11452 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11453 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011454 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011455# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011456/*
11457 * With multi-byte support use growarray for 'langmap' chars >= 256
11458 */
11459typedef struct
11460{
11461 int from;
11462 int to;
11463} langmap_entry_T;
11464
11465static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011466static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011467
11468/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011469 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11470 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011471 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011472 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011473langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011474{
11475 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011476 int a = 0;
11477 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011478
11479 /* Do a binary search for an existing entry. */
11480 while (a != b)
11481 {
11482 int i = (a + b) / 2;
11483 int d = entries[i].from - from;
11484
11485 if (d == 0)
11486 {
11487 entries[i].to = to;
11488 return;
11489 }
11490 if (d < 0)
11491 a = i + 1;
11492 else
11493 b = i;
11494 }
11495
11496 if (ga_grow(&langmap_mapga, 1) != OK)
11497 return; /* out of memory */
11498
11499 /* insert new entry at position "a" */
11500 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11501 mch_memmove(entries + 1, entries,
11502 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11503 ++langmap_mapga.ga_len;
11504 entries[0].from = from;
11505 entries[0].to = to;
11506}
11507
11508/*
11509 * Apply 'langmap' to multi-byte character "c" and return the result.
11510 */
11511 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011512langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011513{
11514 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11515 int a = 0;
11516 int b = langmap_mapga.ga_len;
11517
11518 while (a != b)
11519 {
11520 int i = (a + b) / 2;
11521 int d = entries[i].from - c;
11522
11523 if (d == 0)
11524 return entries[i].to; /* found matching entry */
11525 if (d < 0)
11526 a = i + 1;
11527 else
11528 b = i;
11529 }
11530 return c; /* no entry found, return "c" unmodified */
11531}
11532# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533
11534 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011535langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011536{
11537 int i;
11538
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011539 for (i = 0; i < 256; i++)
11540 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11541# ifdef FEAT_MBYTE
11542 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11543# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011544}
11545
11546/*
11547 * Called when langmap option is set; the language map can be
11548 * changed at any time!
11549 */
11550 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011551langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011552{
11553 char_u *p;
11554 char_u *p2;
11555 int from, to;
11556
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011557#ifdef FEAT_MBYTE
11558 ga_clear(&langmap_mapga); /* clear the previous map first */
11559#endif
11560 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561
11562 for (p = p_langmap; p[0] != NUL; )
11563 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011564 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11565 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566 {
11567 if (p2[0] == '\\' && p2[1] != NUL)
11568 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011569 }
11570 if (p2[0] == ';')
11571 ++p2; /* abcd;ABCD form, p2 points to A */
11572 else
11573 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11574 while (p[0])
11575 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011576 if (p[0] == ',')
11577 {
11578 ++p;
11579 break;
11580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011581 if (p[0] == '\\' && p[1] != NUL)
11582 ++p;
11583#ifdef FEAT_MBYTE
11584 from = (*mb_ptr2char)(p);
11585#else
11586 from = p[0];
11587#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011588 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011589 if (p2 == NULL)
11590 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011591 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011592 if (p[0] != ',')
11593 {
11594 if (p[0] == '\\')
11595 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011596#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011597 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011598#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011599 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011600#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011601 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011602 }
11603 else
11604 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011605 if (p2[0] != ',')
11606 {
11607 if (p2[0] == '\\')
11608 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011609#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011610 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011611#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011612 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011613#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011614 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011615 }
11616 if (to == NUL)
11617 {
11618 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11619 transchar(from));
11620 return;
11621 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011622
11623#ifdef FEAT_MBYTE
11624 if (from >= 256)
11625 langmap_set_entry(from, to);
11626 else
11627#endif
11628 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011629
11630 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011631 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011632 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011634 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011635 if (*p == ';')
11636 {
11637 p = p2;
11638 if (p[0] != NUL)
11639 {
11640 if (p[0] != ',')
11641 {
11642 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11643 return;
11644 }
11645 ++p;
11646 }
11647 break;
11648 }
11649 }
11650 }
11651 }
11652}
11653#endif
11654
11655/*
11656 * Return TRUE if format option 'x' is in effect.
11657 * Take care of no formatting when 'paste' is set.
11658 */
11659 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011660has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011661{
11662 if (p_paste)
11663 return FALSE;
11664 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11665}
11666
11667/*
11668 * Return TRUE if "x" is present in 'shortmess' option, or
11669 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11670 */
11671 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011672shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011674 return p_shm != NULL &&
11675 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011676 || (vim_strchr(p_shm, 'a') != NULL
11677 && vim_strchr((char_u *)SHM_A, x) != NULL));
11678}
11679
11680/*
11681 * paste_option_changed() - Called after p_paste was set or reset.
11682 */
11683 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011684paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011685{
11686 static int old_p_paste = FALSE;
11687 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011688 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689#ifdef FEAT_CMDL_INFO
11690 static int save_ru = 0;
11691#endif
11692#ifdef FEAT_RIGHTLEFT
11693 static int save_ri = 0;
11694 static int save_hkmap = 0;
11695#endif
11696 buf_T *buf;
11697
11698 if (p_paste)
11699 {
11700 /*
11701 * Paste switched from off to on.
11702 * Save the current values, so they can be restored later.
11703 */
11704 if (!old_p_paste)
11705 {
11706 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011707 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011708 {
11709 buf->b_p_tw_nopaste = buf->b_p_tw;
11710 buf->b_p_wm_nopaste = buf->b_p_wm;
11711 buf->b_p_sts_nopaste = buf->b_p_sts;
11712 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011713 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714 }
11715
11716 /* save global options */
11717 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011718 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011719#ifdef FEAT_CMDL_INFO
11720 save_ru = p_ru;
11721#endif
11722#ifdef FEAT_RIGHTLEFT
11723 save_ri = p_ri;
11724 save_hkmap = p_hkmap;
11725#endif
11726 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011727 p_ai_nopaste = p_ai;
11728 p_et_nopaste = p_et;
11729 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011730 p_tw_nopaste = p_tw;
11731 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011732 }
11733
11734 /*
11735 * Always set the option values, also when 'paste' is set when it is
11736 * already on.
11737 */
11738 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011739 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011740 {
11741 buf->b_p_tw = 0; /* textwidth is 0 */
11742 buf->b_p_wm = 0; /* wrapmargin is 0 */
11743 buf->b_p_sts = 0; /* softtabstop is 0 */
11744 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011745 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746 }
11747
11748 /* set global options */
11749 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011750 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011751#ifdef FEAT_CMDL_INFO
11752# ifdef FEAT_WINDOWS
11753 if (p_ru)
11754 status_redraw_all(); /* redraw to remove the ruler */
11755# endif
11756 p_ru = 0; /* no ruler */
11757#endif
11758#ifdef FEAT_RIGHTLEFT
11759 p_ri = 0; /* no reverse insert */
11760 p_hkmap = 0; /* no Hebrew keyboard */
11761#endif
11762 /* set global values for local buffer options */
11763 p_tw = 0;
11764 p_wm = 0;
11765 p_sts = 0;
11766 p_ai = 0;
11767 }
11768
11769 /*
11770 * Paste switched from on to off: Restore saved values.
11771 */
11772 else if (old_p_paste)
11773 {
11774 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011775 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776 {
11777 buf->b_p_tw = buf->b_p_tw_nopaste;
11778 buf->b_p_wm = buf->b_p_wm_nopaste;
11779 buf->b_p_sts = buf->b_p_sts_nopaste;
11780 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011781 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782 }
11783
11784 /* restore global options */
11785 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011786 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011787#ifdef FEAT_CMDL_INFO
11788# ifdef FEAT_WINDOWS
11789 if (p_ru != save_ru)
11790 status_redraw_all(); /* redraw to draw the ruler */
11791# endif
11792 p_ru = save_ru;
11793#endif
11794#ifdef FEAT_RIGHTLEFT
11795 p_ri = save_ri;
11796 p_hkmap = save_hkmap;
11797#endif
11798 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011799 p_ai = p_ai_nopaste;
11800 p_et = p_et_nopaste;
11801 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802 p_tw = p_tw_nopaste;
11803 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011804 }
11805
11806 old_p_paste = p_paste;
11807}
11808
11809/*
11810 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11811 *
11812 * Reset 'compatible' and set the values for options that didn't get set yet
11813 * to the Vim defaults.
11814 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011815 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816 */
11817 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011818vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011820 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011821 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011822 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823
11824 if (!option_was_set((char_u *)"cp"))
11825 {
11826 p_cp = FALSE;
11827 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11828 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11829 set_option_default(opt_idx, OPT_FREE, FALSE);
11830 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011831 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011832 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011833
11834 if (fname != NULL)
11835 {
11836 p = vim_getenv(envname, &dofree);
11837 if (p == NULL)
11838 {
11839 /* Set $MYVIMRC to the first vimrc file found. */
11840 p = FullName_save(fname, FALSE);
11841 if (p != NULL)
11842 {
11843 vim_setenv(envname, p);
11844 vim_free(p);
11845 }
11846 }
11847 else if (dofree)
11848 vim_free(p);
11849 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011850}
11851
11852/*
11853 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11854 */
11855 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011856change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011857{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011858 int opt_idx;
11859
Bram Moolenaar071d4272004-06-13 20:20:40 +000011860 if (p_cp != on)
11861 {
11862 p_cp = on;
11863 compatible_set();
11864 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011865 opt_idx = findoption((char_u *)"cp");
11866 if (opt_idx >= 0)
11867 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868}
11869
11870/*
11871 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011872 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011873 */
11874 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011875option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876{
11877 int idx;
11878
11879 idx = findoption(name);
11880 if (idx < 0) /* unknown option */
11881 return FALSE;
11882 if (options[idx].flags & P_WAS_SET)
11883 return TRUE;
11884 return FALSE;
11885}
11886
11887/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011888 * Reset the flag indicating option "name" was set.
11889 */
11890 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011891reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011892{
11893 int idx = findoption(name);
11894
11895 if (idx >= 0)
11896 options[idx].flags &= ~P_WAS_SET;
11897}
11898
11899/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900 * compatible_set() - Called when 'compatible' has been set or unset.
11901 *
11902 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11903 * flag) to a Vi compatible value.
11904 * When 'compatible' is unset: Set all options that have a different default
11905 * for Vim (without the P_VI_DEF flag) to that default.
11906 */
11907 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011908compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011909{
11910 int opt_idx;
11911
11912 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11913 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11914 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11915 set_option_default(opt_idx, OPT_FREE, p_cp);
11916 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011917 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011918}
11919
11920#ifdef FEAT_LINEBREAK
11921
11922# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11923 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011924 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011925# endif
11926
11927/*
11928 * fill_breakat_flags() -- called when 'breakat' changes value.
11929 */
11930 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011931fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011933 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934 int i;
11935
11936 for (i = 0; i < 256; i++)
11937 breakat_flags[i] = FALSE;
11938
11939 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011940 for (p = p_breakat; *p; p++)
11941 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011942}
11943
11944# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011945 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011946# endif
11947
11948#endif
11949
11950/*
11951 * Check an option that can be a range of string values.
11952 *
11953 * Return OK for correct value, FAIL otherwise.
11954 * Empty is always OK.
11955 */
11956 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011957check_opt_strings(
11958 char_u *val,
11959 char **values,
11960 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011961{
11962 return opt_strings_flags(val, values, NULL, list);
11963}
11964
11965/*
11966 * Handle an option that can be a range of string values.
11967 * Set a flag in "*flagp" for each string present.
11968 *
11969 * Return OK for correct value, FAIL otherwise.
11970 * Empty is always OK.
11971 */
11972 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011973opt_strings_flags(
11974 char_u *val, /* new value */
11975 char **values, /* array of valid string values */
11976 unsigned *flagp,
11977 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978{
11979 int i;
11980 int len;
11981 unsigned new_flags = 0;
11982
11983 while (*val)
11984 {
11985 for (i = 0; ; ++i)
11986 {
11987 if (values[i] == NULL) /* val not found in values[] */
11988 return FAIL;
11989
11990 len = (int)STRLEN(values[i]);
11991 if (STRNCMP(values[i], val, len) == 0
11992 && ((list && val[len] == ',') || val[len] == NUL))
11993 {
11994 val += len + (val[len] == ',');
11995 new_flags |= (1 << i);
11996 break; /* check next item in val list */
11997 }
11998 }
11999 }
12000 if (flagp != NULL)
12001 *flagp = new_flags;
12002
12003 return OK;
12004}
12005
12006/*
12007 * Read the 'wildmode' option, fill wim_flags[].
12008 */
12009 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012010check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012011{
12012 char_u new_wim_flags[4];
12013 char_u *p;
12014 int i;
12015 int idx = 0;
12016
12017 for (i = 0; i < 4; ++i)
12018 new_wim_flags[i] = 0;
12019
12020 for (p = p_wim; *p; ++p)
12021 {
12022 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12023 ;
12024 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12025 return FAIL;
12026 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12027 new_wim_flags[idx] |= WIM_LONGEST;
12028 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12029 new_wim_flags[idx] |= WIM_FULL;
12030 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12031 new_wim_flags[idx] |= WIM_LIST;
12032 else
12033 return FAIL;
12034 p += i;
12035 if (*p == NUL)
12036 break;
12037 if (*p == ',')
12038 {
12039 if (idx == 3)
12040 return FAIL;
12041 ++idx;
12042 }
12043 }
12044
12045 /* fill remaining entries with last flag */
12046 while (idx < 3)
12047 {
12048 new_wim_flags[idx + 1] = new_wim_flags[idx];
12049 ++idx;
12050 }
12051
12052 /* only when there are no errors, wim_flags[] is changed */
12053 for (i = 0; i < 4; ++i)
12054 wim_flags[i] = new_wim_flags[i];
12055 return OK;
12056}
12057
12058/*
12059 * Check if backspacing over something is allowed.
12060 */
12061 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012062can_bs(
12063 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012064{
12065 switch (*p_bs)
12066 {
12067 case '2': return TRUE;
12068 case '1': return (what != BS_START);
12069 case '0': return FALSE;
12070 }
12071 return vim_strchr(p_bs, what) != NULL;
12072}
12073
12074/*
12075 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12076 * the file must be considered changed when the value is different.
12077 */
12078 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012079save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012080{
12081 buf->b_start_ffc = *buf->b_p_ff;
12082 buf->b_start_eol = buf->b_p_eol;
12083#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012084 buf->b_start_bomb = buf->b_p_bomb;
12085
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086 /* Only use free/alloc when necessary, they take time. */
12087 if (buf->b_start_fenc == NULL
12088 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12089 {
12090 vim_free(buf->b_start_fenc);
12091 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12092 }
12093#endif
12094}
12095
12096/*
12097 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12098 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012099 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12100 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012101 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012102 * When "ignore_empty" is true don't consider a new, empty buffer to be
12103 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012104 */
12105 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012106file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012107{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012108 /* In a buffer that was never loaded the options are not valid. */
12109 if (buf->b_flags & BF_NEVERLOADED)
12110 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012111 if (ignore_empty
12112 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012113 && buf->b_ml.ml_line_count == 1
12114 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12115 return FALSE;
12116 if (buf->b_start_ffc != *buf->b_p_ff)
12117 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012118 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012119 return TRUE;
12120#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012121 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12122 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012123 if (buf->b_start_fenc == NULL)
12124 return (*buf->b_p_fenc != NUL);
12125 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12126#else
12127 return FALSE;
12128#endif
12129}
12130
12131/*
12132 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12133 */
12134 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012135check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136{
12137 return check_opt_strings(p, p_ff_values, FALSE);
12138}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012139
12140/*
12141 * Return the effective shiftwidth value for current buffer, using the
12142 * 'tabstop' value when 'shiftwidth' is zero.
12143 */
12144 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012145get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012146{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012147 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012148}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012149
12150/*
12151 * Return the effective softtabstop value for the current buffer, using the
12152 * 'tabstop' value when 'softtabstop' is negative.
12153 */
12154 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012155get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012156{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012157 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012158}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012159
12160/*
12161 * Check matchpairs option for "*initc".
12162 * If there is a match set "*initc" to the matching character and "*findc" to
12163 * the opposite character. Set "*backwards" to the direction.
12164 * When "switchit" is TRUE swap the direction.
12165 */
12166 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012167find_mps_values(
12168 int *initc,
12169 int *findc,
12170 int *backwards,
12171 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012172{
12173 char_u *ptr;
12174
12175 ptr = curbuf->b_p_mps;
12176 while (*ptr != NUL)
12177 {
12178#ifdef FEAT_MBYTE
12179 if (has_mbyte)
12180 {
12181 char_u *prev;
12182
12183 if (mb_ptr2char(ptr) == *initc)
12184 {
12185 if (switchit)
12186 {
12187 *findc = *initc;
12188 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12189 *backwards = TRUE;
12190 }
12191 else
12192 {
12193 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12194 *backwards = FALSE;
12195 }
12196 return;
12197 }
12198 prev = ptr;
12199 ptr += mb_ptr2len(ptr) + 1;
12200 if (mb_ptr2char(ptr) == *initc)
12201 {
12202 if (switchit)
12203 {
12204 *findc = *initc;
12205 *initc = mb_ptr2char(prev);
12206 *backwards = FALSE;
12207 }
12208 else
12209 {
12210 *findc = mb_ptr2char(prev);
12211 *backwards = TRUE;
12212 }
12213 return;
12214 }
12215 ptr += mb_ptr2len(ptr);
12216 }
12217 else
12218#endif
12219 {
12220 if (*ptr == *initc)
12221 {
12222 if (switchit)
12223 {
12224 *backwards = TRUE;
12225 *findc = *initc;
12226 *initc = ptr[2];
12227 }
12228 else
12229 {
12230 *backwards = FALSE;
12231 *findc = ptr[2];
12232 }
12233 return;
12234 }
12235 ptr += 2;
12236 if (*ptr == *initc)
12237 {
12238 if (switchit)
12239 {
12240 *backwards = FALSE;
12241 *findc = *initc;
12242 *initc = ptr[-2];
12243 }
12244 else
12245 {
12246 *backwards = TRUE;
12247 *findc = ptr[-2];
12248 }
12249 return;
12250 }
12251 ++ptr;
12252 }
12253 if (*ptr == ',')
12254 ++ptr;
12255 }
12256}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012257
12258#if defined(FEAT_LINEBREAK) || defined(PROTO)
12259/*
12260 * This is called when 'breakindentopt' is changed and when a window is
12261 * initialized.
12262 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012263 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012264briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012265{
12266 char_u *p;
12267 int bri_shift = 0;
12268 long bri_min = 20;
12269 int bri_sbr = FALSE;
12270
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012271 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012272 while (*p != NUL)
12273 {
12274 if (STRNCMP(p, "shift:", 6) == 0
12275 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12276 {
12277 p += 6;
12278 bri_shift = getdigits(&p);
12279 }
12280 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12281 {
12282 p += 4;
12283 bri_min = getdigits(&p);
12284 }
12285 else if (STRNCMP(p, "sbr", 3) == 0)
12286 {
12287 p += 3;
12288 bri_sbr = TRUE;
12289 }
12290 if (*p != ',' && *p != NUL)
12291 return FAIL;
12292 if (*p == ',')
12293 ++p;
12294 }
12295
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012296 wp->w_p_brishift = bri_shift;
12297 wp->w_p_brimin = bri_min;
12298 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012299
12300 return OK;
12301}
12302#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012303
12304/*
12305 * Get the local or global value of 'backupcopy'.
12306 */
12307 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012308get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012309{
12310 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12311}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012312
12313#if defined(FEAT_SIGNS) || defined(PROTO)
12314/*
12315 * Return TRUE when window "wp" has a column to draw signs in.
12316 */
12317 int
12318signcolumn_on(win_T *wp)
12319{
12320 if (*wp->w_p_scl == 'n')
12321 return FALSE;
12322 if (*wp->w_p_scl == 'y')
12323 return TRUE;
12324 return (wp->w_buffer->b_signlist != NULL
12325# ifdef FEAT_NETBEANS_INTG
12326 || wp->w_buffer->b_has_sign_column
12327# endif
12328 );
12329}
12330#endif