blob: 9f1aaf1d152b8b9ddc46aa60ee6c637cd47d4f24 [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 Moolenaar58b85342016-08-14 19:54:54 +0200474# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@: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 Moolenaar920694c2016-08-21 17:45:02 +02001708 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1709#ifdef FEAT_LANGMAP
1710 (char_u *)&p_lrm, PV_NONE,
1711#else
1712 (char_u *)NULL, PV_NONE,
1713#endif
1714 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1716#ifdef FEAT_WINDOWS
1717 (char_u *)&p_ls, PV_NONE,
1718#else
1719 (char_u *)NULL, PV_NONE,
1720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1723 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1726#ifdef FEAT_LINEBREAK
1727 (char_u *)VAR_WIN, PV_LBR,
1728#else
1729 (char_u *)NULL, PV_NONE,
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1733 (char_u *)&Rows, PV_NONE,
1734 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001735#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 (char_u *)25L,
1737#else
1738 (char_u *)24L,
1739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001740 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1742#ifdef FEAT_GUI
1743 (char_u *)&p_linespace, PV_NONE,
1744#else
1745 (char_u *)NULL, PV_NONE,
1746#endif
1747#ifdef FEAT_GUI_W32
1748 {(char_u *)1L, (char_u *)0L}
1749#else
1750 {(char_u *)0L, (char_u *)0L}
1751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"lisp", NULL, P_BOOL|P_VI_DEF,
1754#ifdef FEAT_LISP
1755 (char_u *)&p_lisp, PV_LISP,
1756#else
1757 (char_u *)NULL, PV_NONE,
1758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001760 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001762 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1764#else
1765 (char_u *)NULL, PV_NONE,
1766 {(char_u *)"", (char_u *)0L}
1767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1770 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001772 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1776 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001778#if defined(DYNAMIC_LUA)
Bram Moolenaara6e42502016-04-20 16:19:52 +02001779 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001780 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001781 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1782 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001783#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001784#ifdef FEAT_GUI_MAC
1785 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1786 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001787 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"magic", NULL, P_BOOL|P_VI_DEF,
1790 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001792 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793#ifdef FEAT_QUICKFIX
1794 (char_u *)&p_mef, PV_NONE,
1795 {(char_u *)"", (char_u *)0L}
1796#else
1797 (char_u *)NULL, PV_NONE,
1798 {(char_u *)NULL, (char_u *)0L}
1799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001800 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001801 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1802#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001803 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804# ifdef VMS
1805 {(char_u *)"MMS", (char_u *)0L}
1806# else
1807 {(char_u *)"make", (char_u *)0L}
1808# endif
1809#else
1810 (char_u *)NULL, PV_NONE,
1811 {(char_u *)NULL, (char_u *)0L}
1812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001814 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1817 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"matchtime", "mat", P_NUM|P_VI_DEF,
1819 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001821 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001822#ifdef FEAT_MBYTE
1823 (char_u *)&p_mco, PV_NONE,
1824#else
1825 (char_u *)NULL, PV_NONE,
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1829#ifdef FEAT_EVAL
1830 (char_u *)&p_mfd, PV_NONE,
1831#else
1832 (char_u *)NULL, PV_NONE,
1833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mmd, 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 {"maxmem", "mm", P_NUM|P_VI_DEF,
1839 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1841 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001842 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1843 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1846 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1848 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"menuitems", "mis", P_NUM|P_VI_DEF,
1850#ifdef FEAT_MENU
1851 (char_u *)&p_mis, PV_NONE,
1852#else
1853 (char_u *)NULL, PV_NONE,
1854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {"mesg", NULL, P_BOOL|P_VI_DEF,
1857 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001859 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001860#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001861 (char_u *)&p_msm, PV_NONE,
1862 {(char_u *)"460000,2000,500", (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)0L, (char_u *)0L}
1866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"modeline", "ml", P_BOOL|P_VIM,
1869 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"modelines", "mls", P_NUM|P_VI_DEF,
1872 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1875 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1878 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"more", NULL, P_BOOL|P_VIM,
1881 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001882 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1884 (char_u *)&p_mouse, PV_NONE,
1885 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001886#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001887 (char_u *)"a",
1888#else
1889 (char_u *)"",
1890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1893#ifdef FEAT_GUI
1894 (char_u *)&p_mousef, PV_NONE,
1895#else
1896 (char_u *)NULL, PV_NONE,
1897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1900#ifdef FEAT_GUI
1901 (char_u *)&p_mh, PV_NONE,
1902#else
1903 (char_u *)NULL, PV_NONE,
1904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1907 (char_u *)&p_mousem, PV_NONE,
1908 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001909#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 (char_u *)"popup",
1911#else
1912# if defined(MACOS)
1913 (char_u *)"popup_setpos",
1914# else
1915 (char_u *)"extend",
1916# endif
1917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001918 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001919 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920#ifdef FEAT_MOUSESHAPE
1921 (char_u *)&p_mouseshape, PV_NONE,
1922 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1923#else
1924 (char_u *)NULL, PV_NONE,
1925 {(char_u *)NULL, (char_u *)0L}
1926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1929 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001931 {"mzquantum", "mzq", P_NUM,
1932#ifdef FEAT_MZSCHEME
1933 (char_u *)&p_mzq, PV_NONE,
1934#else
1935 (char_u *)NULL, PV_NONE,
1936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"novice", NULL, P_BOOL|P_VI_DEF,
1939 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001941 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001943 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1946 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001948 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1949#ifdef FEAT_LINEBREAK
1950 (char_u *)VAR_WIN, PV_NUW,
1951#else
1952 (char_u *)NULL, PV_NONE,
1953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001955 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001956#ifdef FEAT_COMPL_FUNC
1957 (char_u *)&p_ofu, PV_OFU,
1958 {(char_u *)"", (char_u *)0L}
1959#else
1960 (char_u *)NULL, PV_NONE,
1961 {(char_u *)0L, (char_u *)0L}
1962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"open", NULL, P_BOOL|P_VI_DEF,
1965 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001966 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001967 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001968#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001969 (char_u *)&p_odev, PV_NONE,
1970#else
1971 (char_u *)NULL, PV_NONE,
1972#endif
1973 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001975 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1976 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"optimize", "opt", P_BOOL|P_VI_DEF,
1979 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001983 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001984 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1985 |P_SECURE,
1986 (char_u *)&p_pp, PV_NONE,
1987 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
1988 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"paragraphs", "para", P_STRING|P_VI_DEF,
1990 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001991 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001992 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001993 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001995 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1997 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2000#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2001 (char_u *)&p_pex, PV_NONE,
2002 {(char_u *)"", (char_u *)0L}
2003#else
2004 (char_u *)NULL, PV_NONE,
2005 {(char_u *)0L, (char_u *)0L}
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002008 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002010 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002011 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002012 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002014#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002015 (char_u *)".,,",
2016#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002019 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002020#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002021 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002022 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002023 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2024 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2027 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002028 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002029 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2031 (char_u *)&p_pvh, PV_NONE,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2037#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2038 (char_u *)VAR_WIN, PV_PVW,
2039#else
2040 (char_u *)NULL, PV_NONE,
2041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002043 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044#ifdef FEAT_PRINTER
2045 (char_u *)&p_pdev, PV_NONE,
2046 {(char_u *)"", (char_u *)0L}
2047#else
2048 (char_u *)NULL, PV_NONE,
2049 {(char_u *)NULL, (char_u *)0L}
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"printencoding", "penc", P_STRING|P_VI_DEF,
2053#ifdef FEAT_POSTSCRIPT
2054 (char_u *)&p_penc, PV_NONE,
2055 {(char_u *)"", (char_u *)0L}
2056#else
2057 (char_u *)NULL, PV_NONE,
2058 {(char_u *)NULL, (char_u *)0L}
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2062#ifdef FEAT_POSTSCRIPT
2063 (char_u *)&p_pexpr, PV_NONE,
2064 {(char_u *)"", (char_u *)0L}
2065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)NULL, (char_u *)0L}
2068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"printfont", "pfn", P_STRING|P_VI_DEF,
2071#ifdef FEAT_PRINTER
2072 (char_u *)&p_pfn, PV_NONE,
2073 {
2074# ifdef MSWIN
2075 (char_u *)"Courier_New:h10",
2076# else
2077 (char_u *)"courier",
2078# endif
2079 (char_u *)0L}
2080#else
2081 (char_u *)NULL, PV_NONE,
2082 {(char_u *)NULL, (char_u *)0L}
2083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2086#ifdef FEAT_PRINTER
2087 (char_u *)&p_header, PV_NONE,
2088 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2089#else
2090 (char_u *)NULL, PV_NONE,
2091 {(char_u *)NULL, (char_u *)0L}
2092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002094 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2095#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2096 (char_u *)&p_pmcs, PV_NONE,
2097 {(char_u *)"", (char_u *)0L}
2098#else
2099 (char_u *)NULL, PV_NONE,
2100 {(char_u *)NULL, (char_u *)0L}
2101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002103 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2104#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2105 (char_u *)&p_pmfn, PV_NONE,
2106 {(char_u *)"", (char_u *)0L}
2107#else
2108 (char_u *)NULL, PV_NONE,
2109 {(char_u *)NULL, (char_u *)0L}
2110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002112 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113#ifdef FEAT_PRINTER
2114 (char_u *)&p_popt, PV_NONE,
2115 {(char_u *)"", (char_u *)0L}
2116#else
2117 (char_u *)NULL, PV_NONE,
2118 {(char_u *)NULL, (char_u *)0L}
2119#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002122 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002124 {"pumheight", "ph", P_NUM|P_VI_DEF,
2125#ifdef FEAT_INS_EXPAND
2126 (char_u *)&p_ph, PV_NONE,
2127#else
2128 (char_u *)NULL, PV_NONE,
2129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002130 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002131#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002132 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002134 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2135 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002137#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002138 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002139 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002140 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2141 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002142#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002143 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2144#ifdef FEAT_TEXTOBJ
2145 (char_u *)&p_qe, PV_QE,
2146 {(char_u *)"\\", (char_u *)0L}
2147#else
2148 (char_u *)NULL, PV_NONE,
2149 {(char_u *)NULL, (char_u *)0L}
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2153 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155 {"redraw", NULL, P_BOOL|P_VI_DEF,
2156 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002158 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2159#ifdef FEAT_RELTIME
2160 (char_u *)&p_rdt, PV_NONE,
2161#else
2162 (char_u *)NULL, PV_NONE,
2163#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002164 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002165 {"regexpengine", "re", P_NUM|P_VI_DEF,
2166 (char_u *)&p_re, PV_NONE,
2167 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002168 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2169 (char_u *)VAR_WIN, PV_RNU,
2170 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 {"remap", NULL, P_BOOL|P_VI_DEF,
2172 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002173 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002174 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002175#ifdef FEAT_RENDER_OPTIONS
2176 (char_u *)&p_rop, PV_NONE,
2177 {(char_u *)"", (char_u *)0L}
2178#else
2179 (char_u *)NULL, PV_NONE,
2180 {(char_u *)NULL, (char_u *)0L}
2181#endif
2182 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"report", NULL, P_NUM|P_VI_DEF,
2184 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2187#ifdef WIN3264
2188 (char_u *)&p_rs, PV_NONE,
2189#else
2190 (char_u *)NULL, PV_NONE,
2191#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002192 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2194#ifdef FEAT_RIGHTLEFT
2195 (char_u *)&p_ri, PV_NONE,
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 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2201#ifdef FEAT_RIGHTLEFT
2202 (char_u *)VAR_WIN, PV_RL,
2203#else
2204 (char_u *)NULL, PV_NONE,
2205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002206 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2208#ifdef FEAT_RIGHTLEFT
2209 (char_u *)VAR_WIN, PV_RLC,
2210 {(char_u *)"search", (char_u *)NULL}
2211#else
2212 (char_u *)NULL, PV_NONE,
2213 {(char_u *)NULL, (char_u *)0L}
2214#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002215 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002216#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002217 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002218 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002219 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2220 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2223#ifdef FEAT_CMDL_INFO
2224 (char_u *)&p_ru, PV_NONE,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2230#ifdef FEAT_STL_OPT
2231 (char_u *)&p_ruf, PV_NONE,
2232#else
2233 (char_u *)NULL, PV_NONE,
2234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002235 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002236 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2237 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002239 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2240 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2242 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2245#ifdef FEAT_SCROLLBIND
2246 (char_u *)VAR_WIN, PV_SCBIND,
2247#else
2248 (char_u *)NULL, PV_NONE,
2249#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002250 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2252 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2255 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002256 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002257 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258#ifdef FEAT_SCROLLBIND
2259 (char_u *)&p_sbo, PV_NONE,
2260 {(char_u *)"ver,jump", (char_u *)0L}
2261#else
2262 (char_u *)NULL, PV_NONE,
2263 {(char_u *)0L, (char_u *)0L}
2264#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"sections", "sect", P_STRING|P_VI_DEF,
2267 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2269 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2271 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 {(char_u *)"inclusive", (char_u *)0L}
2276 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002277 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002280 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281#ifdef FEAT_SESSION
2282 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002283 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 (char_u *)0L}
2285#else
2286 (char_u *)NULL, PV_NONE,
2287 {(char_u *)0L, (char_u *)0L}
2288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2291 (char_u *)&p_sh, PV_NONE,
2292 {
2293#ifdef VMS
2294 (char_u *)"-",
2295#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002296# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002298# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300# endif
2301#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2304 (char_u *)&p_shcf, PV_NONE,
2305 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002306#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 (char_u *)"/c",
2308#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2313#ifdef FEAT_QUICKFIX
2314 (char_u *)&p_sp, PV_NONE,
2315 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002316#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318#else
2319 (char_u *)">",
2320#endif
2321 (char_u *)0L}
2322#else
2323 (char_u *)NULL, PV_NONE,
2324 {(char_u *)0L, (char_u *)0L}
2325#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2328 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2331 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2334#ifdef BACKSLASH_IN_FILENAME
2335 (char_u *)&p_ssl, PV_NONE,
2336#else
2337 (char_u *)NULL, PV_NONE,
2338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002340 {"shelltemp", "stmp", P_BOOL,
2341 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"shelltype", "st", P_NUM|P_VI_DEF,
2344#ifdef AMIGA
2345 (char_u *)&p_st, PV_NONE,
2346#else
2347 (char_u *)NULL, PV_NONE,
2348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2351 (char_u *)&p_sxq, PV_NONE,
2352 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002353#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 (char_u *)"\"",
2355#else
2356 (char_u *)"",
2357#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002359 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2360 (char_u *)&p_sxe, PV_NONE,
2361 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002362#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002363 (char_u *)"\"&|<>()@^",
2364#else
2365 (char_u *)"",
2366#endif
2367 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2369 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2372 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2375 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002376 {(char_u *)"", (char_u *)"filnxtToO"}
2377 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2382#ifdef FEAT_LINEBREAK
2383 (char_u *)&p_sbr, PV_NONE,
2384#else
2385 (char_u *)NULL, PV_NONE,
2386#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"showcmd", "sc", P_BOOL|P_VIM,
2389#ifdef FEAT_CMDL_INFO
2390 (char_u *)&p_sc, PV_NONE,
2391#else
2392 (char_u *)NULL, PV_NONE,
2393#endif
2394 {(char_u *)FALSE,
2395#ifdef UNIX
2396 (char_u *)FALSE
2397#else
2398 (char_u *)TRUE
2399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2402 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2405 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"showmode", "smd", P_BOOL|P_VIM,
2408 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002410 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2411#ifdef FEAT_WINDOWS
2412 (char_u *)&p_stal, PV_NONE,
2413#else
2414 (char_u *)NULL, PV_NONE,
2415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2418 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2421 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002423 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2424#ifdef FEAT_SIGNS
2425 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002426 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002427#else
2428 (char_u *)NULL, PV_NONE,
2429 {(char_u *)NULL, (char_u *)0L}
2430#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002431 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2433 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2436 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2439#ifdef FEAT_SMARTINDENT
2440 (char_u *)&p_si, PV_SI,
2441#else
2442 (char_u *)NULL, PV_NONE,
2443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2446 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2449 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2452 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002454 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002455#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002456 (char_u *)VAR_WIN, PV_SPELL,
2457#else
2458 (char_u *)NULL, PV_NONE,
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002461 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002462#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002463 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002464 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002465#else
2466 (char_u *)NULL, PV_NONE,
2467 {(char_u *)0L, (char_u *)0L}
2468#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002470 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2471 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002472#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002473 (char_u *)&p_spf, PV_SPF,
2474 {(char_u *)"", (char_u *)0L}
2475#else
2476 (char_u *)NULL, PV_NONE,
2477 {(char_u *)0L, (char_u *)0L}
2478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002479 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002480 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2481 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002482#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002483 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002484 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002485#else
2486 (char_u *)NULL, PV_NONE,
2487 {(char_u *)0L, (char_u *)0L}
2488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002490 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002491#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002492 (char_u *)&p_sps, PV_NONE,
2493 {(char_u *)"best", (char_u *)0L}
2494#else
2495 (char_u *)NULL, PV_NONE,
2496 {(char_u *)0L, (char_u *)0L}
2497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2500#ifdef FEAT_WINDOWS
2501 (char_u *)&p_sb, PV_NONE,
2502#else
2503 (char_u *)NULL, PV_NONE,
2504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002507#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 (char_u *)&p_spr, PV_NONE,
2509#else
2510 (char_u *)NULL, PV_NONE,
2511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2514 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2517#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002518 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519#else
2520 (char_u *)NULL, PV_NONE,
2521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002523 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 (char_u *)&p_su, PV_NONE,
2525 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002527 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002528#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 (char_u *)&p_sua, PV_SUA,
2530 {(char_u *)"", (char_u *)0L}
2531#else
2532 (char_u *)NULL, PV_NONE,
2533 {(char_u *)0L, (char_u *)0L}
2534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002535 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2537 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"swapsync", "sws", P_STRING|P_VI_DEF,
2540 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002542 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002545 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2546#ifdef FEAT_SYN_HL
2547 (char_u *)&p_smc, PV_SMC,
2548 {(char_u *)3000L, (char_u *)0L}
2549#else
2550 (char_u *)NULL, PV_NONE,
2551 {(char_u *)0L, (char_u *)0L}
2552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002554 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555#ifdef FEAT_SYN_HL
2556 (char_u *)&p_syn, PV_SYN,
2557 {(char_u *)"", (char_u *)0L}
2558#else
2559 (char_u *)NULL, PV_NONE,
2560 {(char_u *)0L, (char_u *)0L}
2561#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002563 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2564#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002565 (char_u *)&p_tal, PV_NONE,
2566#else
2567 (char_u *)NULL, PV_NONE,
2568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002570 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2571#ifdef FEAT_WINDOWS
2572 (char_u *)&p_tpm, PV_NONE,
2573#else
2574 (char_u *)NULL, PV_NONE,
2575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2578 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2581 (char_u *)&p_tbs, PV_NONE,
2582#ifdef VMS /* binary searching doesn't appear to work on VMS */
2583 {(char_u *)0L, (char_u *)0L}
2584#else
2585 {(char_u *)TRUE, (char_u *)0L}
2586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002588 {"tagcase", "tc", P_STRING|P_VIM,
2589 (char_u *)&p_tc, PV_TC,
2590 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"taglength", "tl", P_NUM|P_VI_DEF,
2592 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"tagrelative", "tr", P_BOOL|P_VIM,
2595 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002597 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002598 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {
2600#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2601 (char_u *)"./tags,./TAGS,tags,TAGS",
2602#else
2603 (char_u *)"./tags,tags",
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2607 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002608 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002609#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002610 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002611 (char_u *)&p_tcldll, PV_NONE,
2612 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2613 SCRIPTID_INIT},
2614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2616 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2619#ifdef FEAT_ARABIC
2620 (char_u *)&p_tbidi, PV_NONE,
2621#else
2622 (char_u *)NULL, PV_NONE,
2623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2626#ifdef FEAT_MBYTE
2627 (char_u *)&p_tenc, PV_NONE,
2628 {(char_u *)"", (char_u *)0L}
2629#else
2630 (char_u *)NULL, PV_NONE,
2631 {(char_u *)0L, (char_u *)0L}
2632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002634 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2635#ifdef FEAT_TERMGUICOLORS
2636 (char_u *)&p_tgc, PV_NONE,
2637 {(char_u *)FALSE, (char_u *)FALSE}
2638#else
2639 (char_u*)NULL, PV_NONE,
2640 {(char_u *)FALSE, (char_u *)FALSE}
2641#endif
2642 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"terse", NULL, P_BOOL|P_VI_DEF,
2644 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"textauto", "ta", P_BOOL|P_VIM,
2647 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2649 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2651 (char_u *)&p_tx, PV_TX,
2652 {
2653#ifdef USE_CRNL
2654 (char_u *)TRUE,
2655#else
2656 (char_u *)FALSE,
2657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002659 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002662 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002664 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665#else
2666 (char_u *)NULL, PV_NONE,
2667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2670 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"timeout", "to", P_BOOL|P_VI_DEF,
2673 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2676 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"title", NULL, P_BOOL|P_VI_DEF,
2679#ifdef FEAT_TITLE
2680 (char_u *)&p_title, PV_NONE,
2681#else
2682 (char_u *)NULL, PV_NONE,
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 {"titlelen", NULL, P_NUM|P_VI_DEF,
2686#ifdef FEAT_TITLE
2687 (char_u *)&p_titlelen, PV_NONE,
2688#else
2689 (char_u *)NULL, PV_NONE,
2690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002692 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693#ifdef FEAT_TITLE
2694 (char_u *)&p_titleold, PV_NONE,
2695 {(char_u *)N_("Thanks for flying Vim"),
2696 (char_u *)0L}
2697#else
2698 (char_u *)NULL, PV_NONE,
2699 {(char_u *)0L, (char_u *)0L}
2700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"titlestring", NULL, P_STRING|P_VI_DEF,
2703#ifdef FEAT_TITLE
2704 (char_u *)&p_titlestring, PV_NONE,
2705#else
2706 (char_u *)NULL, PV_NONE,
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002710 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 {(char_u *)"icons,tooltips", (char_u *)0L}
2713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002715#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2717 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719#endif
2720 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2721 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2724 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002725 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2727 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2730 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2733#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2734 (char_u *)&p_ttym, PV_NONE,
2735#else
2736 (char_u *)NULL, PV_NONE,
2737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2740 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002741 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2743 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002745 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2746 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002747#ifdef FEAT_PERSISTENT_UNDO
2748 (char_u *)&p_udir, PV_NONE,
2749 {(char_u *)".", (char_u *)0L}
2750#else
2751 (char_u *)NULL, PV_NONE,
2752 {(char_u *)0L, (char_u *)0L}
2753#endif
2754 SCRIPTID_INIT},
2755 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2756#ifdef FEAT_PERSISTENT_UNDO
2757 (char_u *)&p_udf, PV_UDF,
2758#else
2759 (char_u *)NULL, PV_NONE,
2760#endif
2761 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002763 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002765#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 (char_u *)1000L,
2767#else
2768 (char_u *)100L,
2769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002771 {"undoreload", "ur", P_NUM|P_VI_DEF,
2772 (char_u *)&p_ur, PV_NONE,
2773 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 {"updatecount", "uc", P_NUM|P_VI_DEF,
2775 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002776 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 {"updatetime", "ut", P_NUM|P_VI_DEF,
2778 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002779 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"verbose", "vbs", P_NUM|P_VI_DEF,
2781 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002783 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2784 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2787#ifdef FEAT_SESSION
2788 (char_u *)&p_vdir, PV_NONE,
2789 {(char_u *)DFLT_VDIR, (char_u *)0L}
2790#else
2791 (char_u *)NULL, PV_NONE,
2792 {(char_u *)0L, (char_u *)0L}
2793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002795 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796#ifdef FEAT_SESSION
2797 (char_u *)&p_vop, PV_NONE,
2798 {(char_u *)"folds,options,cursor", (char_u *)0L}
2799#else
2800 (char_u *)NULL, PV_NONE,
2801 {(char_u *)0L, (char_u *)0L}
2802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002803 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002804 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805#ifdef FEAT_VIMINFO
2806 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002807#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002808 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809#else
2810# ifdef AMIGA
2811 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002812 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002814 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815# endif
2816#endif
2817#else
2818 (char_u *)NULL, PV_NONE,
2819 {(char_u *)0L, (char_u *)0L}
2820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002822 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2823 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824#ifdef FEAT_VIRTUALEDIT
2825 (char_u *)&p_ve, PV_NONE,
2826 {(char_u *)"", (char_u *)""}
2827#else
2828 (char_u *)NULL, PV_NONE,
2829 {(char_u *)0L, (char_u *)0L}
2830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2833 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"w300", NULL, P_NUM|P_VI_DEF,
2836 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"w1200", NULL, P_NUM|P_VI_DEF,
2839 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"w9600", NULL, P_NUM|P_VI_DEF,
2842 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"warn", NULL, P_BOOL|P_VI_DEF,
2845 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2848 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002850 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"wildchar", "wc", P_NUM|P_VIM,
2854 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2856 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002857 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002860 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861#ifdef FEAT_WILDIGN
2862 (char_u *)&p_wig, PV_NONE,
2863#else
2864 (char_u *)NULL, PV_NONE,
2865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002867 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2868 (char_u *)&p_wic, PV_NONE,
2869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2871#ifdef FEAT_WILDMENU
2872 (char_u *)&p_wmnu, PV_NONE,
2873#else
2874 (char_u *)NULL, PV_NONE,
2875#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002877 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002880 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2881#ifdef FEAT_CMDL_COMPL
2882 (char_u *)&p_wop, PV_NONE,
2883 {(char_u *)"", (char_u *)0L}
2884#else
2885 (char_u *)NULL, PV_NONE,
2886 {(char_u *)NULL, (char_u *)0L}
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2890#ifdef FEAT_WAK
2891 (char_u *)&p_wak, PV_NONE,
2892 {(char_u *)"menu", (char_u *)0L}
2893#else
2894 (char_u *)NULL, PV_NONE,
2895 {(char_u *)NULL, (char_u *)0L}
2896#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002899 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"winheight", "wh", P_NUM|P_VI_DEF,
2902#ifdef FEAT_WINDOWS
2903 (char_u *)&p_wh, PV_NONE,
2904#else
2905 (char_u *)NULL, PV_NONE,
2906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002907 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002909#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 (char_u *)VAR_WIN, PV_WFH,
2911#else
2912 (char_u *)NULL, PV_NONE,
2913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002915 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002916#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002917 (char_u *)VAR_WIN, PV_WFW,
2918#else
2919 (char_u *)NULL, PV_NONE,
2920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2923#ifdef FEAT_WINDOWS
2924 (char_u *)&p_wmh, PV_NONE,
2925#else
2926 (char_u *)NULL, PV_NONE,
2927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002928 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002930#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 (char_u *)&p_wmw, PV_NONE,
2932#else
2933 (char_u *)NULL, PV_NONE,
2934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002937#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938 (char_u *)&p_wiw, PV_NONE,
2939#else
2940 (char_u *)NULL, PV_NONE,
2941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002942 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2944 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002945 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2947 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2950 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002951 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952 {"write", NULL, P_BOOL|P_VI_DEF,
2953 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002954 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 {"writeany", "wa", P_BOOL|P_VI_DEF,
2956 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2959 (char_u *)&p_wb, PV_NONE,
2960 {
2961#ifdef FEAT_WRITEBACKUP
2962 (char_u *)TRUE,
2963#else
2964 (char_u *)FALSE,
2965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002966 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 {"writedelay", "wd", P_NUM|P_VI_DEF,
2968 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002969 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970
2971/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002972#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002974 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975
2976 p_term("t_AB", T_CAB)
2977 p_term("t_AF", T_CAF)
2978 p_term("t_AL", T_CAL)
2979 p_term("t_al", T_AL)
2980 p_term("t_bc", T_BC)
2981 p_term("t_cd", T_CD)
2982 p_term("t_ce", T_CE)
2983 p_term("t_cl", T_CL)
2984 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002985 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 p_term("t_Co", T_CCO)
2987 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002988 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002990#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 p_term("t_CV", T_CSV)
2992#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 p_term("t_da", T_DA)
2994 p_term("t_db", T_DB)
2995 p_term("t_DL", T_CDL)
2996 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002997 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 p_term("t_fs", T_FS)
2999 p_term("t_IE", T_CIE)
3000 p_term("t_IS", T_CIS)
3001 p_term("t_ke", T_KE)
3002 p_term("t_ks", T_KS)
3003 p_term("t_le", T_LE)
3004 p_term("t_mb", T_MB)
3005 p_term("t_md", T_MD)
3006 p_term("t_me", T_ME)
3007 p_term("t_mr", T_MR)
3008 p_term("t_ms", T_MS)
3009 p_term("t_nd", T_ND)
3010 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003011 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 p_term("t_RI", T_CRI)
3013 p_term("t_RV", T_CRV)
3014 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003016 p_term("t_Sf", T_CSF)
3017 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003019 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 p_term("t_te", T_TE)
3022 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003023 p_term("t_ts", T_TS)
3024 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 p_term("t_ue", T_UE)
3026 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003027 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 p_term("t_vb", T_VB)
3029 p_term("t_ve", T_VE)
3030 p_term("t_vi", T_VI)
3031 p_term("t_vs", T_VS)
3032 p_term("t_WP", T_CWP)
3033 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003034 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035 p_term("t_xs", T_XS)
3036 p_term("t_ZH", T_CZH)
3037 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003038 p_term("t_8f", T_8F)
3039 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040
3041/* terminal key codes are not in here */
3042
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003043 /* end marker */
3044 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045};
3046
3047#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3048
3049#ifdef FEAT_MBYTE
3050static char *(p_ambw_values[]) = {"single", "double", NULL};
3051#endif
3052static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003053static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003055#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003056static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003057#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003058#ifdef FEAT_CMDL_COMPL
3059static char *(p_wop_values[]) = {"tagfile", NULL};
3060#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061#ifdef FEAT_WAK
3062static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3063#endif
3064static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3066static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068#ifdef FEAT_BROWSE
3069static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3070#endif
3071#ifdef FEAT_SCROLLBIND
3072static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3073#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003074static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003075#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3077#endif
3078#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003079# ifdef FEAT_AUTOCMD
3080static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3081# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003083# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3085#endif
3086static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3087#ifdef FEAT_FOLDING
3088static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003089# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003091# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 NULL};
3093static char *(p_fcl_values[]) = {"all", NULL};
3094#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003095#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003096static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003097#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003098#ifdef FEAT_SIGNS
3099static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003102static void set_option_default(int, int opt_flags, int compatible);
3103static void set_options_default(int opt_flags);
3104static char_u *term_bg_default(void);
3105static void did_set_option(int opt_idx, int opt_flags, int new_value);
3106static char_u *illegal_char(char_u *, int);
3107static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003109static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110#endif
3111#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003112static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003114static char_u *option_expand(int opt_idx, char_u *val);
3115static void didset_options(void);
3116static void didset_options2(void);
3117static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003118#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003119static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003120#else
3121# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3122#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003123static void set_string_option_global(int opt_idx, char_u **varp);
3124static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3125static 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);
3126static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003127#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003128static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003131static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003133#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003134static char_u *did_set_spell_option(int is_spellfile);
3135static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003136#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003137#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003138static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003139#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003140static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3141static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3142static void check_redraw(long_u flags);
3143static int findoption(char_u *);
3144static int find_key_option(char_u *);
3145static void showoptions(int all, int opt_flags);
3146static int optval_default(struct vimoption *, char_u *varp);
3147static void showoneopt(struct vimoption *, int opt_flags);
3148static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3149static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3150static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3151static int istermoption(struct vimoption *);
3152static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3153static char_u *get_varp(struct vimoption *);
3154static void option_value2string(struct vimoption *, int opt_flags);
3155static void check_winopt(winopt_T *wop);
3156static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003158static void langmap_init(void);
3159static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003161static void paste_option_changed(void);
3162static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003164static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003166static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3167static int check_opt_strings(char_u *val, char **values, int);
3168static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003169#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003170static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003171#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172
3173/*
3174 * Initialize the options, first part.
3175 *
3176 * Called only once from main(), just after creating the first buffer.
3177 */
3178 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003179set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180{
3181 char_u *p;
3182 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003183 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184
3185#ifdef FEAT_LANGMAP
3186 langmap_init();
3187#endif
3188
3189 /* Be Vi compatible by default */
3190 p_cp = TRUE;
3191
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003192 /* Use POSIX compatibility when $VIM_POSIX is set. */
3193 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003194 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003195 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003196 set_string_default("shm", (char_u *)"A");
3197 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003198
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 /*
3200 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003201 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003203 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003204#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003205 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003207 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208# endif
3209#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003210 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211 set_string_default("sh", p);
3212
3213#ifdef FEAT_WILDIGN
3214 /*
3215 * Set the default for 'backupskip' to include environment variables for
3216 * temp files.
3217 */
3218 {
3219# ifdef UNIX
3220 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3221# else
3222 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3223# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003224 int len;
3225 garray_T ga;
3226 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227
3228 ga_init2(&ga, 1, 100);
3229 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3230 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003231 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232# ifdef UNIX
3233 if (*names[n] == NUL)
3234 p = (char_u *)"/tmp";
3235 else
3236# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003237 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 if (p != NULL && *p != NUL)
3239 {
3240 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003241 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242 if (ga_grow(&ga, len) == OK)
3243 {
3244 if (ga.ga_len > 0)
3245 STRCAT(ga.ga_data, ",");
3246 STRCAT(ga.ga_data, p);
3247 add_pathsep(ga.ga_data);
3248 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249 ga.ga_len += len;
3250 }
3251 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003252 if (mustfree)
3253 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254 }
3255 if (ga.ga_data != NULL)
3256 {
3257 set_string_default("bsk", ga.ga_data);
3258 vim_free(ga.ga_data);
3259 }
3260 }
3261#endif
3262
3263 /*
3264 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3265 */
3266 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003267 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003269#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3270 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3271#endif
3272 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003274 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003275 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276#else
3277# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003278 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003279 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003281 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282# endif
3283#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003285 opt_idx = findoption((char_u *)"maxmem");
3286 if (opt_idx >= 0)
3287 {
3288#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003289 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3290 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003291#endif
3292 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3293 }
3294 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295 }
3296
3297#ifdef FEAT_GUI_W32
3298 /* force 'shortname' for Win32s */
3299 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003300 {
3301 opt_idx = findoption((char_u *)"shortname");
3302 if (opt_idx >= 0)
3303 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3304 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305#endif
3306
3307#ifdef FEAT_SEARCHPATH
3308 {
3309 char_u *cdpath;
3310 char_u *buf;
3311 int i;
3312 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003313 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314
3315 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003316 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317 if (cdpath != NULL)
3318 {
3319 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3320 if (buf != NULL)
3321 {
3322 buf[0] = ','; /* start with ",", current dir first */
3323 j = 1;
3324 for (i = 0; cdpath[i] != NUL; ++i)
3325 {
3326 if (vim_ispathlistsep(cdpath[i]))
3327 buf[j++] = ',';
3328 else
3329 {
3330 if (cdpath[i] == ' ' || cdpath[i] == ',')
3331 buf[j++] = '\\';
3332 buf[j++] = cdpath[i];
3333 }
3334 }
3335 buf[j] = NUL;
3336 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003337 if (opt_idx >= 0)
3338 {
3339 options[opt_idx].def_val[VI_DEFAULT] = buf;
3340 options[opt_idx].flags |= P_DEF_ALLOCED;
3341 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003342 else
3343 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003345 if (mustfree)
3346 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 }
3348 }
3349#endif
3350
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003351#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352 /* Set print encoding on platforms that don't default to latin1 */
3353 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003354# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355 (char_u *)"cp1252"
3356# else
3357# ifdef VMS
3358 (char_u *)"dec-mcs"
3359# else
3360# ifdef EBCDIC
3361 (char_u *)"ebcdic-uk"
3362# else
3363# ifdef MAC
3364 (char_u *)"mac-roman"
3365# else /* HPUX */
3366 (char_u *)"hp-roman8"
3367# endif
3368# endif
3369# endif
3370# endif
3371 );
3372#endif
3373
3374#ifdef FEAT_POSTSCRIPT
3375 /* 'printexpr' must be allocated to be able to evaluate it. */
3376 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003377# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003378 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003379# else
3380# ifdef VMS
3381 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3382
3383# else
3384 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3385# endif
3386# endif
3387 );
3388#endif
3389
3390 /*
3391 * Set all the options (except the terminal options) to their default
3392 * value. Also set the global value for local options.
3393 */
3394 set_options_default(0);
3395
3396#ifdef FEAT_GUI
3397 if (found_reverse_arg)
3398 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3399#endif
3400
3401 curbuf->b_p_initialized = TRUE;
3402 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003403 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 check_buf_options(curbuf);
3405 check_win_options(curwin);
3406 check_options();
3407
3408 /* Must be before option_expand(), because that one needs vim_isIDc() */
3409 didset_options();
3410
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003411#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003412 /* Use the current chartab for the generic chartab. This is not in
3413 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003414 init_spell_chartab();
3415#endif
3416
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417 /*
3418 * Expand environment variables and things like "~" for the defaults.
3419 * If option_expand() returns non-NULL the variable is expanded. This can
3420 * only happen for non-indirect options.
3421 * Also set the default to the expanded value, so ":set" does not list
3422 * them.
3423 * Don't set the P_ALLOCED flag, because we don't want to free the
3424 * default.
3425 */
3426 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3427 {
3428 if ((options[opt_idx].flags & P_GETTEXT)
3429 && options[opt_idx].var != NULL)
3430 p = (char_u *)_(*(char **)options[opt_idx].var);
3431 else
3432 p = option_expand(opt_idx, NULL);
3433 if (p != NULL && (p = vim_strsave(p)) != NULL)
3434 {
3435 *(char_u **)options[opt_idx].var = p;
3436 /* VIMEXP
3437 * Defaults for all expanded options are currently the same for Vi
3438 * and Vim. When this changes, add some code here! Also need to
3439 * split P_DEF_ALLOCED in two.
3440 */
3441 if (options[opt_idx].flags & P_DEF_ALLOCED)
3442 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3443 options[opt_idx].def_val[VI_DEFAULT] = p;
3444 options[opt_idx].flags |= P_DEF_ALLOCED;
3445 }
3446 }
3447
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 save_file_ff(curbuf); /* Buffer is unchanged */
3449
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450#if defined(FEAT_ARABIC)
3451 /* Detect use of mlterm.
3452 * Mlterm is a terminal emulator akin to xterm that has some special
3453 * abilities (bidi namely).
3454 * NOTE: mlterm's author is being asked to 'set' a variable
3455 * instead of an environment variable due to inheritance.
3456 */
3457 if (mch_getenv((char_u *)"MLTERM") != NULL)
3458 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3459#endif
3460
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003461 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462
3463#ifdef FEAT_MBYTE
3464# if defined(WIN3264) && defined(FEAT_GETTEXT)
3465 /*
3466 * If $LANG isn't set, try to get a good value for it. This makes the
3467 * right language be used automatically. Don't do this for English.
3468 */
3469 if (mch_getenv((char_u *)"LANG") == NULL)
3470 {
3471 char buf[20];
3472
3473 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3474 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3475 * only the first two. */
3476 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3477 (LPTSTR)buf, 20);
3478 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3479 {
3480 /* There are a few exceptions (probably more) */
3481 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3482 STRCPY(buf, "zh_TW");
3483 else if (STRNICMP(buf, "chs", 3) == 0
3484 || STRNICMP(buf, "zhc", 3) == 0)
3485 STRCPY(buf, "zh_CN");
3486 else if (STRNICMP(buf, "jp", 2) == 0)
3487 STRCPY(buf, "ja");
3488 else
3489 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003490 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 }
3492 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003493# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003494# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003495 /* Moved to os_mac_conv.c to avoid dependency problems. */
3496 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003497# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498# endif
3499
3500 /* enc_locale() will try to find the encoding of the current locale. */
3501 p = enc_locale();
3502 if (p != NULL)
3503 {
3504 char_u *save_enc;
3505
3506 /* Try setting 'encoding' and check if the value is valid.
3507 * If not, go back to the default "latin1". */
3508 save_enc = p_enc;
3509 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003510 if (STRCMP(p_enc, "gb18030") == 0)
3511 {
3512 /* We don't support "gb18030", but "cp936" is a good substitute
3513 * for practical purposes, thus use that. It's not an alias to
3514 * still support conversion between gb18030 and utf-8. */
3515 p_enc = vim_strsave((char_u *)"cp936");
3516 vim_free(p);
3517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003518 if (mb_init() == NULL)
3519 {
3520 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003521 if (opt_idx >= 0)
3522 {
3523 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3524 options[opt_idx].flags |= P_DEF_ALLOCED;
3525 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003527#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003528 if (STRCMP(p_enc, "latin1") == 0
3529# ifdef FEAT_MBYTE
3530 || enc_utf8
3531# endif
3532 )
3533 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003534 /* Adjust the default for 'isprint' and 'iskeyword' to match
3535 * latin1. Also set the defaults for when 'nocompatible' is
3536 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003537 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003538 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003539 set_string_option_direct((char_u *)"isk", -1,
3540 ISK_LATIN1, OPT_FREE, SID_NONE);
3541 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003542 if (opt_idx >= 0)
3543 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003544 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003545 if (opt_idx >= 0)
3546 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003547 (void)init_chartab();
3548 }
3549#endif
3550
Bram Moolenaar071d4272004-06-13 20:20:40 +00003551# if defined(WIN3264) && !defined(FEAT_GUI)
3552 /* Win32 console: When GetACP() returns a different value from
3553 * GetConsoleCP() set 'termencoding'. */
3554 if (GetACP() != GetConsoleCP())
3555 {
3556 char buf[50];
3557
3558 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3559 p_tenc = vim_strsave((char_u *)buf);
3560 if (p_tenc != NULL)
3561 {
3562 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003563 if (opt_idx >= 0)
3564 {
3565 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3566 options[opt_idx].flags |= P_DEF_ALLOCED;
3567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003568 convert_setup(&input_conv, p_tenc, p_enc);
3569 convert_setup(&output_conv, p_enc, p_tenc);
3570 }
3571 else
3572 p_tenc = empty_option;
3573 }
3574# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003575# if defined(WIN3264) && defined(FEAT_MBYTE)
3576 /* $HOME may have characters in active code page. */
3577 init_homedir();
3578# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003579 }
3580 else
3581 {
3582 vim_free(p_enc);
3583 p_enc = save_enc;
3584 }
3585 }
3586#endif
3587
3588#ifdef FEAT_MULTI_LANG
3589 /* Set the default for 'helplang'. */
3590 set_helplang_default(get_mess_lang());
3591#endif
3592}
3593
3594/*
3595 * Set an option to its default value.
3596 * This does not take care of side effects!
3597 */
3598 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003599set_option_default(
3600 int opt_idx,
3601 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3602 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603{
3604 char_u *varp; /* pointer to variable for current option */
3605 int dvi; /* index in def_val[] */
3606 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003607 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3609
3610 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3611 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003612 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003613 {
3614 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3615 if (flags & P_STRING)
3616 {
3617 /* Use set_string_option_direct() for local options to handle
3618 * freeing and allocating the value. */
3619 if (options[opt_idx].indir != PV_NONE)
3620 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003621 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 else
3623 {
3624 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3625 free_string_option(*(char_u **)(varp));
3626 *(char_u **)varp = options[opt_idx].def_val[dvi];
3627 options[opt_idx].flags &= ~P_ALLOCED;
3628 }
3629 }
3630 else if (flags & P_NUM)
3631 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003632 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003633 win_comp_scroll(curwin);
3634 else
3635 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003636 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003637 /* May also set global value for local option. */
3638 if (both)
3639 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3640 *(long *)varp;
3641 }
3642 }
3643 else /* P_BOOL */
3644 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003645 /* the cast to long is required for Manx C, long_i is needed for
3646 * MSVC */
3647 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003648#ifdef UNIX
3649 /* 'modeline' defaults to off for root */
3650 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3651 *(int *)varp = FALSE;
3652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653 /* May also set global value for local option. */
3654 if (both)
3655 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3656 *(int *)varp;
3657 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003658
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003659 /* The default value is not insecure. */
3660 flagsp = insecure_flag(opt_idx, opt_flags);
3661 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662 }
3663
3664#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003665 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003666#endif
3667}
3668
3669/*
3670 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003671 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003672 */
3673 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003674set_options_default(
3675 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676{
3677 int i;
3678#ifdef FEAT_WINDOWS
3679 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003680 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681#endif
3682
3683 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003684 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003685#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003686 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003687 || (TRUE
3688# if defined(FEAT_MBYTE)
3689 && options[i].var != (char_u *)&p_enc
3690# endif
3691# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003692 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003693 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003694# endif
3695 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003696#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003697 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698 set_option_default(i, opt_flags, p_cp);
3699
3700#ifdef FEAT_WINDOWS
3701 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003702 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703 win_comp_scroll(wp);
3704#else
3705 win_comp_scroll(curwin);
3706#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003707#ifdef FEAT_CINDENT
3708 parse_cino(curbuf);
3709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710}
3711
3712/*
3713 * Set the Vi-default value of a string option.
3714 * Used for 'sh', 'backupskip' and 'term'.
3715 */
3716 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003717set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718{
3719 char_u *p;
3720 int opt_idx;
3721
3722 p = vim_strsave(val);
3723 if (p != NULL) /* we don't want a NULL */
3724 {
3725 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003726 if (opt_idx >= 0)
3727 {
3728 if (options[opt_idx].flags & P_DEF_ALLOCED)
3729 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3730 options[opt_idx].def_val[VI_DEFAULT] = p;
3731 options[opt_idx].flags |= P_DEF_ALLOCED;
3732 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 }
3734}
3735
3736/*
3737 * Set the Vi-default value of a number option.
3738 * Used for 'lines' and 'columns'.
3739 */
3740 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003741set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003743 int opt_idx;
3744
3745 opt_idx = findoption((char_u *)name);
3746 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003747 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748}
3749
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003750#if defined(EXITFREE) || defined(PROTO)
3751/*
3752 * Free all options.
3753 */
3754 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003755free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003756{
3757 int i;
3758
3759 for (i = 0; !istermoption(&options[i]); i++)
3760 {
3761 if (options[i].indir == PV_NONE)
3762 {
3763 /* global option: free value and default value. */
3764 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3765 free_string_option(*(char_u **)options[i].var);
3766 if (options[i].flags & P_DEF_ALLOCED)
3767 free_string_option(options[i].def_val[VI_DEFAULT]);
3768 }
3769 else if (options[i].var != VAR_WIN
3770 && (options[i].flags & P_STRING))
3771 /* buffer-local option: free global value */
3772 free_string_option(*(char_u **)options[i].var);
3773 }
3774}
3775#endif
3776
3777
Bram Moolenaar071d4272004-06-13 20:20:40 +00003778/*
3779 * Initialize the options, part two: After getting Rows and Columns and
3780 * setting 'term'.
3781 */
3782 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003783set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003784{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003785 int idx;
3786
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 /*
3788 * 'scroll' defaults to half the window height. Note that this default is
3789 * wrong when the window height changes.
3790 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003791 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003792 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003793 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003794 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 comp_col();
3796
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003797 /*
3798 * 'window' is only for backwards compatibility with Vi.
3799 * Default is Rows - 1.
3800 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003801 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003802 p_window = Rows - 1;
3803 set_number_default("window", Rows - 1);
3804
Bram Moolenaarf740b292006-02-16 22:11:02 +00003805 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003806#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003807 /*
3808 * If 'background' wasn't set by the user, try guessing the value,
3809 * depending on the terminal name. Only need to check for terminals
3810 * with a dark background, that can handle color.
3811 */
3812 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003813 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3814 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003816 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003817 /* don't mark it as set, when starting the GUI it may be
3818 * changed again */
3819 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 }
3821#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003822
3823#ifdef CURSOR_SHAPE
3824 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3825#endif
3826#ifdef FEAT_MOUSESHAPE
3827 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3828#endif
3829#ifdef FEAT_PRINTER
3830 (void)parse_printoptions(); /* parse 'printoptions' default value */
3831#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003832}
3833
3834/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003835 * Return "dark" or "light" depending on the kind of terminal.
3836 * This is just guessing! Recognized are:
3837 * "linux" Linux console
3838 * "screen.linux" Linux console with screen
3839 * "cygwin" Cygwin shell
3840 * "putty" Putty program
3841 * We also check the COLORFGBG environment variable, which is set by
3842 * rxvt and derivatives. This variable contains either two or three
3843 * values separated by semicolons; we want the last value in either
3844 * case. If this value is 0-6 or 8, our background is dark.
3845 */
3846 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003847term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003848{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003849#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003850 /* DOS console nearly always black */
3851 return (char_u *)"dark";
3852#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003853 char_u *p;
3854
Bram Moolenaarf740b292006-02-16 22:11:02 +00003855 if (STRCMP(T_NAME, "linux") == 0
3856 || STRCMP(T_NAME, "screen.linux") == 0
3857 || STRCMP(T_NAME, "cygwin") == 0
3858 || STRCMP(T_NAME, "putty") == 0
3859 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3860 && (p = vim_strrchr(p, ';')) != NULL
3861 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3862 && p[2] == NUL))
3863 return (char_u *)"dark";
3864 return (char_u *)"light";
3865#endif
3866}
3867
3868/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 * Initialize the options, part three: After reading the .vimrc
3870 */
3871 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003872set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003874#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875/*
3876 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3877 * This is done after other initializations, where 'shell' might have been
3878 * set, but only if they have not been set before.
3879 */
3880 char_u *p;
3881 int idx_srr;
3882 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003883# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 int idx_sp;
3885 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003886# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887
3888 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003889 if (idx_srr < 0)
3890 do_srr = FALSE;
3891 else
3892 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003893# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003895 if (idx_sp < 0)
3896 do_sp = FALSE;
3897 else
3898 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003899# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003900 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 if (p != NULL)
3902 {
3903 /*
3904 * Default for p_sp is "| tee", for p_srr is ">".
3905 * For known shells it is changed here to include stderr.
3906 */
3907 if ( fnamecmp(p, "csh") == 0
3908 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003909# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 || fnamecmp(p, "csh.exe") == 0
3911 || fnamecmp(p, "tcsh.exe") == 0
3912# endif
3913 )
3914 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003915# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 if (do_sp)
3917 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003918# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003920# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003921 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003922# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3924 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003925# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926 if (do_srr)
3927 {
3928 p_srr = (char_u *)">&";
3929 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3930 }
3931 }
3932 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003933 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 if ( fnamecmp(p, "sh") == 0
3935 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003936 || fnamecmp(p, "mksh") == 0
3937 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003939 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003941 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003942# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 || fnamecmp(p, "cmd") == 0
3944 || fnamecmp(p, "sh.exe") == 0
3945 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003946 || fnamecmp(p, "mksh.exe") == 0
3947 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003949 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 || fnamecmp(p, "bash.exe") == 0
3951 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003953 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003955# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 if (do_sp)
3957 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003958# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003960# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003962# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3964 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003965# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 if (do_srr)
3967 {
3968 p_srr = (char_u *)">%s 2>&1";
3969 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3970 }
3971 }
3972 vim_free(p);
3973 }
3974#endif
3975
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003976#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003978 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3979 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003980 * This is done after other initializations, where 'shell' might have been
3981 * set, but only if they have not been set before. Default for p_shcf is
3982 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003983 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003985 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986 {
3987 int idx3;
3988
3989 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003990 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 {
3992 p_shcf = (char_u *)"-c";
3993 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3994 }
3995
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003996# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003997 /* Somehow Win32 requires the quotes around the redirection too */
3998 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003999 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 {
4001 p_sxq = (char_u *)"\"";
4002 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4003 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004004# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004006 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007 {
4008 p_shq = (char_u *)"\"";
4009 options[idx3].def_val[VI_DEFAULT] = p_shq;
4010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011# endif
4012 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004013 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4014 {
4015 int idx3;
4016
4017 /*
4018 * cmd.exe on Windows will strip the first and last double quote given
4019 * on the command line, e.g. most of the time things like:
4020 * cmd /c "my path/to/echo" "my args to echo"
4021 * become:
4022 * my path/to/echo" "my args to echo
4023 * when executed.
4024 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004025 * To avoid this, set shellxquote to surround the command in
4026 * parenthesis. This appears to make most commands work, without
4027 * breaking commands that worked previously, such as
4028 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004029 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004030 idx3 = findoption((char_u *)"sxq");
4031 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4032 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004033 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004034 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4035 }
4036
Bram Moolenaara64ba222012-02-12 23:23:31 +01004037 idx3 = findoption((char_u *)"shcf");
4038 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4039 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004040 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004041 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4042 }
4043 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044#endif
4045
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004046 if (bufempty())
4047 {
4048 int idx_ffs = findoption((char_u *)"ffs");
4049
4050 /* Apply the first entry of 'fileformats' to the initial buffer. */
4051 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4052 set_fileformat(default_fileformat(), OPT_LOCAL);
4053 }
4054
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055#ifdef FEAT_TITLE
4056 set_title_defaults();
4057#endif
4058}
4059
4060#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4061/*
4062 * When 'helplang' is still at its default value, set it to "lang".
4063 * Only the first two characters of "lang" are used.
4064 */
4065 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004066set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067{
4068 int idx;
4069
4070 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4071 return;
4072 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004073 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 {
4075 if (options[idx].flags & P_ALLOCED)
4076 free_string_option(p_hlg);
4077 p_hlg = vim_strsave(lang);
4078 if (p_hlg == NULL)
4079 p_hlg = empty_option;
4080 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004081 {
4082 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4083 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4084 {
4085 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4086 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004089 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 options[idx].flags |= P_ALLOCED;
4091 }
4092}
4093#endif
4094
4095#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004096static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097
4098 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004099gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100{
4101 if (gui_get_lightness(gui.back_pixel) < 127)
4102 return (char_u *)"dark";
4103 return (char_u *)"light";
4104}
4105
4106/*
4107 * Option initializations that can only be done after opening the GUI window.
4108 */
4109 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004110init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111{
4112 /* Set the 'background' option according to the lightness of the
4113 * background color, unless the user has set it already. */
4114 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4115 {
4116 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4117 highlight_changed();
4118 }
4119}
4120#endif
4121
4122#ifdef FEAT_TITLE
4123/*
4124 * 'title' and 'icon' only default to true if they have not been set or reset
4125 * in .vimrc and we can read the old value.
4126 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4127 * they can be reset. This reduces startup time when using X on a remote
4128 * machine.
4129 */
4130 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004131set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132{
4133 int idx1;
4134 long val;
4135
4136 /*
4137 * If GUI is (going to be) used, we can always set the window title and
4138 * icon name. Saves a bit of time, because the X11 display server does
4139 * not need to be contacted.
4140 */
4141 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004142 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 {
4144#ifdef FEAT_GUI
4145 if (gui.starting || gui.in_use)
4146 val = TRUE;
4147 else
4148#endif
4149 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004150 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 p_title = val;
4152 }
4153 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004154 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 {
4156#ifdef FEAT_GUI
4157 if (gui.starting || gui.in_use)
4158 val = TRUE;
4159 else
4160#endif
4161 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004162 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 p_icon = val;
4164 }
4165}
4166#endif
4167
4168/*
4169 * Parse 'arg' for option settings.
4170 *
4171 * 'arg' may be IObuff, but only when no errors can be present and option
4172 * does not need to be expanded with option_expand().
4173 * "opt_flags":
4174 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004175 * OPT_GLOBAL for ":setglobal"
4176 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004178 * OPT_WINONLY to only set window-local options
4179 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180 *
4181 * returns FAIL if an error is detected, OK otherwise
4182 */
4183 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004184do_set(
4185 char_u *arg, /* option string (may be written to!) */
4186 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187{
4188 int opt_idx;
4189 char_u *errmsg;
4190 char_u errbuf[80];
4191 char_u *startarg;
4192 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4193 int nextchar; /* next non-white char after option name */
4194 int afterchar; /* character just after option name */
4195 int len;
4196 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004197 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004198 int key;
4199 long_u flags; /* flags for current option */
4200 char_u *varp = NULL; /* pointer to variable for current option */
4201 int did_show = FALSE; /* already showed one value */
4202 int adding; /* "opt+=arg" */
4203 int prepending; /* "opt^=arg" */
4204 int removing; /* "opt-=arg" */
4205 int cp_val = 0;
4206 char_u key_name[2];
4207
4208 if (*arg == NUL)
4209 {
4210 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004211 did_show = TRUE;
4212 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004213 }
4214
4215 while (*arg != NUL) /* loop to process all options */
4216 {
4217 errmsg = NULL;
4218 startarg = arg; /* remember for error message */
4219
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004220 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4221 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 {
4223 /*
4224 * ":set all" show all options.
4225 * ":set all&" set all options to their default value.
4226 */
4227 arg += 3;
4228 if (*arg == '&')
4229 {
4230 ++arg;
4231 /* Only for :set command set global value of local options. */
4232 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004233 didset_options();
4234 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004235 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 }
4237 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004238 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004239 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004240 did_show = TRUE;
4241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004243 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004244 {
4245 showoptions(2, opt_flags);
4246 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004247 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248 arg += 7;
4249 }
4250 else
4251 {
4252 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004253 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004254 {
4255 prefix = 0;
4256 arg += 2;
4257 }
4258 else if (STRNCMP(arg, "inv", 3) == 0)
4259 {
4260 prefix = 2;
4261 arg += 3;
4262 }
4263
4264 /* find end of name */
4265 key = 0;
4266 if (*arg == '<')
4267 {
4268 nextchar = 0;
4269 opt_idx = -1;
4270 /* look out for <t_>;> */
4271 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4272 len = 5;
4273 else
4274 {
4275 len = 1;
4276 while (arg[len] != NUL && arg[len] != '>')
4277 ++len;
4278 }
4279 if (arg[len] != '>')
4280 {
4281 errmsg = e_invarg;
4282 goto skip;
4283 }
4284 arg[len] = NUL; /* put NUL after name */
4285 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4286 opt_idx = findoption(arg + 1);
4287 arg[len++] = '>'; /* restore '>' */
4288 if (opt_idx == -1)
4289 key = find_key_option(arg + 1);
4290 }
4291 else
4292 {
4293 len = 0;
4294 /*
4295 * The two characters after "t_" may not be alphanumeric.
4296 */
4297 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4298 len = 4;
4299 else
4300 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4301 ++len;
4302 nextchar = arg[len];
4303 arg[len] = NUL; /* put NUL after name */
4304 opt_idx = findoption(arg);
4305 arg[len] = nextchar; /* restore nextchar */
4306 if (opt_idx == -1)
4307 key = find_key_option(arg);
4308 }
4309
4310 /* remember character after option name */
4311 afterchar = arg[len];
4312
4313 /* skip white space, allow ":set ai ?" */
4314 while (vim_iswhite(arg[len]))
4315 ++len;
4316
4317 adding = FALSE;
4318 prepending = FALSE;
4319 removing = FALSE;
4320 if (arg[len] != NUL && arg[len + 1] == '=')
4321 {
4322 if (arg[len] == '+')
4323 {
4324 adding = TRUE; /* "+=" */
4325 ++len;
4326 }
4327 else if (arg[len] == '^')
4328 {
4329 prepending = TRUE; /* "^=" */
4330 ++len;
4331 }
4332 else if (arg[len] == '-')
4333 {
4334 removing = TRUE; /* "-=" */
4335 ++len;
4336 }
4337 }
4338 nextchar = arg[len];
4339
4340 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4341 {
4342 errmsg = (char_u *)N_("E518: Unknown option");
4343 goto skip;
4344 }
4345
4346 if (opt_idx >= 0)
4347 {
4348 if (options[opt_idx].var == NULL) /* hidden option: skip */
4349 {
4350 /* Only give an error message when requesting the value of
4351 * a hidden option, ignore setting it. */
4352 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4353 && (!(options[opt_idx].flags & P_BOOL)
4354 || nextchar == '?'))
4355 errmsg = (char_u *)N_("E519: Option not supported");
4356 goto skip;
4357 }
4358
4359 flags = options[opt_idx].flags;
4360 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4361 }
4362 else
4363 {
4364 flags = P_STRING;
4365 if (key < 0)
4366 {
4367 key_name[0] = KEY2TERMCAP0(key);
4368 key_name[1] = KEY2TERMCAP1(key);
4369 }
4370 else
4371 {
4372 key_name[0] = KS_KEY;
4373 key_name[1] = (key & 0xff);
4374 }
4375 }
4376
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004377 /* Skip all options that are not window-local (used when showing
4378 * an already loaded buffer in a window). */
4379 if ((opt_flags & OPT_WINONLY)
4380 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4381 goto skip;
4382
Bram Moolenaara3227e22006-03-08 21:32:40 +00004383 /* Skip all options that are window-local (used for :vimgrep). */
4384 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4385 && options[opt_idx].var == VAR_WIN)
4386 goto skip;
4387
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004388 /* Disallow changing some options from modelines. */
4389 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004390 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004391 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004392 {
4393 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4394 goto skip;
4395 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004396#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004397 /* In diff mode some options are overruled. This avoids that
4398 * 'foldmethod' becomes "marker" instead of "diff" and that
4399 * "wrap" gets set. */
4400 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004401 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004402 && (options[opt_idx].indir == PV_FDM
4403 || options[opt_idx].indir == PV_WRAP))
4404 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004406 }
4407
4408#ifdef HAVE_SANDBOX
4409 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004410 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 {
4412 errmsg = (char_u *)_(e_sandbox);
4413 goto skip;
4414 }
4415#endif
4416
4417 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4418 {
4419 arg += len;
4420 cp_val = p_cp;
4421 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4422 {
4423 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4424 {
4425 cp_val = FALSE;
4426 arg += 3;
4427 }
4428 else /* "opt&vi": set to Vi default */
4429 {
4430 cp_val = TRUE;
4431 arg += 2;
4432 }
4433 }
4434 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4435 && arg[1] != NUL && !vim_iswhite(arg[1]))
4436 {
4437 errmsg = e_trailing;
4438 goto skip;
4439 }
4440 }
4441
4442 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004443 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4444 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445 */
4446 if (nextchar == '?'
4447 || (prefix == 1
4448 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4449 && !(flags & P_BOOL)))
4450 {
4451 /*
4452 * print value
4453 */
4454 if (did_show)
4455 msg_putchar('\n'); /* cursor below last one */
4456 else
4457 {
4458 gotocmdline(TRUE); /* cursor at status line */
4459 did_show = TRUE; /* remember that we did a line */
4460 }
4461 if (opt_idx >= 0)
4462 {
4463 showoneopt(&options[opt_idx], opt_flags);
4464#ifdef FEAT_EVAL
4465 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004466 {
4467 /* Mention where the option was last set. */
4468 if (varp == options[opt_idx].var)
4469 last_set_msg(options[opt_idx].scriptID);
4470 else if ((int)options[opt_idx].indir & PV_WIN)
4471 last_set_msg(curwin->w_p_scriptID[
4472 (int)options[opt_idx].indir & PV_MASK]);
4473 else if ((int)options[opt_idx].indir & PV_BUF)
4474 last_set_msg(curbuf->b_p_scriptID[
4475 (int)options[opt_idx].indir & PV_MASK]);
4476 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004477#endif
4478 }
4479 else
4480 {
4481 char_u *p;
4482
4483 p = find_termcode(key_name);
4484 if (p == NULL)
4485 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004486 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004487 goto skip;
4488 }
4489 else
4490 (void)show_one_termcode(key_name, p, TRUE);
4491 }
4492 if (nextchar != '?'
4493 && nextchar != NUL && !vim_iswhite(afterchar))
4494 errmsg = e_trailing;
4495 }
4496 else
4497 {
4498 if (flags & P_BOOL) /* boolean */
4499 {
4500 if (nextchar == '=' || nextchar == ':')
4501 {
4502 errmsg = e_invarg;
4503 goto skip;
4504 }
4505
4506 /*
4507 * ":set opt!": invert
4508 * ":set opt&": reset to default value
4509 * ":set opt<": reset to global value
4510 */
4511 if (nextchar == '!')
4512 value = *(int *)(varp) ^ 1;
4513 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004514 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004515 ((flags & P_VI_DEF) || cp_val)
4516 ? VI_DEFAULT : VIM_DEFAULT];
4517 else if (nextchar == '<')
4518 {
4519 /* For 'autoread' -1 means to use global value. */
4520 if ((int *)varp == &curbuf->b_p_ar
4521 && opt_flags == OPT_LOCAL)
4522 value = -1;
4523 else
4524 value = *(int *)get_varp_scope(&(options[opt_idx]),
4525 OPT_GLOBAL);
4526 }
4527 else
4528 {
4529 /*
4530 * ":set invopt": invert
4531 * ":set opt" or ":set noopt": set or reset
4532 */
4533 if (nextchar != NUL && !vim_iswhite(afterchar))
4534 {
4535 errmsg = e_trailing;
4536 goto skip;
4537 }
4538 if (prefix == 2) /* inv */
4539 value = *(int *)(varp) ^ 1;
4540 else
4541 value = prefix;
4542 }
4543
4544 errmsg = set_bool_option(opt_idx, varp, (int)value,
4545 opt_flags);
4546 }
4547 else /* numeric or string */
4548 {
4549 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4550 || prefix != 1)
4551 {
4552 errmsg = e_invarg;
4553 goto skip;
4554 }
4555
4556 if (flags & P_NUM) /* numeric */
4557 {
4558 /*
4559 * Different ways to set a number option:
4560 * & set to default value
4561 * < set to global value
4562 * <xx> accept special key codes for 'wildchar'
4563 * c accept any non-digit for 'wildchar'
4564 * [-]0-9 set number
4565 * other error
4566 */
4567 ++arg;
4568 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004569 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 ((flags & P_VI_DEF) || cp_val)
4571 ? VI_DEFAULT : VIM_DEFAULT];
4572 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004573 {
4574 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4575 * use the global value. */
4576 if ((long *)varp == &curbuf->b_p_ul
4577 && opt_flags == OPT_LOCAL)
4578 value = NO_LOCAL_UNDOLEVEL;
4579 else
4580 value = *(long *)get_varp_scope(
4581 &(options[opt_idx]), OPT_GLOBAL);
4582 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004583 else if (((long *)varp == &p_wc
4584 || (long *)varp == &p_wcm)
4585 && (*arg == '<'
4586 || *arg == '^'
4587 || ((!arg[1] || vim_iswhite(arg[1]))
4588 && !VIM_ISDIGIT(*arg))))
4589 {
4590 value = string_to_key(arg);
4591 if (value == 0 && (long *)varp != &p_wcm)
4592 {
4593 errmsg = e_invarg;
4594 goto skip;
4595 }
4596 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004597 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4598 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004599 /* Allow negative (for 'undolevels'), octal and
4600 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004601 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4602 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004603 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4604 {
4605 errmsg = e_invarg;
4606 goto skip;
4607 }
4608 }
4609 else
4610 {
4611 errmsg = (char_u *)N_("E521: Number required after =");
4612 goto skip;
4613 }
4614
4615 if (adding)
4616 value = *(long *)varp + value;
4617 if (prepending)
4618 value = *(long *)varp * value;
4619 if (removing)
4620 value = *(long *)varp - value;
4621 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004622 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623 }
4624 else if (opt_idx >= 0) /* string */
4625 {
4626 char_u *save_arg = NULL;
4627 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004628 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004630 char_u *origval = NULL;
4631#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4632 char_u *saved_origval = NULL;
4633#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004634 unsigned newlen;
4635 int comma;
4636 int bs;
4637 int new_value_alloced; /* new string option
4638 was allocated */
4639
4640 /* When using ":set opt=val" for a global option
4641 * with a local value the local value will be
4642 * reset, use the global value here. */
4643 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004644 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004645 varp = options[opt_idx].var;
4646
4647 /* The old value is kept until we are sure that the
4648 * new value is valid. */
4649 oldval = *(char_u **)varp;
4650 if (nextchar == '&') /* set to default val */
4651 {
4652 newval = options[opt_idx].def_val[
4653 ((flags & P_VI_DEF) || cp_val)
4654 ? VI_DEFAULT : VIM_DEFAULT];
4655 if ((char_u **)varp == &p_bg)
4656 {
4657 /* guess the value of 'background' */
4658#ifdef FEAT_GUI
4659 if (gui.in_use)
4660 newval = gui_bg_default();
4661 else
4662#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004663 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004664 }
4665
4666 /* expand environment variables and ~ (since the
4667 * default value was already expanded, only
4668 * required when an environment variable was set
4669 * later */
4670 if (newval == NULL)
4671 newval = empty_option;
4672 else
4673 {
4674 s = option_expand(opt_idx, newval);
4675 if (s == NULL)
4676 s = newval;
4677 newval = vim_strsave(s);
4678 }
4679 new_value_alloced = TRUE;
4680 }
4681 else if (nextchar == '<') /* set to global val */
4682 {
4683 newval = vim_strsave(*(char_u **)get_varp_scope(
4684 &(options[opt_idx]), OPT_GLOBAL));
4685 new_value_alloced = TRUE;
4686 }
4687 else
4688 {
4689 ++arg; /* jump to after the '=' or ':' */
4690
4691 /*
4692 * Set 'keywordprg' to ":help" if an empty
4693 * value was passed to :set by the user.
4694 * Misuse errbuf[] for the resulting string.
4695 */
4696 if (varp == (char_u *)&p_kp
4697 && (*arg == NUL || *arg == ' '))
4698 {
4699 STRCPY(errbuf, ":help");
4700 save_arg = arg;
4701 arg = errbuf;
4702 }
4703 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004704 * Convert 'backspace' number to string, for
4705 * adding, prepending and removing string.
4706 */
4707 else if (varp == (char_u *)&p_bs
4708 && VIM_ISDIGIT(**(char_u **)varp))
4709 {
4710 i = getdigits((char_u **)varp);
4711 switch (i)
4712 {
4713 case 0:
4714 *(char_u **)varp = empty_option;
4715 break;
4716 case 1:
4717 *(char_u **)varp = vim_strsave(
4718 (char_u *)"indent,eol");
4719 break;
4720 case 2:
4721 *(char_u **)varp = vim_strsave(
4722 (char_u *)"indent,eol,start");
4723 break;
4724 }
4725 vim_free(oldval);
4726 oldval = *(char_u **)varp;
4727 }
4728 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004729 * Convert 'whichwrap' number to string, for
4730 * backwards compatibility with Vim 3.0.
4731 * Misuse errbuf[] for the resulting string.
4732 */
4733 else if (varp == (char_u *)&p_ww
4734 && VIM_ISDIGIT(*arg))
4735 {
4736 *errbuf = NUL;
4737 i = getdigits(&arg);
4738 if (i & 1)
4739 STRCAT(errbuf, "b,");
4740 if (i & 2)
4741 STRCAT(errbuf, "s,");
4742 if (i & 4)
4743 STRCAT(errbuf, "h,l,");
4744 if (i & 8)
4745 STRCAT(errbuf, "<,>,");
4746 if (i & 16)
4747 STRCAT(errbuf, "[,],");
4748 if (*errbuf != NUL) /* remove trailing , */
4749 errbuf[STRLEN(errbuf) - 1] = NUL;
4750 save_arg = arg;
4751 arg = errbuf;
4752 }
4753 /*
4754 * Remove '>' before 'dir' and 'bdir', for
4755 * backwards compatibility with version 3.0
4756 */
4757 else if ( *arg == '>'
4758 && (varp == (char_u *)&p_dir
4759 || varp == (char_u *)&p_bdir))
4760 {
4761 ++arg;
4762 }
4763
4764 /* When setting the local value of a global
4765 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004766 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 && (opt_flags & OPT_LOCAL))
4768 origval = *(char_u **)get_varp(
4769 &options[opt_idx]);
4770 else
4771 origval = oldval;
4772
4773 /*
4774 * Copy the new string into allocated memory.
4775 * Can't use set_string_option_direct(), because
4776 * we need to remove the backslashes.
4777 */
4778 /* get a bit too much */
4779 newlen = (unsigned)STRLEN(arg) + 1;
4780 if (adding || prepending || removing)
4781 newlen += (unsigned)STRLEN(origval) + 1;
4782 newval = alloc(newlen);
4783 if (newval == NULL) /* out of mem, don't change */
4784 break;
4785 s = newval;
4786
4787 /*
4788 * Copy the string, skip over escaped chars.
4789 * For MS-DOS and WIN32 backslashes before normal
4790 * file name characters are not removed, and keep
4791 * backslash at start, for "\\machine\path", but
4792 * do remove it for "\\\\machine\\path".
4793 * The reverse is found in ExpandOldSetting().
4794 */
4795 while (*arg && !vim_iswhite(*arg))
4796 {
4797 if (*arg == '\\' && arg[1] != NUL
4798#ifdef BACKSLASH_IN_FILENAME
4799 && !((flags & P_EXPAND)
4800 && vim_isfilec(arg[1])
4801 && (arg[1] != '\\'
4802 || (s == newval
4803 && arg[2] != '\\')))
4804#endif
4805 )
4806 ++arg; /* remove backslash */
4807#ifdef FEAT_MBYTE
4808 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004809 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004810 {
4811 /* copy multibyte char */
4812 mch_memmove(s, arg, (size_t)i);
4813 arg += i;
4814 s += i;
4815 }
4816 else
4817#endif
4818 *s++ = *arg++;
4819 }
4820 *s = NUL;
4821
4822 /*
4823 * Expand environment variables and ~.
4824 * Don't do it when adding without inserting a
4825 * comma.
4826 */
4827 if (!(adding || prepending || removing)
4828 || (flags & P_COMMA))
4829 {
4830 s = option_expand(opt_idx, newval);
4831 if (s != NULL)
4832 {
4833 vim_free(newval);
4834 newlen = (unsigned)STRLEN(s) + 1;
4835 if (adding || prepending || removing)
4836 newlen += (unsigned)STRLEN(origval) + 1;
4837 newval = alloc(newlen);
4838 if (newval == NULL)
4839 break;
4840 STRCPY(newval, s);
4841 }
4842 }
4843
4844 /* locate newval[] in origval[] when removing it
4845 * and when adding to avoid duplicates */
4846 i = 0; /* init for GCC */
4847 if (removing || (flags & P_NODUP))
4848 {
4849 i = (int)STRLEN(newval);
4850 bs = 0;
4851 for (s = origval; *s; ++s)
4852 {
4853 if ((!(flags & P_COMMA)
4854 || s == origval
4855 || (s[-1] == ',' && !(bs & 1)))
4856 && STRNCMP(s, newval, i) == 0
4857 && (!(flags & P_COMMA)
4858 || s[i] == ','
4859 || s[i] == NUL))
4860 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004861 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004862 * even number of backslashes or a single
4863 * backslash preceded by a comma before it
4864 * is recognized as a separator */
4865 if ((s > origval + 1
4866 && s[-1] == '\\'
4867 && s[-2] != ',')
4868 || (s == origval + 1
4869 && s[-1] == '\\'))
4870
Bram Moolenaar071d4272004-06-13 20:20:40 +00004871 ++bs;
4872 else
4873 bs = 0;
4874 }
4875
4876 /* do not add if already there */
4877 if ((adding || prepending) && *s)
4878 {
4879 prepending = FALSE;
4880 adding = FALSE;
4881 STRCPY(newval, origval);
4882 }
4883 }
4884
4885 /* concatenate the two strings; add a ',' if
4886 * needed */
4887 if (adding || prepending)
4888 {
4889 comma = ((flags & P_COMMA) && *origval != NUL
4890 && *newval != NUL);
4891 if (adding)
4892 {
4893 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004894 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004895 if (comma && i > 1
4896 && (flags & P_ONECOMMA) == P_ONECOMMA
4897 && origval[i - 1] == ','
4898 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004899 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004900 mch_memmove(newval + i + comma, newval,
4901 STRLEN(newval) + 1);
4902 mch_memmove(newval, origval, (size_t)i);
4903 }
4904 else
4905 {
4906 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004907 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004908 }
4909 if (comma)
4910 newval[i] = ',';
4911 }
4912
4913 /* Remove newval[] from origval[]. (Note: "i" has
4914 * been set above and is used here). */
4915 if (removing)
4916 {
4917 STRCPY(newval, origval);
4918 if (*s)
4919 {
4920 /* may need to remove a comma */
4921 if (flags & P_COMMA)
4922 {
4923 if (s == origval)
4924 {
4925 /* include comma after string */
4926 if (s[i] == ',')
4927 ++i;
4928 }
4929 else
4930 {
4931 /* include comma before string */
4932 --s;
4933 ++i;
4934 }
4935 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004936 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004937 }
4938 }
4939
4940 if (flags & P_FLAGLIST)
4941 {
4942 /* Remove flags that appear twice. */
4943 for (s = newval; *s; ++s)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004944 {
4945 /* if options have P_FLAGLIST and
4946 * P_ONECOMMA such as 'whichwrap' */
4947 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004948 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004949 if (*s != ',' && *(s + 1) == ','
4950 && vim_strchr(s + 2, *s) != NULL)
4951 {
4952 /* Remove the duplicated value and
4953 * the next comma. */
4954 STRMOVE(s, s + 2);
4955 s -= 2;
4956 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004957 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004958 else
4959 {
4960 if ((!(flags & P_COMMA) || *s != ',')
4961 && vim_strchr(s + 1, *s) != NULL)
4962 {
4963 STRMOVE(s, s + 1);
4964 --s;
4965 }
4966 }
4967 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004968 }
4969
4970 if (save_arg != NULL) /* number for 'whichwrap' */
4971 arg = save_arg;
4972 new_value_alloced = TRUE;
4973 }
4974
4975 /* Set the new value. */
4976 *(char_u **)(varp) = newval;
4977
Bram Moolenaar53744302015-07-17 17:38:22 +02004978#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004979 if (!starting
4980# ifdef FEAT_CRYPT
4981 && options[opt_idx].indir != PV_KEY
4982# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004983 && origval != NULL)
4984 /* origval may be freed by
4985 * did_set_string_option(), make a copy. */
4986 saved_origval = vim_strsave(origval);
4987#endif
4988
Bram Moolenaar071d4272004-06-13 20:20:40 +00004989 /* Handle side effects, and set the global value for
4990 * ":set" on local options. */
4991 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4992 new_value_alloced, oldval, errbuf, opt_flags);
4993
4994 /* If error detected, print the error message. */
4995 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004996 {
4997#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4998 vim_free(saved_origval);
4999#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005000 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005001 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005002#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5003 if (saved_origval != NULL)
5004 {
5005 char_u buf_type[7];
5006
5007 sprintf((char *)buf_type, "%s",
5008 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005009 set_vim_var_string(VV_OPTION_NEW,
5010 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005011 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5012 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5013 apply_autocmds(EVENT_OPTIONSET,
5014 (char_u *)options[opt_idx].fullname,
5015 NULL, FALSE, NULL);
5016 reset_v_option_vars();
5017 vim_free(saved_origval);
5018 }
5019#endif
5020
Bram Moolenaar071d4272004-06-13 20:20:40 +00005021 }
5022 else /* key code option */
5023 {
5024 char_u *p;
5025
5026 if (nextchar == '&')
5027 {
5028 if (add_termcap_entry(key_name, TRUE) == FAIL)
5029 errmsg = (char_u *)N_("E522: Not found in termcap");
5030 }
5031 else
5032 {
5033 ++arg; /* jump to after the '=' or ':' */
5034 for (p = arg; *p && !vim_iswhite(*p); ++p)
5035 if (*p == '\\' && p[1] != NUL)
5036 ++p;
5037 nextchar = *p;
5038 *p = NUL;
5039 add_termcode(key_name, arg, FALSE);
5040 *p = nextchar;
5041 }
5042 if (full_screen)
5043 ttest(FALSE);
5044 redraw_all_later(CLEAR);
5045 }
5046 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005047
Bram Moolenaar071d4272004-06-13 20:20:40 +00005048 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005049 did_set_option(opt_idx, opt_flags,
5050 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005051 }
5052
5053skip:
5054 /*
5055 * Advance to next argument.
5056 * - skip until a blank found, taking care of backslashes
5057 * - skip blanks
5058 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5059 */
5060 for (i = 0; i < 2 ; ++i)
5061 {
5062 while (*arg != NUL && !vim_iswhite(*arg))
5063 if (*arg++ == '\\' && *arg != NUL)
5064 ++arg;
5065 arg = skipwhite(arg);
5066 if (*arg != '=')
5067 break;
5068 }
5069 }
5070
5071 if (errmsg != NULL)
5072 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005073 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005074 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005075 if (i + (arg - startarg) < IOSIZE)
5076 {
5077 /* append the argument with the error */
5078 STRCAT(IObuff, ": ");
5079 mch_memmove(IObuff + i, startarg, (arg - startarg));
5080 IObuff[i + (arg - startarg)] = NUL;
5081 }
5082 /* make sure all characters are printable */
5083 trans_characters(IObuff, IOSIZE);
5084
5085 ++no_wait_return; /* wait_return done later */
5086 emsg(IObuff); /* show error highlighted */
5087 --no_wait_return;
5088
5089 return FAIL;
5090 }
5091
5092 arg = skipwhite(arg);
5093 }
5094
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005095theend:
5096 if (silent_mode && did_show)
5097 {
5098 /* After displaying option values in silent mode. */
5099 silent_mode = FALSE;
5100 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5101 msg_putchar('\n');
5102 cursor_on(); /* msg_start() switches it off */
5103 out_flush();
5104 silent_mode = TRUE;
5105 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5106 }
5107
Bram Moolenaar071d4272004-06-13 20:20:40 +00005108 return OK;
5109}
5110
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005111/*
5112 * Call this when an option has been given a new value through a user command.
5113 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5114 */
5115 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005116did_set_option(
5117 int opt_idx,
5118 int opt_flags, /* possibly with OPT_MODELINE */
5119 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005120{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005121 long_u *p;
5122
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005123 options[opt_idx].flags |= P_WAS_SET;
5124
5125 /* When an option is set in the sandbox, from a modeline or in secure mode
5126 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005127 * flag. */
5128 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005129 if (secure
5130#ifdef HAVE_SANDBOX
5131 || sandbox != 0
5132#endif
5133 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005134 *p = *p | P_INSECURE;
5135 else if (new_value)
5136 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005137}
5138
Bram Moolenaar071d4272004-06-13 20:20:40 +00005139 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005140illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005141{
5142 if (errbuf == NULL)
5143 return (char_u *)"";
5144 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005145 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005146 return errbuf;
5147}
5148
5149/*
5150 * Convert a key name or string into a key value.
5151 * Used for 'wildchar' and 'cedit' options.
5152 */
5153 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005154string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005155{
5156 if (*arg == '<')
5157 return find_key_option(arg + 1);
5158 if (*arg == '^')
5159 return Ctrl_chr(arg[1]);
5160 return *arg;
5161}
5162
5163#ifdef FEAT_CMDWIN
5164/*
5165 * Check value of 'cedit' and set cedit_key.
5166 * Returns NULL if value is OK, error message otherwise.
5167 */
5168 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005169check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005170{
5171 int n;
5172
5173 if (*p_cedit == NUL)
5174 cedit_key = -1;
5175 else
5176 {
5177 n = string_to_key(p_cedit);
5178 if (vim_isprintc(n))
5179 return e_invarg;
5180 cedit_key = n;
5181 }
5182 return NULL;
5183}
5184#endif
5185
5186#ifdef FEAT_TITLE
5187/*
5188 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5189 * maketitle() to create and display it.
5190 * When switching the title or icon off, call mch_restore_title() to get
5191 * the old value back.
5192 */
5193 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005194did_set_title(
5195 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005196{
5197 if (starting != NO_SCREEN
5198#ifdef FEAT_GUI
5199 && !gui.starting
5200#endif
5201 )
5202 {
5203 maketitle();
5204 if (icon)
5205 {
5206 if (!p_icon)
5207 mch_restore_title(2);
5208 }
5209 else
5210 {
5211 if (!p_title)
5212 mch_restore_title(1);
5213 }
5214 }
5215}
5216#endif
5217
5218/*
5219 * set_options_bin - called when 'bin' changes value.
5220 */
5221 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005222set_options_bin(
5223 int oldval,
5224 int newval,
5225 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005226{
5227 /*
5228 * The option values that are changed when 'bin' changes are
5229 * copied when 'bin is set and restored when 'bin' is reset.
5230 */
5231 if (newval)
5232 {
5233 if (!oldval) /* switched on */
5234 {
5235 if (!(opt_flags & OPT_GLOBAL))
5236 {
5237 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5238 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5239 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5240 curbuf->b_p_et_nobin = curbuf->b_p_et;
5241 }
5242 if (!(opt_flags & OPT_LOCAL))
5243 {
5244 p_tw_nobin = p_tw;
5245 p_wm_nobin = p_wm;
5246 p_ml_nobin = p_ml;
5247 p_et_nobin = p_et;
5248 }
5249 }
5250
5251 if (!(opt_flags & OPT_GLOBAL))
5252 {
5253 curbuf->b_p_tw = 0; /* no automatic line wrap */
5254 curbuf->b_p_wm = 0; /* no automatic line wrap */
5255 curbuf->b_p_ml = 0; /* no modelines */
5256 curbuf->b_p_et = 0; /* no expandtab */
5257 }
5258 if (!(opt_flags & OPT_LOCAL))
5259 {
5260 p_tw = 0;
5261 p_wm = 0;
5262 p_ml = FALSE;
5263 p_et = FALSE;
5264 p_bin = TRUE; /* needed when called for the "-b" argument */
5265 }
5266 }
5267 else if (oldval) /* switched off */
5268 {
5269 if (!(opt_flags & OPT_GLOBAL))
5270 {
5271 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5272 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5273 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5274 curbuf->b_p_et = curbuf->b_p_et_nobin;
5275 }
5276 if (!(opt_flags & OPT_LOCAL))
5277 {
5278 p_tw = p_tw_nobin;
5279 p_wm = p_wm_nobin;
5280 p_ml = p_ml_nobin;
5281 p_et = p_et_nobin;
5282 }
5283 }
5284}
5285
5286#ifdef FEAT_VIMINFO
5287/*
5288 * Find the parameter represented by the given character (eg ', :, ", or /),
5289 * and return its associated value in the 'viminfo' string.
5290 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005291 * If the parameter is not specified in the string or there is no following
5292 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005293 */
5294 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005295get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005296{
5297 char_u *p;
5298
5299 p = find_viminfo_parameter(type);
5300 if (p != NULL && VIM_ISDIGIT(*p))
5301 return atoi((char *)p);
5302 return -1;
5303}
5304
5305/*
5306 * Find the parameter represented by the given character (eg ''', ':', '"', or
5307 * '/') in the 'viminfo' option and return a pointer to the string after it.
5308 * Return NULL if the parameter is not specified in the string.
5309 */
5310 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005311find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312{
5313 char_u *p;
5314
5315 for (p = p_viminfo; *p; ++p)
5316 {
5317 if (*p == type)
5318 return p + 1;
5319 if (*p == 'n') /* 'n' is always the last one */
5320 break;
5321 p = vim_strchr(p, ','); /* skip until next ',' */
5322 if (p == NULL) /* hit the end without finding parameter */
5323 break;
5324 }
5325 return NULL;
5326}
5327#endif
5328
5329/*
5330 * Expand environment variables for some string options.
5331 * These string options cannot be indirect!
5332 * If "val" is NULL expand the current value of the option.
5333 * Return pointer to NameBuff, or NULL when not expanded.
5334 */
5335 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005336option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337{
5338 /* if option doesn't need expansion nothing to do */
5339 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5340 return NULL;
5341
5342 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5343 * expand_env() would truncate the string. */
5344 if (val != NULL && STRLEN(val) > MAXPATHL)
5345 return NULL;
5346
5347 if (val == NULL)
5348 val = *(char_u **)options[opt_idx].var;
5349
5350 /*
5351 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5352 * Escape spaces when expanding 'tags', they are used to separate file
5353 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005354 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 */
5356 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005357 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005358#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005359 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5360#endif
5361 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5363 return NULL;
5364
5365 return NameBuff;
5366}
5367
5368/*
5369 * After setting various option values: recompute variables that depend on
5370 * option values.
5371 */
5372 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005373didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374{
5375 /* initialize the table for 'iskeyword' et.al. */
5376 (void)init_chartab();
5377
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005378#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005380#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005382 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005383#ifdef FEAT_SESSION
5384 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5385 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5386#endif
5387#ifdef FEAT_FOLDING
5388 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5389#endif
5390 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005391 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005392#ifdef FEAT_VIRTUALEDIT
5393 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5394#endif
5395#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5396 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5397#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005398#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005399 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005400 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005401 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005402 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005404#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5405 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5406#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005407#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005408 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5409#endif
5410#ifdef FEAT_CMDWIN
5411 /* set cedit_key */
5412 (void)check_cedit();
5413#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005414#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005415 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005416#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005417#ifdef FEAT_LINEBREAK
5418 /* initialize the table for 'breakat'. */
5419 fill_breakat_flags();
5420#endif
5421
5422}
5423
5424/*
5425 * More side effects of setting options.
5426 */
5427 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005428didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005429{
5430 /* Initialize the highlight_attr[] table. */
5431 (void)highlight_changed();
5432
5433 /* Parse default for 'wildmode' */
5434 check_opt_wim();
5435
5436 (void)set_chars_option(&p_lcs);
5437#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5438 /* Parse default for 'fillchars'. */
5439 (void)set_chars_option(&p_fcs);
5440#endif
5441
5442#ifdef FEAT_CLIPBOARD
5443 /* Parse default for 'clipboard' */
5444 (void)check_clipboard_option();
5445#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446}
5447
5448/*
5449 * Check for string options that are NULL (normally only termcap options).
5450 */
5451 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005452check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005453{
5454 int opt_idx;
5455
5456 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5457 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5458 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5459}
5460
5461/*
5462 * Check string options in a buffer for NULL value.
5463 */
5464 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005465check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005466{
5467#if defined(FEAT_QUICKFIX)
5468 check_string_option(&buf->b_p_bh);
5469 check_string_option(&buf->b_p_bt);
5470#endif
5471#ifdef FEAT_MBYTE
5472 check_string_option(&buf->b_p_fenc);
5473#endif
5474 check_string_option(&buf->b_p_ff);
5475#ifdef FEAT_FIND_ID
5476 check_string_option(&buf->b_p_def);
5477 check_string_option(&buf->b_p_inc);
5478# ifdef FEAT_EVAL
5479 check_string_option(&buf->b_p_inex);
5480# endif
5481#endif
5482#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5483 check_string_option(&buf->b_p_inde);
5484 check_string_option(&buf->b_p_indk);
5485#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005486#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5487 check_string_option(&buf->b_p_bexpr);
5488#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005489#if defined(FEAT_CRYPT)
5490 check_string_option(&buf->b_p_cm);
5491#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005492#if defined(FEAT_EVAL)
5493 check_string_option(&buf->b_p_fex);
5494#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495#ifdef FEAT_CRYPT
5496 check_string_option(&buf->b_p_key);
5497#endif
5498 check_string_option(&buf->b_p_kp);
5499 check_string_option(&buf->b_p_mps);
5500 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005501 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502 check_string_option(&buf->b_p_isk);
5503#ifdef FEAT_COMMENTS
5504 check_string_option(&buf->b_p_com);
5505#endif
5506#ifdef FEAT_FOLDING
5507 check_string_option(&buf->b_p_cms);
5508#endif
5509 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005510#ifdef FEAT_TEXTOBJ
5511 check_string_option(&buf->b_p_qe);
5512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513#ifdef FEAT_SYN_HL
5514 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005515 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005516#endif
5517#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005518 check_string_option(&buf->b_s.b_p_spc);
5519 check_string_option(&buf->b_s.b_p_spf);
5520 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521#endif
5522#ifdef FEAT_SEARCHPATH
5523 check_string_option(&buf->b_p_sua);
5524#endif
5525#ifdef FEAT_CINDENT
5526 check_string_option(&buf->b_p_cink);
5527 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005528 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529#endif
5530#ifdef FEAT_AUTOCMD
5531 check_string_option(&buf->b_p_ft);
5532#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5534 check_string_option(&buf->b_p_cinw);
5535#endif
5536#ifdef FEAT_INS_EXPAND
5537 check_string_option(&buf->b_p_cpt);
5538#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005539#ifdef FEAT_COMPL_FUNC
5540 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005541 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005543#ifdef FEAT_KEYMAP
5544 check_string_option(&buf->b_p_keymap);
5545#endif
5546#ifdef FEAT_QUICKFIX
5547 check_string_option(&buf->b_p_gp);
5548 check_string_option(&buf->b_p_mp);
5549 check_string_option(&buf->b_p_efm);
5550#endif
5551 check_string_option(&buf->b_p_ep);
5552 check_string_option(&buf->b_p_path);
5553 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005554 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555#ifdef FEAT_INS_EXPAND
5556 check_string_option(&buf->b_p_dict);
5557 check_string_option(&buf->b_p_tsr);
5558#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005559#ifdef FEAT_LISP
5560 check_string_option(&buf->b_p_lw);
5561#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005562 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005563}
5564
5565/*
5566 * Free the string allocated for an option.
5567 * Checks for the string being empty_option. This may happen if we're out of
5568 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5569 * check_options().
5570 * Does NOT check for P_ALLOCED flag!
5571 */
5572 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005573free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005574{
5575 if (p != empty_option)
5576 vim_free(p);
5577}
5578
5579 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005580clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581{
5582 if (*pp != empty_option)
5583 vim_free(*pp);
5584 *pp = empty_option;
5585}
5586
5587 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005588check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589{
5590 if (*pp == NULL)
5591 *pp = empty_option;
5592}
5593
5594/*
5595 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5596 */
5597 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005598set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005599{
5600 int opt_idx;
5601
5602 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5603 if (options[opt_idx].var == (char_u *)p)
5604 {
5605 options[opt_idx].flags |= P_ALLOCED;
5606 return;
5607 }
5608 return; /* cannot happen: didn't find it! */
5609}
5610
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005611#if defined(FEAT_EVAL) || defined(PROTO)
5612/*
5613 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5614 * Return FALSE when it wasn't.
5615 * Return -1 for an unknown option.
5616 */
5617 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005618was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005619{
5620 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005621 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005622
5623 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005624 {
5625 flagp = insecure_flag(idx, opt_flags);
5626 return (*flagp & P_INSECURE) != 0;
5627 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005628 EMSG2(_(e_intern2), "was_set_insecurely()");
5629 return -1;
5630}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005631
5632/*
5633 * Get a pointer to the flags used for the P_INSECURE flag of option
5634 * "opt_idx". For some local options a local flags field is used.
5635 */
5636 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005637insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005638{
5639 if (opt_flags & OPT_LOCAL)
5640 switch ((int)options[opt_idx].indir)
5641 {
5642#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005643 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005644#endif
5645#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005646# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005647 case PV_FDE: return &curwin->w_p_fde_flags;
5648 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005649# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005650# ifdef FEAT_BEVAL
5651 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5652# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005653# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005654 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005655# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005656 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005657# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005658 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005659# endif
5660#endif
5661 }
5662
5663 /* Nothing special, return global flags field. */
5664 return &options[opt_idx].flags;
5665}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005666#endif
5667
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005668#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005669static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005670
5671/*
5672 * Redraw the window title and/or tab page text later.
5673 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005674static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005675{
5676 need_maketitle = TRUE;
5677# ifdef FEAT_WINDOWS
5678 redraw_tabline = TRUE;
5679# endif
5680}
5681#endif
5682
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683/*
5684 * Set a string option to a new value (without checking the effect).
5685 * The string is copied into allocated memory.
5686 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005687 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005688 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689 */
5690 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005691set_string_option_direct(
5692 char_u *name,
5693 int opt_idx,
5694 char_u *val,
5695 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5696 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697{
5698 char_u *s;
5699 char_u **varp;
5700 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005701 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702
Bram Moolenaar89d40322006-08-29 15:30:07 +00005703 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005705 idx = findoption(name);
5706 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005707 {
5708 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005709 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005711 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712 }
5713
Bram Moolenaar89d40322006-08-29 15:30:07 +00005714 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715 return;
5716
5717 s = vim_strsave(val);
5718 if (s != NULL)
5719 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005720 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005721 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005722 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005723 free_string_option(*varp);
5724 *varp = s;
5725
5726 /* For buffer/window local option may also set the global value. */
5727 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005728 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729
Bram Moolenaar89d40322006-08-29 15:30:07 +00005730 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731
5732 /* When setting both values of a global option with a local value,
5733 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005734 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735 {
5736 free_string_option(*varp);
5737 *varp = empty_option;
5738 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005739# ifdef FEAT_EVAL
5740 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005741 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005742 set_sid == 0 ? current_SID : set_sid);
5743# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005744 }
5745}
5746
5747/*
5748 * Set global value for string option when it's a local option.
5749 */
5750 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005751set_string_option_global(
5752 int opt_idx, /* option index */
5753 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754{
5755 char_u **p, *s;
5756
5757 /* the global value is always allocated */
5758 if (options[opt_idx].var == VAR_WIN)
5759 p = (char_u **)GLOBAL_WO(varp);
5760 else
5761 p = (char_u **)options[opt_idx].var;
5762 if (options[opt_idx].indir != PV_NONE
5763 && p != varp
5764 && (s = vim_strsave(*varp)) != NULL)
5765 {
5766 free_string_option(*p);
5767 *p = s;
5768 }
5769}
5770
5771/*
5772 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005773 *
5774 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005775 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005776 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005777set_string_option(
5778 int opt_idx,
5779 char_u *value,
5780 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005781{
5782 char_u *s;
5783 char_u **varp;
5784 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005785#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5786 char_u *saved_oldval = NULL;
5787#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005788 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005789
5790 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005791 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005792
5793 s = vim_strsave(value);
5794 if (s != NULL)
5795 {
5796 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5797 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005798 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005799 ? OPT_GLOBAL : OPT_LOCAL)
5800 : opt_flags);
5801 oldval = *varp;
5802 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005803
5804#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005805 if (!starting
5806# ifdef FEAT_CRYPT
5807 && options[opt_idx].indir != PV_KEY
5808# endif
5809 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005810 saved_oldval = vim_strsave(oldval);
5811#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005812 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5813 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005814 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005815
5816 /* call autocomamnd after handling side effects */
5817#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5818 if (saved_oldval != NULL)
5819 {
5820 char_u buf_type[7];
5821 sprintf((char *)buf_type, "%s",
5822 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005823 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5824 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005825 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5826 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5827 reset_v_option_vars();
5828 vim_free(saved_oldval);
5829 }
5830#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005831 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005832 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005833}
5834
5835/*
5836 * Handle string options that need some action to perform when changed.
5837 * Returns NULL for success, or an error message for an error.
5838 */
5839 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005840did_set_string_option(
5841 int opt_idx, /* index in options[] table */
5842 char_u **varp, /* pointer to the option variable */
5843 int new_value_alloced, /* new value was allocated */
5844 char_u *oldval, /* previous value of the option */
5845 char_u *errbuf, /* buffer for errors, or NULL */
5846 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847{
5848 char_u *errmsg = NULL;
5849 char_u *s, *p;
5850 int did_chartab = FALSE;
5851 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005852 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005853#ifdef FEAT_GUI
5854 /* set when changing an option that only requires a redraw in the GUI */
5855 int redraw_gui_only = FALSE;
5856#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005857
5858 /* Get the global option to compare with, otherwise we would have to check
5859 * two values for all local options. */
5860 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5861
5862 /* Disallow changing some options from secure mode */
5863 if ((secure
5864#ifdef HAVE_SANDBOX
5865 || sandbox != 0
5866#endif
5867 ) && (options[opt_idx].flags & P_SECURE))
5868 {
5869 errmsg = e_secure;
5870 }
5871
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005872 /* Check for a "normal" file name in some options. Disallow a path
5873 * separator (slash and/or backslash), wildcards and characters that are
5874 * often illegal in a file name. */
5875 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005876 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005877 {
5878 errmsg = e_invarg;
5879 }
5880
Bram Moolenaar071d4272004-06-13 20:20:40 +00005881 /* 'term' */
5882 else if (varp == &T_NAME)
5883 {
5884 if (T_NAME[0] == NUL)
5885 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5886#ifdef FEAT_GUI
5887 if (gui.in_use)
5888 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5889 else if (term_is_gui(T_NAME))
5890 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5891#endif
5892 else if (set_termname(T_NAME) == FAIL)
5893 errmsg = (char_u *)N_("E522: Not found in termcap");
5894 else
5895 /* Screen colors may have changed. */
5896 redraw_later_clear();
5897 }
5898
5899 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005900 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005902 char_u *bkc = p_bkc;
5903 unsigned int *flags = &bkc_flags;
5904
5905 if (opt_flags & OPT_LOCAL)
5906 {
5907 bkc = curbuf->b_p_bkc;
5908 flags = &curbuf->b_bkc_flags;
5909 }
5910
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005911 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5912 /* make the local value empty: use the global value */
5913 *flags = 0;
5914 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005915 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005916 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5917 errmsg = e_invarg;
5918 if ((((int)*flags & BKC_AUTO) != 0)
5919 + (((int)*flags & BKC_YES) != 0)
5920 + (((int)*flags & BKC_NO) != 0) != 1)
5921 {
5922 /* Must have exactly one of "auto", "yes" and "no". */
5923 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5924 errmsg = e_invarg;
5925 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926 }
5927 }
5928
5929 /* 'backupext' and 'patchmode' */
5930 else if (varp == &p_bex || varp == &p_pm)
5931 {
5932 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5933 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5934 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5935 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005936#ifdef FEAT_LINEBREAK
5937 /* 'breakindentopt' */
5938 else if (varp == &curwin->w_p_briopt)
5939 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005940 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005941 errmsg = e_invarg;
5942 }
5943#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944
5945 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005946 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005947 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005948 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005949 */
5950 else if ( varp == &p_isi
5951 || varp == &(curbuf->b_p_isk)
5952 || varp == &p_isp
5953 || varp == &p_isf)
5954 {
5955 if (init_chartab() == FAIL)
5956 {
5957 did_chartab = TRUE; /* need to restore it below */
5958 errmsg = e_invarg; /* error in value */
5959 }
5960 }
5961
5962 /* 'helpfile' */
5963 else if (varp == &p_hf)
5964 {
5965 /* May compute new values for $VIM and $VIMRUNTIME */
5966 if (didset_vim)
5967 {
5968 vim_setenv((char_u *)"VIM", (char_u *)"");
5969 didset_vim = FALSE;
5970 }
5971 if (didset_vimruntime)
5972 {
5973 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5974 didset_vimruntime = FALSE;
5975 }
5976 }
5977
Bram Moolenaar1a384422010-07-14 19:53:30 +02005978#ifdef FEAT_SYN_HL
5979 /* 'colorcolumn' */
5980 else if (varp == &curwin->w_p_cc)
5981 errmsg = check_colorcolumn(curwin);
5982#endif
5983
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984#ifdef FEAT_MULTI_LANG
5985 /* 'helplang' */
5986 else if (varp == &p_hlg)
5987 {
5988 /* Check for "", "ab", "ab,cd", etc. */
5989 for (s = p_hlg; *s != NUL; s += 3)
5990 {
5991 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5992 {
5993 errmsg = e_invarg;
5994 break;
5995 }
5996 if (s[2] == NUL)
5997 break;
5998 }
5999 }
6000#endif
6001
6002 /* 'highlight' */
6003 else if (varp == &p_hl)
6004 {
6005 if (highlight_changed() == FAIL)
6006 errmsg = e_invarg; /* invalid flags */
6007 }
6008
6009 /* 'nrformats' */
6010 else if (gvarp == &p_nf)
6011 {
6012 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6013 errmsg = e_invarg;
6014 }
6015
6016#ifdef FEAT_SESSION
6017 /* 'sessionoptions' */
6018 else if (varp == &p_ssop)
6019 {
6020 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6021 errmsg = e_invarg;
6022 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6023 {
6024 /* Don't allow both "sesdir" and "curdir". */
6025 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6026 errmsg = e_invarg;
6027 }
6028 }
6029 /* 'viewoptions' */
6030 else if (varp == &p_vop)
6031 {
6032 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6033 errmsg = e_invarg;
6034 }
6035#endif
6036
6037 /* 'scrollopt' */
6038#ifdef FEAT_SCROLLBIND
6039 else if (varp == &p_sbo)
6040 {
6041 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6042 errmsg = e_invarg;
6043 }
6044#endif
6045
6046 /* 'ambiwidth' */
6047#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006048 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006049 {
6050 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6051 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006052 else if (set_chars_option(&p_lcs) != NULL)
6053 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6054# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6055 else if (set_chars_option(&p_fcs) != NULL)
6056 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6057# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058 }
6059#endif
6060
6061 /* 'background' */
6062 else if (varp == &p_bg)
6063 {
6064 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6065 {
6066#ifdef FEAT_EVAL
6067 int dark = (*p_bg == 'd');
6068#endif
6069
6070 init_highlight(FALSE, FALSE);
6071
6072#ifdef FEAT_EVAL
6073 if (dark != (*p_bg == 'd')
6074 && get_var_value((char_u *)"g:colors_name") != NULL)
6075 {
6076 /* The color scheme must have set 'background' back to another
6077 * value, that's not what we want here. Disable the color
6078 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006079 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006080 free_string_option(p_bg);
6081 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6082 check_string_option(&p_bg);
6083 init_highlight(FALSE, FALSE);
6084 }
6085#endif
6086 }
6087 else
6088 errmsg = e_invarg;
6089 }
6090
6091 /* 'wildmode' */
6092 else if (varp == &p_wim)
6093 {
6094 if (check_opt_wim() == FAIL)
6095 errmsg = e_invarg;
6096 }
6097
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006098#ifdef FEAT_CMDL_COMPL
6099 /* 'wildoptions' */
6100 else if (varp == &p_wop)
6101 {
6102 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6103 errmsg = e_invarg;
6104 }
6105#endif
6106
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107#ifdef FEAT_WAK
6108 /* 'winaltkeys' */
6109 else if (varp == &p_wak)
6110 {
6111 if (*p_wak == NUL
6112 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6113 errmsg = e_invarg;
6114# ifdef FEAT_MENU
6115# ifdef FEAT_GUI_MOTIF
6116 else if (gui.in_use)
6117 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6118# else
6119# ifdef FEAT_GUI_GTK
6120 else if (gui.in_use)
6121 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6122# endif
6123# endif
6124# endif
6125 }
6126#endif
6127
6128#ifdef FEAT_AUTOCMD
6129 /* 'eventignore' */
6130 else if (varp == &p_ei)
6131 {
6132 if (check_ei() == FAIL)
6133 errmsg = e_invarg;
6134 }
6135#endif
6136
6137#ifdef FEAT_MBYTE
6138 /* 'encoding' and 'fileencoding' */
6139 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6140 {
6141 if (gvarp == &p_fenc)
6142 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006143 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144 errmsg = e_modifiable;
6145 else if (vim_strchr(*varp, ',') != NULL)
6146 /* No comma allowed in 'fileencoding'; catches confusing it
6147 * with 'fileencodings'. */
6148 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006149 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006150 {
6151# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006152 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006153 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006155 /* Add 'fileencoding' to the swap file. */
6156 ml_setflags(curbuf);
6157 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006158 }
6159 if (errmsg == NULL)
6160 {
6161 /* canonize the value, so that STRCMP() can be used on it */
6162 p = enc_canonize(*varp);
6163 if (p != NULL)
6164 {
6165 vim_free(*varp);
6166 *varp = p;
6167 }
6168 if (varp == &p_enc)
6169 {
6170 errmsg = mb_init();
6171# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006172 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006173# endif
6174 }
6175 }
6176
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006177# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006178 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6179 {
6180 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6181 if (STRCMP(p_tenc, "utf-8") != 0)
6182 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6183 }
6184# endif
6185
6186 if (errmsg == NULL)
6187 {
6188# ifdef FEAT_KEYMAP
6189 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6190 * (with another encoding). */
6191 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6192 (void)keymap_init();
6193# endif
6194
6195 /* When 'termencoding' is not empty and 'encoding' changes or when
6196 * 'termencoding' changes, need to setup for keyboard input and
6197 * display output conversion. */
6198 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6199 {
6200 convert_setup(&input_conv, p_tenc, p_enc);
6201 convert_setup(&output_conv, p_enc, p_tenc);
6202 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006203
6204# if defined(WIN3264) && defined(FEAT_MBYTE)
6205 /* $HOME may have characters in active code page. */
6206 if (varp == &p_enc)
6207 init_homedir();
6208# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006209 }
6210 }
6211#endif
6212
6213#if defined(FEAT_POSTSCRIPT)
6214 else if (varp == &p_penc)
6215 {
6216 /* Canonize printencoding if VIM standard one */
6217 p = enc_canonize(p_penc);
6218 if (p != NULL)
6219 {
6220 vim_free(p_penc);
6221 p_penc = p;
6222 }
6223 else
6224 {
6225 /* Ensure lower case and '-' for '_' */
6226 for (s = p_penc; *s != NUL; s++)
6227 {
6228 if (*s == '_')
6229 *s = '-';
6230 else
6231 *s = TOLOWER_ASC(*s);
6232 }
6233 }
6234 }
6235#endif
6236
Bram Moolenaar9372a112005-12-06 19:59:18 +00006237#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006238 else if (varp == &p_imak)
6239 {
6240 if (gui.in_use && !im_xim_isvalid_imactivate())
6241 errmsg = e_invarg;
6242 }
6243#endif
6244
6245#ifdef FEAT_KEYMAP
6246 else if (varp == &curbuf->b_p_keymap)
6247 {
6248 /* load or unload key mapping tables */
6249 errmsg = keymap_init();
6250
Bram Moolenaarfab06232009-03-04 03:13:35 +00006251 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006252 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006253 if (*curbuf->b_p_keymap != NUL)
6254 {
6255 /* Installed a new keymap, switch on using it. */
6256 curbuf->b_p_iminsert = B_IMODE_LMAP;
6257 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6258 curbuf->b_p_imsearch = B_IMODE_LMAP;
6259 }
6260 else
6261 {
6262 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6263 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6264 curbuf->b_p_iminsert = B_IMODE_NONE;
6265 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6266 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6267 }
6268 if ((opt_flags & OPT_LOCAL) == 0)
6269 {
6270 set_iminsert_global();
6271 set_imsearch_global();
6272 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006273# ifdef FEAT_WINDOWS
6274 status_redraw_curbuf();
6275# endif
6276 }
6277 }
6278#endif
6279
6280 /* 'fileformat' */
6281 else if (gvarp == &p_ff)
6282 {
6283 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6284 errmsg = e_modifiable;
6285 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6286 errmsg = e_invarg;
6287 else
6288 {
6289 /* may also change 'textmode' */
6290 if (get_fileformat(curbuf) == EOL_DOS)
6291 curbuf->b_p_tx = TRUE;
6292 else
6293 curbuf->b_p_tx = FALSE;
6294#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006295 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006297 /* update flag in swap file */
6298 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006299 /* Redraw needed when switching to/from "mac": a CR in the text
6300 * will be displayed differently. */
6301 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6302 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 }
6304 }
6305
6306 /* 'fileformats' */
6307 else if (varp == &p_ffs)
6308 {
6309 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6310 errmsg = e_invarg;
6311 else
6312 {
6313 /* also change 'textauto' */
6314 if (*p_ffs == NUL)
6315 p_ta = FALSE;
6316 else
6317 p_ta = TRUE;
6318 }
6319 }
6320
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006321#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006322 /* 'cryptkey' */
6323 else if (gvarp == &p_key)
6324 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006325# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006326 /* Make sure the ":set" command doesn't show the new value in the
6327 * history. */
6328 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006329# endif
6330 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6331 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006332 ml_set_crypt_key(curbuf, oldval,
6333 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006334 }
6335
6336 else if (gvarp == &p_cm)
6337 {
6338 if (opt_flags & OPT_LOCAL)
6339 p = curbuf->b_p_cm;
6340 else
6341 p = p_cm;
6342 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6343 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006344 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006345 errmsg = e_invarg;
6346 else
6347 {
6348 /* When setting the global value to empty, make it "zip". */
6349 if (*p_cm == NUL)
6350 {
6351 if (new_value_alloced)
6352 free_string_option(p_cm);
6353 p_cm = vim_strsave((char_u *)"zip");
6354 new_value_alloced = TRUE;
6355 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006356 /* When using ":set cm=name" the local value is going to be empty.
6357 * Do that here, otherwise the crypt functions will still use the
6358 * local value. */
6359 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6360 {
6361 free_string_option(curbuf->b_p_cm);
6362 curbuf->b_p_cm = empty_option;
6363 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006364
6365 /* Need to update the swapfile when the effective method changed.
6366 * Set "s" to the effective old value, "p" to the effective new
6367 * method and compare. */
6368 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6369 s = p_cm; /* was previously using the global value */
6370 else
6371 s = oldval;
6372 if (*curbuf->b_p_cm == NUL)
6373 p = p_cm; /* is now using the global value */
6374 else
6375 p = curbuf->b_p_cm;
6376 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006377 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006378
6379 /* If the global value changes need to update the swapfile for all
6380 * buffers using that value. */
6381 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6382 {
6383 buf_T *buf;
6384
Bram Moolenaar29323592016-07-24 22:04:11 +02006385 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006386 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006387 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006388 }
6389 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006390 }
6391#endif
6392
6393 /* 'matchpairs' */
6394 else if (gvarp == &p_mps)
6395 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006396#ifdef FEAT_MBYTE
6397 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006398 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006399 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006400 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006401 int x2 = -1;
6402 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006403
6404 if (*p != NUL)
6405 p += mb_ptr2len(p);
6406 if (*p != NUL)
6407 x2 = *p++;
6408 if (*p != NUL)
6409 {
6410 x3 = mb_ptr2char(p);
6411 p += mb_ptr2len(p);
6412 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006413 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006414 {
6415 errmsg = e_invarg;
6416 break;
6417 }
6418 if (*p == NUL)
6419 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006421 }
6422 else
6423#endif
6424 {
6425 /* Check for "x:y,x:y" */
6426 for (p = *varp; *p != NUL; p += 4)
6427 {
6428 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6429 {
6430 errmsg = e_invarg;
6431 break;
6432 }
6433 if (p[3] == NUL)
6434 break;
6435 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006436 }
6437 }
6438
6439#ifdef FEAT_COMMENTS
6440 /* 'comments' */
6441 else if (gvarp == &p_com)
6442 {
6443 for (s = *varp; *s; )
6444 {
6445 while (*s && *s != ':')
6446 {
6447 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6448 && !VIM_ISDIGIT(*s) && *s != '-')
6449 {
6450 errmsg = illegal_char(errbuf, *s);
6451 break;
6452 }
6453 ++s;
6454 }
6455 if (*s++ == NUL)
6456 errmsg = (char_u *)N_("E524: Missing colon");
6457 else if (*s == ',' || *s == NUL)
6458 errmsg = (char_u *)N_("E525: Zero length string");
6459 if (errmsg != NULL)
6460 break;
6461 while (*s && *s != ',')
6462 {
6463 if (*s == '\\' && s[1] != NUL)
6464 ++s;
6465 ++s;
6466 }
6467 s = skip_to_option_part(s);
6468 }
6469 }
6470#endif
6471
6472 /* 'listchars' */
6473 else if (varp == &p_lcs)
6474 {
6475 errmsg = set_chars_option(varp);
6476 }
6477
6478#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6479 /* 'fillchars' */
6480 else if (varp == &p_fcs)
6481 {
6482 errmsg = set_chars_option(varp);
6483 }
6484#endif
6485
6486#ifdef FEAT_CMDWIN
6487 /* 'cedit' */
6488 else if (varp == &p_cedit)
6489 {
6490 errmsg = check_cedit();
6491 }
6492#endif
6493
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006494 /* 'verbosefile' */
6495 else if (varp == &p_vfile)
6496 {
6497 verbose_stop();
6498 if (*p_vfile != NUL && verbose_open() == FAIL)
6499 errmsg = e_invarg;
6500 }
6501
Bram Moolenaar071d4272004-06-13 20:20:40 +00006502#ifdef FEAT_VIMINFO
6503 /* 'viminfo' */
6504 else if (varp == &p_viminfo)
6505 {
6506 for (s = p_viminfo; *s;)
6507 {
6508 /* Check it's a valid character */
6509 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6510 {
6511 errmsg = illegal_char(errbuf, *s);
6512 break;
6513 }
6514 if (*s == 'n') /* name is always last one */
6515 {
6516 break;
6517 }
6518 else if (*s == 'r') /* skip until next ',' */
6519 {
6520 while (*++s && *s != ',')
6521 ;
6522 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006523 else if (*s == '%')
6524 {
6525 /* optional number */
6526 while (vim_isdigit(*++s))
6527 ;
6528 }
6529 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006530 ++s; /* no extra chars */
6531 else /* must have a number */
6532 {
6533 while (vim_isdigit(*++s))
6534 ;
6535
6536 if (!VIM_ISDIGIT(*(s - 1)))
6537 {
6538 if (errbuf != NULL)
6539 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006540 sprintf((char *)errbuf,
6541 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006542 transchar_byte(*(s - 1)));
6543 errmsg = errbuf;
6544 }
6545 else
6546 errmsg = (char_u *)"";
6547 break;
6548 }
6549 }
6550 if (*s == ',')
6551 ++s;
6552 else if (*s)
6553 {
6554 if (errbuf != NULL)
6555 errmsg = (char_u *)N_("E527: Missing comma");
6556 else
6557 errmsg = (char_u *)"";
6558 break;
6559 }
6560 }
6561 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6562 errmsg = (char_u *)N_("E528: Must specify a ' value");
6563 }
6564#endif /* FEAT_VIMINFO */
6565
6566 /* terminal options */
6567 else if (istermoption(&options[opt_idx]) && full_screen)
6568 {
6569 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6570 if (varp == &T_CCO)
6571 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006572 int colors = atoi((char *)T_CCO);
6573
6574 /* Only reinitialize colors if t_Co value has really changed to
6575 * avoid expensive reload of colorscheme if t_Co is set to the
6576 * same value multiple times. */
6577 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006579 t_colors = colors;
6580 if (t_colors <= 1)
6581 {
6582 if (new_value_alloced)
6583 vim_free(T_CCO);
6584 T_CCO = empty_option;
6585 }
6586 /* We now have a different color setup, initialize it again. */
6587 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006588 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006589 }
6590 ttest(FALSE);
6591 if (varp == &T_ME)
6592 {
6593 out_str(T_ME);
6594 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006595#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006596 /* Since t_me has been set, this probably means that the user
6597 * wants to use this as default colors. Need to reset default
6598 * background/foreground colors. */
6599 mch_set_normal_colors();
6600#endif
6601 }
6602 }
6603
6604#ifdef FEAT_LINEBREAK
6605 /* 'showbreak' */
6606 else if (varp == &p_sbr)
6607 {
6608 for (s = p_sbr; *s; )
6609 {
6610 if (ptr2cells(s) != 1)
6611 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006612 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006613 }
6614 }
6615#endif
6616
6617#ifdef FEAT_GUI
6618 /* 'guifont' */
6619 else if (varp == &p_guifont)
6620 {
6621 if (gui.in_use)
6622 {
6623 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006624# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006625 /*
6626 * Put up a font dialog and let the user select a new value.
6627 * If this is cancelled go back to the old value but don't
6628 * give an error message.
6629 */
6630 if (STRCMP(p, "*") == 0)
6631 {
6632 p = gui_mch_font_dialog(oldval);
6633
6634 if (new_value_alloced)
6635 free_string_option(p_guifont);
6636
6637 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6638 new_value_alloced = TRUE;
6639 }
6640# endif
6641 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6642 {
6643# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6644 if (STRCMP(p_guifont, "*") == 0)
6645 {
6646 /* Dialog was cancelled: Keep the old value without giving
6647 * an error message. */
6648 if (new_value_alloced)
6649 free_string_option(p_guifont);
6650 p_guifont = vim_strsave(oldval);
6651 new_value_alloced = TRUE;
6652 }
6653 else
6654# endif
6655 errmsg = (char_u *)N_("E596: Invalid font(s)");
6656 }
6657 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006658 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006659 }
6660# ifdef FEAT_XFONTSET
6661 else if (varp == &p_guifontset)
6662 {
6663 if (STRCMP(p_guifontset, "*") == 0)
6664 errmsg = (char_u *)N_("E597: can't select fontset");
6665 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6666 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006667 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006668 }
6669# endif
6670# ifdef FEAT_MBYTE
6671 else if (varp == &p_guifontwide)
6672 {
6673 if (STRCMP(p_guifontwide, "*") == 0)
6674 errmsg = (char_u *)N_("E533: can't select wide font");
6675 else if (gui_get_wide_font() == FAIL)
6676 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006677 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006678 }
6679# endif
6680#endif
6681
6682#ifdef CURSOR_SHAPE
6683 /* 'guicursor' */
6684 else if (varp == &p_guicursor)
6685 errmsg = parse_shape_opt(SHAPE_CURSOR);
6686#endif
6687
6688#ifdef FEAT_MOUSESHAPE
6689 /* 'mouseshape' */
6690 else if (varp == &p_mouseshape)
6691 {
6692 errmsg = parse_shape_opt(SHAPE_MOUSE);
6693 update_mouseshape(-1);
6694 }
6695#endif
6696
6697#ifdef FEAT_PRINTER
6698 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006699 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006700# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006701 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006702 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006703# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006704#endif
6705
6706#ifdef FEAT_LANGMAP
6707 /* 'langmap' */
6708 else if (varp == &p_langmap)
6709 langmap_set();
6710#endif
6711
6712#ifdef FEAT_LINEBREAK
6713 /* 'breakat' */
6714 else if (varp == &p_breakat)
6715 fill_breakat_flags();
6716#endif
6717
6718#ifdef FEAT_TITLE
6719 /* 'titlestring' and 'iconstring' */
6720 else if (varp == &p_titlestring || varp == &p_iconstring)
6721 {
6722# ifdef FEAT_STL_OPT
6723 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6724
6725 /* NULL => statusline syntax */
6726 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6727 stl_syntax |= flagval;
6728 else
6729 stl_syntax &= ~flagval;
6730# endif
6731 did_set_title(varp == &p_iconstring);
6732
6733 }
6734#endif
6735
6736#ifdef FEAT_GUI
6737 /* 'guioptions' */
6738 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006739 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006741 redraw_gui_only = TRUE;
6742 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006743#endif
6744
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006745#if defined(FEAT_GUI_TABLINE)
6746 /* 'guitablabel' */
6747 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006748 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006749 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006750 redraw_gui_only = TRUE;
6751 }
6752 /* 'guitabtooltip' */
6753 else if (varp == &p_gtt)
6754 {
6755 redraw_gui_only = TRUE;
6756 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006757#endif
6758
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6760 /* 'ttymouse' */
6761 else if (varp == &p_ttym)
6762 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006763 /* Switch the mouse off before changing the escape sequences used for
6764 * that. */
6765 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006766 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6767 errmsg = e_invarg;
6768 else
6769 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006770 if (termcap_active)
6771 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772 }
6773#endif
6774
Bram Moolenaar071d4272004-06-13 20:20:40 +00006775 /* 'selection' */
6776 else if (varp == &p_sel)
6777 {
6778 if (*p_sel == NUL
6779 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6780 errmsg = e_invarg;
6781 }
6782
6783 /* 'selectmode' */
6784 else if (varp == &p_slm)
6785 {
6786 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6787 errmsg = e_invarg;
6788 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006789
6790#ifdef FEAT_BROWSE
6791 /* 'browsedir' */
6792 else if (varp == &p_bsdir)
6793 {
6794 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6795 && !mch_isdir(p_bsdir))
6796 errmsg = e_invarg;
6797 }
6798#endif
6799
Bram Moolenaar071d4272004-06-13 20:20:40 +00006800 /* 'keymodel' */
6801 else if (varp == &p_km)
6802 {
6803 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6804 errmsg = e_invarg;
6805 else
6806 {
6807 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6808 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6809 }
6810 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006811
6812 /* 'mousemodel' */
6813 else if (varp == &p_mousem)
6814 {
6815 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6816 errmsg = e_invarg;
6817#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6818 else if (*p_mousem != *oldval)
6819 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6820 * to create or delete the popup menus. */
6821 gui_motif_update_mousemodel(root_menu);
6822#endif
6823 }
6824
6825 /* 'switchbuf' */
6826 else if (varp == &p_swb)
6827 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006828 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 errmsg = e_invarg;
6830 }
6831
6832 /* 'debug' */
6833 else if (varp == &p_debug)
6834 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006835 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006836 errmsg = e_invarg;
6837 }
6838
6839 /* 'display' */
6840 else if (varp == &p_dy)
6841 {
6842 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6843 errmsg = e_invarg;
6844 else
6845 (void)init_chartab();
6846
6847 }
6848
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006849#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006850 /* 'eadirection' */
6851 else if (varp == &p_ead)
6852 {
6853 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6854 errmsg = e_invarg;
6855 }
6856#endif
6857
6858#ifdef FEAT_CLIPBOARD
6859 /* 'clipboard' */
6860 else if (varp == &p_cb)
6861 errmsg = check_clipboard_option();
6862#endif
6863
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006864#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006865 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6866 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006867 else if (varp == &(curwin->w_s->b_p_spl)
6868 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006869 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006870 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006871 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006872 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006873 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006874 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006875 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006876 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006877 /* 'spellsuggest' */
6878 else if (varp == &p_sps)
6879 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006880 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006881 errmsg = e_invarg;
6882 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006883 /* 'mkspellmem' */
6884 else if (varp == &p_msm)
6885 {
6886 if (spell_check_msm() != OK)
6887 errmsg = e_invarg;
6888 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006889#endif
6890
Bram Moolenaar071d4272004-06-13 20:20:40 +00006891#ifdef FEAT_QUICKFIX
6892 /* When 'bufhidden' is set, check for valid value. */
6893 else if (gvarp == &p_bh)
6894 {
6895 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6896 errmsg = e_invarg;
6897 }
6898
6899 /* When 'buftype' is set, check for valid value. */
6900 else if (gvarp == &p_bt)
6901 {
6902 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6903 errmsg = e_invarg;
6904 else
6905 {
6906# ifdef FEAT_WINDOWS
6907 if (curwin->w_status_height)
6908 {
6909 curwin->w_redr_status = TRUE;
6910 redraw_later(VALID);
6911 }
6912# endif
6913 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006914# ifdef FEAT_TITLE
6915 redraw_titles();
6916# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 }
6918 }
6919#endif
6920
6921#ifdef FEAT_STL_OPT
6922 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006923 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006924 {
6925 int wid;
6926
6927 if (varp == &p_ruf) /* reset ru_wid first */
6928 ru_wid = 0;
6929 s = *varp;
6930 if (varp == &p_ruf && *s == '%')
6931 {
6932 /* set ru_wid if 'ruf' starts with "%99(" */
6933 if (*++s == '-') /* ignore a '-' */
6934 s++;
6935 wid = getdigits(&s);
6936 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6937 ru_wid = wid;
6938 else
6939 errmsg = check_stl_option(p_ruf);
6940 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006941 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006942 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006944 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006945 comp_col();
6946 }
6947#endif
6948
6949#ifdef FEAT_INS_EXPAND
6950 /* check if it is a valid value for 'complete' -- Acevedo */
6951 else if (gvarp == &p_cpt)
6952 {
6953 for (s = *varp; *s;)
6954 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006955 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006956 s++;
6957 if (!*s)
6958 break;
6959 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6960 {
6961 errmsg = illegal_char(errbuf, *s);
6962 break;
6963 }
6964 if (*++s != NUL && *s != ',' && *s != ' ')
6965 {
6966 if (s[-1] == 'k' || s[-1] == 's')
6967 {
6968 /* skip optional filename after 'k' and 's' */
6969 while (*s && *s != ',' && *s != ' ')
6970 {
6971 if (*s == '\\')
6972 ++s;
6973 ++s;
6974 }
6975 }
6976 else
6977 {
6978 if (errbuf != NULL)
6979 {
6980 sprintf((char *)errbuf,
6981 _("E535: Illegal character after <%c>"),
6982 *--s);
6983 errmsg = errbuf;
6984 }
6985 else
6986 errmsg = (char_u *)"";
6987 break;
6988 }
6989 }
6990 }
6991 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006992
6993 /* 'completeopt' */
6994 else if (varp == &p_cot)
6995 {
6996 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6997 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02006998 else
6999 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007000 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007001#endif /* FEAT_INS_EXPAND */
7002
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007003#ifdef FEAT_SIGNS
7004 /* 'signcolumn' */
7005 else if (varp == &curwin->w_p_scl)
7006 {
7007 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7008 errmsg = e_invarg;
7009 }
7010#endif
7011
Bram Moolenaar071d4272004-06-13 20:20:40 +00007012
7013#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
7014 else if (varp == &p_toolbar)
7015 {
7016 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7017 &toolbar_flags, TRUE) != OK)
7018 errmsg = e_invarg;
7019 else
7020 {
7021 out_flush();
7022 gui_mch_show_toolbar((toolbar_flags &
7023 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7024 }
7025 }
7026#endif
7027
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007028#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029 /* 'toolbariconsize': GTK+ 2 only */
7030 else if (varp == &p_tbis)
7031 {
7032 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7033 errmsg = e_invarg;
7034 else
7035 {
7036 out_flush();
7037 gui_mch_show_toolbar((toolbar_flags &
7038 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7039 }
7040 }
7041#endif
7042
7043 /* 'pastetoggle': translate key codes like in a mapping */
7044 else if (varp == &p_pt)
7045 {
7046 if (*p_pt)
7047 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007048 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049 if (p != NULL)
7050 {
7051 if (new_value_alloced)
7052 free_string_option(p_pt);
7053 p_pt = p;
7054 new_value_alloced = TRUE;
7055 }
7056 }
7057 }
7058
7059 /* 'backspace' */
7060 else if (varp == &p_bs)
7061 {
7062 if (VIM_ISDIGIT(*p_bs))
7063 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007064 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007065 errmsg = e_invarg;
7066 }
7067 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7068 errmsg = e_invarg;
7069 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007070 else if (varp == &p_bo)
7071 {
7072 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7073 errmsg = e_invarg;
7074 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007075
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007076 /* 'tagcase' */
7077 else if (gvarp == &p_tc)
7078 {
7079 unsigned int *flags;
7080
7081 if (opt_flags & OPT_LOCAL)
7082 {
7083 p = curbuf->b_p_tc;
7084 flags = &curbuf->b_tc_flags;
7085 }
7086 else
7087 {
7088 p = p_tc;
7089 flags = &tc_flags;
7090 }
7091
7092 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7093 /* make the local value empty: use the global value */
7094 *flags = 0;
7095 else if (*p == NUL
7096 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7097 errmsg = e_invarg;
7098 }
7099
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007100#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007101 /* 'casemap' */
7102 else if (varp == &p_cmp)
7103 {
7104 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7105 errmsg = e_invarg;
7106 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007107#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007108
7109#ifdef FEAT_DIFF
7110 /* 'diffopt' */
7111 else if (varp == &p_dip)
7112 {
7113 if (diffopt_changed() == FAIL)
7114 errmsg = e_invarg;
7115 }
7116#endif
7117
7118#ifdef FEAT_FOLDING
7119 /* 'foldmethod' */
7120 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7121 {
7122 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7123 || *curwin->w_p_fdm == NUL)
7124 errmsg = e_invarg;
7125 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007126 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007128 if (foldmethodIsDiff(curwin))
7129 newFoldLevel();
7130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007131 }
7132# ifdef FEAT_EVAL
7133 /* 'foldexpr' */
7134 else if (varp == &curwin->w_p_fde)
7135 {
7136 if (foldmethodIsExpr(curwin))
7137 foldUpdateAll(curwin);
7138 }
7139# endif
7140 /* 'foldmarker' */
7141 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7142 {
7143 p = vim_strchr(*varp, ',');
7144 if (p == NULL)
7145 errmsg = (char_u *)N_("E536: comma required");
7146 else if (p == *varp || p[1] == NUL)
7147 errmsg = e_invarg;
7148 else if (foldmethodIsMarker(curwin))
7149 foldUpdateAll(curwin);
7150 }
7151 /* 'commentstring' */
7152 else if (gvarp == &p_cms)
7153 {
7154 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7155 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7156 }
7157 /* 'foldopen' */
7158 else if (varp == &p_fdo)
7159 {
7160 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7161 errmsg = e_invarg;
7162 }
7163 /* 'foldclose' */
7164 else if (varp == &p_fcl)
7165 {
7166 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7167 errmsg = e_invarg;
7168 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007169 /* 'foldignore' */
7170 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7171 {
7172 if (foldmethodIsIndent(curwin))
7173 foldUpdateAll(curwin);
7174 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007175#endif
7176
7177#ifdef FEAT_VIRTUALEDIT
7178 /* 'virtualedit' */
7179 else if (varp == &p_ve)
7180 {
7181 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7182 errmsg = e_invarg;
7183 else if (STRCMP(p_ve, oldval) != 0)
7184 {
7185 /* Recompute cursor position in case the new 've' setting
7186 * changes something. */
7187 validate_virtcol();
7188 coladvance(curwin->w_virtcol);
7189 }
7190 }
7191#endif
7192
7193#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7194 else if (varp == &p_csqf)
7195 {
7196 if (p_csqf != NULL)
7197 {
7198 p = p_csqf;
7199 while (*p != NUL)
7200 {
7201 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7202 || p[1] == NUL
7203 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7204 || (p[2] != NUL && p[2] != ','))
7205 {
7206 errmsg = e_invarg;
7207 break;
7208 }
7209 else if (p[2] == NUL)
7210 break;
7211 else
7212 p += 3;
7213 }
7214 }
7215 }
7216#endif
7217
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007218#ifdef FEAT_CINDENT
7219 /* 'cinoptions' */
7220 else if (gvarp == &p_cino)
7221 {
7222 /* TODO: recognize errors */
7223 parse_cino(curbuf);
7224 }
7225#endif
7226
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007227#if defined(FEAT_RENDER_OPTIONS)
7228 else if (varp == &p_rop && gui.in_use)
7229 {
7230 if (!gui_mch_set_rendering_options(p_rop))
7231 errmsg = e_invarg;
7232 }
7233#endif
7234
Bram Moolenaar071d4272004-06-13 20:20:40 +00007235 /* Options that are a list of flags. */
7236 else
7237 {
7238 p = NULL;
7239 if (varp == &p_ww)
7240 p = (char_u *)WW_ALL;
7241 if (varp == &p_shm)
7242 p = (char_u *)SHM_ALL;
7243 else if (varp == &(p_cpo))
7244 p = (char_u *)CPO_ALL;
7245 else if (varp == &(curbuf->b_p_fo))
7246 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007247#ifdef FEAT_CONCEAL
7248 else if (varp == &curwin->w_p_cocu)
7249 p = (char_u *)COCU_ALL;
7250#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251 else if (varp == &p_mouse)
7252 {
7253#ifdef FEAT_MOUSE
7254 p = (char_u *)MOUSE_ALL;
7255#else
7256 if (*p_mouse != NUL)
7257 errmsg = (char_u *)N_("E538: No mouse support");
7258#endif
7259 }
7260#if defined(FEAT_GUI)
7261 else if (varp == &p_go)
7262 p = (char_u *)GO_ALL;
7263#endif
7264 if (p != NULL)
7265 {
7266 for (s = *varp; *s; ++s)
7267 if (vim_strchr(p, *s) == NULL)
7268 {
7269 errmsg = illegal_char(errbuf, *s);
7270 break;
7271 }
7272 }
7273 }
7274
7275 /*
7276 * If error detected, restore the previous value.
7277 */
7278 if (errmsg != NULL)
7279 {
7280 if (new_value_alloced)
7281 free_string_option(*varp);
7282 *varp = oldval;
7283 /*
7284 * When resetting some values, need to act on it.
7285 */
7286 if (did_chartab)
7287 (void)init_chartab();
7288 if (varp == &p_hl)
7289 (void)highlight_changed();
7290 }
7291 else
7292 {
7293#ifdef FEAT_EVAL
7294 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007295 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007296#endif
7297 /*
7298 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007299 * Use "free_oldval", because recursiveness may change the flags under
7300 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007301 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007302 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007303 free_string_option(oldval);
7304 if (new_value_alloced)
7305 options[opt_idx].flags |= P_ALLOCED;
7306 else
7307 options[opt_idx].flags &= ~P_ALLOCED;
7308
7309 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007310 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 {
7312 /* global option with local value set to use global value; free
7313 * the local value and make it empty */
7314 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7315 free_string_option(*(char_u **)p);
7316 *(char_u **)p = empty_option;
7317 }
7318
7319 /* May set global value for local option. */
7320 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7321 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007322
7323#ifdef FEAT_AUTOCMD
7324 /*
7325 * Trigger the autocommand only after setting the flags.
7326 */
7327# ifdef FEAT_SYN_HL
7328 /* When 'syntax' is set, load the syntax of that name */
7329 if (varp == &(curbuf->b_p_syn))
7330 {
7331 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7332 curbuf->b_fname, TRUE, curbuf);
7333 }
7334# endif
7335 else if (varp == &(curbuf->b_p_ft))
7336 {
7337 /* 'filetype' is set, trigger the FileType autocommand */
7338 did_filetype = TRUE;
7339 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7340 curbuf->b_fname, TRUE, curbuf);
7341 }
7342#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007343#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007344 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007345 {
7346 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007347 char_u *q = curwin->w_s->b_p_spl;
7348
7349 /* Skip the first name if it is "cjk". */
7350 if (STRNCMP(q, "cjk,", 4) == 0)
7351 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007352
7353 /*
7354 * Source the spell/LANG.vim in 'runtimepath'.
7355 * They could set 'spellcapcheck' depending on the language.
7356 * Use the first name in 'spelllang' up to '_region' or
7357 * '.encoding'.
7358 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007359 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007360 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7361 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007362 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007363 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007364 }
7365#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007366 }
7367
7368#ifdef FEAT_MOUSE
7369 if (varp == &p_mouse)
7370 {
7371# ifdef FEAT_MOUSE_TTY
7372 if (*p_mouse == NUL)
7373 mch_setmouse(FALSE); /* switch mouse off */
7374 else
7375# endif
7376 setmouse(); /* in case 'mouse' changed */
7377 }
7378#endif
7379
Bram Moolenaar913077c2012-03-28 19:59:04 +02007380 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007381 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007382 curwin->w_set_curswant = TRUE;
7383
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007384#ifdef FEAT_GUI
7385 /* check redraw when it's not a GUI option or the GUI is active. */
7386 if (!redraw_gui_only || gui.in_use)
7387#endif
7388 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007389
7390 return errmsg;
7391}
7392
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007393#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007394/*
7395 * Simple int comparison function for use with qsort()
7396 */
7397 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007398int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007399{
7400 return *(const int *)a - *(const int *)b;
7401}
7402
7403/*
7404 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7405 * Returns error message, NULL if it's OK.
7406 */
7407 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007408check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007409{
7410 char_u *s;
7411 int col;
7412 int count = 0;
7413 int color_cols[256];
7414 int i;
7415 int j = 0;
7416
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007417 if (wp->w_buffer == NULL)
7418 return NULL; /* buffer was closed */
7419
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007420 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007421 {
7422 if (*s == '-' || *s == '+')
7423 {
7424 /* -N and +N: add to 'textwidth' */
7425 col = (*s == '-') ? -1 : 1;
7426 ++s;
7427 if (!VIM_ISDIGIT(*s))
7428 return e_invarg;
7429 col = col * getdigits(&s);
7430 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007431 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007432 col += wp->w_buffer->b_p_tw;
7433 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007434 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007435 }
7436 else if (VIM_ISDIGIT(*s))
7437 col = getdigits(&s);
7438 else
7439 return e_invarg;
7440 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007441skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007442 if (*s == NUL)
7443 break;
7444 if (*s != ',')
7445 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007446 if (*++s == NUL)
7447 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007448 }
7449
7450 vim_free(wp->w_p_cc_cols);
7451 if (count == 0)
7452 wp->w_p_cc_cols = NULL;
7453 else
7454 {
7455 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7456 if (wp->w_p_cc_cols != NULL)
7457 {
7458 /* sort the columns for faster usage on screen redraw inside
7459 * win_line() */
7460 qsort(color_cols, count, sizeof(int), int_cmp);
7461
7462 for (i = 0; i < count; ++i)
7463 /* skip duplicates */
7464 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7465 wp->w_p_cc_cols[j++] = color_cols[i];
7466 wp->w_p_cc_cols[j] = -1; /* end marker */
7467 }
7468 }
7469
7470 return NULL; /* no error */
7471}
7472#endif
7473
Bram Moolenaar071d4272004-06-13 20:20:40 +00007474/*
7475 * Handle setting 'listchars' or 'fillchars'.
7476 * Returns error message, NULL if it's OK.
7477 */
7478 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007479set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007480{
7481 int round, i, len, entries;
7482 char_u *p, *s;
7483 int c1, c2 = 0;
7484 struct charstab
7485 {
7486 int *cp;
7487 char *name;
7488 };
7489#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7490 static struct charstab filltab[] =
7491 {
7492 {&fill_stl, "stl"},
7493 {&fill_stlnc, "stlnc"},
7494 {&fill_vert, "vert"},
7495 {&fill_fold, "fold"},
7496 {&fill_diff, "diff"},
7497 };
7498#endif
7499 static struct charstab lcstab[] =
7500 {
7501 {&lcs_eol, "eol"},
7502 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007503 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007505 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 {&lcs_tab2, "tab"},
7507 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007508#ifdef FEAT_CONCEAL
7509 {&lcs_conceal, "conceal"},
7510#else
7511 {NULL, "conceal"},
7512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 };
7514 struct charstab *tab;
7515
7516#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7517 if (varp == &p_lcs)
7518#endif
7519 {
7520 tab = lcstab;
7521 entries = sizeof(lcstab) / sizeof(struct charstab);
7522 }
7523#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7524 else
7525 {
7526 tab = filltab;
7527 entries = sizeof(filltab) / sizeof(struct charstab);
7528 }
7529#endif
7530
7531 /* first round: check for valid value, second round: assign values */
7532 for (round = 0; round <= 1; ++round)
7533 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007534 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007535 {
7536 /* After checking that the value is valid: set defaults: space for
7537 * 'fillchars', NUL for 'listchars' */
7538 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007539 if (tab[i].cp != NULL)
7540 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007541 if (varp == &p_lcs)
7542 lcs_tab1 = NUL;
7543#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7544 else
7545 fill_diff = '-';
7546#endif
7547 }
7548 p = *varp;
7549 while (*p)
7550 {
7551 for (i = 0; i < entries; ++i)
7552 {
7553 len = (int)STRLEN(tab[i].name);
7554 if (STRNCMP(p, tab[i].name, len) == 0
7555 && p[len] == ':'
7556 && p[len + 1] != NUL)
7557 {
7558 s = p + len + 1;
7559#ifdef FEAT_MBYTE
7560 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007561 if (mb_char2cells(c1) > 1)
7562 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007563#else
7564 c1 = *s++;
7565#endif
7566 if (tab[i].cp == &lcs_tab2)
7567 {
7568 if (*s == NUL)
7569 continue;
7570#ifdef FEAT_MBYTE
7571 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007572 if (mb_char2cells(c2) > 1)
7573 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007574#else
7575 c2 = *s++;
7576#endif
7577 }
7578 if (*s == ',' || *s == NUL)
7579 {
7580 if (round)
7581 {
7582 if (tab[i].cp == &lcs_tab2)
7583 {
7584 lcs_tab1 = c1;
7585 lcs_tab2 = c2;
7586 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007587 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007588 *(tab[i].cp) = c1;
7589
7590 }
7591 p = s;
7592 break;
7593 }
7594 }
7595 }
7596
7597 if (i == entries)
7598 return e_invarg;
7599 if (*p == ',')
7600 ++p;
7601 }
7602 }
7603
7604 return NULL; /* no error */
7605}
7606
7607#ifdef FEAT_STL_OPT
7608/*
7609 * Check validity of options with the 'statusline' format.
7610 * Return error message or NULL.
7611 */
7612 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007613check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007614{
7615 int itemcnt = 0;
7616 int groupdepth = 0;
7617 static char_u errbuf[80];
7618
7619 while (*s && itemcnt < STL_MAX_ITEM)
7620 {
7621 /* Check for valid keys after % sequences */
7622 while (*s && *s != '%')
7623 s++;
7624 if (!*s)
7625 break;
7626 s++;
7627 if (*s != '%' && *s != ')')
7628 ++itemcnt;
7629 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7630 {
7631 s++;
7632 continue;
7633 }
7634 if (*s == ')')
7635 {
7636 s++;
7637 if (--groupdepth < 0)
7638 break;
7639 continue;
7640 }
7641 if (*s == '-')
7642 s++;
7643 while (VIM_ISDIGIT(*s))
7644 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007645 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007646 continue;
7647 if (*s == '.')
7648 {
7649 s++;
7650 while (*s && VIM_ISDIGIT(*s))
7651 s++;
7652 }
7653 if (*s == '(')
7654 {
7655 groupdepth++;
7656 continue;
7657 }
7658 if (vim_strchr(STL_ALL, *s) == NULL)
7659 {
7660 return illegal_char(errbuf, *s);
7661 }
7662 if (*s == '{')
7663 {
7664 s++;
7665 while (*s != '}' && *s)
7666 s++;
7667 if (*s != '}')
7668 return (char_u *)N_("E540: Unclosed expression sequence");
7669 }
7670 }
7671 if (itemcnt >= STL_MAX_ITEM)
7672 return (char_u *)N_("E541: too many items");
7673 if (groupdepth != 0)
7674 return (char_u *)N_("E542: unbalanced groups");
7675 return NULL;
7676}
7677#endif
7678
7679#ifdef FEAT_CLIPBOARD
7680/*
7681 * Extract the items in the 'clipboard' option and set global values.
7682 */
7683 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007684check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007685{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007686 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007687 int new_autoselect_star = FALSE;
7688 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007689 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007690 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691 regprog_T *new_exclude_prog = NULL;
7692 char_u *errmsg = NULL;
7693 char_u *p;
7694
7695 for (p = p_cb; *p != NUL; )
7696 {
7697 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7698 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007699 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007700 p += 7;
7701 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007702 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007703 && (p[11] == ',' || p[11] == NUL))
7704 {
7705 new_unnamed |= CLIP_UNNAMED_PLUS;
7706 p += 11;
7707 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007708 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007709 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007711 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 p += 10;
7713 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007714 else if (STRNCMP(p, "autoselectplus", 14) == 0
7715 && (p[14] == ',' || p[14] == NUL))
7716 {
7717 new_autoselect_plus = TRUE;
7718 p += 14;
7719 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007720 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007721 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007722 {
7723 new_autoselectml = TRUE;
7724 p += 12;
7725 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007726 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7727 {
7728 new_html = TRUE;
7729 p += 4;
7730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007731 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7732 {
7733 p += 8;
7734 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7735 if (new_exclude_prog == NULL)
7736 errmsg = e_invarg;
7737 break;
7738 }
7739 else
7740 {
7741 errmsg = e_invarg;
7742 break;
7743 }
7744 if (*p == ',')
7745 ++p;
7746 }
7747 if (errmsg == NULL)
7748 {
7749 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007750 clip_autoselect_star = new_autoselect_star;
7751 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007752 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007753 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007754 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007756#ifdef FEAT_GUI_GTK
7757 if (gui.in_use)
7758 {
7759 gui_gtk_set_selection_targets();
7760 gui_gtk_set_dnd_targets();
7761 }
7762#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 }
7764 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007765 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766
7767 return errmsg;
7768}
7769#endif
7770
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007771#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007772 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007773did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007774{
7775 char_u *errmsg = NULL;
7776 win_T *wp;
7777 int l;
7778
7779 if (is_spellfile)
7780 {
7781 l = (int)STRLEN(curwin->w_s->b_p_spf);
7782 if (l > 0 && (l < 4
7783 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7784 errmsg = e_invarg;
7785 }
7786
7787 if (errmsg == NULL)
7788 {
7789 FOR_ALL_WINDOWS(wp)
7790 if (wp->w_buffer == curbuf && wp->w_p_spell)
7791 {
7792 errmsg = did_set_spelllang(wp);
7793# ifdef FEAT_WINDOWS
7794 break;
7795# endif
7796 }
7797 }
7798 return errmsg;
7799}
7800
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007801/*
7802 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7803 * Return error message when failed, NULL when OK.
7804 */
7805 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007806compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007807{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007808 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007809 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007810
Bram Moolenaar860cae12010-06-05 23:22:07 +02007811 if (*synblock->b_p_spc == NUL)
7812 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007813 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007814 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007815 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007816 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007817 if (re != NULL)
7818 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007819 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007820 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007821 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007822 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007823 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007824 return e_invarg;
7825 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007826 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007827 }
7828
Bram Moolenaar473de612013-06-08 18:19:48 +02007829 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007830 return NULL;
7831}
7832#endif
7833
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007834#if defined(FEAT_EVAL) || defined(PROTO)
7835/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007836 * Set the scriptID for an option, taking care of setting the buffer- or
7837 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007838 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007839 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007840set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007841{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007842 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7843 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007844
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007845 /* Remember where the option was set. For local options need to do that
7846 * in the buffer or window structure. */
7847 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007848 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007849 if (both || (opt_flags & OPT_LOCAL))
7850 {
7851 if (indir & PV_BUF)
7852 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7853 else if (indir & PV_WIN)
7854 curwin->w_p_scriptID[indir & PV_MASK] = id;
7855 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007856}
7857#endif
7858
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859/*
7860 * Set the value of a boolean option, and take care of side effects.
7861 * Returns NULL for success, or an error message for an error.
7862 */
7863 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007864set_bool_option(
7865 int opt_idx, /* index in options[] table */
7866 char_u *varp, /* pointer to the option variable */
7867 int value, /* new value */
7868 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869{
7870 int old_value = *(int *)varp;
7871
Bram Moolenaar071d4272004-06-13 20:20:40 +00007872 /* Disallow changing some options from secure mode */
7873 if ((secure
7874#ifdef HAVE_SANDBOX
7875 || sandbox != 0
7876#endif
7877 ) && (options[opt_idx].flags & P_SECURE))
7878 return e_secure;
7879
7880 *(int *)varp = value; /* set the new value */
7881#ifdef FEAT_EVAL
7882 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007883 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884#endif
7885
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007886#ifdef FEAT_GUI
7887 need_mouse_correct = TRUE;
7888#endif
7889
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 /* May set global value for local option. */
7891 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7892 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7893
7894 /*
7895 * Handle side effects of changing a bool option.
7896 */
7897
7898 /* 'compatible' */
7899 if ((int *)varp == &p_cp)
7900 {
7901 compatible_set();
7902 }
7903
Bram Moolenaar920694c2016-08-21 17:45:02 +02007904#ifdef FEAT_LANGMAP
7905 if ((int *)varp == &p_lrm)
7906 /* 'langremap' -> !'langnoremap' */
7907 p_lnr = !p_lrm;
7908 else if ((int *)varp == &p_lnr)
7909 /* 'langnoremap' -> !'langremap' */
7910 p_lrm = !p_lnr;
7911#endif
7912
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007913#ifdef FEAT_PERSISTENT_UNDO
7914 /* 'undofile' */
7915 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7916 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007917 /* Only take action when the option was set. When reset we do not
7918 * delete the undo file, the option may be set again without making
7919 * any changes in between. */
7920 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007921 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007922 char_u hash[UNDO_HASH_SIZE];
7923 buf_T *save_curbuf = curbuf;
7924
Bram Moolenaar29323592016-07-24 22:04:11 +02007925 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007926 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007927 /* When 'undofile' is set globally: for every buffer, otherwise
7928 * only for the current buffer: Try to read in the undofile,
7929 * if one exists, the buffer wasn't changed and the buffer was
7930 * loaded */
7931 if ((curbuf == save_curbuf
7932 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7933 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7934 {
7935 u_compute_hash(hash);
7936 u_read_undo(NULL, hash, curbuf->b_fname);
7937 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007938 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007939 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007940 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007941 }
7942#endif
7943
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 else if ((int *)varp == &curbuf->b_p_ro)
7945 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007946 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7948 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007949
7950 /* when 'readonly' is set may give W10 again */
7951 if (curbuf->b_p_ro)
7952 curbuf->b_did_warn = FALSE;
7953
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007955 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956#endif
7957 }
7958
Bram Moolenaar9c449722010-07-20 18:44:27 +02007959#ifdef FEAT_GUI
7960 else if ((int *)varp == &p_mh)
7961 {
7962 if (!p_mh)
7963 gui_mch_mousehide(FALSE);
7964 }
7965#endif
7966
Bram Moolenaara539df02010-08-01 14:35:05 +02007967#ifdef FEAT_TITLE
7968 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007970 {
7971 redraw_titles();
7972 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973 /* when 'endofline' is changed, redraw the window title */
7974 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007975 {
7976 redraw_titles();
7977 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007978 /* when 'fixeol' is changed, redraw the window title */
7979 else if ((int *)varp == &curbuf->b_p_fixeol)
7980 {
7981 redraw_titles();
7982 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007983# ifdef FEAT_MBYTE
7984 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007985 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007986 {
7987 redraw_titles();
7988 }
7989# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990#endif
7991
7992 /* when 'bin' is set also set some other options */
7993 else if ((int *)varp == &curbuf->b_p_bin)
7994 {
7995 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7996#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007997 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007998#endif
7999 }
8000
8001#ifdef FEAT_AUTOCMD
8002 /* when 'buflisted' changes, trigger autocommands */
8003 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8004 {
8005 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8006 NULL, NULL, TRUE, curbuf);
8007 }
8008#endif
8009
8010 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8011 else if ((int *)varp == &curbuf->b_p_swf)
8012 {
8013 if (curbuf->b_p_swf && p_uc)
8014 ml_open_file(curbuf); /* create the swap file */
8015 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008016 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8017 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 mf_close_file(curbuf, TRUE); /* remove the swap file */
8019 }
8020
8021 /* when 'terse' is set change 'shortmess' */
8022 else if ((int *)varp == &p_terse)
8023 {
8024 char_u *p;
8025
8026 p = vim_strchr(p_shm, SHM_SEARCH);
8027
8028 /* insert 's' in p_shm */
8029 if (p_terse && p == NULL)
8030 {
8031 STRCPY(IObuff, p_shm);
8032 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008033 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034 }
8035 /* remove 's' from p_shm */
8036 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008037 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008038 }
8039
8040 /* when 'paste' is set or reset also change other options */
8041 else if ((int *)varp == &p_paste)
8042 {
8043 paste_option_changed();
8044 }
8045
8046 /* when 'insertmode' is set from an autocommand need to do work here */
8047 else if ((int *)varp == &p_im)
8048 {
8049 if (p_im)
8050 {
8051 if ((State & INSERT) == 0)
8052 need_start_insertmode = TRUE;
8053 stop_insert_mode = FALSE;
8054 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008055 /* only reset if it was set previously */
8056 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008057 {
8058 need_start_insertmode = FALSE;
8059 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008060 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008061 clear_cmdline = TRUE; /* remove "(insert)" */
8062 restart_edit = 0;
8063 }
8064 }
8065
8066 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8067 else if ((int *)varp == &p_ic && p_hls)
8068 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008069 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 }
8071
8072#ifdef FEAT_SEARCH_EXTRA
8073 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8074 else if ((int *)varp == &p_hls)
8075 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008076 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008077 }
8078#endif
8079
8080#ifdef FEAT_SCROLLBIND
8081 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8082 * at the end of normal_cmd() */
8083 else if ((int *)varp == &curwin->w_p_scb)
8084 {
8085 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008086 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008088 curwin->w_scbind_pos = curwin->w_topline;
8089 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008090 }
8091#endif
8092
8093#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8094 /* There can be only one window with 'previewwindow' set. */
8095 else if ((int *)varp == &curwin->w_p_pvw)
8096 {
8097 if (curwin->w_p_pvw)
8098 {
8099 win_T *win;
8100
Bram Moolenaar29323592016-07-24 22:04:11 +02008101 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008102 if (win->w_p_pvw && win != curwin)
8103 {
8104 curwin->w_p_pvw = FALSE;
8105 return (char_u *)N_("E590: A preview window already exists");
8106 }
8107 }
8108 }
8109#endif
8110
8111 /* when 'textmode' is set or reset also change 'fileformat' */
8112 else if ((int *)varp == &curbuf->b_p_tx)
8113 {
8114 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8115 }
8116
8117 /* when 'textauto' is set or reset also change 'fileformats' */
8118 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008119 set_string_option_direct((char_u *)"ffs", -1,
8120 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008121 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008122
8123 /*
8124 * When 'lisp' option changes include/exclude '-' in
8125 * keyword characters.
8126 */
8127#ifdef FEAT_LISP
8128 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8129 {
8130 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8131 }
8132#endif
8133
8134#ifdef FEAT_TITLE
8135 /* when 'title' changed, may need to change the title; same for 'icon' */
8136 else if ((int *)varp == &p_title)
8137 {
8138 did_set_title(FALSE);
8139 }
8140
8141 else if ((int *)varp == &p_icon)
8142 {
8143 did_set_title(TRUE);
8144 }
8145#endif
8146
8147 else if ((int *)varp == &curbuf->b_changed)
8148 {
8149 if (!value)
8150 save_file_ff(curbuf); /* Buffer is unchanged */
8151#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008152 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153#endif
8154#ifdef FEAT_AUTOCMD
8155 modified_was_set = value;
8156#endif
8157 }
8158
8159#ifdef BACKSLASH_IN_FILENAME
8160 else if ((int *)varp == &p_ssl)
8161 {
8162 if (p_ssl)
8163 {
8164 psepc = '/';
8165 psepcN = '\\';
8166 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 }
8168 else
8169 {
8170 psepc = '\\';
8171 psepcN = '/';
8172 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 }
8174
8175 /* need to adjust the file name arguments and buffer names. */
8176 buflist_slash_adjust();
8177 alist_slash_adjust();
8178# ifdef FEAT_EVAL
8179 scriptnames_slash_adjust();
8180# endif
8181 }
8182#endif
8183
8184 /* If 'wrap' is set, set w_leftcol to zero. */
8185 else if ((int *)varp == &curwin->w_p_wrap)
8186 {
8187 if (curwin->w_p_wrap)
8188 curwin->w_leftcol = 0;
8189 }
8190
8191#ifdef FEAT_WINDOWS
8192 else if ((int *)varp == &p_ea)
8193 {
8194 if (p_ea && !old_value)
8195 win_equal(curwin, FALSE, 0);
8196 }
8197#endif
8198
8199 else if ((int *)varp == &p_wiv)
8200 {
8201 /*
8202 * When 'weirdinvert' changed, set/reset 't_xs'.
8203 * Then set 'weirdinvert' according to value of 't_xs'.
8204 */
8205 if (p_wiv && !old_value)
8206 T_XS = (char_u *)"y";
8207 else if (!p_wiv && old_value)
8208 T_XS = empty_option;
8209 p_wiv = (*T_XS != NUL);
8210 }
8211
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008212#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008213 else if ((int *)varp == &p_beval)
8214 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008215 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008216 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008217 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 gui_mch_disable_beval_area(balloonEval);
8219 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008220#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008221
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008222#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008223 else if ((int *)varp == &p_acd)
8224 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008225 /* Change directories when the 'acd' option is set now. */
8226 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008227 }
8228#endif
8229
8230#ifdef FEAT_DIFF
8231 /* 'diff' */
8232 else if ((int *)varp == &curwin->w_p_diff)
8233 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008234 /* May add or remove the buffer from the list of diff buffers. */
8235 diff_buf_adjust(curwin);
8236# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237 if (foldmethodIsDiff(curwin))
8238 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008239# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008240 }
8241#endif
8242
8243#ifdef USE_IM_CONTROL
8244 /* 'imdisable' */
8245 else if ((int *)varp == &p_imdisable)
8246 {
8247 /* Only de-activate it here, it will be enabled when changing mode. */
8248 if (p_imdisable)
8249 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008250 else if (State & INSERT)
8251 /* When the option is set from an autocommand, it may need to take
8252 * effect right away. */
8253 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008254 }
8255#endif
8256
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008257#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008258 /* 'spell' */
8259 else if ((int *)varp == &curwin->w_p_spell)
8260 {
8261 if (curwin->w_p_spell)
8262 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008263 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008264 if (errmsg != NULL)
8265 EMSG(_(errmsg));
8266 }
8267 }
8268#endif
8269
Bram Moolenaar071d4272004-06-13 20:20:40 +00008270#ifdef FEAT_FKMAP
8271 else if ((int *)varp == &p_altkeymap)
8272 {
8273 if (old_value != p_altkeymap)
8274 {
8275 if (!p_altkeymap)
8276 {
8277 p_hkmap = p_fkmap;
8278 p_fkmap = 0;
8279 }
8280 else
8281 {
8282 p_fkmap = p_hkmap;
8283 p_hkmap = 0;
8284 }
8285 (void)init_chartab();
8286 }
8287 }
8288
8289 /*
8290 * In case some second language keymapping options have changed, check
8291 * and correct the setting in a consistent way.
8292 */
8293
8294 /*
8295 * If hkmap or fkmap are set, reset Arabic keymapping.
8296 */
8297 if ((p_hkmap || p_fkmap) && p_altkeymap)
8298 {
8299 p_altkeymap = p_fkmap;
8300# ifdef FEAT_ARABIC
8301 curwin->w_p_arab = FALSE;
8302# endif
8303 (void)init_chartab();
8304 }
8305
8306 /*
8307 * If hkmap set, reset Farsi keymapping.
8308 */
8309 if (p_hkmap && p_altkeymap)
8310 {
8311 p_altkeymap = 0;
8312 p_fkmap = 0;
8313# ifdef FEAT_ARABIC
8314 curwin->w_p_arab = FALSE;
8315# endif
8316 (void)init_chartab();
8317 }
8318
8319 /*
8320 * If fkmap set, reset Hebrew keymapping.
8321 */
8322 if (p_fkmap && !p_altkeymap)
8323 {
8324 p_altkeymap = 1;
8325 p_hkmap = 0;
8326# ifdef FEAT_ARABIC
8327 curwin->w_p_arab = FALSE;
8328# endif
8329 (void)init_chartab();
8330 }
8331#endif
8332
8333#ifdef FEAT_ARABIC
8334 if ((int *)varp == &curwin->w_p_arab)
8335 {
8336 if (curwin->w_p_arab)
8337 {
8338 /*
8339 * 'arabic' is set, handle various sub-settings.
8340 */
8341 if (!p_tbidi)
8342 {
8343 /* set rightleft mode */
8344 if (!curwin->w_p_rl)
8345 {
8346 curwin->w_p_rl = TRUE;
8347 changed_window_setting();
8348 }
8349
8350 /* Enable Arabic shaping (major part of what Arabic requires) */
8351 if (!p_arshape)
8352 {
8353 p_arshape = TRUE;
8354 redraw_later_clear();
8355 }
8356 }
8357
8358 /* Arabic requires a utf-8 encoding, inform the user if its not
8359 * set. */
8360 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008361 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008362 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8363
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008364 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008365 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8366#ifdef FEAT_EVAL
8367 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8368#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008369 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370
8371# ifdef FEAT_MBYTE
8372 /* set 'delcombine' */
8373 p_deco = TRUE;
8374# endif
8375
8376# ifdef FEAT_KEYMAP
8377 /* Force-set the necessary keymap for arabic */
8378 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8379 OPT_LOCAL);
8380# endif
8381# ifdef FEAT_FKMAP
8382 p_altkeymap = 0;
8383 p_hkmap = 0;
8384 p_fkmap = 0;
8385 (void)init_chartab();
8386# endif
8387 }
8388 else
8389 {
8390 /*
8391 * 'arabic' is reset, handle various sub-settings.
8392 */
8393 if (!p_tbidi)
8394 {
8395 /* reset rightleft mode */
8396 if (curwin->w_p_rl)
8397 {
8398 curwin->w_p_rl = FALSE;
8399 changed_window_setting();
8400 }
8401
8402 /* 'arabicshape' isn't reset, it is a global option and
8403 * another window may still need it "on". */
8404 }
8405
8406 /* 'delcombine' isn't reset, it is a global option and another
8407 * window may still want it "on". */
8408
8409# ifdef FEAT_KEYMAP
8410 /* Revert to the default keymap */
8411 curbuf->b_p_iminsert = B_IMODE_NONE;
8412 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8413# endif
8414 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008415 }
8416
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008417#endif
8418
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008419#ifdef FEAT_TERMGUICOLORS
8420 /* 'termguicolors' */
8421 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008422 {
8423# ifdef FEAT_GUI
8424 if (!gui.in_use && !gui.starting)
8425# endif
8426 highlight_gui_started();
8427 }
8428#endif
8429
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 /*
8431 * End of handling side effects for bool options.
8432 */
8433
Bram Moolenaar53744302015-07-17 17:38:22 +02008434 /* after handling side effects, call autocommand */
8435
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436 options[opt_idx].flags |= P_WAS_SET;
8437
Bram Moolenaar53744302015-07-17 17:38:22 +02008438#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8439 if (!starting)
8440 {
8441 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008442 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8443 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8444 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008445 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8446 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8447 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8448 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8449 reset_v_option_vars();
8450 }
8451#endif
8452
Bram Moolenaar071d4272004-06-13 20:20:40 +00008453 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008454 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008455 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008456 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457 check_redraw(options[opt_idx].flags);
8458
8459 return NULL;
8460}
8461
8462/*
8463 * Set the value of a number option, and take care of side effects.
8464 * Returns NULL for success, or an error message for an error.
8465 */
8466 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008467set_num_option(
8468 int opt_idx, /* index in options[] table */
8469 char_u *varp, /* pointer to the option variable */
8470 long value, /* new value */
8471 char_u *errbuf, /* buffer for error messages */
8472 size_t errbuflen, /* length of "errbuf" */
8473 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 OPT_MODELINE */
8475{
8476 char_u *errmsg = NULL;
8477 long old_value = *(long *)varp;
8478 long old_Rows = Rows; /* remember old Rows */
8479 long old_Columns = Columns; /* remember old Columns */
8480 long *pp = (long *)varp;
8481
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008482 /* Disallow changing some options from secure mode. */
8483 if ((secure
8484#ifdef HAVE_SANDBOX
8485 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008487 ) && (options[opt_idx].flags & P_SECURE))
8488 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489
8490 *pp = value;
8491#ifdef FEAT_EVAL
8492 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008493 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008494#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008495#ifdef FEAT_GUI
8496 need_mouse_correct = TRUE;
8497#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008498
Bram Moolenaar14f24742012-08-08 18:01:05 +02008499 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500 {
8501 errmsg = e_positive;
8502 curbuf->b_p_sw = curbuf->b_p_ts;
8503 }
8504
8505 /*
8506 * Number options that need some action when changed
8507 */
8508#ifdef FEAT_WINDOWS
8509 if (pp == &p_wh || pp == &p_hh)
8510 {
8511 if (p_wh < 1)
8512 {
8513 errmsg = e_positive;
8514 p_wh = 1;
8515 }
8516 if (p_wmh > p_wh)
8517 {
8518 errmsg = e_winheight;
8519 p_wh = p_wmh;
8520 }
8521 if (p_hh < 0)
8522 {
8523 errmsg = e_positive;
8524 p_hh = 0;
8525 }
8526
8527 /* Change window height NOW */
8528 if (lastwin != firstwin)
8529 {
8530 if (pp == &p_wh && curwin->w_height < p_wh)
8531 win_setheight((int)p_wh);
8532 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8533 win_setheight((int)p_hh);
8534 }
8535 }
8536
8537 /* 'winminheight' */
8538 else if (pp == &p_wmh)
8539 {
8540 if (p_wmh < 0)
8541 {
8542 errmsg = e_positive;
8543 p_wmh = 0;
8544 }
8545 if (p_wmh > p_wh)
8546 {
8547 errmsg = e_winheight;
8548 p_wmh = p_wh;
8549 }
8550 win_setminheight();
8551 }
8552
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008553# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008554 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008555 {
8556 if (p_wiw < 1)
8557 {
8558 errmsg = e_positive;
8559 p_wiw = 1;
8560 }
8561 if (p_wmw > p_wiw)
8562 {
8563 errmsg = e_winwidth;
8564 p_wiw = p_wmw;
8565 }
8566
8567 /* Change window width NOW */
8568 if (lastwin != firstwin && curwin->w_width < p_wiw)
8569 win_setwidth((int)p_wiw);
8570 }
8571
8572 /* 'winminwidth' */
8573 else if (pp == &p_wmw)
8574 {
8575 if (p_wmw < 0)
8576 {
8577 errmsg = e_positive;
8578 p_wmw = 0;
8579 }
8580 if (p_wmw > p_wiw)
8581 {
8582 errmsg = e_winwidth;
8583 p_wmw = p_wiw;
8584 }
8585 win_setminheight();
8586 }
8587# endif
8588
8589#endif
8590
8591#ifdef FEAT_WINDOWS
8592 /* (re)set last window status line */
8593 else if (pp == &p_ls)
8594 {
8595 last_status(FALSE);
8596 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008597
8598 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008599 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008600 {
8601 shell_new_rows(); /* recompute window positions and heights */
8602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008603#endif
8604
8605#ifdef FEAT_GUI
8606 else if (pp == &p_linespace)
8607 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008608 /* Recompute gui.char_height and resize the Vim window to keep the
8609 * same number of lines. */
8610 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008611 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008612 }
8613#endif
8614
8615#ifdef FEAT_FOLDING
8616 /* 'foldlevel' */
8617 else if (pp == &curwin->w_p_fdl)
8618 {
8619 if (curwin->w_p_fdl < 0)
8620 curwin->w_p_fdl = 0;
8621 newFoldLevel();
8622 }
8623
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008624 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 else if (pp == &curwin->w_p_fml)
8626 {
8627 foldUpdateAll(curwin);
8628 }
8629
8630 /* 'foldnestmax' */
8631 else if (pp == &curwin->w_p_fdn)
8632 {
8633 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8634 foldUpdateAll(curwin);
8635 }
8636
8637 /* 'foldcolumn' */
8638 else if (pp == &curwin->w_p_fdc)
8639 {
8640 if (curwin->w_p_fdc < 0)
8641 {
8642 errmsg = e_positive;
8643 curwin->w_p_fdc = 0;
8644 }
8645 else if (curwin->w_p_fdc > 12)
8646 {
8647 errmsg = e_invarg;
8648 curwin->w_p_fdc = 12;
8649 }
8650 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008651#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008653#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654 /* 'shiftwidth' or 'tabstop' */
8655 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8656 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008657# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008658 if (foldmethodIsIndent(curwin))
8659 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008660# endif
8661# ifdef FEAT_CINDENT
8662 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8663 * parse 'cinoptions'. */
8664 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8665 parse_cino(curbuf);
8666# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008667 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008668#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008669
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008670#ifdef FEAT_MBYTE
8671 /* 'maxcombine' */
8672 else if (pp == &p_mco)
8673 {
8674 if (p_mco > MAX_MCO)
8675 p_mco = MAX_MCO;
8676 else if (p_mco < 0)
8677 p_mco = 0;
8678 screenclear(); /* will re-allocate the screen */
8679 }
8680#endif
8681
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 else if (pp == &curbuf->b_p_iminsert)
8683 {
8684 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8685 {
8686 errmsg = e_invarg;
8687 curbuf->b_p_iminsert = B_IMODE_NONE;
8688 }
8689 p_iminsert = curbuf->b_p_iminsert;
8690 if (termcap_active) /* don't do this in the alternate screen */
8691 showmode();
8692#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8693 /* Show/unshow value of 'keymap' in status lines. */
8694 status_redraw_curbuf();
8695#endif
8696 }
8697
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008698 else if (pp == &p_window)
8699 {
8700 if (p_window < 1)
8701 p_window = 1;
8702 else if (p_window >= Rows)
8703 p_window = Rows - 1;
8704 }
8705
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706 else if (pp == &curbuf->b_p_imsearch)
8707 {
8708 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8709 {
8710 errmsg = e_invarg;
8711 curbuf->b_p_imsearch = B_IMODE_NONE;
8712 }
8713 p_imsearch = curbuf->b_p_imsearch;
8714 }
8715
8716#ifdef FEAT_TITLE
8717 /* if 'titlelen' has changed, redraw the title */
8718 else if (pp == &p_titlelen)
8719 {
8720 if (p_titlelen < 0)
8721 {
8722 errmsg = e_positive;
8723 p_titlelen = 85;
8724 }
8725 if (starting != NO_SCREEN && old_value != p_titlelen)
8726 need_maketitle = TRUE;
8727 }
8728#endif
8729
8730 /* if p_ch changed value, change the command line height */
8731 else if (pp == &p_ch)
8732 {
8733 if (p_ch < 1)
8734 {
8735 errmsg = e_positive;
8736 p_ch = 1;
8737 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008738 if (p_ch > Rows - min_rows() + 1)
8739 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740
8741 /* Only compute the new window layout when startup has been
8742 * completed. Otherwise the frame sizes may be wrong. */
8743 if (p_ch != old_value && full_screen
8744#ifdef FEAT_GUI
8745 && !gui.starting
8746#endif
8747 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008748 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008749 }
8750
8751 /* when 'updatecount' changes from zero to non-zero, open swap files */
8752 else if (pp == &p_uc)
8753 {
8754 if (p_uc < 0)
8755 {
8756 errmsg = e_positive;
8757 p_uc = 100;
8758 }
8759 if (p_uc && !old_value)
8760 ml_open_files();
8761 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008762#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008763 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008764 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008765 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008766 {
8767 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008768 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008769 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008770 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008771 {
8772 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008773 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008774 }
8775 }
8776#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008777#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008778 else if (pp == &p_mzq)
8779 mzvim_reset_timer();
8780#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781
8782 /* sync undo before 'undolevels' changes */
8783 else if (pp == &p_ul)
8784 {
8785 /* use the old value, otherwise u_sync() may not work properly */
8786 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008787 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008788 p_ul = value;
8789 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008790 else if (pp == &curbuf->b_p_ul)
8791 {
8792 /* use the old value, otherwise u_sync() may not work properly */
8793 curbuf->b_p_ul = old_value;
8794 u_sync(TRUE);
8795 curbuf->b_p_ul = value;
8796 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008798#ifdef FEAT_LINEBREAK
8799 /* 'numberwidth' must be positive */
8800 else if (pp == &curwin->w_p_nuw)
8801 {
8802 if (curwin->w_p_nuw < 1)
8803 {
8804 errmsg = e_positive;
8805 curwin->w_p_nuw = 1;
8806 }
8807 if (curwin->w_p_nuw > 10)
8808 {
8809 errmsg = e_invarg;
8810 curwin->w_p_nuw = 10;
8811 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008812 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008813 }
8814#endif
8815
Bram Moolenaar1a384422010-07-14 19:53:30 +02008816 else if (pp == &curbuf->b_p_tw)
8817 {
8818 if (curbuf->b_p_tw < 0)
8819 {
8820 errmsg = e_positive;
8821 curbuf->b_p_tw = 0;
8822 }
8823#ifdef FEAT_SYN_HL
8824# ifdef FEAT_WINDOWS
8825 {
8826 win_T *wp;
8827 tabpage_T *tp;
8828
8829 FOR_ALL_TAB_WINDOWS(tp, wp)
8830 check_colorcolumn(wp);
8831 }
8832# else
8833 check_colorcolumn(curwin);
8834# endif
8835#endif
8836 }
8837
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 /*
8839 * Check the bounds for numeric options here
8840 */
8841 if (Rows < min_rows() && full_screen)
8842 {
8843 if (errbuf != NULL)
8844 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008845 vim_snprintf((char *)errbuf, errbuflen,
8846 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008847 errmsg = errbuf;
8848 }
8849 Rows = min_rows();
8850 }
8851 if (Columns < MIN_COLUMNS && full_screen)
8852 {
8853 if (errbuf != NULL)
8854 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008855 vim_snprintf((char *)errbuf, errbuflen,
8856 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 errmsg = errbuf;
8858 }
8859 Columns = MIN_COLUMNS;
8860 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008861 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862
Bram Moolenaar071d4272004-06-13 20:20:40 +00008863 /*
8864 * If the screen (shell) height has been changed, assume it is the
8865 * physical screenheight.
8866 */
8867 if (old_Rows != Rows || old_Columns != Columns)
8868 {
8869 /* Changing the screen size is not allowed while updating the screen. */
8870 if (updating_screen)
8871 *pp = old_value;
8872 else if (full_screen
8873#ifdef FEAT_GUI
8874 && !gui.starting
8875#endif
8876 )
8877 set_shellsize((int)Columns, (int)Rows, TRUE);
8878 else
8879 {
8880 /* Postpone the resizing; check the size and cmdline position for
8881 * messages. */
8882 check_shellsize();
8883 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8884 cmdline_row = Rows - p_ch;
8885 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008886 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008887 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008888 }
8889
Bram Moolenaar071d4272004-06-13 20:20:40 +00008890 if (curbuf->b_p_ts <= 0)
8891 {
8892 errmsg = e_positive;
8893 curbuf->b_p_ts = 8;
8894 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008895 if (p_tm < 0)
8896 {
8897 errmsg = e_positive;
8898 p_tm = 0;
8899 }
8900 if ((curwin->w_p_scr <= 0
8901 || (curwin->w_p_scr > curwin->w_height
8902 && curwin->w_height > 0))
8903 && full_screen)
8904 {
8905 if (pp == &(curwin->w_p_scr))
8906 {
8907 if (curwin->w_p_scr != 0)
8908 errmsg = e_scroll;
8909 win_comp_scroll(curwin);
8910 }
8911 /* If 'scroll' became invalid because of a side effect silently adjust
8912 * it. */
8913 else if (curwin->w_p_scr <= 0)
8914 curwin->w_p_scr = 1;
8915 else /* curwin->w_p_scr > curwin->w_height */
8916 curwin->w_p_scr = curwin->w_height;
8917 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008918 if (p_hi < 0)
8919 {
8920 errmsg = e_positive;
8921 p_hi = 0;
8922 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008923 else if (p_hi > 10000)
8924 {
8925 errmsg = e_invarg;
8926 p_hi = 10000;
8927 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008928 if (p_re < 0 || p_re > 2)
8929 {
8930 errmsg = e_invarg;
8931 p_re = 0;
8932 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008933 if (p_report < 0)
8934 {
8935 errmsg = e_positive;
8936 p_report = 1;
8937 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008938 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 {
8940 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8941 p_sj = Rows / 2;
8942 else
8943 {
8944 errmsg = e_scroll;
8945 p_sj = 1;
8946 }
8947 }
8948 if (p_so < 0 && full_screen)
8949 {
8950 errmsg = e_scroll;
8951 p_so = 0;
8952 }
8953 if (p_siso < 0 && full_screen)
8954 {
8955 errmsg = e_positive;
8956 p_siso = 0;
8957 }
8958#ifdef FEAT_CMDWIN
8959 if (p_cwh < 1)
8960 {
8961 errmsg = e_positive;
8962 p_cwh = 1;
8963 }
8964#endif
8965 if (p_ut < 0)
8966 {
8967 errmsg = e_positive;
8968 p_ut = 2000;
8969 }
8970 if (p_ss < 0)
8971 {
8972 errmsg = e_positive;
8973 p_ss = 0;
8974 }
8975
8976 /* May set global value for local option. */
8977 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8978 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8979
8980 options[opt_idx].flags |= P_WAS_SET;
8981
Bram Moolenaar53744302015-07-17 17:38:22 +02008982#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8983 if (!starting && errmsg == NULL)
8984 {
8985 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008986 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8987 vim_snprintf((char *)buf_new, 10, "%ld", value);
8988 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008989 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8990 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8991 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8992 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8993 reset_v_option_vars();
8994 }
8995#endif
8996
Bram Moolenaar071d4272004-06-13 20:20:40 +00008997 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008998 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008999 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009000 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009001 check_redraw(options[opt_idx].flags);
9002
9003 return errmsg;
9004}
9005
9006/*
9007 * Called after an option changed: check if something needs to be redrawn.
9008 */
9009 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009010check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009011{
9012 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009013 int doclear = (flags & P_RCLR) == P_RCLR;
9014 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009015
9016#ifdef FEAT_WINDOWS
9017 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9018 status_redraw_all();
9019#endif
9020
9021 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9022 changed_window_setting();
9023 if (flags & P_RBUF)
9024 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009025 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009026 redraw_all_later(CLEAR);
9027 else if (all)
9028 redraw_all_later(NOT_VALID);
9029}
9030
9031/*
9032 * Find index for option 'arg'.
9033 * Return -1 if not found.
9034 */
9035 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009036findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037{
9038 int opt_idx;
9039 char *s, *p;
9040 static short quick_tab[27] = {0, 0}; /* quick access table */
9041 int is_term_opt;
9042
9043 /*
9044 * For first call: Initialize the quick-access table.
9045 * It contains the index for the first option that starts with a certain
9046 * letter. There are 26 letters, plus the first "t_" option.
9047 */
9048 if (quick_tab[1] == 0)
9049 {
9050 p = options[0].fullname;
9051 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9052 {
9053 if (s[0] != p[0])
9054 {
9055 if (s[0] == 't' && s[1] == '_')
9056 quick_tab[26] = opt_idx;
9057 else
9058 quick_tab[CharOrdLow(s[0])] = opt_idx;
9059 }
9060 p = s;
9061 }
9062 }
9063
9064 /*
9065 * Check for name starting with an illegal character.
9066 */
9067#ifdef EBCDIC
9068 if (!islower(arg[0]))
9069#else
9070 if (arg[0] < 'a' || arg[0] > 'z')
9071#endif
9072 return -1;
9073
9074 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9075 if (is_term_opt)
9076 opt_idx = quick_tab[26];
9077 else
9078 opt_idx = quick_tab[CharOrdLow(arg[0])];
9079 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9080 {
9081 if (STRCMP(arg, s) == 0) /* match full name */
9082 break;
9083 }
9084 if (s == NULL && !is_term_opt)
9085 {
9086 opt_idx = quick_tab[CharOrdLow(arg[0])];
9087 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9088 {
9089 s = options[opt_idx].shortname;
9090 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9091 break;
9092 s = NULL;
9093 }
9094 }
9095 if (s == NULL)
9096 opt_idx = -1;
9097 return opt_idx;
9098}
9099
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009100#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009101/*
9102 * Get the value for an option.
9103 *
9104 * Returns:
9105 * Number or Toggle option: 1, *numval gets value.
9106 * String option: 0, *stringval gets allocated string.
9107 * Hidden Number or Toggle option: -1.
9108 * hidden String option: -2.
9109 * unknown option: -3.
9110 */
9111 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009112get_option_value(
9113 char_u *name,
9114 long *numval,
9115 char_u **stringval, /* NULL when only checking existence */
9116 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117{
9118 int opt_idx;
9119 char_u *varp;
9120
9121 opt_idx = findoption(name);
9122 if (opt_idx < 0) /* unknown option */
9123 return -3;
9124
9125 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9126
9127 if (options[opt_idx].flags & P_STRING)
9128 {
9129 if (varp == NULL) /* hidden option */
9130 return -2;
9131 if (stringval != NULL)
9132 {
9133#ifdef FEAT_CRYPT
9134 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009135 if ((char_u **)varp == &curbuf->b_p_key
9136 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009137 *stringval = vim_strsave((char_u *)"*****");
9138 else
9139#endif
9140 *stringval = vim_strsave(*(char_u **)(varp));
9141 }
9142 return 0;
9143 }
9144
9145 if (varp == NULL) /* hidden option */
9146 return -1;
9147 if (options[opt_idx].flags & P_NUM)
9148 *numval = *(long *)varp;
9149 else
9150 {
9151 /* Special case: 'modified' is b_changed, but we also want to consider
9152 * it set when 'ff' or 'fenc' changed. */
9153 if ((int *)varp == &curbuf->b_changed)
9154 *numval = curbufIsChanged();
9155 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009156 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157 }
9158 return 1;
9159}
9160#endif
9161
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009162#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009163/*
9164 * Returns the option attributes and its value. Unlike the above function it
9165 * will return either global value or local value of the option depending on
9166 * what was requested, but it will never return global value if it was
9167 * requested to return local one and vice versa. Neither it will return
9168 * buffer-local value if it was requested to return window-local one.
9169 *
9170 * Pretends that option is absent if it is not present in the requested scope
9171 * (i.e. has no global, window-local or buffer-local value depending on
9172 * opt_type). Uses
9173 *
9174 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009175 * 0 hidden or unknown option, also option that does not have requested
9176 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009177 * see SOPT_* in vim.h for other flags
9178 *
9179 * Possible opt_type values: see SREQ_* in vim.h
9180 */
9181 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009182get_option_value_strict(
9183 char_u *name,
9184 long *numval,
9185 char_u **stringval, /* NULL when only obtaining attributes */
9186 int opt_type,
9187 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009188{
9189 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009190 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009191 struct vimoption *p;
9192 int r = 0;
9193
9194 opt_idx = findoption(name);
9195 if (opt_idx < 0)
9196 return 0;
9197
9198 p = &(options[opt_idx]);
9199
9200 /* Hidden option */
9201 if (p->var == NULL)
9202 return 0;
9203
9204 if (p->flags & P_BOOL)
9205 r |= SOPT_BOOL;
9206 else if (p->flags & P_NUM)
9207 r |= SOPT_NUM;
9208 else if (p->flags & P_STRING)
9209 r |= SOPT_STRING;
9210
9211 if (p->indir == PV_NONE)
9212 {
9213 if (opt_type == SREQ_GLOBAL)
9214 r |= SOPT_GLOBAL;
9215 else
9216 return 0; /* Did not request global-only option */
9217 }
9218 else
9219 {
9220 if (p->indir & PV_BOTH)
9221 r |= SOPT_GLOBAL;
9222 else if (opt_type == SREQ_GLOBAL)
9223 return 0; /* Requested global option */
9224
9225 if (p->indir & PV_WIN)
9226 {
9227 if (opt_type == SREQ_BUF)
9228 return 0; /* Did not request window-local option */
9229 else
9230 r |= SOPT_WIN;
9231 }
9232 else if (p->indir & PV_BUF)
9233 {
9234 if (opt_type == SREQ_WIN)
9235 return 0; /* Did not request buffer-local option */
9236 else
9237 r |= SOPT_BUF;
9238 }
9239 }
9240
9241 if (stringval == NULL)
9242 return r;
9243
9244 if (opt_type == SREQ_GLOBAL)
9245 varp = p->var;
9246 else
9247 {
9248 if (opt_type == SREQ_BUF)
9249 {
9250 /* Special case: 'modified' is b_changed, but we also want to
9251 * consider it set when 'ff' or 'fenc' changed. */
9252 if (p->indir == PV_MOD)
9253 {
9254 *numval = bufIsChanged((buf_T *) from);
9255 varp = NULL;
9256 }
9257#ifdef FEAT_CRYPT
9258 else if (p->indir == PV_KEY)
9259 {
9260 /* never return the value of the crypt key */
9261 *stringval = NULL;
9262 varp = NULL;
9263 }
9264#endif
9265 else
9266 {
9267 aco_save_T aco;
9268 aucmd_prepbuf(&aco, (buf_T *) from);
9269 varp = get_varp(p);
9270 aucmd_restbuf(&aco);
9271 }
9272 }
9273 else if (opt_type == SREQ_WIN)
9274 {
9275 win_T *save_curwin;
9276 save_curwin = curwin;
9277 curwin = (win_T *) from;
9278 curbuf = curwin->w_buffer;
9279 varp = get_varp(p);
9280 curwin = save_curwin;
9281 curbuf = curwin->w_buffer;
9282 }
9283 if (varp == p->var)
9284 return (r | SOPT_UNSET);
9285 }
9286
9287 if (varp != NULL)
9288 {
9289 if (p->flags & P_STRING)
9290 *stringval = vim_strsave(*(char_u **)(varp));
9291 else if (p->flags & P_NUM)
9292 *numval = *(long *) varp;
9293 else
9294 *numval = *(int *)varp;
9295 }
9296
9297 return r;
9298}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009299
9300/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009301 * Iterate over options. First argument is a pointer to a pointer to a
9302 * structure inside options[] array, second is option type like in the above
9303 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009304 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009305 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009306 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009307 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009308 * first argument to NULL.
9309 *
9310 * Returns full option name for current option on each call.
9311 */
9312 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009313option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009314{
9315 struct vimoption *ret = NULL;
9316 do
9317 {
9318 if (*option == NULL)
9319 *option = (void *) options;
9320 else if (((struct vimoption *) (*option))->fullname == NULL)
9321 {
9322 *option = NULL;
9323 return NULL;
9324 }
9325 else
9326 *option = (void *) (((struct vimoption *) (*option)) + 1);
9327
9328 ret = ((struct vimoption *) (*option));
9329
9330 /* Hidden option */
9331 if (ret->var == NULL)
9332 {
9333 ret = NULL;
9334 continue;
9335 }
9336
9337 switch (opt_type)
9338 {
9339 case SREQ_GLOBAL:
9340 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9341 ret = NULL;
9342 break;
9343 case SREQ_BUF:
9344 if (!(ret->indir & PV_BUF))
9345 ret = NULL;
9346 break;
9347 case SREQ_WIN:
9348 if (!(ret->indir & PV_WIN))
9349 ret = NULL;
9350 break;
9351 default:
9352 EMSG2(_(e_intern2), "option_iter_next()");
9353 return NULL;
9354 }
9355 }
9356 while (ret == NULL);
9357
9358 return (char_u *)ret->fullname;
9359}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009360#endif
9361
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362/*
9363 * Set the value of option "name".
9364 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009365 *
9366 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009368 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009369set_option_value(
9370 char_u *name,
9371 long number,
9372 char_u *string,
9373 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009374{
9375 int opt_idx;
9376 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009377 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009378
9379 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009380 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009381 EMSG2(_("E355: Unknown option: %s"), name);
9382 else
9383 {
9384 flags = options[opt_idx].flags;
9385#ifdef HAVE_SANDBOX
9386 /* Disallow changing some options in the sandbox */
9387 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009388 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009389 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009390 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009391 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009392#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009393 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009394 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009395 else
9396 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009397 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009398 if (varp != NULL) /* hidden option is not changed */
9399 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009400 if (number == 0 && string != NULL)
9401 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009402 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009403
9404 /* Either we are given a string or we are setting option
9405 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009406 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009407 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009408 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009409 {
9410 /* There's another character after zeros or the string
9411 * is empty. In both cases, we are trying to set a
9412 * num option using a string. */
9413 EMSG3(_("E521: Number required: &%s = '%s'"),
9414 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009415 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009416
9417 }
9418 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009419 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009420 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009421 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009422 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009423 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009424 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425 }
9426 }
9427 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009428 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009429}
9430
9431/*
9432 * Get the terminal code for a terminal option.
9433 * Returns NULL when not found.
9434 */
9435 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009436get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009437{
9438 int opt_idx;
9439 char_u *varp;
9440
9441 if (tname[0] != 't' || tname[1] != '_' ||
9442 tname[2] == NUL || tname[3] == NUL)
9443 return NULL;
9444 if ((opt_idx = findoption(tname)) >= 0)
9445 {
9446 varp = get_varp(&(options[opt_idx]));
9447 if (varp != NULL)
9448 varp = *(char_u **)(varp);
9449 return varp;
9450 }
9451 return find_termcode(tname + 2);
9452}
9453
9454 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009455get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009456{
9457 int i;
9458
9459 i = findoption((char_u *)"hl");
9460 if (i >= 0)
9461 return options[i].def_val[VI_DEFAULT];
9462 return (char_u *)NULL;
9463}
9464
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009465#if defined(FEAT_MBYTE) || defined(PROTO)
9466 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009467get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009468{
9469 int i;
9470
9471 i = findoption((char_u *)"enc");
9472 if (i >= 0)
9473 return options[i].def_val[VI_DEFAULT];
9474 return (char_u *)NULL;
9475}
9476#endif
9477
Bram Moolenaar071d4272004-06-13 20:20:40 +00009478/*
9479 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9480 */
9481 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009482find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009483{
9484 int key;
9485 int modifiers;
9486
9487 /*
9488 * Don't use get_special_key_code() for t_xx, we don't want it to call
9489 * add_termcap_entry().
9490 */
9491 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9492 key = TERMCAP2KEY(arg[2], arg[3]);
9493 else
9494 {
9495 --arg; /* put arg at the '<' */
9496 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009497 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009498 if (modifiers) /* can't handle modifiers here */
9499 key = 0;
9500 }
9501 return key;
9502}
9503
9504/*
9505 * if 'all' == 0: show changed options
9506 * if 'all' == 1: show all normal options
9507 * if 'all' == 2: show all terminal options
9508 */
9509 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009510showoptions(
9511 int all,
9512 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009513{
9514 struct vimoption *p;
9515 int col;
9516 int isterm;
9517 char_u *varp;
9518 struct vimoption **items;
9519 int item_count;
9520 int run;
9521 int row, rows;
9522 int cols;
9523 int i;
9524 int len;
9525
9526#define INC 20
9527#define GAP 3
9528
9529 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9530 PARAM_COUNT));
9531 if (items == NULL)
9532 return;
9533
9534 /* Highlight title */
9535 if (all == 2)
9536 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9537 else if (opt_flags & OPT_GLOBAL)
9538 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9539 else if (opt_flags & OPT_LOCAL)
9540 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9541 else
9542 MSG_PUTS_TITLE(_("\n--- Options ---"));
9543
9544 /*
9545 * do the loop two times:
9546 * 1. display the short items
9547 * 2. display the long items (only strings and numbers)
9548 */
9549 for (run = 1; run <= 2 && !got_int; ++run)
9550 {
9551 /*
9552 * collect the items in items[]
9553 */
9554 item_count = 0;
9555 for (p = &options[0]; p->fullname != NULL; p++)
9556 {
9557 varp = NULL;
9558 isterm = istermoption(p);
9559 if (opt_flags != 0)
9560 {
9561 if (p->indir != PV_NONE && !isterm)
9562 varp = get_varp_scope(p, opt_flags);
9563 }
9564 else
9565 varp = get_varp(p);
9566 if (varp != NULL
9567 && ((all == 2 && isterm)
9568 || (all == 1 && !isterm)
9569 || (all == 0 && !optval_default(p, varp))))
9570 {
9571 if (p->flags & P_BOOL)
9572 len = 1; /* a toggle option fits always */
9573 else
9574 {
9575 option_value2string(p, opt_flags);
9576 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9577 }
9578 if ((len <= INC - GAP && run == 1) ||
9579 (len > INC - GAP && run == 2))
9580 items[item_count++] = p;
9581 }
9582 }
9583
9584 /*
9585 * display the items
9586 */
9587 if (run == 1)
9588 {
9589 cols = (Columns + GAP - 3) / INC;
9590 if (cols == 0)
9591 cols = 1;
9592 rows = (item_count + cols - 1) / cols;
9593 }
9594 else /* run == 2 */
9595 rows = item_count;
9596 for (row = 0; row < rows && !got_int; ++row)
9597 {
9598 msg_putchar('\n'); /* go to next line */
9599 if (got_int) /* 'q' typed in more */
9600 break;
9601 col = 0;
9602 for (i = row; i < item_count; i += rows)
9603 {
9604 msg_col = col; /* make columns */
9605 showoneopt(items[i], opt_flags);
9606 col += INC;
9607 }
9608 out_flush();
9609 ui_breakcheck();
9610 }
9611 }
9612 vim_free(items);
9613}
9614
9615/*
9616 * Return TRUE if option "p" has its default value.
9617 */
9618 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009619optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620{
9621 int dvi;
9622
9623 if (varp == NULL)
9624 return TRUE; /* hidden option is always at default */
9625 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9626 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009627 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009628 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009629 /* the cast to long is required for Manx C, long_i is
9630 * needed for MSVC */
9631 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632 /* P_STRING */
9633 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9634}
9635
9636/*
9637 * showoneopt: show the value of one option
9638 * must not be called with a hidden option!
9639 */
9640 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009641showoneopt(
9642 struct vimoption *p,
9643 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009645 char_u *varp;
9646 int save_silent = silent_mode;
9647
9648 silent_mode = FALSE;
9649 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009650
9651 varp = get_varp_scope(p, opt_flags);
9652
9653 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9654 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9655 ? !curbufIsChanged() : !*(int *)varp))
9656 MSG_PUTS("no");
9657 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9658 MSG_PUTS("--");
9659 else
9660 MSG_PUTS(" ");
9661 MSG_PUTS(p->fullname);
9662 if (!(p->flags & P_BOOL))
9663 {
9664 msg_putchar('=');
9665 /* put value string in NameBuff */
9666 option_value2string(p, opt_flags);
9667 msg_outtrans(NameBuff);
9668 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009669
9670 silent_mode = save_silent;
9671 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009672}
9673
9674/*
9675 * Write modified options as ":set" commands to a file.
9676 *
9677 * There are three values for "opt_flags":
9678 * OPT_GLOBAL: Write global option values and fresh values of
9679 * buffer-local options (used for start of a session
9680 * file).
9681 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9682 * curwin (used for a vimrc file).
9683 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9684 * and local values for window-local options of
9685 * curwin. Local values are also written when at the
9686 * default value, because a modeline or autocommand
9687 * may have set them when doing ":edit file" and the
9688 * user has set them back at the default or fresh
9689 * value.
9690 * When "local_only" is TRUE, don't write fresh
9691 * values, only local values (for ":mkview").
9692 * (fresh value = value used for a new buffer or window for a local option).
9693 *
9694 * Return FAIL on error, OK otherwise.
9695 */
9696 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009697makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009698{
9699 struct vimoption *p;
9700 char_u *varp; /* currently used value */
9701 char_u *varp_fresh; /* local value */
9702 char_u *varp_local = NULL; /* fresh value */
9703 char *cmd;
9704 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009705 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009706
9707 /*
9708 * The options that don't have a default (terminal name, columns, lines)
9709 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009710 * Do the loop over "options[]" twice: once for options with the
9711 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009712 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009713 for (pri = 1; pri >= 0; --pri)
9714 {
9715 for (p = &options[0]; !istermoption(p); p++)
9716 if (!(p->flags & P_NO_MKRC)
9717 && !istermoption(p)
9718 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009719 {
9720 /* skip global option when only doing locals */
9721 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9722 continue;
9723
9724 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9725 * file, they are always buffer-specific. */
9726 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9727 continue;
9728
9729 /* Global values are only written when not at the default value. */
9730 varp = get_varp_scope(p, opt_flags);
9731 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9732 continue;
9733
9734 round = 2;
9735 if (p->indir != PV_NONE)
9736 {
9737 if (p->var == VAR_WIN)
9738 {
9739 /* skip window-local option when only doing globals */
9740 if (!(opt_flags & OPT_LOCAL))
9741 continue;
9742 /* When fresh value of window-local option is not at the
9743 * default, need to write it too. */
9744 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9745 {
9746 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9747 if (!optval_default(p, varp_fresh))
9748 {
9749 round = 1;
9750 varp_local = varp;
9751 varp = varp_fresh;
9752 }
9753 }
9754 }
9755 }
9756
9757 /* Round 1: fresh value for window-local options.
9758 * Round 2: other values */
9759 for ( ; round <= 2; varp = varp_local, ++round)
9760 {
9761 if (round == 1 || (opt_flags & OPT_GLOBAL))
9762 cmd = "set";
9763 else
9764 cmd = "setlocal";
9765
9766 if (p->flags & P_BOOL)
9767 {
9768 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9769 return FAIL;
9770 }
9771 else if (p->flags & P_NUM)
9772 {
9773 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9774 return FAIL;
9775 }
9776 else /* P_STRING */
9777 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009778#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9779 int do_endif = FALSE;
9780
Bram Moolenaar071d4272004-06-13 20:20:40 +00009781 /* Don't set 'syntax' and 'filetype' again if the value is
9782 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009783 if (
9784# if defined(FEAT_SYN_HL)
9785 p->indir == PV_SYN
9786# if defined(FEAT_AUTOCMD)
9787 ||
9788# endif
9789# endif
9790# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009791 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009792# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009793 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009794 {
9795 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9796 *(char_u **)(varp)) < 0
9797 || put_eol(fd) < 0)
9798 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009799 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009800 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009802 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9803 (p->flags & P_EXPAND) != 0) == FAIL)
9804 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009805#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9806 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009807 {
9808 if (put_line(fd, "endif") == FAIL)
9809 return FAIL;
9810 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009811#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009812 }
9813 }
9814 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009815 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009816 return OK;
9817}
9818
9819#if defined(FEAT_FOLDING) || defined(PROTO)
9820/*
9821 * Generate set commands for the local fold options only. Used when
9822 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9823 */
9824 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009825makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009826{
9827 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9828# ifdef FEAT_EVAL
9829 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9830 == FAIL
9831# endif
9832 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9833 == FAIL
9834 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9835 == FAIL
9836 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9837 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9838 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9839 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9840 )
9841 return FAIL;
9842
9843 return OK;
9844}
9845#endif
9846
9847 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009848put_setstring(
9849 FILE *fd,
9850 char *cmd,
9851 char *name,
9852 char_u **valuep,
9853 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009854{
9855 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009856 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009857
9858 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9859 return FAIL;
9860 if (*valuep != NULL)
9861 {
9862 /* Output 'pastetoggle' as key names. For other
9863 * options some characters have to be escaped with
9864 * CTRL-V or backslash */
9865 if (valuep == &p_pt)
9866 {
9867 s = *valuep;
9868 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009869 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009870 return FAIL;
9871 }
9872 else if (expand)
9873 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009874 buf = alloc(MAXPATHL);
9875 if (buf == NULL)
9876 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9878 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009879 {
9880 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009881 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009882 }
9883 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009884 }
9885 else if (put_escstr(fd, *valuep, 2) == FAIL)
9886 return FAIL;
9887 }
9888 if (put_eol(fd) < 0)
9889 return FAIL;
9890 return OK;
9891}
9892
9893 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009894put_setnum(
9895 FILE *fd,
9896 char *cmd,
9897 char *name,
9898 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899{
9900 long wc;
9901
9902 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9903 return FAIL;
9904 if (wc_use_keyname((char_u *)valuep, &wc))
9905 {
9906 /* print 'wildchar' and 'wildcharm' as a key name */
9907 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9908 return FAIL;
9909 }
9910 else if (fprintf(fd, "%ld", *valuep) < 0)
9911 return FAIL;
9912 if (put_eol(fd) < 0)
9913 return FAIL;
9914 return OK;
9915}
9916
9917 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009918put_setbool(
9919 FILE *fd,
9920 char *cmd,
9921 char *name,
9922 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923{
Bram Moolenaar893de922007-10-02 18:40:57 +00009924 if (value < 0) /* global/local option using global value */
9925 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009926 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9927 || put_eol(fd) < 0)
9928 return FAIL;
9929 return OK;
9930}
9931
9932/*
9933 * Clear all the terminal options.
9934 * If the option has been allocated, free the memory.
9935 * Terminal options are never hidden or indirect.
9936 */
9937 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009938clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009939{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940 /*
9941 * Reset a few things before clearing the old options. This may cause
9942 * outputting a few things that the terminal doesn't understand, but the
9943 * screen will be cleared later, so this is OK.
9944 */
9945#ifdef FEAT_MOUSE_TTY
9946 mch_setmouse(FALSE); /* switch mouse off */
9947#endif
9948#ifdef FEAT_TITLE
9949 mch_restore_title(3); /* restore window titles */
9950#endif
9951#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9952 /* When starting the GUI close the display opened for the clipboard.
9953 * After restoring the title, because that will need the display. */
9954 if (gui.starting)
9955 clear_xterm_clip();
9956#endif
9957#ifdef WIN3264
9958 /*
9959 * Check if this is allowed now.
9960 */
9961 if (can_end_termcap_mode(FALSE) == TRUE)
9962#endif
9963 stoptermcap(); /* stop termcap mode */
9964
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009965 free_termoptions();
9966}
9967
9968 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009969free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009970{
9971 struct vimoption *p;
9972
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973 for (p = &options[0]; p->fullname != NULL; p++)
9974 if (istermoption(p))
9975 {
9976 if (p->flags & P_ALLOCED)
9977 free_string_option(*(char_u **)(p->var));
9978 if (p->flags & P_DEF_ALLOCED)
9979 free_string_option(p->def_val[VI_DEFAULT]);
9980 *(char_u **)(p->var) = empty_option;
9981 p->def_val[VI_DEFAULT] = empty_option;
9982 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9983 }
9984 clear_termcodes();
9985}
9986
9987/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009988 * Free the string for one term option, if it was allocated.
9989 * Set the string to empty_option and clear allocated flag.
9990 * "var" points to the option value.
9991 */
9992 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009993free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009994{
9995 struct vimoption *p;
9996
9997 for (p = &options[0]; p->fullname != NULL; p++)
9998 if (p->var == var)
9999 {
10000 if (p->flags & P_ALLOCED)
10001 free_string_option(*(char_u **)(p->var));
10002 *(char_u **)(p->var) = empty_option;
10003 p->flags &= ~P_ALLOCED;
10004 break;
10005 }
10006}
10007
10008/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010009 * Set the terminal option defaults to the current value.
10010 * Used after setting the terminal name.
10011 */
10012 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010013set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014{
10015 struct vimoption *p;
10016
10017 for (p = &options[0]; p->fullname != NULL; p++)
10018 {
10019 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10020 {
10021 if (p->flags & P_DEF_ALLOCED)
10022 {
10023 free_string_option(p->def_val[VI_DEFAULT]);
10024 p->flags &= ~P_DEF_ALLOCED;
10025 }
10026 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10027 if (p->flags & P_ALLOCED)
10028 {
10029 p->flags |= P_DEF_ALLOCED;
10030 p->flags &= ~P_ALLOCED; /* don't free the value now */
10031 }
10032 }
10033 }
10034}
10035
10036/*
10037 * return TRUE if 'p' starts with 't_'
10038 */
10039 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010040istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010041{
10042 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10043}
10044
10045/*
10046 * Compute columns for ruler and shown command. 'sc_col' is also used to
10047 * decide what the maximum length of a message on the status line can be.
10048 * If there is a status line for the last window, 'sc_col' is independent
10049 * of 'ru_col'.
10050 */
10051
10052#define COL_RULER 17 /* columns needed by standard ruler */
10053
10054 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010055comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056{
10057#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10058 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10059
10060 sc_col = 0;
10061 ru_col = 0;
10062 if (p_ru)
10063 {
10064#ifdef FEAT_STL_OPT
10065 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10066#else
10067 ru_col = COL_RULER + 1;
10068#endif
10069 /* no last status line, adjust sc_col */
10070 if (!last_has_status)
10071 sc_col = ru_col;
10072 }
10073 if (p_sc)
10074 {
10075 sc_col += SHOWCMD_COLS;
10076 if (!p_ru || last_has_status) /* no need for separating space */
10077 ++sc_col;
10078 }
10079 sc_col = Columns - sc_col;
10080 ru_col = Columns - ru_col;
10081 if (sc_col <= 0) /* screen too narrow, will become a mess */
10082 sc_col = 1;
10083 if (ru_col <= 0)
10084 ru_col = 1;
10085#else
10086 sc_col = Columns;
10087 ru_col = Columns;
10088#endif
10089}
10090
10091/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010092 * Unset local option value, similar to ":set opt<".
10093 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010094 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010095unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010096{
10097 struct vimoption *p;
10098 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010099 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010100
10101 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010102 if (opt_idx < 0)
10103 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010104 p = &(options[opt_idx]);
10105
10106 switch ((int)p->indir)
10107 {
10108 /* global option with local value: use local value if it's been set */
10109 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010110 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010111 break;
10112 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010113 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010114 break;
10115 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010116 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010117 break;
10118 case PV_AR:
10119 buf->b_p_ar = -1;
10120 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010121 case PV_BKC:
10122 clear_string_option(&buf->b_p_bkc);
10123 buf->b_bkc_flags = 0;
10124 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010125 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010126 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010127 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010128 case PV_TC:
10129 clear_string_option(&buf->b_p_tc);
10130 buf->b_tc_flags = 0;
10131 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010132#ifdef FEAT_FIND_ID
10133 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010134 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010135 break;
10136 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010137 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010138 break;
10139#endif
10140#ifdef FEAT_INS_EXPAND
10141 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010142 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010143 break;
10144 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010145 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010146 break;
10147#endif
10148#ifdef FEAT_QUICKFIX
10149 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010150 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010151 break;
10152 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010153 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010154 break;
10155 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010156 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010157 break;
10158#endif
10159#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10160 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010161 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010162 break;
10163#endif
10164#if defined(FEAT_CRYPT)
10165 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010166 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010167 break;
10168#endif
10169#ifdef FEAT_STL_OPT
10170 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010171 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010172 break;
10173#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010174 case PV_UL:
10175 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10176 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010177#ifdef FEAT_LISP
10178 case PV_LW:
10179 clear_string_option(&buf->b_p_lw);
10180 break;
10181#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010182 }
10183}
10184
10185/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 * Get pointer to option variable, depending on local or global scope.
10187 */
10188 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010189get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190{
10191 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10192 {
10193 if (p->var == VAR_WIN)
10194 return (char_u *)GLOBAL_WO(get_varp(p));
10195 return p->var;
10196 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010197 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 {
10199 switch ((int)p->indir)
10200 {
10201#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010202 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10203 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10204 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010206 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10207 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10208 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010209 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010210 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010211 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010213 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10214 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215#endif
10216#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010217 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10218 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010220#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10221 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10222#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010223#if defined(FEAT_CRYPT)
10224 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10225#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010226#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010227 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010228#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010229 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010230#ifdef FEAT_LISP
10231 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10232#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010233 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234 }
10235 return NULL; /* "cannot happen" */
10236 }
10237 return get_varp(p);
10238}
10239
10240/*
10241 * Get pointer to option variable.
10242 */
10243 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010244get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010245{
10246 /* hidden option, always return NULL */
10247 if (p->var == NULL)
10248 return NULL;
10249
10250 switch ((int)p->indir)
10251 {
10252 case PV_NONE: return p->var;
10253
10254 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010255 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010257 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010258 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010259 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010261 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010263 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010265 case PV_TC: return *curbuf->b_p_tc != NUL
10266 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010267 case PV_BKC: return *curbuf->b_p_bkc != NUL
10268 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010270 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010272 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10274#endif
10275#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010276 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010277 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010278 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10280#endif
10281#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010282 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010283 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010284 case PV_GP: return *curbuf->b_p_gp != NUL
10285 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10286 case PV_MP: return *curbuf->b_p_mp != NUL
10287 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010288#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010289#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10290 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10291 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10292#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010293#if defined(FEAT_CRYPT)
10294 case PV_CM: return *curbuf->b_p_cm != NUL
10295 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10296#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010297#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010298 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010299 ? (char_u *)&(curwin->w_p_stl) : p->var;
10300#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010301 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10302 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010303#ifdef FEAT_LISP
10304 case PV_LW: return *curbuf->b_p_lw != NUL
10305 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307
10308#ifdef FEAT_ARABIC
10309 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10310#endif
10311 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010312#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010313 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10314#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010315#ifdef FEAT_SYN_HL
10316 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10317 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010318 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320#ifdef FEAT_DIFF
10321 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10322#endif
10323#ifdef FEAT_FOLDING
10324 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10325 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10326 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10327 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10328 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10329 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10330 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10331# ifdef FEAT_EVAL
10332 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10333 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10334# endif
10335 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10336#endif
10337 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010338 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010339#ifdef FEAT_LINEBREAK
10340 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10341#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010342#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010344 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10347 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10348#endif
10349#ifdef FEAT_RIGHTLEFT
10350 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10351 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10352#endif
10353 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10354 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10355#ifdef FEAT_LINEBREAK
10356 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010357 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10358 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010359#endif
10360#ifdef FEAT_SCROLLBIND
10361 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10362#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010363#ifdef FEAT_CURSORBIND
10364 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10365#endif
10366#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010367 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10368 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370
10371 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10372 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10373#ifdef FEAT_MBYTE
10374 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10375#endif
10376#if defined(FEAT_QUICKFIX)
10377 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10378 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10379#endif
10380 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10381 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10382#ifdef FEAT_CINDENT
10383 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10384 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10385 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10386#endif
10387#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10388 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10389#endif
10390#ifdef FEAT_COMMENTS
10391 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10392#endif
10393#ifdef FEAT_FOLDING
10394 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10395#endif
10396#ifdef FEAT_INS_EXPAND
10397 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10398#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010399#ifdef FEAT_COMPL_FUNC
10400 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010401 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010402#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010404 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010405 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10406#ifdef FEAT_MBYTE
10407 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10408#endif
10409 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10410#ifdef FEAT_AUTOCMD
10411 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10412#endif
10413 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010414 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10416 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10417 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10418 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10419#ifdef FEAT_FIND_ID
10420# ifdef FEAT_EVAL
10421 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10422# endif
10423#endif
10424#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10425 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10426 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10427#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010428#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010429 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10430#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431#ifdef FEAT_CRYPT
10432 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10433#endif
10434#ifdef FEAT_LISP
10435 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10436#endif
10437 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10438 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10439 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10440 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10441 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010442 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010443#ifdef FEAT_TEXTOBJ
10444 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10445#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010446 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10447#ifdef FEAT_SMARTINDENT
10448 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10449#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010450 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10452#ifdef FEAT_SEARCHPATH
10453 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10454#endif
10455 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10456#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010457 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010458 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10459#endif
10460#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010461 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10462 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10463 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010464#endif
10465 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10466 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10467 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10468 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010469#ifdef FEAT_PERSISTENT_UNDO
10470 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10471#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10473#ifdef FEAT_KEYMAP
10474 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10475#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010476#ifdef FEAT_SIGNS
10477 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10478#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010479 default: EMSG(_("E356: get_varp ERROR"));
10480 }
10481 /* always return a valid pointer to avoid a crash! */
10482 return (char_u *)&(curbuf->b_p_wm);
10483}
10484
10485/*
10486 * Get the value of 'equalprg', either the buffer-local one or the global one.
10487 */
10488 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010489get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490{
10491 if (*curbuf->b_p_ep == NUL)
10492 return p_ep;
10493 return curbuf->b_p_ep;
10494}
10495
10496#if defined(FEAT_WINDOWS) || defined(PROTO)
10497/*
10498 * Copy options from one window to another.
10499 * Used when splitting a window.
10500 */
10501 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010502win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010503{
10504 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10505 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10506# ifdef FEAT_RIGHTLEFT
10507# ifdef FEAT_FKMAP
10508 /* Is this right? */
10509 wp_to->w_farsi = wp_from->w_farsi;
10510# endif
10511# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010512#if defined(FEAT_LINEBREAK)
10513 briopt_check(wp_to);
10514#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515}
10516#endif
10517
10518/*
10519 * Copy the options from one winopt_T to another.
10520 * Doesn't free the old option values in "to", use clear_winopt() for that.
10521 * The 'scroll' option is not copied, because it depends on the window height.
10522 * The 'previewwindow' option is reset, there can be only one preview window.
10523 */
10524 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010525copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526{
10527#ifdef FEAT_ARABIC
10528 to->wo_arab = from->wo_arab;
10529#endif
10530 to->wo_list = from->wo_list;
10531 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010532 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010533#ifdef FEAT_LINEBREAK
10534 to->wo_nuw = from->wo_nuw;
10535#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536#ifdef FEAT_RIGHTLEFT
10537 to->wo_rl = from->wo_rl;
10538 to->wo_rlc = vim_strsave(from->wo_rlc);
10539#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010540#ifdef FEAT_STL_OPT
10541 to->wo_stl = vim_strsave(from->wo_stl);
10542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010544#ifdef FEAT_DIFF
10545 to->wo_wrap_save = from->wo_wrap_save;
10546#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547#ifdef FEAT_LINEBREAK
10548 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010549 to->wo_bri = from->wo_bri;
10550 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551#endif
10552#ifdef FEAT_SCROLLBIND
10553 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010554 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010556#ifdef FEAT_CURSORBIND
10557 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010558 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010559#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010560#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010561 to->wo_spell = from->wo_spell;
10562#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010563#ifdef FEAT_SYN_HL
10564 to->wo_cuc = from->wo_cuc;
10565 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010566 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010567#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568#ifdef FEAT_DIFF
10569 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010570 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010572#ifdef FEAT_CONCEAL
10573 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010574 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010575#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576#ifdef FEAT_FOLDING
10577 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010578 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010580 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 to->wo_fdi = vim_strsave(from->wo_fdi);
10582 to->wo_fml = from->wo_fml;
10583 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010584 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010586 to->wo_fdm_save = from->wo_diff_saved
10587 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588 to->wo_fdn = from->wo_fdn;
10589# ifdef FEAT_EVAL
10590 to->wo_fde = vim_strsave(from->wo_fde);
10591 to->wo_fdt = vim_strsave(from->wo_fdt);
10592# endif
10593 to->wo_fmr = vim_strsave(from->wo_fmr);
10594#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010595#ifdef FEAT_SIGNS
10596 to->wo_scl = vim_strsave(from->wo_scl);
10597#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010598 check_winopt(to); /* don't want NULL pointers */
10599}
10600
10601/*
10602 * Check string options in a window for a NULL value.
10603 */
10604 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010605check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606{
10607 check_winopt(&win->w_onebuf_opt);
10608 check_winopt(&win->w_allbuf_opt);
10609}
10610
10611/*
10612 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10613 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010614 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010615check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616{
10617#ifdef FEAT_FOLDING
10618 check_string_option(&wop->wo_fdi);
10619 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010620 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621# ifdef FEAT_EVAL
10622 check_string_option(&wop->wo_fde);
10623 check_string_option(&wop->wo_fdt);
10624# endif
10625 check_string_option(&wop->wo_fmr);
10626#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010627#ifdef FEAT_SIGNS
10628 check_string_option(&wop->wo_scl);
10629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630#ifdef FEAT_RIGHTLEFT
10631 check_string_option(&wop->wo_rlc);
10632#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010633#ifdef FEAT_STL_OPT
10634 check_string_option(&wop->wo_stl);
10635#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010636#ifdef FEAT_SYN_HL
10637 check_string_option(&wop->wo_cc);
10638#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010639#ifdef FEAT_CONCEAL
10640 check_string_option(&wop->wo_cocu);
10641#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010642#ifdef FEAT_LINEBREAK
10643 check_string_option(&wop->wo_briopt);
10644#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010645}
10646
10647/*
10648 * Free the allocated memory inside a winopt_T.
10649 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010650 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010651clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010652{
10653#ifdef FEAT_FOLDING
10654 clear_string_option(&wop->wo_fdi);
10655 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010656 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657# ifdef FEAT_EVAL
10658 clear_string_option(&wop->wo_fde);
10659 clear_string_option(&wop->wo_fdt);
10660# endif
10661 clear_string_option(&wop->wo_fmr);
10662#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010663#ifdef FEAT_SIGNS
10664 clear_string_option(&wop->wo_scl);
10665#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010666#ifdef FEAT_LINEBREAK
10667 clear_string_option(&wop->wo_briopt);
10668#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010669#ifdef FEAT_RIGHTLEFT
10670 clear_string_option(&wop->wo_rlc);
10671#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010672#ifdef FEAT_STL_OPT
10673 clear_string_option(&wop->wo_stl);
10674#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010675#ifdef FEAT_SYN_HL
10676 clear_string_option(&wop->wo_cc);
10677#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010678#ifdef FEAT_CONCEAL
10679 clear_string_option(&wop->wo_cocu);
10680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010681}
10682
10683/*
10684 * Copy global option values to local options for one buffer.
10685 * Used when creating a new buffer and sometimes when entering a buffer.
10686 * flags:
10687 * BCO_ENTER We will enter the buf buffer.
10688 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10689 * appropriate.
10690 * BCO_NOHELP Don't copy the values to a help buffer.
10691 */
10692 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010693buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010694{
10695 int should_copy = TRUE;
10696 char_u *save_p_isk = NULL; /* init for GCC */
10697 int dont_do_help;
10698 int did_isk = FALSE;
10699
10700 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010701 * Skip this when the option defaults have not been set yet. Happens when
10702 * main() allocates the first buffer.
10703 */
10704 if (p_cpo != NULL)
10705 {
10706 /*
10707 * Always copy when entering and 'cpo' contains 'S'.
10708 * Don't copy when already initialized.
10709 * Don't copy when 'cpo' contains 's' and not entering.
10710 * 'S' BCO_ENTER initialized 's' should_copy
10711 * yes yes X X TRUE
10712 * yes no yes X FALSE
10713 * no X yes X FALSE
10714 * X no no yes FALSE
10715 * X no no no TRUE
10716 * no yes no X TRUE
10717 */
10718 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10719 && (buf->b_p_initialized
10720 || (!(flags & BCO_ENTER)
10721 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10722 should_copy = FALSE;
10723
10724 if (should_copy || (flags & BCO_ALWAYS))
10725 {
10726 /* Don't copy the options specific to a help buffer when
10727 * BCO_NOHELP is given or the options were initialized already
10728 * (jumping back to a help file with CTRL-T or CTRL-O) */
10729 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10730 || buf->b_p_initialized;
10731 if (dont_do_help) /* don't free b_p_isk */
10732 {
10733 save_p_isk = buf->b_p_isk;
10734 buf->b_p_isk = NULL;
10735 }
10736 /*
10737 * Always free the allocated strings.
10738 * If not already initialized, set 'readonly' and copy 'fileformat'.
10739 */
10740 if (!buf->b_p_initialized)
10741 {
10742 free_buf_options(buf, TRUE);
10743 buf->b_p_ro = FALSE; /* don't copy readonly */
10744 buf->b_p_tx = p_tx;
10745#ifdef FEAT_MBYTE
10746 buf->b_p_fenc = vim_strsave(p_fenc);
10747#endif
10748 buf->b_p_ff = vim_strsave(p_ff);
10749#if defined(FEAT_QUICKFIX)
10750 buf->b_p_bh = empty_option;
10751 buf->b_p_bt = empty_option;
10752#endif
10753 }
10754 else
10755 free_buf_options(buf, FALSE);
10756
10757 buf->b_p_ai = p_ai;
10758 buf->b_p_ai_nopaste = p_ai_nopaste;
10759 buf->b_p_sw = p_sw;
10760 buf->b_p_tw = p_tw;
10761 buf->b_p_tw_nopaste = p_tw_nopaste;
10762 buf->b_p_tw_nobin = p_tw_nobin;
10763 buf->b_p_wm = p_wm;
10764 buf->b_p_wm_nopaste = p_wm_nopaste;
10765 buf->b_p_wm_nobin = p_wm_nobin;
10766 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010767#ifdef FEAT_MBYTE
10768 buf->b_p_bomb = p_bomb;
10769#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010770 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771 buf->b_p_et = p_et;
10772 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010773 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 buf->b_p_ml = p_ml;
10775 buf->b_p_ml_nobin = p_ml_nobin;
10776 buf->b_p_inf = p_inf;
10777 buf->b_p_swf = p_swf;
10778#ifdef FEAT_INS_EXPAND
10779 buf->b_p_cpt = vim_strsave(p_cpt);
10780#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010781#ifdef FEAT_COMPL_FUNC
10782 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010783 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785 buf->b_p_sts = p_sts;
10786 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010787 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788#ifdef FEAT_COMMENTS
10789 buf->b_p_com = vim_strsave(p_com);
10790#endif
10791#ifdef FEAT_FOLDING
10792 buf->b_p_cms = vim_strsave(p_cms);
10793#endif
10794 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010795 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796 buf->b_p_nf = vim_strsave(p_nf);
10797 buf->b_p_mps = vim_strsave(p_mps);
10798#ifdef FEAT_SMARTINDENT
10799 buf->b_p_si = p_si;
10800#endif
10801 buf->b_p_ci = p_ci;
10802#ifdef FEAT_CINDENT
10803 buf->b_p_cin = p_cin;
10804 buf->b_p_cink = vim_strsave(p_cink);
10805 buf->b_p_cino = vim_strsave(p_cino);
10806#endif
10807#ifdef FEAT_AUTOCMD
10808 /* Don't copy 'filetype', it must be detected */
10809 buf->b_p_ft = empty_option;
10810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 buf->b_p_pi = p_pi;
10812#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10813 buf->b_p_cinw = vim_strsave(p_cinw);
10814#endif
10815#ifdef FEAT_LISP
10816 buf->b_p_lisp = p_lisp;
10817#endif
10818#ifdef FEAT_SYN_HL
10819 /* Don't copy 'syntax', it must be set */
10820 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010821 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010822 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010823#endif
10824#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010825 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010826 (void)compile_cap_prog(&buf->b_s);
10827 buf->b_s.b_p_spf = vim_strsave(p_spf);
10828 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010829#endif
10830#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10831 buf->b_p_inde = vim_strsave(p_inde);
10832 buf->b_p_indk = vim_strsave(p_indk);
10833#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010834#if defined(FEAT_EVAL)
10835 buf->b_p_fex = vim_strsave(p_fex);
10836#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837#ifdef FEAT_CRYPT
10838 buf->b_p_key = vim_strsave(p_key);
10839#endif
10840#ifdef FEAT_SEARCHPATH
10841 buf->b_p_sua = vim_strsave(p_sua);
10842#endif
10843#ifdef FEAT_KEYMAP
10844 buf->b_p_keymap = vim_strsave(p_keymap);
10845 buf->b_kmap_state |= KEYMAP_INIT;
10846#endif
10847 /* This isn't really an option, but copying the langmap and IME
10848 * state from the current buffer is better than resetting it. */
10849 buf->b_p_iminsert = p_iminsert;
10850 buf->b_p_imsearch = p_imsearch;
10851
10852 /* options that are normally global but also have a local value
10853 * are not copied, start using the global value */
10854 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010855 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010856 buf->b_p_bkc = empty_option;
10857 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858#ifdef FEAT_QUICKFIX
10859 buf->b_p_gp = empty_option;
10860 buf->b_p_mp = empty_option;
10861 buf->b_p_efm = empty_option;
10862#endif
10863 buf->b_p_ep = empty_option;
10864 buf->b_p_kp = empty_option;
10865 buf->b_p_path = empty_option;
10866 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010867 buf->b_p_tc = empty_option;
10868 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869#ifdef FEAT_FIND_ID
10870 buf->b_p_def = empty_option;
10871 buf->b_p_inc = empty_option;
10872# ifdef FEAT_EVAL
10873 buf->b_p_inex = vim_strsave(p_inex);
10874# endif
10875#endif
10876#ifdef FEAT_INS_EXPAND
10877 buf->b_p_dict = empty_option;
10878 buf->b_p_tsr = empty_option;
10879#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010880#ifdef FEAT_TEXTOBJ
10881 buf->b_p_qe = vim_strsave(p_qe);
10882#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010883#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10884 buf->b_p_bexpr = empty_option;
10885#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010886#if defined(FEAT_CRYPT)
10887 buf->b_p_cm = empty_option;
10888#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010889#ifdef FEAT_PERSISTENT_UNDO
10890 buf->b_p_udf = p_udf;
10891#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010892#ifdef FEAT_LISP
10893 buf->b_p_lw = empty_option;
10894#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895
10896 /*
10897 * Don't copy the options set by ex_help(), use the saved values,
10898 * when going from a help buffer to a non-help buffer.
10899 * Don't touch these at all when BCO_NOHELP is used and going from
10900 * or to a help buffer.
10901 */
10902 if (dont_do_help)
10903 buf->b_p_isk = save_p_isk;
10904 else
10905 {
10906 buf->b_p_isk = vim_strsave(p_isk);
10907 did_isk = TRUE;
10908 buf->b_p_ts = p_ts;
10909 buf->b_help = FALSE;
10910#ifdef FEAT_QUICKFIX
10911 if (buf->b_p_bt[0] == 'h')
10912 clear_string_option(&buf->b_p_bt);
10913#endif
10914 buf->b_p_ma = p_ma;
10915 }
10916 }
10917
10918 /*
10919 * When the options should be copied (ignoring BCO_ALWAYS), set the
10920 * flag that indicates that the options have been initialized.
10921 */
10922 if (should_copy)
10923 buf->b_p_initialized = TRUE;
10924 }
10925
10926 check_buf_options(buf); /* make sure we don't have NULLs */
10927 if (did_isk)
10928 (void)buf_init_chartab(buf, FALSE);
10929}
10930
10931/*
10932 * Reset the 'modifiable' option and its default value.
10933 */
10934 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010935reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936{
10937 int opt_idx;
10938
10939 curbuf->b_p_ma = FALSE;
10940 p_ma = FALSE;
10941 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010942 if (opt_idx >= 0)
10943 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944}
10945
10946/*
10947 * Set the global value for 'iminsert' to the local value.
10948 */
10949 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010950set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010951{
10952 p_iminsert = curbuf->b_p_iminsert;
10953}
10954
10955/*
10956 * Set the global value for 'imsearch' to the local value.
10957 */
10958 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010959set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010960{
10961 p_imsearch = curbuf->b_p_imsearch;
10962}
10963
10964#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10965static int expand_option_idx = -1;
10966static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10967static int expand_option_flags = 0;
10968
10969 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010970set_context_in_set_cmd(
10971 expand_T *xp,
10972 char_u *arg,
10973 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010974{
10975 int nextchar;
10976 long_u flags = 0; /* init for GCC */
10977 int opt_idx = 0; /* init for GCC */
10978 char_u *p;
10979 char_u *s;
10980 int is_term_option = FALSE;
10981 int key;
10982
10983 expand_option_flags = opt_flags;
10984
10985 xp->xp_context = EXPAND_SETTINGS;
10986 if (*arg == NUL)
10987 {
10988 xp->xp_pattern = arg;
10989 return;
10990 }
10991 p = arg + STRLEN(arg) - 1;
10992 if (*p == ' ' && *(p - 1) != '\\')
10993 {
10994 xp->xp_pattern = p + 1;
10995 return;
10996 }
10997 while (p > arg)
10998 {
10999 s = p;
11000 /* count number of backslashes before ' ' or ',' */
11001 if (*p == ' ' || *p == ',')
11002 {
11003 while (s > arg && *(s - 1) == '\\')
11004 --s;
11005 }
11006 /* break at a space with an even number of backslashes */
11007 if (*p == ' ' && ((p - s) & 1) == 0)
11008 {
11009 ++p;
11010 break;
11011 }
11012 --p;
11013 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011014 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011015 {
11016 xp->xp_context = EXPAND_BOOL_SETTINGS;
11017 p += 2;
11018 }
11019 if (STRNCMP(p, "inv", 3) == 0)
11020 {
11021 xp->xp_context = EXPAND_BOOL_SETTINGS;
11022 p += 3;
11023 }
11024 xp->xp_pattern = arg = p;
11025 if (*arg == '<')
11026 {
11027 while (*p != '>')
11028 if (*p++ == NUL) /* expand terminal option name */
11029 return;
11030 key = get_special_key_code(arg + 1);
11031 if (key == 0) /* unknown name */
11032 {
11033 xp->xp_context = EXPAND_NOTHING;
11034 return;
11035 }
11036 nextchar = *++p;
11037 is_term_option = TRUE;
11038 expand_option_name[2] = KEY2TERMCAP0(key);
11039 expand_option_name[3] = KEY2TERMCAP1(key);
11040 }
11041 else
11042 {
11043 if (p[0] == 't' && p[1] == '_')
11044 {
11045 p += 2;
11046 if (*p != NUL)
11047 ++p;
11048 if (*p == NUL)
11049 return; /* expand option name */
11050 nextchar = *++p;
11051 is_term_option = TRUE;
11052 expand_option_name[2] = p[-2];
11053 expand_option_name[3] = p[-1];
11054 }
11055 else
11056 {
11057 /* Allow * wildcard */
11058 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11059 p++;
11060 if (*p == NUL)
11061 return;
11062 nextchar = *p;
11063 *p = NUL;
11064 opt_idx = findoption(arg);
11065 *p = nextchar;
11066 if (opt_idx == -1 || options[opt_idx].var == NULL)
11067 {
11068 xp->xp_context = EXPAND_NOTHING;
11069 return;
11070 }
11071 flags = options[opt_idx].flags;
11072 if (flags & P_BOOL)
11073 {
11074 xp->xp_context = EXPAND_NOTHING;
11075 return;
11076 }
11077 }
11078 }
11079 /* handle "-=" and "+=" */
11080 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11081 {
11082 ++p;
11083 nextchar = '=';
11084 }
11085 if ((nextchar != '=' && nextchar != ':')
11086 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11087 {
11088 xp->xp_context = EXPAND_UNSUCCESSFUL;
11089 return;
11090 }
11091 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11092 {
11093 xp->xp_context = EXPAND_OLD_SETTING;
11094 if (is_term_option)
11095 expand_option_idx = -1;
11096 else
11097 expand_option_idx = opt_idx;
11098 xp->xp_pattern = p + 1;
11099 return;
11100 }
11101 xp->xp_context = EXPAND_NOTHING;
11102 if (is_term_option || (flags & P_NUM))
11103 return;
11104
11105 xp->xp_pattern = p + 1;
11106
11107 if (flags & P_EXPAND)
11108 {
11109 p = options[opt_idx].var;
11110 if (p == (char_u *)&p_bdir
11111 || p == (char_u *)&p_dir
11112 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011113 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114 || p == (char_u *)&p_rtp
11115#ifdef FEAT_SEARCHPATH
11116 || p == (char_u *)&p_cdpath
11117#endif
11118#ifdef FEAT_SESSION
11119 || p == (char_u *)&p_vdir
11120#endif
11121 )
11122 {
11123 xp->xp_context = EXPAND_DIRECTORIES;
11124 if (p == (char_u *)&p_path
11125#ifdef FEAT_SEARCHPATH
11126 || p == (char_u *)&p_cdpath
11127#endif
11128 )
11129 xp->xp_backslash = XP_BS_THREE;
11130 else
11131 xp->xp_backslash = XP_BS_ONE;
11132 }
11133 else
11134 {
11135 xp->xp_context = EXPAND_FILES;
11136 /* for 'tags' need three backslashes for a space */
11137 if (p == (char_u *)&p_tags)
11138 xp->xp_backslash = XP_BS_THREE;
11139 else
11140 xp->xp_backslash = XP_BS_ONE;
11141 }
11142 }
11143
11144 /* For an option that is a list of file names, find the start of the
11145 * last file name. */
11146 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11147 {
11148 /* count number of backslashes before ' ' or ',' */
11149 if (*p == ' ' || *p == ',')
11150 {
11151 s = p;
11152 while (s > xp->xp_pattern && *(s - 1) == '\\')
11153 --s;
11154 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11155 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11156 {
11157 xp->xp_pattern = p + 1;
11158 break;
11159 }
11160 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011161
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011162#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011163 /* for 'spellsuggest' start at "file:" */
11164 if (options[opt_idx].var == (char_u *)&p_sps
11165 && STRNCMP(p, "file:", 5) == 0)
11166 {
11167 xp->xp_pattern = p + 5;
11168 break;
11169 }
11170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011171 }
11172
11173 return;
11174}
11175
11176 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011177ExpandSettings(
11178 expand_T *xp,
11179 regmatch_T *regmatch,
11180 int *num_file,
11181 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011182{
11183 int num_normal = 0; /* Nr of matching non-term-code settings */
11184 int num_term = 0; /* Nr of matching terminal code settings */
11185 int opt_idx;
11186 int match;
11187 int count = 0;
11188 char_u *str;
11189 int loop;
11190 int is_term_opt;
11191 char_u name_buf[MAX_KEY_NAME_LEN];
11192 static char *(names[]) = {"all", "termcap"};
11193 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11194
11195 /* do this loop twice:
11196 * loop == 0: count the number of matching options
11197 * loop == 1: copy the matching options into allocated memory
11198 */
11199 for (loop = 0; loop <= 1; ++loop)
11200 {
11201 regmatch->rm_ic = ic;
11202 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11203 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011204 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11205 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11207 {
11208 if (loop == 0)
11209 num_normal++;
11210 else
11211 (*file)[count++] = vim_strsave((char_u *)names[match]);
11212 }
11213 }
11214 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11215 opt_idx++)
11216 {
11217 if (options[opt_idx].var == NULL)
11218 continue;
11219 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11220 && !(options[opt_idx].flags & P_BOOL))
11221 continue;
11222 is_term_opt = istermoption(&options[opt_idx]);
11223 if (is_term_opt && num_normal > 0)
11224 continue;
11225 match = FALSE;
11226 if (vim_regexec(regmatch, str, (colnr_T)0)
11227 || (options[opt_idx].shortname != NULL
11228 && vim_regexec(regmatch,
11229 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11230 match = TRUE;
11231 else if (is_term_opt)
11232 {
11233 name_buf[0] = '<';
11234 name_buf[1] = 't';
11235 name_buf[2] = '_';
11236 name_buf[3] = str[2];
11237 name_buf[4] = str[3];
11238 name_buf[5] = '>';
11239 name_buf[6] = NUL;
11240 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11241 {
11242 match = TRUE;
11243 str = name_buf;
11244 }
11245 }
11246 if (match)
11247 {
11248 if (loop == 0)
11249 {
11250 if (is_term_opt)
11251 num_term++;
11252 else
11253 num_normal++;
11254 }
11255 else
11256 (*file)[count++] = vim_strsave(str);
11257 }
11258 }
11259 /*
11260 * Check terminal key codes, these are not in the option table
11261 */
11262 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11263 {
11264 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11265 {
11266 if (!isprint(str[0]) || !isprint(str[1]))
11267 continue;
11268
11269 name_buf[0] = 't';
11270 name_buf[1] = '_';
11271 name_buf[2] = str[0];
11272 name_buf[3] = str[1];
11273 name_buf[4] = NUL;
11274
11275 match = FALSE;
11276 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11277 match = TRUE;
11278 else
11279 {
11280 name_buf[0] = '<';
11281 name_buf[1] = 't';
11282 name_buf[2] = '_';
11283 name_buf[3] = str[0];
11284 name_buf[4] = str[1];
11285 name_buf[5] = '>';
11286 name_buf[6] = NUL;
11287
11288 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11289 match = TRUE;
11290 }
11291 if (match)
11292 {
11293 if (loop == 0)
11294 num_term++;
11295 else
11296 (*file)[count++] = vim_strsave(name_buf);
11297 }
11298 }
11299
11300 /*
11301 * Check special key names.
11302 */
11303 regmatch->rm_ic = TRUE; /* ignore case here */
11304 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11305 {
11306 name_buf[0] = '<';
11307 STRCPY(name_buf + 1, str);
11308 STRCAT(name_buf, ">");
11309
11310 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11311 {
11312 if (loop == 0)
11313 num_term++;
11314 else
11315 (*file)[count++] = vim_strsave(name_buf);
11316 }
11317 }
11318 }
11319 if (loop == 0)
11320 {
11321 if (num_normal > 0)
11322 *num_file = num_normal;
11323 else if (num_term > 0)
11324 *num_file = num_term;
11325 else
11326 return OK;
11327 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11328 if (*file == NULL)
11329 {
11330 *file = (char_u **)"";
11331 return FAIL;
11332 }
11333 }
11334 }
11335 return OK;
11336}
11337
11338 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011339ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011340{
11341 char_u *var = NULL; /* init for GCC */
11342 char_u *buf;
11343
11344 *num_file = 0;
11345 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11346 if (*file == NULL)
11347 return FAIL;
11348
11349 /*
11350 * For a terminal key code expand_option_idx is < 0.
11351 */
11352 if (expand_option_idx < 0)
11353 {
11354 var = find_termcode(expand_option_name + 2);
11355 if (var == NULL)
11356 expand_option_idx = findoption(expand_option_name);
11357 }
11358
11359 if (expand_option_idx >= 0)
11360 {
11361 /* put string of option value in NameBuff */
11362 option_value2string(&options[expand_option_idx], expand_option_flags);
11363 var = NameBuff;
11364 }
11365 else if (var == NULL)
11366 var = (char_u *)"";
11367
11368 /* A backslash is required before some characters. This is the reverse of
11369 * what happens in do_set(). */
11370 buf = vim_strsave_escaped(var, escape_chars);
11371
11372 if (buf == NULL)
11373 {
11374 vim_free(*file);
11375 *file = NULL;
11376 return FAIL;
11377 }
11378
11379#ifdef BACKSLASH_IN_FILENAME
11380 /* For MS-Windows et al. we don't double backslashes at the start and
11381 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011382 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383 if (var[0] == '\\' && var[1] == '\\'
11384 && expand_option_idx >= 0
11385 && (options[expand_option_idx].flags & P_EXPAND)
11386 && vim_isfilec(var[2])
11387 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011388 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389#endif
11390
11391 *file[0] = buf;
11392 *num_file = 1;
11393 return OK;
11394}
11395#endif
11396
11397/*
11398 * Get the value for the numeric or string option *opp in a nice format into
11399 * NameBuff[]. Must not be called with a hidden option!
11400 */
11401 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011402option_value2string(
11403 struct vimoption *opp,
11404 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011405{
11406 char_u *varp;
11407
11408 varp = get_varp_scope(opp, opt_flags);
11409
11410 if (opp->flags & P_NUM)
11411 {
11412 long wc = 0;
11413
11414 if (wc_use_keyname(varp, &wc))
11415 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11416 else if (wc != 0)
11417 STRCPY(NameBuff, transchar((int)wc));
11418 else
11419 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11420 }
11421 else /* P_STRING */
11422 {
11423 varp = *(char_u **)(varp);
11424 if (varp == NULL) /* just in case */
11425 NameBuff[0] = NUL;
11426#ifdef FEAT_CRYPT
11427 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011428 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011429 STRCPY(NameBuff, "*****");
11430#endif
11431 else if (opp->flags & P_EXPAND)
11432 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11433 /* Translate 'pastetoggle' into special key names */
11434 else if ((char_u **)opp->var == &p_pt)
11435 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11436 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011437 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011438 }
11439}
11440
11441/*
11442 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11443 * printed as a keyname.
11444 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11445 */
11446 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011447wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011448{
11449 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11450 {
11451 *wcp = *(long *)varp;
11452 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11453 return TRUE;
11454 }
11455 return FALSE;
11456}
11457
Bram Moolenaar01615492015-02-03 13:00:38 +010011458#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011459/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011460 * Any character has an equivalent 'langmap' character. This is used for
11461 * keyboards that have a special language mode that sends characters above
11462 * 128 (although other characters can be translated too). The "to" field is a
11463 * Vim command character. This avoids having to switch the keyboard back to
11464 * ASCII mode when leaving Insert mode.
11465 *
11466 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11467 * commands.
11468 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11469 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11470 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011471 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011472# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011473/*
11474 * With multi-byte support use growarray for 'langmap' chars >= 256
11475 */
11476typedef struct
11477{
11478 int from;
11479 int to;
11480} langmap_entry_T;
11481
11482static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011483static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484
11485/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011486 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11487 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011489 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011490langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011491{
11492 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011493 int a = 0;
11494 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011495
11496 /* Do a binary search for an existing entry. */
11497 while (a != b)
11498 {
11499 int i = (a + b) / 2;
11500 int d = entries[i].from - from;
11501
11502 if (d == 0)
11503 {
11504 entries[i].to = to;
11505 return;
11506 }
11507 if (d < 0)
11508 a = i + 1;
11509 else
11510 b = i;
11511 }
11512
11513 if (ga_grow(&langmap_mapga, 1) != OK)
11514 return; /* out of memory */
11515
11516 /* insert new entry at position "a" */
11517 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11518 mch_memmove(entries + 1, entries,
11519 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11520 ++langmap_mapga.ga_len;
11521 entries[0].from = from;
11522 entries[0].to = to;
11523}
11524
11525/*
11526 * Apply 'langmap' to multi-byte character "c" and return the result.
11527 */
11528 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011529langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011530{
11531 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11532 int a = 0;
11533 int b = langmap_mapga.ga_len;
11534
11535 while (a != b)
11536 {
11537 int i = (a + b) / 2;
11538 int d = entries[i].from - c;
11539
11540 if (d == 0)
11541 return entries[i].to; /* found matching entry */
11542 if (d < 0)
11543 a = i + 1;
11544 else
11545 b = i;
11546 }
11547 return c; /* no entry found, return "c" unmodified */
11548}
11549# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011550
11551 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011552langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553{
11554 int i;
11555
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011556 for (i = 0; i < 256; i++)
11557 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11558# ifdef FEAT_MBYTE
11559 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11560# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561}
11562
11563/*
11564 * Called when langmap option is set; the language map can be
11565 * changed at any time!
11566 */
11567 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011568langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011569{
11570 char_u *p;
11571 char_u *p2;
11572 int from, to;
11573
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011574#ifdef FEAT_MBYTE
11575 ga_clear(&langmap_mapga); /* clear the previous map first */
11576#endif
11577 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011578
11579 for (p = p_langmap; p[0] != NUL; )
11580 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011581 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11582 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011583 {
11584 if (p2[0] == '\\' && p2[1] != NUL)
11585 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011586 }
11587 if (p2[0] == ';')
11588 ++p2; /* abcd;ABCD form, p2 points to A */
11589 else
11590 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11591 while (p[0])
11592 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011593 if (p[0] == ',')
11594 {
11595 ++p;
11596 break;
11597 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011598 if (p[0] == '\\' && p[1] != NUL)
11599 ++p;
11600#ifdef FEAT_MBYTE
11601 from = (*mb_ptr2char)(p);
11602#else
11603 from = p[0];
11604#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011605 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011606 if (p2 == NULL)
11607 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011608 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011609 if (p[0] != ',')
11610 {
11611 if (p[0] == '\\')
11612 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011613#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011614 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011615#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011616 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011617#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011618 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011619 }
11620 else
11621 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011622 if (p2[0] != ',')
11623 {
11624 if (p2[0] == '\\')
11625 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011626#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011627 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011628#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011629 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011630#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011631 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011632 }
11633 if (to == NUL)
11634 {
11635 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11636 transchar(from));
11637 return;
11638 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011639
11640#ifdef FEAT_MBYTE
11641 if (from >= 256)
11642 langmap_set_entry(from, to);
11643 else
11644#endif
11645 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011646
11647 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011648 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011649 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011650 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011651 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011652 if (*p == ';')
11653 {
11654 p = p2;
11655 if (p[0] != NUL)
11656 {
11657 if (p[0] != ',')
11658 {
11659 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11660 return;
11661 }
11662 ++p;
11663 }
11664 break;
11665 }
11666 }
11667 }
11668 }
11669}
11670#endif
11671
11672/*
11673 * Return TRUE if format option 'x' is in effect.
11674 * Take care of no formatting when 'paste' is set.
11675 */
11676 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011677has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011678{
11679 if (p_paste)
11680 return FALSE;
11681 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11682}
11683
11684/*
11685 * Return TRUE if "x" is present in 'shortmess' option, or
11686 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11687 */
11688 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011689shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011690{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011691 return p_shm != NULL &&
11692 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011693 || (vim_strchr(p_shm, 'a') != NULL
11694 && vim_strchr((char_u *)SHM_A, x) != NULL));
11695}
11696
11697/*
11698 * paste_option_changed() - Called after p_paste was set or reset.
11699 */
11700 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011701paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011702{
11703 static int old_p_paste = FALSE;
11704 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011705 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011706#ifdef FEAT_CMDL_INFO
11707 static int save_ru = 0;
11708#endif
11709#ifdef FEAT_RIGHTLEFT
11710 static int save_ri = 0;
11711 static int save_hkmap = 0;
11712#endif
11713 buf_T *buf;
11714
11715 if (p_paste)
11716 {
11717 /*
11718 * Paste switched from off to on.
11719 * Save the current values, so they can be restored later.
11720 */
11721 if (!old_p_paste)
11722 {
11723 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011724 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011725 {
11726 buf->b_p_tw_nopaste = buf->b_p_tw;
11727 buf->b_p_wm_nopaste = buf->b_p_wm;
11728 buf->b_p_sts_nopaste = buf->b_p_sts;
11729 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011730 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731 }
11732
11733 /* save global options */
11734 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011735 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011736#ifdef FEAT_CMDL_INFO
11737 save_ru = p_ru;
11738#endif
11739#ifdef FEAT_RIGHTLEFT
11740 save_ri = p_ri;
11741 save_hkmap = p_hkmap;
11742#endif
11743 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011744 p_ai_nopaste = p_ai;
11745 p_et_nopaste = p_et;
11746 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011747 p_tw_nopaste = p_tw;
11748 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011749 }
11750
11751 /*
11752 * Always set the option values, also when 'paste' is set when it is
11753 * already on.
11754 */
11755 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011756 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011757 {
11758 buf->b_p_tw = 0; /* textwidth is 0 */
11759 buf->b_p_wm = 0; /* wrapmargin is 0 */
11760 buf->b_p_sts = 0; /* softtabstop is 0 */
11761 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011762 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011763 }
11764
11765 /* set global options */
11766 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011767 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011768#ifdef FEAT_CMDL_INFO
11769# ifdef FEAT_WINDOWS
11770 if (p_ru)
11771 status_redraw_all(); /* redraw to remove the ruler */
11772# endif
11773 p_ru = 0; /* no ruler */
11774#endif
11775#ifdef FEAT_RIGHTLEFT
11776 p_ri = 0; /* no reverse insert */
11777 p_hkmap = 0; /* no Hebrew keyboard */
11778#endif
11779 /* set global values for local buffer options */
11780 p_tw = 0;
11781 p_wm = 0;
11782 p_sts = 0;
11783 p_ai = 0;
11784 }
11785
11786 /*
11787 * Paste switched from on to off: Restore saved values.
11788 */
11789 else if (old_p_paste)
11790 {
11791 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011792 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011793 {
11794 buf->b_p_tw = buf->b_p_tw_nopaste;
11795 buf->b_p_wm = buf->b_p_wm_nopaste;
11796 buf->b_p_sts = buf->b_p_sts_nopaste;
11797 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011798 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799 }
11800
11801 /* restore global options */
11802 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011803 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011804#ifdef FEAT_CMDL_INFO
11805# ifdef FEAT_WINDOWS
11806 if (p_ru != save_ru)
11807 status_redraw_all(); /* redraw to draw the ruler */
11808# endif
11809 p_ru = save_ru;
11810#endif
11811#ifdef FEAT_RIGHTLEFT
11812 p_ri = save_ri;
11813 p_hkmap = save_hkmap;
11814#endif
11815 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011816 p_ai = p_ai_nopaste;
11817 p_et = p_et_nopaste;
11818 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819 p_tw = p_tw_nopaste;
11820 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011821 }
11822
11823 old_p_paste = p_paste;
11824}
11825
11826/*
11827 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11828 *
11829 * Reset 'compatible' and set the values for options that didn't get set yet
11830 * to the Vim defaults.
11831 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011832 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011833 */
11834 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011835vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011836{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011837 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011838 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011839 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840
11841 if (!option_was_set((char_u *)"cp"))
11842 {
11843 p_cp = FALSE;
11844 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11845 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11846 set_option_default(opt_idx, OPT_FREE, FALSE);
11847 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011848 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011849 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011850
11851 if (fname != NULL)
11852 {
11853 p = vim_getenv(envname, &dofree);
11854 if (p == NULL)
11855 {
11856 /* Set $MYVIMRC to the first vimrc file found. */
11857 p = FullName_save(fname, FALSE);
11858 if (p != NULL)
11859 {
11860 vim_setenv(envname, p);
11861 vim_free(p);
11862 }
11863 }
11864 else if (dofree)
11865 vim_free(p);
11866 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011867}
11868
11869/*
11870 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11871 */
11872 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011873change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011874{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011875 int opt_idx;
11876
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877 if (p_cp != on)
11878 {
11879 p_cp = on;
11880 compatible_set();
11881 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011882 opt_idx = findoption((char_u *)"cp");
11883 if (opt_idx >= 0)
11884 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011885}
11886
11887/*
11888 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011889 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011890 */
11891 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011892option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893{
11894 int idx;
11895
11896 idx = findoption(name);
11897 if (idx < 0) /* unknown option */
11898 return FALSE;
11899 if (options[idx].flags & P_WAS_SET)
11900 return TRUE;
11901 return FALSE;
11902}
11903
11904/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011905 * Reset the flag indicating option "name" was set.
11906 */
11907 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011908reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011909{
11910 int idx = findoption(name);
11911
11912 if (idx >= 0)
11913 options[idx].flags &= ~P_WAS_SET;
11914}
11915
11916/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011917 * compatible_set() - Called when 'compatible' has been set or unset.
11918 *
11919 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11920 * flag) to a Vi compatible value.
11921 * When 'compatible' is unset: Set all options that have a different default
11922 * for Vim (without the P_VI_DEF flag) to that default.
11923 */
11924 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011925compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011926{
11927 int opt_idx;
11928
11929 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11930 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11931 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11932 set_option_default(opt_idx, OPT_FREE, p_cp);
11933 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011934 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011935}
11936
11937#ifdef FEAT_LINEBREAK
11938
11939# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11940 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011941 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011942# endif
11943
11944/*
11945 * fill_breakat_flags() -- called when 'breakat' changes value.
11946 */
11947 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011948fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011949{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011950 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951 int i;
11952
11953 for (i = 0; i < 256; i++)
11954 breakat_flags[i] = FALSE;
11955
11956 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011957 for (p = p_breakat; *p; p++)
11958 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011959}
11960
11961# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011962 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963# endif
11964
11965#endif
11966
11967/*
11968 * Check an option that can be a range of string values.
11969 *
11970 * Return OK for correct value, FAIL otherwise.
11971 * Empty is always OK.
11972 */
11973 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011974check_opt_strings(
11975 char_u *val,
11976 char **values,
11977 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978{
11979 return opt_strings_flags(val, values, NULL, list);
11980}
11981
11982/*
11983 * Handle an option that can be a range of string values.
11984 * Set a flag in "*flagp" for each string present.
11985 *
11986 * Return OK for correct value, FAIL otherwise.
11987 * Empty is always OK.
11988 */
11989 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011990opt_strings_flags(
11991 char_u *val, /* new value */
11992 char **values, /* array of valid string values */
11993 unsigned *flagp,
11994 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011995{
11996 int i;
11997 int len;
11998 unsigned new_flags = 0;
11999
12000 while (*val)
12001 {
12002 for (i = 0; ; ++i)
12003 {
12004 if (values[i] == NULL) /* val not found in values[] */
12005 return FAIL;
12006
12007 len = (int)STRLEN(values[i]);
12008 if (STRNCMP(values[i], val, len) == 0
12009 && ((list && val[len] == ',') || val[len] == NUL))
12010 {
12011 val += len + (val[len] == ',');
12012 new_flags |= (1 << i);
12013 break; /* check next item in val list */
12014 }
12015 }
12016 }
12017 if (flagp != NULL)
12018 *flagp = new_flags;
12019
12020 return OK;
12021}
12022
12023/*
12024 * Read the 'wildmode' option, fill wim_flags[].
12025 */
12026 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012027check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012028{
12029 char_u new_wim_flags[4];
12030 char_u *p;
12031 int i;
12032 int idx = 0;
12033
12034 for (i = 0; i < 4; ++i)
12035 new_wim_flags[i] = 0;
12036
12037 for (p = p_wim; *p; ++p)
12038 {
12039 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12040 ;
12041 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12042 return FAIL;
12043 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12044 new_wim_flags[idx] |= WIM_LONGEST;
12045 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12046 new_wim_flags[idx] |= WIM_FULL;
12047 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12048 new_wim_flags[idx] |= WIM_LIST;
12049 else
12050 return FAIL;
12051 p += i;
12052 if (*p == NUL)
12053 break;
12054 if (*p == ',')
12055 {
12056 if (idx == 3)
12057 return FAIL;
12058 ++idx;
12059 }
12060 }
12061
12062 /* fill remaining entries with last flag */
12063 while (idx < 3)
12064 {
12065 new_wim_flags[idx + 1] = new_wim_flags[idx];
12066 ++idx;
12067 }
12068
12069 /* only when there are no errors, wim_flags[] is changed */
12070 for (i = 0; i < 4; ++i)
12071 wim_flags[i] = new_wim_flags[i];
12072 return OK;
12073}
12074
12075/*
12076 * Check if backspacing over something is allowed.
12077 */
12078 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012079can_bs(
12080 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081{
12082 switch (*p_bs)
12083 {
12084 case '2': return TRUE;
12085 case '1': return (what != BS_START);
12086 case '0': return FALSE;
12087 }
12088 return vim_strchr(p_bs, what) != NULL;
12089}
12090
12091/*
12092 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12093 * the file must be considered changed when the value is different.
12094 */
12095 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012096save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012097{
12098 buf->b_start_ffc = *buf->b_p_ff;
12099 buf->b_start_eol = buf->b_p_eol;
12100#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012101 buf->b_start_bomb = buf->b_p_bomb;
12102
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 /* Only use free/alloc when necessary, they take time. */
12104 if (buf->b_start_fenc == NULL
12105 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12106 {
12107 vim_free(buf->b_start_fenc);
12108 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12109 }
12110#endif
12111}
12112
12113/*
12114 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12115 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012116 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12117 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012118 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012119 * When "ignore_empty" is true don't consider a new, empty buffer to be
12120 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121 */
12122 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012123file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012124{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012125 /* In a buffer that was never loaded the options are not valid. */
12126 if (buf->b_flags & BF_NEVERLOADED)
12127 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012128 if (ignore_empty
12129 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012130 && buf->b_ml.ml_line_count == 1
12131 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12132 return FALSE;
12133 if (buf->b_start_ffc != *buf->b_p_ff)
12134 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012135 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136 return TRUE;
12137#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012138 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12139 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012140 if (buf->b_start_fenc == NULL)
12141 return (*buf->b_p_fenc != NUL);
12142 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12143#else
12144 return FALSE;
12145#endif
12146}
12147
12148/*
12149 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12150 */
12151 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012152check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012153{
12154 return check_opt_strings(p, p_ff_values, FALSE);
12155}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012156
12157/*
12158 * Return the effective shiftwidth value for current buffer, using the
12159 * 'tabstop' value when 'shiftwidth' is zero.
12160 */
12161 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012162get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012163{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012164 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012165}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012166
12167/*
12168 * Return the effective softtabstop value for the current buffer, using the
12169 * 'tabstop' value when 'softtabstop' is negative.
12170 */
12171 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012172get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012173{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012174 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012175}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012176
12177/*
12178 * Check matchpairs option for "*initc".
12179 * If there is a match set "*initc" to the matching character and "*findc" to
12180 * the opposite character. Set "*backwards" to the direction.
12181 * When "switchit" is TRUE swap the direction.
12182 */
12183 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012184find_mps_values(
12185 int *initc,
12186 int *findc,
12187 int *backwards,
12188 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012189{
12190 char_u *ptr;
12191
12192 ptr = curbuf->b_p_mps;
12193 while (*ptr != NUL)
12194 {
12195#ifdef FEAT_MBYTE
12196 if (has_mbyte)
12197 {
12198 char_u *prev;
12199
12200 if (mb_ptr2char(ptr) == *initc)
12201 {
12202 if (switchit)
12203 {
12204 *findc = *initc;
12205 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12206 *backwards = TRUE;
12207 }
12208 else
12209 {
12210 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12211 *backwards = FALSE;
12212 }
12213 return;
12214 }
12215 prev = ptr;
12216 ptr += mb_ptr2len(ptr) + 1;
12217 if (mb_ptr2char(ptr) == *initc)
12218 {
12219 if (switchit)
12220 {
12221 *findc = *initc;
12222 *initc = mb_ptr2char(prev);
12223 *backwards = FALSE;
12224 }
12225 else
12226 {
12227 *findc = mb_ptr2char(prev);
12228 *backwards = TRUE;
12229 }
12230 return;
12231 }
12232 ptr += mb_ptr2len(ptr);
12233 }
12234 else
12235#endif
12236 {
12237 if (*ptr == *initc)
12238 {
12239 if (switchit)
12240 {
12241 *backwards = TRUE;
12242 *findc = *initc;
12243 *initc = ptr[2];
12244 }
12245 else
12246 {
12247 *backwards = FALSE;
12248 *findc = ptr[2];
12249 }
12250 return;
12251 }
12252 ptr += 2;
12253 if (*ptr == *initc)
12254 {
12255 if (switchit)
12256 {
12257 *backwards = FALSE;
12258 *findc = *initc;
12259 *initc = ptr[-2];
12260 }
12261 else
12262 {
12263 *backwards = TRUE;
12264 *findc = ptr[-2];
12265 }
12266 return;
12267 }
12268 ++ptr;
12269 }
12270 if (*ptr == ',')
12271 ++ptr;
12272 }
12273}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012274
12275#if defined(FEAT_LINEBREAK) || defined(PROTO)
12276/*
12277 * This is called when 'breakindentopt' is changed and when a window is
12278 * initialized.
12279 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012280 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012281briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012282{
12283 char_u *p;
12284 int bri_shift = 0;
12285 long bri_min = 20;
12286 int bri_sbr = FALSE;
12287
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012288 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012289 while (*p != NUL)
12290 {
12291 if (STRNCMP(p, "shift:", 6) == 0
12292 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12293 {
12294 p += 6;
12295 bri_shift = getdigits(&p);
12296 }
12297 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12298 {
12299 p += 4;
12300 bri_min = getdigits(&p);
12301 }
12302 else if (STRNCMP(p, "sbr", 3) == 0)
12303 {
12304 p += 3;
12305 bri_sbr = TRUE;
12306 }
12307 if (*p != ',' && *p != NUL)
12308 return FAIL;
12309 if (*p == ',')
12310 ++p;
12311 }
12312
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012313 wp->w_p_brishift = bri_shift;
12314 wp->w_p_brimin = bri_min;
12315 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012316
12317 return OK;
12318}
12319#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012320
12321/*
12322 * Get the local or global value of 'backupcopy'.
12323 */
12324 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012325get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012326{
12327 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12328}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012329
12330#if defined(FEAT_SIGNS) || defined(PROTO)
12331/*
12332 * Return TRUE when window "wp" has a column to draw signs in.
12333 */
12334 int
12335signcolumn_on(win_T *wp)
12336{
12337 if (*wp->w_p_scl == 'n')
12338 return FALSE;
12339 if (*wp->w_p_scl == 'y')
12340 return TRUE;
12341 return (wp->w_buffer->b_signlist != NULL
12342# ifdef FEAT_NETBEANS_INTG
12343 || wp->w_buffer->b_has_sign_column
12344# endif
12345 );
12346}
12347#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012348
12349#if defined(FEAT_EVAL) || defined(PROTO)
12350/*
12351 * Get window or buffer local options.
12352 */
12353 dict_T *
12354get_winbuf_options(int bufopt)
12355{
12356 dict_T *d;
12357 int opt_idx;
12358
12359 d = dict_alloc();
12360 if (d == NULL)
12361 return NULL;
12362
12363 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12364 {
12365 struct vimoption *opt = &options[opt_idx];
12366
12367 if ((bufopt && (opt->indir & PV_BUF))
12368 || (!bufopt && (opt->indir & PV_WIN)))
12369 {
12370 char_u *varp = get_varp(opt);
12371
12372 if (varp != NULL)
12373 {
12374 if (opt->flags & P_STRING)
12375 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
12376 else
12377 dict_add_nr_str(d, opt->fullname, *varp, NULL);
12378 }
12379 }
12380 }
12381
12382 return d;
12383}
12384#endif