blob: bc44cb2d4bde9c7c13a7436acad80b1c63d3df70 [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
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
177#define PV_TS OPT_BUF(BV_TS)
178#define PV_TW OPT_BUF(BV_TW)
179#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200180#ifdef FEAT_PERSISTENT_UNDO
181# define PV_UDF OPT_BUF(BV_UDF)
182#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000184
185/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186 * Definition of the PV_ values for window-local options.
187 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189#define PV_LIST OPT_WIN(WV_LIST)
190#ifdef FEAT_ARABIC
191# define PV_ARAB OPT_WIN(WV_ARAB)
192#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200193#ifdef FEAT_LINEBREAK
194# define PV_BRI OPT_WIN(WV_BRI)
195# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
196#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000197#ifdef FEAT_DIFF
198# define PV_DIFF OPT_WIN(WV_DIFF)
199#endif
200#ifdef FEAT_FOLDING
201# define PV_FDC OPT_WIN(WV_FDC)
202# define PV_FEN OPT_WIN(WV_FEN)
203# define PV_FDI OPT_WIN(WV_FDI)
204# define PV_FDL OPT_WIN(WV_FDL)
205# define PV_FDM OPT_WIN(WV_FDM)
206# define PV_FML OPT_WIN(WV_FML)
207# define PV_FDN OPT_WIN(WV_FDN)
208# ifdef FEAT_EVAL
209# define PV_FDE OPT_WIN(WV_FDE)
210# define PV_FDT OPT_WIN(WV_FDT)
211# endif
212# define PV_FMR OPT_WIN(WV_FMR)
213#endif
214#ifdef FEAT_LINEBREAK
215# define PV_LBR OPT_WIN(WV_LBR)
216#endif
217#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200218#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000219#ifdef FEAT_LINEBREAK
220# define PV_NUW OPT_WIN(WV_NUW)
221#endif
222#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
223# define PV_PVW OPT_WIN(WV_PVW)
224#endif
225#ifdef FEAT_RIGHTLEFT
226# define PV_RL OPT_WIN(WV_RL)
227# define PV_RLC OPT_WIN(WV_RLC)
228#endif
229#ifdef FEAT_SCROLLBIND
230# define PV_SCBIND OPT_WIN(WV_SCBIND)
231#endif
232#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000233#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000234# define PV_SPELL OPT_WIN(WV_SPELL)
235#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SYN_HL
237# define PV_CUC OPT_WIN(WV_CUC)
238# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200239# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000240#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000241#ifdef FEAT_STL_OPT
242# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
243#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100244#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000245#ifdef FEAT_WINDOWS
246# define PV_WFH OPT_WIN(WV_WFH)
247#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000248#ifdef FEAT_VERTSPLIT
249# define PV_WFW OPT_WIN(WV_WFW)
250#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000251#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200252#ifdef FEAT_CURSORBIND
253# define PV_CRBIND OPT_WIN(WV_CRBIND)
254#endif
255#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200256# define PV_COCU OPT_WIN(WV_COCU)
257# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200258#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
354#ifndef SHORT_FNAME
355static int p_sn;
356#endif
357static long p_sts;
358#if defined(FEAT_SEARCHPATH)
359static char_u *p_sua;
360#endif
361static long p_sw;
362static int p_swf;
363#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000364static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000365static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000366#endif
367#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000368static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000369static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000370static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000371#endif
372static long p_ts;
373static long p_tw;
374static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200375#ifdef FEAT_PERSISTENT_UNDO
376static int p_udf;
377#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378static long p_wm;
379#ifdef FEAT_KEYMAP
380static char_u *p_keymap;
381#endif
382
383/* Saved values for when 'bin' is set. */
384static int p_et_nobin;
385static int p_ml_nobin;
386static long p_tw_nobin;
387static long p_wm_nobin;
388
389/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200390static int p_ai_nopaste;
391static int p_et_nopaste;
392static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000393static long p_tw_nopaste;
394static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395
396struct vimoption
397{
398 char *fullname; /* full option name */
399 char *shortname; /* permissible abbreviation */
400 long_u flags; /* see below */
401 char_u *var; /* global option: pointer to variable;
402 * window-local option: VAR_WIN;
403 * buffer-local option: global value */
404 idopt_T indir; /* global option: PV_NONE;
405 * local option: indirect option index */
406 char_u *def_val[2]; /* default values for variable (vi and vim) */
407#ifdef FEAT_EVAL
408 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000409# define SCRIPTID_INIT , 0
410#else
411# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000412#endif
413};
414
415#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
416#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
417
418/*
419 * Flags
420 */
421#define P_BOOL 0x01 /* the option is boolean */
422#define P_NUM 0x02 /* the option is numeric */
423#define P_STRING 0x04 /* the option is a string */
424#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000425 must use free_string_option() when
426 assigning new value. Not set if default is
427 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000428#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
429 never be used for local or hidden options! */
430#define P_NODEFAULT 0x40 /* don't set to default value */
431#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
432 use vim_free() when assigning new value */
433#define P_WAS_SET 0x100 /* option has been set/reset */
434#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
435#define P_VI_DEF 0x400 /* Use Vi default for Vim */
436#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
437
438 /* when option changed, what to display: */
439#define P_RSTAT 0x1000 /* redraw status lines */
440#define P_RWIN 0x2000 /* redraw current window */
441#define P_RBUF 0x4000 /* redraw current buffer */
442#define P_RALL 0x6000 /* redraw all windows */
443#define P_RCLR 0x7000 /* clear and redraw all */
444
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200445#define P_COMMA 0x8000 /* comma separated list */
446#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
447 * commas */
448#define P_NODUP 0x20000L /* don't allow duplicate strings */
449#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000450
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200451#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
452#define P_GETTEXT 0x100000L /* expand default value with _() */
453#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
454#define P_NFNAME 0x400000L /* only normal file name chars allowed */
455#define P_INSECURE 0x800000L /* option was set from a modeline */
456#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000457 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200458#define P_NO_ML 0x2000000L /* not allowed in modeline */
459#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200460 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000461
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000462#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
463
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000464/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
465 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000466#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000467# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000468#else
469# define ISP_LATIN1 (char_u *)"@,161-255"
470#endif
471
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000472/* The 16 bit MS-DOS version is low on space, make the string as short as
473 * possible when compiling with few features. */
474#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
475 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200476 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100477# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000478#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100479# 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 +0000480#endif
481
Bram Moolenaar071d4272004-06-13 20:20:40 +0000482/*
483 * options[] is initialized here.
484 * The order of the options MUST be alphabetic for ":set all" and findoption().
485 * All option names MUST start with a lowercase letter (for findoption()).
486 * Exception: "t_" options are at the end.
487 * The options with a NULL variable are 'hidden': a set command for them is
488 * ignored and they are not printed.
489 */
490static struct vimoption
491#ifdef FEAT_GUI_W16
492 _far
493#endif
494 options[] =
495{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200496 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497#ifdef FEAT_RIGHTLEFT
498 (char_u *)&p_aleph, PV_NONE,
499#else
500 (char_u *)NULL, PV_NONE,
501#endif
502 {
503#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
504 (char_u *)128L,
505#else
506 (char_u *)224L,
507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000508 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
510#if defined(FEAT_GUI) && defined(MACOS_X)
511 (char_u *)&p_antialias, PV_NONE,
512 {(char_u *)FALSE, (char_u *)FALSE}
513#else
514 (char_u *)NULL, PV_NONE,
515 {(char_u *)FALSE, (char_u *)FALSE}
516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000517 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200518 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519#ifdef FEAT_ARABIC
520 (char_u *)VAR_WIN, PV_ARAB,
521#else
522 (char_u *)NULL, PV_NONE,
523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000524 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
526#ifdef FEAT_ARABIC
527 (char_u *)&p_arshape, PV_NONE,
528#else
529 (char_u *)NULL, PV_NONE,
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
533#ifdef FEAT_RIGHTLEFT
534 (char_u *)&p_ari, 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 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
540#ifdef FEAT_FKMAP
541 (char_u *)&p_altkeymap, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
547#if defined(FEAT_MBYTE)
548 (char_u *)&p_ambw, PV_NONE,
549 {(char_u *)"single", (char_u *)0L}
550#else
551 (char_u *)NULL, PV_NONE,
552 {(char_u *)0L, (char_u *)0L}
553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000554 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000555#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autochdir", "acd", P_BOOL|P_VI_DEF,
557 (char_u *)&p_acd, 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#endif
560 {"autoindent", "ai", P_BOOL|P_VI_DEF,
561 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autoprint", "ap", P_BOOL|P_VI_DEF,
564 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000567 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autowrite", "aw", P_BOOL|P_VI_DEF,
570 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"autowriteall","awa", P_BOOL|P_VI_DEF,
573 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000574 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
576 (char_u *)&p_bg, PV_NONE,
577 {
578#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
579 (char_u *)"dark",
580#else
581 (char_u *)"light",
582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200584 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
588 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000589 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200590 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200591 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592#ifdef UNIX
593 {(char_u *)"yes", (char_u *)"auto"}
594#else
595 {(char_u *)"auto", (char_u *)"auto"}
596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000597 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200598 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
599 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000601 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000602 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 (char_u *)&p_bex, PV_NONE,
604 {
605#ifdef VMS
606 (char_u *)"_",
607#else
608 (char_u *)"~",
609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000610 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200611 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612#ifdef FEAT_WILDIGN
613 (char_u *)&p_bsk, PV_NONE,
614 {(char_u *)"", (char_u *)0L}
615#else
616 (char_u *)NULL, PV_NONE,
617 {(char_u *)0L, (char_u *)0L}
618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000620#ifdef FEAT_BEVAL
621 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
622 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
625 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000627# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000628 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000629 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000630 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000631# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632#endif
633 {"beautify", "bf", P_BOOL|P_VI_DEF,
634 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000635 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200636 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
637 (char_u *)&p_bo, PV_NONE,
638 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
640 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000641 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
643#ifdef MSDOS
644 (char_u *)&p_biosk, PV_NONE,
645#else
646 (char_u *)NULL, PV_NONE,
647#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000648 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
650#ifdef FEAT_MBYTE
651 (char_u *)&p_bomb, PV_BOMB,
652#else
653 (char_u *)NULL, PV_NONE,
654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000655 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
657#ifdef FEAT_LINEBREAK
658 (char_u *)&p_breakat, PV_NONE,
659 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000664 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200665 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
666#ifdef FEAT_LINEBREAK
667 (char_u *)VAR_WIN, PV_BRI,
668 {(char_u *)FALSE, (char_u *)0L}
669#else
670 (char_u *)NULL, PV_NONE,
671 {(char_u *)0L, (char_u *)0L}
672#endif
673 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200674 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
675 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200676#ifdef FEAT_LINEBREAK
677 (char_u *)VAR_WIN, PV_BRIOPT,
678 {(char_u *)"", (char_u *)NULL}
679#else
680 (char_u *)NULL, PV_NONE,
681 {(char_u *)"", (char_u *)NULL}
682#endif
683 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
685#ifdef FEAT_BROWSE
686 (char_u *)&p_bsdir, PV_NONE,
687 {(char_u *)"last", (char_u *)0L}
688#else
689 (char_u *)NULL, PV_NONE,
690 {(char_u *)0L, (char_u *)0L}
691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000692 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000693 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
694#if defined(FEAT_QUICKFIX)
695 (char_u *)&p_bh, PV_BH,
696 {(char_u *)"", (char_u *)0L}
697#else
698 (char_u *)NULL, PV_NONE,
699 {(char_u *)0L, (char_u *)0L}
700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000701 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
703 (char_u *)&p_bl, PV_BL,
704 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000705 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
707#if defined(FEAT_QUICKFIX)
708 (char_u *)&p_bt, PV_BT,
709 {(char_u *)"", (char_u *)0L}
710#else
711 (char_u *)NULL, PV_NONE,
712 {(char_u *)0L, (char_u *)0L}
713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000714 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200715 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000716#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 (char_u *)&p_cmp, PV_NONE,
718 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000719#else
720 (char_u *)NULL, PV_NONE,
721 {(char_u *)0L, (char_u *)0L}
722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000723 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
725#ifdef FEAT_SEARCHPATH
726 (char_u *)&p_cdpath, PV_NONE,
727 {(char_u *)",,", (char_u *)0L}
728#else
729 (char_u *)NULL, PV_NONE,
730 {(char_u *)0L, (char_u *)0L}
731#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000732 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733 {"cedit", NULL, P_STRING,
734#ifdef FEAT_CMDWIN
735 (char_u *)&p_cedit, PV_NONE,
736 {(char_u *)"", (char_u *)CTRL_F_STR}
737#else
738 (char_u *)NULL, PV_NONE,
739 {(char_u *)0L, (char_u *)0L}
740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000741 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
743#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
744 (char_u *)&p_ccv, PV_NONE,
745 {(char_u *)"", (char_u *)0L}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
752#ifdef FEAT_CINDENT
753 (char_u *)&p_cin, PV_CIN,
754#else
755 (char_u *)NULL, PV_NONE,
756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000757 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200758 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759#ifdef FEAT_CINDENT
760 (char_u *)&p_cink, PV_CINK,
761 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
762#else
763 (char_u *)NULL, PV_NONE,
764 {(char_u *)0L, (char_u *)0L}
765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000766 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200767 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768#ifdef FEAT_CINDENT
769 (char_u *)&p_cino, PV_CINO,
770#else
771 (char_u *)NULL, PV_NONE,
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
776 (char_u *)&p_cinw, PV_CINW,
777 {(char_u *)"if,else,while,do,for,switch",
778 (char_u *)0L}
779#else
780 (char_u *)NULL, PV_NONE,
781 {(char_u *)0L, (char_u *)0L}
782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000783 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200784 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000785#ifdef FEAT_CLIPBOARD
786 (char_u *)&p_cb, PV_NONE,
787# ifdef FEAT_XCLIPBOARD
788 {(char_u *)"autoselect,exclude:cons\\|linux",
789 (char_u *)0L}
790# else
791 {(char_u *)"", (char_u *)0L}
792# endif
793#else
794 (char_u *)NULL, PV_NONE,
795 {(char_u *)"", (char_u *)0L}
796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000798 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
799 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000800 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
802#ifdef FEAT_CMDWIN
803 (char_u *)&p_cwh, PV_NONE,
804#else
805 (char_u *)NULL, PV_NONE,
806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200808 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200809#ifdef FEAT_SYN_HL
810 (char_u *)VAR_WIN, PV_CC,
811#else
812 (char_u *)NULL, PV_NONE,
813#endif
814 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000815 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
816 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200818 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
819 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820#ifdef FEAT_COMMENTS
821 (char_u *)&p_com, PV_COM,
822 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
823 (char_u *)0L}
824#else
825 (char_u *)NULL, PV_NONE,
826 {(char_u *)0L, (char_u *)0L}
827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000828 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200829 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830#ifdef FEAT_FOLDING
831 (char_u *)&p_cms, PV_CMS,
832 {(char_u *)"/*%s*/", (char_u *)0L}
833#else
834 (char_u *)NULL, PV_NONE,
835 {(char_u *)0L, (char_u *)0L}
836#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000837 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000838 /* P_PRI_MKRC isn't needed here, optval_default()
839 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000840 {"compatible", "cp", P_BOOL|P_RALL,
841 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000842 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200843 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844#ifdef FEAT_INS_EXPAND
845 (char_u *)&p_cpt, PV_CPT,
846 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
847#else
848 (char_u *)NULL, PV_NONE,
849 {(char_u *)0L, (char_u *)0L}
850#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000851 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200852 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200853#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200854 (char_u *)VAR_WIN, PV_COCU,
855 {(char_u *)"", (char_u *)NULL}
856#else
857 (char_u *)NULL, PV_NONE,
858 {(char_u *)NULL, (char_u *)0L}
859#endif
860 SCRIPTID_INIT},
861 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
862#ifdef FEAT_CONCEAL
863 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200864#else
865 (char_u *)NULL, PV_NONE,
866#endif
867 {(char_u *)0L, (char_u *)0L}
868 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000869 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
870#ifdef FEAT_COMPL_FUNC
871 (char_u *)&p_cfu, PV_CFU,
872 {(char_u *)"", (char_u *)0L}
873#else
874 (char_u *)NULL, PV_NONE,
875 {(char_u *)0L, (char_u *)0L}
876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000877 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200878 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000879#ifdef FEAT_INS_EXPAND
880 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000881 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000882#else
883 (char_u *)NULL, PV_NONE,
884 {(char_u *)0L, (char_u *)0L}
885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000886 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887 {"confirm", "cf", P_BOOL|P_VI_DEF,
888#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
889 (char_u *)&p_confirm, PV_NONE,
890#else
891 (char_u *)NULL, PV_NONE,
892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000893 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894 {"conskey", "consk",P_BOOL|P_VI_DEF,
895#ifdef MSDOS
896 (char_u *)&p_consk, PV_NONE,
897#else
898 (char_u *)NULL, PV_NONE,
899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
902 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
905 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
907 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200908 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200909#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200910 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200911 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200912#else
913 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200914 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200915#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200916 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
918#ifdef FEAT_CSCOPE
919 (char_u *)&p_cspc, PV_NONE,
920#else
921 (char_u *)NULL, PV_NONE,
922#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000923 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
925#ifdef FEAT_CSCOPE
926 (char_u *)&p_csprg, PV_NONE,
927 {(char_u *)"cscope", (char_u *)0L}
928#else
929 (char_u *)NULL, PV_NONE,
930 {(char_u *)0L, (char_u *)0L}
931#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000932 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200933 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
935 (char_u *)&p_csqf, PV_NONE,
936 {(char_u *)"", (char_u *)0L}
937#else
938 (char_u *)NULL, PV_NONE,
939 {(char_u *)0L, (char_u *)0L}
940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000941 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200942 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
943#ifdef FEAT_CSCOPE
944 (char_u *)&p_csre, PV_NONE,
945#else
946 (char_u *)NULL, PV_NONE,
947#endif
948 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
950#ifdef FEAT_CSCOPE
951 (char_u *)&p_cst, PV_NONE,
952#else
953 (char_u *)NULL, PV_NONE,
954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000955 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
957#ifdef FEAT_CSCOPE
958 (char_u *)&p_csto, PV_NONE,
959#else
960 (char_u *)NULL, PV_NONE,
961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000962 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
964#ifdef FEAT_CSCOPE
965 (char_u *)&p_csverbose, PV_NONE,
966#else
967 (char_u *)NULL, PV_NONE,
968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000969 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200970 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
971#ifdef FEAT_CURSORBIND
972 (char_u *)VAR_WIN, PV_CRBIND,
973#else
974 (char_u *)NULL, PV_NONE,
975#endif
976 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000977 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
978#ifdef FEAT_SYN_HL
979 (char_u *)VAR_WIN, PV_CUC,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000984 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
985#ifdef FEAT_SYN_HL
986 (char_u *)VAR_WIN, PV_CUL,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"debug", NULL, P_STRING|P_VI_DEF,
992 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000993 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200994 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000996 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000997 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#else
999 (char_u *)NULL, PV_NONE,
1000 {(char_u *)NULL, (char_u *)0L}
1001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001002 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1004#ifdef FEAT_MBYTE
1005 (char_u *)&p_deco, PV_NONE,
1006#else
1007 (char_u *)NULL, PV_NONE,
1008#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001010 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001012 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013#else
1014 (char_u *)NULL, PV_NONE,
1015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001016 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1018#ifdef FEAT_DIFF
1019 (char_u *)VAR_WIN, PV_DIFF,
1020#else
1021 (char_u *)NULL, PV_NONE,
1022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001023 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001024 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1026 (char_u *)&p_dex, PV_NONE,
1027 {(char_u *)"", (char_u *)0L}
1028#else
1029 (char_u *)NULL, PV_NONE,
1030 {(char_u *)0L, (char_u *)0L}
1031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001032 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001033 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1034 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001035#ifdef FEAT_DIFF
1036 (char_u *)&p_dip, PV_NONE,
1037 {(char_u *)"filler", (char_u *)NULL}
1038#else
1039 (char_u *)NULL, PV_NONE,
1040 {(char_u *)"", (char_u *)NULL}
1041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1044#ifdef FEAT_DIGRAPHS
1045 (char_u *)&p_dg, PV_NONE,
1046#else
1047 (char_u *)NULL, PV_NONE,
1048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001049 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001050 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1051 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001054 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"eadirection", "ead", P_STRING|P_VI_DEF,
1058#ifdef FEAT_VERTSPLIT
1059 (char_u *)&p_ead, PV_NONE,
1060 {(char_u *)"both", (char_u *)0L}
1061#else
1062 (char_u *)NULL, PV_NONE,
1063 {(char_u *)NULL, (char_u *)0L}
1064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001065 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1067 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001069 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070#ifdef FEAT_MBYTE
1071 (char_u *)&p_enc, PV_NONE,
1072 {(char_u *)ENC_DFLT, (char_u *)0L}
1073#else
1074 (char_u *)NULL, PV_NONE,
1075 {(char_u *)0L, (char_u *)0L}
1076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1079 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1082 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001085 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001086 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1088 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1091#ifdef FEAT_QUICKFIX
1092 (char_u *)&p_ef, PV_NONE,
1093 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1094#else
1095 (char_u *)NULL, PV_NONE,
1096 {(char_u *)NULL, (char_u *)0L}
1097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001098 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001099 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001101 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103#else
1104 (char_u *)NULL, PV_NONE,
1105 {(char_u *)NULL, (char_u *)0L}
1106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 {"esckeys", "ek", P_BOOL|P_VIM,
1109 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001111 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112#ifdef FEAT_AUTOCMD
1113 (char_u *)&p_ei, PV_NONE,
1114#else
1115 (char_u *)NULL, PV_NONE,
1116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1119 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001120 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1122 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001124 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1125 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#ifdef FEAT_MBYTE
1127 (char_u *)&p_fenc, PV_FENC,
1128 {(char_u *)"", (char_u *)0L}
1129#else
1130 (char_u *)NULL, PV_NONE,
1131 {(char_u *)0L, (char_u *)0L}
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135#ifdef FEAT_MBYTE
1136 (char_u *)&p_fencs, PV_NONE,
1137 {(char_u *)"ucs-bom", (char_u *)0L}
1138#else
1139 (char_u *)NULL, PV_NONE,
1140 {(char_u *)0L, (char_u *)0L}
1141#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001142 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001143 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1144 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001147 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1150 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001151 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1152 (char_u *)&p_fic, PV_NONE,
1153 {
1154#ifdef CASE_INSENSITIVE_FILENAME
1155 (char_u *)TRUE,
1156#else
1157 (char_u *)FALSE,
1158#endif
1159 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001160 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161#ifdef FEAT_AUTOCMD
1162 (char_u *)&p_ft, PV_FT,
1163 {(char_u *)"", (char_u *)0L}
1164#else
1165 (char_u *)NULL, PV_NONE,
1166 {(char_u *)0L, (char_u *)0L}
1167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001169 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001170#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1171 (char_u *)&p_fcs, PV_NONE,
1172 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1173#else
1174 (char_u *)NULL, PV_NONE,
1175 {(char_u *)"", (char_u *)0L}
1176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001177 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001178 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1179 (char_u *)&p_fixeol, PV_FIXEOL,
1180 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001181 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1182#ifdef FEAT_FKMAP
1183 (char_u *)&p_fkmap, PV_NONE,
1184#else
1185 (char_u *)NULL, PV_NONE,
1186#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001187 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001188 {"flash", "fl", P_BOOL|P_VI_DEF,
1189 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001192 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1196 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1199 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1202# ifdef FEAT_EVAL
1203 (char_u *)VAR_WIN, PV_FDE,
1204 {(char_u *)"0", (char_u *)NULL}
1205# else
1206 (char_u *)NULL, PV_NONE,
1207 {(char_u *)NULL, (char_u *)0L}
1208# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1211 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1214 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001215 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001216 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001218 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001220 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001222 {(char_u *)"{{{,}}}", (char_u *)NULL}
1223 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1225 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1228 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001229 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001230 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1231 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001232 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001233 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234 (char_u *)&p_fdo, PV_NONE,
1235 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001236 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1238# ifdef FEAT_EVAL
1239 (char_u *)VAR_WIN, PV_FDT,
1240 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001241# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242 (char_u *)NULL, PV_NONE,
1243 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001244# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001245 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001246#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001247 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001248#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001249 (char_u *)&p_fex, PV_FEX,
1250 {(char_u *)"", (char_u *)0L}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)0L, (char_u *)0L}
1254#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1257 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001258 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1259 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001260 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1261 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001262 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1263 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1265 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001267 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1268#ifdef HAVE_FSYNC
1269 (char_u *)&p_fs, PV_NONE,
1270 {(char_u *)TRUE, (char_u *)0L}
1271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)FALSE, (char_u *)0L}
1274#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1277 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001278 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001279 {"graphic", "gr", P_BOOL|P_VI_DEF,
1280 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001282 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283#ifdef FEAT_QUICKFIX
1284 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001285 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286#else
1287 (char_u *)NULL, PV_NONE,
1288 {(char_u *)NULL, (char_u *)0L}
1289#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001290 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1292#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001293 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294 {
1295# ifdef WIN3264
1296 /* may be changed to "grep -n" in os_win32.c */
1297 (char_u *)"findstr /n",
1298# else
1299# ifdef UNIX
1300 /* Add an extra file name so that grep will always
1301 * insert a file name in the match line. */
1302 (char_u *)"grep -n $* /dev/null",
1303# else
1304# ifdef VMS
1305 (char_u *)"SEARCH/NUMBERS ",
1306# else
1307 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308# endif
1309# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001310# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001311 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001312#else
1313 (char_u *)NULL, PV_NONE,
1314 {(char_u *)NULL, (char_u *)0L}
1315#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001316 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001317 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318#ifdef CURSOR_SHAPE
1319 (char_u *)&p_guicursor, PV_NONE,
1320 {
1321# ifdef FEAT_GUI
1322 (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",
1323# else /* MSDOS or Win32 console */
1324 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1325# endif
1326 (char_u *)0L}
1327#else
1328 (char_u *)NULL, PV_NONE,
1329 {(char_u *)NULL, (char_u *)0L}
1330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001332 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333#ifdef FEAT_GUI
1334 (char_u *)&p_guifont, PV_NONE,
1335 {(char_u *)"", (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)NULL, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001341 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1343 (char_u *)&p_guifontset, PV_NONE,
1344 {(char_u *)"", (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)NULL, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001350 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1352 (char_u *)&p_guifontwide, PV_NONE,
1353 {(char_u *)"", (char_u *)0L}
1354#else
1355 (char_u *)NULL, PV_NONE,
1356 {(char_u *)NULL, (char_u *)0L}
1357#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001358 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001360#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 (char_u *)&p_ghr, PV_NONE,
1362#else
1363 (char_u *)NULL, PV_NONE,
1364#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001365 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001367#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 (char_u *)&p_go, PV_NONE,
1369# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001370 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001372 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373# endif
1374#else
1375 (char_u *)NULL, PV_NONE,
1376 {(char_u *)NULL, (char_u *)0L}
1377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001378 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379 {"guipty", NULL, P_BOOL|P_VI_DEF,
1380#if defined(FEAT_GUI)
1381 (char_u *)&p_guipty, PV_NONE,
1382#else
1383 (char_u *)NULL, PV_NONE,
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001386 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001387#if defined(FEAT_GUI_TABLINE)
1388 (char_u *)&p_gtl, PV_NONE,
1389 {(char_u *)"", (char_u *)0L}
1390#else
1391 (char_u *)NULL, PV_NONE,
1392 {(char_u *)NULL, (char_u *)0L}
1393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001395 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001396#if defined(FEAT_GUI_TABLINE)
1397 (char_u *)&p_gtt, PV_NONE,
1398 {(char_u *)"", (char_u *)0L}
1399#else
1400 (char_u *)NULL, PV_NONE,
1401 {(char_u *)NULL, (char_u *)0L}
1402#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1405 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001406 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1408 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001409 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1410 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001411 {"helpheight", "hh", P_NUM|P_VI_DEF,
1412#ifdef FEAT_WINDOWS
1413 (char_u *)&p_hh, PV_NONE,
1414#else
1415 (char_u *)NULL, PV_NONE,
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001418 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419#ifdef FEAT_MULTI_LANG
1420 (char_u *)&p_hlg, PV_NONE,
1421 {(char_u *)"", (char_u *)0L}
1422#else
1423 (char_u *)NULL, PV_NONE,
1424 {(char_u *)0L, (char_u *)0L}
1425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 {"hidden", "hid", P_BOOL|P_VI_DEF,
1428 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001430 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1433 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434 {"history", "hi", P_NUM|P_VIM,
1435 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001436 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1438#ifdef FEAT_RIGHTLEFT
1439 (char_u *)&p_hkmap, PV_NONE,
1440#else
1441 (char_u *)NULL, PV_NONE,
1442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001443 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1445#ifdef FEAT_RIGHTLEFT
1446 (char_u *)&p_hkmapp, PV_NONE,
1447#else
1448 (char_u *)NULL, PV_NONE,
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1452 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001453 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454 {"icon", NULL, P_BOOL|P_VI_DEF,
1455#ifdef FEAT_TITLE
1456 (char_u *)&p_icon, PV_NONE,
1457#else
1458 (char_u *)NULL, PV_NONE,
1459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001460 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 {"iconstring", NULL, P_STRING|P_VI_DEF,
1462#ifdef FEAT_TITLE
1463 (char_u *)&p_iconstring, PV_NONE,
1464#else
1465 (char_u *)NULL, PV_NONE,
1466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1469 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001470 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001471 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1472# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1473 (char_u *)&p_imaf, PV_NONE,
1474 {(char_u *)"", (char_u *)NULL}
1475# else
1476 (char_u *)NULL, PV_NONE,
1477 {(char_u *)NULL, (char_u *)0L}
1478# endif
1479 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001481#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482 (char_u *)&p_imak, PV_NONE,
1483#else
1484 (char_u *)NULL, PV_NONE,
1485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1488#ifdef USE_IM_CONTROL
1489 (char_u *)&p_imcmdline, PV_NONE,
1490#else
1491 (char_u *)NULL, PV_NONE,
1492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001494 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1495#ifdef USE_IM_CONTROL
1496 (char_u *)&p_imdisable, PV_NONE,
1497#else
1498 (char_u *)NULL, PV_NONE,
1499#endif
1500#ifdef __sgi
1501 {(char_u *)TRUE, (char_u *)0L}
1502#else
1503 {(char_u *)FALSE, (char_u *)0L}
1504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001505 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001506 {"iminsert", "imi", P_NUM|P_VI_DEF,
1507 (char_u *)&p_iminsert, PV_IMI,
1508#ifdef B_IMODE_IM
1509 {(char_u *)B_IMODE_IM, (char_u *)0L}
1510#else
1511 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001513 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"imsearch", "ims", P_NUM|P_VI_DEF,
1515 (char_u *)&p_imsearch, PV_IMS,
1516#ifdef B_IMODE_IM
1517 {(char_u *)B_IMODE_IM, (char_u *)0L}
1518#else
1519 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001522 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001523# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1524 (char_u *)&p_imsf, PV_NONE,
1525 {(char_u *)"", (char_u *)NULL}
1526# else
1527 (char_u *)NULL, PV_NONE,
1528 {(char_u *)NULL, (char_u *)0L}
1529# endif
1530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1532#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001533 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001534 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1535#else
1536 (char_u *)NULL, PV_NONE,
1537 {(char_u *)0L, (char_u *)0L}
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1541#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1542 (char_u *)&p_inex, PV_INEX,
1543 {(char_u *)"", (char_u *)0L}
1544#else
1545 (char_u *)NULL, PV_NONE,
1546 {(char_u *)0L, (char_u *)0L}
1547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001548 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1550 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1553#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1554 (char_u *)&p_inde, PV_INDE,
1555 {(char_u *)"", (char_u *)0L}
1556#else
1557 (char_u *)NULL, PV_NONE,
1558 {(char_u *)0L, (char_u *)0L}
1559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001560 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001561 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001562#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1563 (char_u *)&p_indk, PV_INDK,
1564 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1565#else
1566 (char_u *)NULL, PV_NONE,
1567 {(char_u *)0L, (char_u *)0L}
1568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001569 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570 {"infercase", "inf", P_BOOL|P_VI_DEF,
1571 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1574 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1577 (char_u *)&p_isf, PV_NONE,
1578 {
1579#ifdef BACKSLASH_IN_FILENAME
1580 /* Excluded are: & and ^ are special in cmd.exe
1581 * ( and ) are used in text separating fnames */
1582 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1583#else
1584# ifdef AMIGA
1585 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1586# else
1587# ifdef VMS
1588 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1589# else /* UNIX et al. */
1590# ifdef EBCDIC
1591 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1592# else
1593 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1594# endif
1595# endif
1596# endif
1597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001598 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1600 (char_u *)&p_isi, PV_NONE,
1601 {
1602#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1603 (char_u *)"@,48-57,_,128-167,224-235",
1604#else
1605# ifdef EBCDIC
1606 /* TODO: EBCDIC Check this! @ == isalpha()*/
1607 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1608 "112-120,128,140-142,156,158,172,"
1609 "174,186,191,203-207,219-225,235-239,"
1610 "251-254",
1611# else
1612 (char_u *)"@,48-57,_,192-255",
1613# endif
1614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001615 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1617 (char_u *)&p_isk, PV_ISK,
1618 {
1619#ifdef EBCDIC
1620 (char_u *)"@,240-249,_",
1621 /* TODO: EBCDIC Check this! @ == isalpha()*/
1622 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1623 "112-120,128,140-142,156,158,172,"
1624 "174,186,191,203-207,219-225,235-239,"
1625 "251-254",
1626#else
1627 (char_u *)"@,48-57,_",
1628# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1629 (char_u *)"@,48-57,_,128-167,224-235"
1630# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001631 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632# endif
1633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1636 (char_u *)&p_isp, PV_NONE,
1637 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001638#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1639 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640 || defined(VMS)
1641 (char_u *)"@,~-255",
1642#else
1643# ifdef EBCDIC
1644 /* all chars above 63 are printable */
1645 (char_u *)"63-255",
1646# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001647 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648# endif
1649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001650 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1652 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001653 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1655#ifdef FEAT_CRYPT
1656 (char_u *)&p_key, PV_KEY,
1657 {(char_u *)"", (char_u *)0L}
1658#else
1659 (char_u *)NULL, PV_NONE,
1660 {(char_u *)0L, (char_u *)0L}
1661#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001662 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001663 {"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 +00001664#ifdef FEAT_KEYMAP
1665 (char_u *)&p_keymap, PV_KMAP,
1666 {(char_u *)"", (char_u *)0L}
1667#else
1668 (char_u *)NULL, PV_NONE,
1669 {(char_u *)"", (char_u *)0L}
1670#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001671 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001672 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001674 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001676 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677 {
1678#if defined(MSDOS) || defined(MSWIN)
1679 (char_u *)":help",
1680#else
1681#ifdef VMS
1682 (char_u *)"help",
1683#else
1684# if defined(OS2)
1685 (char_u *)"view /",
1686# else
1687# ifdef USEMAN_S
1688 (char_u *)"man -s",
1689# else
1690 (char_u *)"man",
1691# endif
1692# endif
1693#endif
1694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001695 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001696 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697#ifdef FEAT_LANGMAP
1698 (char_u *)&p_langmap, PV_NONE,
1699 {(char_u *)"", /* unmatched } */
1700#else
1701 (char_u *)NULL, PV_NONE,
1702 {(char_u *)NULL,
1703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001704 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001705 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1707 (char_u *)&p_lm, PV_NONE,
1708#else
1709 (char_u *)NULL, PV_NONE,
1710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001711 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001712 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1713#ifdef FEAT_LANGMAP
1714 (char_u *)&p_lnr, PV_NONE,
1715#else
1716 (char_u *)NULL, PV_NONE,
1717#endif
1718 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1720#ifdef FEAT_WINDOWS
1721 (char_u *)&p_ls, PV_NONE,
1722#else
1723 (char_u *)NULL, PV_NONE,
1724#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001725 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1727 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001728 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1730#ifdef FEAT_LINEBREAK
1731 (char_u *)VAR_WIN, PV_LBR,
1732#else
1733 (char_u *)NULL, PV_NONE,
1734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001735 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1737 (char_u *)&Rows, PV_NONE,
1738 {
1739#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1740 (char_u *)25L,
1741#else
1742 (char_u *)24L,
1743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001744 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1746#ifdef FEAT_GUI
1747 (char_u *)&p_linespace, PV_NONE,
1748#else
1749 (char_u *)NULL, PV_NONE,
1750#endif
1751#ifdef FEAT_GUI_W32
1752 {(char_u *)1L, (char_u *)0L}
1753#else
1754 {(char_u *)0L, (char_u *)0L}
1755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 {"lisp", NULL, P_BOOL|P_VI_DEF,
1758#ifdef FEAT_LISP
1759 (char_u *)&p_lisp, PV_LISP,
1760#else
1761 (char_u *)NULL, PV_NONE,
1762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001764 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001766 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1768#else
1769 (char_u *)NULL, PV_NONE,
1770 {(char_u *)"", (char_u *)0L}
1771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1774 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001775 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001776 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001778 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1780 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001781 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001782#if defined(DYNAMIC_LUA) && !defined(WIN3264)
1783 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1784 (char_u *)&p_luadll, PV_NONE,
1785 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1786#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001787#ifdef FEAT_GUI_MAC
1788 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1789 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 {"magic", NULL, P_BOOL|P_VI_DEF,
1793 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001795 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796#ifdef FEAT_QUICKFIX
1797 (char_u *)&p_mef, PV_NONE,
1798 {(char_u *)"", (char_u *)0L}
1799#else
1800 (char_u *)NULL, PV_NONE,
1801 {(char_u *)NULL, (char_u *)0L}
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1805#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001806 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807# ifdef VMS
1808 {(char_u *)"MMS", (char_u *)0L}
1809# else
1810 {(char_u *)"make", (char_u *)0L}
1811# endif
1812#else
1813 (char_u *)NULL, PV_NONE,
1814 {(char_u *)NULL, (char_u *)0L}
1815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001817 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1820 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"matchtime", "mat", P_NUM|P_VI_DEF,
1822 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001824 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001825#ifdef FEAT_MBYTE
1826 (char_u *)&p_mco, PV_NONE,
1827#else
1828 (char_u *)NULL, PV_NONE,
1829#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1832#ifdef FEAT_EVAL
1833 (char_u *)&p_mfd, PV_NONE,
1834#else
1835 (char_u *)NULL, PV_NONE,
1836#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001838 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1839 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"maxmem", "mm", P_NUM|P_VI_DEF,
1842 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1844 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001845 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1846 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1849 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1851 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"menuitems", "mis", P_NUM|P_VI_DEF,
1853#ifdef FEAT_MENU
1854 (char_u *)&p_mis, PV_NONE,
1855#else
1856 (char_u *)NULL, PV_NONE,
1857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"mesg", NULL, P_BOOL|P_VI_DEF,
1860 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001862 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001863#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001864 (char_u *)&p_msm, PV_NONE,
1865 {(char_u *)"460000,2000,500", (char_u *)0L}
1866#else
1867 (char_u *)NULL, PV_NONE,
1868 {(char_u *)0L, (char_u *)0L}
1869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"modeline", "ml", P_BOOL|P_VIM,
1872 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"modelines", "mls", P_NUM|P_VI_DEF,
1875 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1878 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1881 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883 {"more", NULL, P_BOOL|P_VIM,
1884 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001885 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1887 (char_u *)&p_mouse, PV_NONE,
1888 {
1889#if defined(MSDOS) || defined(WIN3264)
1890 (char_u *)"a",
1891#else
1892 (char_u *)"",
1893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001894 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1896#ifdef FEAT_GUI
1897 (char_u *)&p_mousef, PV_NONE,
1898#else
1899 (char_u *)NULL, PV_NONE,
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1903#ifdef FEAT_GUI
1904 (char_u *)&p_mh, PV_NONE,
1905#else
1906 (char_u *)NULL, PV_NONE,
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1910 (char_u *)&p_mousem, PV_NONE,
1911 {
1912#if defined(MSDOS) || defined(MSWIN)
1913 (char_u *)"popup",
1914#else
1915# if defined(MACOS)
1916 (char_u *)"popup_setpos",
1917# else
1918 (char_u *)"extend",
1919# endif
1920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001921 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001922 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923#ifdef FEAT_MOUSESHAPE
1924 (char_u *)&p_mouseshape, PV_NONE,
1925 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1926#else
1927 (char_u *)NULL, PV_NONE,
1928 {(char_u *)NULL, (char_u *)0L}
1929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1932 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001933 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001934 {"mzquantum", "mzq", P_NUM,
1935#ifdef FEAT_MZSCHEME
1936 (char_u *)&p_mzq, PV_NONE,
1937#else
1938 (char_u *)NULL, PV_NONE,
1939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941 {"novice", NULL, P_BOOL|P_VI_DEF,
1942 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001944 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)"octal,hex", (char_u *)0L}
1947 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1949 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001950 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001951 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1952#ifdef FEAT_LINEBREAK
1953 (char_u *)VAR_WIN, PV_NUW,
1954#else
1955 (char_u *)NULL, PV_NONE,
1956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001957 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001958 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001959#ifdef FEAT_COMPL_FUNC
1960 (char_u *)&p_ofu, PV_OFU,
1961 {(char_u *)"", (char_u *)0L}
1962#else
1963 (char_u *)NULL, PV_NONE,
1964 {(char_u *)0L, (char_u *)0L}
1965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001966 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001967 {"open", NULL, P_BOOL|P_VI_DEF,
1968 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001970 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1971#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1972 (char_u *)&p_odev, PV_NONE,
1973#else
1974 (char_u *)NULL, PV_NONE,
1975#endif
1976 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001978 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1979 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"optimize", "opt", P_BOOL|P_VI_DEF,
1982 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001983 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001986 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 {"paragraphs", "para", P_STRING|P_VI_DEF,
1988 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001989 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001991 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1995 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1998#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1999 (char_u *)&p_pex, PV_NONE,
2000 {(char_u *)"", (char_u *)0L}
2001#else
2002 (char_u *)NULL, PV_NONE,
2003 {(char_u *)0L, (char_u *)0L}
2004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002006 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002008 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002010 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002011 {
2012#if defined AMIGA || defined MSDOS || defined MSWIN
2013 (char_u *)".,,",
2014#else
2015# if defined(__EMX__)
2016 (char_u *)".,/emx/include,,",
2017# else /* Unix, probably */
2018 (char_u *)".,/usr/include,,",
2019# endif
2020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002021 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002022#if defined(DYNAMIC_PERL) && !defined(WIN3264)
2023 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2024 (char_u *)&p_perldll, PV_NONE,
2025 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2026#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2028 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002030 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2032 (char_u *)&p_pvh, PV_NONE,
2033#else
2034 (char_u *)NULL, PV_NONE,
2035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2038#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2039 (char_u *)VAR_WIN, PV_PVW,
2040#else
2041 (char_u *)NULL, PV_NONE,
2042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002043 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002044 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045#ifdef FEAT_PRINTER
2046 (char_u *)&p_pdev, PV_NONE,
2047 {(char_u *)"", (char_u *)0L}
2048#else
2049 (char_u *)NULL, PV_NONE,
2050 {(char_u *)NULL, (char_u *)0L}
2051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002052 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 {"printencoding", "penc", P_STRING|P_VI_DEF,
2054#ifdef FEAT_POSTSCRIPT
2055 (char_u *)&p_penc, PV_NONE,
2056 {(char_u *)"", (char_u *)0L}
2057#else
2058 (char_u *)NULL, PV_NONE,
2059 {(char_u *)NULL, (char_u *)0L}
2060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2063#ifdef FEAT_POSTSCRIPT
2064 (char_u *)&p_pexpr, PV_NONE,
2065 {(char_u *)"", (char_u *)0L}
2066#else
2067 (char_u *)NULL, PV_NONE,
2068 {(char_u *)NULL, (char_u *)0L}
2069#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002070 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 {"printfont", "pfn", P_STRING|P_VI_DEF,
2072#ifdef FEAT_PRINTER
2073 (char_u *)&p_pfn, PV_NONE,
2074 {
2075# ifdef MSWIN
2076 (char_u *)"Courier_New:h10",
2077# else
2078 (char_u *)"courier",
2079# endif
2080 (char_u *)0L}
2081#else
2082 (char_u *)NULL, PV_NONE,
2083 {(char_u *)NULL, (char_u *)0L}
2084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2087#ifdef FEAT_PRINTER
2088 (char_u *)&p_header, PV_NONE,
2089 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2090#else
2091 (char_u *)NULL, PV_NONE,
2092 {(char_u *)NULL, (char_u *)0L}
2093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002095 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2096#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2097 (char_u *)&p_pmcs, PV_NONE,
2098 {(char_u *)"", (char_u *)0L}
2099#else
2100 (char_u *)NULL, PV_NONE,
2101 {(char_u *)NULL, (char_u *)0L}
2102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002103 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002104 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2105#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2106 (char_u *)&p_pmfn, PV_NONE,
2107 {(char_u *)"", (char_u *)0L}
2108#else
2109 (char_u *)NULL, PV_NONE,
2110 {(char_u *)NULL, (char_u *)0L}
2111#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002113 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114#ifdef FEAT_PRINTER
2115 (char_u *)&p_popt, PV_NONE,
2116 {(char_u *)"", (char_u *)0L}
2117#else
2118 (char_u *)NULL, PV_NONE,
2119 {(char_u *)NULL, (char_u *)0L}
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002123 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002125 {"pumheight", "ph", P_NUM|P_VI_DEF,
2126#ifdef FEAT_INS_EXPAND
2127 (char_u *)&p_ph, PV_NONE,
2128#else
2129 (char_u *)NULL, PV_NONE,
2130#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002131 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002132#if defined(DYNAMIC_PYTHON3) && !defined(WIN3264)
2133 {"python3dll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2134 (char_u *)&p_py3dll, PV_NONE,
2135 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2136#endif
2137#if defined(DYNAMIC_PYTHON) && !defined(WIN3264)
2138 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2139 (char_u *)&p_pydll, PV_NONE,
2140 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2141#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002142 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2143#ifdef FEAT_TEXTOBJ
2144 (char_u *)&p_qe, PV_QE,
2145 {(char_u *)"\\", (char_u *)0L}
2146#else
2147 (char_u *)NULL, PV_NONE,
2148 {(char_u *)NULL, (char_u *)0L}
2149#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002150 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2152 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 {"redraw", NULL, P_BOOL|P_VI_DEF,
2155 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002156 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002157 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2158#ifdef FEAT_RELTIME
2159 (char_u *)&p_rdt, PV_NONE,
2160#else
2161 (char_u *)NULL, PV_NONE,
2162#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002163 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002164 {"regexpengine", "re", P_NUM|P_VI_DEF,
2165 (char_u *)&p_re, PV_NONE,
2166 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002167 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2168 (char_u *)VAR_WIN, PV_RNU,
2169 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 {"remap", NULL, P_BOOL|P_VI_DEF,
2171 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002172 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002173 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002174#ifdef FEAT_RENDER_OPTIONS
2175 (char_u *)&p_rop, PV_NONE,
2176 {(char_u *)"", (char_u *)0L}
2177#else
2178 (char_u *)NULL, PV_NONE,
2179 {(char_u *)NULL, (char_u *)0L}
2180#endif
2181 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 {"report", NULL, P_NUM|P_VI_DEF,
2183 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002184 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2186#ifdef WIN3264
2187 (char_u *)&p_rs, PV_NONE,
2188#else
2189 (char_u *)NULL, PV_NONE,
2190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002191 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2193#ifdef FEAT_RIGHTLEFT
2194 (char_u *)&p_ri, PV_NONE,
2195#else
2196 (char_u *)NULL, PV_NONE,
2197#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002199 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2200#ifdef FEAT_RIGHTLEFT
2201 (char_u *)VAR_WIN, PV_RL,
2202#else
2203 (char_u *)NULL, PV_NONE,
2204#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002205 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002206 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2207#ifdef FEAT_RIGHTLEFT
2208 (char_u *)VAR_WIN, PV_RLC,
2209 {(char_u *)"search", (char_u *)NULL}
2210#else
2211 (char_u *)NULL, PV_NONE,
2212 {(char_u *)NULL, (char_u *)0L}
2213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002215#if defined(DYNAMIC_RUBY) && !defined(WIN3264)
2216 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2217 (char_u *)&p_rubydll, PV_NONE,
2218 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2221#ifdef FEAT_CMDL_INFO
2222 (char_u *)&p_ru, PV_NONE,
2223#else
2224 (char_u *)NULL, PV_NONE,
2225#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002226 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2228#ifdef FEAT_STL_OPT
2229 (char_u *)&p_ruf, PV_NONE,
2230#else
2231 (char_u *)NULL, PV_NONE,
2232#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002234 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2235 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002236 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2238 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2240 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2243#ifdef FEAT_SCROLLBIND
2244 (char_u *)VAR_WIN, PV_SCBIND,
2245#else
2246 (char_u *)NULL, PV_NONE,
2247#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002248 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002249 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2250 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002251 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002252 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2253 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002254 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002255 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002256#ifdef FEAT_SCROLLBIND
2257 (char_u *)&p_sbo, PV_NONE,
2258 {(char_u *)"ver,jump", (char_u *)0L}
2259#else
2260 (char_u *)NULL, PV_NONE,
2261 {(char_u *)0L, (char_u *)0L}
2262#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002263 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002264 {"sections", "sect", P_STRING|P_VI_DEF,
2265 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002266 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2267 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2269 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002270 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)"inclusive", (char_u *)0L}
2274 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002275 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002277 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002278 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279#ifdef FEAT_SESSION
2280 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002281 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 (char_u *)0L}
2283#else
2284 (char_u *)NULL, PV_NONE,
2285 {(char_u *)0L, (char_u *)0L}
2286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2289 (char_u *)&p_sh, PV_NONE,
2290 {
2291#ifdef VMS
2292 (char_u *)"-",
2293#else
2294# if defined(MSDOS)
2295 (char_u *)"command",
2296# else
2297# if defined(WIN16)
2298 (char_u *)"command.com",
2299# else
2300# if defined(WIN3264)
2301 (char_u *)"", /* set in set_init_1() */
2302# else
2303# if defined(OS2)
2304 (char_u *)"cmd.exe",
2305# else
2306# if defined(ARCHIE)
2307 (char_u *)"gos",
2308# else
2309 (char_u *)"sh",
2310# endif
2311# endif
2312# endif
2313# endif
2314# endif
2315#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2318 (char_u *)&p_shcf, PV_NONE,
2319 {
2320#if defined(MSDOS) || defined(MSWIN)
2321 (char_u *)"/c",
2322#else
2323# if defined(OS2)
2324 (char_u *)"/c",
2325# else
2326 (char_u *)"-c",
2327# endif
2328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2331#ifdef FEAT_QUICKFIX
2332 (char_u *)&p_sp, PV_NONE,
2333 {
2334#if defined(UNIX) || defined(OS2)
2335# ifdef ARCHIE
2336 (char_u *)"2>",
2337# else
2338 (char_u *)"| tee",
2339# endif
2340#else
2341 (char_u *)">",
2342#endif
2343 (char_u *)0L}
2344#else
2345 (char_u *)NULL, PV_NONE,
2346 {(char_u *)0L, (char_u *)0L}
2347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2350 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2353 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2356#ifdef BACKSLASH_IN_FILENAME
2357 (char_u *)&p_ssl, PV_NONE,
2358#else
2359 (char_u *)NULL, PV_NONE,
2360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002362 {"shelltemp", "stmp", P_BOOL,
2363 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"shelltype", "st", P_NUM|P_VI_DEF,
2366#ifdef AMIGA
2367 (char_u *)&p_st, PV_NONE,
2368#else
2369 (char_u *)NULL, PV_NONE,
2370#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2373 (char_u *)&p_sxq, PV_NONE,
2374 {
2375#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2376 (char_u *)"\"",
2377#else
2378 (char_u *)"",
2379#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002381 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2382 (char_u *)&p_sxe, PV_NONE,
2383 {
2384#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2385 (char_u *)"\"&|<>()@^",
2386#else
2387 (char_u *)"",
2388#endif
2389 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2391 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2394 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2397 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)"", (char_u *)"filnxtToO"}
2399 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"shortname", "sn", P_BOOL|P_VI_DEF,
2401#ifdef SHORT_FNAME
2402 (char_u *)NULL, PV_NONE,
2403#else
2404 (char_u *)&p_sn, PV_SN,
2405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2408#ifdef FEAT_LINEBREAK
2409 (char_u *)&p_sbr, PV_NONE,
2410#else
2411 (char_u *)NULL, PV_NONE,
2412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"showcmd", "sc", P_BOOL|P_VIM,
2415#ifdef FEAT_CMDL_INFO
2416 (char_u *)&p_sc, PV_NONE,
2417#else
2418 (char_u *)NULL, PV_NONE,
2419#endif
2420 {(char_u *)FALSE,
2421#ifdef UNIX
2422 (char_u *)FALSE
2423#else
2424 (char_u *)TRUE
2425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2428 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2431 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"showmode", "smd", P_BOOL|P_VIM,
2434 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002436 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2437#ifdef FEAT_WINDOWS
2438 (char_u *)&p_stal, PV_NONE,
2439#else
2440 (char_u *)NULL, PV_NONE,
2441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2444 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2447 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2450 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2453 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2456#ifdef FEAT_SMARTINDENT
2457 (char_u *)&p_si, PV_SI,
2458#else
2459 (char_u *)NULL, PV_NONE,
2460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2463 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2466 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2469 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002471 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002472#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002473 (char_u *)VAR_WIN, PV_SPELL,
2474#else
2475 (char_u *)NULL, PV_NONE,
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002478 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002479#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002480 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002481 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002482#else
2483 (char_u *)NULL, PV_NONE,
2484 {(char_u *)0L, (char_u *)0L}
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002487 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2488 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002489#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002490 (char_u *)&p_spf, PV_SPF,
2491 {(char_u *)"", (char_u *)0L}
2492#else
2493 (char_u *)NULL, PV_NONE,
2494 {(char_u *)0L, (char_u *)0L}
2495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002497 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2498 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002499#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002500 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002501 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002502#else
2503 (char_u *)NULL, PV_NONE,
2504 {(char_u *)0L, (char_u *)0L}
2505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002506 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002507 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002508#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002509 (char_u *)&p_sps, PV_NONE,
2510 {(char_u *)"best", (char_u *)0L}
2511#else
2512 (char_u *)NULL, PV_NONE,
2513 {(char_u *)0L, (char_u *)0L}
2514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2517#ifdef FEAT_WINDOWS
2518 (char_u *)&p_sb, PV_NONE,
2519#else
2520 (char_u *)NULL, PV_NONE,
2521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"splitright", "spr", P_BOOL|P_VI_DEF,
2524#ifdef FEAT_VERTSPLIT
2525 (char_u *)&p_spr, PV_NONE,
2526#else
2527 (char_u *)NULL, PV_NONE,
2528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2531 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002533 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2534#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002535 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536#else
2537 (char_u *)NULL, PV_NONE,
2538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002540 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 (char_u *)&p_su, PV_NONE,
2542 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002544 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002545#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 (char_u *)&p_sua, PV_SUA,
2547 {(char_u *)"", (char_u *)0L}
2548#else
2549 (char_u *)NULL, PV_NONE,
2550 {(char_u *)0L, (char_u *)0L}
2551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2554 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"swapsync", "sws", P_STRING|P_VI_DEF,
2557 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002559 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002562 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2563#ifdef FEAT_SYN_HL
2564 (char_u *)&p_smc, PV_SMC,
2565 {(char_u *)3000L, (char_u *)0L}
2566#else
2567 (char_u *)NULL, PV_NONE,
2568 {(char_u *)0L, (char_u *)0L}
2569#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002570 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002571 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572#ifdef FEAT_SYN_HL
2573 (char_u *)&p_syn, PV_SYN,
2574 {(char_u *)"", (char_u *)0L}
2575#else
2576 (char_u *)NULL, PV_NONE,
2577 {(char_u *)0L, (char_u *)0L}
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002580 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2581#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002582 (char_u *)&p_tal, PV_NONE,
2583#else
2584 (char_u *)NULL, PV_NONE,
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002587 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2588#ifdef FEAT_WINDOWS
2589 (char_u *)&p_tpm, PV_NONE,
2590#else
2591 (char_u *)NULL, PV_NONE,
2592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2595 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2598 (char_u *)&p_tbs, PV_NONE,
2599#ifdef VMS /* binary searching doesn't appear to work on VMS */
2600 {(char_u *)0L, (char_u *)0L}
2601#else
2602 {(char_u *)TRUE, (char_u *)0L}
2603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 {"taglength", "tl", P_NUM|P_VI_DEF,
2606 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"tagrelative", "tr", P_BOOL|P_VIM,
2609 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002610 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002611 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002612 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 {
2614#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2615 (char_u *)"./tags,./TAGS,tags,TAGS",
2616#else
2617 (char_u *)"./tags,tags",
2618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2621 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2624 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002625 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2627#ifdef FEAT_ARABIC
2628 (char_u *)&p_tbidi, PV_NONE,
2629#else
2630 (char_u *)NULL, PV_NONE,
2631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2634#ifdef FEAT_MBYTE
2635 (char_u *)&p_tenc, PV_NONE,
2636 {(char_u *)"", (char_u *)0L}
2637#else
2638 (char_u *)NULL, PV_NONE,
2639 {(char_u *)0L, (char_u *)0L}
2640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002641 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"terse", NULL, P_BOOL|P_VI_DEF,
2643 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"textauto", "ta", P_BOOL|P_VIM,
2646 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2648 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2650 (char_u *)&p_tx, PV_TX,
2651 {
2652#ifdef USE_CRNL
2653 (char_u *)TRUE,
2654#else
2655 (char_u *)FALSE,
2656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002658 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002661 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002663 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664#else
2665 (char_u *)NULL, PV_NONE,
2666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2669 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 {"timeout", "to", P_BOOL|P_VI_DEF,
2672 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2675 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"title", NULL, P_BOOL|P_VI_DEF,
2678#ifdef FEAT_TITLE
2679 (char_u *)&p_title, PV_NONE,
2680#else
2681 (char_u *)NULL, PV_NONE,
2682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"titlelen", NULL, P_NUM|P_VI_DEF,
2685#ifdef FEAT_TITLE
2686 (char_u *)&p_titlelen, PV_NONE,
2687#else
2688 (char_u *)NULL, PV_NONE,
2689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002691 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692#ifdef FEAT_TITLE
2693 (char_u *)&p_titleold, PV_NONE,
2694 {(char_u *)N_("Thanks for flying Vim"),
2695 (char_u *)0L}
2696#else
2697 (char_u *)NULL, PV_NONE,
2698 {(char_u *)0L, (char_u *)0L}
2699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002700 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 {"titlestring", NULL, P_STRING|P_VI_DEF,
2702#ifdef FEAT_TITLE
2703 (char_u *)&p_titlestring, PV_NONE,
2704#else
2705 (char_u *)NULL, PV_NONE,
2706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002709 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)"icons,tooltips", (char_u *)0L}
2712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002714#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2716 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718#endif
2719 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2720 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2723 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2726 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2729 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2732#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2733 (char_u *)&p_ttym, PV_NONE,
2734#else
2735 (char_u *)NULL, PV_NONE,
2736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002737 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2739 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002741 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2742 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002743 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002744 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2745 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002746#ifdef FEAT_PERSISTENT_UNDO
2747 (char_u *)&p_udir, PV_NONE,
2748 {(char_u *)".", (char_u *)0L}
2749#else
2750 (char_u *)NULL, PV_NONE,
2751 {(char_u *)0L, (char_u *)0L}
2752#endif
2753 SCRIPTID_INIT},
2754 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2755#ifdef FEAT_PERSISTENT_UNDO
2756 (char_u *)&p_udf, PV_UDF,
2757#else
2758 (char_u *)NULL, PV_NONE,
2759#endif
2760 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002762 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {
2764#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2765 (char_u *)1000L,
2766#else
2767 (char_u *)100L,
2768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002769 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002770 {"undoreload", "ur", P_NUM|P_VI_DEF,
2771 (char_u *)&p_ur, PV_NONE,
2772 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773 {"updatecount", "uc", P_NUM|P_VI_DEF,
2774 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 {"updatetime", "ut", P_NUM|P_VI_DEF,
2777 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"verbose", "vbs", P_NUM|P_VI_DEF,
2780 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002781 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002782 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2783 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2786#ifdef FEAT_SESSION
2787 (char_u *)&p_vdir, PV_NONE,
2788 {(char_u *)DFLT_VDIR, (char_u *)0L}
2789#else
2790 (char_u *)NULL, PV_NONE,
2791 {(char_u *)0L, (char_u *)0L}
2792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002794 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795#ifdef FEAT_SESSION
2796 (char_u *)&p_vop, PV_NONE,
2797 {(char_u *)"folds,options,cursor", (char_u *)0L}
2798#else
2799 (char_u *)NULL, PV_NONE,
2800 {(char_u *)0L, (char_u *)0L}
2801#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002803 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804#ifdef FEAT_VIMINFO
2805 (char_u *)&p_viminfo, PV_NONE,
2806#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002807 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808#else
2809# ifdef AMIGA
2810 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002811 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002813 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814# endif
2815#endif
2816#else
2817 (char_u *)NULL, PV_NONE,
2818 {(char_u *)0L, (char_u *)0L}
2819#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002821 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2822 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823#ifdef FEAT_VIRTUALEDIT
2824 (char_u *)&p_ve, PV_NONE,
2825 {(char_u *)"", (char_u *)""}
2826#else
2827 (char_u *)NULL, PV_NONE,
2828 {(char_u *)0L, (char_u *)0L}
2829#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002830 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2832 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"w300", NULL, P_NUM|P_VI_DEF,
2835 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"w1200", NULL, P_NUM|P_VI_DEF,
2838 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"w9600", NULL, P_NUM|P_VI_DEF,
2841 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"warn", NULL, P_BOOL|P_VI_DEF,
2844 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2847 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002849 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002851 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 {"wildchar", "wc", P_NUM|P_VIM,
2853 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002854 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2855 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002856 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002859 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860#ifdef FEAT_WILDIGN
2861 (char_u *)&p_wig, PV_NONE,
2862#else
2863 (char_u *)NULL, PV_NONE,
2864#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002866 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2867 (char_u *)&p_wic, PV_NONE,
2868 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2870#ifdef FEAT_WILDMENU
2871 (char_u *)&p_wmnu, PV_NONE,
2872#else
2873 (char_u *)NULL, PV_NONE,
2874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002875 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002876 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002879 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2880#ifdef FEAT_CMDL_COMPL
2881 (char_u *)&p_wop, PV_NONE,
2882 {(char_u *)"", (char_u *)0L}
2883#else
2884 (char_u *)NULL, PV_NONE,
2885 {(char_u *)NULL, (char_u *)0L}
2886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002887 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2889#ifdef FEAT_WAK
2890 (char_u *)&p_wak, PV_NONE,
2891 {(char_u *)"menu", (char_u *)0L}
2892#else
2893 (char_u *)NULL, PV_NONE,
2894 {(char_u *)NULL, (char_u *)0L}
2895#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002896 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002898 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002899 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 {"winheight", "wh", P_NUM|P_VI_DEF,
2901#ifdef FEAT_WINDOWS
2902 (char_u *)&p_wh, PV_NONE,
2903#else
2904 (char_u *)NULL, PV_NONE,
2905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002906 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002908#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 (char_u *)VAR_WIN, PV_WFH,
2910#else
2911 (char_u *)NULL, PV_NONE,
2912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002913 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002914 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2915#ifdef FEAT_VERTSPLIT
2916 (char_u *)VAR_WIN, PV_WFW,
2917#else
2918 (char_u *)NULL, PV_NONE,
2919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2922#ifdef FEAT_WINDOWS
2923 (char_u *)&p_wmh, PV_NONE,
2924#else
2925 (char_u *)NULL, PV_NONE,
2926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2929#ifdef FEAT_VERTSPLIT
2930 (char_u *)&p_wmw, PV_NONE,
2931#else
2932 (char_u *)NULL, PV_NONE,
2933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2936#ifdef FEAT_VERTSPLIT
2937 (char_u *)&p_wiw, PV_NONE,
2938#else
2939 (char_u *)NULL, PV_NONE,
2940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002941 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2943 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002944 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2946 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2949 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 {"write", NULL, P_BOOL|P_VI_DEF,
2952 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002953 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 {"writeany", "wa", P_BOOL|P_VI_DEF,
2955 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002956 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2958 (char_u *)&p_wb, PV_NONE,
2959 {
2960#ifdef FEAT_WRITEBACKUP
2961 (char_u *)TRUE,
2962#else
2963 (char_u *)FALSE,
2964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002965 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 {"writedelay", "wd", P_NUM|P_VI_DEF,
2967 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002968 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969
2970/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002971#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002973 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974
2975 p_term("t_AB", T_CAB)
2976 p_term("t_AF", T_CAF)
2977 p_term("t_AL", T_CAL)
2978 p_term("t_al", T_AL)
2979 p_term("t_bc", T_BC)
2980 p_term("t_cd", T_CD)
2981 p_term("t_ce", T_CE)
2982 p_term("t_cl", T_CL)
2983 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002984 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 p_term("t_Co", T_CCO)
2986 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002987 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 p_term("t_cs", T_CS)
2989#ifdef FEAT_VERTSPLIT
2990 p_term("t_CV", T_CSV)
2991#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 p_term("t_da", T_DA)
2993 p_term("t_db", T_DB)
2994 p_term("t_DL", T_CDL)
2995 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002996 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 p_term("t_fs", T_FS)
2998 p_term("t_IE", T_CIE)
2999 p_term("t_IS", T_CIS)
3000 p_term("t_ke", T_KE)
3001 p_term("t_ks", T_KS)
3002 p_term("t_le", T_LE)
3003 p_term("t_mb", T_MB)
3004 p_term("t_md", T_MD)
3005 p_term("t_me", T_ME)
3006 p_term("t_mr", T_MR)
3007 p_term("t_ms", T_MS)
3008 p_term("t_nd", T_ND)
3009 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003010 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_RI", T_CRI)
3012 p_term("t_RV", T_CRV)
3013 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003015 p_term("t_Sf", T_CSF)
3016 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003018 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 p_term("t_te", T_TE)
3021 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003022 p_term("t_ts", T_TS)
3023 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024 p_term("t_ue", T_UE)
3025 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003026 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 p_term("t_vb", T_VB)
3028 p_term("t_ve", T_VE)
3029 p_term("t_vi", T_VI)
3030 p_term("t_vs", T_VS)
3031 p_term("t_WP", T_CWP)
3032 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003033 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 p_term("t_xs", T_XS)
3035 p_term("t_ZH", T_CZH)
3036 p_term("t_ZR", T_CZR)
3037
3038/* terminal key codes are not in here */
3039
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003040 /* end marker */
3041 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042};
3043
3044#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3045
3046#ifdef FEAT_MBYTE
3047static char *(p_ambw_values[]) = {"single", "double", NULL};
3048#endif
3049static char *(p_bg_values[]) = {"light", "dark", NULL};
3050static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3051static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003052#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003053static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003054#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003055#ifdef FEAT_CMDL_COMPL
3056static char *(p_wop_values[]) = {"tagfile", NULL};
3057#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058#ifdef FEAT_WAK
3059static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3060#endif
3061static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3063static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065#ifdef FEAT_BROWSE
3066static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3067#endif
3068#ifdef FEAT_SCROLLBIND
3069static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3070#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003071static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072#ifdef FEAT_VERTSPLIT
3073static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3074#endif
3075#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003076# ifdef FEAT_AUTOCMD
3077static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3078# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003080# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3082#endif
3083static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3084#ifdef FEAT_FOLDING
3085static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003086# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003088# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 NULL};
3090static char *(p_fcl_values[]) = {"all", NULL};
3091#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003092#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003093static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003094#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095
3096static void set_option_default __ARGS((int, int opt_flags, int compatible));
3097static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003098static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003099static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100static char_u *illegal_char __ARGS((char_u *, int));
3101static int string_to_key __ARGS((char_u *arg));
3102#ifdef FEAT_CMDWIN
3103static char_u *check_cedit __ARGS((void));
3104#endif
3105#ifdef FEAT_TITLE
3106static void did_set_title __ARGS((int icon));
3107#endif
3108static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3109static void didset_options __ARGS((void));
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003110static void didset_options2 __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003112#if defined(FEAT_EVAL) || defined(PROTO)
3113static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3114#else
3115# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3116#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003118static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
3120static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003121#ifdef FEAT_SYN_HL
3122static int int_cmp __ARGS((const void *a, const void *b));
3123#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124#ifdef FEAT_CLIPBOARD
3125static char_u *check_clipboard_option __ARGS((void));
3126#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003127#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003128static char_u *did_set_spell_option __ARGS((int is_spellfile));
Bram Moolenaar860cae12010-06-05 23:22:07 +02003129static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003130#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003131#ifdef FEAT_EVAL
3132static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003135static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136static void check_redraw __ARGS((long_u flags));
3137static int findoption __ARGS((char_u *));
3138static int find_key_option __ARGS((char_u *));
3139static void showoptions __ARGS((int all, int opt_flags));
3140static int optval_default __ARGS((struct vimoption *, char_u *varp));
3141static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3142static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3143static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3144static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3145static int istermoption __ARGS((struct vimoption *));
3146static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3147static char_u *get_varp __ARGS((struct vimoption *));
3148static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003149static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3151#ifdef FEAT_LANGMAP
3152static void langmap_init __ARGS((void));
3153static void langmap_set __ARGS((void));
3154#endif
3155static void paste_option_changed __ARGS((void));
3156static void compatible_set __ARGS((void));
3157#ifdef FEAT_LINEBREAK
3158static void fill_breakat_flags __ARGS((void));
3159#endif
3160static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3161static int check_opt_strings __ARGS((char_u *val, char **values, int));
3162static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003163#ifdef FEAT_LINEBREAK
3164static int briopt_check __ARGS((win_T *wp));
3165#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166
3167/*
3168 * Initialize the options, first part.
3169 *
3170 * Called only once from main(), just after creating the first buffer.
3171 */
3172 void
3173set_init_1()
3174{
3175 char_u *p;
3176 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003177 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178
3179#ifdef FEAT_LANGMAP
3180 langmap_init();
3181#endif
3182
3183 /* Be Vi compatible by default */
3184 p_cp = TRUE;
3185
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003186 /* Use POSIX compatibility when $VIM_POSIX is set. */
3187 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003188 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003189 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003190 set_string_default("shm", (char_u *)"A");
3191 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003192
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 /*
3194 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003195 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003197 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3199# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003200 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003202 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003204 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205# endif
3206#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003207 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208 set_string_default("sh", p);
3209
3210#ifdef FEAT_WILDIGN
3211 /*
3212 * Set the default for 'backupskip' to include environment variables for
3213 * temp files.
3214 */
3215 {
3216# ifdef UNIX
3217 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3218# else
3219 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3220# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003221 int len;
3222 garray_T ga;
3223 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224
3225 ga_init2(&ga, 1, 100);
3226 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3227 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003228 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229# ifdef UNIX
3230 if (*names[n] == NUL)
3231 p = (char_u *)"/tmp";
3232 else
3233# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003234 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235 if (p != NULL && *p != NUL)
3236 {
3237 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003238 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239 if (ga_grow(&ga, len) == OK)
3240 {
3241 if (ga.ga_len > 0)
3242 STRCAT(ga.ga_data, ",");
3243 STRCAT(ga.ga_data, p);
3244 add_pathsep(ga.ga_data);
3245 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 ga.ga_len += len;
3247 }
3248 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003249 if (mustfree)
3250 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251 }
3252 if (ga.ga_data != NULL)
3253 {
3254 set_string_default("bsk", ga.ga_data);
3255 vim_free(ga.ga_data);
3256 }
3257 }
3258#endif
3259
3260 /*
3261 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3262 */
3263 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003264 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003266#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3267 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3268#endif
3269 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003271 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003272 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273#else
3274# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003275 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003276 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003278 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279# endif
3280#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003282 opt_idx = findoption((char_u *)"maxmem");
3283 if (opt_idx >= 0)
3284 {
3285#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003286 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003287 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3288#endif
3289 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3290 }
3291 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292 }
3293
3294#ifdef FEAT_GUI_W32
3295 /* force 'shortname' for Win32s */
3296 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003297 {
3298 opt_idx = findoption((char_u *)"shortname");
3299 if (opt_idx >= 0)
3300 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3301 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302#endif
3303
3304#ifdef FEAT_SEARCHPATH
3305 {
3306 char_u *cdpath;
3307 char_u *buf;
3308 int i;
3309 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003310 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311
3312 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003313 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314 if (cdpath != NULL)
3315 {
3316 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3317 if (buf != NULL)
3318 {
3319 buf[0] = ','; /* start with ",", current dir first */
3320 j = 1;
3321 for (i = 0; cdpath[i] != NUL; ++i)
3322 {
3323 if (vim_ispathlistsep(cdpath[i]))
3324 buf[j++] = ',';
3325 else
3326 {
3327 if (cdpath[i] == ' ' || cdpath[i] == ',')
3328 buf[j++] = '\\';
3329 buf[j++] = cdpath[i];
3330 }
3331 }
3332 buf[j] = NUL;
3333 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003334 if (opt_idx >= 0)
3335 {
3336 options[opt_idx].def_val[VI_DEFAULT] = buf;
3337 options[opt_idx].flags |= P_DEF_ALLOCED;
3338 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003339 else
3340 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003342 if (mustfree)
3343 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 }
3345 }
3346#endif
3347
3348#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3349 /* Set print encoding on platforms that don't default to latin1 */
3350 set_string_default("penc",
3351# if defined(MSWIN) || defined(OS2)
3352 (char_u *)"cp1252"
3353# else
3354# ifdef VMS
3355 (char_u *)"dec-mcs"
3356# else
3357# ifdef EBCDIC
3358 (char_u *)"ebcdic-uk"
3359# else
3360# ifdef MAC
3361 (char_u *)"mac-roman"
3362# else /* HPUX */
3363 (char_u *)"hp-roman8"
3364# endif
3365# endif
3366# endif
3367# endif
3368 );
3369#endif
3370
3371#ifdef FEAT_POSTSCRIPT
3372 /* 'printexpr' must be allocated to be able to evaluate it. */
3373 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003374# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3375 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376# else
3377# ifdef VMS
3378 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3379
3380# else
3381 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3382# endif
3383# endif
3384 );
3385#endif
3386
3387 /*
3388 * Set all the options (except the terminal options) to their default
3389 * value. Also set the global value for local options.
3390 */
3391 set_options_default(0);
3392
3393#ifdef FEAT_GUI
3394 if (found_reverse_arg)
3395 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3396#endif
3397
3398 curbuf->b_p_initialized = TRUE;
3399 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003400 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401 check_buf_options(curbuf);
3402 check_win_options(curwin);
3403 check_options();
3404
3405 /* Must be before option_expand(), because that one needs vim_isIDc() */
3406 didset_options();
3407
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003408#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003409 /* Use the current chartab for the generic chartab. This is not in
3410 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003411 init_spell_chartab();
3412#endif
3413
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414 /*
3415 * Expand environment variables and things like "~" for the defaults.
3416 * If option_expand() returns non-NULL the variable is expanded. This can
3417 * only happen for non-indirect options.
3418 * Also set the default to the expanded value, so ":set" does not list
3419 * them.
3420 * Don't set the P_ALLOCED flag, because we don't want to free the
3421 * default.
3422 */
3423 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3424 {
3425 if ((options[opt_idx].flags & P_GETTEXT)
3426 && options[opt_idx].var != NULL)
3427 p = (char_u *)_(*(char **)options[opt_idx].var);
3428 else
3429 p = option_expand(opt_idx, NULL);
3430 if (p != NULL && (p = vim_strsave(p)) != NULL)
3431 {
3432 *(char_u **)options[opt_idx].var = p;
3433 /* VIMEXP
3434 * Defaults for all expanded options are currently the same for Vi
3435 * and Vim. When this changes, add some code here! Also need to
3436 * split P_DEF_ALLOCED in two.
3437 */
3438 if (options[opt_idx].flags & P_DEF_ALLOCED)
3439 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3440 options[opt_idx].def_val[VI_DEFAULT] = p;
3441 options[opt_idx].flags |= P_DEF_ALLOCED;
3442 }
3443 }
3444
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445 save_file_ff(curbuf); /* Buffer is unchanged */
3446
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447#if defined(FEAT_ARABIC)
3448 /* Detect use of mlterm.
3449 * Mlterm is a terminal emulator akin to xterm that has some special
3450 * abilities (bidi namely).
3451 * NOTE: mlterm's author is being asked to 'set' a variable
3452 * instead of an environment variable due to inheritance.
3453 */
3454 if (mch_getenv((char_u *)"MLTERM") != NULL)
3455 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3456#endif
3457
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003458 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459
3460#ifdef FEAT_MBYTE
3461# if defined(WIN3264) && defined(FEAT_GETTEXT)
3462 /*
3463 * If $LANG isn't set, try to get a good value for it. This makes the
3464 * right language be used automatically. Don't do this for English.
3465 */
3466 if (mch_getenv((char_u *)"LANG") == NULL)
3467 {
3468 char buf[20];
3469
3470 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3471 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3472 * only the first two. */
3473 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3474 (LPTSTR)buf, 20);
3475 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3476 {
3477 /* There are a few exceptions (probably more) */
3478 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3479 STRCPY(buf, "zh_TW");
3480 else if (STRNICMP(buf, "chs", 3) == 0
3481 || STRNICMP(buf, "zhc", 3) == 0)
3482 STRCPY(buf, "zh_CN");
3483 else if (STRNICMP(buf, "jp", 2) == 0)
3484 STRCPY(buf, "ja");
3485 else
3486 buf[2] = NUL; /* truncate to two-letter code */
3487 vim_setenv("LANG", buf);
3488 }
3489 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003490# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003491# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003492 /* Moved to os_mac_conv.c to avoid dependency problems. */
3493 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003494# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003495# endif
3496
3497 /* enc_locale() will try to find the encoding of the current locale. */
3498 p = enc_locale();
3499 if (p != NULL)
3500 {
3501 char_u *save_enc;
3502
3503 /* Try setting 'encoding' and check if the value is valid.
3504 * If not, go back to the default "latin1". */
3505 save_enc = p_enc;
3506 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003507 if (STRCMP(p_enc, "gb18030") == 0)
3508 {
3509 /* We don't support "gb18030", but "cp936" is a good substitute
3510 * for practical purposes, thus use that. It's not an alias to
3511 * still support conversion between gb18030 and utf-8. */
3512 p_enc = vim_strsave((char_u *)"cp936");
3513 vim_free(p);
3514 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515 if (mb_init() == NULL)
3516 {
3517 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003518 if (opt_idx >= 0)
3519 {
3520 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3521 options[opt_idx].flags |= P_DEF_ALLOCED;
3522 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003523
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003524#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3525 || defined(VMS)
3526 if (STRCMP(p_enc, "latin1") == 0
3527# ifdef FEAT_MBYTE
3528 || enc_utf8
3529# endif
3530 )
3531 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003532 /* Adjust the default for 'isprint' and 'iskeyword' to match
3533 * latin1. Also set the defaults for when 'nocompatible' is
3534 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003535 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003536 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003537 set_string_option_direct((char_u *)"isk", -1,
3538 ISK_LATIN1, OPT_FREE, SID_NONE);
3539 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003540 if (opt_idx >= 0)
3541 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003542 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003543 if (opt_idx >= 0)
3544 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003545 (void)init_chartab();
3546 }
3547#endif
3548
Bram Moolenaar071d4272004-06-13 20:20:40 +00003549# if defined(WIN3264) && !defined(FEAT_GUI)
3550 /* Win32 console: When GetACP() returns a different value from
3551 * GetConsoleCP() set 'termencoding'. */
3552 if (GetACP() != GetConsoleCP())
3553 {
3554 char buf[50];
3555
3556 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3557 p_tenc = vim_strsave((char_u *)buf);
3558 if (p_tenc != NULL)
3559 {
3560 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003561 if (opt_idx >= 0)
3562 {
3563 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3564 options[opt_idx].flags |= P_DEF_ALLOCED;
3565 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003566 convert_setup(&input_conv, p_tenc, p_enc);
3567 convert_setup(&output_conv, p_enc, p_tenc);
3568 }
3569 else
3570 p_tenc = empty_option;
3571 }
3572# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003573# if defined(WIN3264) && defined(FEAT_MBYTE)
3574 /* $HOME may have characters in active code page. */
3575 init_homedir();
3576# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003577 }
3578 else
3579 {
3580 vim_free(p_enc);
3581 p_enc = save_enc;
3582 }
3583 }
3584#endif
3585
3586#ifdef FEAT_MULTI_LANG
3587 /* Set the default for 'helplang'. */
3588 set_helplang_default(get_mess_lang());
3589#endif
3590}
3591
3592/*
3593 * Set an option to its default value.
3594 * This does not take care of side effects!
3595 */
3596 static void
3597set_option_default(opt_idx, opt_flags, compatible)
3598 int opt_idx;
3599 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3600 int compatible; /* use Vi default value */
3601{
3602 char_u *varp; /* pointer to variable for current option */
3603 int dvi; /* index in def_val[] */
3604 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003605 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003606 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3607
3608 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3609 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003610 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611 {
3612 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3613 if (flags & P_STRING)
3614 {
3615 /* Use set_string_option_direct() for local options to handle
3616 * freeing and allocating the value. */
3617 if (options[opt_idx].indir != PV_NONE)
3618 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003619 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003620 else
3621 {
3622 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3623 free_string_option(*(char_u **)(varp));
3624 *(char_u **)varp = options[opt_idx].def_val[dvi];
3625 options[opt_idx].flags &= ~P_ALLOCED;
3626 }
3627 }
3628 else if (flags & P_NUM)
3629 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003630 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631 win_comp_scroll(curwin);
3632 else
3633 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003634 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635 /* May also set global value for local option. */
3636 if (both)
3637 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3638 *(long *)varp;
3639 }
3640 }
3641 else /* P_BOOL */
3642 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003643 /* the cast to long is required for Manx C, long_i is needed for
3644 * MSVC */
3645 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003646#ifdef UNIX
3647 /* 'modeline' defaults to off for root */
3648 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3649 *(int *)varp = FALSE;
3650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651 /* May also set global value for local option. */
3652 if (both)
3653 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3654 *(int *)varp;
3655 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003656
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003657 /* The default value is not insecure. */
3658 flagsp = insecure_flag(opt_idx, opt_flags);
3659 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003660 }
3661
3662#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003663 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003664#endif
3665}
3666
3667/*
3668 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003669 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003670 */
3671 static void
3672set_options_default(opt_flags)
3673 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3674{
3675 int i;
3676#ifdef FEAT_WINDOWS
3677 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003678 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003679#endif
3680
3681 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003682 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003683#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003684 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003685 || (TRUE
3686# if defined(FEAT_MBYTE)
3687 && options[i].var != (char_u *)&p_enc
3688# endif
3689# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003690 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003691 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003692# endif
3693 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003694#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003695 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 set_option_default(i, opt_flags, p_cp);
3697
3698#ifdef FEAT_WINDOWS
3699 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003700 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003701 win_comp_scroll(wp);
3702#else
3703 win_comp_scroll(curwin);
3704#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003705#ifdef FEAT_CINDENT
3706 parse_cino(curbuf);
3707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708}
3709
3710/*
3711 * Set the Vi-default value of a string option.
3712 * Used for 'sh', 'backupskip' and 'term'.
3713 */
3714 void
3715set_string_default(name, val)
3716 char *name;
3717 char_u *val;
3718{
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
3741set_number_default(name, val)
3742 char *name;
3743 long val;
3744{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003745 int opt_idx;
3746
3747 opt_idx = findoption((char_u *)name);
3748 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003749 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750}
3751
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003752#if defined(EXITFREE) || defined(PROTO)
3753/*
3754 * Free all options.
3755 */
3756 void
3757free_all_options()
3758{
3759 int i;
3760
3761 for (i = 0; !istermoption(&options[i]); i++)
3762 {
3763 if (options[i].indir == PV_NONE)
3764 {
3765 /* global option: free value and default value. */
3766 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3767 free_string_option(*(char_u **)options[i].var);
3768 if (options[i].flags & P_DEF_ALLOCED)
3769 free_string_option(options[i].def_val[VI_DEFAULT]);
3770 }
3771 else if (options[i].var != VAR_WIN
3772 && (options[i].flags & P_STRING))
3773 /* buffer-local option: free global value */
3774 free_string_option(*(char_u **)options[i].var);
3775 }
3776}
3777#endif
3778
3779
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780/*
3781 * Initialize the options, part two: After getting Rows and Columns and
3782 * setting 'term'.
3783 */
3784 void
3785set_init_2()
3786{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003787 int idx;
3788
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 /*
3790 * 'scroll' defaults to half the window height. Note that this default is
3791 * wrong when the window height changes.
3792 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003793 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003794 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003795 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003796 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 comp_col();
3798
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003799 /*
3800 * 'window' is only for backwards compatibility with Vi.
3801 * Default is Rows - 1.
3802 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003803 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003804 p_window = Rows - 1;
3805 set_number_default("window", Rows - 1);
3806
Bram Moolenaarf740b292006-02-16 22:11:02 +00003807 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003809 /*
3810 * If 'background' wasn't set by the user, try guessing the value,
3811 * depending on the terminal name. Only need to check for terminals
3812 * with a dark background, that can handle color.
3813 */
3814 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003815 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3816 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003818 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003819 /* don't mark it as set, when starting the GUI it may be
3820 * changed again */
3821 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 }
3823#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003824
3825#ifdef CURSOR_SHAPE
3826 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3827#endif
3828#ifdef FEAT_MOUSESHAPE
3829 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3830#endif
3831#ifdef FEAT_PRINTER
3832 (void)parse_printoptions(); /* parse 'printoptions' default value */
3833#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834}
3835
3836/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003837 * Return "dark" or "light" depending on the kind of terminal.
3838 * This is just guessing! Recognized are:
3839 * "linux" Linux console
3840 * "screen.linux" Linux console with screen
3841 * "cygwin" Cygwin shell
3842 * "putty" Putty program
3843 * We also check the COLORFGBG environment variable, which is set by
3844 * rxvt and derivatives. This variable contains either two or three
3845 * values separated by semicolons; we want the last value in either
3846 * case. If this value is 0-6 or 8, our background is dark.
3847 */
3848 static char_u *
3849term_bg_default()
3850{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003851#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3852 /* DOS console nearly always black */
3853 return (char_u *)"dark";
3854#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003855 char_u *p;
3856
Bram Moolenaarf740b292006-02-16 22:11:02 +00003857 if (STRCMP(T_NAME, "linux") == 0
3858 || STRCMP(T_NAME, "screen.linux") == 0
3859 || STRCMP(T_NAME, "cygwin") == 0
3860 || STRCMP(T_NAME, "putty") == 0
3861 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3862 && (p = vim_strrchr(p, ';')) != NULL
3863 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3864 && p[2] == NUL))
3865 return (char_u *)"dark";
3866 return (char_u *)"light";
3867#endif
3868}
3869
3870/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871 * Initialize the options, part three: After reading the .vimrc
3872 */
3873 void
3874set_init_3()
3875{
3876#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3877/*
3878 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3879 * This is done after other initializations, where 'shell' might have been
3880 * set, but only if they have not been set before.
3881 */
3882 char_u *p;
3883 int idx_srr;
3884 int do_srr;
3885#ifdef FEAT_QUICKFIX
3886 int idx_sp;
3887 int do_sp;
3888#endif
3889
3890 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003891 if (idx_srr < 0)
3892 do_srr = FALSE;
3893 else
3894 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895#ifdef FEAT_QUICKFIX
3896 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003897 if (idx_sp < 0)
3898 do_sp = FALSE;
3899 else
3900 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003902 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903 if (p != NULL)
3904 {
3905 /*
3906 * Default for p_sp is "| tee", for p_srr is ">".
3907 * For known shells it is changed here to include stderr.
3908 */
3909 if ( fnamecmp(p, "csh") == 0
3910 || fnamecmp(p, "tcsh") == 0
3911# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3912 || fnamecmp(p, "csh.exe") == 0
3913 || fnamecmp(p, "tcsh.exe") == 0
3914# endif
3915 )
3916 {
3917#if defined(FEAT_QUICKFIX)
3918 if (do_sp)
3919 {
3920# ifdef WIN3264
3921 p_sp = (char_u *)">&";
3922# else
3923 p_sp = (char_u *)"|& tee";
3924# endif
3925 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3926 }
3927#endif
3928 if (do_srr)
3929 {
3930 p_srr = (char_u *)">&";
3931 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3932 }
3933 }
3934 else
3935# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3936 if ( fnamecmp(p, "sh") == 0
3937 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003938 || fnamecmp(p, "mksh") == 0
3939 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003941 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003943 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944# ifdef WIN3264
3945 || fnamecmp(p, "cmd") == 0
3946 || fnamecmp(p, "sh.exe") == 0
3947 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003948 || fnamecmp(p, "mksh.exe") == 0
3949 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003951 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 || fnamecmp(p, "bash.exe") == 0
3953 || fnamecmp(p, "cmd.exe") == 0
3954# endif
3955 )
3956# endif
3957 {
3958#if defined(FEAT_QUICKFIX)
3959 if (do_sp)
3960 {
3961# ifdef WIN3264
3962 p_sp = (char_u *)">%s 2>&1";
3963# else
3964 p_sp = (char_u *)"2>&1| tee";
3965# endif
3966 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3967 }
3968#endif
3969 if (do_srr)
3970 {
3971 p_srr = (char_u *)">%s 2>&1";
3972 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3973 }
3974 }
3975 vim_free(p);
3976 }
3977#endif
3978
3979#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3980 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003981 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3982 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983 * This is done after other initializations, where 'shell' might have been
3984 * set, but only if they have not been set before. Default for p_shcf is
3985 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3986 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3987 * command.com. And for Win32 we need to set p_sxq instead.
3988 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003989 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990 {
3991 int idx3;
3992
3993 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003994 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 {
3996 p_shcf = (char_u *)"-c";
3997 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3998 }
3999
4000# ifndef DJGPP
4001# ifdef WIN3264
4002 /* Somehow Win32 requires the quotes around the redirection too */
4003 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004004 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 {
4006 p_sxq = (char_u *)"\"";
4007 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4008 }
4009# else
4010 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004011 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012 {
4013 p_shq = (char_u *)"\"";
4014 options[idx3].def_val[VI_DEFAULT] = p_shq;
4015 }
4016# endif
4017# endif
4018 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004019 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4020 {
4021 int idx3;
4022
4023 /*
4024 * cmd.exe on Windows will strip the first and last double quote given
4025 * on the command line, e.g. most of the time things like:
4026 * cmd /c "my path/to/echo" "my args to echo"
4027 * become:
4028 * my path/to/echo" "my args to echo
4029 * when executed.
4030 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004031 * To avoid this, set shellxquote to surround the command in
4032 * parenthesis. This appears to make most commands work, without
4033 * breaking commands that worked previously, such as
4034 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004035 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004036 idx3 = findoption((char_u *)"sxq");
4037 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4038 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004039 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004040 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4041 }
4042
Bram Moolenaara64ba222012-02-12 23:23:31 +01004043 idx3 = findoption((char_u *)"shcf");
4044 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4045 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004046 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004047 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4048 }
4049 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050#endif
4051
4052#ifdef FEAT_TITLE
4053 set_title_defaults();
4054#endif
4055}
4056
4057#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4058/*
4059 * When 'helplang' is still at its default value, set it to "lang".
4060 * Only the first two characters of "lang" are used.
4061 */
4062 void
4063set_helplang_default(lang)
4064 char_u *lang;
4065{
4066 int idx;
4067
4068 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4069 return;
4070 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004071 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 {
4073 if (options[idx].flags & P_ALLOCED)
4074 free_string_option(p_hlg);
4075 p_hlg = vim_strsave(lang);
4076 if (p_hlg == NULL)
4077 p_hlg = empty_option;
4078 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004079 {
4080 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4081 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4082 {
4083 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4084 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 options[idx].flags |= P_ALLOCED;
4089 }
4090}
4091#endif
4092
4093#ifdef FEAT_GUI
4094static char_u *gui_bg_default __ARGS((void));
4095
4096 static char_u *
4097gui_bg_default()
4098{
4099 if (gui_get_lightness(gui.back_pixel) < 127)
4100 return (char_u *)"dark";
4101 return (char_u *)"light";
4102}
4103
4104/*
4105 * Option initializations that can only be done after opening the GUI window.
4106 */
4107 void
4108init_gui_options()
4109{
4110 /* Set the 'background' option according to the lightness of the
4111 * background color, unless the user has set it already. */
4112 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4113 {
4114 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4115 highlight_changed();
4116 }
4117}
4118#endif
4119
4120#ifdef FEAT_TITLE
4121/*
4122 * 'title' and 'icon' only default to true if they have not been set or reset
4123 * in .vimrc and we can read the old value.
4124 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4125 * they can be reset. This reduces startup time when using X on a remote
4126 * machine.
4127 */
4128 void
4129set_title_defaults()
4130{
4131 int idx1;
4132 long val;
4133
4134 /*
4135 * If GUI is (going to be) used, we can always set the window title and
4136 * icon name. Saves a bit of time, because the X11 display server does
4137 * not need to be contacted.
4138 */
4139 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004140 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 {
4142#ifdef FEAT_GUI
4143 if (gui.starting || gui.in_use)
4144 val = TRUE;
4145 else
4146#endif
4147 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004148 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 p_title = val;
4150 }
4151 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004152 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 {
4154#ifdef FEAT_GUI
4155 if (gui.starting || gui.in_use)
4156 val = TRUE;
4157 else
4158#endif
4159 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004160 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 p_icon = val;
4162 }
4163}
4164#endif
4165
4166/*
4167 * Parse 'arg' for option settings.
4168 *
4169 * 'arg' may be IObuff, but only when no errors can be present and option
4170 * does not need to be expanded with option_expand().
4171 * "opt_flags":
4172 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004173 * OPT_GLOBAL for ":setglobal"
4174 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004175 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004176 * OPT_WINONLY to only set window-local options
4177 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004178 *
4179 * returns FAIL if an error is detected, OK otherwise
4180 */
4181 int
4182do_set(arg, opt_flags)
4183 char_u *arg; /* option string (may be written to!) */
4184 int opt_flags;
4185{
4186 int opt_idx;
4187 char_u *errmsg;
4188 char_u errbuf[80];
4189 char_u *startarg;
4190 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4191 int nextchar; /* next non-white char after option name */
4192 int afterchar; /* character just after option name */
4193 int len;
4194 int i;
4195 long value;
4196 int key;
4197 long_u flags; /* flags for current option */
4198 char_u *varp = NULL; /* pointer to variable for current option */
4199 int did_show = FALSE; /* already showed one value */
4200 int adding; /* "opt+=arg" */
4201 int prepending; /* "opt^=arg" */
4202 int removing; /* "opt-=arg" */
4203 int cp_val = 0;
4204 char_u key_name[2];
4205
4206 if (*arg == NUL)
4207 {
4208 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004209 did_show = TRUE;
4210 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004211 }
4212
4213 while (*arg != NUL) /* loop to process all options */
4214 {
4215 errmsg = NULL;
4216 startarg = arg; /* remember for error message */
4217
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004218 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4219 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004220 {
4221 /*
4222 * ":set all" show all options.
4223 * ":set all&" set all options to their default value.
4224 */
4225 arg += 3;
4226 if (*arg == '&')
4227 {
4228 ++arg;
4229 /* Only for :set command set global value of local options. */
4230 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004231 didset_options();
4232 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004233 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234 }
4235 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004236 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004237 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004238 did_show = TRUE;
4239 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004241 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242 {
4243 showoptions(2, opt_flags);
4244 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004245 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246 arg += 7;
4247 }
4248 else
4249 {
4250 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004251 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004252 {
4253 prefix = 0;
4254 arg += 2;
4255 }
4256 else if (STRNCMP(arg, "inv", 3) == 0)
4257 {
4258 prefix = 2;
4259 arg += 3;
4260 }
4261
4262 /* find end of name */
4263 key = 0;
4264 if (*arg == '<')
4265 {
4266 nextchar = 0;
4267 opt_idx = -1;
4268 /* look out for <t_>;> */
4269 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4270 len = 5;
4271 else
4272 {
4273 len = 1;
4274 while (arg[len] != NUL && arg[len] != '>')
4275 ++len;
4276 }
4277 if (arg[len] != '>')
4278 {
4279 errmsg = e_invarg;
4280 goto skip;
4281 }
4282 arg[len] = NUL; /* put NUL after name */
4283 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4284 opt_idx = findoption(arg + 1);
4285 arg[len++] = '>'; /* restore '>' */
4286 if (opt_idx == -1)
4287 key = find_key_option(arg + 1);
4288 }
4289 else
4290 {
4291 len = 0;
4292 /*
4293 * The two characters after "t_" may not be alphanumeric.
4294 */
4295 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4296 len = 4;
4297 else
4298 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4299 ++len;
4300 nextchar = arg[len];
4301 arg[len] = NUL; /* put NUL after name */
4302 opt_idx = findoption(arg);
4303 arg[len] = nextchar; /* restore nextchar */
4304 if (opt_idx == -1)
4305 key = find_key_option(arg);
4306 }
4307
4308 /* remember character after option name */
4309 afterchar = arg[len];
4310
4311 /* skip white space, allow ":set ai ?" */
4312 while (vim_iswhite(arg[len]))
4313 ++len;
4314
4315 adding = FALSE;
4316 prepending = FALSE;
4317 removing = FALSE;
4318 if (arg[len] != NUL && arg[len + 1] == '=')
4319 {
4320 if (arg[len] == '+')
4321 {
4322 adding = TRUE; /* "+=" */
4323 ++len;
4324 }
4325 else if (arg[len] == '^')
4326 {
4327 prepending = TRUE; /* "^=" */
4328 ++len;
4329 }
4330 else if (arg[len] == '-')
4331 {
4332 removing = TRUE; /* "-=" */
4333 ++len;
4334 }
4335 }
4336 nextchar = arg[len];
4337
4338 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4339 {
4340 errmsg = (char_u *)N_("E518: Unknown option");
4341 goto skip;
4342 }
4343
4344 if (opt_idx >= 0)
4345 {
4346 if (options[opt_idx].var == NULL) /* hidden option: skip */
4347 {
4348 /* Only give an error message when requesting the value of
4349 * a hidden option, ignore setting it. */
4350 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4351 && (!(options[opt_idx].flags & P_BOOL)
4352 || nextchar == '?'))
4353 errmsg = (char_u *)N_("E519: Option not supported");
4354 goto skip;
4355 }
4356
4357 flags = options[opt_idx].flags;
4358 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4359 }
4360 else
4361 {
4362 flags = P_STRING;
4363 if (key < 0)
4364 {
4365 key_name[0] = KEY2TERMCAP0(key);
4366 key_name[1] = KEY2TERMCAP1(key);
4367 }
4368 else
4369 {
4370 key_name[0] = KS_KEY;
4371 key_name[1] = (key & 0xff);
4372 }
4373 }
4374
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004375 /* Skip all options that are not window-local (used when showing
4376 * an already loaded buffer in a window). */
4377 if ((opt_flags & OPT_WINONLY)
4378 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4379 goto skip;
4380
Bram Moolenaara3227e22006-03-08 21:32:40 +00004381 /* Skip all options that are window-local (used for :vimgrep). */
4382 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4383 && options[opt_idx].var == VAR_WIN)
4384 goto skip;
4385
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004386 /* Disallow changing some options from modelines. */
4387 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004388 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004389 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004390 {
4391 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4392 goto skip;
4393 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004394#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004395 /* In diff mode some options are overruled. This avoids that
4396 * 'foldmethod' becomes "marker" instead of "diff" and that
4397 * "wrap" gets set. */
4398 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004399 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004400 && (options[opt_idx].indir == PV_FDM
4401 || options[opt_idx].indir == PV_WRAP))
4402 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 }
4405
4406#ifdef HAVE_SANDBOX
4407 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004408 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004409 {
4410 errmsg = (char_u *)_(e_sandbox);
4411 goto skip;
4412 }
4413#endif
4414
4415 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4416 {
4417 arg += len;
4418 cp_val = p_cp;
4419 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4420 {
4421 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4422 {
4423 cp_val = FALSE;
4424 arg += 3;
4425 }
4426 else /* "opt&vi": set to Vi default */
4427 {
4428 cp_val = TRUE;
4429 arg += 2;
4430 }
4431 }
4432 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4433 && arg[1] != NUL && !vim_iswhite(arg[1]))
4434 {
4435 errmsg = e_trailing;
4436 goto skip;
4437 }
4438 }
4439
4440 /*
4441 * allow '=' and ':' as MSDOS command.com allows only one
4442 * '=' character per "set" command line. grrr. (jw)
4443 */
4444 if (nextchar == '?'
4445 || (prefix == 1
4446 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4447 && !(flags & P_BOOL)))
4448 {
4449 /*
4450 * print value
4451 */
4452 if (did_show)
4453 msg_putchar('\n'); /* cursor below last one */
4454 else
4455 {
4456 gotocmdline(TRUE); /* cursor at status line */
4457 did_show = TRUE; /* remember that we did a line */
4458 }
4459 if (opt_idx >= 0)
4460 {
4461 showoneopt(&options[opt_idx], opt_flags);
4462#ifdef FEAT_EVAL
4463 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004464 {
4465 /* Mention where the option was last set. */
4466 if (varp == options[opt_idx].var)
4467 last_set_msg(options[opt_idx].scriptID);
4468 else if ((int)options[opt_idx].indir & PV_WIN)
4469 last_set_msg(curwin->w_p_scriptID[
4470 (int)options[opt_idx].indir & PV_MASK]);
4471 else if ((int)options[opt_idx].indir & PV_BUF)
4472 last_set_msg(curbuf->b_p_scriptID[
4473 (int)options[opt_idx].indir & PV_MASK]);
4474 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004475#endif
4476 }
4477 else
4478 {
4479 char_u *p;
4480
4481 p = find_termcode(key_name);
4482 if (p == NULL)
4483 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004484 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004485 goto skip;
4486 }
4487 else
4488 (void)show_one_termcode(key_name, p, TRUE);
4489 }
4490 if (nextchar != '?'
4491 && nextchar != NUL && !vim_iswhite(afterchar))
4492 errmsg = e_trailing;
4493 }
4494 else
4495 {
4496 if (flags & P_BOOL) /* boolean */
4497 {
4498 if (nextchar == '=' || nextchar == ':')
4499 {
4500 errmsg = e_invarg;
4501 goto skip;
4502 }
4503
4504 /*
4505 * ":set opt!": invert
4506 * ":set opt&": reset to default value
4507 * ":set opt<": reset to global value
4508 */
4509 if (nextchar == '!')
4510 value = *(int *)(varp) ^ 1;
4511 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004512 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004513 ((flags & P_VI_DEF) || cp_val)
4514 ? VI_DEFAULT : VIM_DEFAULT];
4515 else if (nextchar == '<')
4516 {
4517 /* For 'autoread' -1 means to use global value. */
4518 if ((int *)varp == &curbuf->b_p_ar
4519 && opt_flags == OPT_LOCAL)
4520 value = -1;
4521 else
4522 value = *(int *)get_varp_scope(&(options[opt_idx]),
4523 OPT_GLOBAL);
4524 }
4525 else
4526 {
4527 /*
4528 * ":set invopt": invert
4529 * ":set opt" or ":set noopt": set or reset
4530 */
4531 if (nextchar != NUL && !vim_iswhite(afterchar))
4532 {
4533 errmsg = e_trailing;
4534 goto skip;
4535 }
4536 if (prefix == 2) /* inv */
4537 value = *(int *)(varp) ^ 1;
4538 else
4539 value = prefix;
4540 }
4541
4542 errmsg = set_bool_option(opt_idx, varp, (int)value,
4543 opt_flags);
4544 }
4545 else /* numeric or string */
4546 {
4547 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4548 || prefix != 1)
4549 {
4550 errmsg = e_invarg;
4551 goto skip;
4552 }
4553
4554 if (flags & P_NUM) /* numeric */
4555 {
4556 /*
4557 * Different ways to set a number option:
4558 * & set to default value
4559 * < set to global value
4560 * <xx> accept special key codes for 'wildchar'
4561 * c accept any non-digit for 'wildchar'
4562 * [-]0-9 set number
4563 * other error
4564 */
4565 ++arg;
4566 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004567 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004568 ((flags & P_VI_DEF) || cp_val)
4569 ? VI_DEFAULT : VIM_DEFAULT];
4570 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004571 {
4572 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4573 * use the global value. */
4574 if ((long *)varp == &curbuf->b_p_ul
4575 && opt_flags == OPT_LOCAL)
4576 value = NO_LOCAL_UNDOLEVEL;
4577 else
4578 value = *(long *)get_varp_scope(
4579 &(options[opt_idx]), OPT_GLOBAL);
4580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 else if (((long *)varp == &p_wc
4582 || (long *)varp == &p_wcm)
4583 && (*arg == '<'
4584 || *arg == '^'
4585 || ((!arg[1] || vim_iswhite(arg[1]))
4586 && !VIM_ISDIGIT(*arg))))
4587 {
4588 value = string_to_key(arg);
4589 if (value == 0 && (long *)varp != &p_wcm)
4590 {
4591 errmsg = e_invarg;
4592 goto skip;
4593 }
4594 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004595 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4596 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004597 /* Allow negative (for 'undolevels'), octal and
4598 * hex numbers. */
Bram Moolenaar5d1bc782015-07-17 13:03:48 +02004599 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004600 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4601 {
4602 errmsg = e_invarg;
4603 goto skip;
4604 }
4605 }
4606 else
4607 {
4608 errmsg = (char_u *)N_("E521: Number required after =");
4609 goto skip;
4610 }
4611
4612 if (adding)
4613 value = *(long *)varp + value;
4614 if (prepending)
4615 value = *(long *)varp * value;
4616 if (removing)
4617 value = *(long *)varp - value;
4618 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004619 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004620 }
4621 else if (opt_idx >= 0) /* string */
4622 {
4623 char_u *save_arg = NULL;
4624 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004625 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004626 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004627 char_u *origval = NULL;
4628#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4629 char_u *saved_origval = NULL;
4630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004631 unsigned newlen;
4632 int comma;
4633 int bs;
4634 int new_value_alloced; /* new string option
4635 was allocated */
4636
4637 /* When using ":set opt=val" for a global option
4638 * with a local value the local value will be
4639 * reset, use the global value here. */
4640 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004641 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004642 varp = options[opt_idx].var;
4643
4644 /* The old value is kept until we are sure that the
4645 * new value is valid. */
4646 oldval = *(char_u **)varp;
4647 if (nextchar == '&') /* set to default val */
4648 {
4649 newval = options[opt_idx].def_val[
4650 ((flags & P_VI_DEF) || cp_val)
4651 ? VI_DEFAULT : VIM_DEFAULT];
4652 if ((char_u **)varp == &p_bg)
4653 {
4654 /* guess the value of 'background' */
4655#ifdef FEAT_GUI
4656 if (gui.in_use)
4657 newval = gui_bg_default();
4658 else
4659#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004660 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004661 }
4662
4663 /* expand environment variables and ~ (since the
4664 * default value was already expanded, only
4665 * required when an environment variable was set
4666 * later */
4667 if (newval == NULL)
4668 newval = empty_option;
4669 else
4670 {
4671 s = option_expand(opt_idx, newval);
4672 if (s == NULL)
4673 s = newval;
4674 newval = vim_strsave(s);
4675 }
4676 new_value_alloced = TRUE;
4677 }
4678 else if (nextchar == '<') /* set to global val */
4679 {
4680 newval = vim_strsave(*(char_u **)get_varp_scope(
4681 &(options[opt_idx]), OPT_GLOBAL));
4682 new_value_alloced = TRUE;
4683 }
4684 else
4685 {
4686 ++arg; /* jump to after the '=' or ':' */
4687
4688 /*
4689 * Set 'keywordprg' to ":help" if an empty
4690 * value was passed to :set by the user.
4691 * Misuse errbuf[] for the resulting string.
4692 */
4693 if (varp == (char_u *)&p_kp
4694 && (*arg == NUL || *arg == ' '))
4695 {
4696 STRCPY(errbuf, ":help");
4697 save_arg = arg;
4698 arg = errbuf;
4699 }
4700 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004701 * Convert 'backspace' number to string, for
4702 * adding, prepending and removing string.
4703 */
4704 else if (varp == (char_u *)&p_bs
4705 && VIM_ISDIGIT(**(char_u **)varp))
4706 {
4707 i = getdigits((char_u **)varp);
4708 switch (i)
4709 {
4710 case 0:
4711 *(char_u **)varp = empty_option;
4712 break;
4713 case 1:
4714 *(char_u **)varp = vim_strsave(
4715 (char_u *)"indent,eol");
4716 break;
4717 case 2:
4718 *(char_u **)varp = vim_strsave(
4719 (char_u *)"indent,eol,start");
4720 break;
4721 }
4722 vim_free(oldval);
4723 oldval = *(char_u **)varp;
4724 }
4725 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004726 * Convert 'whichwrap' number to string, for
4727 * backwards compatibility with Vim 3.0.
4728 * Misuse errbuf[] for the resulting string.
4729 */
4730 else if (varp == (char_u *)&p_ww
4731 && VIM_ISDIGIT(*arg))
4732 {
4733 *errbuf = NUL;
4734 i = getdigits(&arg);
4735 if (i & 1)
4736 STRCAT(errbuf, "b,");
4737 if (i & 2)
4738 STRCAT(errbuf, "s,");
4739 if (i & 4)
4740 STRCAT(errbuf, "h,l,");
4741 if (i & 8)
4742 STRCAT(errbuf, "<,>,");
4743 if (i & 16)
4744 STRCAT(errbuf, "[,],");
4745 if (*errbuf != NUL) /* remove trailing , */
4746 errbuf[STRLEN(errbuf) - 1] = NUL;
4747 save_arg = arg;
4748 arg = errbuf;
4749 }
4750 /*
4751 * Remove '>' before 'dir' and 'bdir', for
4752 * backwards compatibility with version 3.0
4753 */
4754 else if ( *arg == '>'
4755 && (varp == (char_u *)&p_dir
4756 || varp == (char_u *)&p_bdir))
4757 {
4758 ++arg;
4759 }
4760
4761 /* When setting the local value of a global
4762 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004763 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004764 && (opt_flags & OPT_LOCAL))
4765 origval = *(char_u **)get_varp(
4766 &options[opt_idx]);
4767 else
4768 origval = oldval;
4769
4770 /*
4771 * Copy the new string into allocated memory.
4772 * Can't use set_string_option_direct(), because
4773 * we need to remove the backslashes.
4774 */
4775 /* get a bit too much */
4776 newlen = (unsigned)STRLEN(arg) + 1;
4777 if (adding || prepending || removing)
4778 newlen += (unsigned)STRLEN(origval) + 1;
4779 newval = alloc(newlen);
4780 if (newval == NULL) /* out of mem, don't change */
4781 break;
4782 s = newval;
4783
4784 /*
4785 * Copy the string, skip over escaped chars.
4786 * For MS-DOS and WIN32 backslashes before normal
4787 * file name characters are not removed, and keep
4788 * backslash at start, for "\\machine\path", but
4789 * do remove it for "\\\\machine\\path".
4790 * The reverse is found in ExpandOldSetting().
4791 */
4792 while (*arg && !vim_iswhite(*arg))
4793 {
4794 if (*arg == '\\' && arg[1] != NUL
4795#ifdef BACKSLASH_IN_FILENAME
4796 && !((flags & P_EXPAND)
4797 && vim_isfilec(arg[1])
4798 && (arg[1] != '\\'
4799 || (s == newval
4800 && arg[2] != '\\')))
4801#endif
4802 )
4803 ++arg; /* remove backslash */
4804#ifdef FEAT_MBYTE
4805 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004806 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004807 {
4808 /* copy multibyte char */
4809 mch_memmove(s, arg, (size_t)i);
4810 arg += i;
4811 s += i;
4812 }
4813 else
4814#endif
4815 *s++ = *arg++;
4816 }
4817 *s = NUL;
4818
4819 /*
4820 * Expand environment variables and ~.
4821 * Don't do it when adding without inserting a
4822 * comma.
4823 */
4824 if (!(adding || prepending || removing)
4825 || (flags & P_COMMA))
4826 {
4827 s = option_expand(opt_idx, newval);
4828 if (s != NULL)
4829 {
4830 vim_free(newval);
4831 newlen = (unsigned)STRLEN(s) + 1;
4832 if (adding || prepending || removing)
4833 newlen += (unsigned)STRLEN(origval) + 1;
4834 newval = alloc(newlen);
4835 if (newval == NULL)
4836 break;
4837 STRCPY(newval, s);
4838 }
4839 }
4840
4841 /* locate newval[] in origval[] when removing it
4842 * and when adding to avoid duplicates */
4843 i = 0; /* init for GCC */
4844 if (removing || (flags & P_NODUP))
4845 {
4846 i = (int)STRLEN(newval);
4847 bs = 0;
4848 for (s = origval; *s; ++s)
4849 {
4850 if ((!(flags & P_COMMA)
4851 || s == origval
4852 || (s[-1] == ',' && !(bs & 1)))
4853 && STRNCMP(s, newval, i) == 0
4854 && (!(flags & P_COMMA)
4855 || s[i] == ','
4856 || s[i] == NUL))
4857 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004858 /* Count backslashes. Only a comma with an
4859 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004860 * recognized as a separator */
4861 if (s > origval && s[-1] == '\\')
4862 ++bs;
4863 else
4864 bs = 0;
4865 }
4866
4867 /* do not add if already there */
4868 if ((adding || prepending) && *s)
4869 {
4870 prepending = FALSE;
4871 adding = FALSE;
4872 STRCPY(newval, origval);
4873 }
4874 }
4875
4876 /* concatenate the two strings; add a ',' if
4877 * needed */
4878 if (adding || prepending)
4879 {
4880 comma = ((flags & P_COMMA) && *origval != NUL
4881 && *newval != NUL);
4882 if (adding)
4883 {
4884 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004885 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004886 if (comma && i > 1
4887 && (flags & P_ONECOMMA) == P_ONECOMMA
4888 && origval[i - 1] == ','
4889 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004890 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004891 mch_memmove(newval + i + comma, newval,
4892 STRLEN(newval) + 1);
4893 mch_memmove(newval, origval, (size_t)i);
4894 }
4895 else
4896 {
4897 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004898 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004899 }
4900 if (comma)
4901 newval[i] = ',';
4902 }
4903
4904 /* Remove newval[] from origval[]. (Note: "i" has
4905 * been set above and is used here). */
4906 if (removing)
4907 {
4908 STRCPY(newval, origval);
4909 if (*s)
4910 {
4911 /* may need to remove a comma */
4912 if (flags & P_COMMA)
4913 {
4914 if (s == origval)
4915 {
4916 /* include comma after string */
4917 if (s[i] == ',')
4918 ++i;
4919 }
4920 else
4921 {
4922 /* include comma before string */
4923 --s;
4924 ++i;
4925 }
4926 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004927 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004928 }
4929 }
4930
4931 if (flags & P_FLAGLIST)
4932 {
4933 /* Remove flags that appear twice. */
4934 for (s = newval; *s; ++s)
4935 if ((!(flags & P_COMMA) || *s != ',')
4936 && vim_strchr(s + 1, *s) != NULL)
4937 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004938 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004939 --s;
4940 }
4941 }
4942
4943 if (save_arg != NULL) /* number for 'whichwrap' */
4944 arg = save_arg;
4945 new_value_alloced = TRUE;
4946 }
4947
4948 /* Set the new value. */
4949 *(char_u **)(varp) = newval;
4950
Bram Moolenaar53744302015-07-17 17:38:22 +02004951#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004952 if (!starting
4953# ifdef FEAT_CRYPT
4954 && options[opt_idx].indir != PV_KEY
4955# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004956 && origval != NULL)
4957 /* origval may be freed by
4958 * did_set_string_option(), make a copy. */
4959 saved_origval = vim_strsave(origval);
4960#endif
4961
Bram Moolenaar071d4272004-06-13 20:20:40 +00004962 /* Handle side effects, and set the global value for
4963 * ":set" on local options. */
4964 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4965 new_value_alloced, oldval, errbuf, opt_flags);
4966
4967 /* If error detected, print the error message. */
4968 if (errmsg != NULL)
4969 goto skip;
Bram Moolenaar53744302015-07-17 17:38:22 +02004970#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4971 if (saved_origval != NULL)
4972 {
4973 char_u buf_type[7];
4974
4975 sprintf((char *)buf_type, "%s",
4976 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004977 set_vim_var_string(VV_OPTION_NEW,
4978 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004979 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4980 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4981 apply_autocmds(EVENT_OPTIONSET,
4982 (char_u *)options[opt_idx].fullname,
4983 NULL, FALSE, NULL);
4984 reset_v_option_vars();
4985 vim_free(saved_origval);
4986 }
4987#endif
4988
Bram Moolenaar071d4272004-06-13 20:20:40 +00004989 }
4990 else /* key code option */
4991 {
4992 char_u *p;
4993
4994 if (nextchar == '&')
4995 {
4996 if (add_termcap_entry(key_name, TRUE) == FAIL)
4997 errmsg = (char_u *)N_("E522: Not found in termcap");
4998 }
4999 else
5000 {
5001 ++arg; /* jump to after the '=' or ':' */
5002 for (p = arg; *p && !vim_iswhite(*p); ++p)
5003 if (*p == '\\' && p[1] != NUL)
5004 ++p;
5005 nextchar = *p;
5006 *p = NUL;
5007 add_termcode(key_name, arg, FALSE);
5008 *p = nextchar;
5009 }
5010 if (full_screen)
5011 ttest(FALSE);
5012 redraw_all_later(CLEAR);
5013 }
5014 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005015
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005017 did_set_option(opt_idx, opt_flags,
5018 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005019 }
5020
5021skip:
5022 /*
5023 * Advance to next argument.
5024 * - skip until a blank found, taking care of backslashes
5025 * - skip blanks
5026 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5027 */
5028 for (i = 0; i < 2 ; ++i)
5029 {
5030 while (*arg != NUL && !vim_iswhite(*arg))
5031 if (*arg++ == '\\' && *arg != NUL)
5032 ++arg;
5033 arg = skipwhite(arg);
5034 if (*arg != '=')
5035 break;
5036 }
5037 }
5038
5039 if (errmsg != NULL)
5040 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005041 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005042 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005043 if (i + (arg - startarg) < IOSIZE)
5044 {
5045 /* append the argument with the error */
5046 STRCAT(IObuff, ": ");
5047 mch_memmove(IObuff + i, startarg, (arg - startarg));
5048 IObuff[i + (arg - startarg)] = NUL;
5049 }
5050 /* make sure all characters are printable */
5051 trans_characters(IObuff, IOSIZE);
5052
5053 ++no_wait_return; /* wait_return done later */
5054 emsg(IObuff); /* show error highlighted */
5055 --no_wait_return;
5056
5057 return FAIL;
5058 }
5059
5060 arg = skipwhite(arg);
5061 }
5062
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005063theend:
5064 if (silent_mode && did_show)
5065 {
5066 /* After displaying option values in silent mode. */
5067 silent_mode = FALSE;
5068 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5069 msg_putchar('\n');
5070 cursor_on(); /* msg_start() switches it off */
5071 out_flush();
5072 silent_mode = TRUE;
5073 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5074 }
5075
Bram Moolenaar071d4272004-06-13 20:20:40 +00005076 return OK;
5077}
5078
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005079/*
5080 * Call this when an option has been given a new value through a user command.
5081 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5082 */
5083 static void
5084did_set_option(opt_idx, opt_flags, new_value)
5085 int opt_idx;
5086 int opt_flags; /* possibly with OPT_MODELINE */
5087 int new_value; /* value was replaced completely */
5088{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005089 long_u *p;
5090
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005091 options[opt_idx].flags |= P_WAS_SET;
5092
5093 /* When an option is set in the sandbox, from a modeline or in secure mode
5094 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005095 * flag. */
5096 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005097 if (secure
5098#ifdef HAVE_SANDBOX
5099 || sandbox != 0
5100#endif
5101 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005102 *p = *p | P_INSECURE;
5103 else if (new_value)
5104 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005105}
5106
Bram Moolenaar071d4272004-06-13 20:20:40 +00005107 static char_u *
5108illegal_char(errbuf, c)
5109 char_u *errbuf;
5110 int c;
5111{
5112 if (errbuf == NULL)
5113 return (char_u *)"";
5114 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005115 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005116 return errbuf;
5117}
5118
5119/*
5120 * Convert a key name or string into a key value.
5121 * Used for 'wildchar' and 'cedit' options.
5122 */
5123 static int
5124string_to_key(arg)
5125 char_u *arg;
5126{
5127 if (*arg == '<')
5128 return find_key_option(arg + 1);
5129 if (*arg == '^')
5130 return Ctrl_chr(arg[1]);
5131 return *arg;
5132}
5133
5134#ifdef FEAT_CMDWIN
5135/*
5136 * Check value of 'cedit' and set cedit_key.
5137 * Returns NULL if value is OK, error message otherwise.
5138 */
5139 static char_u *
5140check_cedit()
5141{
5142 int n;
5143
5144 if (*p_cedit == NUL)
5145 cedit_key = -1;
5146 else
5147 {
5148 n = string_to_key(p_cedit);
5149 if (vim_isprintc(n))
5150 return e_invarg;
5151 cedit_key = n;
5152 }
5153 return NULL;
5154}
5155#endif
5156
5157#ifdef FEAT_TITLE
5158/*
5159 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5160 * maketitle() to create and display it.
5161 * When switching the title or icon off, call mch_restore_title() to get
5162 * the old value back.
5163 */
5164 static void
5165did_set_title(icon)
5166 int icon; /* Did set icon instead of title */
5167{
5168 if (starting != NO_SCREEN
5169#ifdef FEAT_GUI
5170 && !gui.starting
5171#endif
5172 )
5173 {
5174 maketitle();
5175 if (icon)
5176 {
5177 if (!p_icon)
5178 mch_restore_title(2);
5179 }
5180 else
5181 {
5182 if (!p_title)
5183 mch_restore_title(1);
5184 }
5185 }
5186}
5187#endif
5188
5189/*
5190 * set_options_bin - called when 'bin' changes value.
5191 */
5192 void
5193set_options_bin(oldval, newval, opt_flags)
5194 int oldval;
5195 int newval;
5196 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5197{
5198 /*
5199 * The option values that are changed when 'bin' changes are
5200 * copied when 'bin is set and restored when 'bin' is reset.
5201 */
5202 if (newval)
5203 {
5204 if (!oldval) /* switched on */
5205 {
5206 if (!(opt_flags & OPT_GLOBAL))
5207 {
5208 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5209 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5210 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5211 curbuf->b_p_et_nobin = curbuf->b_p_et;
5212 }
5213 if (!(opt_flags & OPT_LOCAL))
5214 {
5215 p_tw_nobin = p_tw;
5216 p_wm_nobin = p_wm;
5217 p_ml_nobin = p_ml;
5218 p_et_nobin = p_et;
5219 }
5220 }
5221
5222 if (!(opt_flags & OPT_GLOBAL))
5223 {
5224 curbuf->b_p_tw = 0; /* no automatic line wrap */
5225 curbuf->b_p_wm = 0; /* no automatic line wrap */
5226 curbuf->b_p_ml = 0; /* no modelines */
5227 curbuf->b_p_et = 0; /* no expandtab */
5228 }
5229 if (!(opt_flags & OPT_LOCAL))
5230 {
5231 p_tw = 0;
5232 p_wm = 0;
5233 p_ml = FALSE;
5234 p_et = FALSE;
5235 p_bin = TRUE; /* needed when called for the "-b" argument */
5236 }
5237 }
5238 else if (oldval) /* switched off */
5239 {
5240 if (!(opt_flags & OPT_GLOBAL))
5241 {
5242 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5243 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5244 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5245 curbuf->b_p_et = curbuf->b_p_et_nobin;
5246 }
5247 if (!(opt_flags & OPT_LOCAL))
5248 {
5249 p_tw = p_tw_nobin;
5250 p_wm = p_wm_nobin;
5251 p_ml = p_ml_nobin;
5252 p_et = p_et_nobin;
5253 }
5254 }
5255}
5256
5257#ifdef FEAT_VIMINFO
5258/*
5259 * Find the parameter represented by the given character (eg ', :, ", or /),
5260 * and return its associated value in the 'viminfo' string.
5261 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005262 * If the parameter is not specified in the string or there is no following
5263 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005264 */
5265 int
5266get_viminfo_parameter(type)
5267 int type;
5268{
5269 char_u *p;
5270
5271 p = find_viminfo_parameter(type);
5272 if (p != NULL && VIM_ISDIGIT(*p))
5273 return atoi((char *)p);
5274 return -1;
5275}
5276
5277/*
5278 * Find the parameter represented by the given character (eg ''', ':', '"', or
5279 * '/') in the 'viminfo' option and return a pointer to the string after it.
5280 * Return NULL if the parameter is not specified in the string.
5281 */
5282 char_u *
5283find_viminfo_parameter(type)
5284 int type;
5285{
5286 char_u *p;
5287
5288 for (p = p_viminfo; *p; ++p)
5289 {
5290 if (*p == type)
5291 return p + 1;
5292 if (*p == 'n') /* 'n' is always the last one */
5293 break;
5294 p = vim_strchr(p, ','); /* skip until next ',' */
5295 if (p == NULL) /* hit the end without finding parameter */
5296 break;
5297 }
5298 return NULL;
5299}
5300#endif
5301
5302/*
5303 * Expand environment variables for some string options.
5304 * These string options cannot be indirect!
5305 * If "val" is NULL expand the current value of the option.
5306 * Return pointer to NameBuff, or NULL when not expanded.
5307 */
5308 static char_u *
5309option_expand(opt_idx, val)
5310 int opt_idx;
5311 char_u *val;
5312{
5313 /* if option doesn't need expansion nothing to do */
5314 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5315 return NULL;
5316
5317 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5318 * expand_env() would truncate the string. */
5319 if (val != NULL && STRLEN(val) > MAXPATHL)
5320 return NULL;
5321
5322 if (val == NULL)
5323 val = *(char_u **)options[opt_idx].var;
5324
5325 /*
5326 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5327 * Escape spaces when expanding 'tags', they are used to separate file
5328 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005329 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330 */
5331 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005332 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005333#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005334 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5335#endif
5336 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5338 return NULL;
5339
5340 return NameBuff;
5341}
5342
5343/*
5344 * After setting various option values: recompute variables that depend on
5345 * option values.
5346 */
5347 static void
5348didset_options()
5349{
5350 /* initialize the table for 'iskeyword' et.al. */
5351 (void)init_chartab();
5352
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005353#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005356 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005357 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358#ifdef FEAT_SESSION
5359 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5360 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5361#endif
5362#ifdef FEAT_FOLDING
5363 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5364#endif
5365 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5366#ifdef FEAT_VIRTUALEDIT
5367 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5368#endif
5369#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5370 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5371#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005372#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005373 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005374 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005375 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005376 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005377#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005378#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5379 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5380#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005381#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005382 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5383#endif
5384#ifdef FEAT_CMDWIN
5385 /* set cedit_key */
5386 (void)check_cedit();
5387#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005388#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005389 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005390#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005391#ifdef FEAT_LINEBREAK
5392 /* initialize the table for 'breakat'. */
5393 fill_breakat_flags();
5394#endif
5395
5396}
5397
5398/*
5399 * More side effects of setting options.
5400 */
5401 static void
5402didset_options2()
5403{
5404 /* Initialize the highlight_attr[] table. */
5405 (void)highlight_changed();
5406
5407 /* Parse default for 'wildmode' */
5408 check_opt_wim();
5409
5410 (void)set_chars_option(&p_lcs);
5411#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5412 /* Parse default for 'fillchars'. */
5413 (void)set_chars_option(&p_fcs);
5414#endif
5415
5416#ifdef FEAT_CLIPBOARD
5417 /* Parse default for 'clipboard' */
5418 (void)check_clipboard_option();
5419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005420}
5421
5422/*
5423 * Check for string options that are NULL (normally only termcap options).
5424 */
5425 void
5426check_options()
5427{
5428 int opt_idx;
5429
5430 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5431 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5432 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5433}
5434
5435/*
5436 * Check string options in a buffer for NULL value.
5437 */
5438 void
5439check_buf_options(buf)
5440 buf_T *buf;
5441{
5442#if defined(FEAT_QUICKFIX)
5443 check_string_option(&buf->b_p_bh);
5444 check_string_option(&buf->b_p_bt);
5445#endif
5446#ifdef FEAT_MBYTE
5447 check_string_option(&buf->b_p_fenc);
5448#endif
5449 check_string_option(&buf->b_p_ff);
5450#ifdef FEAT_FIND_ID
5451 check_string_option(&buf->b_p_def);
5452 check_string_option(&buf->b_p_inc);
5453# ifdef FEAT_EVAL
5454 check_string_option(&buf->b_p_inex);
5455# endif
5456#endif
5457#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5458 check_string_option(&buf->b_p_inde);
5459 check_string_option(&buf->b_p_indk);
5460#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005461#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5462 check_string_option(&buf->b_p_bexpr);
5463#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005464#if defined(FEAT_CRYPT)
5465 check_string_option(&buf->b_p_cm);
5466#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005467#if defined(FEAT_EVAL)
5468 check_string_option(&buf->b_p_fex);
5469#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005470#ifdef FEAT_CRYPT
5471 check_string_option(&buf->b_p_key);
5472#endif
5473 check_string_option(&buf->b_p_kp);
5474 check_string_option(&buf->b_p_mps);
5475 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005476 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005477 check_string_option(&buf->b_p_isk);
5478#ifdef FEAT_COMMENTS
5479 check_string_option(&buf->b_p_com);
5480#endif
5481#ifdef FEAT_FOLDING
5482 check_string_option(&buf->b_p_cms);
5483#endif
5484 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005485#ifdef FEAT_TEXTOBJ
5486 check_string_option(&buf->b_p_qe);
5487#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005488#ifdef FEAT_SYN_HL
5489 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005490#endif
5491#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005492 check_string_option(&buf->b_s.b_p_spc);
5493 check_string_option(&buf->b_s.b_p_spf);
5494 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495#endif
5496#ifdef FEAT_SEARCHPATH
5497 check_string_option(&buf->b_p_sua);
5498#endif
5499#ifdef FEAT_CINDENT
5500 check_string_option(&buf->b_p_cink);
5501 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005502 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005503#endif
5504#ifdef FEAT_AUTOCMD
5505 check_string_option(&buf->b_p_ft);
5506#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005507#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5508 check_string_option(&buf->b_p_cinw);
5509#endif
5510#ifdef FEAT_INS_EXPAND
5511 check_string_option(&buf->b_p_cpt);
5512#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005513#ifdef FEAT_COMPL_FUNC
5514 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005515 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005516#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517#ifdef FEAT_KEYMAP
5518 check_string_option(&buf->b_p_keymap);
5519#endif
5520#ifdef FEAT_QUICKFIX
5521 check_string_option(&buf->b_p_gp);
5522 check_string_option(&buf->b_p_mp);
5523 check_string_option(&buf->b_p_efm);
5524#endif
5525 check_string_option(&buf->b_p_ep);
5526 check_string_option(&buf->b_p_path);
5527 check_string_option(&buf->b_p_tags);
5528#ifdef FEAT_INS_EXPAND
5529 check_string_option(&buf->b_p_dict);
5530 check_string_option(&buf->b_p_tsr);
5531#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005532#ifdef FEAT_LISP
5533 check_string_option(&buf->b_p_lw);
5534#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005535 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536}
5537
5538/*
5539 * Free the string allocated for an option.
5540 * Checks for the string being empty_option. This may happen if we're out of
5541 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5542 * check_options().
5543 * Does NOT check for P_ALLOCED flag!
5544 */
5545 void
5546free_string_option(p)
5547 char_u *p;
5548{
5549 if (p != empty_option)
5550 vim_free(p);
5551}
5552
5553 void
5554clear_string_option(pp)
5555 char_u **pp;
5556{
5557 if (*pp != empty_option)
5558 vim_free(*pp);
5559 *pp = empty_option;
5560}
5561
5562 static void
5563check_string_option(pp)
5564 char_u **pp;
5565{
5566 if (*pp == NULL)
5567 *pp = empty_option;
5568}
5569
5570/*
5571 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5572 */
5573 void
5574set_term_option_alloced(p)
5575 char_u **p;
5576{
5577 int opt_idx;
5578
5579 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5580 if (options[opt_idx].var == (char_u *)p)
5581 {
5582 options[opt_idx].flags |= P_ALLOCED;
5583 return;
5584 }
5585 return; /* cannot happen: didn't find it! */
5586}
5587
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005588#if defined(FEAT_EVAL) || defined(PROTO)
5589/*
5590 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5591 * Return FALSE when it wasn't.
5592 * Return -1 for an unknown option.
5593 */
5594 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005595was_set_insecurely(opt, opt_flags)
5596 char_u *opt;
5597 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005598{
5599 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005600 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005601
5602 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005603 {
5604 flagp = insecure_flag(idx, opt_flags);
5605 return (*flagp & P_INSECURE) != 0;
5606 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005607 EMSG2(_(e_intern2), "was_set_insecurely()");
5608 return -1;
5609}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005610
5611/*
5612 * Get a pointer to the flags used for the P_INSECURE flag of option
5613 * "opt_idx". For some local options a local flags field is used.
5614 */
5615 static long_u *
5616insecure_flag(opt_idx, opt_flags)
5617 int opt_idx;
5618 int opt_flags;
5619{
5620 if (opt_flags & OPT_LOCAL)
5621 switch ((int)options[opt_idx].indir)
5622 {
5623#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005624 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005625#endif
5626#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005627# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005628 case PV_FDE: return &curwin->w_p_fde_flags;
5629 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005630# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005631# ifdef FEAT_BEVAL
5632 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5633# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005634# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005635 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005636# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005637 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005638# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005639 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005640# endif
5641#endif
5642 }
5643
5644 /* Nothing special, return global flags field. */
5645 return &options[opt_idx].flags;
5646}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005647#endif
5648
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005649#ifdef FEAT_TITLE
5650static void redraw_titles __ARGS((void));
5651
5652/*
5653 * Redraw the window title and/or tab page text later.
5654 */
5655static void redraw_titles()
5656{
5657 need_maketitle = TRUE;
5658# ifdef FEAT_WINDOWS
5659 redraw_tabline = TRUE;
5660# endif
5661}
5662#endif
5663
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664/*
5665 * Set a string option to a new value (without checking the effect).
5666 * The string is copied into allocated memory.
5667 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005668 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005669 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670 */
5671 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005672set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673 char_u *name;
5674 int opt_idx;
5675 char_u *val;
5676 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005677 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005678{
5679 char_u *s;
5680 char_u **varp;
5681 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005682 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683
Bram Moolenaar89d40322006-08-29 15:30:07 +00005684 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005686 idx = findoption(name);
5687 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005688 {
5689 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005690 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005692 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693 }
5694
Bram Moolenaar89d40322006-08-29 15:30:07 +00005695 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696 return;
5697
5698 s = vim_strsave(val);
5699 if (s != NULL)
5700 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005701 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005703 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704 free_string_option(*varp);
5705 *varp = s;
5706
5707 /* For buffer/window local option may also set the global value. */
5708 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005709 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710
Bram Moolenaar89d40322006-08-29 15:30:07 +00005711 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712
5713 /* When setting both values of a global option with a local value,
5714 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005715 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716 {
5717 free_string_option(*varp);
5718 *varp = empty_option;
5719 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005720# ifdef FEAT_EVAL
5721 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005722 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005723 set_sid == 0 ? current_SID : set_sid);
5724# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725 }
5726}
5727
5728/*
5729 * Set global value for string option when it's a local option.
5730 */
5731 static void
5732set_string_option_global(opt_idx, varp)
5733 int opt_idx; /* option index */
5734 char_u **varp; /* pointer to option variable */
5735{
5736 char_u **p, *s;
5737
5738 /* the global value is always allocated */
5739 if (options[opt_idx].var == VAR_WIN)
5740 p = (char_u **)GLOBAL_WO(varp);
5741 else
5742 p = (char_u **)options[opt_idx].var;
5743 if (options[opt_idx].indir != PV_NONE
5744 && p != varp
5745 && (s = vim_strsave(*varp)) != NULL)
5746 {
5747 free_string_option(*p);
5748 *p = s;
5749 }
5750}
5751
5752/*
5753 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005754 *
5755 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005757 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005758set_string_option(opt_idx, value, opt_flags)
5759 int opt_idx;
5760 char_u *value;
5761 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5762{
5763 char_u *s;
5764 char_u **varp;
5765 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005766#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5767 char_u *saved_oldval = NULL;
5768#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005769 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770
5771 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005772 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005773
5774 s = vim_strsave(value);
5775 if (s != NULL)
5776 {
5777 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5778 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005779 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005780 ? OPT_GLOBAL : OPT_LOCAL)
5781 : opt_flags);
5782 oldval = *varp;
5783 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005784
5785#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005786 if (!starting
5787# ifdef FEAT_CRYPT
5788 && options[opt_idx].indir != PV_KEY
5789# endif
5790 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005791 saved_oldval = vim_strsave(oldval);
5792#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005793 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5794 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005795 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005796
5797 /* call autocomamnd after handling side effects */
5798#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5799 if (saved_oldval != NULL)
5800 {
5801 char_u buf_type[7];
5802 sprintf((char *)buf_type, "%s",
5803 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005804 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5805 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005806 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5807 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5808 reset_v_option_vars();
5809 vim_free(saved_oldval);
5810 }
5811#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005812 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005813 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005814}
5815
5816/*
5817 * Handle string options that need some action to perform when changed.
5818 * Returns NULL for success, or an error message for an error.
5819 */
5820 static char_u *
5821did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5822 opt_flags)
5823 int opt_idx; /* index in options[] table */
5824 char_u **varp; /* pointer to the option variable */
5825 int new_value_alloced; /* new value was allocated */
5826 char_u *oldval; /* previous value of the option */
5827 char_u *errbuf; /* buffer for errors, or NULL */
5828 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5829{
5830 char_u *errmsg = NULL;
5831 char_u *s, *p;
5832 int did_chartab = FALSE;
5833 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005834 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005835#ifdef FEAT_GUI
5836 /* set when changing an option that only requires a redraw in the GUI */
5837 int redraw_gui_only = FALSE;
5838#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005839
5840 /* Get the global option to compare with, otherwise we would have to check
5841 * two values for all local options. */
5842 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5843
5844 /* Disallow changing some options from secure mode */
5845 if ((secure
5846#ifdef HAVE_SANDBOX
5847 || sandbox != 0
5848#endif
5849 ) && (options[opt_idx].flags & P_SECURE))
5850 {
5851 errmsg = e_secure;
5852 }
5853
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005854 /* Check for a "normal" file name in some options. Disallow a path
5855 * separator (slash and/or backslash), wildcards and characters that are
5856 * often illegal in a file name. */
5857 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005858 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005859 {
5860 errmsg = e_invarg;
5861 }
5862
Bram Moolenaar071d4272004-06-13 20:20:40 +00005863 /* 'term' */
5864 else if (varp == &T_NAME)
5865 {
5866 if (T_NAME[0] == NUL)
5867 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5868#ifdef FEAT_GUI
5869 if (gui.in_use)
5870 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5871 else if (term_is_gui(T_NAME))
5872 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5873#endif
5874 else if (set_termname(T_NAME) == FAIL)
5875 errmsg = (char_u *)N_("E522: Not found in termcap");
5876 else
5877 /* Screen colors may have changed. */
5878 redraw_later_clear();
5879 }
5880
5881 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005882 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005884 char_u *bkc = p_bkc;
5885 unsigned int *flags = &bkc_flags;
5886
5887 if (opt_flags & OPT_LOCAL)
5888 {
5889 bkc = curbuf->b_p_bkc;
5890 flags = &curbuf->b_bkc_flags;
5891 }
5892
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005893 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5894 /* make the local value empty: use the global value */
5895 *flags = 0;
5896 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005898 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5899 errmsg = e_invarg;
5900 if ((((int)*flags & BKC_AUTO) != 0)
5901 + (((int)*flags & BKC_YES) != 0)
5902 + (((int)*flags & BKC_NO) != 0) != 1)
5903 {
5904 /* Must have exactly one of "auto", "yes" and "no". */
5905 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5906 errmsg = e_invarg;
5907 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005908 }
5909 }
5910
5911 /* 'backupext' and 'patchmode' */
5912 else if (varp == &p_bex || varp == &p_pm)
5913 {
5914 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5915 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5916 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5917 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005918#ifdef FEAT_LINEBREAK
5919 /* 'breakindentopt' */
5920 else if (varp == &curwin->w_p_briopt)
5921 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005922 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005923 errmsg = e_invarg;
5924 }
5925#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926
5927 /*
5928 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5929 * If the new option is invalid, use old value. 'lisp' option: refill
5930 * chartab[] for '-' char
5931 */
5932 else if ( varp == &p_isi
5933 || varp == &(curbuf->b_p_isk)
5934 || varp == &p_isp
5935 || varp == &p_isf)
5936 {
5937 if (init_chartab() == FAIL)
5938 {
5939 did_chartab = TRUE; /* need to restore it below */
5940 errmsg = e_invarg; /* error in value */
5941 }
5942 }
5943
5944 /* 'helpfile' */
5945 else if (varp == &p_hf)
5946 {
5947 /* May compute new values for $VIM and $VIMRUNTIME */
5948 if (didset_vim)
5949 {
5950 vim_setenv((char_u *)"VIM", (char_u *)"");
5951 didset_vim = FALSE;
5952 }
5953 if (didset_vimruntime)
5954 {
5955 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5956 didset_vimruntime = FALSE;
5957 }
5958 }
5959
Bram Moolenaar1a384422010-07-14 19:53:30 +02005960#ifdef FEAT_SYN_HL
5961 /* 'colorcolumn' */
5962 else if (varp == &curwin->w_p_cc)
5963 errmsg = check_colorcolumn(curwin);
5964#endif
5965
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966#ifdef FEAT_MULTI_LANG
5967 /* 'helplang' */
5968 else if (varp == &p_hlg)
5969 {
5970 /* Check for "", "ab", "ab,cd", etc. */
5971 for (s = p_hlg; *s != NUL; s += 3)
5972 {
5973 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5974 {
5975 errmsg = e_invarg;
5976 break;
5977 }
5978 if (s[2] == NUL)
5979 break;
5980 }
5981 }
5982#endif
5983
5984 /* 'highlight' */
5985 else if (varp == &p_hl)
5986 {
5987 if (highlight_changed() == FAIL)
5988 errmsg = e_invarg; /* invalid flags */
5989 }
5990
5991 /* 'nrformats' */
5992 else if (gvarp == &p_nf)
5993 {
5994 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5995 errmsg = e_invarg;
5996 }
5997
5998#ifdef FEAT_SESSION
5999 /* 'sessionoptions' */
6000 else if (varp == &p_ssop)
6001 {
6002 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6003 errmsg = e_invarg;
6004 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6005 {
6006 /* Don't allow both "sesdir" and "curdir". */
6007 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6008 errmsg = e_invarg;
6009 }
6010 }
6011 /* 'viewoptions' */
6012 else if (varp == &p_vop)
6013 {
6014 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6015 errmsg = e_invarg;
6016 }
6017#endif
6018
6019 /* 'scrollopt' */
6020#ifdef FEAT_SCROLLBIND
6021 else if (varp == &p_sbo)
6022 {
6023 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6024 errmsg = e_invarg;
6025 }
6026#endif
6027
6028 /* 'ambiwidth' */
6029#ifdef FEAT_MBYTE
6030 else if (varp == &p_ambw)
6031 {
6032 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6033 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006034 else if (set_chars_option(&p_lcs) != NULL)
6035 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6036# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6037 else if (set_chars_option(&p_fcs) != NULL)
6038 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6039# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006040 }
6041#endif
6042
6043 /* 'background' */
6044 else if (varp == &p_bg)
6045 {
6046 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6047 {
6048#ifdef FEAT_EVAL
6049 int dark = (*p_bg == 'd');
6050#endif
6051
6052 init_highlight(FALSE, FALSE);
6053
6054#ifdef FEAT_EVAL
6055 if (dark != (*p_bg == 'd')
6056 && get_var_value((char_u *)"g:colors_name") != NULL)
6057 {
6058 /* The color scheme must have set 'background' back to another
6059 * value, that's not what we want here. Disable the color
6060 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006061 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006062 free_string_option(p_bg);
6063 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6064 check_string_option(&p_bg);
6065 init_highlight(FALSE, FALSE);
6066 }
6067#endif
6068 }
6069 else
6070 errmsg = e_invarg;
6071 }
6072
6073 /* 'wildmode' */
6074 else if (varp == &p_wim)
6075 {
6076 if (check_opt_wim() == FAIL)
6077 errmsg = e_invarg;
6078 }
6079
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006080#ifdef FEAT_CMDL_COMPL
6081 /* 'wildoptions' */
6082 else if (varp == &p_wop)
6083 {
6084 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6085 errmsg = e_invarg;
6086 }
6087#endif
6088
Bram Moolenaar071d4272004-06-13 20:20:40 +00006089#ifdef FEAT_WAK
6090 /* 'winaltkeys' */
6091 else if (varp == &p_wak)
6092 {
6093 if (*p_wak == NUL
6094 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6095 errmsg = e_invarg;
6096# ifdef FEAT_MENU
6097# ifdef FEAT_GUI_MOTIF
6098 else if (gui.in_use)
6099 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6100# else
6101# ifdef FEAT_GUI_GTK
6102 else if (gui.in_use)
6103 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6104# endif
6105# endif
6106# endif
6107 }
6108#endif
6109
6110#ifdef FEAT_AUTOCMD
6111 /* 'eventignore' */
6112 else if (varp == &p_ei)
6113 {
6114 if (check_ei() == FAIL)
6115 errmsg = e_invarg;
6116 }
6117#endif
6118
6119#ifdef FEAT_MBYTE
6120 /* 'encoding' and 'fileencoding' */
6121 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6122 {
6123 if (gvarp == &p_fenc)
6124 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006125 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006126 errmsg = e_modifiable;
6127 else if (vim_strchr(*varp, ',') != NULL)
6128 /* No comma allowed in 'fileencoding'; catches confusing it
6129 * with 'fileencodings'. */
6130 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006131 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006132 {
6133# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006135 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006137 /* Add 'fileencoding' to the swap file. */
6138 ml_setflags(curbuf);
6139 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006140 }
6141 if (errmsg == NULL)
6142 {
6143 /* canonize the value, so that STRCMP() can be used on it */
6144 p = enc_canonize(*varp);
6145 if (p != NULL)
6146 {
6147 vim_free(*varp);
6148 *varp = p;
6149 }
6150 if (varp == &p_enc)
6151 {
6152 errmsg = mb_init();
6153# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006154 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006155# endif
6156 }
6157 }
6158
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006159# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006160 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6161 {
6162 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6163 if (STRCMP(p_tenc, "utf-8") != 0)
6164 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6165 }
6166# endif
6167
6168 if (errmsg == NULL)
6169 {
6170# ifdef FEAT_KEYMAP
6171 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6172 * (with another encoding). */
6173 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6174 (void)keymap_init();
6175# endif
6176
6177 /* When 'termencoding' is not empty and 'encoding' changes or when
6178 * 'termencoding' changes, need to setup for keyboard input and
6179 * display output conversion. */
6180 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6181 {
6182 convert_setup(&input_conv, p_tenc, p_enc);
6183 convert_setup(&output_conv, p_enc, p_tenc);
6184 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006185
6186# if defined(WIN3264) && defined(FEAT_MBYTE)
6187 /* $HOME may have characters in active code page. */
6188 if (varp == &p_enc)
6189 init_homedir();
6190# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006191 }
6192 }
6193#endif
6194
6195#if defined(FEAT_POSTSCRIPT)
6196 else if (varp == &p_penc)
6197 {
6198 /* Canonize printencoding if VIM standard one */
6199 p = enc_canonize(p_penc);
6200 if (p != NULL)
6201 {
6202 vim_free(p_penc);
6203 p_penc = p;
6204 }
6205 else
6206 {
6207 /* Ensure lower case and '-' for '_' */
6208 for (s = p_penc; *s != NUL; s++)
6209 {
6210 if (*s == '_')
6211 *s = '-';
6212 else
6213 *s = TOLOWER_ASC(*s);
6214 }
6215 }
6216 }
6217#endif
6218
Bram Moolenaar9372a112005-12-06 19:59:18 +00006219#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006220 else if (varp == &p_imak)
6221 {
6222 if (gui.in_use && !im_xim_isvalid_imactivate())
6223 errmsg = e_invarg;
6224 }
6225#endif
6226
6227#ifdef FEAT_KEYMAP
6228 else if (varp == &curbuf->b_p_keymap)
6229 {
6230 /* load or unload key mapping tables */
6231 errmsg = keymap_init();
6232
Bram Moolenaarfab06232009-03-04 03:13:35 +00006233 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006234 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006235 if (*curbuf->b_p_keymap != NUL)
6236 {
6237 /* Installed a new keymap, switch on using it. */
6238 curbuf->b_p_iminsert = B_IMODE_LMAP;
6239 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6240 curbuf->b_p_imsearch = B_IMODE_LMAP;
6241 }
6242 else
6243 {
6244 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6245 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6246 curbuf->b_p_iminsert = B_IMODE_NONE;
6247 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6248 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6249 }
6250 if ((opt_flags & OPT_LOCAL) == 0)
6251 {
6252 set_iminsert_global();
6253 set_imsearch_global();
6254 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006255# ifdef FEAT_WINDOWS
6256 status_redraw_curbuf();
6257# endif
6258 }
6259 }
6260#endif
6261
6262 /* 'fileformat' */
6263 else if (gvarp == &p_ff)
6264 {
6265 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6266 errmsg = e_modifiable;
6267 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6268 errmsg = e_invarg;
6269 else
6270 {
6271 /* may also change 'textmode' */
6272 if (get_fileformat(curbuf) == EOL_DOS)
6273 curbuf->b_p_tx = TRUE;
6274 else
6275 curbuf->b_p_tx = FALSE;
6276#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006277 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006278#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006279 /* update flag in swap file */
6280 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006281 /* Redraw needed when switching to/from "mac": a CR in the text
6282 * will be displayed differently. */
6283 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6284 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006285 }
6286 }
6287
6288 /* 'fileformats' */
6289 else if (varp == &p_ffs)
6290 {
6291 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6292 errmsg = e_invarg;
6293 else
6294 {
6295 /* also change 'textauto' */
6296 if (*p_ffs == NUL)
6297 p_ta = FALSE;
6298 else
6299 p_ta = TRUE;
6300 }
6301 }
6302
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006303#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006304 /* 'cryptkey' */
6305 else if (gvarp == &p_key)
6306 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006307# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006308 /* Make sure the ":set" command doesn't show the new value in the
6309 * history. */
6310 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006311# endif
6312 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6313 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006314 ml_set_crypt_key(curbuf, oldval,
6315 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006316 }
6317
6318 else if (gvarp == &p_cm)
6319 {
6320 if (opt_flags & OPT_LOCAL)
6321 p = curbuf->b_p_cm;
6322 else
6323 p = p_cm;
6324 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6325 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006326 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006327 errmsg = e_invarg;
6328 else
6329 {
6330 /* When setting the global value to empty, make it "zip". */
6331 if (*p_cm == NUL)
6332 {
6333 if (new_value_alloced)
6334 free_string_option(p_cm);
6335 p_cm = vim_strsave((char_u *)"zip");
6336 new_value_alloced = TRUE;
6337 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006338 /* When using ":set cm=name" the local value is going to be empty.
6339 * Do that here, otherwise the crypt functions will still use the
6340 * local value. */
6341 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6342 {
6343 free_string_option(curbuf->b_p_cm);
6344 curbuf->b_p_cm = empty_option;
6345 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006346
6347 /* Need to update the swapfile when the effective method changed.
6348 * Set "s" to the effective old value, "p" to the effective new
6349 * method and compare. */
6350 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6351 s = p_cm; /* was previously using the global value */
6352 else
6353 s = oldval;
6354 if (*curbuf->b_p_cm == NUL)
6355 p = p_cm; /* is now using the global value */
6356 else
6357 p = curbuf->b_p_cm;
6358 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006359 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006360
6361 /* If the global value changes need to update the swapfile for all
6362 * buffers using that value. */
6363 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6364 {
6365 buf_T *buf;
6366
6367 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6368 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006369 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006370 }
6371 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372 }
6373#endif
6374
6375 /* 'matchpairs' */
6376 else if (gvarp == &p_mps)
6377 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006378#ifdef FEAT_MBYTE
6379 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006381 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006382 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006383 int x2 = -1;
6384 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006385
6386 if (*p != NUL)
6387 p += mb_ptr2len(p);
6388 if (*p != NUL)
6389 x2 = *p++;
6390 if (*p != NUL)
6391 {
6392 x3 = mb_ptr2char(p);
6393 p += mb_ptr2len(p);
6394 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006395 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006396 {
6397 errmsg = e_invarg;
6398 break;
6399 }
6400 if (*p == NUL)
6401 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006402 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006403 }
6404 else
6405#endif
6406 {
6407 /* Check for "x:y,x:y" */
6408 for (p = *varp; *p != NUL; p += 4)
6409 {
6410 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6411 {
6412 errmsg = e_invarg;
6413 break;
6414 }
6415 if (p[3] == NUL)
6416 break;
6417 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 }
6419 }
6420
6421#ifdef FEAT_COMMENTS
6422 /* 'comments' */
6423 else if (gvarp == &p_com)
6424 {
6425 for (s = *varp; *s; )
6426 {
6427 while (*s && *s != ':')
6428 {
6429 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6430 && !VIM_ISDIGIT(*s) && *s != '-')
6431 {
6432 errmsg = illegal_char(errbuf, *s);
6433 break;
6434 }
6435 ++s;
6436 }
6437 if (*s++ == NUL)
6438 errmsg = (char_u *)N_("E524: Missing colon");
6439 else if (*s == ',' || *s == NUL)
6440 errmsg = (char_u *)N_("E525: Zero length string");
6441 if (errmsg != NULL)
6442 break;
6443 while (*s && *s != ',')
6444 {
6445 if (*s == '\\' && s[1] != NUL)
6446 ++s;
6447 ++s;
6448 }
6449 s = skip_to_option_part(s);
6450 }
6451 }
6452#endif
6453
6454 /* 'listchars' */
6455 else if (varp == &p_lcs)
6456 {
6457 errmsg = set_chars_option(varp);
6458 }
6459
6460#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6461 /* 'fillchars' */
6462 else if (varp == &p_fcs)
6463 {
6464 errmsg = set_chars_option(varp);
6465 }
6466#endif
6467
6468#ifdef FEAT_CMDWIN
6469 /* 'cedit' */
6470 else if (varp == &p_cedit)
6471 {
6472 errmsg = check_cedit();
6473 }
6474#endif
6475
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006476 /* 'verbosefile' */
6477 else if (varp == &p_vfile)
6478 {
6479 verbose_stop();
6480 if (*p_vfile != NUL && verbose_open() == FAIL)
6481 errmsg = e_invarg;
6482 }
6483
Bram Moolenaar071d4272004-06-13 20:20:40 +00006484#ifdef FEAT_VIMINFO
6485 /* 'viminfo' */
6486 else if (varp == &p_viminfo)
6487 {
6488 for (s = p_viminfo; *s;)
6489 {
6490 /* Check it's a valid character */
6491 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6492 {
6493 errmsg = illegal_char(errbuf, *s);
6494 break;
6495 }
6496 if (*s == 'n') /* name is always last one */
6497 {
6498 break;
6499 }
6500 else if (*s == 'r') /* skip until next ',' */
6501 {
6502 while (*++s && *s != ',')
6503 ;
6504 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006505 else if (*s == '%')
6506 {
6507 /* optional number */
6508 while (vim_isdigit(*++s))
6509 ;
6510 }
6511 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006512 ++s; /* no extra chars */
6513 else /* must have a number */
6514 {
6515 while (vim_isdigit(*++s))
6516 ;
6517
6518 if (!VIM_ISDIGIT(*(s - 1)))
6519 {
6520 if (errbuf != NULL)
6521 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006522 sprintf((char *)errbuf,
6523 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006524 transchar_byte(*(s - 1)));
6525 errmsg = errbuf;
6526 }
6527 else
6528 errmsg = (char_u *)"";
6529 break;
6530 }
6531 }
6532 if (*s == ',')
6533 ++s;
6534 else if (*s)
6535 {
6536 if (errbuf != NULL)
6537 errmsg = (char_u *)N_("E527: Missing comma");
6538 else
6539 errmsg = (char_u *)"";
6540 break;
6541 }
6542 }
6543 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6544 errmsg = (char_u *)N_("E528: Must specify a ' value");
6545 }
6546#endif /* FEAT_VIMINFO */
6547
6548 /* terminal options */
6549 else if (istermoption(&options[opt_idx]) && full_screen)
6550 {
6551 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6552 if (varp == &T_CCO)
6553 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006554 int colors = atoi((char *)T_CCO);
6555
6556 /* Only reinitialize colors if t_Co value has really changed to
6557 * avoid expensive reload of colorscheme if t_Co is set to the
6558 * same value multiple times. */
6559 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006560 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006561 t_colors = colors;
6562 if (t_colors <= 1)
6563 {
6564 if (new_value_alloced)
6565 vim_free(T_CCO);
6566 T_CCO = empty_option;
6567 }
6568 /* We now have a different color setup, initialize it again. */
6569 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006570 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006571 }
6572 ttest(FALSE);
6573 if (varp == &T_ME)
6574 {
6575 out_str(T_ME);
6576 redraw_later(CLEAR);
6577#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6578 /* Since t_me has been set, this probably means that the user
6579 * wants to use this as default colors. Need to reset default
6580 * background/foreground colors. */
6581 mch_set_normal_colors();
6582#endif
6583 }
6584 }
6585
6586#ifdef FEAT_LINEBREAK
6587 /* 'showbreak' */
6588 else if (varp == &p_sbr)
6589 {
6590 for (s = p_sbr; *s; )
6591 {
6592 if (ptr2cells(s) != 1)
6593 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006594 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006595 }
6596 }
6597#endif
6598
6599#ifdef FEAT_GUI
6600 /* 'guifont' */
6601 else if (varp == &p_guifont)
6602 {
6603 if (gui.in_use)
6604 {
6605 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006606# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006607 /*
6608 * Put up a font dialog and let the user select a new value.
6609 * If this is cancelled go back to the old value but don't
6610 * give an error message.
6611 */
6612 if (STRCMP(p, "*") == 0)
6613 {
6614 p = gui_mch_font_dialog(oldval);
6615
6616 if (new_value_alloced)
6617 free_string_option(p_guifont);
6618
6619 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6620 new_value_alloced = TRUE;
6621 }
6622# endif
6623 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6624 {
6625# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6626 if (STRCMP(p_guifont, "*") == 0)
6627 {
6628 /* Dialog was cancelled: Keep the old value without giving
6629 * an error message. */
6630 if (new_value_alloced)
6631 free_string_option(p_guifont);
6632 p_guifont = vim_strsave(oldval);
6633 new_value_alloced = TRUE;
6634 }
6635 else
6636# endif
6637 errmsg = (char_u *)N_("E596: Invalid font(s)");
6638 }
6639 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006640 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006641 }
6642# ifdef FEAT_XFONTSET
6643 else if (varp == &p_guifontset)
6644 {
6645 if (STRCMP(p_guifontset, "*") == 0)
6646 errmsg = (char_u *)N_("E597: can't select fontset");
6647 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6648 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006649 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006650 }
6651# endif
6652# ifdef FEAT_MBYTE
6653 else if (varp == &p_guifontwide)
6654 {
6655 if (STRCMP(p_guifontwide, "*") == 0)
6656 errmsg = (char_u *)N_("E533: can't select wide font");
6657 else if (gui_get_wide_font() == FAIL)
6658 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006659 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006660 }
6661# endif
6662#endif
6663
6664#ifdef CURSOR_SHAPE
6665 /* 'guicursor' */
6666 else if (varp == &p_guicursor)
6667 errmsg = parse_shape_opt(SHAPE_CURSOR);
6668#endif
6669
6670#ifdef FEAT_MOUSESHAPE
6671 /* 'mouseshape' */
6672 else if (varp == &p_mouseshape)
6673 {
6674 errmsg = parse_shape_opt(SHAPE_MOUSE);
6675 update_mouseshape(-1);
6676 }
6677#endif
6678
6679#ifdef FEAT_PRINTER
6680 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006681 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006682# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006683 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006684 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006685# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006686#endif
6687
6688#ifdef FEAT_LANGMAP
6689 /* 'langmap' */
6690 else if (varp == &p_langmap)
6691 langmap_set();
6692#endif
6693
6694#ifdef FEAT_LINEBREAK
6695 /* 'breakat' */
6696 else if (varp == &p_breakat)
6697 fill_breakat_flags();
6698#endif
6699
6700#ifdef FEAT_TITLE
6701 /* 'titlestring' and 'iconstring' */
6702 else if (varp == &p_titlestring || varp == &p_iconstring)
6703 {
6704# ifdef FEAT_STL_OPT
6705 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6706
6707 /* NULL => statusline syntax */
6708 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6709 stl_syntax |= flagval;
6710 else
6711 stl_syntax &= ~flagval;
6712# endif
6713 did_set_title(varp == &p_iconstring);
6714
6715 }
6716#endif
6717
6718#ifdef FEAT_GUI
6719 /* 'guioptions' */
6720 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006721 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006723 redraw_gui_only = TRUE;
6724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006725#endif
6726
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006727#if defined(FEAT_GUI_TABLINE)
6728 /* 'guitablabel' */
6729 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006730 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006731 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006732 redraw_gui_only = TRUE;
6733 }
6734 /* 'guitabtooltip' */
6735 else if (varp == &p_gtt)
6736 {
6737 redraw_gui_only = TRUE;
6738 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006739#endif
6740
Bram Moolenaar071d4272004-06-13 20:20:40 +00006741#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6742 /* 'ttymouse' */
6743 else if (varp == &p_ttym)
6744 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006745 /* Switch the mouse off before changing the escape sequences used for
6746 * that. */
6747 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6749 errmsg = e_invarg;
6750 else
6751 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006752 if (termcap_active)
6753 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 }
6755#endif
6756
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 /* 'selection' */
6758 else if (varp == &p_sel)
6759 {
6760 if (*p_sel == NUL
6761 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6762 errmsg = e_invarg;
6763 }
6764
6765 /* 'selectmode' */
6766 else if (varp == &p_slm)
6767 {
6768 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6769 errmsg = e_invarg;
6770 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006771
6772#ifdef FEAT_BROWSE
6773 /* 'browsedir' */
6774 else if (varp == &p_bsdir)
6775 {
6776 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6777 && !mch_isdir(p_bsdir))
6778 errmsg = e_invarg;
6779 }
6780#endif
6781
Bram Moolenaar071d4272004-06-13 20:20:40 +00006782 /* 'keymodel' */
6783 else if (varp == &p_km)
6784 {
6785 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6786 errmsg = e_invarg;
6787 else
6788 {
6789 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6790 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6791 }
6792 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793
6794 /* 'mousemodel' */
6795 else if (varp == &p_mousem)
6796 {
6797 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6798 errmsg = e_invarg;
6799#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6800 else if (*p_mousem != *oldval)
6801 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6802 * to create or delete the popup menus. */
6803 gui_motif_update_mousemodel(root_menu);
6804#endif
6805 }
6806
6807 /* 'switchbuf' */
6808 else if (varp == &p_swb)
6809 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006810 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006811 errmsg = e_invarg;
6812 }
6813
6814 /* 'debug' */
6815 else if (varp == &p_debug)
6816 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006817 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006818 errmsg = e_invarg;
6819 }
6820
6821 /* 'display' */
6822 else if (varp == &p_dy)
6823 {
6824 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6825 errmsg = e_invarg;
6826 else
6827 (void)init_chartab();
6828
6829 }
6830
6831#ifdef FEAT_VERTSPLIT
6832 /* 'eadirection' */
6833 else if (varp == &p_ead)
6834 {
6835 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6836 errmsg = e_invarg;
6837 }
6838#endif
6839
6840#ifdef FEAT_CLIPBOARD
6841 /* 'clipboard' */
6842 else if (varp == &p_cb)
6843 errmsg = check_clipboard_option();
6844#endif
6845
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006846#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006847 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6848 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006849 else if (varp == &(curwin->w_s->b_p_spl)
6850 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006851 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006852 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006853 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006854 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006855 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006856 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006857 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006858 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006859 /* 'spellsuggest' */
6860 else if (varp == &p_sps)
6861 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006862 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006863 errmsg = e_invarg;
6864 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006865 /* 'mkspellmem' */
6866 else if (varp == &p_msm)
6867 {
6868 if (spell_check_msm() != OK)
6869 errmsg = e_invarg;
6870 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006871#endif
6872
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873#ifdef FEAT_QUICKFIX
6874 /* When 'bufhidden' is set, check for valid value. */
6875 else if (gvarp == &p_bh)
6876 {
6877 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6878 errmsg = e_invarg;
6879 }
6880
6881 /* When 'buftype' is set, check for valid value. */
6882 else if (gvarp == &p_bt)
6883 {
6884 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6885 errmsg = e_invarg;
6886 else
6887 {
6888# ifdef FEAT_WINDOWS
6889 if (curwin->w_status_height)
6890 {
6891 curwin->w_redr_status = TRUE;
6892 redraw_later(VALID);
6893 }
6894# endif
6895 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006896# ifdef FEAT_TITLE
6897 redraw_titles();
6898# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 }
6900 }
6901#endif
6902
6903#ifdef FEAT_STL_OPT
6904 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006905 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 {
6907 int wid;
6908
6909 if (varp == &p_ruf) /* reset ru_wid first */
6910 ru_wid = 0;
6911 s = *varp;
6912 if (varp == &p_ruf && *s == '%')
6913 {
6914 /* set ru_wid if 'ruf' starts with "%99(" */
6915 if (*++s == '-') /* ignore a '-' */
6916 s++;
6917 wid = getdigits(&s);
6918 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6919 ru_wid = wid;
6920 else
6921 errmsg = check_stl_option(p_ruf);
6922 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006923 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006924 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006926 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006927 comp_col();
6928 }
6929#endif
6930
6931#ifdef FEAT_INS_EXPAND
6932 /* check if it is a valid value for 'complete' -- Acevedo */
6933 else if (gvarp == &p_cpt)
6934 {
6935 for (s = *varp; *s;)
6936 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006937 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938 s++;
6939 if (!*s)
6940 break;
6941 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6942 {
6943 errmsg = illegal_char(errbuf, *s);
6944 break;
6945 }
6946 if (*++s != NUL && *s != ',' && *s != ' ')
6947 {
6948 if (s[-1] == 'k' || s[-1] == 's')
6949 {
6950 /* skip optional filename after 'k' and 's' */
6951 while (*s && *s != ',' && *s != ' ')
6952 {
6953 if (*s == '\\')
6954 ++s;
6955 ++s;
6956 }
6957 }
6958 else
6959 {
6960 if (errbuf != NULL)
6961 {
6962 sprintf((char *)errbuf,
6963 _("E535: Illegal character after <%c>"),
6964 *--s);
6965 errmsg = errbuf;
6966 }
6967 else
6968 errmsg = (char_u *)"";
6969 break;
6970 }
6971 }
6972 }
6973 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006974
6975 /* 'completeopt' */
6976 else if (varp == &p_cot)
6977 {
6978 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6979 errmsg = e_invarg;
6980 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006981#endif /* FEAT_INS_EXPAND */
6982
6983
6984#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6985 else if (varp == &p_toolbar)
6986 {
6987 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6988 &toolbar_flags, TRUE) != OK)
6989 errmsg = e_invarg;
6990 else
6991 {
6992 out_flush();
6993 gui_mch_show_toolbar((toolbar_flags &
6994 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6995 }
6996 }
6997#endif
6998
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006999#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007000 /* 'toolbariconsize': GTK+ 2 only */
7001 else if (varp == &p_tbis)
7002 {
7003 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7004 errmsg = e_invarg;
7005 else
7006 {
7007 out_flush();
7008 gui_mch_show_toolbar((toolbar_flags &
7009 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7010 }
7011 }
7012#endif
7013
7014 /* 'pastetoggle': translate key codes like in a mapping */
7015 else if (varp == &p_pt)
7016 {
7017 if (*p_pt)
7018 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007019 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007020 if (p != NULL)
7021 {
7022 if (new_value_alloced)
7023 free_string_option(p_pt);
7024 p_pt = p;
7025 new_value_alloced = TRUE;
7026 }
7027 }
7028 }
7029
7030 /* 'backspace' */
7031 else if (varp == &p_bs)
7032 {
7033 if (VIM_ISDIGIT(*p_bs))
7034 {
7035 if (*p_bs >'2' || p_bs[1] != NUL)
7036 errmsg = e_invarg;
7037 }
7038 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7039 errmsg = e_invarg;
7040 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007041 else if (varp == &p_bo)
7042 {
7043 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7044 errmsg = e_invarg;
7045 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007046
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007047#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048 /* 'casemap' */
7049 else if (varp == &p_cmp)
7050 {
7051 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7052 errmsg = e_invarg;
7053 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007054#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007055
7056#ifdef FEAT_DIFF
7057 /* 'diffopt' */
7058 else if (varp == &p_dip)
7059 {
7060 if (diffopt_changed() == FAIL)
7061 errmsg = e_invarg;
7062 }
7063#endif
7064
7065#ifdef FEAT_FOLDING
7066 /* 'foldmethod' */
7067 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7068 {
7069 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7070 || *curwin->w_p_fdm == NUL)
7071 errmsg = e_invarg;
7072 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007073 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007074 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007075 if (foldmethodIsDiff(curwin))
7076 newFoldLevel();
7077 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 }
7079# ifdef FEAT_EVAL
7080 /* 'foldexpr' */
7081 else if (varp == &curwin->w_p_fde)
7082 {
7083 if (foldmethodIsExpr(curwin))
7084 foldUpdateAll(curwin);
7085 }
7086# endif
7087 /* 'foldmarker' */
7088 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7089 {
7090 p = vim_strchr(*varp, ',');
7091 if (p == NULL)
7092 errmsg = (char_u *)N_("E536: comma required");
7093 else if (p == *varp || p[1] == NUL)
7094 errmsg = e_invarg;
7095 else if (foldmethodIsMarker(curwin))
7096 foldUpdateAll(curwin);
7097 }
7098 /* 'commentstring' */
7099 else if (gvarp == &p_cms)
7100 {
7101 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7102 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7103 }
7104 /* 'foldopen' */
7105 else if (varp == &p_fdo)
7106 {
7107 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7108 errmsg = e_invarg;
7109 }
7110 /* 'foldclose' */
7111 else if (varp == &p_fcl)
7112 {
7113 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7114 errmsg = e_invarg;
7115 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007116 /* 'foldignore' */
7117 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7118 {
7119 if (foldmethodIsIndent(curwin))
7120 foldUpdateAll(curwin);
7121 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122#endif
7123
7124#ifdef FEAT_VIRTUALEDIT
7125 /* 'virtualedit' */
7126 else if (varp == &p_ve)
7127 {
7128 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7129 errmsg = e_invarg;
7130 else if (STRCMP(p_ve, oldval) != 0)
7131 {
7132 /* Recompute cursor position in case the new 've' setting
7133 * changes something. */
7134 validate_virtcol();
7135 coladvance(curwin->w_virtcol);
7136 }
7137 }
7138#endif
7139
7140#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7141 else if (varp == &p_csqf)
7142 {
7143 if (p_csqf != NULL)
7144 {
7145 p = p_csqf;
7146 while (*p != NUL)
7147 {
7148 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7149 || p[1] == NUL
7150 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7151 || (p[2] != NUL && p[2] != ','))
7152 {
7153 errmsg = e_invarg;
7154 break;
7155 }
7156 else if (p[2] == NUL)
7157 break;
7158 else
7159 p += 3;
7160 }
7161 }
7162 }
7163#endif
7164
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007165#ifdef FEAT_CINDENT
7166 /* 'cinoptions' */
7167 else if (gvarp == &p_cino)
7168 {
7169 /* TODO: recognize errors */
7170 parse_cino(curbuf);
7171 }
7172#endif
7173
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007174#if defined(FEAT_RENDER_OPTIONS)
7175 else if (varp == &p_rop && gui.in_use)
7176 {
7177 if (!gui_mch_set_rendering_options(p_rop))
7178 errmsg = e_invarg;
7179 }
7180#endif
7181
Bram Moolenaar071d4272004-06-13 20:20:40 +00007182 /* Options that are a list of flags. */
7183 else
7184 {
7185 p = NULL;
7186 if (varp == &p_ww)
7187 p = (char_u *)WW_ALL;
7188 if (varp == &p_shm)
7189 p = (char_u *)SHM_ALL;
7190 else if (varp == &(p_cpo))
7191 p = (char_u *)CPO_ALL;
7192 else if (varp == &(curbuf->b_p_fo))
7193 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007194#ifdef FEAT_CONCEAL
7195 else if (varp == &curwin->w_p_cocu)
7196 p = (char_u *)COCU_ALL;
7197#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198 else if (varp == &p_mouse)
7199 {
7200#ifdef FEAT_MOUSE
7201 p = (char_u *)MOUSE_ALL;
7202#else
7203 if (*p_mouse != NUL)
7204 errmsg = (char_u *)N_("E538: No mouse support");
7205#endif
7206 }
7207#if defined(FEAT_GUI)
7208 else if (varp == &p_go)
7209 p = (char_u *)GO_ALL;
7210#endif
7211 if (p != NULL)
7212 {
7213 for (s = *varp; *s; ++s)
7214 if (vim_strchr(p, *s) == NULL)
7215 {
7216 errmsg = illegal_char(errbuf, *s);
7217 break;
7218 }
7219 }
7220 }
7221
7222 /*
7223 * If error detected, restore the previous value.
7224 */
7225 if (errmsg != NULL)
7226 {
7227 if (new_value_alloced)
7228 free_string_option(*varp);
7229 *varp = oldval;
7230 /*
7231 * When resetting some values, need to act on it.
7232 */
7233 if (did_chartab)
7234 (void)init_chartab();
7235 if (varp == &p_hl)
7236 (void)highlight_changed();
7237 }
7238 else
7239 {
7240#ifdef FEAT_EVAL
7241 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007242 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007243#endif
7244 /*
7245 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007246 * Use "free_oldval", because recursiveness may change the flags under
7247 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007248 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007249 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007250 free_string_option(oldval);
7251 if (new_value_alloced)
7252 options[opt_idx].flags |= P_ALLOCED;
7253 else
7254 options[opt_idx].flags &= ~P_ALLOCED;
7255
7256 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007257 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007258 {
7259 /* global option with local value set to use global value; free
7260 * the local value and make it empty */
7261 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7262 free_string_option(*(char_u **)p);
7263 *(char_u **)p = empty_option;
7264 }
7265
7266 /* May set global value for local option. */
7267 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7268 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007269
7270#ifdef FEAT_AUTOCMD
7271 /*
7272 * Trigger the autocommand only after setting the flags.
7273 */
7274# ifdef FEAT_SYN_HL
7275 /* When 'syntax' is set, load the syntax of that name */
7276 if (varp == &(curbuf->b_p_syn))
7277 {
7278 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7279 curbuf->b_fname, TRUE, curbuf);
7280 }
7281# endif
7282 else if (varp == &(curbuf->b_p_ft))
7283 {
7284 /* 'filetype' is set, trigger the FileType autocommand */
7285 did_filetype = TRUE;
7286 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7287 curbuf->b_fname, TRUE, curbuf);
7288 }
7289#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007290#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007291 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007292 {
7293 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007294 char_u *q = curwin->w_s->b_p_spl;
7295
7296 /* Skip the first name if it is "cjk". */
7297 if (STRNCMP(q, "cjk,", 4) == 0)
7298 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007299
7300 /*
7301 * Source the spell/LANG.vim in 'runtimepath'.
7302 * They could set 'spellcapcheck' depending on the language.
7303 * Use the first name in 'spelllang' up to '_region' or
7304 * '.encoding'.
7305 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007306 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007307 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7308 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007309 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007310 source_runtime(fname, TRUE);
7311 }
7312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313 }
7314
7315#ifdef FEAT_MOUSE
7316 if (varp == &p_mouse)
7317 {
7318# ifdef FEAT_MOUSE_TTY
7319 if (*p_mouse == NUL)
7320 mch_setmouse(FALSE); /* switch mouse off */
7321 else
7322# endif
7323 setmouse(); /* in case 'mouse' changed */
7324 }
7325#endif
7326
Bram Moolenaar913077c2012-03-28 19:59:04 +02007327 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007328 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007329 curwin->w_set_curswant = TRUE;
7330
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007331#ifdef FEAT_GUI
7332 /* check redraw when it's not a GUI option or the GUI is active. */
7333 if (!redraw_gui_only || gui.in_use)
7334#endif
7335 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336
7337 return errmsg;
7338}
7339
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007340#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007341/*
7342 * Simple int comparison function for use with qsort()
7343 */
7344 static int
7345int_cmp(a, b)
7346 const void *a;
7347 const void *b;
7348{
7349 return *(const int *)a - *(const int *)b;
7350}
7351
7352/*
7353 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7354 * Returns error message, NULL if it's OK.
7355 */
7356 char_u *
7357check_colorcolumn(wp)
7358 win_T *wp;
7359{
7360 char_u *s;
7361 int col;
7362 int count = 0;
7363 int color_cols[256];
7364 int i;
7365 int j = 0;
7366
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007367 if (wp->w_buffer == NULL)
7368 return NULL; /* buffer was closed */
7369
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007370 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007371 {
7372 if (*s == '-' || *s == '+')
7373 {
7374 /* -N and +N: add to 'textwidth' */
7375 col = (*s == '-') ? -1 : 1;
7376 ++s;
7377 if (!VIM_ISDIGIT(*s))
7378 return e_invarg;
7379 col = col * getdigits(&s);
7380 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007381 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007382 col += wp->w_buffer->b_p_tw;
7383 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007384 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007385 }
7386 else if (VIM_ISDIGIT(*s))
7387 col = getdigits(&s);
7388 else
7389 return e_invarg;
7390 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007391skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007392 if (*s == NUL)
7393 break;
7394 if (*s != ',')
7395 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007396 if (*++s == NUL)
7397 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007398 }
7399
7400 vim_free(wp->w_p_cc_cols);
7401 if (count == 0)
7402 wp->w_p_cc_cols = NULL;
7403 else
7404 {
7405 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7406 if (wp->w_p_cc_cols != NULL)
7407 {
7408 /* sort the columns for faster usage on screen redraw inside
7409 * win_line() */
7410 qsort(color_cols, count, sizeof(int), int_cmp);
7411
7412 for (i = 0; i < count; ++i)
7413 /* skip duplicates */
7414 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7415 wp->w_p_cc_cols[j++] = color_cols[i];
7416 wp->w_p_cc_cols[j] = -1; /* end marker */
7417 }
7418 }
7419
7420 return NULL; /* no error */
7421}
7422#endif
7423
Bram Moolenaar071d4272004-06-13 20:20:40 +00007424/*
7425 * Handle setting 'listchars' or 'fillchars'.
7426 * Returns error message, NULL if it's OK.
7427 */
7428 static char_u *
7429set_chars_option(varp)
7430 char_u **varp;
7431{
7432 int round, i, len, entries;
7433 char_u *p, *s;
7434 int c1, c2 = 0;
7435 struct charstab
7436 {
7437 int *cp;
7438 char *name;
7439 };
7440#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7441 static struct charstab filltab[] =
7442 {
7443 {&fill_stl, "stl"},
7444 {&fill_stlnc, "stlnc"},
7445 {&fill_vert, "vert"},
7446 {&fill_fold, "fold"},
7447 {&fill_diff, "diff"},
7448 };
7449#endif
7450 static struct charstab lcstab[] =
7451 {
7452 {&lcs_eol, "eol"},
7453 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007454 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007455 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007456 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457 {&lcs_tab2, "tab"},
7458 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007459#ifdef FEAT_CONCEAL
7460 {&lcs_conceal, "conceal"},
7461#else
7462 {NULL, "conceal"},
7463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007464 };
7465 struct charstab *tab;
7466
7467#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7468 if (varp == &p_lcs)
7469#endif
7470 {
7471 tab = lcstab;
7472 entries = sizeof(lcstab) / sizeof(struct charstab);
7473 }
7474#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7475 else
7476 {
7477 tab = filltab;
7478 entries = sizeof(filltab) / sizeof(struct charstab);
7479 }
7480#endif
7481
7482 /* first round: check for valid value, second round: assign values */
7483 for (round = 0; round <= 1; ++round)
7484 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007485 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 {
7487 /* After checking that the value is valid: set defaults: space for
7488 * 'fillchars', NUL for 'listchars' */
7489 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007490 if (tab[i].cp != NULL)
7491 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 if (varp == &p_lcs)
7493 lcs_tab1 = NUL;
7494#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7495 else
7496 fill_diff = '-';
7497#endif
7498 }
7499 p = *varp;
7500 while (*p)
7501 {
7502 for (i = 0; i < entries; ++i)
7503 {
7504 len = (int)STRLEN(tab[i].name);
7505 if (STRNCMP(p, tab[i].name, len) == 0
7506 && p[len] == ':'
7507 && p[len + 1] != NUL)
7508 {
7509 s = p + len + 1;
7510#ifdef FEAT_MBYTE
7511 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007512 if (mb_char2cells(c1) > 1)
7513 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514#else
7515 c1 = *s++;
7516#endif
7517 if (tab[i].cp == &lcs_tab2)
7518 {
7519 if (*s == NUL)
7520 continue;
7521#ifdef FEAT_MBYTE
7522 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007523 if (mb_char2cells(c2) > 1)
7524 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525#else
7526 c2 = *s++;
7527#endif
7528 }
7529 if (*s == ',' || *s == NUL)
7530 {
7531 if (round)
7532 {
7533 if (tab[i].cp == &lcs_tab2)
7534 {
7535 lcs_tab1 = c1;
7536 lcs_tab2 = c2;
7537 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007538 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007539 *(tab[i].cp) = c1;
7540
7541 }
7542 p = s;
7543 break;
7544 }
7545 }
7546 }
7547
7548 if (i == entries)
7549 return e_invarg;
7550 if (*p == ',')
7551 ++p;
7552 }
7553 }
7554
7555 return NULL; /* no error */
7556}
7557
7558#ifdef FEAT_STL_OPT
7559/*
7560 * Check validity of options with the 'statusline' format.
7561 * Return error message or NULL.
7562 */
7563 char_u *
7564check_stl_option(s)
7565 char_u *s;
7566{
7567 int itemcnt = 0;
7568 int groupdepth = 0;
7569 static char_u errbuf[80];
7570
7571 while (*s && itemcnt < STL_MAX_ITEM)
7572 {
7573 /* Check for valid keys after % sequences */
7574 while (*s && *s != '%')
7575 s++;
7576 if (!*s)
7577 break;
7578 s++;
7579 if (*s != '%' && *s != ')')
7580 ++itemcnt;
7581 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7582 {
7583 s++;
7584 continue;
7585 }
7586 if (*s == ')')
7587 {
7588 s++;
7589 if (--groupdepth < 0)
7590 break;
7591 continue;
7592 }
7593 if (*s == '-')
7594 s++;
7595 while (VIM_ISDIGIT(*s))
7596 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007597 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007598 continue;
7599 if (*s == '.')
7600 {
7601 s++;
7602 while (*s && VIM_ISDIGIT(*s))
7603 s++;
7604 }
7605 if (*s == '(')
7606 {
7607 groupdepth++;
7608 continue;
7609 }
7610 if (vim_strchr(STL_ALL, *s) == NULL)
7611 {
7612 return illegal_char(errbuf, *s);
7613 }
7614 if (*s == '{')
7615 {
7616 s++;
7617 while (*s != '}' && *s)
7618 s++;
7619 if (*s != '}')
7620 return (char_u *)N_("E540: Unclosed expression sequence");
7621 }
7622 }
7623 if (itemcnt >= STL_MAX_ITEM)
7624 return (char_u *)N_("E541: too many items");
7625 if (groupdepth != 0)
7626 return (char_u *)N_("E542: unbalanced groups");
7627 return NULL;
7628}
7629#endif
7630
7631#ifdef FEAT_CLIPBOARD
7632/*
7633 * Extract the items in the 'clipboard' option and set global values.
7634 */
7635 static char_u *
7636check_clipboard_option()
7637{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007638 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007639 int new_autoselect_star = FALSE;
7640 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007641 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007642 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007643 regprog_T *new_exclude_prog = NULL;
7644 char_u *errmsg = NULL;
7645 char_u *p;
7646
7647 for (p = p_cb; *p != NUL; )
7648 {
7649 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7650 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007651 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007652 p += 7;
7653 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007654 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007655 && (p[11] == ',' || p[11] == NUL))
7656 {
7657 new_unnamed |= CLIP_UNNAMED_PLUS;
7658 p += 11;
7659 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007660 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007661 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007663 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007664 p += 10;
7665 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007666 else if (STRNCMP(p, "autoselectplus", 14) == 0
7667 && (p[14] == ',' || p[14] == NUL))
7668 {
7669 new_autoselect_plus = TRUE;
7670 p += 14;
7671 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007672 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007673 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007674 {
7675 new_autoselectml = TRUE;
7676 p += 12;
7677 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007678 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7679 {
7680 new_html = TRUE;
7681 p += 4;
7682 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007683 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7684 {
7685 p += 8;
7686 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7687 if (new_exclude_prog == NULL)
7688 errmsg = e_invarg;
7689 break;
7690 }
7691 else
7692 {
7693 errmsg = e_invarg;
7694 break;
7695 }
7696 if (*p == ',')
7697 ++p;
7698 }
7699 if (errmsg == NULL)
7700 {
7701 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007702 clip_autoselect_star = new_autoselect_star;
7703 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007705 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007706 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007707 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007708#ifdef FEAT_GUI_GTK
7709 if (gui.in_use)
7710 {
7711 gui_gtk_set_selection_targets();
7712 gui_gtk_set_dnd_targets();
7713 }
7714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715 }
7716 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007717 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718
7719 return errmsg;
7720}
7721#endif
7722
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007723#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007724 static char_u *
7725did_set_spell_option(is_spellfile)
7726 int is_spellfile;
7727{
7728 char_u *errmsg = NULL;
7729 win_T *wp;
7730 int l;
7731
7732 if (is_spellfile)
7733 {
7734 l = (int)STRLEN(curwin->w_s->b_p_spf);
7735 if (l > 0 && (l < 4
7736 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7737 errmsg = e_invarg;
7738 }
7739
7740 if (errmsg == NULL)
7741 {
7742 FOR_ALL_WINDOWS(wp)
7743 if (wp->w_buffer == curbuf && wp->w_p_spell)
7744 {
7745 errmsg = did_set_spelllang(wp);
7746# ifdef FEAT_WINDOWS
7747 break;
7748# endif
7749 }
7750 }
7751 return errmsg;
7752}
7753
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007754/*
7755 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7756 * Return error message when failed, NULL when OK.
7757 */
7758 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007759compile_cap_prog(synblock)
7760 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007761{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007762 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007763 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007764
Bram Moolenaar860cae12010-06-05 23:22:07 +02007765 if (*synblock->b_p_spc == NUL)
7766 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007767 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007768 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007769 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007770 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007771 if (re != NULL)
7772 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007773 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007774 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007775 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007776 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007777 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007778 return e_invarg;
7779 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007780 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007781 }
7782
Bram Moolenaar473de612013-06-08 18:19:48 +02007783 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007784 return NULL;
7785}
7786#endif
7787
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007788#if defined(FEAT_EVAL) || defined(PROTO)
7789/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007790 * Set the scriptID for an option, taking care of setting the buffer- or
7791 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007792 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007793 static void
7794set_option_scriptID_idx(opt_idx, opt_flags, id)
7795 int opt_idx;
7796 int opt_flags;
7797 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007798{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007799 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7800 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007801
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007802 /* Remember where the option was set. For local options need to do that
7803 * in the buffer or window structure. */
7804 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007805 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007806 if (both || (opt_flags & OPT_LOCAL))
7807 {
7808 if (indir & PV_BUF)
7809 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7810 else if (indir & PV_WIN)
7811 curwin->w_p_scriptID[indir & PV_MASK] = id;
7812 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007813}
7814#endif
7815
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816/*
7817 * Set the value of a boolean option, and take care of side effects.
7818 * Returns NULL for success, or an error message for an error.
7819 */
7820 static char_u *
7821set_bool_option(opt_idx, varp, value, opt_flags)
7822 int opt_idx; /* index in options[] table */
7823 char_u *varp; /* pointer to the option variable */
7824 int value; /* new value */
7825 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7826{
7827 int old_value = *(int *)varp;
7828
Bram Moolenaar071d4272004-06-13 20:20:40 +00007829 /* Disallow changing some options from secure mode */
7830 if ((secure
7831#ifdef HAVE_SANDBOX
7832 || sandbox != 0
7833#endif
7834 ) && (options[opt_idx].flags & P_SECURE))
7835 return e_secure;
7836
7837 *(int *)varp = value; /* set the new value */
7838#ifdef FEAT_EVAL
7839 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007840 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841#endif
7842
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007843#ifdef FEAT_GUI
7844 need_mouse_correct = TRUE;
7845#endif
7846
Bram Moolenaar071d4272004-06-13 20:20:40 +00007847 /* May set global value for local option. */
7848 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7849 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7850
7851 /*
7852 * Handle side effects of changing a bool option.
7853 */
7854
7855 /* 'compatible' */
7856 if ((int *)varp == &p_cp)
7857 {
7858 compatible_set();
7859 }
7860
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007861#ifdef FEAT_PERSISTENT_UNDO
7862 /* 'undofile' */
7863 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7864 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007865 /* Only take action when the option was set. When reset we do not
7866 * delete the undo file, the option may be set again without making
7867 * any changes in between. */
7868 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007869 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007870 char_u hash[UNDO_HASH_SIZE];
7871 buf_T *save_curbuf = curbuf;
7872
7873 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007874 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007875 /* When 'undofile' is set globally: for every buffer, otherwise
7876 * only for the current buffer: Try to read in the undofile,
7877 * if one exists, the buffer wasn't changed and the buffer was
7878 * loaded */
7879 if ((curbuf == save_curbuf
7880 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7881 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7882 {
7883 u_compute_hash(hash);
7884 u_read_undo(NULL, hash, curbuf->b_fname);
7885 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007886 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007887 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007888 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007889 }
7890#endif
7891
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 else if ((int *)varp == &curbuf->b_p_ro)
7893 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007894 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7896 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007897
7898 /* when 'readonly' is set may give W10 again */
7899 if (curbuf->b_p_ro)
7900 curbuf->b_did_warn = FALSE;
7901
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007903 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904#endif
7905 }
7906
Bram Moolenaar9c449722010-07-20 18:44:27 +02007907#ifdef FEAT_GUI
7908 else if ((int *)varp == &p_mh)
7909 {
7910 if (!p_mh)
7911 gui_mch_mousehide(FALSE);
7912 }
7913#endif
7914
Bram Moolenaara539df02010-08-01 14:35:05 +02007915#ifdef FEAT_TITLE
7916 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007918 {
7919 redraw_titles();
7920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921 /* when 'endofline' is changed, redraw the window title */
7922 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007923 {
7924 redraw_titles();
7925 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007926 /* when 'fixeol' is changed, redraw the window title */
7927 else if ((int *)varp == &curbuf->b_p_fixeol)
7928 {
7929 redraw_titles();
7930 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007931# ifdef FEAT_MBYTE
7932 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007933 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007934 {
7935 redraw_titles();
7936 }
7937# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938#endif
7939
7940 /* when 'bin' is set also set some other options */
7941 else if ((int *)varp == &curbuf->b_p_bin)
7942 {
7943 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7944#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007945 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946#endif
7947 }
7948
7949#ifdef FEAT_AUTOCMD
7950 /* when 'buflisted' changes, trigger autocommands */
7951 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7952 {
7953 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7954 NULL, NULL, TRUE, curbuf);
7955 }
7956#endif
7957
7958 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7959 else if ((int *)varp == &curbuf->b_p_swf)
7960 {
7961 if (curbuf->b_p_swf && p_uc)
7962 ml_open_file(curbuf); /* create the swap file */
7963 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007964 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7965 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 mf_close_file(curbuf, TRUE); /* remove the swap file */
7967 }
7968
7969 /* when 'terse' is set change 'shortmess' */
7970 else if ((int *)varp == &p_terse)
7971 {
7972 char_u *p;
7973
7974 p = vim_strchr(p_shm, SHM_SEARCH);
7975
7976 /* insert 's' in p_shm */
7977 if (p_terse && p == NULL)
7978 {
7979 STRCPY(IObuff, p_shm);
7980 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007981 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007982 }
7983 /* remove 's' from p_shm */
7984 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007985 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986 }
7987
7988 /* when 'paste' is set or reset also change other options */
7989 else if ((int *)varp == &p_paste)
7990 {
7991 paste_option_changed();
7992 }
7993
7994 /* when 'insertmode' is set from an autocommand need to do work here */
7995 else if ((int *)varp == &p_im)
7996 {
7997 if (p_im)
7998 {
7999 if ((State & INSERT) == 0)
8000 need_start_insertmode = TRUE;
8001 stop_insert_mode = FALSE;
8002 }
8003 else
8004 {
8005 need_start_insertmode = FALSE;
8006 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008007 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008008 clear_cmdline = TRUE; /* remove "(insert)" */
8009 restart_edit = 0;
8010 }
8011 }
8012
8013 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8014 else if ((int *)varp == &p_ic && p_hls)
8015 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008016 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 }
8018
8019#ifdef FEAT_SEARCH_EXTRA
8020 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8021 else if ((int *)varp == &p_hls)
8022 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008023 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008024 }
8025#endif
8026
8027#ifdef FEAT_SCROLLBIND
8028 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8029 * at the end of normal_cmd() */
8030 else if ((int *)varp == &curwin->w_p_scb)
8031 {
8032 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008033 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008035 curwin->w_scbind_pos = curwin->w_topline;
8036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 }
8038#endif
8039
8040#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8041 /* There can be only one window with 'previewwindow' set. */
8042 else if ((int *)varp == &curwin->w_p_pvw)
8043 {
8044 if (curwin->w_p_pvw)
8045 {
8046 win_T *win;
8047
8048 for (win = firstwin; win != NULL; win = win->w_next)
8049 if (win->w_p_pvw && win != curwin)
8050 {
8051 curwin->w_p_pvw = FALSE;
8052 return (char_u *)N_("E590: A preview window already exists");
8053 }
8054 }
8055 }
8056#endif
8057
8058 /* when 'textmode' is set or reset also change 'fileformat' */
8059 else if ((int *)varp == &curbuf->b_p_tx)
8060 {
8061 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8062 }
8063
8064 /* when 'textauto' is set or reset also change 'fileformats' */
8065 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066 set_string_option_direct((char_u *)"ffs", -1,
8067 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008068 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069
8070 /*
8071 * When 'lisp' option changes include/exclude '-' in
8072 * keyword characters.
8073 */
8074#ifdef FEAT_LISP
8075 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8076 {
8077 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8078 }
8079#endif
8080
8081#ifdef FEAT_TITLE
8082 /* when 'title' changed, may need to change the title; same for 'icon' */
8083 else if ((int *)varp == &p_title)
8084 {
8085 did_set_title(FALSE);
8086 }
8087
8088 else if ((int *)varp == &p_icon)
8089 {
8090 did_set_title(TRUE);
8091 }
8092#endif
8093
8094 else if ((int *)varp == &curbuf->b_changed)
8095 {
8096 if (!value)
8097 save_file_ff(curbuf); /* Buffer is unchanged */
8098#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008099 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008100#endif
8101#ifdef FEAT_AUTOCMD
8102 modified_was_set = value;
8103#endif
8104 }
8105
8106#ifdef BACKSLASH_IN_FILENAME
8107 else if ((int *)varp == &p_ssl)
8108 {
8109 if (p_ssl)
8110 {
8111 psepc = '/';
8112 psepcN = '\\';
8113 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114 }
8115 else
8116 {
8117 psepc = '\\';
8118 psepcN = '/';
8119 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008120 }
8121
8122 /* need to adjust the file name arguments and buffer names. */
8123 buflist_slash_adjust();
8124 alist_slash_adjust();
8125# ifdef FEAT_EVAL
8126 scriptnames_slash_adjust();
8127# endif
8128 }
8129#endif
8130
8131 /* If 'wrap' is set, set w_leftcol to zero. */
8132 else if ((int *)varp == &curwin->w_p_wrap)
8133 {
8134 if (curwin->w_p_wrap)
8135 curwin->w_leftcol = 0;
8136 }
8137
8138#ifdef FEAT_WINDOWS
8139 else if ((int *)varp == &p_ea)
8140 {
8141 if (p_ea && !old_value)
8142 win_equal(curwin, FALSE, 0);
8143 }
8144#endif
8145
8146 else if ((int *)varp == &p_wiv)
8147 {
8148 /*
8149 * When 'weirdinvert' changed, set/reset 't_xs'.
8150 * Then set 'weirdinvert' according to value of 't_xs'.
8151 */
8152 if (p_wiv && !old_value)
8153 T_XS = (char_u *)"y";
8154 else if (!p_wiv && old_value)
8155 T_XS = empty_option;
8156 p_wiv = (*T_XS != NUL);
8157 }
8158
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008159#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 else if ((int *)varp == &p_beval)
8161 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008162 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008164 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 gui_mch_disable_beval_area(balloonEval);
8166 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008167#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008168
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008169#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008170 else if ((int *)varp == &p_acd)
8171 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008172 /* Change directories when the 'acd' option is set now. */
8173 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008174 }
8175#endif
8176
8177#ifdef FEAT_DIFF
8178 /* 'diff' */
8179 else if ((int *)varp == &curwin->w_p_diff)
8180 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008181 /* May add or remove the buffer from the list of diff buffers. */
8182 diff_buf_adjust(curwin);
8183# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184 if (foldmethodIsDiff(curwin))
8185 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008186# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187 }
8188#endif
8189
8190#ifdef USE_IM_CONTROL
8191 /* 'imdisable' */
8192 else if ((int *)varp == &p_imdisable)
8193 {
8194 /* Only de-activate it here, it will be enabled when changing mode. */
8195 if (p_imdisable)
8196 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008197 else if (State & INSERT)
8198 /* When the option is set from an autocommand, it may need to take
8199 * effect right away. */
8200 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008201 }
8202#endif
8203
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008204#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008205 /* 'spell' */
8206 else if ((int *)varp == &curwin->w_p_spell)
8207 {
8208 if (curwin->w_p_spell)
8209 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008210 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008211 if (errmsg != NULL)
8212 EMSG(_(errmsg));
8213 }
8214 }
8215#endif
8216
Bram Moolenaar071d4272004-06-13 20:20:40 +00008217#ifdef FEAT_FKMAP
8218 else if ((int *)varp == &p_altkeymap)
8219 {
8220 if (old_value != p_altkeymap)
8221 {
8222 if (!p_altkeymap)
8223 {
8224 p_hkmap = p_fkmap;
8225 p_fkmap = 0;
8226 }
8227 else
8228 {
8229 p_fkmap = p_hkmap;
8230 p_hkmap = 0;
8231 }
8232 (void)init_chartab();
8233 }
8234 }
8235
8236 /*
8237 * In case some second language keymapping options have changed, check
8238 * and correct the setting in a consistent way.
8239 */
8240
8241 /*
8242 * If hkmap or fkmap are set, reset Arabic keymapping.
8243 */
8244 if ((p_hkmap || p_fkmap) && p_altkeymap)
8245 {
8246 p_altkeymap = p_fkmap;
8247# ifdef FEAT_ARABIC
8248 curwin->w_p_arab = FALSE;
8249# endif
8250 (void)init_chartab();
8251 }
8252
8253 /*
8254 * If hkmap set, reset Farsi keymapping.
8255 */
8256 if (p_hkmap && p_altkeymap)
8257 {
8258 p_altkeymap = 0;
8259 p_fkmap = 0;
8260# ifdef FEAT_ARABIC
8261 curwin->w_p_arab = FALSE;
8262# endif
8263 (void)init_chartab();
8264 }
8265
8266 /*
8267 * If fkmap set, reset Hebrew keymapping.
8268 */
8269 if (p_fkmap && !p_altkeymap)
8270 {
8271 p_altkeymap = 1;
8272 p_hkmap = 0;
8273# ifdef FEAT_ARABIC
8274 curwin->w_p_arab = FALSE;
8275# endif
8276 (void)init_chartab();
8277 }
8278#endif
8279
8280#ifdef FEAT_ARABIC
8281 if ((int *)varp == &curwin->w_p_arab)
8282 {
8283 if (curwin->w_p_arab)
8284 {
8285 /*
8286 * 'arabic' is set, handle various sub-settings.
8287 */
8288 if (!p_tbidi)
8289 {
8290 /* set rightleft mode */
8291 if (!curwin->w_p_rl)
8292 {
8293 curwin->w_p_rl = TRUE;
8294 changed_window_setting();
8295 }
8296
8297 /* Enable Arabic shaping (major part of what Arabic requires) */
8298 if (!p_arshape)
8299 {
8300 p_arshape = TRUE;
8301 redraw_later_clear();
8302 }
8303 }
8304
8305 /* Arabic requires a utf-8 encoding, inform the user if its not
8306 * set. */
8307 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008308 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008309 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8310
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008311 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008312 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8313#ifdef FEAT_EVAL
8314 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8315#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008316 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008317
8318# ifdef FEAT_MBYTE
8319 /* set 'delcombine' */
8320 p_deco = TRUE;
8321# endif
8322
8323# ifdef FEAT_KEYMAP
8324 /* Force-set the necessary keymap for arabic */
8325 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8326 OPT_LOCAL);
8327# endif
8328# ifdef FEAT_FKMAP
8329 p_altkeymap = 0;
8330 p_hkmap = 0;
8331 p_fkmap = 0;
8332 (void)init_chartab();
8333# endif
8334 }
8335 else
8336 {
8337 /*
8338 * 'arabic' is reset, handle various sub-settings.
8339 */
8340 if (!p_tbidi)
8341 {
8342 /* reset rightleft mode */
8343 if (curwin->w_p_rl)
8344 {
8345 curwin->w_p_rl = FALSE;
8346 changed_window_setting();
8347 }
8348
8349 /* 'arabicshape' isn't reset, it is a global option and
8350 * another window may still need it "on". */
8351 }
8352
8353 /* 'delcombine' isn't reset, it is a global option and another
8354 * window may still want it "on". */
8355
8356# ifdef FEAT_KEYMAP
8357 /* Revert to the default keymap */
8358 curbuf->b_p_iminsert = B_IMODE_NONE;
8359 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8360# endif
8361 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008362 }
8363
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008364#endif
8365
Bram Moolenaar071d4272004-06-13 20:20:40 +00008366 /*
8367 * End of handling side effects for bool options.
8368 */
8369
Bram Moolenaar53744302015-07-17 17:38:22 +02008370 /* after handling side effects, call autocommand */
8371
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372 options[opt_idx].flags |= P_WAS_SET;
8373
Bram Moolenaar53744302015-07-17 17:38:22 +02008374#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8375 if (!starting)
8376 {
8377 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008378 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8379 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8380 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008381 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8382 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8383 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8384 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8385 reset_v_option_vars();
8386 }
8387#endif
8388
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008390 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008391 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008392 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008393 check_redraw(options[opt_idx].flags);
8394
8395 return NULL;
8396}
8397
8398/*
8399 * Set the value of a number option, and take care of side effects.
8400 * Returns NULL for success, or an error message for an error.
8401 */
8402 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008403set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404 int opt_idx; /* index in options[] table */
8405 char_u *varp; /* pointer to the option variable */
8406 long value; /* new value */
8407 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008408 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8410 OPT_MODELINE */
8411{
8412 char_u *errmsg = NULL;
8413 long old_value = *(long *)varp;
8414 long old_Rows = Rows; /* remember old Rows */
8415 long old_Columns = Columns; /* remember old Columns */
8416 long *pp = (long *)varp;
8417
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008418 /* Disallow changing some options from secure mode. */
8419 if ((secure
8420#ifdef HAVE_SANDBOX
8421 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008422#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008423 ) && (options[opt_idx].flags & P_SECURE))
8424 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425
8426 *pp = value;
8427#ifdef FEAT_EVAL
8428 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008429 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008431#ifdef FEAT_GUI
8432 need_mouse_correct = TRUE;
8433#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434
Bram Moolenaar14f24742012-08-08 18:01:05 +02008435 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436 {
8437 errmsg = e_positive;
8438 curbuf->b_p_sw = curbuf->b_p_ts;
8439 }
8440
8441 /*
8442 * Number options that need some action when changed
8443 */
8444#ifdef FEAT_WINDOWS
8445 if (pp == &p_wh || pp == &p_hh)
8446 {
8447 if (p_wh < 1)
8448 {
8449 errmsg = e_positive;
8450 p_wh = 1;
8451 }
8452 if (p_wmh > p_wh)
8453 {
8454 errmsg = e_winheight;
8455 p_wh = p_wmh;
8456 }
8457 if (p_hh < 0)
8458 {
8459 errmsg = e_positive;
8460 p_hh = 0;
8461 }
8462
8463 /* Change window height NOW */
8464 if (lastwin != firstwin)
8465 {
8466 if (pp == &p_wh && curwin->w_height < p_wh)
8467 win_setheight((int)p_wh);
8468 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8469 win_setheight((int)p_hh);
8470 }
8471 }
8472
8473 /* 'winminheight' */
8474 else if (pp == &p_wmh)
8475 {
8476 if (p_wmh < 0)
8477 {
8478 errmsg = e_positive;
8479 p_wmh = 0;
8480 }
8481 if (p_wmh > p_wh)
8482 {
8483 errmsg = e_winheight;
8484 p_wmh = p_wh;
8485 }
8486 win_setminheight();
8487 }
8488
8489# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008490 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008491 {
8492 if (p_wiw < 1)
8493 {
8494 errmsg = e_positive;
8495 p_wiw = 1;
8496 }
8497 if (p_wmw > p_wiw)
8498 {
8499 errmsg = e_winwidth;
8500 p_wiw = p_wmw;
8501 }
8502
8503 /* Change window width NOW */
8504 if (lastwin != firstwin && curwin->w_width < p_wiw)
8505 win_setwidth((int)p_wiw);
8506 }
8507
8508 /* 'winminwidth' */
8509 else if (pp == &p_wmw)
8510 {
8511 if (p_wmw < 0)
8512 {
8513 errmsg = e_positive;
8514 p_wmw = 0;
8515 }
8516 if (p_wmw > p_wiw)
8517 {
8518 errmsg = e_winwidth;
8519 p_wmw = p_wiw;
8520 }
8521 win_setminheight();
8522 }
8523# endif
8524
8525#endif
8526
8527#ifdef FEAT_WINDOWS
8528 /* (re)set last window status line */
8529 else if (pp == &p_ls)
8530 {
8531 last_status(FALSE);
8532 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008533
8534 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008535 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008536 {
8537 shell_new_rows(); /* recompute window positions and heights */
8538 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008539#endif
8540
8541#ifdef FEAT_GUI
8542 else if (pp == &p_linespace)
8543 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008544 /* Recompute gui.char_height and resize the Vim window to keep the
8545 * same number of lines. */
8546 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008547 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008548 }
8549#endif
8550
8551#ifdef FEAT_FOLDING
8552 /* 'foldlevel' */
8553 else if (pp == &curwin->w_p_fdl)
8554 {
8555 if (curwin->w_p_fdl < 0)
8556 curwin->w_p_fdl = 0;
8557 newFoldLevel();
8558 }
8559
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008560 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561 else if (pp == &curwin->w_p_fml)
8562 {
8563 foldUpdateAll(curwin);
8564 }
8565
8566 /* 'foldnestmax' */
8567 else if (pp == &curwin->w_p_fdn)
8568 {
8569 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8570 foldUpdateAll(curwin);
8571 }
8572
8573 /* 'foldcolumn' */
8574 else if (pp == &curwin->w_p_fdc)
8575 {
8576 if (curwin->w_p_fdc < 0)
8577 {
8578 errmsg = e_positive;
8579 curwin->w_p_fdc = 0;
8580 }
8581 else if (curwin->w_p_fdc > 12)
8582 {
8583 errmsg = e_invarg;
8584 curwin->w_p_fdc = 12;
8585 }
8586 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008587#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008589#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590 /* 'shiftwidth' or 'tabstop' */
8591 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8592 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008593# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008594 if (foldmethodIsIndent(curwin))
8595 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008596# endif
8597# ifdef FEAT_CINDENT
8598 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8599 * parse 'cinoptions'. */
8600 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8601 parse_cino(curbuf);
8602# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008603 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008604#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008606#ifdef FEAT_MBYTE
8607 /* 'maxcombine' */
8608 else if (pp == &p_mco)
8609 {
8610 if (p_mco > MAX_MCO)
8611 p_mco = MAX_MCO;
8612 else if (p_mco < 0)
8613 p_mco = 0;
8614 screenclear(); /* will re-allocate the screen */
8615 }
8616#endif
8617
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618 else if (pp == &curbuf->b_p_iminsert)
8619 {
8620 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8621 {
8622 errmsg = e_invarg;
8623 curbuf->b_p_iminsert = B_IMODE_NONE;
8624 }
8625 p_iminsert = curbuf->b_p_iminsert;
8626 if (termcap_active) /* don't do this in the alternate screen */
8627 showmode();
8628#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8629 /* Show/unshow value of 'keymap' in status lines. */
8630 status_redraw_curbuf();
8631#endif
8632 }
8633
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008634 else if (pp == &p_window)
8635 {
8636 if (p_window < 1)
8637 p_window = 1;
8638 else if (p_window >= Rows)
8639 p_window = Rows - 1;
8640 }
8641
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 else if (pp == &curbuf->b_p_imsearch)
8643 {
8644 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8645 {
8646 errmsg = e_invarg;
8647 curbuf->b_p_imsearch = B_IMODE_NONE;
8648 }
8649 p_imsearch = curbuf->b_p_imsearch;
8650 }
8651
8652#ifdef FEAT_TITLE
8653 /* if 'titlelen' has changed, redraw the title */
8654 else if (pp == &p_titlelen)
8655 {
8656 if (p_titlelen < 0)
8657 {
8658 errmsg = e_positive;
8659 p_titlelen = 85;
8660 }
8661 if (starting != NO_SCREEN && old_value != p_titlelen)
8662 need_maketitle = TRUE;
8663 }
8664#endif
8665
8666 /* if p_ch changed value, change the command line height */
8667 else if (pp == &p_ch)
8668 {
8669 if (p_ch < 1)
8670 {
8671 errmsg = e_positive;
8672 p_ch = 1;
8673 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008674 if (p_ch > Rows - min_rows() + 1)
8675 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676
8677 /* Only compute the new window layout when startup has been
8678 * completed. Otherwise the frame sizes may be wrong. */
8679 if (p_ch != old_value && full_screen
8680#ifdef FEAT_GUI
8681 && !gui.starting
8682#endif
8683 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008684 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008685 }
8686
8687 /* when 'updatecount' changes from zero to non-zero, open swap files */
8688 else if (pp == &p_uc)
8689 {
8690 if (p_uc < 0)
8691 {
8692 errmsg = e_positive;
8693 p_uc = 100;
8694 }
8695 if (p_uc && !old_value)
8696 ml_open_files();
8697 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008698#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008699 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008700 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008701 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008702 {
8703 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008704 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008705 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008706 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008707 {
8708 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008709 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008710 }
8711 }
8712#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008713#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008714 else if (pp == &p_mzq)
8715 mzvim_reset_timer();
8716#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008717
8718 /* sync undo before 'undolevels' changes */
8719 else if (pp == &p_ul)
8720 {
8721 /* use the old value, otherwise u_sync() may not work properly */
8722 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008723 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008724 p_ul = value;
8725 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008726 else if (pp == &curbuf->b_p_ul)
8727 {
8728 /* use the old value, otherwise u_sync() may not work properly */
8729 curbuf->b_p_ul = old_value;
8730 u_sync(TRUE);
8731 curbuf->b_p_ul = value;
8732 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008733
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008734#ifdef FEAT_LINEBREAK
8735 /* 'numberwidth' must be positive */
8736 else if (pp == &curwin->w_p_nuw)
8737 {
8738 if (curwin->w_p_nuw < 1)
8739 {
8740 errmsg = e_positive;
8741 curwin->w_p_nuw = 1;
8742 }
8743 if (curwin->w_p_nuw > 10)
8744 {
8745 errmsg = e_invarg;
8746 curwin->w_p_nuw = 10;
8747 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008748 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008749 }
8750#endif
8751
Bram Moolenaar1a384422010-07-14 19:53:30 +02008752 else if (pp == &curbuf->b_p_tw)
8753 {
8754 if (curbuf->b_p_tw < 0)
8755 {
8756 errmsg = e_positive;
8757 curbuf->b_p_tw = 0;
8758 }
8759#ifdef FEAT_SYN_HL
8760# ifdef FEAT_WINDOWS
8761 {
8762 win_T *wp;
8763 tabpage_T *tp;
8764
8765 FOR_ALL_TAB_WINDOWS(tp, wp)
8766 check_colorcolumn(wp);
8767 }
8768# else
8769 check_colorcolumn(curwin);
8770# endif
8771#endif
8772 }
8773
Bram Moolenaar071d4272004-06-13 20:20:40 +00008774 /*
8775 * Check the bounds for numeric options here
8776 */
8777 if (Rows < min_rows() && full_screen)
8778 {
8779 if (errbuf != NULL)
8780 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008781 vim_snprintf((char *)errbuf, errbuflen,
8782 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008783 errmsg = errbuf;
8784 }
8785 Rows = min_rows();
8786 }
8787 if (Columns < MIN_COLUMNS && full_screen)
8788 {
8789 if (errbuf != NULL)
8790 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008791 vim_snprintf((char *)errbuf, errbuflen,
8792 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008793 errmsg = errbuf;
8794 }
8795 Columns = MIN_COLUMNS;
8796 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008797 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798
8799#ifdef DJGPP
8800 /* avoid a crash by checking for a too large value of 'columns' */
8801 if (old_Columns != Columns && full_screen && term_console)
8802 mch_check_columns();
8803#endif
8804
8805 /*
8806 * If the screen (shell) height has been changed, assume it is the
8807 * physical screenheight.
8808 */
8809 if (old_Rows != Rows || old_Columns != Columns)
8810 {
8811 /* Changing the screen size is not allowed while updating the screen. */
8812 if (updating_screen)
8813 *pp = old_value;
8814 else if (full_screen
8815#ifdef FEAT_GUI
8816 && !gui.starting
8817#endif
8818 )
8819 set_shellsize((int)Columns, (int)Rows, TRUE);
8820 else
8821 {
8822 /* Postpone the resizing; check the size and cmdline position for
8823 * messages. */
8824 check_shellsize();
8825 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8826 cmdline_row = Rows - p_ch;
8827 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008828 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008829 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830 }
8831
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832 if (curbuf->b_p_ts <= 0)
8833 {
8834 errmsg = e_positive;
8835 curbuf->b_p_ts = 8;
8836 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 if (p_tm < 0)
8838 {
8839 errmsg = e_positive;
8840 p_tm = 0;
8841 }
8842 if ((curwin->w_p_scr <= 0
8843 || (curwin->w_p_scr > curwin->w_height
8844 && curwin->w_height > 0))
8845 && full_screen)
8846 {
8847 if (pp == &(curwin->w_p_scr))
8848 {
8849 if (curwin->w_p_scr != 0)
8850 errmsg = e_scroll;
8851 win_comp_scroll(curwin);
8852 }
8853 /* If 'scroll' became invalid because of a side effect silently adjust
8854 * it. */
8855 else if (curwin->w_p_scr <= 0)
8856 curwin->w_p_scr = 1;
8857 else /* curwin->w_p_scr > curwin->w_height */
8858 curwin->w_p_scr = curwin->w_height;
8859 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008860 if (p_hi < 0)
8861 {
8862 errmsg = e_positive;
8863 p_hi = 0;
8864 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008865 else if (p_hi > 10000)
8866 {
8867 errmsg = e_invarg;
8868 p_hi = 10000;
8869 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008870 if (p_re < 0 || p_re > 2)
8871 {
8872 errmsg = e_invarg;
8873 p_re = 0;
8874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008875 if (p_report < 0)
8876 {
8877 errmsg = e_positive;
8878 p_report = 1;
8879 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008880 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 {
8882 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8883 p_sj = Rows / 2;
8884 else
8885 {
8886 errmsg = e_scroll;
8887 p_sj = 1;
8888 }
8889 }
8890 if (p_so < 0 && full_screen)
8891 {
8892 errmsg = e_scroll;
8893 p_so = 0;
8894 }
8895 if (p_siso < 0 && full_screen)
8896 {
8897 errmsg = e_positive;
8898 p_siso = 0;
8899 }
8900#ifdef FEAT_CMDWIN
8901 if (p_cwh < 1)
8902 {
8903 errmsg = e_positive;
8904 p_cwh = 1;
8905 }
8906#endif
8907 if (p_ut < 0)
8908 {
8909 errmsg = e_positive;
8910 p_ut = 2000;
8911 }
8912 if (p_ss < 0)
8913 {
8914 errmsg = e_positive;
8915 p_ss = 0;
8916 }
8917
8918 /* May set global value for local option. */
8919 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8920 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8921
8922 options[opt_idx].flags |= P_WAS_SET;
8923
Bram Moolenaar53744302015-07-17 17:38:22 +02008924#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8925 if (!starting && errmsg == NULL)
8926 {
8927 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008928 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8929 vim_snprintf((char *)buf_new, 10, "%ld", value);
8930 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008931 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8932 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8933 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8934 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8935 reset_v_option_vars();
8936 }
8937#endif
8938
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008940 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008941 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008942 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008943 check_redraw(options[opt_idx].flags);
8944
8945 return errmsg;
8946}
8947
8948/*
8949 * Called after an option changed: check if something needs to be redrawn.
8950 */
8951 static void
8952check_redraw(flags)
8953 long_u flags;
8954{
8955 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008956 int doclear = (flags & P_RCLR) == P_RCLR;
8957 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008958
8959#ifdef FEAT_WINDOWS
8960 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8961 status_redraw_all();
8962#endif
8963
8964 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8965 changed_window_setting();
8966 if (flags & P_RBUF)
8967 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008968 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008969 redraw_all_later(CLEAR);
8970 else if (all)
8971 redraw_all_later(NOT_VALID);
8972}
8973
8974/*
8975 * Find index for option 'arg'.
8976 * Return -1 if not found.
8977 */
8978 static int
8979findoption(arg)
8980 char_u *arg;
8981{
8982 int opt_idx;
8983 char *s, *p;
8984 static short quick_tab[27] = {0, 0}; /* quick access table */
8985 int is_term_opt;
8986
8987 /*
8988 * For first call: Initialize the quick-access table.
8989 * It contains the index for the first option that starts with a certain
8990 * letter. There are 26 letters, plus the first "t_" option.
8991 */
8992 if (quick_tab[1] == 0)
8993 {
8994 p = options[0].fullname;
8995 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8996 {
8997 if (s[0] != p[0])
8998 {
8999 if (s[0] == 't' && s[1] == '_')
9000 quick_tab[26] = opt_idx;
9001 else
9002 quick_tab[CharOrdLow(s[0])] = opt_idx;
9003 }
9004 p = s;
9005 }
9006 }
9007
9008 /*
9009 * Check for name starting with an illegal character.
9010 */
9011#ifdef EBCDIC
9012 if (!islower(arg[0]))
9013#else
9014 if (arg[0] < 'a' || arg[0] > 'z')
9015#endif
9016 return -1;
9017
9018 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9019 if (is_term_opt)
9020 opt_idx = quick_tab[26];
9021 else
9022 opt_idx = quick_tab[CharOrdLow(arg[0])];
9023 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9024 {
9025 if (STRCMP(arg, s) == 0) /* match full name */
9026 break;
9027 }
9028 if (s == NULL && !is_term_opt)
9029 {
9030 opt_idx = quick_tab[CharOrdLow(arg[0])];
9031 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9032 {
9033 s = options[opt_idx].shortname;
9034 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9035 break;
9036 s = NULL;
9037 }
9038 }
9039 if (s == NULL)
9040 opt_idx = -1;
9041 return opt_idx;
9042}
9043
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009044#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009045/*
9046 * Get the value for an option.
9047 *
9048 * Returns:
9049 * Number or Toggle option: 1, *numval gets value.
9050 * String option: 0, *stringval gets allocated string.
9051 * Hidden Number or Toggle option: -1.
9052 * hidden String option: -2.
9053 * unknown option: -3.
9054 */
9055 int
9056get_option_value(name, numval, stringval, opt_flags)
9057 char_u *name;
9058 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009059 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009060 int opt_flags;
9061{
9062 int opt_idx;
9063 char_u *varp;
9064
9065 opt_idx = findoption(name);
9066 if (opt_idx < 0) /* unknown option */
9067 return -3;
9068
9069 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9070
9071 if (options[opt_idx].flags & P_STRING)
9072 {
9073 if (varp == NULL) /* hidden option */
9074 return -2;
9075 if (stringval != NULL)
9076 {
9077#ifdef FEAT_CRYPT
9078 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009079 if ((char_u **)varp == &curbuf->b_p_key
9080 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009081 *stringval = vim_strsave((char_u *)"*****");
9082 else
9083#endif
9084 *stringval = vim_strsave(*(char_u **)(varp));
9085 }
9086 return 0;
9087 }
9088
9089 if (varp == NULL) /* hidden option */
9090 return -1;
9091 if (options[opt_idx].flags & P_NUM)
9092 *numval = *(long *)varp;
9093 else
9094 {
9095 /* Special case: 'modified' is b_changed, but we also want to consider
9096 * it set when 'ff' or 'fenc' changed. */
9097 if ((int *)varp == &curbuf->b_changed)
9098 *numval = curbufIsChanged();
9099 else
9100 *numval = *(int *)varp;
9101 }
9102 return 1;
9103}
9104#endif
9105
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009106#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009107/*
9108 * Returns the option attributes and its value. Unlike the above function it
9109 * will return either global value or local value of the option depending on
9110 * what was requested, but it will never return global value if it was
9111 * requested to return local one and vice versa. Neither it will return
9112 * buffer-local value if it was requested to return window-local one.
9113 *
9114 * Pretends that option is absent if it is not present in the requested scope
9115 * (i.e. has no global, window-local or buffer-local value depending on
9116 * opt_type). Uses
9117 *
9118 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009119 * 0 hidden or unknown option, also option that does not have requested
9120 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009121 * see SOPT_* in vim.h for other flags
9122 *
9123 * Possible opt_type values: see SREQ_* in vim.h
9124 */
9125 int
9126get_option_value_strict(name, numval, stringval, opt_type, from)
9127 char_u *name;
9128 long *numval;
9129 char_u **stringval; /* NULL when only obtaining attributes */
9130 int opt_type;
9131 void *from;
9132{
9133 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009134 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009135 struct vimoption *p;
9136 int r = 0;
9137
9138 opt_idx = findoption(name);
9139 if (opt_idx < 0)
9140 return 0;
9141
9142 p = &(options[opt_idx]);
9143
9144 /* Hidden option */
9145 if (p->var == NULL)
9146 return 0;
9147
9148 if (p->flags & P_BOOL)
9149 r |= SOPT_BOOL;
9150 else if (p->flags & P_NUM)
9151 r |= SOPT_NUM;
9152 else if (p->flags & P_STRING)
9153 r |= SOPT_STRING;
9154
9155 if (p->indir == PV_NONE)
9156 {
9157 if (opt_type == SREQ_GLOBAL)
9158 r |= SOPT_GLOBAL;
9159 else
9160 return 0; /* Did not request global-only option */
9161 }
9162 else
9163 {
9164 if (p->indir & PV_BOTH)
9165 r |= SOPT_GLOBAL;
9166 else if (opt_type == SREQ_GLOBAL)
9167 return 0; /* Requested global option */
9168
9169 if (p->indir & PV_WIN)
9170 {
9171 if (opt_type == SREQ_BUF)
9172 return 0; /* Did not request window-local option */
9173 else
9174 r |= SOPT_WIN;
9175 }
9176 else if (p->indir & PV_BUF)
9177 {
9178 if (opt_type == SREQ_WIN)
9179 return 0; /* Did not request buffer-local option */
9180 else
9181 r |= SOPT_BUF;
9182 }
9183 }
9184
9185 if (stringval == NULL)
9186 return r;
9187
9188 if (opt_type == SREQ_GLOBAL)
9189 varp = p->var;
9190 else
9191 {
9192 if (opt_type == SREQ_BUF)
9193 {
9194 /* Special case: 'modified' is b_changed, but we also want to
9195 * consider it set when 'ff' or 'fenc' changed. */
9196 if (p->indir == PV_MOD)
9197 {
9198 *numval = bufIsChanged((buf_T *) from);
9199 varp = NULL;
9200 }
9201#ifdef FEAT_CRYPT
9202 else if (p->indir == PV_KEY)
9203 {
9204 /* never return the value of the crypt key */
9205 *stringval = NULL;
9206 varp = NULL;
9207 }
9208#endif
9209 else
9210 {
9211 aco_save_T aco;
9212 aucmd_prepbuf(&aco, (buf_T *) from);
9213 varp = get_varp(p);
9214 aucmd_restbuf(&aco);
9215 }
9216 }
9217 else if (opt_type == SREQ_WIN)
9218 {
9219 win_T *save_curwin;
9220 save_curwin = curwin;
9221 curwin = (win_T *) from;
9222 curbuf = curwin->w_buffer;
9223 varp = get_varp(p);
9224 curwin = save_curwin;
9225 curbuf = curwin->w_buffer;
9226 }
9227 if (varp == p->var)
9228 return (r | SOPT_UNSET);
9229 }
9230
9231 if (varp != NULL)
9232 {
9233 if (p->flags & P_STRING)
9234 *stringval = vim_strsave(*(char_u **)(varp));
9235 else if (p->flags & P_NUM)
9236 *numval = *(long *) varp;
9237 else
9238 *numval = *(int *)varp;
9239 }
9240
9241 return r;
9242}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009243
9244/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009245 * Iterate over options. First argument is a pointer to a pointer to a
9246 * structure inside options[] array, second is option type like in the above
9247 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009248 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009249 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009250 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009251 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009252 * first argument to NULL.
9253 *
9254 * Returns full option name for current option on each call.
9255 */
9256 char_u *
9257option_iter_next(option, opt_type)
9258 void **option;
9259 int opt_type;
9260{
9261 struct vimoption *ret = NULL;
9262 do
9263 {
9264 if (*option == NULL)
9265 *option = (void *) options;
9266 else if (((struct vimoption *) (*option))->fullname == NULL)
9267 {
9268 *option = NULL;
9269 return NULL;
9270 }
9271 else
9272 *option = (void *) (((struct vimoption *) (*option)) + 1);
9273
9274 ret = ((struct vimoption *) (*option));
9275
9276 /* Hidden option */
9277 if (ret->var == NULL)
9278 {
9279 ret = NULL;
9280 continue;
9281 }
9282
9283 switch (opt_type)
9284 {
9285 case SREQ_GLOBAL:
9286 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9287 ret = NULL;
9288 break;
9289 case SREQ_BUF:
9290 if (!(ret->indir & PV_BUF))
9291 ret = NULL;
9292 break;
9293 case SREQ_WIN:
9294 if (!(ret->indir & PV_WIN))
9295 ret = NULL;
9296 break;
9297 default:
9298 EMSG2(_(e_intern2), "option_iter_next()");
9299 return NULL;
9300 }
9301 }
9302 while (ret == NULL);
9303
9304 return (char_u *)ret->fullname;
9305}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009306#endif
9307
Bram Moolenaar071d4272004-06-13 20:20:40 +00009308/*
9309 * Set the value of option "name".
9310 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009311 *
9312 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009313 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009314 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009315set_option_value(name, number, string, opt_flags)
9316 char_u *name;
9317 long number;
9318 char_u *string;
9319 int opt_flags; /* OPT_LOCAL or 0 (both) */
9320{
9321 int opt_idx;
9322 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009323 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009324
9325 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009326 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327 EMSG2(_("E355: Unknown option: %s"), name);
9328 else
9329 {
9330 flags = options[opt_idx].flags;
9331#ifdef HAVE_SANDBOX
9332 /* Disallow changing some options in the sandbox */
9333 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009334 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009336 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009337 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009339 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009340 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341 else
9342 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009343 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009344 if (varp != NULL) /* hidden option is not changed */
9345 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009346 if (number == 0 && string != NULL)
9347 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009348 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009349
9350 /* Either we are given a string or we are setting option
9351 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009352 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009353 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009354 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009355 {
9356 /* There's another character after zeros or the string
9357 * is empty. In both cases, we are trying to set a
9358 * num option using a string. */
9359 EMSG3(_("E521: Number required: &%s = '%s'"),
9360 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009361 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009362
9363 }
9364 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009366 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009367 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009369 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009370 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009371 }
9372 }
9373 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009374 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009375}
9376
9377/*
9378 * Get the terminal code for a terminal option.
9379 * Returns NULL when not found.
9380 */
9381 char_u *
9382get_term_code(tname)
9383 char_u *tname;
9384{
9385 int opt_idx;
9386 char_u *varp;
9387
9388 if (tname[0] != 't' || tname[1] != '_' ||
9389 tname[2] == NUL || tname[3] == NUL)
9390 return NULL;
9391 if ((opt_idx = findoption(tname)) >= 0)
9392 {
9393 varp = get_varp(&(options[opt_idx]));
9394 if (varp != NULL)
9395 varp = *(char_u **)(varp);
9396 return varp;
9397 }
9398 return find_termcode(tname + 2);
9399}
9400
9401 char_u *
9402get_highlight_default()
9403{
9404 int i;
9405
9406 i = findoption((char_u *)"hl");
9407 if (i >= 0)
9408 return options[i].def_val[VI_DEFAULT];
9409 return (char_u *)NULL;
9410}
9411
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009412#if defined(FEAT_MBYTE) || defined(PROTO)
9413 char_u *
9414get_encoding_default()
9415{
9416 int i;
9417
9418 i = findoption((char_u *)"enc");
9419 if (i >= 0)
9420 return options[i].def_val[VI_DEFAULT];
9421 return (char_u *)NULL;
9422}
9423#endif
9424
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425/*
9426 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9427 */
9428 static int
9429find_key_option(arg)
9430 char_u *arg;
9431{
9432 int key;
9433 int modifiers;
9434
9435 /*
9436 * Don't use get_special_key_code() for t_xx, we don't want it to call
9437 * add_termcap_entry().
9438 */
9439 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9440 key = TERMCAP2KEY(arg[2], arg[3]);
9441 else
9442 {
9443 --arg; /* put arg at the '<' */
9444 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009445 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009446 if (modifiers) /* can't handle modifiers here */
9447 key = 0;
9448 }
9449 return key;
9450}
9451
9452/*
9453 * if 'all' == 0: show changed options
9454 * if 'all' == 1: show all normal options
9455 * if 'all' == 2: show all terminal options
9456 */
9457 static void
9458showoptions(all, opt_flags)
9459 int all;
9460 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9461{
9462 struct vimoption *p;
9463 int col;
9464 int isterm;
9465 char_u *varp;
9466 struct vimoption **items;
9467 int item_count;
9468 int run;
9469 int row, rows;
9470 int cols;
9471 int i;
9472 int len;
9473
9474#define INC 20
9475#define GAP 3
9476
9477 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9478 PARAM_COUNT));
9479 if (items == NULL)
9480 return;
9481
9482 /* Highlight title */
9483 if (all == 2)
9484 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9485 else if (opt_flags & OPT_GLOBAL)
9486 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9487 else if (opt_flags & OPT_LOCAL)
9488 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9489 else
9490 MSG_PUTS_TITLE(_("\n--- Options ---"));
9491
9492 /*
9493 * do the loop two times:
9494 * 1. display the short items
9495 * 2. display the long items (only strings and numbers)
9496 */
9497 for (run = 1; run <= 2 && !got_int; ++run)
9498 {
9499 /*
9500 * collect the items in items[]
9501 */
9502 item_count = 0;
9503 for (p = &options[0]; p->fullname != NULL; p++)
9504 {
9505 varp = NULL;
9506 isterm = istermoption(p);
9507 if (opt_flags != 0)
9508 {
9509 if (p->indir != PV_NONE && !isterm)
9510 varp = get_varp_scope(p, opt_flags);
9511 }
9512 else
9513 varp = get_varp(p);
9514 if (varp != NULL
9515 && ((all == 2 && isterm)
9516 || (all == 1 && !isterm)
9517 || (all == 0 && !optval_default(p, varp))))
9518 {
9519 if (p->flags & P_BOOL)
9520 len = 1; /* a toggle option fits always */
9521 else
9522 {
9523 option_value2string(p, opt_flags);
9524 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9525 }
9526 if ((len <= INC - GAP && run == 1) ||
9527 (len > INC - GAP && run == 2))
9528 items[item_count++] = p;
9529 }
9530 }
9531
9532 /*
9533 * display the items
9534 */
9535 if (run == 1)
9536 {
9537 cols = (Columns + GAP - 3) / INC;
9538 if (cols == 0)
9539 cols = 1;
9540 rows = (item_count + cols - 1) / cols;
9541 }
9542 else /* run == 2 */
9543 rows = item_count;
9544 for (row = 0; row < rows && !got_int; ++row)
9545 {
9546 msg_putchar('\n'); /* go to next line */
9547 if (got_int) /* 'q' typed in more */
9548 break;
9549 col = 0;
9550 for (i = row; i < item_count; i += rows)
9551 {
9552 msg_col = col; /* make columns */
9553 showoneopt(items[i], opt_flags);
9554 col += INC;
9555 }
9556 out_flush();
9557 ui_breakcheck();
9558 }
9559 }
9560 vim_free(items);
9561}
9562
9563/*
9564 * Return TRUE if option "p" has its default value.
9565 */
9566 static int
9567optval_default(p, varp)
9568 struct vimoption *p;
9569 char_u *varp;
9570{
9571 int dvi;
9572
9573 if (varp == NULL)
9574 return TRUE; /* hidden option is always at default */
9575 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9576 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009577 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009578 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009579 /* the cast to long is required for Manx C, long_i is
9580 * needed for MSVC */
9581 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582 /* P_STRING */
9583 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9584}
9585
9586/*
9587 * showoneopt: show the value of one option
9588 * must not be called with a hidden option!
9589 */
9590 static void
9591showoneopt(p, opt_flags)
9592 struct vimoption *p;
9593 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9594{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009595 char_u *varp;
9596 int save_silent = silent_mode;
9597
9598 silent_mode = FALSE;
9599 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009600
9601 varp = get_varp_scope(p, opt_flags);
9602
9603 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9604 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9605 ? !curbufIsChanged() : !*(int *)varp))
9606 MSG_PUTS("no");
9607 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9608 MSG_PUTS("--");
9609 else
9610 MSG_PUTS(" ");
9611 MSG_PUTS(p->fullname);
9612 if (!(p->flags & P_BOOL))
9613 {
9614 msg_putchar('=');
9615 /* put value string in NameBuff */
9616 option_value2string(p, opt_flags);
9617 msg_outtrans(NameBuff);
9618 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009619
9620 silent_mode = save_silent;
9621 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009622}
9623
9624/*
9625 * Write modified options as ":set" commands to a file.
9626 *
9627 * There are three values for "opt_flags":
9628 * OPT_GLOBAL: Write global option values and fresh values of
9629 * buffer-local options (used for start of a session
9630 * file).
9631 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9632 * curwin (used for a vimrc file).
9633 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9634 * and local values for window-local options of
9635 * curwin. Local values are also written when at the
9636 * default value, because a modeline or autocommand
9637 * may have set them when doing ":edit file" and the
9638 * user has set them back at the default or fresh
9639 * value.
9640 * When "local_only" is TRUE, don't write fresh
9641 * values, only local values (for ":mkview").
9642 * (fresh value = value used for a new buffer or window for a local option).
9643 *
9644 * Return FAIL on error, OK otherwise.
9645 */
9646 int
9647makeset(fd, opt_flags, local_only)
9648 FILE *fd;
9649 int opt_flags;
9650 int local_only;
9651{
9652 struct vimoption *p;
9653 char_u *varp; /* currently used value */
9654 char_u *varp_fresh; /* local value */
9655 char_u *varp_local = NULL; /* fresh value */
9656 char *cmd;
9657 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009658 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009659
9660 /*
9661 * The options that don't have a default (terminal name, columns, lines)
9662 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009663 * Do the loop over "options[]" twice: once for options with the
9664 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009665 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009666 for (pri = 1; pri >= 0; --pri)
9667 {
9668 for (p = &options[0]; !istermoption(p); p++)
9669 if (!(p->flags & P_NO_MKRC)
9670 && !istermoption(p)
9671 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009672 {
9673 /* skip global option when only doing locals */
9674 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9675 continue;
9676
9677 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9678 * file, they are always buffer-specific. */
9679 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9680 continue;
9681
9682 /* Global values are only written when not at the default value. */
9683 varp = get_varp_scope(p, opt_flags);
9684 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9685 continue;
9686
9687 round = 2;
9688 if (p->indir != PV_NONE)
9689 {
9690 if (p->var == VAR_WIN)
9691 {
9692 /* skip window-local option when only doing globals */
9693 if (!(opt_flags & OPT_LOCAL))
9694 continue;
9695 /* When fresh value of window-local option is not at the
9696 * default, need to write it too. */
9697 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9698 {
9699 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9700 if (!optval_default(p, varp_fresh))
9701 {
9702 round = 1;
9703 varp_local = varp;
9704 varp = varp_fresh;
9705 }
9706 }
9707 }
9708 }
9709
9710 /* Round 1: fresh value for window-local options.
9711 * Round 2: other values */
9712 for ( ; round <= 2; varp = varp_local, ++round)
9713 {
9714 if (round == 1 || (opt_flags & OPT_GLOBAL))
9715 cmd = "set";
9716 else
9717 cmd = "setlocal";
9718
9719 if (p->flags & P_BOOL)
9720 {
9721 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9722 return FAIL;
9723 }
9724 else if (p->flags & P_NUM)
9725 {
9726 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9727 return FAIL;
9728 }
9729 else /* P_STRING */
9730 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009731#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9732 int do_endif = FALSE;
9733
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 /* Don't set 'syntax' and 'filetype' again if the value is
9735 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009736 if (
9737# if defined(FEAT_SYN_HL)
9738 p->indir == PV_SYN
9739# if defined(FEAT_AUTOCMD)
9740 ||
9741# endif
9742# endif
9743# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009744 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009745# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009746 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747 {
9748 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9749 *(char_u **)(varp)) < 0
9750 || put_eol(fd) < 0)
9751 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009752 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009753 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9756 (p->flags & P_EXPAND) != 0) == FAIL)
9757 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009758#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9759 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760 {
9761 if (put_line(fd, "endif") == FAIL)
9762 return FAIL;
9763 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009764#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009765 }
9766 }
9767 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009768 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009769 return OK;
9770}
9771
9772#if defined(FEAT_FOLDING) || defined(PROTO)
9773/*
9774 * Generate set commands for the local fold options only. Used when
9775 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9776 */
9777 int
9778makefoldset(fd)
9779 FILE *fd;
9780{
9781 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9782# ifdef FEAT_EVAL
9783 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9784 == FAIL
9785# endif
9786 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9787 == FAIL
9788 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9789 == FAIL
9790 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9791 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9792 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9793 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9794 )
9795 return FAIL;
9796
9797 return OK;
9798}
9799#endif
9800
9801 static int
9802put_setstring(fd, cmd, name, valuep, expand)
9803 FILE *fd;
9804 char *cmd;
9805 char *name;
9806 char_u **valuep;
9807 int expand;
9808{
9809 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009810 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009811
9812 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9813 return FAIL;
9814 if (*valuep != NULL)
9815 {
9816 /* Output 'pastetoggle' as key names. For other
9817 * options some characters have to be escaped with
9818 * CTRL-V or backslash */
9819 if (valuep == &p_pt)
9820 {
9821 s = *valuep;
9822 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009823 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009824 return FAIL;
9825 }
9826 else if (expand)
9827 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009828 buf = alloc(MAXPATHL);
9829 if (buf == NULL)
9830 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009831 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9832 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009833 {
9834 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009835 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009836 }
9837 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009838 }
9839 else if (put_escstr(fd, *valuep, 2) == FAIL)
9840 return FAIL;
9841 }
9842 if (put_eol(fd) < 0)
9843 return FAIL;
9844 return OK;
9845}
9846
9847 static int
9848put_setnum(fd, cmd, name, valuep)
9849 FILE *fd;
9850 char *cmd;
9851 char *name;
9852 long *valuep;
9853{
9854 long wc;
9855
9856 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9857 return FAIL;
9858 if (wc_use_keyname((char_u *)valuep, &wc))
9859 {
9860 /* print 'wildchar' and 'wildcharm' as a key name */
9861 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9862 return FAIL;
9863 }
9864 else if (fprintf(fd, "%ld", *valuep) < 0)
9865 return FAIL;
9866 if (put_eol(fd) < 0)
9867 return FAIL;
9868 return OK;
9869}
9870
9871 static int
9872put_setbool(fd, cmd, name, value)
9873 FILE *fd;
9874 char *cmd;
9875 char *name;
9876 int value;
9877{
Bram Moolenaar893de922007-10-02 18:40:57 +00009878 if (value < 0) /* global/local option using global value */
9879 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009880 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9881 || put_eol(fd) < 0)
9882 return FAIL;
9883 return OK;
9884}
9885
9886/*
9887 * Clear all the terminal options.
9888 * If the option has been allocated, free the memory.
9889 * Terminal options are never hidden or indirect.
9890 */
9891 void
9892clear_termoptions()
9893{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009894 /*
9895 * Reset a few things before clearing the old options. This may cause
9896 * outputting a few things that the terminal doesn't understand, but the
9897 * screen will be cleared later, so this is OK.
9898 */
9899#ifdef FEAT_MOUSE_TTY
9900 mch_setmouse(FALSE); /* switch mouse off */
9901#endif
9902#ifdef FEAT_TITLE
9903 mch_restore_title(3); /* restore window titles */
9904#endif
9905#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9906 /* When starting the GUI close the display opened for the clipboard.
9907 * After restoring the title, because that will need the display. */
9908 if (gui.starting)
9909 clear_xterm_clip();
9910#endif
9911#ifdef WIN3264
9912 /*
9913 * Check if this is allowed now.
9914 */
9915 if (can_end_termcap_mode(FALSE) == TRUE)
9916#endif
9917 stoptermcap(); /* stop termcap mode */
9918
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009919 free_termoptions();
9920}
9921
9922 void
9923free_termoptions()
9924{
9925 struct vimoption *p;
9926
Bram Moolenaar071d4272004-06-13 20:20:40 +00009927 for (p = &options[0]; p->fullname != NULL; p++)
9928 if (istermoption(p))
9929 {
9930 if (p->flags & P_ALLOCED)
9931 free_string_option(*(char_u **)(p->var));
9932 if (p->flags & P_DEF_ALLOCED)
9933 free_string_option(p->def_val[VI_DEFAULT]);
9934 *(char_u **)(p->var) = empty_option;
9935 p->def_val[VI_DEFAULT] = empty_option;
9936 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9937 }
9938 clear_termcodes();
9939}
9940
9941/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009942 * Free the string for one term option, if it was allocated.
9943 * Set the string to empty_option and clear allocated flag.
9944 * "var" points to the option value.
9945 */
9946 void
9947free_one_termoption(var)
9948 char_u *var;
9949{
9950 struct vimoption *p;
9951
9952 for (p = &options[0]; p->fullname != NULL; p++)
9953 if (p->var == var)
9954 {
9955 if (p->flags & P_ALLOCED)
9956 free_string_option(*(char_u **)(p->var));
9957 *(char_u **)(p->var) = empty_option;
9958 p->flags &= ~P_ALLOCED;
9959 break;
9960 }
9961}
9962
9963/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009964 * Set the terminal option defaults to the current value.
9965 * Used after setting the terminal name.
9966 */
9967 void
9968set_term_defaults()
9969{
9970 struct vimoption *p;
9971
9972 for (p = &options[0]; p->fullname != NULL; p++)
9973 {
9974 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9975 {
9976 if (p->flags & P_DEF_ALLOCED)
9977 {
9978 free_string_option(p->def_val[VI_DEFAULT]);
9979 p->flags &= ~P_DEF_ALLOCED;
9980 }
9981 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9982 if (p->flags & P_ALLOCED)
9983 {
9984 p->flags |= P_DEF_ALLOCED;
9985 p->flags &= ~P_ALLOCED; /* don't free the value now */
9986 }
9987 }
9988 }
9989}
9990
9991/*
9992 * return TRUE if 'p' starts with 't_'
9993 */
9994 static int
9995istermoption(p)
9996 struct vimoption *p;
9997{
9998 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9999}
10000
10001/*
10002 * Compute columns for ruler and shown command. 'sc_col' is also used to
10003 * decide what the maximum length of a message on the status line can be.
10004 * If there is a status line for the last window, 'sc_col' is independent
10005 * of 'ru_col'.
10006 */
10007
10008#define COL_RULER 17 /* columns needed by standard ruler */
10009
10010 void
10011comp_col()
10012{
10013#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10014 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10015
10016 sc_col = 0;
10017 ru_col = 0;
10018 if (p_ru)
10019 {
10020#ifdef FEAT_STL_OPT
10021 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10022#else
10023 ru_col = COL_RULER + 1;
10024#endif
10025 /* no last status line, adjust sc_col */
10026 if (!last_has_status)
10027 sc_col = ru_col;
10028 }
10029 if (p_sc)
10030 {
10031 sc_col += SHOWCMD_COLS;
10032 if (!p_ru || last_has_status) /* no need for separating space */
10033 ++sc_col;
10034 }
10035 sc_col = Columns - sc_col;
10036 ru_col = Columns - ru_col;
10037 if (sc_col <= 0) /* screen too narrow, will become a mess */
10038 sc_col = 1;
10039 if (ru_col <= 0)
10040 ru_col = 1;
10041#else
10042 sc_col = Columns;
10043 ru_col = Columns;
10044#endif
10045}
10046
10047/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010048 * Unset local option value, similar to ":set opt<".
10049 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010050 void
10051unset_global_local_option(name, from)
10052 char_u *name;
10053 void *from;
10054{
10055 struct vimoption *p;
10056 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010057 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010058
10059 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010060 if (opt_idx < 0)
10061 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010062 p = &(options[opt_idx]);
10063
10064 switch ((int)p->indir)
10065 {
10066 /* global option with local value: use local value if it's been set */
10067 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010068 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010069 break;
10070 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010071 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010072 break;
10073 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010074 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010075 break;
10076 case PV_AR:
10077 buf->b_p_ar = -1;
10078 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010079 case PV_BKC:
10080 clear_string_option(&buf->b_p_bkc);
10081 buf->b_bkc_flags = 0;
10082 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010083 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010084 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010085 break;
10086#ifdef FEAT_FIND_ID
10087 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010088 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010089 break;
10090 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010091 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010092 break;
10093#endif
10094#ifdef FEAT_INS_EXPAND
10095 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010096 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097 break;
10098 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010099 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010100 break;
10101#endif
10102#ifdef FEAT_QUICKFIX
10103 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010104 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010105 break;
10106 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010107 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010108 break;
10109 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010110 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010111 break;
10112#endif
10113#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10114 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010115 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010116 break;
10117#endif
10118#if defined(FEAT_CRYPT)
10119 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010120 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010121 break;
10122#endif
10123#ifdef FEAT_STL_OPT
10124 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010125 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010126 break;
10127#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010128 case PV_UL:
10129 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10130 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010131#ifdef FEAT_LISP
10132 case PV_LW:
10133 clear_string_option(&buf->b_p_lw);
10134 break;
10135#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010136 }
10137}
10138
10139/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140 * Get pointer to option variable, depending on local or global scope.
10141 */
10142 static char_u *
10143get_varp_scope(p, opt_flags)
10144 struct vimoption *p;
10145 int opt_flags;
10146{
10147 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10148 {
10149 if (p->var == VAR_WIN)
10150 return (char_u *)GLOBAL_WO(get_varp(p));
10151 return p->var;
10152 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010153 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154 {
10155 switch ((int)p->indir)
10156 {
10157#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010158 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10159 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10160 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010162 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10163 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10164 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010165 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010166 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010168 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10169 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170#endif
10171#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010172 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10173 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010175#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10176 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10177#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010178#if defined(FEAT_CRYPT)
10179 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10180#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010181#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010182 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010183#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010184 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010185#ifdef FEAT_LISP
10186 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10187#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010188 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 }
10190 return NULL; /* "cannot happen" */
10191 }
10192 return get_varp(p);
10193}
10194
10195/*
10196 * Get pointer to option variable.
10197 */
10198 static char_u *
10199get_varp(p)
10200 struct vimoption *p;
10201{
10202 /* hidden option, always return NULL */
10203 if (p->var == NULL)
10204 return NULL;
10205
10206 switch ((int)p->indir)
10207 {
10208 case PV_NONE: return p->var;
10209
10210 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010211 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010213 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010214 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010215 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010217 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010219 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010221 case PV_BKC: return *curbuf->b_p_bkc != NUL
10222 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010223#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010224 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010225 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010226 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10228#endif
10229#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010230 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010231 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010232 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10234#endif
10235#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010236 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010237 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010238 case PV_GP: return *curbuf->b_p_gp != NUL
10239 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10240 case PV_MP: return *curbuf->b_p_mp != NUL
10241 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010242#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010243#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10244 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10245 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10246#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010247#if defined(FEAT_CRYPT)
10248 case PV_CM: return *curbuf->b_p_cm != NUL
10249 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10250#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010251#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010252 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010253 ? (char_u *)&(curwin->w_p_stl) : p->var;
10254#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010255 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10256 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010257#ifdef FEAT_LISP
10258 case PV_LW: return *curbuf->b_p_lw != NUL
10259 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261
10262#ifdef FEAT_ARABIC
10263 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10264#endif
10265 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010266#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010267 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10268#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010269#ifdef FEAT_SYN_HL
10270 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10271 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010272 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010273#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274#ifdef FEAT_DIFF
10275 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10276#endif
10277#ifdef FEAT_FOLDING
10278 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10279 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10280 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10281 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10282 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10283 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10284 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10285# ifdef FEAT_EVAL
10286 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10287 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10288# endif
10289 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10290#endif
10291 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010292 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010293#ifdef FEAT_LINEBREAK
10294 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10295#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010296#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10298#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010299#ifdef FEAT_VERTSPLIT
10300 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10301#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10303 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10304#endif
10305#ifdef FEAT_RIGHTLEFT
10306 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10307 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10308#endif
10309 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10310 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10311#ifdef FEAT_LINEBREAK
10312 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010313 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10314 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315#endif
10316#ifdef FEAT_SCROLLBIND
10317 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10318#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010319#ifdef FEAT_CURSORBIND
10320 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10321#endif
10322#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010323 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10324 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326
10327 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10328 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10329#ifdef FEAT_MBYTE
10330 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10331#endif
10332#if defined(FEAT_QUICKFIX)
10333 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10334 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10335#endif
10336 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10337 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10338#ifdef FEAT_CINDENT
10339 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10340 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10341 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10342#endif
10343#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10344 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10345#endif
10346#ifdef FEAT_COMMENTS
10347 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10348#endif
10349#ifdef FEAT_FOLDING
10350 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10351#endif
10352#ifdef FEAT_INS_EXPAND
10353 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10354#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010355#ifdef FEAT_COMPL_FUNC
10356 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010357 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010359 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010360 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010361 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10362#ifdef FEAT_MBYTE
10363 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10364#endif
10365 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10366#ifdef FEAT_AUTOCMD
10367 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10368#endif
10369 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010370 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10372 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10373 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10374 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10375#ifdef FEAT_FIND_ID
10376# ifdef FEAT_EVAL
10377 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10378# endif
10379#endif
10380#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10381 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10382 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10383#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010384#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010385 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387#ifdef FEAT_CRYPT
10388 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10389#endif
10390#ifdef FEAT_LISP
10391 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10392#endif
10393 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10394 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10395 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10396 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10397 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010399#ifdef FEAT_TEXTOBJ
10400 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10401#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10403#ifdef FEAT_SMARTINDENT
10404 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10405#endif
10406#ifndef SHORT_FNAME
10407 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10408#endif
10409 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10410#ifdef FEAT_SEARCHPATH
10411 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10412#endif
10413 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10414#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010415 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010416 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10417#endif
10418#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010419 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10420 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10421 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010422#endif
10423 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10424 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10425 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10426 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010427#ifdef FEAT_PERSISTENT_UNDO
10428 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010430 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10431#ifdef FEAT_KEYMAP
10432 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10433#endif
10434 default: EMSG(_("E356: get_varp ERROR"));
10435 }
10436 /* always return a valid pointer to avoid a crash! */
10437 return (char_u *)&(curbuf->b_p_wm);
10438}
10439
10440/*
10441 * Get the value of 'equalprg', either the buffer-local one or the global one.
10442 */
10443 char_u *
10444get_equalprg()
10445{
10446 if (*curbuf->b_p_ep == NUL)
10447 return p_ep;
10448 return curbuf->b_p_ep;
10449}
10450
10451#if defined(FEAT_WINDOWS) || defined(PROTO)
10452/*
10453 * Copy options from one window to another.
10454 * Used when splitting a window.
10455 */
10456 void
10457win_copy_options(wp_from, wp_to)
10458 win_T *wp_from;
10459 win_T *wp_to;
10460{
10461 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10462 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10463# ifdef FEAT_RIGHTLEFT
10464# ifdef FEAT_FKMAP
10465 /* Is this right? */
10466 wp_to->w_farsi = wp_from->w_farsi;
10467# endif
10468# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010469#if defined(FEAT_LINEBREAK)
10470 briopt_check(wp_to);
10471#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472}
10473#endif
10474
10475/*
10476 * Copy the options from one winopt_T to another.
10477 * Doesn't free the old option values in "to", use clear_winopt() for that.
10478 * The 'scroll' option is not copied, because it depends on the window height.
10479 * The 'previewwindow' option is reset, there can be only one preview window.
10480 */
10481 void
10482copy_winopt(from, to)
10483 winopt_T *from;
10484 winopt_T *to;
10485{
10486#ifdef FEAT_ARABIC
10487 to->wo_arab = from->wo_arab;
10488#endif
10489 to->wo_list = from->wo_list;
10490 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010491 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010492#ifdef FEAT_LINEBREAK
10493 to->wo_nuw = from->wo_nuw;
10494#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010495#ifdef FEAT_RIGHTLEFT
10496 to->wo_rl = from->wo_rl;
10497 to->wo_rlc = vim_strsave(from->wo_rlc);
10498#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010499#ifdef FEAT_STL_OPT
10500 to->wo_stl = vim_strsave(from->wo_stl);
10501#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010503#ifdef FEAT_DIFF
10504 to->wo_wrap_save = from->wo_wrap_save;
10505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010506#ifdef FEAT_LINEBREAK
10507 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010508 to->wo_bri = from->wo_bri;
10509 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510#endif
10511#ifdef FEAT_SCROLLBIND
10512 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010513 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010514#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010515#ifdef FEAT_CURSORBIND
10516 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010517 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010518#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010519#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010520 to->wo_spell = from->wo_spell;
10521#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010522#ifdef FEAT_SYN_HL
10523 to->wo_cuc = from->wo_cuc;
10524 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010525 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010526#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527#ifdef FEAT_DIFF
10528 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010529 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010531#ifdef FEAT_CONCEAL
10532 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010533 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535#ifdef FEAT_FOLDING
10536 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010537 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010539 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540 to->wo_fdi = vim_strsave(from->wo_fdi);
10541 to->wo_fml = from->wo_fml;
10542 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010543 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010545 to->wo_fdm_save = from->wo_diff_saved
10546 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547 to->wo_fdn = from->wo_fdn;
10548# ifdef FEAT_EVAL
10549 to->wo_fde = vim_strsave(from->wo_fde);
10550 to->wo_fdt = vim_strsave(from->wo_fdt);
10551# endif
10552 to->wo_fmr = vim_strsave(from->wo_fmr);
10553#endif
10554 check_winopt(to); /* don't want NULL pointers */
10555}
10556
10557/*
10558 * Check string options in a window for a NULL value.
10559 */
10560 void
10561check_win_options(win)
10562 win_T *win;
10563{
10564 check_winopt(&win->w_onebuf_opt);
10565 check_winopt(&win->w_allbuf_opt);
10566}
10567
10568/*
10569 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10570 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010571 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010573 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574{
10575#ifdef FEAT_FOLDING
10576 check_string_option(&wop->wo_fdi);
10577 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010578 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579# ifdef FEAT_EVAL
10580 check_string_option(&wop->wo_fde);
10581 check_string_option(&wop->wo_fdt);
10582# endif
10583 check_string_option(&wop->wo_fmr);
10584#endif
10585#ifdef FEAT_RIGHTLEFT
10586 check_string_option(&wop->wo_rlc);
10587#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010588#ifdef FEAT_STL_OPT
10589 check_string_option(&wop->wo_stl);
10590#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010591#ifdef FEAT_SYN_HL
10592 check_string_option(&wop->wo_cc);
10593#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010594#ifdef FEAT_CONCEAL
10595 check_string_option(&wop->wo_cocu);
10596#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010597#ifdef FEAT_LINEBREAK
10598 check_string_option(&wop->wo_briopt);
10599#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600}
10601
10602/*
10603 * Free the allocated memory inside a winopt_T.
10604 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605 void
10606clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010607 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608{
10609#ifdef FEAT_FOLDING
10610 clear_string_option(&wop->wo_fdi);
10611 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010612 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613# ifdef FEAT_EVAL
10614 clear_string_option(&wop->wo_fde);
10615 clear_string_option(&wop->wo_fdt);
10616# endif
10617 clear_string_option(&wop->wo_fmr);
10618#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010619#ifdef FEAT_LINEBREAK
10620 clear_string_option(&wop->wo_briopt);
10621#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010622#ifdef FEAT_RIGHTLEFT
10623 clear_string_option(&wop->wo_rlc);
10624#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010625#ifdef FEAT_STL_OPT
10626 clear_string_option(&wop->wo_stl);
10627#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010628#ifdef FEAT_SYN_HL
10629 clear_string_option(&wop->wo_cc);
10630#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010631#ifdef FEAT_CONCEAL
10632 clear_string_option(&wop->wo_cocu);
10633#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634}
10635
10636/*
10637 * Copy global option values to local options for one buffer.
10638 * Used when creating a new buffer and sometimes when entering a buffer.
10639 * flags:
10640 * BCO_ENTER We will enter the buf buffer.
10641 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10642 * appropriate.
10643 * BCO_NOHELP Don't copy the values to a help buffer.
10644 */
10645 void
10646buf_copy_options(buf, flags)
10647 buf_T *buf;
10648 int flags;
10649{
10650 int should_copy = TRUE;
10651 char_u *save_p_isk = NULL; /* init for GCC */
10652 int dont_do_help;
10653 int did_isk = FALSE;
10654
10655 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010656 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657 */
10658 if (buf == NULL || !buf_valid(buf))
10659 return;
10660
10661 /*
10662 * Skip this when the option defaults have not been set yet. Happens when
10663 * main() allocates the first buffer.
10664 */
10665 if (p_cpo != NULL)
10666 {
10667 /*
10668 * Always copy when entering and 'cpo' contains 'S'.
10669 * Don't copy when already initialized.
10670 * Don't copy when 'cpo' contains 's' and not entering.
10671 * 'S' BCO_ENTER initialized 's' should_copy
10672 * yes yes X X TRUE
10673 * yes no yes X FALSE
10674 * no X yes X FALSE
10675 * X no no yes FALSE
10676 * X no no no TRUE
10677 * no yes no X TRUE
10678 */
10679 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10680 && (buf->b_p_initialized
10681 || (!(flags & BCO_ENTER)
10682 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10683 should_copy = FALSE;
10684
10685 if (should_copy || (flags & BCO_ALWAYS))
10686 {
10687 /* Don't copy the options specific to a help buffer when
10688 * BCO_NOHELP is given or the options were initialized already
10689 * (jumping back to a help file with CTRL-T or CTRL-O) */
10690 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10691 || buf->b_p_initialized;
10692 if (dont_do_help) /* don't free b_p_isk */
10693 {
10694 save_p_isk = buf->b_p_isk;
10695 buf->b_p_isk = NULL;
10696 }
10697 /*
10698 * Always free the allocated strings.
10699 * If not already initialized, set 'readonly' and copy 'fileformat'.
10700 */
10701 if (!buf->b_p_initialized)
10702 {
10703 free_buf_options(buf, TRUE);
10704 buf->b_p_ro = FALSE; /* don't copy readonly */
10705 buf->b_p_tx = p_tx;
10706#ifdef FEAT_MBYTE
10707 buf->b_p_fenc = vim_strsave(p_fenc);
10708#endif
10709 buf->b_p_ff = vim_strsave(p_ff);
10710#if defined(FEAT_QUICKFIX)
10711 buf->b_p_bh = empty_option;
10712 buf->b_p_bt = empty_option;
10713#endif
10714 }
10715 else
10716 free_buf_options(buf, FALSE);
10717
10718 buf->b_p_ai = p_ai;
10719 buf->b_p_ai_nopaste = p_ai_nopaste;
10720 buf->b_p_sw = p_sw;
10721 buf->b_p_tw = p_tw;
10722 buf->b_p_tw_nopaste = p_tw_nopaste;
10723 buf->b_p_tw_nobin = p_tw_nobin;
10724 buf->b_p_wm = p_wm;
10725 buf->b_p_wm_nopaste = p_wm_nopaste;
10726 buf->b_p_wm_nobin = p_wm_nobin;
10727 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010728#ifdef FEAT_MBYTE
10729 buf->b_p_bomb = p_bomb;
10730#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010731 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732 buf->b_p_et = p_et;
10733 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010734 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 buf->b_p_ml = p_ml;
10736 buf->b_p_ml_nobin = p_ml_nobin;
10737 buf->b_p_inf = p_inf;
10738 buf->b_p_swf = p_swf;
10739#ifdef FEAT_INS_EXPAND
10740 buf->b_p_cpt = vim_strsave(p_cpt);
10741#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010742#ifdef FEAT_COMPL_FUNC
10743 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010744 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746 buf->b_p_sts = p_sts;
10747 buf->b_p_sts_nopaste = p_sts_nopaste;
10748#ifndef SHORT_FNAME
10749 buf->b_p_sn = p_sn;
10750#endif
10751#ifdef FEAT_COMMENTS
10752 buf->b_p_com = vim_strsave(p_com);
10753#endif
10754#ifdef FEAT_FOLDING
10755 buf->b_p_cms = vim_strsave(p_cms);
10756#endif
10757 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010758 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759 buf->b_p_nf = vim_strsave(p_nf);
10760 buf->b_p_mps = vim_strsave(p_mps);
10761#ifdef FEAT_SMARTINDENT
10762 buf->b_p_si = p_si;
10763#endif
10764 buf->b_p_ci = p_ci;
10765#ifdef FEAT_CINDENT
10766 buf->b_p_cin = p_cin;
10767 buf->b_p_cink = vim_strsave(p_cink);
10768 buf->b_p_cino = vim_strsave(p_cino);
10769#endif
10770#ifdef FEAT_AUTOCMD
10771 /* Don't copy 'filetype', it must be detected */
10772 buf->b_p_ft = empty_option;
10773#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 buf->b_p_pi = p_pi;
10775#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10776 buf->b_p_cinw = vim_strsave(p_cinw);
10777#endif
10778#ifdef FEAT_LISP
10779 buf->b_p_lisp = p_lisp;
10780#endif
10781#ifdef FEAT_SYN_HL
10782 /* Don't copy 'syntax', it must be set */
10783 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010784 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010785#endif
10786#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010787 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010788 (void)compile_cap_prog(&buf->b_s);
10789 buf->b_s.b_p_spf = vim_strsave(p_spf);
10790 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010791#endif
10792#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10793 buf->b_p_inde = vim_strsave(p_inde);
10794 buf->b_p_indk = vim_strsave(p_indk);
10795#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010796#if defined(FEAT_EVAL)
10797 buf->b_p_fex = vim_strsave(p_fex);
10798#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799#ifdef FEAT_CRYPT
10800 buf->b_p_key = vim_strsave(p_key);
10801#endif
10802#ifdef FEAT_SEARCHPATH
10803 buf->b_p_sua = vim_strsave(p_sua);
10804#endif
10805#ifdef FEAT_KEYMAP
10806 buf->b_p_keymap = vim_strsave(p_keymap);
10807 buf->b_kmap_state |= KEYMAP_INIT;
10808#endif
10809 /* This isn't really an option, but copying the langmap and IME
10810 * state from the current buffer is better than resetting it. */
10811 buf->b_p_iminsert = p_iminsert;
10812 buf->b_p_imsearch = p_imsearch;
10813
10814 /* options that are normally global but also have a local value
10815 * are not copied, start using the global value */
10816 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010817 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010818 buf->b_p_bkc = empty_option;
10819 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820#ifdef FEAT_QUICKFIX
10821 buf->b_p_gp = empty_option;
10822 buf->b_p_mp = empty_option;
10823 buf->b_p_efm = empty_option;
10824#endif
10825 buf->b_p_ep = empty_option;
10826 buf->b_p_kp = empty_option;
10827 buf->b_p_path = empty_option;
10828 buf->b_p_tags = empty_option;
10829#ifdef FEAT_FIND_ID
10830 buf->b_p_def = empty_option;
10831 buf->b_p_inc = empty_option;
10832# ifdef FEAT_EVAL
10833 buf->b_p_inex = vim_strsave(p_inex);
10834# endif
10835#endif
10836#ifdef FEAT_INS_EXPAND
10837 buf->b_p_dict = empty_option;
10838 buf->b_p_tsr = empty_option;
10839#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010840#ifdef FEAT_TEXTOBJ
10841 buf->b_p_qe = vim_strsave(p_qe);
10842#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010843#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10844 buf->b_p_bexpr = empty_option;
10845#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010846#if defined(FEAT_CRYPT)
10847 buf->b_p_cm = empty_option;
10848#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010849#ifdef FEAT_PERSISTENT_UNDO
10850 buf->b_p_udf = p_udf;
10851#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010852#ifdef FEAT_LISP
10853 buf->b_p_lw = empty_option;
10854#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855
10856 /*
10857 * Don't copy the options set by ex_help(), use the saved values,
10858 * when going from a help buffer to a non-help buffer.
10859 * Don't touch these at all when BCO_NOHELP is used and going from
10860 * or to a help buffer.
10861 */
10862 if (dont_do_help)
10863 buf->b_p_isk = save_p_isk;
10864 else
10865 {
10866 buf->b_p_isk = vim_strsave(p_isk);
10867 did_isk = TRUE;
10868 buf->b_p_ts = p_ts;
10869 buf->b_help = FALSE;
10870#ifdef FEAT_QUICKFIX
10871 if (buf->b_p_bt[0] == 'h')
10872 clear_string_option(&buf->b_p_bt);
10873#endif
10874 buf->b_p_ma = p_ma;
10875 }
10876 }
10877
10878 /*
10879 * When the options should be copied (ignoring BCO_ALWAYS), set the
10880 * flag that indicates that the options have been initialized.
10881 */
10882 if (should_copy)
10883 buf->b_p_initialized = TRUE;
10884 }
10885
10886 check_buf_options(buf); /* make sure we don't have NULLs */
10887 if (did_isk)
10888 (void)buf_init_chartab(buf, FALSE);
10889}
10890
10891/*
10892 * Reset the 'modifiable' option and its default value.
10893 */
10894 void
10895reset_modifiable()
10896{
10897 int opt_idx;
10898
10899 curbuf->b_p_ma = FALSE;
10900 p_ma = FALSE;
10901 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010902 if (opt_idx >= 0)
10903 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904}
10905
10906/*
10907 * Set the global value for 'iminsert' to the local value.
10908 */
10909 void
10910set_iminsert_global()
10911{
10912 p_iminsert = curbuf->b_p_iminsert;
10913}
10914
10915/*
10916 * Set the global value for 'imsearch' to the local value.
10917 */
10918 void
10919set_imsearch_global()
10920{
10921 p_imsearch = curbuf->b_p_imsearch;
10922}
10923
10924#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10925static int expand_option_idx = -1;
10926static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10927static int expand_option_flags = 0;
10928
10929 void
10930set_context_in_set_cmd(xp, arg, opt_flags)
10931 expand_T *xp;
10932 char_u *arg;
10933 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10934{
10935 int nextchar;
10936 long_u flags = 0; /* init for GCC */
10937 int opt_idx = 0; /* init for GCC */
10938 char_u *p;
10939 char_u *s;
10940 int is_term_option = FALSE;
10941 int key;
10942
10943 expand_option_flags = opt_flags;
10944
10945 xp->xp_context = EXPAND_SETTINGS;
10946 if (*arg == NUL)
10947 {
10948 xp->xp_pattern = arg;
10949 return;
10950 }
10951 p = arg + STRLEN(arg) - 1;
10952 if (*p == ' ' && *(p - 1) != '\\')
10953 {
10954 xp->xp_pattern = p + 1;
10955 return;
10956 }
10957 while (p > arg)
10958 {
10959 s = p;
10960 /* count number of backslashes before ' ' or ',' */
10961 if (*p == ' ' || *p == ',')
10962 {
10963 while (s > arg && *(s - 1) == '\\')
10964 --s;
10965 }
10966 /* break at a space with an even number of backslashes */
10967 if (*p == ' ' && ((p - s) & 1) == 0)
10968 {
10969 ++p;
10970 break;
10971 }
10972 --p;
10973 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010974 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975 {
10976 xp->xp_context = EXPAND_BOOL_SETTINGS;
10977 p += 2;
10978 }
10979 if (STRNCMP(p, "inv", 3) == 0)
10980 {
10981 xp->xp_context = EXPAND_BOOL_SETTINGS;
10982 p += 3;
10983 }
10984 xp->xp_pattern = arg = p;
10985 if (*arg == '<')
10986 {
10987 while (*p != '>')
10988 if (*p++ == NUL) /* expand terminal option name */
10989 return;
10990 key = get_special_key_code(arg + 1);
10991 if (key == 0) /* unknown name */
10992 {
10993 xp->xp_context = EXPAND_NOTHING;
10994 return;
10995 }
10996 nextchar = *++p;
10997 is_term_option = TRUE;
10998 expand_option_name[2] = KEY2TERMCAP0(key);
10999 expand_option_name[3] = KEY2TERMCAP1(key);
11000 }
11001 else
11002 {
11003 if (p[0] == 't' && p[1] == '_')
11004 {
11005 p += 2;
11006 if (*p != NUL)
11007 ++p;
11008 if (*p == NUL)
11009 return; /* expand option name */
11010 nextchar = *++p;
11011 is_term_option = TRUE;
11012 expand_option_name[2] = p[-2];
11013 expand_option_name[3] = p[-1];
11014 }
11015 else
11016 {
11017 /* Allow * wildcard */
11018 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11019 p++;
11020 if (*p == NUL)
11021 return;
11022 nextchar = *p;
11023 *p = NUL;
11024 opt_idx = findoption(arg);
11025 *p = nextchar;
11026 if (opt_idx == -1 || options[opt_idx].var == NULL)
11027 {
11028 xp->xp_context = EXPAND_NOTHING;
11029 return;
11030 }
11031 flags = options[opt_idx].flags;
11032 if (flags & P_BOOL)
11033 {
11034 xp->xp_context = EXPAND_NOTHING;
11035 return;
11036 }
11037 }
11038 }
11039 /* handle "-=" and "+=" */
11040 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11041 {
11042 ++p;
11043 nextchar = '=';
11044 }
11045 if ((nextchar != '=' && nextchar != ':')
11046 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11047 {
11048 xp->xp_context = EXPAND_UNSUCCESSFUL;
11049 return;
11050 }
11051 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11052 {
11053 xp->xp_context = EXPAND_OLD_SETTING;
11054 if (is_term_option)
11055 expand_option_idx = -1;
11056 else
11057 expand_option_idx = opt_idx;
11058 xp->xp_pattern = p + 1;
11059 return;
11060 }
11061 xp->xp_context = EXPAND_NOTHING;
11062 if (is_term_option || (flags & P_NUM))
11063 return;
11064
11065 xp->xp_pattern = p + 1;
11066
11067 if (flags & P_EXPAND)
11068 {
11069 p = options[opt_idx].var;
11070 if (p == (char_u *)&p_bdir
11071 || p == (char_u *)&p_dir
11072 || p == (char_u *)&p_path
11073 || p == (char_u *)&p_rtp
11074#ifdef FEAT_SEARCHPATH
11075 || p == (char_u *)&p_cdpath
11076#endif
11077#ifdef FEAT_SESSION
11078 || p == (char_u *)&p_vdir
11079#endif
11080 )
11081 {
11082 xp->xp_context = EXPAND_DIRECTORIES;
11083 if (p == (char_u *)&p_path
11084#ifdef FEAT_SEARCHPATH
11085 || p == (char_u *)&p_cdpath
11086#endif
11087 )
11088 xp->xp_backslash = XP_BS_THREE;
11089 else
11090 xp->xp_backslash = XP_BS_ONE;
11091 }
11092 else
11093 {
11094 xp->xp_context = EXPAND_FILES;
11095 /* for 'tags' need three backslashes for a space */
11096 if (p == (char_u *)&p_tags)
11097 xp->xp_backslash = XP_BS_THREE;
11098 else
11099 xp->xp_backslash = XP_BS_ONE;
11100 }
11101 }
11102
11103 /* For an option that is a list of file names, find the start of the
11104 * last file name. */
11105 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11106 {
11107 /* count number of backslashes before ' ' or ',' */
11108 if (*p == ' ' || *p == ',')
11109 {
11110 s = p;
11111 while (s > xp->xp_pattern && *(s - 1) == '\\')
11112 --s;
11113 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11114 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11115 {
11116 xp->xp_pattern = p + 1;
11117 break;
11118 }
11119 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011120
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011121#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011122 /* for 'spellsuggest' start at "file:" */
11123 if (options[opt_idx].var == (char_u *)&p_sps
11124 && STRNCMP(p, "file:", 5) == 0)
11125 {
11126 xp->xp_pattern = p + 5;
11127 break;
11128 }
11129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011130 }
11131
11132 return;
11133}
11134
11135 int
11136ExpandSettings(xp, regmatch, num_file, file)
11137 expand_T *xp;
11138 regmatch_T *regmatch;
11139 int *num_file;
11140 char_u ***file;
11141{
11142 int num_normal = 0; /* Nr of matching non-term-code settings */
11143 int num_term = 0; /* Nr of matching terminal code settings */
11144 int opt_idx;
11145 int match;
11146 int count = 0;
11147 char_u *str;
11148 int loop;
11149 int is_term_opt;
11150 char_u name_buf[MAX_KEY_NAME_LEN];
11151 static char *(names[]) = {"all", "termcap"};
11152 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11153
11154 /* do this loop twice:
11155 * loop == 0: count the number of matching options
11156 * loop == 1: copy the matching options into allocated memory
11157 */
11158 for (loop = 0; loop <= 1; ++loop)
11159 {
11160 regmatch->rm_ic = ic;
11161 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11162 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011163 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11164 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011165 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11166 {
11167 if (loop == 0)
11168 num_normal++;
11169 else
11170 (*file)[count++] = vim_strsave((char_u *)names[match]);
11171 }
11172 }
11173 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11174 opt_idx++)
11175 {
11176 if (options[opt_idx].var == NULL)
11177 continue;
11178 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11179 && !(options[opt_idx].flags & P_BOOL))
11180 continue;
11181 is_term_opt = istermoption(&options[opt_idx]);
11182 if (is_term_opt && num_normal > 0)
11183 continue;
11184 match = FALSE;
11185 if (vim_regexec(regmatch, str, (colnr_T)0)
11186 || (options[opt_idx].shortname != NULL
11187 && vim_regexec(regmatch,
11188 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11189 match = TRUE;
11190 else if (is_term_opt)
11191 {
11192 name_buf[0] = '<';
11193 name_buf[1] = 't';
11194 name_buf[2] = '_';
11195 name_buf[3] = str[2];
11196 name_buf[4] = str[3];
11197 name_buf[5] = '>';
11198 name_buf[6] = NUL;
11199 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11200 {
11201 match = TRUE;
11202 str = name_buf;
11203 }
11204 }
11205 if (match)
11206 {
11207 if (loop == 0)
11208 {
11209 if (is_term_opt)
11210 num_term++;
11211 else
11212 num_normal++;
11213 }
11214 else
11215 (*file)[count++] = vim_strsave(str);
11216 }
11217 }
11218 /*
11219 * Check terminal key codes, these are not in the option table
11220 */
11221 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11222 {
11223 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11224 {
11225 if (!isprint(str[0]) || !isprint(str[1]))
11226 continue;
11227
11228 name_buf[0] = 't';
11229 name_buf[1] = '_';
11230 name_buf[2] = str[0];
11231 name_buf[3] = str[1];
11232 name_buf[4] = NUL;
11233
11234 match = FALSE;
11235 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11236 match = TRUE;
11237 else
11238 {
11239 name_buf[0] = '<';
11240 name_buf[1] = 't';
11241 name_buf[2] = '_';
11242 name_buf[3] = str[0];
11243 name_buf[4] = str[1];
11244 name_buf[5] = '>';
11245 name_buf[6] = NUL;
11246
11247 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11248 match = TRUE;
11249 }
11250 if (match)
11251 {
11252 if (loop == 0)
11253 num_term++;
11254 else
11255 (*file)[count++] = vim_strsave(name_buf);
11256 }
11257 }
11258
11259 /*
11260 * Check special key names.
11261 */
11262 regmatch->rm_ic = TRUE; /* ignore case here */
11263 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11264 {
11265 name_buf[0] = '<';
11266 STRCPY(name_buf + 1, str);
11267 STRCAT(name_buf, ">");
11268
11269 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11270 {
11271 if (loop == 0)
11272 num_term++;
11273 else
11274 (*file)[count++] = vim_strsave(name_buf);
11275 }
11276 }
11277 }
11278 if (loop == 0)
11279 {
11280 if (num_normal > 0)
11281 *num_file = num_normal;
11282 else if (num_term > 0)
11283 *num_file = num_term;
11284 else
11285 return OK;
11286 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11287 if (*file == NULL)
11288 {
11289 *file = (char_u **)"";
11290 return FAIL;
11291 }
11292 }
11293 }
11294 return OK;
11295}
11296
11297 int
11298ExpandOldSetting(num_file, file)
11299 int *num_file;
11300 char_u ***file;
11301{
11302 char_u *var = NULL; /* init for GCC */
11303 char_u *buf;
11304
11305 *num_file = 0;
11306 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11307 if (*file == NULL)
11308 return FAIL;
11309
11310 /*
11311 * For a terminal key code expand_option_idx is < 0.
11312 */
11313 if (expand_option_idx < 0)
11314 {
11315 var = find_termcode(expand_option_name + 2);
11316 if (var == NULL)
11317 expand_option_idx = findoption(expand_option_name);
11318 }
11319
11320 if (expand_option_idx >= 0)
11321 {
11322 /* put string of option value in NameBuff */
11323 option_value2string(&options[expand_option_idx], expand_option_flags);
11324 var = NameBuff;
11325 }
11326 else if (var == NULL)
11327 var = (char_u *)"";
11328
11329 /* A backslash is required before some characters. This is the reverse of
11330 * what happens in do_set(). */
11331 buf = vim_strsave_escaped(var, escape_chars);
11332
11333 if (buf == NULL)
11334 {
11335 vim_free(*file);
11336 *file = NULL;
11337 return FAIL;
11338 }
11339
11340#ifdef BACKSLASH_IN_FILENAME
11341 /* For MS-Windows et al. we don't double backslashes at the start and
11342 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011343 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344 if (var[0] == '\\' && var[1] == '\\'
11345 && expand_option_idx >= 0
11346 && (options[expand_option_idx].flags & P_EXPAND)
11347 && vim_isfilec(var[2])
11348 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011349 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350#endif
11351
11352 *file[0] = buf;
11353 *num_file = 1;
11354 return OK;
11355}
11356#endif
11357
11358/*
11359 * Get the value for the numeric or string option *opp in a nice format into
11360 * NameBuff[]. Must not be called with a hidden option!
11361 */
11362 static void
11363option_value2string(opp, opt_flags)
11364 struct vimoption *opp;
11365 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11366{
11367 char_u *varp;
11368
11369 varp = get_varp_scope(opp, opt_flags);
11370
11371 if (opp->flags & P_NUM)
11372 {
11373 long wc = 0;
11374
11375 if (wc_use_keyname(varp, &wc))
11376 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11377 else if (wc != 0)
11378 STRCPY(NameBuff, transchar((int)wc));
11379 else
11380 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11381 }
11382 else /* P_STRING */
11383 {
11384 varp = *(char_u **)(varp);
11385 if (varp == NULL) /* just in case */
11386 NameBuff[0] = NUL;
11387#ifdef FEAT_CRYPT
11388 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011389 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011390 STRCPY(NameBuff, "*****");
11391#endif
11392 else if (opp->flags & P_EXPAND)
11393 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11394 /* Translate 'pastetoggle' into special key names */
11395 else if ((char_u **)opp->var == &p_pt)
11396 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11397 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011398 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011399 }
11400}
11401
11402/*
11403 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11404 * printed as a keyname.
11405 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11406 */
11407 static int
11408wc_use_keyname(varp, wcp)
11409 char_u *varp;
11410 long *wcp;
11411{
11412 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11413 {
11414 *wcp = *(long *)varp;
11415 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11416 return TRUE;
11417 }
11418 return FALSE;
11419}
11420
Bram Moolenaar01615492015-02-03 13:00:38 +010011421#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011422/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011423 * Any character has an equivalent 'langmap' character. This is used for
11424 * keyboards that have a special language mode that sends characters above
11425 * 128 (although other characters can be translated too). The "to" field is a
11426 * Vim command character. This avoids having to switch the keyboard back to
11427 * ASCII mode when leaving Insert mode.
11428 *
11429 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11430 * commands.
11431 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11432 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11433 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011434 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011435# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011436/*
11437 * With multi-byte support use growarray for 'langmap' chars >= 256
11438 */
11439typedef struct
11440{
11441 int from;
11442 int to;
11443} langmap_entry_T;
11444
11445static garray_T langmap_mapga;
11446static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011447
11448/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011449 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11450 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011451 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011452 static void
11453langmap_set_entry(from, to)
11454 int from;
11455 int to;
11456{
11457 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011458 int a = 0;
11459 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011460
11461 /* Do a binary search for an existing entry. */
11462 while (a != b)
11463 {
11464 int i = (a + b) / 2;
11465 int d = entries[i].from - from;
11466
11467 if (d == 0)
11468 {
11469 entries[i].to = to;
11470 return;
11471 }
11472 if (d < 0)
11473 a = i + 1;
11474 else
11475 b = i;
11476 }
11477
11478 if (ga_grow(&langmap_mapga, 1) != OK)
11479 return; /* out of memory */
11480
11481 /* insert new entry at position "a" */
11482 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11483 mch_memmove(entries + 1, entries,
11484 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11485 ++langmap_mapga.ga_len;
11486 entries[0].from = from;
11487 entries[0].to = to;
11488}
11489
11490/*
11491 * Apply 'langmap' to multi-byte character "c" and return the result.
11492 */
11493 int
11494langmap_adjust_mb(c)
11495 int c;
11496{
11497 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11498 int a = 0;
11499 int b = langmap_mapga.ga_len;
11500
11501 while (a != b)
11502 {
11503 int i = (a + b) / 2;
11504 int d = entries[i].from - c;
11505
11506 if (d == 0)
11507 return entries[i].to; /* found matching entry */
11508 if (d < 0)
11509 a = i + 1;
11510 else
11511 b = i;
11512 }
11513 return c; /* no entry found, return "c" unmodified */
11514}
11515# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011516
11517 static void
11518langmap_init()
11519{
11520 int i;
11521
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011522 for (i = 0; i < 256; i++)
11523 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11524# ifdef FEAT_MBYTE
11525 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11526# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011527}
11528
11529/*
11530 * Called when langmap option is set; the language map can be
11531 * changed at any time!
11532 */
11533 static void
11534langmap_set()
11535{
11536 char_u *p;
11537 char_u *p2;
11538 int from, to;
11539
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011540#ifdef FEAT_MBYTE
11541 ga_clear(&langmap_mapga); /* clear the previous map first */
11542#endif
11543 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011544
11545 for (p = p_langmap; p[0] != NUL; )
11546 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011547 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11548 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011549 {
11550 if (p2[0] == '\\' && p2[1] != NUL)
11551 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011552 }
11553 if (p2[0] == ';')
11554 ++p2; /* abcd;ABCD form, p2 points to A */
11555 else
11556 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11557 while (p[0])
11558 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011559 if (p[0] == ',')
11560 {
11561 ++p;
11562 break;
11563 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011564 if (p[0] == '\\' && p[1] != NUL)
11565 ++p;
11566#ifdef FEAT_MBYTE
11567 from = (*mb_ptr2char)(p);
11568#else
11569 from = p[0];
11570#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011571 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011572 if (p2 == NULL)
11573 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011574 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011575 if (p[0] != ',')
11576 {
11577 if (p[0] == '\\')
11578 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011579#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011580 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011581#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011582 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011583#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011584 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011585 }
11586 else
11587 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011588 if (p2[0] != ',')
11589 {
11590 if (p2[0] == '\\')
11591 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011592#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011593 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011594#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011595 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011596#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011597 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011598 }
11599 if (to == NUL)
11600 {
11601 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11602 transchar(from));
11603 return;
11604 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011605
11606#ifdef FEAT_MBYTE
11607 if (from >= 256)
11608 langmap_set_entry(from, to);
11609 else
11610#endif
11611 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612
11613 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011614 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011615 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011617 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011618 if (*p == ';')
11619 {
11620 p = p2;
11621 if (p[0] != NUL)
11622 {
11623 if (p[0] != ',')
11624 {
11625 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11626 return;
11627 }
11628 ++p;
11629 }
11630 break;
11631 }
11632 }
11633 }
11634 }
11635}
11636#endif
11637
11638/*
11639 * Return TRUE if format option 'x' is in effect.
11640 * Take care of no formatting when 'paste' is set.
11641 */
11642 int
11643has_format_option(x)
11644 int x;
11645{
11646 if (p_paste)
11647 return FALSE;
11648 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11649}
11650
11651/*
11652 * Return TRUE if "x" is present in 'shortmess' option, or
11653 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11654 */
11655 int
11656shortmess(x)
11657 int x;
11658{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011659 return p_shm != NULL &&
11660 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011661 || (vim_strchr(p_shm, 'a') != NULL
11662 && vim_strchr((char_u *)SHM_A, x) != NULL));
11663}
11664
11665/*
11666 * paste_option_changed() - Called after p_paste was set or reset.
11667 */
11668 static void
11669paste_option_changed()
11670{
11671 static int old_p_paste = FALSE;
11672 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011673 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011674#ifdef FEAT_CMDL_INFO
11675 static int save_ru = 0;
11676#endif
11677#ifdef FEAT_RIGHTLEFT
11678 static int save_ri = 0;
11679 static int save_hkmap = 0;
11680#endif
11681 buf_T *buf;
11682
11683 if (p_paste)
11684 {
11685 /*
11686 * Paste switched from off to on.
11687 * Save the current values, so they can be restored later.
11688 */
11689 if (!old_p_paste)
11690 {
11691 /* save options for each buffer */
11692 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11693 {
11694 buf->b_p_tw_nopaste = buf->b_p_tw;
11695 buf->b_p_wm_nopaste = buf->b_p_wm;
11696 buf->b_p_sts_nopaste = buf->b_p_sts;
11697 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011698 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011699 }
11700
11701 /* save global options */
11702 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011703 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011704#ifdef FEAT_CMDL_INFO
11705 save_ru = p_ru;
11706#endif
11707#ifdef FEAT_RIGHTLEFT
11708 save_ri = p_ri;
11709 save_hkmap = p_hkmap;
11710#endif
11711 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011712 p_ai_nopaste = p_ai;
11713 p_et_nopaste = p_et;
11714 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011715 p_tw_nopaste = p_tw;
11716 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011717 }
11718
11719 /*
11720 * Always set the option values, also when 'paste' is set when it is
11721 * already on.
11722 */
11723 /* set options for each buffer */
11724 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11725 {
11726 buf->b_p_tw = 0; /* textwidth is 0 */
11727 buf->b_p_wm = 0; /* wrapmargin is 0 */
11728 buf->b_p_sts = 0; /* softtabstop is 0 */
11729 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011730 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731 }
11732
11733 /* set global options */
11734 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011735 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011736#ifdef FEAT_CMDL_INFO
11737# ifdef FEAT_WINDOWS
11738 if (p_ru)
11739 status_redraw_all(); /* redraw to remove the ruler */
11740# endif
11741 p_ru = 0; /* no ruler */
11742#endif
11743#ifdef FEAT_RIGHTLEFT
11744 p_ri = 0; /* no reverse insert */
11745 p_hkmap = 0; /* no Hebrew keyboard */
11746#endif
11747 /* set global values for local buffer options */
11748 p_tw = 0;
11749 p_wm = 0;
11750 p_sts = 0;
11751 p_ai = 0;
11752 }
11753
11754 /*
11755 * Paste switched from on to off: Restore saved values.
11756 */
11757 else if (old_p_paste)
11758 {
11759 /* restore options for each buffer */
11760 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11761 {
11762 buf->b_p_tw = buf->b_p_tw_nopaste;
11763 buf->b_p_wm = buf->b_p_wm_nopaste;
11764 buf->b_p_sts = buf->b_p_sts_nopaste;
11765 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011766 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767 }
11768
11769 /* restore global options */
11770 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011771 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011772#ifdef FEAT_CMDL_INFO
11773# ifdef FEAT_WINDOWS
11774 if (p_ru != save_ru)
11775 status_redraw_all(); /* redraw to draw the ruler */
11776# endif
11777 p_ru = save_ru;
11778#endif
11779#ifdef FEAT_RIGHTLEFT
11780 p_ri = save_ri;
11781 p_hkmap = save_hkmap;
11782#endif
11783 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011784 p_ai = p_ai_nopaste;
11785 p_et = p_et_nopaste;
11786 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011787 p_tw = p_tw_nopaste;
11788 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011789 }
11790
11791 old_p_paste = p_paste;
11792}
11793
11794/*
11795 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11796 *
11797 * Reset 'compatible' and set the values for options that didn't get set yet
11798 * to the Vim defaults.
11799 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011800 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011801 */
11802 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011803vimrc_found(fname, envname)
11804 char_u *fname;
11805 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011806{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011807 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011808 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011809 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011810
11811 if (!option_was_set((char_u *)"cp"))
11812 {
11813 p_cp = FALSE;
11814 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11815 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11816 set_option_default(opt_idx, OPT_FREE, FALSE);
11817 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011818 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011820
11821 if (fname != NULL)
11822 {
11823 p = vim_getenv(envname, &dofree);
11824 if (p == NULL)
11825 {
11826 /* Set $MYVIMRC to the first vimrc file found. */
11827 p = FullName_save(fname, FALSE);
11828 if (p != NULL)
11829 {
11830 vim_setenv(envname, p);
11831 vim_free(p);
11832 }
11833 }
11834 else if (dofree)
11835 vim_free(p);
11836 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837}
11838
11839/*
11840 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11841 */
11842 void
11843change_compatible(on)
11844 int on;
11845{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011846 int opt_idx;
11847
Bram Moolenaar071d4272004-06-13 20:20:40 +000011848 if (p_cp != on)
11849 {
11850 p_cp = on;
11851 compatible_set();
11852 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011853 opt_idx = findoption((char_u *)"cp");
11854 if (opt_idx >= 0)
11855 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856}
11857
11858/*
11859 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011860 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011861 */
11862 int
11863option_was_set(name)
11864 char_u *name;
11865{
11866 int idx;
11867
11868 idx = findoption(name);
11869 if (idx < 0) /* unknown option */
11870 return FALSE;
11871 if (options[idx].flags & P_WAS_SET)
11872 return TRUE;
11873 return FALSE;
11874}
11875
11876/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011877 * Reset the flag indicating option "name" was set.
11878 */
11879 void
11880reset_option_was_set(name)
11881 char_u *name;
11882{
11883 int idx = findoption(name);
11884
11885 if (idx >= 0)
11886 options[idx].flags &= ~P_WAS_SET;
11887}
11888
11889/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011890 * compatible_set() - Called when 'compatible' has been set or unset.
11891 *
11892 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11893 * flag) to a Vi compatible value.
11894 * When 'compatible' is unset: Set all options that have a different default
11895 * for Vim (without the P_VI_DEF flag) to that default.
11896 */
11897 static void
11898compatible_set()
11899{
11900 int opt_idx;
11901
11902 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11903 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11904 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11905 set_option_default(opt_idx, OPT_FREE, p_cp);
11906 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011907 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011908}
11909
11910#ifdef FEAT_LINEBREAK
11911
11912# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11913 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011914 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915# endif
11916
11917/*
11918 * fill_breakat_flags() -- called when 'breakat' changes value.
11919 */
11920 static void
11921fill_breakat_flags()
11922{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011923 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011924 int i;
11925
11926 for (i = 0; i < 256; i++)
11927 breakat_flags[i] = FALSE;
11928
11929 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011930 for (p = p_breakat; *p; p++)
11931 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932}
11933
11934# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011935 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936# endif
11937
11938#endif
11939
11940/*
11941 * Check an option that can be a range of string values.
11942 *
11943 * Return OK for correct value, FAIL otherwise.
11944 * Empty is always OK.
11945 */
11946 static int
11947check_opt_strings(val, values, list)
11948 char_u *val;
11949 char **values;
11950 int list; /* when TRUE: accept a list of values */
11951{
11952 return opt_strings_flags(val, values, NULL, list);
11953}
11954
11955/*
11956 * Handle an option that can be a range of string values.
11957 * Set a flag in "*flagp" for each string present.
11958 *
11959 * Return OK for correct value, FAIL otherwise.
11960 * Empty is always OK.
11961 */
11962 static int
11963opt_strings_flags(val, values, flagp, list)
11964 char_u *val; /* new value */
11965 char **values; /* array of valid string values */
11966 unsigned *flagp;
11967 int list; /* when TRUE: accept a list of values */
11968{
11969 int i;
11970 int len;
11971 unsigned new_flags = 0;
11972
11973 while (*val)
11974 {
11975 for (i = 0; ; ++i)
11976 {
11977 if (values[i] == NULL) /* val not found in values[] */
11978 return FAIL;
11979
11980 len = (int)STRLEN(values[i]);
11981 if (STRNCMP(values[i], val, len) == 0
11982 && ((list && val[len] == ',') || val[len] == NUL))
11983 {
11984 val += len + (val[len] == ',');
11985 new_flags |= (1 << i);
11986 break; /* check next item in val list */
11987 }
11988 }
11989 }
11990 if (flagp != NULL)
11991 *flagp = new_flags;
11992
11993 return OK;
11994}
11995
11996/*
11997 * Read the 'wildmode' option, fill wim_flags[].
11998 */
11999 static int
12000check_opt_wim()
12001{
12002 char_u new_wim_flags[4];
12003 char_u *p;
12004 int i;
12005 int idx = 0;
12006
12007 for (i = 0; i < 4; ++i)
12008 new_wim_flags[i] = 0;
12009
12010 for (p = p_wim; *p; ++p)
12011 {
12012 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12013 ;
12014 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12015 return FAIL;
12016 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12017 new_wim_flags[idx] |= WIM_LONGEST;
12018 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12019 new_wim_flags[idx] |= WIM_FULL;
12020 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12021 new_wim_flags[idx] |= WIM_LIST;
12022 else
12023 return FAIL;
12024 p += i;
12025 if (*p == NUL)
12026 break;
12027 if (*p == ',')
12028 {
12029 if (idx == 3)
12030 return FAIL;
12031 ++idx;
12032 }
12033 }
12034
12035 /* fill remaining entries with last flag */
12036 while (idx < 3)
12037 {
12038 new_wim_flags[idx + 1] = new_wim_flags[idx];
12039 ++idx;
12040 }
12041
12042 /* only when there are no errors, wim_flags[] is changed */
12043 for (i = 0; i < 4; ++i)
12044 wim_flags[i] = new_wim_flags[i];
12045 return OK;
12046}
12047
12048/*
12049 * Check if backspacing over something is allowed.
12050 */
12051 int
12052can_bs(what)
12053 int what; /* BS_INDENT, BS_EOL or BS_START */
12054{
12055 switch (*p_bs)
12056 {
12057 case '2': return TRUE;
12058 case '1': return (what != BS_START);
12059 case '0': return FALSE;
12060 }
12061 return vim_strchr(p_bs, what) != NULL;
12062}
12063
12064/*
12065 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12066 * the file must be considered changed when the value is different.
12067 */
12068 void
12069save_file_ff(buf)
12070 buf_T *buf;
12071{
12072 buf->b_start_ffc = *buf->b_p_ff;
12073 buf->b_start_eol = buf->b_p_eol;
12074#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012075 buf->b_start_bomb = buf->b_p_bomb;
12076
Bram Moolenaar071d4272004-06-13 20:20:40 +000012077 /* Only use free/alloc when necessary, they take time. */
12078 if (buf->b_start_fenc == NULL
12079 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12080 {
12081 vim_free(buf->b_start_fenc);
12082 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12083 }
12084#endif
12085}
12086
12087/*
12088 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12089 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012090 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12091 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012092 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012093 * When "ignore_empty" is true don't consider a new, empty buffer to be
12094 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 */
12096 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012097file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012098 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012099 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012101 /* In a buffer that was never loaded the options are not valid. */
12102 if (buf->b_flags & BF_NEVERLOADED)
12103 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012104 if (ignore_empty
12105 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012106 && buf->b_ml.ml_line_count == 1
12107 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12108 return FALSE;
12109 if (buf->b_start_ffc != *buf->b_p_ff)
12110 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012111 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012112 return TRUE;
12113#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012114 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12115 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012116 if (buf->b_start_fenc == NULL)
12117 return (*buf->b_p_fenc != NUL);
12118 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12119#else
12120 return FALSE;
12121#endif
12122}
12123
12124/*
12125 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12126 */
12127 int
12128check_ff_value(p)
12129 char_u *p;
12130{
12131 return check_opt_strings(p, p_ff_values, FALSE);
12132}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012133
12134/*
12135 * Return the effective shiftwidth value for current buffer, using the
12136 * 'tabstop' value when 'shiftwidth' is zero.
12137 */
12138 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012139get_sw_value(buf)
12140 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012141{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012142 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012143}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012144
12145/*
12146 * Return the effective softtabstop value for the current buffer, using the
12147 * 'tabstop' value when 'softtabstop' is negative.
12148 */
12149 long
12150get_sts_value()
12151{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012152 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012153}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012154
12155/*
12156 * Check matchpairs option for "*initc".
12157 * If there is a match set "*initc" to the matching character and "*findc" to
12158 * the opposite character. Set "*backwards" to the direction.
12159 * When "switchit" is TRUE swap the direction.
12160 */
12161 void
12162find_mps_values(initc, findc, backwards, switchit)
12163 int *initc;
12164 int *findc;
12165 int *backwards;
12166 int switchit;
12167{
12168 char_u *ptr;
12169
12170 ptr = curbuf->b_p_mps;
12171 while (*ptr != NUL)
12172 {
12173#ifdef FEAT_MBYTE
12174 if (has_mbyte)
12175 {
12176 char_u *prev;
12177
12178 if (mb_ptr2char(ptr) == *initc)
12179 {
12180 if (switchit)
12181 {
12182 *findc = *initc;
12183 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12184 *backwards = TRUE;
12185 }
12186 else
12187 {
12188 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12189 *backwards = FALSE;
12190 }
12191 return;
12192 }
12193 prev = ptr;
12194 ptr += mb_ptr2len(ptr) + 1;
12195 if (mb_ptr2char(ptr) == *initc)
12196 {
12197 if (switchit)
12198 {
12199 *findc = *initc;
12200 *initc = mb_ptr2char(prev);
12201 *backwards = FALSE;
12202 }
12203 else
12204 {
12205 *findc = mb_ptr2char(prev);
12206 *backwards = TRUE;
12207 }
12208 return;
12209 }
12210 ptr += mb_ptr2len(ptr);
12211 }
12212 else
12213#endif
12214 {
12215 if (*ptr == *initc)
12216 {
12217 if (switchit)
12218 {
12219 *backwards = TRUE;
12220 *findc = *initc;
12221 *initc = ptr[2];
12222 }
12223 else
12224 {
12225 *backwards = FALSE;
12226 *findc = ptr[2];
12227 }
12228 return;
12229 }
12230 ptr += 2;
12231 if (*ptr == *initc)
12232 {
12233 if (switchit)
12234 {
12235 *backwards = FALSE;
12236 *findc = *initc;
12237 *initc = ptr[-2];
12238 }
12239 else
12240 {
12241 *backwards = TRUE;
12242 *findc = ptr[-2];
12243 }
12244 return;
12245 }
12246 ++ptr;
12247 }
12248 if (*ptr == ',')
12249 ++ptr;
12250 }
12251}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012252
12253#if defined(FEAT_LINEBREAK) || defined(PROTO)
12254/*
12255 * This is called when 'breakindentopt' is changed and when a window is
12256 * initialized.
12257 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012258 static int
12259briopt_check(wp)
12260 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012261{
12262 char_u *p;
12263 int bri_shift = 0;
12264 long bri_min = 20;
12265 int bri_sbr = FALSE;
12266
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012267 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012268 while (*p != NUL)
12269 {
12270 if (STRNCMP(p, "shift:", 6) == 0
12271 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12272 {
12273 p += 6;
12274 bri_shift = getdigits(&p);
12275 }
12276 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12277 {
12278 p += 4;
12279 bri_min = getdigits(&p);
12280 }
12281 else if (STRNCMP(p, "sbr", 3) == 0)
12282 {
12283 p += 3;
12284 bri_sbr = TRUE;
12285 }
12286 if (*p != ',' && *p != NUL)
12287 return FAIL;
12288 if (*p == ',')
12289 ++p;
12290 }
12291
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012292 wp->w_p_brishift = bri_shift;
12293 wp->w_p_brimin = bri_min;
12294 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012295
12296 return OK;
12297}
12298#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012299
12300/*
12301 * Get the local or global value of 'backupcopy'.
12302 */
12303 unsigned int
12304get_bkc_value(buf)
12305 buf_T *buf;
12306{
12307 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12308}