blob: db3a197af4bce9b44d7ae7ba38817bf78d076882 [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 Moolenaar0e7c4b92015-06-20 15:30:03 +02004886 if (comma && (flags & P_ONECOMMA) && i > 1
4887 && origval[i - 1] == ','
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004888 && origval[i - 2] != '\\')
4889 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004890 mch_memmove(newval + i + comma, newval,
4891 STRLEN(newval) + 1);
4892 mch_memmove(newval, origval, (size_t)i);
4893 }
4894 else
4895 {
4896 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004897 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004898 }
4899 if (comma)
4900 newval[i] = ',';
4901 }
4902
4903 /* Remove newval[] from origval[]. (Note: "i" has
4904 * been set above and is used here). */
4905 if (removing)
4906 {
4907 STRCPY(newval, origval);
4908 if (*s)
4909 {
4910 /* may need to remove a comma */
4911 if (flags & P_COMMA)
4912 {
4913 if (s == origval)
4914 {
4915 /* include comma after string */
4916 if (s[i] == ',')
4917 ++i;
4918 }
4919 else
4920 {
4921 /* include comma before string */
4922 --s;
4923 ++i;
4924 }
4925 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004926 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004927 }
4928 }
4929
4930 if (flags & P_FLAGLIST)
4931 {
4932 /* Remove flags that appear twice. */
4933 for (s = newval; *s; ++s)
4934 if ((!(flags & P_COMMA) || *s != ',')
4935 && vim_strchr(s + 1, *s) != NULL)
4936 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004937 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004938 --s;
4939 }
4940 }
4941
4942 if (save_arg != NULL) /* number for 'whichwrap' */
4943 arg = save_arg;
4944 new_value_alloced = TRUE;
4945 }
4946
4947 /* Set the new value. */
4948 *(char_u **)(varp) = newval;
4949
Bram Moolenaar53744302015-07-17 17:38:22 +02004950#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004951 if (!starting
4952# ifdef FEAT_CRYPT
4953 && options[opt_idx].indir != PV_KEY
4954# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004955 && origval != NULL)
4956 /* origval may be freed by
4957 * did_set_string_option(), make a copy. */
4958 saved_origval = vim_strsave(origval);
4959#endif
4960
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 /* Handle side effects, and set the global value for
4962 * ":set" on local options. */
4963 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4964 new_value_alloced, oldval, errbuf, opt_flags);
4965
4966 /* If error detected, print the error message. */
4967 if (errmsg != NULL)
4968 goto skip;
Bram Moolenaar53744302015-07-17 17:38:22 +02004969#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4970 if (saved_origval != NULL)
4971 {
4972 char_u buf_type[7];
4973
4974 sprintf((char *)buf_type, "%s",
4975 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004976 set_vim_var_string(VV_OPTION_NEW,
4977 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004978 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4979 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4980 apply_autocmds(EVENT_OPTIONSET,
4981 (char_u *)options[opt_idx].fullname,
4982 NULL, FALSE, NULL);
4983 reset_v_option_vars();
4984 vim_free(saved_origval);
4985 }
4986#endif
4987
Bram Moolenaar071d4272004-06-13 20:20:40 +00004988 }
4989 else /* key code option */
4990 {
4991 char_u *p;
4992
4993 if (nextchar == '&')
4994 {
4995 if (add_termcap_entry(key_name, TRUE) == FAIL)
4996 errmsg = (char_u *)N_("E522: Not found in termcap");
4997 }
4998 else
4999 {
5000 ++arg; /* jump to after the '=' or ':' */
5001 for (p = arg; *p && !vim_iswhite(*p); ++p)
5002 if (*p == '\\' && p[1] != NUL)
5003 ++p;
5004 nextchar = *p;
5005 *p = NUL;
5006 add_termcode(key_name, arg, FALSE);
5007 *p = nextchar;
5008 }
5009 if (full_screen)
5010 ttest(FALSE);
5011 redraw_all_later(CLEAR);
5012 }
5013 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005014
Bram Moolenaar071d4272004-06-13 20:20:40 +00005015 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005016 did_set_option(opt_idx, opt_flags,
5017 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005018 }
5019
5020skip:
5021 /*
5022 * Advance to next argument.
5023 * - skip until a blank found, taking care of backslashes
5024 * - skip blanks
5025 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5026 */
5027 for (i = 0; i < 2 ; ++i)
5028 {
5029 while (*arg != NUL && !vim_iswhite(*arg))
5030 if (*arg++ == '\\' && *arg != NUL)
5031 ++arg;
5032 arg = skipwhite(arg);
5033 if (*arg != '=')
5034 break;
5035 }
5036 }
5037
5038 if (errmsg != NULL)
5039 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005040 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005041 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005042 if (i + (arg - startarg) < IOSIZE)
5043 {
5044 /* append the argument with the error */
5045 STRCAT(IObuff, ": ");
5046 mch_memmove(IObuff + i, startarg, (arg - startarg));
5047 IObuff[i + (arg - startarg)] = NUL;
5048 }
5049 /* make sure all characters are printable */
5050 trans_characters(IObuff, IOSIZE);
5051
5052 ++no_wait_return; /* wait_return done later */
5053 emsg(IObuff); /* show error highlighted */
5054 --no_wait_return;
5055
5056 return FAIL;
5057 }
5058
5059 arg = skipwhite(arg);
5060 }
5061
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005062theend:
5063 if (silent_mode && did_show)
5064 {
5065 /* After displaying option values in silent mode. */
5066 silent_mode = FALSE;
5067 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5068 msg_putchar('\n');
5069 cursor_on(); /* msg_start() switches it off */
5070 out_flush();
5071 silent_mode = TRUE;
5072 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5073 }
5074
Bram Moolenaar071d4272004-06-13 20:20:40 +00005075 return OK;
5076}
5077
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005078/*
5079 * Call this when an option has been given a new value through a user command.
5080 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5081 */
5082 static void
5083did_set_option(opt_idx, opt_flags, new_value)
5084 int opt_idx;
5085 int opt_flags; /* possibly with OPT_MODELINE */
5086 int new_value; /* value was replaced completely */
5087{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005088 long_u *p;
5089
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005090 options[opt_idx].flags |= P_WAS_SET;
5091
5092 /* When an option is set in the sandbox, from a modeline or in secure mode
5093 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005094 * flag. */
5095 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005096 if (secure
5097#ifdef HAVE_SANDBOX
5098 || sandbox != 0
5099#endif
5100 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005101 *p = *p | P_INSECURE;
5102 else if (new_value)
5103 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005104}
5105
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106 static char_u *
5107illegal_char(errbuf, c)
5108 char_u *errbuf;
5109 int c;
5110{
5111 if (errbuf == NULL)
5112 return (char_u *)"";
5113 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005114 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005115 return errbuf;
5116}
5117
5118/*
5119 * Convert a key name or string into a key value.
5120 * Used for 'wildchar' and 'cedit' options.
5121 */
5122 static int
5123string_to_key(arg)
5124 char_u *arg;
5125{
5126 if (*arg == '<')
5127 return find_key_option(arg + 1);
5128 if (*arg == '^')
5129 return Ctrl_chr(arg[1]);
5130 return *arg;
5131}
5132
5133#ifdef FEAT_CMDWIN
5134/*
5135 * Check value of 'cedit' and set cedit_key.
5136 * Returns NULL if value is OK, error message otherwise.
5137 */
5138 static char_u *
5139check_cedit()
5140{
5141 int n;
5142
5143 if (*p_cedit == NUL)
5144 cedit_key = -1;
5145 else
5146 {
5147 n = string_to_key(p_cedit);
5148 if (vim_isprintc(n))
5149 return e_invarg;
5150 cedit_key = n;
5151 }
5152 return NULL;
5153}
5154#endif
5155
5156#ifdef FEAT_TITLE
5157/*
5158 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5159 * maketitle() to create and display it.
5160 * When switching the title or icon off, call mch_restore_title() to get
5161 * the old value back.
5162 */
5163 static void
5164did_set_title(icon)
5165 int icon; /* Did set icon instead of title */
5166{
5167 if (starting != NO_SCREEN
5168#ifdef FEAT_GUI
5169 && !gui.starting
5170#endif
5171 )
5172 {
5173 maketitle();
5174 if (icon)
5175 {
5176 if (!p_icon)
5177 mch_restore_title(2);
5178 }
5179 else
5180 {
5181 if (!p_title)
5182 mch_restore_title(1);
5183 }
5184 }
5185}
5186#endif
5187
5188/*
5189 * set_options_bin - called when 'bin' changes value.
5190 */
5191 void
5192set_options_bin(oldval, newval, opt_flags)
5193 int oldval;
5194 int newval;
5195 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5196{
5197 /*
5198 * The option values that are changed when 'bin' changes are
5199 * copied when 'bin is set and restored when 'bin' is reset.
5200 */
5201 if (newval)
5202 {
5203 if (!oldval) /* switched on */
5204 {
5205 if (!(opt_flags & OPT_GLOBAL))
5206 {
5207 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5208 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5209 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5210 curbuf->b_p_et_nobin = curbuf->b_p_et;
5211 }
5212 if (!(opt_flags & OPT_LOCAL))
5213 {
5214 p_tw_nobin = p_tw;
5215 p_wm_nobin = p_wm;
5216 p_ml_nobin = p_ml;
5217 p_et_nobin = p_et;
5218 }
5219 }
5220
5221 if (!(opt_flags & OPT_GLOBAL))
5222 {
5223 curbuf->b_p_tw = 0; /* no automatic line wrap */
5224 curbuf->b_p_wm = 0; /* no automatic line wrap */
5225 curbuf->b_p_ml = 0; /* no modelines */
5226 curbuf->b_p_et = 0; /* no expandtab */
5227 }
5228 if (!(opt_flags & OPT_LOCAL))
5229 {
5230 p_tw = 0;
5231 p_wm = 0;
5232 p_ml = FALSE;
5233 p_et = FALSE;
5234 p_bin = TRUE; /* needed when called for the "-b" argument */
5235 }
5236 }
5237 else if (oldval) /* switched off */
5238 {
5239 if (!(opt_flags & OPT_GLOBAL))
5240 {
5241 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5242 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5243 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5244 curbuf->b_p_et = curbuf->b_p_et_nobin;
5245 }
5246 if (!(opt_flags & OPT_LOCAL))
5247 {
5248 p_tw = p_tw_nobin;
5249 p_wm = p_wm_nobin;
5250 p_ml = p_ml_nobin;
5251 p_et = p_et_nobin;
5252 }
5253 }
5254}
5255
5256#ifdef FEAT_VIMINFO
5257/*
5258 * Find the parameter represented by the given character (eg ', :, ", or /),
5259 * and return its associated value in the 'viminfo' string.
5260 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005261 * If the parameter is not specified in the string or there is no following
5262 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005263 */
5264 int
5265get_viminfo_parameter(type)
5266 int type;
5267{
5268 char_u *p;
5269
5270 p = find_viminfo_parameter(type);
5271 if (p != NULL && VIM_ISDIGIT(*p))
5272 return atoi((char *)p);
5273 return -1;
5274}
5275
5276/*
5277 * Find the parameter represented by the given character (eg ''', ':', '"', or
5278 * '/') in the 'viminfo' option and return a pointer to the string after it.
5279 * Return NULL if the parameter is not specified in the string.
5280 */
5281 char_u *
5282find_viminfo_parameter(type)
5283 int type;
5284{
5285 char_u *p;
5286
5287 for (p = p_viminfo; *p; ++p)
5288 {
5289 if (*p == type)
5290 return p + 1;
5291 if (*p == 'n') /* 'n' is always the last one */
5292 break;
5293 p = vim_strchr(p, ','); /* skip until next ',' */
5294 if (p == NULL) /* hit the end without finding parameter */
5295 break;
5296 }
5297 return NULL;
5298}
5299#endif
5300
5301/*
5302 * Expand environment variables for some string options.
5303 * These string options cannot be indirect!
5304 * If "val" is NULL expand the current value of the option.
5305 * Return pointer to NameBuff, or NULL when not expanded.
5306 */
5307 static char_u *
5308option_expand(opt_idx, val)
5309 int opt_idx;
5310 char_u *val;
5311{
5312 /* if option doesn't need expansion nothing to do */
5313 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5314 return NULL;
5315
5316 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5317 * expand_env() would truncate the string. */
5318 if (val != NULL && STRLEN(val) > MAXPATHL)
5319 return NULL;
5320
5321 if (val == NULL)
5322 val = *(char_u **)options[opt_idx].var;
5323
5324 /*
5325 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5326 * Escape spaces when expanding 'tags', they are used to separate file
5327 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005328 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005329 */
5330 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005331 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005332#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005333 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5334#endif
5335 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5337 return NULL;
5338
5339 return NameBuff;
5340}
5341
5342/*
5343 * After setting various option values: recompute variables that depend on
5344 * option values.
5345 */
5346 static void
5347didset_options()
5348{
5349 /* initialize the table for 'iskeyword' et.al. */
5350 (void)init_chartab();
5351
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005352#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005356 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357#ifdef FEAT_SESSION
5358 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5359 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5360#endif
5361#ifdef FEAT_FOLDING
5362 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5363#endif
5364 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5365#ifdef FEAT_VIRTUALEDIT
5366 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5367#endif
5368#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5369 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5370#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005371#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005372 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005373 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005374 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005375 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005377#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5378 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5379#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005380#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5382#endif
5383#ifdef FEAT_CMDWIN
5384 /* set cedit_key */
5385 (void)check_cedit();
5386#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005387#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005388 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005389#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005390#ifdef FEAT_LINEBREAK
5391 /* initialize the table for 'breakat'. */
5392 fill_breakat_flags();
5393#endif
5394
5395}
5396
5397/*
5398 * More side effects of setting options.
5399 */
5400 static void
5401didset_options2()
5402{
5403 /* Initialize the highlight_attr[] table. */
5404 (void)highlight_changed();
5405
5406 /* Parse default for 'wildmode' */
5407 check_opt_wim();
5408
5409 (void)set_chars_option(&p_lcs);
5410#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5411 /* Parse default for 'fillchars'. */
5412 (void)set_chars_option(&p_fcs);
5413#endif
5414
5415#ifdef FEAT_CLIPBOARD
5416 /* Parse default for 'clipboard' */
5417 (void)check_clipboard_option();
5418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005419}
5420
5421/*
5422 * Check for string options that are NULL (normally only termcap options).
5423 */
5424 void
5425check_options()
5426{
5427 int opt_idx;
5428
5429 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5430 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5431 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5432}
5433
5434/*
5435 * Check string options in a buffer for NULL value.
5436 */
5437 void
5438check_buf_options(buf)
5439 buf_T *buf;
5440{
5441#if defined(FEAT_QUICKFIX)
5442 check_string_option(&buf->b_p_bh);
5443 check_string_option(&buf->b_p_bt);
5444#endif
5445#ifdef FEAT_MBYTE
5446 check_string_option(&buf->b_p_fenc);
5447#endif
5448 check_string_option(&buf->b_p_ff);
5449#ifdef FEAT_FIND_ID
5450 check_string_option(&buf->b_p_def);
5451 check_string_option(&buf->b_p_inc);
5452# ifdef FEAT_EVAL
5453 check_string_option(&buf->b_p_inex);
5454# endif
5455#endif
5456#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5457 check_string_option(&buf->b_p_inde);
5458 check_string_option(&buf->b_p_indk);
5459#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005460#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5461 check_string_option(&buf->b_p_bexpr);
5462#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005463#if defined(FEAT_CRYPT)
5464 check_string_option(&buf->b_p_cm);
5465#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005466#if defined(FEAT_EVAL)
5467 check_string_option(&buf->b_p_fex);
5468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469#ifdef FEAT_CRYPT
5470 check_string_option(&buf->b_p_key);
5471#endif
5472 check_string_option(&buf->b_p_kp);
5473 check_string_option(&buf->b_p_mps);
5474 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005475 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005476 check_string_option(&buf->b_p_isk);
5477#ifdef FEAT_COMMENTS
5478 check_string_option(&buf->b_p_com);
5479#endif
5480#ifdef FEAT_FOLDING
5481 check_string_option(&buf->b_p_cms);
5482#endif
5483 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005484#ifdef FEAT_TEXTOBJ
5485 check_string_option(&buf->b_p_qe);
5486#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005487#ifdef FEAT_SYN_HL
5488 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005489#endif
5490#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005491 check_string_option(&buf->b_s.b_p_spc);
5492 check_string_option(&buf->b_s.b_p_spf);
5493 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494#endif
5495#ifdef FEAT_SEARCHPATH
5496 check_string_option(&buf->b_p_sua);
5497#endif
5498#ifdef FEAT_CINDENT
5499 check_string_option(&buf->b_p_cink);
5500 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005501 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502#endif
5503#ifdef FEAT_AUTOCMD
5504 check_string_option(&buf->b_p_ft);
5505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005506#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5507 check_string_option(&buf->b_p_cinw);
5508#endif
5509#ifdef FEAT_INS_EXPAND
5510 check_string_option(&buf->b_p_cpt);
5511#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005512#ifdef FEAT_COMPL_FUNC
5513 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005514 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005515#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005516#ifdef FEAT_KEYMAP
5517 check_string_option(&buf->b_p_keymap);
5518#endif
5519#ifdef FEAT_QUICKFIX
5520 check_string_option(&buf->b_p_gp);
5521 check_string_option(&buf->b_p_mp);
5522 check_string_option(&buf->b_p_efm);
5523#endif
5524 check_string_option(&buf->b_p_ep);
5525 check_string_option(&buf->b_p_path);
5526 check_string_option(&buf->b_p_tags);
5527#ifdef FEAT_INS_EXPAND
5528 check_string_option(&buf->b_p_dict);
5529 check_string_option(&buf->b_p_tsr);
5530#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005531#ifdef FEAT_LISP
5532 check_string_option(&buf->b_p_lw);
5533#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005534 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535}
5536
5537/*
5538 * Free the string allocated for an option.
5539 * Checks for the string being empty_option. This may happen if we're out of
5540 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5541 * check_options().
5542 * Does NOT check for P_ALLOCED flag!
5543 */
5544 void
5545free_string_option(p)
5546 char_u *p;
5547{
5548 if (p != empty_option)
5549 vim_free(p);
5550}
5551
5552 void
5553clear_string_option(pp)
5554 char_u **pp;
5555{
5556 if (*pp != empty_option)
5557 vim_free(*pp);
5558 *pp = empty_option;
5559}
5560
5561 static void
5562check_string_option(pp)
5563 char_u **pp;
5564{
5565 if (*pp == NULL)
5566 *pp = empty_option;
5567}
5568
5569/*
5570 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5571 */
5572 void
5573set_term_option_alloced(p)
5574 char_u **p;
5575{
5576 int opt_idx;
5577
5578 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5579 if (options[opt_idx].var == (char_u *)p)
5580 {
5581 options[opt_idx].flags |= P_ALLOCED;
5582 return;
5583 }
5584 return; /* cannot happen: didn't find it! */
5585}
5586
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005587#if defined(FEAT_EVAL) || defined(PROTO)
5588/*
5589 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5590 * Return FALSE when it wasn't.
5591 * Return -1 for an unknown option.
5592 */
5593 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005594was_set_insecurely(opt, opt_flags)
5595 char_u *opt;
5596 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005597{
5598 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005599 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005600
5601 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005602 {
5603 flagp = insecure_flag(idx, opt_flags);
5604 return (*flagp & P_INSECURE) != 0;
5605 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005606 EMSG2(_(e_intern2), "was_set_insecurely()");
5607 return -1;
5608}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005609
5610/*
5611 * Get a pointer to the flags used for the P_INSECURE flag of option
5612 * "opt_idx". For some local options a local flags field is used.
5613 */
5614 static long_u *
5615insecure_flag(opt_idx, opt_flags)
5616 int opt_idx;
5617 int opt_flags;
5618{
5619 if (opt_flags & OPT_LOCAL)
5620 switch ((int)options[opt_idx].indir)
5621 {
5622#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005623 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005624#endif
5625#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005626# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005627 case PV_FDE: return &curwin->w_p_fde_flags;
5628 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005629# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005630# ifdef FEAT_BEVAL
5631 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5632# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005633# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005634 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005635# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005636 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005637# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005638 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005639# endif
5640#endif
5641 }
5642
5643 /* Nothing special, return global flags field. */
5644 return &options[opt_idx].flags;
5645}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005646#endif
5647
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005648#ifdef FEAT_TITLE
5649static void redraw_titles __ARGS((void));
5650
5651/*
5652 * Redraw the window title and/or tab page text later.
5653 */
5654static void redraw_titles()
5655{
5656 need_maketitle = TRUE;
5657# ifdef FEAT_WINDOWS
5658 redraw_tabline = TRUE;
5659# endif
5660}
5661#endif
5662
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663/*
5664 * Set a string option to a new value (without checking the effect).
5665 * The string is copied into allocated memory.
5666 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005667 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005668 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005669 */
5670 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005671set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672 char_u *name;
5673 int opt_idx;
5674 char_u *val;
5675 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005676 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677{
5678 char_u *s;
5679 char_u **varp;
5680 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005681 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682
Bram Moolenaar89d40322006-08-29 15:30:07 +00005683 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005685 idx = findoption(name);
5686 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005687 {
5688 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005689 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005691 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005692 }
5693
Bram Moolenaar89d40322006-08-29 15:30:07 +00005694 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695 return;
5696
5697 s = vim_strsave(val);
5698 if (s != NULL)
5699 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005700 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005702 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005703 free_string_option(*varp);
5704 *varp = s;
5705
5706 /* For buffer/window local option may also set the global value. */
5707 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005708 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709
Bram Moolenaar89d40322006-08-29 15:30:07 +00005710 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711
5712 /* When setting both values of a global option with a local value,
5713 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005714 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715 {
5716 free_string_option(*varp);
5717 *varp = empty_option;
5718 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005719# ifdef FEAT_EVAL
5720 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005721 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005722 set_sid == 0 ? current_SID : set_sid);
5723# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005724 }
5725}
5726
5727/*
5728 * Set global value for string option when it's a local option.
5729 */
5730 static void
5731set_string_option_global(opt_idx, varp)
5732 int opt_idx; /* option index */
5733 char_u **varp; /* pointer to option variable */
5734{
5735 char_u **p, *s;
5736
5737 /* the global value is always allocated */
5738 if (options[opt_idx].var == VAR_WIN)
5739 p = (char_u **)GLOBAL_WO(varp);
5740 else
5741 p = (char_u **)options[opt_idx].var;
5742 if (options[opt_idx].indir != PV_NONE
5743 && p != varp
5744 && (s = vim_strsave(*varp)) != NULL)
5745 {
5746 free_string_option(*p);
5747 *p = s;
5748 }
5749}
5750
5751/*
5752 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005753 *
5754 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005756 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757set_string_option(opt_idx, value, opt_flags)
5758 int opt_idx;
5759 char_u *value;
5760 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5761{
5762 char_u *s;
5763 char_u **varp;
5764 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005765#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5766 char_u *saved_oldval = NULL;
5767#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005768 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769
5770 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005771 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772
5773 s = vim_strsave(value);
5774 if (s != NULL)
5775 {
5776 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5777 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005778 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005779 ? OPT_GLOBAL : OPT_LOCAL)
5780 : opt_flags);
5781 oldval = *varp;
5782 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005783
5784#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005785 if (!starting
5786# ifdef FEAT_CRYPT
5787 && options[opt_idx].indir != PV_KEY
5788# endif
5789 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005790 saved_oldval = vim_strsave(oldval);
5791#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005792 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5793 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005794 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005795
5796 /* call autocomamnd after handling side effects */
5797#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5798 if (saved_oldval != NULL)
5799 {
5800 char_u buf_type[7];
5801 sprintf((char *)buf_type, "%s",
5802 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005803 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5804 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005805 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5806 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5807 reset_v_option_vars();
5808 vim_free(saved_oldval);
5809 }
5810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005811 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005812 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005813}
5814
5815/*
5816 * Handle string options that need some action to perform when changed.
5817 * Returns NULL for success, or an error message for an error.
5818 */
5819 static char_u *
5820did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5821 opt_flags)
5822 int opt_idx; /* index in options[] table */
5823 char_u **varp; /* pointer to the option variable */
5824 int new_value_alloced; /* new value was allocated */
5825 char_u *oldval; /* previous value of the option */
5826 char_u *errbuf; /* buffer for errors, or NULL */
5827 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5828{
5829 char_u *errmsg = NULL;
5830 char_u *s, *p;
5831 int did_chartab = FALSE;
5832 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005833 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005834#ifdef FEAT_GUI
5835 /* set when changing an option that only requires a redraw in the GUI */
5836 int redraw_gui_only = FALSE;
5837#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005838
5839 /* Get the global option to compare with, otherwise we would have to check
5840 * two values for all local options. */
5841 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5842
5843 /* Disallow changing some options from secure mode */
5844 if ((secure
5845#ifdef HAVE_SANDBOX
5846 || sandbox != 0
5847#endif
5848 ) && (options[opt_idx].flags & P_SECURE))
5849 {
5850 errmsg = e_secure;
5851 }
5852
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005853 /* Check for a "normal" file name in some options. Disallow a path
5854 * separator (slash and/or backslash), wildcards and characters that are
5855 * often illegal in a file name. */
5856 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005857 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005858 {
5859 errmsg = e_invarg;
5860 }
5861
Bram Moolenaar071d4272004-06-13 20:20:40 +00005862 /* 'term' */
5863 else if (varp == &T_NAME)
5864 {
5865 if (T_NAME[0] == NUL)
5866 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5867#ifdef FEAT_GUI
5868 if (gui.in_use)
5869 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5870 else if (term_is_gui(T_NAME))
5871 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5872#endif
5873 else if (set_termname(T_NAME) == FAIL)
5874 errmsg = (char_u *)N_("E522: Not found in termcap");
5875 else
5876 /* Screen colors may have changed. */
5877 redraw_later_clear();
5878 }
5879
5880 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005881 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005882 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005883 char_u *bkc = p_bkc;
5884 unsigned int *flags = &bkc_flags;
5885
5886 if (opt_flags & OPT_LOCAL)
5887 {
5888 bkc = curbuf->b_p_bkc;
5889 flags = &curbuf->b_bkc_flags;
5890 }
5891
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005892 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5893 /* make the local value empty: use the global value */
5894 *flags = 0;
5895 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005897 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5898 errmsg = e_invarg;
5899 if ((((int)*flags & BKC_AUTO) != 0)
5900 + (((int)*flags & BKC_YES) != 0)
5901 + (((int)*flags & BKC_NO) != 0) != 1)
5902 {
5903 /* Must have exactly one of "auto", "yes" and "no". */
5904 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5905 errmsg = e_invarg;
5906 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907 }
5908 }
5909
5910 /* 'backupext' and 'patchmode' */
5911 else if (varp == &p_bex || varp == &p_pm)
5912 {
5913 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5914 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5915 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5916 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005917#ifdef FEAT_LINEBREAK
5918 /* 'breakindentopt' */
5919 else if (varp == &curwin->w_p_briopt)
5920 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005921 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005922 errmsg = e_invarg;
5923 }
5924#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925
5926 /*
5927 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5928 * If the new option is invalid, use old value. 'lisp' option: refill
5929 * chartab[] for '-' char
5930 */
5931 else if ( varp == &p_isi
5932 || varp == &(curbuf->b_p_isk)
5933 || varp == &p_isp
5934 || varp == &p_isf)
5935 {
5936 if (init_chartab() == FAIL)
5937 {
5938 did_chartab = TRUE; /* need to restore it below */
5939 errmsg = e_invarg; /* error in value */
5940 }
5941 }
5942
5943 /* 'helpfile' */
5944 else if (varp == &p_hf)
5945 {
5946 /* May compute new values for $VIM and $VIMRUNTIME */
5947 if (didset_vim)
5948 {
5949 vim_setenv((char_u *)"VIM", (char_u *)"");
5950 didset_vim = FALSE;
5951 }
5952 if (didset_vimruntime)
5953 {
5954 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5955 didset_vimruntime = FALSE;
5956 }
5957 }
5958
Bram Moolenaar1a384422010-07-14 19:53:30 +02005959#ifdef FEAT_SYN_HL
5960 /* 'colorcolumn' */
5961 else if (varp == &curwin->w_p_cc)
5962 errmsg = check_colorcolumn(curwin);
5963#endif
5964
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965#ifdef FEAT_MULTI_LANG
5966 /* 'helplang' */
5967 else if (varp == &p_hlg)
5968 {
5969 /* Check for "", "ab", "ab,cd", etc. */
5970 for (s = p_hlg; *s != NUL; s += 3)
5971 {
5972 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5973 {
5974 errmsg = e_invarg;
5975 break;
5976 }
5977 if (s[2] == NUL)
5978 break;
5979 }
5980 }
5981#endif
5982
5983 /* 'highlight' */
5984 else if (varp == &p_hl)
5985 {
5986 if (highlight_changed() == FAIL)
5987 errmsg = e_invarg; /* invalid flags */
5988 }
5989
5990 /* 'nrformats' */
5991 else if (gvarp == &p_nf)
5992 {
5993 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5994 errmsg = e_invarg;
5995 }
5996
5997#ifdef FEAT_SESSION
5998 /* 'sessionoptions' */
5999 else if (varp == &p_ssop)
6000 {
6001 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6002 errmsg = e_invarg;
6003 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6004 {
6005 /* Don't allow both "sesdir" and "curdir". */
6006 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6007 errmsg = e_invarg;
6008 }
6009 }
6010 /* 'viewoptions' */
6011 else if (varp == &p_vop)
6012 {
6013 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6014 errmsg = e_invarg;
6015 }
6016#endif
6017
6018 /* 'scrollopt' */
6019#ifdef FEAT_SCROLLBIND
6020 else if (varp == &p_sbo)
6021 {
6022 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6023 errmsg = e_invarg;
6024 }
6025#endif
6026
6027 /* 'ambiwidth' */
6028#ifdef FEAT_MBYTE
6029 else if (varp == &p_ambw)
6030 {
6031 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6032 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006033 else if (set_chars_option(&p_lcs) != NULL)
6034 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6035# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6036 else if (set_chars_option(&p_fcs) != NULL)
6037 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6038# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006039 }
6040#endif
6041
6042 /* 'background' */
6043 else if (varp == &p_bg)
6044 {
6045 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6046 {
6047#ifdef FEAT_EVAL
6048 int dark = (*p_bg == 'd');
6049#endif
6050
6051 init_highlight(FALSE, FALSE);
6052
6053#ifdef FEAT_EVAL
6054 if (dark != (*p_bg == 'd')
6055 && get_var_value((char_u *)"g:colors_name") != NULL)
6056 {
6057 /* The color scheme must have set 'background' back to another
6058 * value, that's not what we want here. Disable the color
6059 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006060 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006061 free_string_option(p_bg);
6062 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6063 check_string_option(&p_bg);
6064 init_highlight(FALSE, FALSE);
6065 }
6066#endif
6067 }
6068 else
6069 errmsg = e_invarg;
6070 }
6071
6072 /* 'wildmode' */
6073 else if (varp == &p_wim)
6074 {
6075 if (check_opt_wim() == FAIL)
6076 errmsg = e_invarg;
6077 }
6078
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006079#ifdef FEAT_CMDL_COMPL
6080 /* 'wildoptions' */
6081 else if (varp == &p_wop)
6082 {
6083 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6084 errmsg = e_invarg;
6085 }
6086#endif
6087
Bram Moolenaar071d4272004-06-13 20:20:40 +00006088#ifdef FEAT_WAK
6089 /* 'winaltkeys' */
6090 else if (varp == &p_wak)
6091 {
6092 if (*p_wak == NUL
6093 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6094 errmsg = e_invarg;
6095# ifdef FEAT_MENU
6096# ifdef FEAT_GUI_MOTIF
6097 else if (gui.in_use)
6098 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6099# else
6100# ifdef FEAT_GUI_GTK
6101 else if (gui.in_use)
6102 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6103# endif
6104# endif
6105# endif
6106 }
6107#endif
6108
6109#ifdef FEAT_AUTOCMD
6110 /* 'eventignore' */
6111 else if (varp == &p_ei)
6112 {
6113 if (check_ei() == FAIL)
6114 errmsg = e_invarg;
6115 }
6116#endif
6117
6118#ifdef FEAT_MBYTE
6119 /* 'encoding' and 'fileencoding' */
6120 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6121 {
6122 if (gvarp == &p_fenc)
6123 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006124 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006125 errmsg = e_modifiable;
6126 else if (vim_strchr(*varp, ',') != NULL)
6127 /* No comma allowed in 'fileencoding'; catches confusing it
6128 * with 'fileencodings'. */
6129 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006131 {
6132# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006133 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006134 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006135# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006136 /* Add 'fileencoding' to the swap file. */
6137 ml_setflags(curbuf);
6138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139 }
6140 if (errmsg == NULL)
6141 {
6142 /* canonize the value, so that STRCMP() can be used on it */
6143 p = enc_canonize(*varp);
6144 if (p != NULL)
6145 {
6146 vim_free(*varp);
6147 *varp = p;
6148 }
6149 if (varp == &p_enc)
6150 {
6151 errmsg = mb_init();
6152# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006153 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154# endif
6155 }
6156 }
6157
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006158# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006159 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6160 {
6161 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6162 if (STRCMP(p_tenc, "utf-8") != 0)
6163 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6164 }
6165# endif
6166
6167 if (errmsg == NULL)
6168 {
6169# ifdef FEAT_KEYMAP
6170 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6171 * (with another encoding). */
6172 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6173 (void)keymap_init();
6174# endif
6175
6176 /* When 'termencoding' is not empty and 'encoding' changes or when
6177 * 'termencoding' changes, need to setup for keyboard input and
6178 * display output conversion. */
6179 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6180 {
6181 convert_setup(&input_conv, p_tenc, p_enc);
6182 convert_setup(&output_conv, p_enc, p_tenc);
6183 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006184
6185# if defined(WIN3264) && defined(FEAT_MBYTE)
6186 /* $HOME may have characters in active code page. */
6187 if (varp == &p_enc)
6188 init_homedir();
6189# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006190 }
6191 }
6192#endif
6193
6194#if defined(FEAT_POSTSCRIPT)
6195 else if (varp == &p_penc)
6196 {
6197 /* Canonize printencoding if VIM standard one */
6198 p = enc_canonize(p_penc);
6199 if (p != NULL)
6200 {
6201 vim_free(p_penc);
6202 p_penc = p;
6203 }
6204 else
6205 {
6206 /* Ensure lower case and '-' for '_' */
6207 for (s = p_penc; *s != NUL; s++)
6208 {
6209 if (*s == '_')
6210 *s = '-';
6211 else
6212 *s = TOLOWER_ASC(*s);
6213 }
6214 }
6215 }
6216#endif
6217
Bram Moolenaar9372a112005-12-06 19:59:18 +00006218#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006219 else if (varp == &p_imak)
6220 {
6221 if (gui.in_use && !im_xim_isvalid_imactivate())
6222 errmsg = e_invarg;
6223 }
6224#endif
6225
6226#ifdef FEAT_KEYMAP
6227 else if (varp == &curbuf->b_p_keymap)
6228 {
6229 /* load or unload key mapping tables */
6230 errmsg = keymap_init();
6231
Bram Moolenaarfab06232009-03-04 03:13:35 +00006232 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006233 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006234 if (*curbuf->b_p_keymap != NUL)
6235 {
6236 /* Installed a new keymap, switch on using it. */
6237 curbuf->b_p_iminsert = B_IMODE_LMAP;
6238 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6239 curbuf->b_p_imsearch = B_IMODE_LMAP;
6240 }
6241 else
6242 {
6243 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6244 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6245 curbuf->b_p_iminsert = B_IMODE_NONE;
6246 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6247 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6248 }
6249 if ((opt_flags & OPT_LOCAL) == 0)
6250 {
6251 set_iminsert_global();
6252 set_imsearch_global();
6253 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254# ifdef FEAT_WINDOWS
6255 status_redraw_curbuf();
6256# endif
6257 }
6258 }
6259#endif
6260
6261 /* 'fileformat' */
6262 else if (gvarp == &p_ff)
6263 {
6264 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6265 errmsg = e_modifiable;
6266 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6267 errmsg = e_invarg;
6268 else
6269 {
6270 /* may also change 'textmode' */
6271 if (get_fileformat(curbuf) == EOL_DOS)
6272 curbuf->b_p_tx = TRUE;
6273 else
6274 curbuf->b_p_tx = FALSE;
6275#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006276 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006277#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006278 /* update flag in swap file */
6279 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006280 /* Redraw needed when switching to/from "mac": a CR in the text
6281 * will be displayed differently. */
6282 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6283 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006284 }
6285 }
6286
6287 /* 'fileformats' */
6288 else if (varp == &p_ffs)
6289 {
6290 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6291 errmsg = e_invarg;
6292 else
6293 {
6294 /* also change 'textauto' */
6295 if (*p_ffs == NUL)
6296 p_ta = FALSE;
6297 else
6298 p_ta = TRUE;
6299 }
6300 }
6301
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006302#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 /* 'cryptkey' */
6304 else if (gvarp == &p_key)
6305 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006306# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006307 /* Make sure the ":set" command doesn't show the new value in the
6308 * history. */
6309 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006310# endif
6311 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6312 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006313 ml_set_crypt_key(curbuf, oldval,
6314 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006315 }
6316
6317 else if (gvarp == &p_cm)
6318 {
6319 if (opt_flags & OPT_LOCAL)
6320 p = curbuf->b_p_cm;
6321 else
6322 p = p_cm;
6323 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6324 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006325 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006326 errmsg = e_invarg;
6327 else
6328 {
6329 /* When setting the global value to empty, make it "zip". */
6330 if (*p_cm == NUL)
6331 {
6332 if (new_value_alloced)
6333 free_string_option(p_cm);
6334 p_cm = vim_strsave((char_u *)"zip");
6335 new_value_alloced = TRUE;
6336 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006337 /* When using ":set cm=name" the local value is going to be empty.
6338 * Do that here, otherwise the crypt functions will still use the
6339 * local value. */
6340 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6341 {
6342 free_string_option(curbuf->b_p_cm);
6343 curbuf->b_p_cm = empty_option;
6344 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006345
6346 /* Need to update the swapfile when the effective method changed.
6347 * Set "s" to the effective old value, "p" to the effective new
6348 * method and compare. */
6349 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6350 s = p_cm; /* was previously using the global value */
6351 else
6352 s = oldval;
6353 if (*curbuf->b_p_cm == NUL)
6354 p = p_cm; /* is now using the global value */
6355 else
6356 p = curbuf->b_p_cm;
6357 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006358 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006359
6360 /* If the global value changes need to update the swapfile for all
6361 * buffers using that value. */
6362 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6363 {
6364 buf_T *buf;
6365
6366 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6367 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006368 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006369 }
6370 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006371 }
6372#endif
6373
6374 /* 'matchpairs' */
6375 else if (gvarp == &p_mps)
6376 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006377#ifdef FEAT_MBYTE
6378 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006380 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006381 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006382 int x2 = -1;
6383 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006384
6385 if (*p != NUL)
6386 p += mb_ptr2len(p);
6387 if (*p != NUL)
6388 x2 = *p++;
6389 if (*p != NUL)
6390 {
6391 x3 = mb_ptr2char(p);
6392 p += mb_ptr2len(p);
6393 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006394 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006395 {
6396 errmsg = e_invarg;
6397 break;
6398 }
6399 if (*p == NUL)
6400 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006402 }
6403 else
6404#endif
6405 {
6406 /* Check for "x:y,x:y" */
6407 for (p = *varp; *p != NUL; p += 4)
6408 {
6409 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6410 {
6411 errmsg = e_invarg;
6412 break;
6413 }
6414 if (p[3] == NUL)
6415 break;
6416 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006417 }
6418 }
6419
6420#ifdef FEAT_COMMENTS
6421 /* 'comments' */
6422 else if (gvarp == &p_com)
6423 {
6424 for (s = *varp; *s; )
6425 {
6426 while (*s && *s != ':')
6427 {
6428 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6429 && !VIM_ISDIGIT(*s) && *s != '-')
6430 {
6431 errmsg = illegal_char(errbuf, *s);
6432 break;
6433 }
6434 ++s;
6435 }
6436 if (*s++ == NUL)
6437 errmsg = (char_u *)N_("E524: Missing colon");
6438 else if (*s == ',' || *s == NUL)
6439 errmsg = (char_u *)N_("E525: Zero length string");
6440 if (errmsg != NULL)
6441 break;
6442 while (*s && *s != ',')
6443 {
6444 if (*s == '\\' && s[1] != NUL)
6445 ++s;
6446 ++s;
6447 }
6448 s = skip_to_option_part(s);
6449 }
6450 }
6451#endif
6452
6453 /* 'listchars' */
6454 else if (varp == &p_lcs)
6455 {
6456 errmsg = set_chars_option(varp);
6457 }
6458
6459#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6460 /* 'fillchars' */
6461 else if (varp == &p_fcs)
6462 {
6463 errmsg = set_chars_option(varp);
6464 }
6465#endif
6466
6467#ifdef FEAT_CMDWIN
6468 /* 'cedit' */
6469 else if (varp == &p_cedit)
6470 {
6471 errmsg = check_cedit();
6472 }
6473#endif
6474
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006475 /* 'verbosefile' */
6476 else if (varp == &p_vfile)
6477 {
6478 verbose_stop();
6479 if (*p_vfile != NUL && verbose_open() == FAIL)
6480 errmsg = e_invarg;
6481 }
6482
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483#ifdef FEAT_VIMINFO
6484 /* 'viminfo' */
6485 else if (varp == &p_viminfo)
6486 {
6487 for (s = p_viminfo; *s;)
6488 {
6489 /* Check it's a valid character */
6490 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6491 {
6492 errmsg = illegal_char(errbuf, *s);
6493 break;
6494 }
6495 if (*s == 'n') /* name is always last one */
6496 {
6497 break;
6498 }
6499 else if (*s == 'r') /* skip until next ',' */
6500 {
6501 while (*++s && *s != ',')
6502 ;
6503 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006504 else if (*s == '%')
6505 {
6506 /* optional number */
6507 while (vim_isdigit(*++s))
6508 ;
6509 }
6510 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006511 ++s; /* no extra chars */
6512 else /* must have a number */
6513 {
6514 while (vim_isdigit(*++s))
6515 ;
6516
6517 if (!VIM_ISDIGIT(*(s - 1)))
6518 {
6519 if (errbuf != NULL)
6520 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006521 sprintf((char *)errbuf,
6522 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006523 transchar_byte(*(s - 1)));
6524 errmsg = errbuf;
6525 }
6526 else
6527 errmsg = (char_u *)"";
6528 break;
6529 }
6530 }
6531 if (*s == ',')
6532 ++s;
6533 else if (*s)
6534 {
6535 if (errbuf != NULL)
6536 errmsg = (char_u *)N_("E527: Missing comma");
6537 else
6538 errmsg = (char_u *)"";
6539 break;
6540 }
6541 }
6542 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6543 errmsg = (char_u *)N_("E528: Must specify a ' value");
6544 }
6545#endif /* FEAT_VIMINFO */
6546
6547 /* terminal options */
6548 else if (istermoption(&options[opt_idx]) && full_screen)
6549 {
6550 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6551 if (varp == &T_CCO)
6552 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006553 int colors = atoi((char *)T_CCO);
6554
6555 /* Only reinitialize colors if t_Co value has really changed to
6556 * avoid expensive reload of colorscheme if t_Co is set to the
6557 * same value multiple times. */
6558 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006559 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006560 t_colors = colors;
6561 if (t_colors <= 1)
6562 {
6563 if (new_value_alloced)
6564 vim_free(T_CCO);
6565 T_CCO = empty_option;
6566 }
6567 /* We now have a different color setup, initialize it again. */
6568 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006570 }
6571 ttest(FALSE);
6572 if (varp == &T_ME)
6573 {
6574 out_str(T_ME);
6575 redraw_later(CLEAR);
6576#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6577 /* Since t_me has been set, this probably means that the user
6578 * wants to use this as default colors. Need to reset default
6579 * background/foreground colors. */
6580 mch_set_normal_colors();
6581#endif
6582 }
6583 }
6584
6585#ifdef FEAT_LINEBREAK
6586 /* 'showbreak' */
6587 else if (varp == &p_sbr)
6588 {
6589 for (s = p_sbr; *s; )
6590 {
6591 if (ptr2cells(s) != 1)
6592 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006593 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006594 }
6595 }
6596#endif
6597
6598#ifdef FEAT_GUI
6599 /* 'guifont' */
6600 else if (varp == &p_guifont)
6601 {
6602 if (gui.in_use)
6603 {
6604 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006605# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 /*
6607 * Put up a font dialog and let the user select a new value.
6608 * If this is cancelled go back to the old value but don't
6609 * give an error message.
6610 */
6611 if (STRCMP(p, "*") == 0)
6612 {
6613 p = gui_mch_font_dialog(oldval);
6614
6615 if (new_value_alloced)
6616 free_string_option(p_guifont);
6617
6618 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6619 new_value_alloced = TRUE;
6620 }
6621# endif
6622 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6623 {
6624# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6625 if (STRCMP(p_guifont, "*") == 0)
6626 {
6627 /* Dialog was cancelled: Keep the old value without giving
6628 * an error message. */
6629 if (new_value_alloced)
6630 free_string_option(p_guifont);
6631 p_guifont = vim_strsave(oldval);
6632 new_value_alloced = TRUE;
6633 }
6634 else
6635# endif
6636 errmsg = (char_u *)N_("E596: Invalid font(s)");
6637 }
6638 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006639 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006640 }
6641# ifdef FEAT_XFONTSET
6642 else if (varp == &p_guifontset)
6643 {
6644 if (STRCMP(p_guifontset, "*") == 0)
6645 errmsg = (char_u *)N_("E597: can't select fontset");
6646 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6647 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006648 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006649 }
6650# endif
6651# ifdef FEAT_MBYTE
6652 else if (varp == &p_guifontwide)
6653 {
6654 if (STRCMP(p_guifontwide, "*") == 0)
6655 errmsg = (char_u *)N_("E533: can't select wide font");
6656 else if (gui_get_wide_font() == FAIL)
6657 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006658 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006659 }
6660# endif
6661#endif
6662
6663#ifdef CURSOR_SHAPE
6664 /* 'guicursor' */
6665 else if (varp == &p_guicursor)
6666 errmsg = parse_shape_opt(SHAPE_CURSOR);
6667#endif
6668
6669#ifdef FEAT_MOUSESHAPE
6670 /* 'mouseshape' */
6671 else if (varp == &p_mouseshape)
6672 {
6673 errmsg = parse_shape_opt(SHAPE_MOUSE);
6674 update_mouseshape(-1);
6675 }
6676#endif
6677
6678#ifdef FEAT_PRINTER
6679 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006680 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006681# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006682 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006683 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006684# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006685#endif
6686
6687#ifdef FEAT_LANGMAP
6688 /* 'langmap' */
6689 else if (varp == &p_langmap)
6690 langmap_set();
6691#endif
6692
6693#ifdef FEAT_LINEBREAK
6694 /* 'breakat' */
6695 else if (varp == &p_breakat)
6696 fill_breakat_flags();
6697#endif
6698
6699#ifdef FEAT_TITLE
6700 /* 'titlestring' and 'iconstring' */
6701 else if (varp == &p_titlestring || varp == &p_iconstring)
6702 {
6703# ifdef FEAT_STL_OPT
6704 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6705
6706 /* NULL => statusline syntax */
6707 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6708 stl_syntax |= flagval;
6709 else
6710 stl_syntax &= ~flagval;
6711# endif
6712 did_set_title(varp == &p_iconstring);
6713
6714 }
6715#endif
6716
6717#ifdef FEAT_GUI
6718 /* 'guioptions' */
6719 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006720 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006721 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006722 redraw_gui_only = TRUE;
6723 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006724#endif
6725
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006726#if defined(FEAT_GUI_TABLINE)
6727 /* 'guitablabel' */
6728 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006729 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006730 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006731 redraw_gui_only = TRUE;
6732 }
6733 /* 'guitabtooltip' */
6734 else if (varp == &p_gtt)
6735 {
6736 redraw_gui_only = TRUE;
6737 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006738#endif
6739
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6741 /* 'ttymouse' */
6742 else if (varp == &p_ttym)
6743 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006744 /* Switch the mouse off before changing the escape sequences used for
6745 * that. */
6746 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6748 errmsg = e_invarg;
6749 else
6750 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006751 if (termcap_active)
6752 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753 }
6754#endif
6755
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 /* 'selection' */
6757 else if (varp == &p_sel)
6758 {
6759 if (*p_sel == NUL
6760 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6761 errmsg = e_invarg;
6762 }
6763
6764 /* 'selectmode' */
6765 else if (varp == &p_slm)
6766 {
6767 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6768 errmsg = e_invarg;
6769 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006770
6771#ifdef FEAT_BROWSE
6772 /* 'browsedir' */
6773 else if (varp == &p_bsdir)
6774 {
6775 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6776 && !mch_isdir(p_bsdir))
6777 errmsg = e_invarg;
6778 }
6779#endif
6780
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781 /* 'keymodel' */
6782 else if (varp == &p_km)
6783 {
6784 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6785 errmsg = e_invarg;
6786 else
6787 {
6788 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6789 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6790 }
6791 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792
6793 /* 'mousemodel' */
6794 else if (varp == &p_mousem)
6795 {
6796 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6797 errmsg = e_invarg;
6798#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6799 else if (*p_mousem != *oldval)
6800 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6801 * to create or delete the popup menus. */
6802 gui_motif_update_mousemodel(root_menu);
6803#endif
6804 }
6805
6806 /* 'switchbuf' */
6807 else if (varp == &p_swb)
6808 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006809 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006810 errmsg = e_invarg;
6811 }
6812
6813 /* 'debug' */
6814 else if (varp == &p_debug)
6815 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006816 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006817 errmsg = e_invarg;
6818 }
6819
6820 /* 'display' */
6821 else if (varp == &p_dy)
6822 {
6823 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6824 errmsg = e_invarg;
6825 else
6826 (void)init_chartab();
6827
6828 }
6829
6830#ifdef FEAT_VERTSPLIT
6831 /* 'eadirection' */
6832 else if (varp == &p_ead)
6833 {
6834 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6835 errmsg = e_invarg;
6836 }
6837#endif
6838
6839#ifdef FEAT_CLIPBOARD
6840 /* 'clipboard' */
6841 else if (varp == &p_cb)
6842 errmsg = check_clipboard_option();
6843#endif
6844
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006845#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006846 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6847 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006848 else if (varp == &(curwin->w_s->b_p_spl)
6849 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006850 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006851 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006852 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006853 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006854 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006855 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006856 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006857 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006858 /* 'spellsuggest' */
6859 else if (varp == &p_sps)
6860 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006861 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006862 errmsg = e_invarg;
6863 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006864 /* 'mkspellmem' */
6865 else if (varp == &p_msm)
6866 {
6867 if (spell_check_msm() != OK)
6868 errmsg = e_invarg;
6869 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006870#endif
6871
Bram Moolenaar071d4272004-06-13 20:20:40 +00006872#ifdef FEAT_QUICKFIX
6873 /* When 'bufhidden' is set, check for valid value. */
6874 else if (gvarp == &p_bh)
6875 {
6876 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6877 errmsg = e_invarg;
6878 }
6879
6880 /* When 'buftype' is set, check for valid value. */
6881 else if (gvarp == &p_bt)
6882 {
6883 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6884 errmsg = e_invarg;
6885 else
6886 {
6887# ifdef FEAT_WINDOWS
6888 if (curwin->w_status_height)
6889 {
6890 curwin->w_redr_status = TRUE;
6891 redraw_later(VALID);
6892 }
6893# endif
6894 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006895# ifdef FEAT_TITLE
6896 redraw_titles();
6897# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898 }
6899 }
6900#endif
6901
6902#ifdef FEAT_STL_OPT
6903 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006904 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006905 {
6906 int wid;
6907
6908 if (varp == &p_ruf) /* reset ru_wid first */
6909 ru_wid = 0;
6910 s = *varp;
6911 if (varp == &p_ruf && *s == '%')
6912 {
6913 /* set ru_wid if 'ruf' starts with "%99(" */
6914 if (*++s == '-') /* ignore a '-' */
6915 s++;
6916 wid = getdigits(&s);
6917 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6918 ru_wid = wid;
6919 else
6920 errmsg = check_stl_option(p_ruf);
6921 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006922 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006923 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006924 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006925 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006926 comp_col();
6927 }
6928#endif
6929
6930#ifdef FEAT_INS_EXPAND
6931 /* check if it is a valid value for 'complete' -- Acevedo */
6932 else if (gvarp == &p_cpt)
6933 {
6934 for (s = *varp; *s;)
6935 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006936 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006937 s++;
6938 if (!*s)
6939 break;
6940 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6941 {
6942 errmsg = illegal_char(errbuf, *s);
6943 break;
6944 }
6945 if (*++s != NUL && *s != ',' && *s != ' ')
6946 {
6947 if (s[-1] == 'k' || s[-1] == 's')
6948 {
6949 /* skip optional filename after 'k' and 's' */
6950 while (*s && *s != ',' && *s != ' ')
6951 {
6952 if (*s == '\\')
6953 ++s;
6954 ++s;
6955 }
6956 }
6957 else
6958 {
6959 if (errbuf != NULL)
6960 {
6961 sprintf((char *)errbuf,
6962 _("E535: Illegal character after <%c>"),
6963 *--s);
6964 errmsg = errbuf;
6965 }
6966 else
6967 errmsg = (char_u *)"";
6968 break;
6969 }
6970 }
6971 }
6972 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006973
6974 /* 'completeopt' */
6975 else if (varp == &p_cot)
6976 {
6977 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6978 errmsg = e_invarg;
6979 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980#endif /* FEAT_INS_EXPAND */
6981
6982
6983#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6984 else if (varp == &p_toolbar)
6985 {
6986 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6987 &toolbar_flags, TRUE) != OK)
6988 errmsg = e_invarg;
6989 else
6990 {
6991 out_flush();
6992 gui_mch_show_toolbar((toolbar_flags &
6993 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6994 }
6995 }
6996#endif
6997
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006998#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006999 /* 'toolbariconsize': GTK+ 2 only */
7000 else if (varp == &p_tbis)
7001 {
7002 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7003 errmsg = e_invarg;
7004 else
7005 {
7006 out_flush();
7007 gui_mch_show_toolbar((toolbar_flags &
7008 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7009 }
7010 }
7011#endif
7012
7013 /* 'pastetoggle': translate key codes like in a mapping */
7014 else if (varp == &p_pt)
7015 {
7016 if (*p_pt)
7017 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007018 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019 if (p != NULL)
7020 {
7021 if (new_value_alloced)
7022 free_string_option(p_pt);
7023 p_pt = p;
7024 new_value_alloced = TRUE;
7025 }
7026 }
7027 }
7028
7029 /* 'backspace' */
7030 else if (varp == &p_bs)
7031 {
7032 if (VIM_ISDIGIT(*p_bs))
7033 {
7034 if (*p_bs >'2' || p_bs[1] != NUL)
7035 errmsg = e_invarg;
7036 }
7037 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7038 errmsg = e_invarg;
7039 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007040 else if (varp == &p_bo)
7041 {
7042 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7043 errmsg = e_invarg;
7044 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007045
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007046#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007047 /* 'casemap' */
7048 else if (varp == &p_cmp)
7049 {
7050 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7051 errmsg = e_invarg;
7052 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007053#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007054
7055#ifdef FEAT_DIFF
7056 /* 'diffopt' */
7057 else if (varp == &p_dip)
7058 {
7059 if (diffopt_changed() == FAIL)
7060 errmsg = e_invarg;
7061 }
7062#endif
7063
7064#ifdef FEAT_FOLDING
7065 /* 'foldmethod' */
7066 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7067 {
7068 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7069 || *curwin->w_p_fdm == NUL)
7070 errmsg = e_invarg;
7071 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007072 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007073 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007074 if (foldmethodIsDiff(curwin))
7075 newFoldLevel();
7076 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077 }
7078# ifdef FEAT_EVAL
7079 /* 'foldexpr' */
7080 else if (varp == &curwin->w_p_fde)
7081 {
7082 if (foldmethodIsExpr(curwin))
7083 foldUpdateAll(curwin);
7084 }
7085# endif
7086 /* 'foldmarker' */
7087 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7088 {
7089 p = vim_strchr(*varp, ',');
7090 if (p == NULL)
7091 errmsg = (char_u *)N_("E536: comma required");
7092 else if (p == *varp || p[1] == NUL)
7093 errmsg = e_invarg;
7094 else if (foldmethodIsMarker(curwin))
7095 foldUpdateAll(curwin);
7096 }
7097 /* 'commentstring' */
7098 else if (gvarp == &p_cms)
7099 {
7100 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7101 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7102 }
7103 /* 'foldopen' */
7104 else if (varp == &p_fdo)
7105 {
7106 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7107 errmsg = e_invarg;
7108 }
7109 /* 'foldclose' */
7110 else if (varp == &p_fcl)
7111 {
7112 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7113 errmsg = e_invarg;
7114 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007115 /* 'foldignore' */
7116 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7117 {
7118 if (foldmethodIsIndent(curwin))
7119 foldUpdateAll(curwin);
7120 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121#endif
7122
7123#ifdef FEAT_VIRTUALEDIT
7124 /* 'virtualedit' */
7125 else if (varp == &p_ve)
7126 {
7127 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7128 errmsg = e_invarg;
7129 else if (STRCMP(p_ve, oldval) != 0)
7130 {
7131 /* Recompute cursor position in case the new 've' setting
7132 * changes something. */
7133 validate_virtcol();
7134 coladvance(curwin->w_virtcol);
7135 }
7136 }
7137#endif
7138
7139#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7140 else if (varp == &p_csqf)
7141 {
7142 if (p_csqf != NULL)
7143 {
7144 p = p_csqf;
7145 while (*p != NUL)
7146 {
7147 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7148 || p[1] == NUL
7149 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7150 || (p[2] != NUL && p[2] != ','))
7151 {
7152 errmsg = e_invarg;
7153 break;
7154 }
7155 else if (p[2] == NUL)
7156 break;
7157 else
7158 p += 3;
7159 }
7160 }
7161 }
7162#endif
7163
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007164#ifdef FEAT_CINDENT
7165 /* 'cinoptions' */
7166 else if (gvarp == &p_cino)
7167 {
7168 /* TODO: recognize errors */
7169 parse_cino(curbuf);
7170 }
7171#endif
7172
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007173#if defined(FEAT_RENDER_OPTIONS)
7174 else if (varp == &p_rop && gui.in_use)
7175 {
7176 if (!gui_mch_set_rendering_options(p_rop))
7177 errmsg = e_invarg;
7178 }
7179#endif
7180
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 /* Options that are a list of flags. */
7182 else
7183 {
7184 p = NULL;
7185 if (varp == &p_ww)
7186 p = (char_u *)WW_ALL;
7187 if (varp == &p_shm)
7188 p = (char_u *)SHM_ALL;
7189 else if (varp == &(p_cpo))
7190 p = (char_u *)CPO_ALL;
7191 else if (varp == &(curbuf->b_p_fo))
7192 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007193#ifdef FEAT_CONCEAL
7194 else if (varp == &curwin->w_p_cocu)
7195 p = (char_u *)COCU_ALL;
7196#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 else if (varp == &p_mouse)
7198 {
7199#ifdef FEAT_MOUSE
7200 p = (char_u *)MOUSE_ALL;
7201#else
7202 if (*p_mouse != NUL)
7203 errmsg = (char_u *)N_("E538: No mouse support");
7204#endif
7205 }
7206#if defined(FEAT_GUI)
7207 else if (varp == &p_go)
7208 p = (char_u *)GO_ALL;
7209#endif
7210 if (p != NULL)
7211 {
7212 for (s = *varp; *s; ++s)
7213 if (vim_strchr(p, *s) == NULL)
7214 {
7215 errmsg = illegal_char(errbuf, *s);
7216 break;
7217 }
7218 }
7219 }
7220
7221 /*
7222 * If error detected, restore the previous value.
7223 */
7224 if (errmsg != NULL)
7225 {
7226 if (new_value_alloced)
7227 free_string_option(*varp);
7228 *varp = oldval;
7229 /*
7230 * When resetting some values, need to act on it.
7231 */
7232 if (did_chartab)
7233 (void)init_chartab();
7234 if (varp == &p_hl)
7235 (void)highlight_changed();
7236 }
7237 else
7238 {
7239#ifdef FEAT_EVAL
7240 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007241 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242#endif
7243 /*
7244 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007245 * Use "free_oldval", because recursiveness may change the flags under
7246 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007248 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007249 free_string_option(oldval);
7250 if (new_value_alloced)
7251 options[opt_idx].flags |= P_ALLOCED;
7252 else
7253 options[opt_idx].flags &= ~P_ALLOCED;
7254
7255 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007256 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007257 {
7258 /* global option with local value set to use global value; free
7259 * the local value and make it empty */
7260 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7261 free_string_option(*(char_u **)p);
7262 *(char_u **)p = empty_option;
7263 }
7264
7265 /* May set global value for local option. */
7266 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7267 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007268
7269#ifdef FEAT_AUTOCMD
7270 /*
7271 * Trigger the autocommand only after setting the flags.
7272 */
7273# ifdef FEAT_SYN_HL
7274 /* When 'syntax' is set, load the syntax of that name */
7275 if (varp == &(curbuf->b_p_syn))
7276 {
7277 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7278 curbuf->b_fname, TRUE, curbuf);
7279 }
7280# endif
7281 else if (varp == &(curbuf->b_p_ft))
7282 {
7283 /* 'filetype' is set, trigger the FileType autocommand */
7284 did_filetype = TRUE;
7285 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7286 curbuf->b_fname, TRUE, curbuf);
7287 }
7288#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007289#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007290 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007291 {
7292 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007293 char_u *q = curwin->w_s->b_p_spl;
7294
7295 /* Skip the first name if it is "cjk". */
7296 if (STRNCMP(q, "cjk,", 4) == 0)
7297 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007298
7299 /*
7300 * Source the spell/LANG.vim in 'runtimepath'.
7301 * They could set 'spellcapcheck' depending on the language.
7302 * Use the first name in 'spelllang' up to '_region' or
7303 * '.encoding'.
7304 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007305 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007306 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7307 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007308 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007309 source_runtime(fname, TRUE);
7310 }
7311#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007312 }
7313
7314#ifdef FEAT_MOUSE
7315 if (varp == &p_mouse)
7316 {
7317# ifdef FEAT_MOUSE_TTY
7318 if (*p_mouse == NUL)
7319 mch_setmouse(FALSE); /* switch mouse off */
7320 else
7321# endif
7322 setmouse(); /* in case 'mouse' changed */
7323 }
7324#endif
7325
Bram Moolenaar913077c2012-03-28 19:59:04 +02007326 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007327 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007328 curwin->w_set_curswant = TRUE;
7329
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007330#ifdef FEAT_GUI
7331 /* check redraw when it's not a GUI option or the GUI is active. */
7332 if (!redraw_gui_only || gui.in_use)
7333#endif
7334 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007335
7336 return errmsg;
7337}
7338
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007339#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007340/*
7341 * Simple int comparison function for use with qsort()
7342 */
7343 static int
7344int_cmp(a, b)
7345 const void *a;
7346 const void *b;
7347{
7348 return *(const int *)a - *(const int *)b;
7349}
7350
7351/*
7352 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7353 * Returns error message, NULL if it's OK.
7354 */
7355 char_u *
7356check_colorcolumn(wp)
7357 win_T *wp;
7358{
7359 char_u *s;
7360 int col;
7361 int count = 0;
7362 int color_cols[256];
7363 int i;
7364 int j = 0;
7365
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007366 if (wp->w_buffer == NULL)
7367 return NULL; /* buffer was closed */
7368
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007369 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007370 {
7371 if (*s == '-' || *s == '+')
7372 {
7373 /* -N and +N: add to 'textwidth' */
7374 col = (*s == '-') ? -1 : 1;
7375 ++s;
7376 if (!VIM_ISDIGIT(*s))
7377 return e_invarg;
7378 col = col * getdigits(&s);
7379 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007380 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007381 col += wp->w_buffer->b_p_tw;
7382 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007383 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007384 }
7385 else if (VIM_ISDIGIT(*s))
7386 col = getdigits(&s);
7387 else
7388 return e_invarg;
7389 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007390skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007391 if (*s == NUL)
7392 break;
7393 if (*s != ',')
7394 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007395 if (*++s == NUL)
7396 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007397 }
7398
7399 vim_free(wp->w_p_cc_cols);
7400 if (count == 0)
7401 wp->w_p_cc_cols = NULL;
7402 else
7403 {
7404 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7405 if (wp->w_p_cc_cols != NULL)
7406 {
7407 /* sort the columns for faster usage on screen redraw inside
7408 * win_line() */
7409 qsort(color_cols, count, sizeof(int), int_cmp);
7410
7411 for (i = 0; i < count; ++i)
7412 /* skip duplicates */
7413 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7414 wp->w_p_cc_cols[j++] = color_cols[i];
7415 wp->w_p_cc_cols[j] = -1; /* end marker */
7416 }
7417 }
7418
7419 return NULL; /* no error */
7420}
7421#endif
7422
Bram Moolenaar071d4272004-06-13 20:20:40 +00007423/*
7424 * Handle setting 'listchars' or 'fillchars'.
7425 * Returns error message, NULL if it's OK.
7426 */
7427 static char_u *
7428set_chars_option(varp)
7429 char_u **varp;
7430{
7431 int round, i, len, entries;
7432 char_u *p, *s;
7433 int c1, c2 = 0;
7434 struct charstab
7435 {
7436 int *cp;
7437 char *name;
7438 };
7439#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7440 static struct charstab filltab[] =
7441 {
7442 {&fill_stl, "stl"},
7443 {&fill_stlnc, "stlnc"},
7444 {&fill_vert, "vert"},
7445 {&fill_fold, "fold"},
7446 {&fill_diff, "diff"},
7447 };
7448#endif
7449 static struct charstab lcstab[] =
7450 {
7451 {&lcs_eol, "eol"},
7452 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007453 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007454 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007455 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007456 {&lcs_tab2, "tab"},
7457 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007458#ifdef FEAT_CONCEAL
7459 {&lcs_conceal, "conceal"},
7460#else
7461 {NULL, "conceal"},
7462#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463 };
7464 struct charstab *tab;
7465
7466#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7467 if (varp == &p_lcs)
7468#endif
7469 {
7470 tab = lcstab;
7471 entries = sizeof(lcstab) / sizeof(struct charstab);
7472 }
7473#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7474 else
7475 {
7476 tab = filltab;
7477 entries = sizeof(filltab) / sizeof(struct charstab);
7478 }
7479#endif
7480
7481 /* first round: check for valid value, second round: assign values */
7482 for (round = 0; round <= 1; ++round)
7483 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007484 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485 {
7486 /* After checking that the value is valid: set defaults: space for
7487 * 'fillchars', NUL for 'listchars' */
7488 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007489 if (tab[i].cp != NULL)
7490 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 if (varp == &p_lcs)
7492 lcs_tab1 = NUL;
7493#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7494 else
7495 fill_diff = '-';
7496#endif
7497 }
7498 p = *varp;
7499 while (*p)
7500 {
7501 for (i = 0; i < entries; ++i)
7502 {
7503 len = (int)STRLEN(tab[i].name);
7504 if (STRNCMP(p, tab[i].name, len) == 0
7505 && p[len] == ':'
7506 && p[len + 1] != NUL)
7507 {
7508 s = p + len + 1;
7509#ifdef FEAT_MBYTE
7510 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007511 if (mb_char2cells(c1) > 1)
7512 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513#else
7514 c1 = *s++;
7515#endif
7516 if (tab[i].cp == &lcs_tab2)
7517 {
7518 if (*s == NUL)
7519 continue;
7520#ifdef FEAT_MBYTE
7521 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007522 if (mb_char2cells(c2) > 1)
7523 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007524#else
7525 c2 = *s++;
7526#endif
7527 }
7528 if (*s == ',' || *s == NUL)
7529 {
7530 if (round)
7531 {
7532 if (tab[i].cp == &lcs_tab2)
7533 {
7534 lcs_tab1 = c1;
7535 lcs_tab2 = c2;
7536 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007537 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007538 *(tab[i].cp) = c1;
7539
7540 }
7541 p = s;
7542 break;
7543 }
7544 }
7545 }
7546
7547 if (i == entries)
7548 return e_invarg;
7549 if (*p == ',')
7550 ++p;
7551 }
7552 }
7553
7554 return NULL; /* no error */
7555}
7556
7557#ifdef FEAT_STL_OPT
7558/*
7559 * Check validity of options with the 'statusline' format.
7560 * Return error message or NULL.
7561 */
7562 char_u *
7563check_stl_option(s)
7564 char_u *s;
7565{
7566 int itemcnt = 0;
7567 int groupdepth = 0;
7568 static char_u errbuf[80];
7569
7570 while (*s && itemcnt < STL_MAX_ITEM)
7571 {
7572 /* Check for valid keys after % sequences */
7573 while (*s && *s != '%')
7574 s++;
7575 if (!*s)
7576 break;
7577 s++;
7578 if (*s != '%' && *s != ')')
7579 ++itemcnt;
7580 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7581 {
7582 s++;
7583 continue;
7584 }
7585 if (*s == ')')
7586 {
7587 s++;
7588 if (--groupdepth < 0)
7589 break;
7590 continue;
7591 }
7592 if (*s == '-')
7593 s++;
7594 while (VIM_ISDIGIT(*s))
7595 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007596 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007597 continue;
7598 if (*s == '.')
7599 {
7600 s++;
7601 while (*s && VIM_ISDIGIT(*s))
7602 s++;
7603 }
7604 if (*s == '(')
7605 {
7606 groupdepth++;
7607 continue;
7608 }
7609 if (vim_strchr(STL_ALL, *s) == NULL)
7610 {
7611 return illegal_char(errbuf, *s);
7612 }
7613 if (*s == '{')
7614 {
7615 s++;
7616 while (*s != '}' && *s)
7617 s++;
7618 if (*s != '}')
7619 return (char_u *)N_("E540: Unclosed expression sequence");
7620 }
7621 }
7622 if (itemcnt >= STL_MAX_ITEM)
7623 return (char_u *)N_("E541: too many items");
7624 if (groupdepth != 0)
7625 return (char_u *)N_("E542: unbalanced groups");
7626 return NULL;
7627}
7628#endif
7629
7630#ifdef FEAT_CLIPBOARD
7631/*
7632 * Extract the items in the 'clipboard' option and set global values.
7633 */
7634 static char_u *
7635check_clipboard_option()
7636{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007637 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007638 int new_autoselect_star = FALSE;
7639 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007640 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007641 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007642 regprog_T *new_exclude_prog = NULL;
7643 char_u *errmsg = NULL;
7644 char_u *p;
7645
7646 for (p = p_cb; *p != NUL; )
7647 {
7648 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7649 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007650 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007651 p += 7;
7652 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007653 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007654 && (p[11] == ',' || p[11] == NUL))
7655 {
7656 new_unnamed |= CLIP_UNNAMED_PLUS;
7657 p += 11;
7658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007660 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007662 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007663 p += 10;
7664 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007665 else if (STRNCMP(p, "autoselectplus", 14) == 0
7666 && (p[14] == ',' || p[14] == NUL))
7667 {
7668 new_autoselect_plus = TRUE;
7669 p += 14;
7670 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007671 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007672 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007673 {
7674 new_autoselectml = TRUE;
7675 p += 12;
7676 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007677 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7678 {
7679 new_html = TRUE;
7680 p += 4;
7681 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7683 {
7684 p += 8;
7685 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7686 if (new_exclude_prog == NULL)
7687 errmsg = e_invarg;
7688 break;
7689 }
7690 else
7691 {
7692 errmsg = e_invarg;
7693 break;
7694 }
7695 if (*p == ',')
7696 ++p;
7697 }
7698 if (errmsg == NULL)
7699 {
7700 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007701 clip_autoselect_star = new_autoselect_star;
7702 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007703 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007704 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007705 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007707#ifdef FEAT_GUI_GTK
7708 if (gui.in_use)
7709 {
7710 gui_gtk_set_selection_targets();
7711 gui_gtk_set_dnd_targets();
7712 }
7713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007714 }
7715 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007716 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007717
7718 return errmsg;
7719}
7720#endif
7721
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007722#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007723 static char_u *
7724did_set_spell_option(is_spellfile)
7725 int is_spellfile;
7726{
7727 char_u *errmsg = NULL;
7728 win_T *wp;
7729 int l;
7730
7731 if (is_spellfile)
7732 {
7733 l = (int)STRLEN(curwin->w_s->b_p_spf);
7734 if (l > 0 && (l < 4
7735 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7736 errmsg = e_invarg;
7737 }
7738
7739 if (errmsg == NULL)
7740 {
7741 FOR_ALL_WINDOWS(wp)
7742 if (wp->w_buffer == curbuf && wp->w_p_spell)
7743 {
7744 errmsg = did_set_spelllang(wp);
7745# ifdef FEAT_WINDOWS
7746 break;
7747# endif
7748 }
7749 }
7750 return errmsg;
7751}
7752
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007753/*
7754 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7755 * Return error message when failed, NULL when OK.
7756 */
7757 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007758compile_cap_prog(synblock)
7759 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007760{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007761 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007762 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007763
Bram Moolenaar860cae12010-06-05 23:22:07 +02007764 if (*synblock->b_p_spc == NUL)
7765 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007766 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007767 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007768 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007769 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007770 if (re != NULL)
7771 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007772 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007773 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007774 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007775 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007776 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007777 return e_invarg;
7778 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007779 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007780 }
7781
Bram Moolenaar473de612013-06-08 18:19:48 +02007782 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007783 return NULL;
7784}
7785#endif
7786
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007787#if defined(FEAT_EVAL) || defined(PROTO)
7788/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007789 * Set the scriptID for an option, taking care of setting the buffer- or
7790 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007791 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007792 static void
7793set_option_scriptID_idx(opt_idx, opt_flags, id)
7794 int opt_idx;
7795 int opt_flags;
7796 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007797{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007798 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7799 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007800
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007801 /* Remember where the option was set. For local options need to do that
7802 * in the buffer or window structure. */
7803 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007804 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007805 if (both || (opt_flags & OPT_LOCAL))
7806 {
7807 if (indir & PV_BUF)
7808 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7809 else if (indir & PV_WIN)
7810 curwin->w_p_scriptID[indir & PV_MASK] = id;
7811 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007812}
7813#endif
7814
Bram Moolenaar071d4272004-06-13 20:20:40 +00007815/*
7816 * Set the value of a boolean option, and take care of side effects.
7817 * Returns NULL for success, or an error message for an error.
7818 */
7819 static char_u *
7820set_bool_option(opt_idx, varp, value, opt_flags)
7821 int opt_idx; /* index in options[] table */
7822 char_u *varp; /* pointer to the option variable */
7823 int value; /* new value */
7824 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7825{
7826 int old_value = *(int *)varp;
7827
Bram Moolenaar071d4272004-06-13 20:20:40 +00007828 /* Disallow changing some options from secure mode */
7829 if ((secure
7830#ifdef HAVE_SANDBOX
7831 || sandbox != 0
7832#endif
7833 ) && (options[opt_idx].flags & P_SECURE))
7834 return e_secure;
7835
7836 *(int *)varp = value; /* set the new value */
7837#ifdef FEAT_EVAL
7838 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007839 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007840#endif
7841
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007842#ifdef FEAT_GUI
7843 need_mouse_correct = TRUE;
7844#endif
7845
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846 /* May set global value for local option. */
7847 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7848 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7849
7850 /*
7851 * Handle side effects of changing a bool option.
7852 */
7853
7854 /* 'compatible' */
7855 if ((int *)varp == &p_cp)
7856 {
7857 compatible_set();
7858 }
7859
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007860#ifdef FEAT_PERSISTENT_UNDO
7861 /* 'undofile' */
7862 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7863 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007864 /* Only take action when the option was set. When reset we do not
7865 * delete the undo file, the option may be set again without making
7866 * any changes in between. */
7867 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007868 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007869 char_u hash[UNDO_HASH_SIZE];
7870 buf_T *save_curbuf = curbuf;
7871
7872 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007873 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007874 /* When 'undofile' is set globally: for every buffer, otherwise
7875 * only for the current buffer: Try to read in the undofile,
7876 * if one exists, the buffer wasn't changed and the buffer was
7877 * loaded */
7878 if ((curbuf == save_curbuf
7879 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7880 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7881 {
7882 u_compute_hash(hash);
7883 u_read_undo(NULL, hash, curbuf->b_fname);
7884 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007885 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007886 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007887 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007888 }
7889#endif
7890
Bram Moolenaar071d4272004-06-13 20:20:40 +00007891 else if ((int *)varp == &curbuf->b_p_ro)
7892 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007893 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7895 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007896
7897 /* when 'readonly' is set may give W10 again */
7898 if (curbuf->b_p_ro)
7899 curbuf->b_did_warn = FALSE;
7900
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007902 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903#endif
7904 }
7905
Bram Moolenaar9c449722010-07-20 18:44:27 +02007906#ifdef FEAT_GUI
7907 else if ((int *)varp == &p_mh)
7908 {
7909 if (!p_mh)
7910 gui_mch_mousehide(FALSE);
7911 }
7912#endif
7913
Bram Moolenaara539df02010-08-01 14:35:05 +02007914#ifdef FEAT_TITLE
7915 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007916 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007917 {
7918 redraw_titles();
7919 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007920 /* when 'endofline' is changed, redraw the window title */
7921 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007922 {
7923 redraw_titles();
7924 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007925 /* when 'fixeol' is changed, redraw the window title */
7926 else if ((int *)varp == &curbuf->b_p_fixeol)
7927 {
7928 redraw_titles();
7929 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007930# ifdef FEAT_MBYTE
7931 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007932 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007933 {
7934 redraw_titles();
7935 }
7936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937#endif
7938
7939 /* when 'bin' is set also set some other options */
7940 else if ((int *)varp == &curbuf->b_p_bin)
7941 {
7942 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7943#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007944 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945#endif
7946 }
7947
7948#ifdef FEAT_AUTOCMD
7949 /* when 'buflisted' changes, trigger autocommands */
7950 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7951 {
7952 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7953 NULL, NULL, TRUE, curbuf);
7954 }
7955#endif
7956
7957 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7958 else if ((int *)varp == &curbuf->b_p_swf)
7959 {
7960 if (curbuf->b_p_swf && p_uc)
7961 ml_open_file(curbuf); /* create the swap file */
7962 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007963 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7964 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007965 mf_close_file(curbuf, TRUE); /* remove the swap file */
7966 }
7967
7968 /* when 'terse' is set change 'shortmess' */
7969 else if ((int *)varp == &p_terse)
7970 {
7971 char_u *p;
7972
7973 p = vim_strchr(p_shm, SHM_SEARCH);
7974
7975 /* insert 's' in p_shm */
7976 if (p_terse && p == NULL)
7977 {
7978 STRCPY(IObuff, p_shm);
7979 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007980 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981 }
7982 /* remove 's' from p_shm */
7983 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007984 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 }
7986
7987 /* when 'paste' is set or reset also change other options */
7988 else if ((int *)varp == &p_paste)
7989 {
7990 paste_option_changed();
7991 }
7992
7993 /* when 'insertmode' is set from an autocommand need to do work here */
7994 else if ((int *)varp == &p_im)
7995 {
7996 if (p_im)
7997 {
7998 if ((State & INSERT) == 0)
7999 need_start_insertmode = TRUE;
8000 stop_insert_mode = FALSE;
8001 }
8002 else
8003 {
8004 need_start_insertmode = FALSE;
8005 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008006 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 clear_cmdline = TRUE; /* remove "(insert)" */
8008 restart_edit = 0;
8009 }
8010 }
8011
8012 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8013 else if ((int *)varp == &p_ic && p_hls)
8014 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008015 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 }
8017
8018#ifdef FEAT_SEARCH_EXTRA
8019 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8020 else if ((int *)varp == &p_hls)
8021 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008022 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008023 }
8024#endif
8025
8026#ifdef FEAT_SCROLLBIND
8027 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8028 * at the end of normal_cmd() */
8029 else if ((int *)varp == &curwin->w_p_scb)
8030 {
8031 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008032 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008033 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008034 curwin->w_scbind_pos = curwin->w_topline;
8035 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008036 }
8037#endif
8038
8039#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8040 /* There can be only one window with 'previewwindow' set. */
8041 else if ((int *)varp == &curwin->w_p_pvw)
8042 {
8043 if (curwin->w_p_pvw)
8044 {
8045 win_T *win;
8046
8047 for (win = firstwin; win != NULL; win = win->w_next)
8048 if (win->w_p_pvw && win != curwin)
8049 {
8050 curwin->w_p_pvw = FALSE;
8051 return (char_u *)N_("E590: A preview window already exists");
8052 }
8053 }
8054 }
8055#endif
8056
8057 /* when 'textmode' is set or reset also change 'fileformat' */
8058 else if ((int *)varp == &curbuf->b_p_tx)
8059 {
8060 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8061 }
8062
8063 /* when 'textauto' is set or reset also change 'fileformats' */
8064 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008065 set_string_option_direct((char_u *)"ffs", -1,
8066 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008067 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008068
8069 /*
8070 * When 'lisp' option changes include/exclude '-' in
8071 * keyword characters.
8072 */
8073#ifdef FEAT_LISP
8074 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8075 {
8076 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8077 }
8078#endif
8079
8080#ifdef FEAT_TITLE
8081 /* when 'title' changed, may need to change the title; same for 'icon' */
8082 else if ((int *)varp == &p_title)
8083 {
8084 did_set_title(FALSE);
8085 }
8086
8087 else if ((int *)varp == &p_icon)
8088 {
8089 did_set_title(TRUE);
8090 }
8091#endif
8092
8093 else if ((int *)varp == &curbuf->b_changed)
8094 {
8095 if (!value)
8096 save_file_ff(curbuf); /* Buffer is unchanged */
8097#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008098 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008099#endif
8100#ifdef FEAT_AUTOCMD
8101 modified_was_set = value;
8102#endif
8103 }
8104
8105#ifdef BACKSLASH_IN_FILENAME
8106 else if ((int *)varp == &p_ssl)
8107 {
8108 if (p_ssl)
8109 {
8110 psepc = '/';
8111 psepcN = '\\';
8112 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008113 }
8114 else
8115 {
8116 psepc = '\\';
8117 psepcN = '/';
8118 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008119 }
8120
8121 /* need to adjust the file name arguments and buffer names. */
8122 buflist_slash_adjust();
8123 alist_slash_adjust();
8124# ifdef FEAT_EVAL
8125 scriptnames_slash_adjust();
8126# endif
8127 }
8128#endif
8129
8130 /* If 'wrap' is set, set w_leftcol to zero. */
8131 else if ((int *)varp == &curwin->w_p_wrap)
8132 {
8133 if (curwin->w_p_wrap)
8134 curwin->w_leftcol = 0;
8135 }
8136
8137#ifdef FEAT_WINDOWS
8138 else if ((int *)varp == &p_ea)
8139 {
8140 if (p_ea && !old_value)
8141 win_equal(curwin, FALSE, 0);
8142 }
8143#endif
8144
8145 else if ((int *)varp == &p_wiv)
8146 {
8147 /*
8148 * When 'weirdinvert' changed, set/reset 't_xs'.
8149 * Then set 'weirdinvert' according to value of 't_xs'.
8150 */
8151 if (p_wiv && !old_value)
8152 T_XS = (char_u *)"y";
8153 else if (!p_wiv && old_value)
8154 T_XS = empty_option;
8155 p_wiv = (*T_XS != NUL);
8156 }
8157
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008158#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159 else if ((int *)varp == &p_beval)
8160 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008161 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008162 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008163 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164 gui_mch_disable_beval_area(balloonEval);
8165 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008166#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008168#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 else if ((int *)varp == &p_acd)
8170 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008171 /* Change directories when the 'acd' option is set now. */
8172 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 }
8174#endif
8175
8176#ifdef FEAT_DIFF
8177 /* 'diff' */
8178 else if ((int *)varp == &curwin->w_p_diff)
8179 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008180 /* May add or remove the buffer from the list of diff buffers. */
8181 diff_buf_adjust(curwin);
8182# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008183 if (foldmethodIsDiff(curwin))
8184 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008185# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008186 }
8187#endif
8188
8189#ifdef USE_IM_CONTROL
8190 /* 'imdisable' */
8191 else if ((int *)varp == &p_imdisable)
8192 {
8193 /* Only de-activate it here, it will be enabled when changing mode. */
8194 if (p_imdisable)
8195 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008196 else if (State & INSERT)
8197 /* When the option is set from an autocommand, it may need to take
8198 * effect right away. */
8199 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200 }
8201#endif
8202
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008203#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008204 /* 'spell' */
8205 else if ((int *)varp == &curwin->w_p_spell)
8206 {
8207 if (curwin->w_p_spell)
8208 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008209 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008210 if (errmsg != NULL)
8211 EMSG(_(errmsg));
8212 }
8213 }
8214#endif
8215
Bram Moolenaar071d4272004-06-13 20:20:40 +00008216#ifdef FEAT_FKMAP
8217 else if ((int *)varp == &p_altkeymap)
8218 {
8219 if (old_value != p_altkeymap)
8220 {
8221 if (!p_altkeymap)
8222 {
8223 p_hkmap = p_fkmap;
8224 p_fkmap = 0;
8225 }
8226 else
8227 {
8228 p_fkmap = p_hkmap;
8229 p_hkmap = 0;
8230 }
8231 (void)init_chartab();
8232 }
8233 }
8234
8235 /*
8236 * In case some second language keymapping options have changed, check
8237 * and correct the setting in a consistent way.
8238 */
8239
8240 /*
8241 * If hkmap or fkmap are set, reset Arabic keymapping.
8242 */
8243 if ((p_hkmap || p_fkmap) && p_altkeymap)
8244 {
8245 p_altkeymap = p_fkmap;
8246# ifdef FEAT_ARABIC
8247 curwin->w_p_arab = FALSE;
8248# endif
8249 (void)init_chartab();
8250 }
8251
8252 /*
8253 * If hkmap set, reset Farsi keymapping.
8254 */
8255 if (p_hkmap && p_altkeymap)
8256 {
8257 p_altkeymap = 0;
8258 p_fkmap = 0;
8259# ifdef FEAT_ARABIC
8260 curwin->w_p_arab = FALSE;
8261# endif
8262 (void)init_chartab();
8263 }
8264
8265 /*
8266 * If fkmap set, reset Hebrew keymapping.
8267 */
8268 if (p_fkmap && !p_altkeymap)
8269 {
8270 p_altkeymap = 1;
8271 p_hkmap = 0;
8272# ifdef FEAT_ARABIC
8273 curwin->w_p_arab = FALSE;
8274# endif
8275 (void)init_chartab();
8276 }
8277#endif
8278
8279#ifdef FEAT_ARABIC
8280 if ((int *)varp == &curwin->w_p_arab)
8281 {
8282 if (curwin->w_p_arab)
8283 {
8284 /*
8285 * 'arabic' is set, handle various sub-settings.
8286 */
8287 if (!p_tbidi)
8288 {
8289 /* set rightleft mode */
8290 if (!curwin->w_p_rl)
8291 {
8292 curwin->w_p_rl = TRUE;
8293 changed_window_setting();
8294 }
8295
8296 /* Enable Arabic shaping (major part of what Arabic requires) */
8297 if (!p_arshape)
8298 {
8299 p_arshape = TRUE;
8300 redraw_later_clear();
8301 }
8302 }
8303
8304 /* Arabic requires a utf-8 encoding, inform the user if its not
8305 * set. */
8306 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008307 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008308 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8309
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008310 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008311 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8312#ifdef FEAT_EVAL
8313 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8314#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008315 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316
8317# ifdef FEAT_MBYTE
8318 /* set 'delcombine' */
8319 p_deco = TRUE;
8320# endif
8321
8322# ifdef FEAT_KEYMAP
8323 /* Force-set the necessary keymap for arabic */
8324 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8325 OPT_LOCAL);
8326# endif
8327# ifdef FEAT_FKMAP
8328 p_altkeymap = 0;
8329 p_hkmap = 0;
8330 p_fkmap = 0;
8331 (void)init_chartab();
8332# endif
8333 }
8334 else
8335 {
8336 /*
8337 * 'arabic' is reset, handle various sub-settings.
8338 */
8339 if (!p_tbidi)
8340 {
8341 /* reset rightleft mode */
8342 if (curwin->w_p_rl)
8343 {
8344 curwin->w_p_rl = FALSE;
8345 changed_window_setting();
8346 }
8347
8348 /* 'arabicshape' isn't reset, it is a global option and
8349 * another window may still need it "on". */
8350 }
8351
8352 /* 'delcombine' isn't reset, it is a global option and another
8353 * window may still want it "on". */
8354
8355# ifdef FEAT_KEYMAP
8356 /* Revert to the default keymap */
8357 curbuf->b_p_iminsert = B_IMODE_NONE;
8358 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8359# endif
8360 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008361 }
8362
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008363#endif
8364
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365 /*
8366 * End of handling side effects for bool options.
8367 */
8368
Bram Moolenaar53744302015-07-17 17:38:22 +02008369 /* after handling side effects, call autocommand */
8370
Bram Moolenaar071d4272004-06-13 20:20:40 +00008371 options[opt_idx].flags |= P_WAS_SET;
8372
Bram Moolenaar53744302015-07-17 17:38:22 +02008373#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8374 if (!starting)
8375 {
8376 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008377 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8378 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8379 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008380 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8381 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8382 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8383 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8384 reset_v_option_vars();
8385 }
8386#endif
8387
Bram Moolenaar071d4272004-06-13 20:20:40 +00008388 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008389 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008390 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008391 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008392 check_redraw(options[opt_idx].flags);
8393
8394 return NULL;
8395}
8396
8397/*
8398 * Set the value of a number option, and take care of side effects.
8399 * Returns NULL for success, or an error message for an error.
8400 */
8401 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008402set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 int opt_idx; /* index in options[] table */
8404 char_u *varp; /* pointer to the option variable */
8405 long value; /* new value */
8406 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008407 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8409 OPT_MODELINE */
8410{
8411 char_u *errmsg = NULL;
8412 long old_value = *(long *)varp;
8413 long old_Rows = Rows; /* remember old Rows */
8414 long old_Columns = Columns; /* remember old Columns */
8415 long *pp = (long *)varp;
8416
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008417 /* Disallow changing some options from secure mode. */
8418 if ((secure
8419#ifdef HAVE_SANDBOX
8420 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008422 ) && (options[opt_idx].flags & P_SECURE))
8423 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424
8425 *pp = value;
8426#ifdef FEAT_EVAL
8427 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008428 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008429#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008430#ifdef FEAT_GUI
8431 need_mouse_correct = TRUE;
8432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433
Bram Moolenaar14f24742012-08-08 18:01:05 +02008434 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008435 {
8436 errmsg = e_positive;
8437 curbuf->b_p_sw = curbuf->b_p_ts;
8438 }
8439
8440 /*
8441 * Number options that need some action when changed
8442 */
8443#ifdef FEAT_WINDOWS
8444 if (pp == &p_wh || pp == &p_hh)
8445 {
8446 if (p_wh < 1)
8447 {
8448 errmsg = e_positive;
8449 p_wh = 1;
8450 }
8451 if (p_wmh > p_wh)
8452 {
8453 errmsg = e_winheight;
8454 p_wh = p_wmh;
8455 }
8456 if (p_hh < 0)
8457 {
8458 errmsg = e_positive;
8459 p_hh = 0;
8460 }
8461
8462 /* Change window height NOW */
8463 if (lastwin != firstwin)
8464 {
8465 if (pp == &p_wh && curwin->w_height < p_wh)
8466 win_setheight((int)p_wh);
8467 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8468 win_setheight((int)p_hh);
8469 }
8470 }
8471
8472 /* 'winminheight' */
8473 else if (pp == &p_wmh)
8474 {
8475 if (p_wmh < 0)
8476 {
8477 errmsg = e_positive;
8478 p_wmh = 0;
8479 }
8480 if (p_wmh > p_wh)
8481 {
8482 errmsg = e_winheight;
8483 p_wmh = p_wh;
8484 }
8485 win_setminheight();
8486 }
8487
8488# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008489 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008490 {
8491 if (p_wiw < 1)
8492 {
8493 errmsg = e_positive;
8494 p_wiw = 1;
8495 }
8496 if (p_wmw > p_wiw)
8497 {
8498 errmsg = e_winwidth;
8499 p_wiw = p_wmw;
8500 }
8501
8502 /* Change window width NOW */
8503 if (lastwin != firstwin && curwin->w_width < p_wiw)
8504 win_setwidth((int)p_wiw);
8505 }
8506
8507 /* 'winminwidth' */
8508 else if (pp == &p_wmw)
8509 {
8510 if (p_wmw < 0)
8511 {
8512 errmsg = e_positive;
8513 p_wmw = 0;
8514 }
8515 if (p_wmw > p_wiw)
8516 {
8517 errmsg = e_winwidth;
8518 p_wmw = p_wiw;
8519 }
8520 win_setminheight();
8521 }
8522# endif
8523
8524#endif
8525
8526#ifdef FEAT_WINDOWS
8527 /* (re)set last window status line */
8528 else if (pp == &p_ls)
8529 {
8530 last_status(FALSE);
8531 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008532
8533 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008534 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008535 {
8536 shell_new_rows(); /* recompute window positions and heights */
8537 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538#endif
8539
8540#ifdef FEAT_GUI
8541 else if (pp == &p_linespace)
8542 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008543 /* Recompute gui.char_height and resize the Vim window to keep the
8544 * same number of lines. */
8545 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008546 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008547 }
8548#endif
8549
8550#ifdef FEAT_FOLDING
8551 /* 'foldlevel' */
8552 else if (pp == &curwin->w_p_fdl)
8553 {
8554 if (curwin->w_p_fdl < 0)
8555 curwin->w_p_fdl = 0;
8556 newFoldLevel();
8557 }
8558
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008559 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560 else if (pp == &curwin->w_p_fml)
8561 {
8562 foldUpdateAll(curwin);
8563 }
8564
8565 /* 'foldnestmax' */
8566 else if (pp == &curwin->w_p_fdn)
8567 {
8568 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8569 foldUpdateAll(curwin);
8570 }
8571
8572 /* 'foldcolumn' */
8573 else if (pp == &curwin->w_p_fdc)
8574 {
8575 if (curwin->w_p_fdc < 0)
8576 {
8577 errmsg = e_positive;
8578 curwin->w_p_fdc = 0;
8579 }
8580 else if (curwin->w_p_fdc > 12)
8581 {
8582 errmsg = e_invarg;
8583 curwin->w_p_fdc = 12;
8584 }
8585 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008586#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008588#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008589 /* 'shiftwidth' or 'tabstop' */
8590 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8591 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008592# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008593 if (foldmethodIsIndent(curwin))
8594 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008595# endif
8596# ifdef FEAT_CINDENT
8597 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8598 * parse 'cinoptions'. */
8599 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8600 parse_cino(curbuf);
8601# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008602 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008603#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008604
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008605#ifdef FEAT_MBYTE
8606 /* 'maxcombine' */
8607 else if (pp == &p_mco)
8608 {
8609 if (p_mco > MAX_MCO)
8610 p_mco = MAX_MCO;
8611 else if (p_mco < 0)
8612 p_mco = 0;
8613 screenclear(); /* will re-allocate the screen */
8614 }
8615#endif
8616
Bram Moolenaar071d4272004-06-13 20:20:40 +00008617 else if (pp == &curbuf->b_p_iminsert)
8618 {
8619 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8620 {
8621 errmsg = e_invarg;
8622 curbuf->b_p_iminsert = B_IMODE_NONE;
8623 }
8624 p_iminsert = curbuf->b_p_iminsert;
8625 if (termcap_active) /* don't do this in the alternate screen */
8626 showmode();
8627#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8628 /* Show/unshow value of 'keymap' in status lines. */
8629 status_redraw_curbuf();
8630#endif
8631 }
8632
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008633 else if (pp == &p_window)
8634 {
8635 if (p_window < 1)
8636 p_window = 1;
8637 else if (p_window >= Rows)
8638 p_window = Rows - 1;
8639 }
8640
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 else if (pp == &curbuf->b_p_imsearch)
8642 {
8643 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8644 {
8645 errmsg = e_invarg;
8646 curbuf->b_p_imsearch = B_IMODE_NONE;
8647 }
8648 p_imsearch = curbuf->b_p_imsearch;
8649 }
8650
8651#ifdef FEAT_TITLE
8652 /* if 'titlelen' has changed, redraw the title */
8653 else if (pp == &p_titlelen)
8654 {
8655 if (p_titlelen < 0)
8656 {
8657 errmsg = e_positive;
8658 p_titlelen = 85;
8659 }
8660 if (starting != NO_SCREEN && old_value != p_titlelen)
8661 need_maketitle = TRUE;
8662 }
8663#endif
8664
8665 /* if p_ch changed value, change the command line height */
8666 else if (pp == &p_ch)
8667 {
8668 if (p_ch < 1)
8669 {
8670 errmsg = e_positive;
8671 p_ch = 1;
8672 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008673 if (p_ch > Rows - min_rows() + 1)
8674 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008675
8676 /* Only compute the new window layout when startup has been
8677 * completed. Otherwise the frame sizes may be wrong. */
8678 if (p_ch != old_value && full_screen
8679#ifdef FEAT_GUI
8680 && !gui.starting
8681#endif
8682 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008683 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684 }
8685
8686 /* when 'updatecount' changes from zero to non-zero, open swap files */
8687 else if (pp == &p_uc)
8688 {
8689 if (p_uc < 0)
8690 {
8691 errmsg = e_positive;
8692 p_uc = 100;
8693 }
8694 if (p_uc && !old_value)
8695 ml_open_files();
8696 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008697#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008698 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008699 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008700 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008701 {
8702 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008703 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008704 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008705 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008706 {
8707 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008708 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008709 }
8710 }
8711#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008712#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008713 else if (pp == &p_mzq)
8714 mzvim_reset_timer();
8715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008716
8717 /* sync undo before 'undolevels' changes */
8718 else if (pp == &p_ul)
8719 {
8720 /* use the old value, otherwise u_sync() may not work properly */
8721 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008722 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723 p_ul = value;
8724 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008725 else if (pp == &curbuf->b_p_ul)
8726 {
8727 /* use the old value, otherwise u_sync() may not work properly */
8728 curbuf->b_p_ul = old_value;
8729 u_sync(TRUE);
8730 curbuf->b_p_ul = value;
8731 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008733#ifdef FEAT_LINEBREAK
8734 /* 'numberwidth' must be positive */
8735 else if (pp == &curwin->w_p_nuw)
8736 {
8737 if (curwin->w_p_nuw < 1)
8738 {
8739 errmsg = e_positive;
8740 curwin->w_p_nuw = 1;
8741 }
8742 if (curwin->w_p_nuw > 10)
8743 {
8744 errmsg = e_invarg;
8745 curwin->w_p_nuw = 10;
8746 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008747 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008748 }
8749#endif
8750
Bram Moolenaar1a384422010-07-14 19:53:30 +02008751 else if (pp == &curbuf->b_p_tw)
8752 {
8753 if (curbuf->b_p_tw < 0)
8754 {
8755 errmsg = e_positive;
8756 curbuf->b_p_tw = 0;
8757 }
8758#ifdef FEAT_SYN_HL
8759# ifdef FEAT_WINDOWS
8760 {
8761 win_T *wp;
8762 tabpage_T *tp;
8763
8764 FOR_ALL_TAB_WINDOWS(tp, wp)
8765 check_colorcolumn(wp);
8766 }
8767# else
8768 check_colorcolumn(curwin);
8769# endif
8770#endif
8771 }
8772
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773 /*
8774 * Check the bounds for numeric options here
8775 */
8776 if (Rows < min_rows() && full_screen)
8777 {
8778 if (errbuf != NULL)
8779 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008780 vim_snprintf((char *)errbuf, errbuflen,
8781 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008782 errmsg = errbuf;
8783 }
8784 Rows = min_rows();
8785 }
8786 if (Columns < MIN_COLUMNS && full_screen)
8787 {
8788 if (errbuf != NULL)
8789 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008790 vim_snprintf((char *)errbuf, errbuflen,
8791 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008792 errmsg = errbuf;
8793 }
8794 Columns = MIN_COLUMNS;
8795 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008796 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797
8798#ifdef DJGPP
8799 /* avoid a crash by checking for a too large value of 'columns' */
8800 if (old_Columns != Columns && full_screen && term_console)
8801 mch_check_columns();
8802#endif
8803
8804 /*
8805 * If the screen (shell) height has been changed, assume it is the
8806 * physical screenheight.
8807 */
8808 if (old_Rows != Rows || old_Columns != Columns)
8809 {
8810 /* Changing the screen size is not allowed while updating the screen. */
8811 if (updating_screen)
8812 *pp = old_value;
8813 else if (full_screen
8814#ifdef FEAT_GUI
8815 && !gui.starting
8816#endif
8817 )
8818 set_shellsize((int)Columns, (int)Rows, TRUE);
8819 else
8820 {
8821 /* Postpone the resizing; check the size and cmdline position for
8822 * messages. */
8823 check_shellsize();
8824 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8825 cmdline_row = Rows - p_ch;
8826 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008827 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008828 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008829 }
8830
Bram Moolenaar071d4272004-06-13 20:20:40 +00008831 if (curbuf->b_p_ts <= 0)
8832 {
8833 errmsg = e_positive;
8834 curbuf->b_p_ts = 8;
8835 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008836 if (p_tm < 0)
8837 {
8838 errmsg = e_positive;
8839 p_tm = 0;
8840 }
8841 if ((curwin->w_p_scr <= 0
8842 || (curwin->w_p_scr > curwin->w_height
8843 && curwin->w_height > 0))
8844 && full_screen)
8845 {
8846 if (pp == &(curwin->w_p_scr))
8847 {
8848 if (curwin->w_p_scr != 0)
8849 errmsg = e_scroll;
8850 win_comp_scroll(curwin);
8851 }
8852 /* If 'scroll' became invalid because of a side effect silently adjust
8853 * it. */
8854 else if (curwin->w_p_scr <= 0)
8855 curwin->w_p_scr = 1;
8856 else /* curwin->w_p_scr > curwin->w_height */
8857 curwin->w_p_scr = curwin->w_height;
8858 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008859 if (p_hi < 0)
8860 {
8861 errmsg = e_positive;
8862 p_hi = 0;
8863 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008864 else if (p_hi > 10000)
8865 {
8866 errmsg = e_invarg;
8867 p_hi = 10000;
8868 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008869 if (p_re < 0 || p_re > 2)
8870 {
8871 errmsg = e_invarg;
8872 p_re = 0;
8873 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874 if (p_report < 0)
8875 {
8876 errmsg = e_positive;
8877 p_report = 1;
8878 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008879 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880 {
8881 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8882 p_sj = Rows / 2;
8883 else
8884 {
8885 errmsg = e_scroll;
8886 p_sj = 1;
8887 }
8888 }
8889 if (p_so < 0 && full_screen)
8890 {
8891 errmsg = e_scroll;
8892 p_so = 0;
8893 }
8894 if (p_siso < 0 && full_screen)
8895 {
8896 errmsg = e_positive;
8897 p_siso = 0;
8898 }
8899#ifdef FEAT_CMDWIN
8900 if (p_cwh < 1)
8901 {
8902 errmsg = e_positive;
8903 p_cwh = 1;
8904 }
8905#endif
8906 if (p_ut < 0)
8907 {
8908 errmsg = e_positive;
8909 p_ut = 2000;
8910 }
8911 if (p_ss < 0)
8912 {
8913 errmsg = e_positive;
8914 p_ss = 0;
8915 }
8916
8917 /* May set global value for local option. */
8918 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8919 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8920
8921 options[opt_idx].flags |= P_WAS_SET;
8922
Bram Moolenaar53744302015-07-17 17:38:22 +02008923#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8924 if (!starting && errmsg == NULL)
8925 {
8926 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008927 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8928 vim_snprintf((char *)buf_new, 10, "%ld", value);
8929 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008930 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8931 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8932 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8933 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8934 reset_v_option_vars();
8935 }
8936#endif
8937
Bram Moolenaar071d4272004-06-13 20:20:40 +00008938 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008939 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008940 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008941 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942 check_redraw(options[opt_idx].flags);
8943
8944 return errmsg;
8945}
8946
8947/*
8948 * Called after an option changed: check if something needs to be redrawn.
8949 */
8950 static void
8951check_redraw(flags)
8952 long_u flags;
8953{
8954 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008955 int doclear = (flags & P_RCLR) == P_RCLR;
8956 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008957
8958#ifdef FEAT_WINDOWS
8959 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8960 status_redraw_all();
8961#endif
8962
8963 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8964 changed_window_setting();
8965 if (flags & P_RBUF)
8966 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008967 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008968 redraw_all_later(CLEAR);
8969 else if (all)
8970 redraw_all_later(NOT_VALID);
8971}
8972
8973/*
8974 * Find index for option 'arg'.
8975 * Return -1 if not found.
8976 */
8977 static int
8978findoption(arg)
8979 char_u *arg;
8980{
8981 int opt_idx;
8982 char *s, *p;
8983 static short quick_tab[27] = {0, 0}; /* quick access table */
8984 int is_term_opt;
8985
8986 /*
8987 * For first call: Initialize the quick-access table.
8988 * It contains the index for the first option that starts with a certain
8989 * letter. There are 26 letters, plus the first "t_" option.
8990 */
8991 if (quick_tab[1] == 0)
8992 {
8993 p = options[0].fullname;
8994 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8995 {
8996 if (s[0] != p[0])
8997 {
8998 if (s[0] == 't' && s[1] == '_')
8999 quick_tab[26] = opt_idx;
9000 else
9001 quick_tab[CharOrdLow(s[0])] = opt_idx;
9002 }
9003 p = s;
9004 }
9005 }
9006
9007 /*
9008 * Check for name starting with an illegal character.
9009 */
9010#ifdef EBCDIC
9011 if (!islower(arg[0]))
9012#else
9013 if (arg[0] < 'a' || arg[0] > 'z')
9014#endif
9015 return -1;
9016
9017 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9018 if (is_term_opt)
9019 opt_idx = quick_tab[26];
9020 else
9021 opt_idx = quick_tab[CharOrdLow(arg[0])];
9022 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9023 {
9024 if (STRCMP(arg, s) == 0) /* match full name */
9025 break;
9026 }
9027 if (s == NULL && !is_term_opt)
9028 {
9029 opt_idx = quick_tab[CharOrdLow(arg[0])];
9030 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9031 {
9032 s = options[opt_idx].shortname;
9033 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9034 break;
9035 s = NULL;
9036 }
9037 }
9038 if (s == NULL)
9039 opt_idx = -1;
9040 return opt_idx;
9041}
9042
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009043#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009044/*
9045 * Get the value for an option.
9046 *
9047 * Returns:
9048 * Number or Toggle option: 1, *numval gets value.
9049 * String option: 0, *stringval gets allocated string.
9050 * Hidden Number or Toggle option: -1.
9051 * hidden String option: -2.
9052 * unknown option: -3.
9053 */
9054 int
9055get_option_value(name, numval, stringval, opt_flags)
9056 char_u *name;
9057 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009058 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059 int opt_flags;
9060{
9061 int opt_idx;
9062 char_u *varp;
9063
9064 opt_idx = findoption(name);
9065 if (opt_idx < 0) /* unknown option */
9066 return -3;
9067
9068 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9069
9070 if (options[opt_idx].flags & P_STRING)
9071 {
9072 if (varp == NULL) /* hidden option */
9073 return -2;
9074 if (stringval != NULL)
9075 {
9076#ifdef FEAT_CRYPT
9077 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009078 if ((char_u **)varp == &curbuf->b_p_key
9079 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080 *stringval = vim_strsave((char_u *)"*****");
9081 else
9082#endif
9083 *stringval = vim_strsave(*(char_u **)(varp));
9084 }
9085 return 0;
9086 }
9087
9088 if (varp == NULL) /* hidden option */
9089 return -1;
9090 if (options[opt_idx].flags & P_NUM)
9091 *numval = *(long *)varp;
9092 else
9093 {
9094 /* Special case: 'modified' is b_changed, but we also want to consider
9095 * it set when 'ff' or 'fenc' changed. */
9096 if ((int *)varp == &curbuf->b_changed)
9097 *numval = curbufIsChanged();
9098 else
9099 *numval = *(int *)varp;
9100 }
9101 return 1;
9102}
9103#endif
9104
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009105#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009106/*
9107 * Returns the option attributes and its value. Unlike the above function it
9108 * will return either global value or local value of the option depending on
9109 * what was requested, but it will never return global value if it was
9110 * requested to return local one and vice versa. Neither it will return
9111 * buffer-local value if it was requested to return window-local one.
9112 *
9113 * Pretends that option is absent if it is not present in the requested scope
9114 * (i.e. has no global, window-local or buffer-local value depending on
9115 * opt_type). Uses
9116 *
9117 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009118 * 0 hidden or unknown option, also option that does not have requested
9119 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009120 * see SOPT_* in vim.h for other flags
9121 *
9122 * Possible opt_type values: see SREQ_* in vim.h
9123 */
9124 int
9125get_option_value_strict(name, numval, stringval, opt_type, from)
9126 char_u *name;
9127 long *numval;
9128 char_u **stringval; /* NULL when only obtaining attributes */
9129 int opt_type;
9130 void *from;
9131{
9132 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009133 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009134 struct vimoption *p;
9135 int r = 0;
9136
9137 opt_idx = findoption(name);
9138 if (opt_idx < 0)
9139 return 0;
9140
9141 p = &(options[opt_idx]);
9142
9143 /* Hidden option */
9144 if (p->var == NULL)
9145 return 0;
9146
9147 if (p->flags & P_BOOL)
9148 r |= SOPT_BOOL;
9149 else if (p->flags & P_NUM)
9150 r |= SOPT_NUM;
9151 else if (p->flags & P_STRING)
9152 r |= SOPT_STRING;
9153
9154 if (p->indir == PV_NONE)
9155 {
9156 if (opt_type == SREQ_GLOBAL)
9157 r |= SOPT_GLOBAL;
9158 else
9159 return 0; /* Did not request global-only option */
9160 }
9161 else
9162 {
9163 if (p->indir & PV_BOTH)
9164 r |= SOPT_GLOBAL;
9165 else if (opt_type == SREQ_GLOBAL)
9166 return 0; /* Requested global option */
9167
9168 if (p->indir & PV_WIN)
9169 {
9170 if (opt_type == SREQ_BUF)
9171 return 0; /* Did not request window-local option */
9172 else
9173 r |= SOPT_WIN;
9174 }
9175 else if (p->indir & PV_BUF)
9176 {
9177 if (opt_type == SREQ_WIN)
9178 return 0; /* Did not request buffer-local option */
9179 else
9180 r |= SOPT_BUF;
9181 }
9182 }
9183
9184 if (stringval == NULL)
9185 return r;
9186
9187 if (opt_type == SREQ_GLOBAL)
9188 varp = p->var;
9189 else
9190 {
9191 if (opt_type == SREQ_BUF)
9192 {
9193 /* Special case: 'modified' is b_changed, but we also want to
9194 * consider it set when 'ff' or 'fenc' changed. */
9195 if (p->indir == PV_MOD)
9196 {
9197 *numval = bufIsChanged((buf_T *) from);
9198 varp = NULL;
9199 }
9200#ifdef FEAT_CRYPT
9201 else if (p->indir == PV_KEY)
9202 {
9203 /* never return the value of the crypt key */
9204 *stringval = NULL;
9205 varp = NULL;
9206 }
9207#endif
9208 else
9209 {
9210 aco_save_T aco;
9211 aucmd_prepbuf(&aco, (buf_T *) from);
9212 varp = get_varp(p);
9213 aucmd_restbuf(&aco);
9214 }
9215 }
9216 else if (opt_type == SREQ_WIN)
9217 {
9218 win_T *save_curwin;
9219 save_curwin = curwin;
9220 curwin = (win_T *) from;
9221 curbuf = curwin->w_buffer;
9222 varp = get_varp(p);
9223 curwin = save_curwin;
9224 curbuf = curwin->w_buffer;
9225 }
9226 if (varp == p->var)
9227 return (r | SOPT_UNSET);
9228 }
9229
9230 if (varp != NULL)
9231 {
9232 if (p->flags & P_STRING)
9233 *stringval = vim_strsave(*(char_u **)(varp));
9234 else if (p->flags & P_NUM)
9235 *numval = *(long *) varp;
9236 else
9237 *numval = *(int *)varp;
9238 }
9239
9240 return r;
9241}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009242
9243/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009244 * Iterate over options. First argument is a pointer to a pointer to a
9245 * structure inside options[] array, second is option type like in the above
9246 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009247 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009248 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009249 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009250 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009251 * first argument to NULL.
9252 *
9253 * Returns full option name for current option on each call.
9254 */
9255 char_u *
9256option_iter_next(option, opt_type)
9257 void **option;
9258 int opt_type;
9259{
9260 struct vimoption *ret = NULL;
9261 do
9262 {
9263 if (*option == NULL)
9264 *option = (void *) options;
9265 else if (((struct vimoption *) (*option))->fullname == NULL)
9266 {
9267 *option = NULL;
9268 return NULL;
9269 }
9270 else
9271 *option = (void *) (((struct vimoption *) (*option)) + 1);
9272
9273 ret = ((struct vimoption *) (*option));
9274
9275 /* Hidden option */
9276 if (ret->var == NULL)
9277 {
9278 ret = NULL;
9279 continue;
9280 }
9281
9282 switch (opt_type)
9283 {
9284 case SREQ_GLOBAL:
9285 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9286 ret = NULL;
9287 break;
9288 case SREQ_BUF:
9289 if (!(ret->indir & PV_BUF))
9290 ret = NULL;
9291 break;
9292 case SREQ_WIN:
9293 if (!(ret->indir & PV_WIN))
9294 ret = NULL;
9295 break;
9296 default:
9297 EMSG2(_(e_intern2), "option_iter_next()");
9298 return NULL;
9299 }
9300 }
9301 while (ret == NULL);
9302
9303 return (char_u *)ret->fullname;
9304}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009305#endif
9306
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307/*
9308 * Set the value of option "name".
9309 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009310 *
9311 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009313 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009314set_option_value(name, number, string, opt_flags)
9315 char_u *name;
9316 long number;
9317 char_u *string;
9318 int opt_flags; /* OPT_LOCAL or 0 (both) */
9319{
9320 int opt_idx;
9321 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009322 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009323
9324 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009325 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009326 EMSG2(_("E355: Unknown option: %s"), name);
9327 else
9328 {
9329 flags = options[opt_idx].flags;
9330#ifdef HAVE_SANDBOX
9331 /* Disallow changing some options in the sandbox */
9332 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009333 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009335 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009338 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009339 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009340 else
9341 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009342 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343 if (varp != NULL) /* hidden option is not changed */
9344 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009345 if (number == 0 && string != NULL)
9346 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009347 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009348
9349 /* Either we are given a string or we are setting option
9350 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009351 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009352 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009353 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009354 {
9355 /* There's another character after zeros or the string
9356 * is empty. In both cases, we are trying to set a
9357 * num option using a string. */
9358 EMSG3(_("E521: Number required: &%s = '%s'"),
9359 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009360 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009361
9362 }
9363 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009365 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009366 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009368 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009369 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370 }
9371 }
9372 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009373 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009374}
9375
9376/*
9377 * Get the terminal code for a terminal option.
9378 * Returns NULL when not found.
9379 */
9380 char_u *
9381get_term_code(tname)
9382 char_u *tname;
9383{
9384 int opt_idx;
9385 char_u *varp;
9386
9387 if (tname[0] != 't' || tname[1] != '_' ||
9388 tname[2] == NUL || tname[3] == NUL)
9389 return NULL;
9390 if ((opt_idx = findoption(tname)) >= 0)
9391 {
9392 varp = get_varp(&(options[opt_idx]));
9393 if (varp != NULL)
9394 varp = *(char_u **)(varp);
9395 return varp;
9396 }
9397 return find_termcode(tname + 2);
9398}
9399
9400 char_u *
9401get_highlight_default()
9402{
9403 int i;
9404
9405 i = findoption((char_u *)"hl");
9406 if (i >= 0)
9407 return options[i].def_val[VI_DEFAULT];
9408 return (char_u *)NULL;
9409}
9410
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009411#if defined(FEAT_MBYTE) || defined(PROTO)
9412 char_u *
9413get_encoding_default()
9414{
9415 int i;
9416
9417 i = findoption((char_u *)"enc");
9418 if (i >= 0)
9419 return options[i].def_val[VI_DEFAULT];
9420 return (char_u *)NULL;
9421}
9422#endif
9423
Bram Moolenaar071d4272004-06-13 20:20:40 +00009424/*
9425 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9426 */
9427 static int
9428find_key_option(arg)
9429 char_u *arg;
9430{
9431 int key;
9432 int modifiers;
9433
9434 /*
9435 * Don't use get_special_key_code() for t_xx, we don't want it to call
9436 * add_termcap_entry().
9437 */
9438 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9439 key = TERMCAP2KEY(arg[2], arg[3]);
9440 else
9441 {
9442 --arg; /* put arg at the '<' */
9443 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009444 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009445 if (modifiers) /* can't handle modifiers here */
9446 key = 0;
9447 }
9448 return key;
9449}
9450
9451/*
9452 * if 'all' == 0: show changed options
9453 * if 'all' == 1: show all normal options
9454 * if 'all' == 2: show all terminal options
9455 */
9456 static void
9457showoptions(all, opt_flags)
9458 int all;
9459 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9460{
9461 struct vimoption *p;
9462 int col;
9463 int isterm;
9464 char_u *varp;
9465 struct vimoption **items;
9466 int item_count;
9467 int run;
9468 int row, rows;
9469 int cols;
9470 int i;
9471 int len;
9472
9473#define INC 20
9474#define GAP 3
9475
9476 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9477 PARAM_COUNT));
9478 if (items == NULL)
9479 return;
9480
9481 /* Highlight title */
9482 if (all == 2)
9483 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9484 else if (opt_flags & OPT_GLOBAL)
9485 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9486 else if (opt_flags & OPT_LOCAL)
9487 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9488 else
9489 MSG_PUTS_TITLE(_("\n--- Options ---"));
9490
9491 /*
9492 * do the loop two times:
9493 * 1. display the short items
9494 * 2. display the long items (only strings and numbers)
9495 */
9496 for (run = 1; run <= 2 && !got_int; ++run)
9497 {
9498 /*
9499 * collect the items in items[]
9500 */
9501 item_count = 0;
9502 for (p = &options[0]; p->fullname != NULL; p++)
9503 {
9504 varp = NULL;
9505 isterm = istermoption(p);
9506 if (opt_flags != 0)
9507 {
9508 if (p->indir != PV_NONE && !isterm)
9509 varp = get_varp_scope(p, opt_flags);
9510 }
9511 else
9512 varp = get_varp(p);
9513 if (varp != NULL
9514 && ((all == 2 && isterm)
9515 || (all == 1 && !isterm)
9516 || (all == 0 && !optval_default(p, varp))))
9517 {
9518 if (p->flags & P_BOOL)
9519 len = 1; /* a toggle option fits always */
9520 else
9521 {
9522 option_value2string(p, opt_flags);
9523 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9524 }
9525 if ((len <= INC - GAP && run == 1) ||
9526 (len > INC - GAP && run == 2))
9527 items[item_count++] = p;
9528 }
9529 }
9530
9531 /*
9532 * display the items
9533 */
9534 if (run == 1)
9535 {
9536 cols = (Columns + GAP - 3) / INC;
9537 if (cols == 0)
9538 cols = 1;
9539 rows = (item_count + cols - 1) / cols;
9540 }
9541 else /* run == 2 */
9542 rows = item_count;
9543 for (row = 0; row < rows && !got_int; ++row)
9544 {
9545 msg_putchar('\n'); /* go to next line */
9546 if (got_int) /* 'q' typed in more */
9547 break;
9548 col = 0;
9549 for (i = row; i < item_count; i += rows)
9550 {
9551 msg_col = col; /* make columns */
9552 showoneopt(items[i], opt_flags);
9553 col += INC;
9554 }
9555 out_flush();
9556 ui_breakcheck();
9557 }
9558 }
9559 vim_free(items);
9560}
9561
9562/*
9563 * Return TRUE if option "p" has its default value.
9564 */
9565 static int
9566optval_default(p, varp)
9567 struct vimoption *p;
9568 char_u *varp;
9569{
9570 int dvi;
9571
9572 if (varp == NULL)
9573 return TRUE; /* hidden option is always at default */
9574 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9575 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009576 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009577 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009578 /* the cast to long is required for Manx C, long_i is
9579 * needed for MSVC */
9580 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009581 /* P_STRING */
9582 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9583}
9584
9585/*
9586 * showoneopt: show the value of one option
9587 * must not be called with a hidden option!
9588 */
9589 static void
9590showoneopt(p, opt_flags)
9591 struct vimoption *p;
9592 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9593{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009594 char_u *varp;
9595 int save_silent = silent_mode;
9596
9597 silent_mode = FALSE;
9598 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009599
9600 varp = get_varp_scope(p, opt_flags);
9601
9602 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9603 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9604 ? !curbufIsChanged() : !*(int *)varp))
9605 MSG_PUTS("no");
9606 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9607 MSG_PUTS("--");
9608 else
9609 MSG_PUTS(" ");
9610 MSG_PUTS(p->fullname);
9611 if (!(p->flags & P_BOOL))
9612 {
9613 msg_putchar('=');
9614 /* put value string in NameBuff */
9615 option_value2string(p, opt_flags);
9616 msg_outtrans(NameBuff);
9617 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009618
9619 silent_mode = save_silent;
9620 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621}
9622
9623/*
9624 * Write modified options as ":set" commands to a file.
9625 *
9626 * There are three values for "opt_flags":
9627 * OPT_GLOBAL: Write global option values and fresh values of
9628 * buffer-local options (used for start of a session
9629 * file).
9630 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9631 * curwin (used for a vimrc file).
9632 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9633 * and local values for window-local options of
9634 * curwin. Local values are also written when at the
9635 * default value, because a modeline or autocommand
9636 * may have set them when doing ":edit file" and the
9637 * user has set them back at the default or fresh
9638 * value.
9639 * When "local_only" is TRUE, don't write fresh
9640 * values, only local values (for ":mkview").
9641 * (fresh value = value used for a new buffer or window for a local option).
9642 *
9643 * Return FAIL on error, OK otherwise.
9644 */
9645 int
9646makeset(fd, opt_flags, local_only)
9647 FILE *fd;
9648 int opt_flags;
9649 int local_only;
9650{
9651 struct vimoption *p;
9652 char_u *varp; /* currently used value */
9653 char_u *varp_fresh; /* local value */
9654 char_u *varp_local = NULL; /* fresh value */
9655 char *cmd;
9656 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009657 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009658
9659 /*
9660 * The options that don't have a default (terminal name, columns, lines)
9661 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009662 * Do the loop over "options[]" twice: once for options with the
9663 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009664 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009665 for (pri = 1; pri >= 0; --pri)
9666 {
9667 for (p = &options[0]; !istermoption(p); p++)
9668 if (!(p->flags & P_NO_MKRC)
9669 && !istermoption(p)
9670 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009671 {
9672 /* skip global option when only doing locals */
9673 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9674 continue;
9675
9676 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9677 * file, they are always buffer-specific. */
9678 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9679 continue;
9680
9681 /* Global values are only written when not at the default value. */
9682 varp = get_varp_scope(p, opt_flags);
9683 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9684 continue;
9685
9686 round = 2;
9687 if (p->indir != PV_NONE)
9688 {
9689 if (p->var == VAR_WIN)
9690 {
9691 /* skip window-local option when only doing globals */
9692 if (!(opt_flags & OPT_LOCAL))
9693 continue;
9694 /* When fresh value of window-local option is not at the
9695 * default, need to write it too. */
9696 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9697 {
9698 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9699 if (!optval_default(p, varp_fresh))
9700 {
9701 round = 1;
9702 varp_local = varp;
9703 varp = varp_fresh;
9704 }
9705 }
9706 }
9707 }
9708
9709 /* Round 1: fresh value for window-local options.
9710 * Round 2: other values */
9711 for ( ; round <= 2; varp = varp_local, ++round)
9712 {
9713 if (round == 1 || (opt_flags & OPT_GLOBAL))
9714 cmd = "set";
9715 else
9716 cmd = "setlocal";
9717
9718 if (p->flags & P_BOOL)
9719 {
9720 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9721 return FAIL;
9722 }
9723 else if (p->flags & P_NUM)
9724 {
9725 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9726 return FAIL;
9727 }
9728 else /* P_STRING */
9729 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009730#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9731 int do_endif = FALSE;
9732
Bram Moolenaar071d4272004-06-13 20:20:40 +00009733 /* Don't set 'syntax' and 'filetype' again if the value is
9734 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009735 if (
9736# if defined(FEAT_SYN_HL)
9737 p->indir == PV_SYN
9738# if defined(FEAT_AUTOCMD)
9739 ||
9740# endif
9741# endif
9742# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009743 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009744# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009745 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009746 {
9747 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9748 *(char_u **)(varp)) < 0
9749 || put_eol(fd) < 0)
9750 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009751 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009753#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009754 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9755 (p->flags & P_EXPAND) != 0) == FAIL)
9756 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009757#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9758 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009759 {
9760 if (put_line(fd, "endif") == FAIL)
9761 return FAIL;
9762 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009763#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009764 }
9765 }
9766 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009767 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768 return OK;
9769}
9770
9771#if defined(FEAT_FOLDING) || defined(PROTO)
9772/*
9773 * Generate set commands for the local fold options only. Used when
9774 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9775 */
9776 int
9777makefoldset(fd)
9778 FILE *fd;
9779{
9780 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9781# ifdef FEAT_EVAL
9782 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9783 == FAIL
9784# endif
9785 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9786 == FAIL
9787 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9788 == FAIL
9789 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9790 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9791 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9792 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9793 )
9794 return FAIL;
9795
9796 return OK;
9797}
9798#endif
9799
9800 static int
9801put_setstring(fd, cmd, name, valuep, expand)
9802 FILE *fd;
9803 char *cmd;
9804 char *name;
9805 char_u **valuep;
9806 int expand;
9807{
9808 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009809 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810
9811 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9812 return FAIL;
9813 if (*valuep != NULL)
9814 {
9815 /* Output 'pastetoggle' as key names. For other
9816 * options some characters have to be escaped with
9817 * CTRL-V or backslash */
9818 if (valuep == &p_pt)
9819 {
9820 s = *valuep;
9821 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009822 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009823 return FAIL;
9824 }
9825 else if (expand)
9826 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009827 buf = alloc(MAXPATHL);
9828 if (buf == NULL)
9829 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009830 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9831 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009832 {
9833 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009834 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009835 }
9836 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009837 }
9838 else if (put_escstr(fd, *valuep, 2) == FAIL)
9839 return FAIL;
9840 }
9841 if (put_eol(fd) < 0)
9842 return FAIL;
9843 return OK;
9844}
9845
9846 static int
9847put_setnum(fd, cmd, name, valuep)
9848 FILE *fd;
9849 char *cmd;
9850 char *name;
9851 long *valuep;
9852{
9853 long wc;
9854
9855 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9856 return FAIL;
9857 if (wc_use_keyname((char_u *)valuep, &wc))
9858 {
9859 /* print 'wildchar' and 'wildcharm' as a key name */
9860 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9861 return FAIL;
9862 }
9863 else if (fprintf(fd, "%ld", *valuep) < 0)
9864 return FAIL;
9865 if (put_eol(fd) < 0)
9866 return FAIL;
9867 return OK;
9868}
9869
9870 static int
9871put_setbool(fd, cmd, name, value)
9872 FILE *fd;
9873 char *cmd;
9874 char *name;
9875 int value;
9876{
Bram Moolenaar893de922007-10-02 18:40:57 +00009877 if (value < 0) /* global/local option using global value */
9878 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009879 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9880 || put_eol(fd) < 0)
9881 return FAIL;
9882 return OK;
9883}
9884
9885/*
9886 * Clear all the terminal options.
9887 * If the option has been allocated, free the memory.
9888 * Terminal options are never hidden or indirect.
9889 */
9890 void
9891clear_termoptions()
9892{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009893 /*
9894 * Reset a few things before clearing the old options. This may cause
9895 * outputting a few things that the terminal doesn't understand, but the
9896 * screen will be cleared later, so this is OK.
9897 */
9898#ifdef FEAT_MOUSE_TTY
9899 mch_setmouse(FALSE); /* switch mouse off */
9900#endif
9901#ifdef FEAT_TITLE
9902 mch_restore_title(3); /* restore window titles */
9903#endif
9904#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9905 /* When starting the GUI close the display opened for the clipboard.
9906 * After restoring the title, because that will need the display. */
9907 if (gui.starting)
9908 clear_xterm_clip();
9909#endif
9910#ifdef WIN3264
9911 /*
9912 * Check if this is allowed now.
9913 */
9914 if (can_end_termcap_mode(FALSE) == TRUE)
9915#endif
9916 stoptermcap(); /* stop termcap mode */
9917
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009918 free_termoptions();
9919}
9920
9921 void
9922free_termoptions()
9923{
9924 struct vimoption *p;
9925
Bram Moolenaar071d4272004-06-13 20:20:40 +00009926 for (p = &options[0]; p->fullname != NULL; p++)
9927 if (istermoption(p))
9928 {
9929 if (p->flags & P_ALLOCED)
9930 free_string_option(*(char_u **)(p->var));
9931 if (p->flags & P_DEF_ALLOCED)
9932 free_string_option(p->def_val[VI_DEFAULT]);
9933 *(char_u **)(p->var) = empty_option;
9934 p->def_val[VI_DEFAULT] = empty_option;
9935 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9936 }
9937 clear_termcodes();
9938}
9939
9940/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009941 * Free the string for one term option, if it was allocated.
9942 * Set the string to empty_option and clear allocated flag.
9943 * "var" points to the option value.
9944 */
9945 void
9946free_one_termoption(var)
9947 char_u *var;
9948{
9949 struct vimoption *p;
9950
9951 for (p = &options[0]; p->fullname != NULL; p++)
9952 if (p->var == var)
9953 {
9954 if (p->flags & P_ALLOCED)
9955 free_string_option(*(char_u **)(p->var));
9956 *(char_u **)(p->var) = empty_option;
9957 p->flags &= ~P_ALLOCED;
9958 break;
9959 }
9960}
9961
9962/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009963 * Set the terminal option defaults to the current value.
9964 * Used after setting the terminal name.
9965 */
9966 void
9967set_term_defaults()
9968{
9969 struct vimoption *p;
9970
9971 for (p = &options[0]; p->fullname != NULL; p++)
9972 {
9973 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9974 {
9975 if (p->flags & P_DEF_ALLOCED)
9976 {
9977 free_string_option(p->def_val[VI_DEFAULT]);
9978 p->flags &= ~P_DEF_ALLOCED;
9979 }
9980 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9981 if (p->flags & P_ALLOCED)
9982 {
9983 p->flags |= P_DEF_ALLOCED;
9984 p->flags &= ~P_ALLOCED; /* don't free the value now */
9985 }
9986 }
9987 }
9988}
9989
9990/*
9991 * return TRUE if 'p' starts with 't_'
9992 */
9993 static int
9994istermoption(p)
9995 struct vimoption *p;
9996{
9997 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9998}
9999
10000/*
10001 * Compute columns for ruler and shown command. 'sc_col' is also used to
10002 * decide what the maximum length of a message on the status line can be.
10003 * If there is a status line for the last window, 'sc_col' is independent
10004 * of 'ru_col'.
10005 */
10006
10007#define COL_RULER 17 /* columns needed by standard ruler */
10008
10009 void
10010comp_col()
10011{
10012#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10013 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10014
10015 sc_col = 0;
10016 ru_col = 0;
10017 if (p_ru)
10018 {
10019#ifdef FEAT_STL_OPT
10020 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10021#else
10022 ru_col = COL_RULER + 1;
10023#endif
10024 /* no last status line, adjust sc_col */
10025 if (!last_has_status)
10026 sc_col = ru_col;
10027 }
10028 if (p_sc)
10029 {
10030 sc_col += SHOWCMD_COLS;
10031 if (!p_ru || last_has_status) /* no need for separating space */
10032 ++sc_col;
10033 }
10034 sc_col = Columns - sc_col;
10035 ru_col = Columns - ru_col;
10036 if (sc_col <= 0) /* screen too narrow, will become a mess */
10037 sc_col = 1;
10038 if (ru_col <= 0)
10039 ru_col = 1;
10040#else
10041 sc_col = Columns;
10042 ru_col = Columns;
10043#endif
10044}
10045
10046/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010047 * Unset local option value, similar to ":set opt<".
10048 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010049 void
10050unset_global_local_option(name, from)
10051 char_u *name;
10052 void *from;
10053{
10054 struct vimoption *p;
10055 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010056 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010057
10058 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010059 if (opt_idx < 0)
10060 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010061 p = &(options[opt_idx]);
10062
10063 switch ((int)p->indir)
10064 {
10065 /* global option with local value: use local value if it's been set */
10066 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010067 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010068 break;
10069 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010070 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010071 break;
10072 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010073 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010074 break;
10075 case PV_AR:
10076 buf->b_p_ar = -1;
10077 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010078 case PV_BKC:
10079 clear_string_option(&buf->b_p_bkc);
10080 buf->b_bkc_flags = 0;
10081 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010082 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010083 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010084 break;
10085#ifdef FEAT_FIND_ID
10086 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010087 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010088 break;
10089 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010090 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010091 break;
10092#endif
10093#ifdef FEAT_INS_EXPAND
10094 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010095 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010096 break;
10097 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010098 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010099 break;
10100#endif
10101#ifdef FEAT_QUICKFIX
10102 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010103 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010104 break;
10105 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010106 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010107 break;
10108 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010109 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010110 break;
10111#endif
10112#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10113 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010114 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010115 break;
10116#endif
10117#if defined(FEAT_CRYPT)
10118 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010119 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010120 break;
10121#endif
10122#ifdef FEAT_STL_OPT
10123 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010124 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010125 break;
10126#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010127 case PV_UL:
10128 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10129 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010130#ifdef FEAT_LISP
10131 case PV_LW:
10132 clear_string_option(&buf->b_p_lw);
10133 break;
10134#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010135 }
10136}
10137
10138/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139 * Get pointer to option variable, depending on local or global scope.
10140 */
10141 static char_u *
10142get_varp_scope(p, opt_flags)
10143 struct vimoption *p;
10144 int opt_flags;
10145{
10146 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10147 {
10148 if (p->var == VAR_WIN)
10149 return (char_u *)GLOBAL_WO(get_varp(p));
10150 return p->var;
10151 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010152 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153 {
10154 switch ((int)p->indir)
10155 {
10156#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010157 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10158 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10159 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010161 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10162 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10163 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010164 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010165 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010167 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10168 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169#endif
10170#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010171 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10172 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010174#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10175 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10176#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010177#if defined(FEAT_CRYPT)
10178 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10179#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010180#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010181 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010182#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010183 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010184#ifdef FEAT_LISP
10185 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10186#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010187 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 }
10189 return NULL; /* "cannot happen" */
10190 }
10191 return get_varp(p);
10192}
10193
10194/*
10195 * Get pointer to option variable.
10196 */
10197 static char_u *
10198get_varp(p)
10199 struct vimoption *p;
10200{
10201 /* hidden option, always return NULL */
10202 if (p->var == NULL)
10203 return NULL;
10204
10205 switch ((int)p->indir)
10206 {
10207 case PV_NONE: return p->var;
10208
10209 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010210 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010212 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010213 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010214 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010216 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010217 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010218 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010220 case PV_BKC: return *curbuf->b_p_bkc != NUL
10221 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010222#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010223 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010224 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010225 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010226 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10227#endif
10228#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010229 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010230 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010231 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10233#endif
10234#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010235 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010236 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010237 case PV_GP: return *curbuf->b_p_gp != NUL
10238 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10239 case PV_MP: return *curbuf->b_p_mp != NUL
10240 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010242#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10243 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10244 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10245#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010246#if defined(FEAT_CRYPT)
10247 case PV_CM: return *curbuf->b_p_cm != NUL
10248 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10249#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010250#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010251 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010252 ? (char_u *)&(curwin->w_p_stl) : p->var;
10253#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010254 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10255 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010256#ifdef FEAT_LISP
10257 case PV_LW: return *curbuf->b_p_lw != NUL
10258 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10259#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260
10261#ifdef FEAT_ARABIC
10262 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10263#endif
10264 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010265#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010266 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10267#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010268#ifdef FEAT_SYN_HL
10269 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10270 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010271 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010272#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273#ifdef FEAT_DIFF
10274 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10275#endif
10276#ifdef FEAT_FOLDING
10277 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10278 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10279 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10280 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10281 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10282 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10283 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10284# ifdef FEAT_EVAL
10285 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10286 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10287# endif
10288 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10289#endif
10290 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010291 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010292#ifdef FEAT_LINEBREAK
10293 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10294#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010295#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010296 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10297#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010298#ifdef FEAT_VERTSPLIT
10299 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10302 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10303#endif
10304#ifdef FEAT_RIGHTLEFT
10305 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10306 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10307#endif
10308 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10309 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10310#ifdef FEAT_LINEBREAK
10311 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010312 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10313 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314#endif
10315#ifdef FEAT_SCROLLBIND
10316 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10317#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010318#ifdef FEAT_CURSORBIND
10319 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10320#endif
10321#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010322 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10323 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010324#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010325
10326 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10327 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10328#ifdef FEAT_MBYTE
10329 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10330#endif
10331#if defined(FEAT_QUICKFIX)
10332 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10333 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10334#endif
10335 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10336 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10337#ifdef FEAT_CINDENT
10338 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10339 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10340 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10341#endif
10342#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10343 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10344#endif
10345#ifdef FEAT_COMMENTS
10346 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10347#endif
10348#ifdef FEAT_FOLDING
10349 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10350#endif
10351#ifdef FEAT_INS_EXPAND
10352 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10353#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010354#ifdef FEAT_COMPL_FUNC
10355 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010356 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010359 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010360 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10361#ifdef FEAT_MBYTE
10362 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10363#endif
10364 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10365#ifdef FEAT_AUTOCMD
10366 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10367#endif
10368 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010369 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10371 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10372 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10373 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10374#ifdef FEAT_FIND_ID
10375# ifdef FEAT_EVAL
10376 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10377# endif
10378#endif
10379#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10380 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10381 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10382#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010383#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010384 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010386#ifdef FEAT_CRYPT
10387 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10388#endif
10389#ifdef FEAT_LISP
10390 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10391#endif
10392 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10393 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10394 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10395 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10396 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010397 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010398#ifdef FEAT_TEXTOBJ
10399 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10402#ifdef FEAT_SMARTINDENT
10403 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10404#endif
10405#ifndef SHORT_FNAME
10406 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10407#endif
10408 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10409#ifdef FEAT_SEARCHPATH
10410 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10411#endif
10412 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10413#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010414 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010415 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10416#endif
10417#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010418 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10419 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10420 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010421#endif
10422 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10423 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10424 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10425 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010426#ifdef FEAT_PERSISTENT_UNDO
10427 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10428#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10430#ifdef FEAT_KEYMAP
10431 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10432#endif
10433 default: EMSG(_("E356: get_varp ERROR"));
10434 }
10435 /* always return a valid pointer to avoid a crash! */
10436 return (char_u *)&(curbuf->b_p_wm);
10437}
10438
10439/*
10440 * Get the value of 'equalprg', either the buffer-local one or the global one.
10441 */
10442 char_u *
10443get_equalprg()
10444{
10445 if (*curbuf->b_p_ep == NUL)
10446 return p_ep;
10447 return curbuf->b_p_ep;
10448}
10449
10450#if defined(FEAT_WINDOWS) || defined(PROTO)
10451/*
10452 * Copy options from one window to another.
10453 * Used when splitting a window.
10454 */
10455 void
10456win_copy_options(wp_from, wp_to)
10457 win_T *wp_from;
10458 win_T *wp_to;
10459{
10460 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10461 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10462# ifdef FEAT_RIGHTLEFT
10463# ifdef FEAT_FKMAP
10464 /* Is this right? */
10465 wp_to->w_farsi = wp_from->w_farsi;
10466# endif
10467# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010468#if defined(FEAT_LINEBREAK)
10469 briopt_check(wp_to);
10470#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010471}
10472#endif
10473
10474/*
10475 * Copy the options from one winopt_T to another.
10476 * Doesn't free the old option values in "to", use clear_winopt() for that.
10477 * The 'scroll' option is not copied, because it depends on the window height.
10478 * The 'previewwindow' option is reset, there can be only one preview window.
10479 */
10480 void
10481copy_winopt(from, to)
10482 winopt_T *from;
10483 winopt_T *to;
10484{
10485#ifdef FEAT_ARABIC
10486 to->wo_arab = from->wo_arab;
10487#endif
10488 to->wo_list = from->wo_list;
10489 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010490 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010491#ifdef FEAT_LINEBREAK
10492 to->wo_nuw = from->wo_nuw;
10493#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494#ifdef FEAT_RIGHTLEFT
10495 to->wo_rl = from->wo_rl;
10496 to->wo_rlc = vim_strsave(from->wo_rlc);
10497#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010498#ifdef FEAT_STL_OPT
10499 to->wo_stl = vim_strsave(from->wo_stl);
10500#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010502#ifdef FEAT_DIFF
10503 to->wo_wrap_save = from->wo_wrap_save;
10504#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010505#ifdef FEAT_LINEBREAK
10506 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010507 to->wo_bri = from->wo_bri;
10508 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509#endif
10510#ifdef FEAT_SCROLLBIND
10511 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010512 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010513#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010514#ifdef FEAT_CURSORBIND
10515 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010516 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010517#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010518#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010519 to->wo_spell = from->wo_spell;
10520#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010521#ifdef FEAT_SYN_HL
10522 to->wo_cuc = from->wo_cuc;
10523 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010524 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010525#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526#ifdef FEAT_DIFF
10527 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010528 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010530#ifdef FEAT_CONCEAL
10531 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010532 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534#ifdef FEAT_FOLDING
10535 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010536 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010538 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539 to->wo_fdi = vim_strsave(from->wo_fdi);
10540 to->wo_fml = from->wo_fml;
10541 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010542 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010544 to->wo_fdm_save = from->wo_diff_saved
10545 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010546 to->wo_fdn = from->wo_fdn;
10547# ifdef FEAT_EVAL
10548 to->wo_fde = vim_strsave(from->wo_fde);
10549 to->wo_fdt = vim_strsave(from->wo_fdt);
10550# endif
10551 to->wo_fmr = vim_strsave(from->wo_fmr);
10552#endif
10553 check_winopt(to); /* don't want NULL pointers */
10554}
10555
10556/*
10557 * Check string options in a window for a NULL value.
10558 */
10559 void
10560check_win_options(win)
10561 win_T *win;
10562{
10563 check_winopt(&win->w_onebuf_opt);
10564 check_winopt(&win->w_allbuf_opt);
10565}
10566
10567/*
10568 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10569 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010570 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010572 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573{
10574#ifdef FEAT_FOLDING
10575 check_string_option(&wop->wo_fdi);
10576 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010577 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578# ifdef FEAT_EVAL
10579 check_string_option(&wop->wo_fde);
10580 check_string_option(&wop->wo_fdt);
10581# endif
10582 check_string_option(&wop->wo_fmr);
10583#endif
10584#ifdef FEAT_RIGHTLEFT
10585 check_string_option(&wop->wo_rlc);
10586#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010587#ifdef FEAT_STL_OPT
10588 check_string_option(&wop->wo_stl);
10589#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010590#ifdef FEAT_SYN_HL
10591 check_string_option(&wop->wo_cc);
10592#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010593#ifdef FEAT_CONCEAL
10594 check_string_option(&wop->wo_cocu);
10595#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010596#ifdef FEAT_LINEBREAK
10597 check_string_option(&wop->wo_briopt);
10598#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599}
10600
10601/*
10602 * Free the allocated memory inside a winopt_T.
10603 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604 void
10605clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010606 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010607{
10608#ifdef FEAT_FOLDING
10609 clear_string_option(&wop->wo_fdi);
10610 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010611 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612# ifdef FEAT_EVAL
10613 clear_string_option(&wop->wo_fde);
10614 clear_string_option(&wop->wo_fdt);
10615# endif
10616 clear_string_option(&wop->wo_fmr);
10617#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010618#ifdef FEAT_LINEBREAK
10619 clear_string_option(&wop->wo_briopt);
10620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621#ifdef FEAT_RIGHTLEFT
10622 clear_string_option(&wop->wo_rlc);
10623#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010624#ifdef FEAT_STL_OPT
10625 clear_string_option(&wop->wo_stl);
10626#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010627#ifdef FEAT_SYN_HL
10628 clear_string_option(&wop->wo_cc);
10629#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010630#ifdef FEAT_CONCEAL
10631 clear_string_option(&wop->wo_cocu);
10632#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633}
10634
10635/*
10636 * Copy global option values to local options for one buffer.
10637 * Used when creating a new buffer and sometimes when entering a buffer.
10638 * flags:
10639 * BCO_ENTER We will enter the buf buffer.
10640 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10641 * appropriate.
10642 * BCO_NOHELP Don't copy the values to a help buffer.
10643 */
10644 void
10645buf_copy_options(buf, flags)
10646 buf_T *buf;
10647 int flags;
10648{
10649 int should_copy = TRUE;
10650 char_u *save_p_isk = NULL; /* init for GCC */
10651 int dont_do_help;
10652 int did_isk = FALSE;
10653
10654 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010655 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010656 */
10657 if (buf == NULL || !buf_valid(buf))
10658 return;
10659
10660 /*
10661 * Skip this when the option defaults have not been set yet. Happens when
10662 * main() allocates the first buffer.
10663 */
10664 if (p_cpo != NULL)
10665 {
10666 /*
10667 * Always copy when entering and 'cpo' contains 'S'.
10668 * Don't copy when already initialized.
10669 * Don't copy when 'cpo' contains 's' and not entering.
10670 * 'S' BCO_ENTER initialized 's' should_copy
10671 * yes yes X X TRUE
10672 * yes no yes X FALSE
10673 * no X yes X FALSE
10674 * X no no yes FALSE
10675 * X no no no TRUE
10676 * no yes no X TRUE
10677 */
10678 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10679 && (buf->b_p_initialized
10680 || (!(flags & BCO_ENTER)
10681 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10682 should_copy = FALSE;
10683
10684 if (should_copy || (flags & BCO_ALWAYS))
10685 {
10686 /* Don't copy the options specific to a help buffer when
10687 * BCO_NOHELP is given or the options were initialized already
10688 * (jumping back to a help file with CTRL-T or CTRL-O) */
10689 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10690 || buf->b_p_initialized;
10691 if (dont_do_help) /* don't free b_p_isk */
10692 {
10693 save_p_isk = buf->b_p_isk;
10694 buf->b_p_isk = NULL;
10695 }
10696 /*
10697 * Always free the allocated strings.
10698 * If not already initialized, set 'readonly' and copy 'fileformat'.
10699 */
10700 if (!buf->b_p_initialized)
10701 {
10702 free_buf_options(buf, TRUE);
10703 buf->b_p_ro = FALSE; /* don't copy readonly */
10704 buf->b_p_tx = p_tx;
10705#ifdef FEAT_MBYTE
10706 buf->b_p_fenc = vim_strsave(p_fenc);
10707#endif
10708 buf->b_p_ff = vim_strsave(p_ff);
10709#if defined(FEAT_QUICKFIX)
10710 buf->b_p_bh = empty_option;
10711 buf->b_p_bt = empty_option;
10712#endif
10713 }
10714 else
10715 free_buf_options(buf, FALSE);
10716
10717 buf->b_p_ai = p_ai;
10718 buf->b_p_ai_nopaste = p_ai_nopaste;
10719 buf->b_p_sw = p_sw;
10720 buf->b_p_tw = p_tw;
10721 buf->b_p_tw_nopaste = p_tw_nopaste;
10722 buf->b_p_tw_nobin = p_tw_nobin;
10723 buf->b_p_wm = p_wm;
10724 buf->b_p_wm_nopaste = p_wm_nopaste;
10725 buf->b_p_wm_nobin = p_wm_nobin;
10726 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010727#ifdef FEAT_MBYTE
10728 buf->b_p_bomb = p_bomb;
10729#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010730 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010731 buf->b_p_et = p_et;
10732 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010733 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 buf->b_p_ml = p_ml;
10735 buf->b_p_ml_nobin = p_ml_nobin;
10736 buf->b_p_inf = p_inf;
10737 buf->b_p_swf = p_swf;
10738#ifdef FEAT_INS_EXPAND
10739 buf->b_p_cpt = vim_strsave(p_cpt);
10740#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010741#ifdef FEAT_COMPL_FUNC
10742 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010743 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010744#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010745 buf->b_p_sts = p_sts;
10746 buf->b_p_sts_nopaste = p_sts_nopaste;
10747#ifndef SHORT_FNAME
10748 buf->b_p_sn = p_sn;
10749#endif
10750#ifdef FEAT_COMMENTS
10751 buf->b_p_com = vim_strsave(p_com);
10752#endif
10753#ifdef FEAT_FOLDING
10754 buf->b_p_cms = vim_strsave(p_cms);
10755#endif
10756 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010757 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010758 buf->b_p_nf = vim_strsave(p_nf);
10759 buf->b_p_mps = vim_strsave(p_mps);
10760#ifdef FEAT_SMARTINDENT
10761 buf->b_p_si = p_si;
10762#endif
10763 buf->b_p_ci = p_ci;
10764#ifdef FEAT_CINDENT
10765 buf->b_p_cin = p_cin;
10766 buf->b_p_cink = vim_strsave(p_cink);
10767 buf->b_p_cino = vim_strsave(p_cino);
10768#endif
10769#ifdef FEAT_AUTOCMD
10770 /* Don't copy 'filetype', it must be detected */
10771 buf->b_p_ft = empty_option;
10772#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773 buf->b_p_pi = p_pi;
10774#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10775 buf->b_p_cinw = vim_strsave(p_cinw);
10776#endif
10777#ifdef FEAT_LISP
10778 buf->b_p_lisp = p_lisp;
10779#endif
10780#ifdef FEAT_SYN_HL
10781 /* Don't copy 'syntax', it must be set */
10782 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010783 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010784#endif
10785#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010786 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010787 (void)compile_cap_prog(&buf->b_s);
10788 buf->b_s.b_p_spf = vim_strsave(p_spf);
10789 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010790#endif
10791#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10792 buf->b_p_inde = vim_strsave(p_inde);
10793 buf->b_p_indk = vim_strsave(p_indk);
10794#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010795#if defined(FEAT_EVAL)
10796 buf->b_p_fex = vim_strsave(p_fex);
10797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798#ifdef FEAT_CRYPT
10799 buf->b_p_key = vim_strsave(p_key);
10800#endif
10801#ifdef FEAT_SEARCHPATH
10802 buf->b_p_sua = vim_strsave(p_sua);
10803#endif
10804#ifdef FEAT_KEYMAP
10805 buf->b_p_keymap = vim_strsave(p_keymap);
10806 buf->b_kmap_state |= KEYMAP_INIT;
10807#endif
10808 /* This isn't really an option, but copying the langmap and IME
10809 * state from the current buffer is better than resetting it. */
10810 buf->b_p_iminsert = p_iminsert;
10811 buf->b_p_imsearch = p_imsearch;
10812
10813 /* options that are normally global but also have a local value
10814 * are not copied, start using the global value */
10815 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010816 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010817 buf->b_p_bkc = empty_option;
10818 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819#ifdef FEAT_QUICKFIX
10820 buf->b_p_gp = empty_option;
10821 buf->b_p_mp = empty_option;
10822 buf->b_p_efm = empty_option;
10823#endif
10824 buf->b_p_ep = empty_option;
10825 buf->b_p_kp = empty_option;
10826 buf->b_p_path = empty_option;
10827 buf->b_p_tags = empty_option;
10828#ifdef FEAT_FIND_ID
10829 buf->b_p_def = empty_option;
10830 buf->b_p_inc = empty_option;
10831# ifdef FEAT_EVAL
10832 buf->b_p_inex = vim_strsave(p_inex);
10833# endif
10834#endif
10835#ifdef FEAT_INS_EXPAND
10836 buf->b_p_dict = empty_option;
10837 buf->b_p_tsr = empty_option;
10838#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010839#ifdef FEAT_TEXTOBJ
10840 buf->b_p_qe = vim_strsave(p_qe);
10841#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010842#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10843 buf->b_p_bexpr = empty_option;
10844#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010845#if defined(FEAT_CRYPT)
10846 buf->b_p_cm = empty_option;
10847#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010848#ifdef FEAT_PERSISTENT_UNDO
10849 buf->b_p_udf = p_udf;
10850#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010851#ifdef FEAT_LISP
10852 buf->b_p_lw = empty_option;
10853#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854
10855 /*
10856 * Don't copy the options set by ex_help(), use the saved values,
10857 * when going from a help buffer to a non-help buffer.
10858 * Don't touch these at all when BCO_NOHELP is used and going from
10859 * or to a help buffer.
10860 */
10861 if (dont_do_help)
10862 buf->b_p_isk = save_p_isk;
10863 else
10864 {
10865 buf->b_p_isk = vim_strsave(p_isk);
10866 did_isk = TRUE;
10867 buf->b_p_ts = p_ts;
10868 buf->b_help = FALSE;
10869#ifdef FEAT_QUICKFIX
10870 if (buf->b_p_bt[0] == 'h')
10871 clear_string_option(&buf->b_p_bt);
10872#endif
10873 buf->b_p_ma = p_ma;
10874 }
10875 }
10876
10877 /*
10878 * When the options should be copied (ignoring BCO_ALWAYS), set the
10879 * flag that indicates that the options have been initialized.
10880 */
10881 if (should_copy)
10882 buf->b_p_initialized = TRUE;
10883 }
10884
10885 check_buf_options(buf); /* make sure we don't have NULLs */
10886 if (did_isk)
10887 (void)buf_init_chartab(buf, FALSE);
10888}
10889
10890/*
10891 * Reset the 'modifiable' option and its default value.
10892 */
10893 void
10894reset_modifiable()
10895{
10896 int opt_idx;
10897
10898 curbuf->b_p_ma = FALSE;
10899 p_ma = FALSE;
10900 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010901 if (opt_idx >= 0)
10902 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010903}
10904
10905/*
10906 * Set the global value for 'iminsert' to the local value.
10907 */
10908 void
10909set_iminsert_global()
10910{
10911 p_iminsert = curbuf->b_p_iminsert;
10912}
10913
10914/*
10915 * Set the global value for 'imsearch' to the local value.
10916 */
10917 void
10918set_imsearch_global()
10919{
10920 p_imsearch = curbuf->b_p_imsearch;
10921}
10922
10923#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10924static int expand_option_idx = -1;
10925static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10926static int expand_option_flags = 0;
10927
10928 void
10929set_context_in_set_cmd(xp, arg, opt_flags)
10930 expand_T *xp;
10931 char_u *arg;
10932 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10933{
10934 int nextchar;
10935 long_u flags = 0; /* init for GCC */
10936 int opt_idx = 0; /* init for GCC */
10937 char_u *p;
10938 char_u *s;
10939 int is_term_option = FALSE;
10940 int key;
10941
10942 expand_option_flags = opt_flags;
10943
10944 xp->xp_context = EXPAND_SETTINGS;
10945 if (*arg == NUL)
10946 {
10947 xp->xp_pattern = arg;
10948 return;
10949 }
10950 p = arg + STRLEN(arg) - 1;
10951 if (*p == ' ' && *(p - 1) != '\\')
10952 {
10953 xp->xp_pattern = p + 1;
10954 return;
10955 }
10956 while (p > arg)
10957 {
10958 s = p;
10959 /* count number of backslashes before ' ' or ',' */
10960 if (*p == ' ' || *p == ',')
10961 {
10962 while (s > arg && *(s - 1) == '\\')
10963 --s;
10964 }
10965 /* break at a space with an even number of backslashes */
10966 if (*p == ' ' && ((p - s) & 1) == 0)
10967 {
10968 ++p;
10969 break;
10970 }
10971 --p;
10972 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010973 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010974 {
10975 xp->xp_context = EXPAND_BOOL_SETTINGS;
10976 p += 2;
10977 }
10978 if (STRNCMP(p, "inv", 3) == 0)
10979 {
10980 xp->xp_context = EXPAND_BOOL_SETTINGS;
10981 p += 3;
10982 }
10983 xp->xp_pattern = arg = p;
10984 if (*arg == '<')
10985 {
10986 while (*p != '>')
10987 if (*p++ == NUL) /* expand terminal option name */
10988 return;
10989 key = get_special_key_code(arg + 1);
10990 if (key == 0) /* unknown name */
10991 {
10992 xp->xp_context = EXPAND_NOTHING;
10993 return;
10994 }
10995 nextchar = *++p;
10996 is_term_option = TRUE;
10997 expand_option_name[2] = KEY2TERMCAP0(key);
10998 expand_option_name[3] = KEY2TERMCAP1(key);
10999 }
11000 else
11001 {
11002 if (p[0] == 't' && p[1] == '_')
11003 {
11004 p += 2;
11005 if (*p != NUL)
11006 ++p;
11007 if (*p == NUL)
11008 return; /* expand option name */
11009 nextchar = *++p;
11010 is_term_option = TRUE;
11011 expand_option_name[2] = p[-2];
11012 expand_option_name[3] = p[-1];
11013 }
11014 else
11015 {
11016 /* Allow * wildcard */
11017 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11018 p++;
11019 if (*p == NUL)
11020 return;
11021 nextchar = *p;
11022 *p = NUL;
11023 opt_idx = findoption(arg);
11024 *p = nextchar;
11025 if (opt_idx == -1 || options[opt_idx].var == NULL)
11026 {
11027 xp->xp_context = EXPAND_NOTHING;
11028 return;
11029 }
11030 flags = options[opt_idx].flags;
11031 if (flags & P_BOOL)
11032 {
11033 xp->xp_context = EXPAND_NOTHING;
11034 return;
11035 }
11036 }
11037 }
11038 /* handle "-=" and "+=" */
11039 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11040 {
11041 ++p;
11042 nextchar = '=';
11043 }
11044 if ((nextchar != '=' && nextchar != ':')
11045 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11046 {
11047 xp->xp_context = EXPAND_UNSUCCESSFUL;
11048 return;
11049 }
11050 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11051 {
11052 xp->xp_context = EXPAND_OLD_SETTING;
11053 if (is_term_option)
11054 expand_option_idx = -1;
11055 else
11056 expand_option_idx = opt_idx;
11057 xp->xp_pattern = p + 1;
11058 return;
11059 }
11060 xp->xp_context = EXPAND_NOTHING;
11061 if (is_term_option || (flags & P_NUM))
11062 return;
11063
11064 xp->xp_pattern = p + 1;
11065
11066 if (flags & P_EXPAND)
11067 {
11068 p = options[opt_idx].var;
11069 if (p == (char_u *)&p_bdir
11070 || p == (char_u *)&p_dir
11071 || p == (char_u *)&p_path
11072 || p == (char_u *)&p_rtp
11073#ifdef FEAT_SEARCHPATH
11074 || p == (char_u *)&p_cdpath
11075#endif
11076#ifdef FEAT_SESSION
11077 || p == (char_u *)&p_vdir
11078#endif
11079 )
11080 {
11081 xp->xp_context = EXPAND_DIRECTORIES;
11082 if (p == (char_u *)&p_path
11083#ifdef FEAT_SEARCHPATH
11084 || p == (char_u *)&p_cdpath
11085#endif
11086 )
11087 xp->xp_backslash = XP_BS_THREE;
11088 else
11089 xp->xp_backslash = XP_BS_ONE;
11090 }
11091 else
11092 {
11093 xp->xp_context = EXPAND_FILES;
11094 /* for 'tags' need three backslashes for a space */
11095 if (p == (char_u *)&p_tags)
11096 xp->xp_backslash = XP_BS_THREE;
11097 else
11098 xp->xp_backslash = XP_BS_ONE;
11099 }
11100 }
11101
11102 /* For an option that is a list of file names, find the start of the
11103 * last file name. */
11104 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11105 {
11106 /* count number of backslashes before ' ' or ',' */
11107 if (*p == ' ' || *p == ',')
11108 {
11109 s = p;
11110 while (s > xp->xp_pattern && *(s - 1) == '\\')
11111 --s;
11112 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11113 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11114 {
11115 xp->xp_pattern = p + 1;
11116 break;
11117 }
11118 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011119
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011120#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011121 /* for 'spellsuggest' start at "file:" */
11122 if (options[opt_idx].var == (char_u *)&p_sps
11123 && STRNCMP(p, "file:", 5) == 0)
11124 {
11125 xp->xp_pattern = p + 5;
11126 break;
11127 }
11128#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129 }
11130
11131 return;
11132}
11133
11134 int
11135ExpandSettings(xp, regmatch, num_file, file)
11136 expand_T *xp;
11137 regmatch_T *regmatch;
11138 int *num_file;
11139 char_u ***file;
11140{
11141 int num_normal = 0; /* Nr of matching non-term-code settings */
11142 int num_term = 0; /* Nr of matching terminal code settings */
11143 int opt_idx;
11144 int match;
11145 int count = 0;
11146 char_u *str;
11147 int loop;
11148 int is_term_opt;
11149 char_u name_buf[MAX_KEY_NAME_LEN];
11150 static char *(names[]) = {"all", "termcap"};
11151 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11152
11153 /* do this loop twice:
11154 * loop == 0: count the number of matching options
11155 * loop == 1: copy the matching options into allocated memory
11156 */
11157 for (loop = 0; loop <= 1; ++loop)
11158 {
11159 regmatch->rm_ic = ic;
11160 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11161 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011162 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11163 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11165 {
11166 if (loop == 0)
11167 num_normal++;
11168 else
11169 (*file)[count++] = vim_strsave((char_u *)names[match]);
11170 }
11171 }
11172 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11173 opt_idx++)
11174 {
11175 if (options[opt_idx].var == NULL)
11176 continue;
11177 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11178 && !(options[opt_idx].flags & P_BOOL))
11179 continue;
11180 is_term_opt = istermoption(&options[opt_idx]);
11181 if (is_term_opt && num_normal > 0)
11182 continue;
11183 match = FALSE;
11184 if (vim_regexec(regmatch, str, (colnr_T)0)
11185 || (options[opt_idx].shortname != NULL
11186 && vim_regexec(regmatch,
11187 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11188 match = TRUE;
11189 else if (is_term_opt)
11190 {
11191 name_buf[0] = '<';
11192 name_buf[1] = 't';
11193 name_buf[2] = '_';
11194 name_buf[3] = str[2];
11195 name_buf[4] = str[3];
11196 name_buf[5] = '>';
11197 name_buf[6] = NUL;
11198 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11199 {
11200 match = TRUE;
11201 str = name_buf;
11202 }
11203 }
11204 if (match)
11205 {
11206 if (loop == 0)
11207 {
11208 if (is_term_opt)
11209 num_term++;
11210 else
11211 num_normal++;
11212 }
11213 else
11214 (*file)[count++] = vim_strsave(str);
11215 }
11216 }
11217 /*
11218 * Check terminal key codes, these are not in the option table
11219 */
11220 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11221 {
11222 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11223 {
11224 if (!isprint(str[0]) || !isprint(str[1]))
11225 continue;
11226
11227 name_buf[0] = 't';
11228 name_buf[1] = '_';
11229 name_buf[2] = str[0];
11230 name_buf[3] = str[1];
11231 name_buf[4] = NUL;
11232
11233 match = FALSE;
11234 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11235 match = TRUE;
11236 else
11237 {
11238 name_buf[0] = '<';
11239 name_buf[1] = 't';
11240 name_buf[2] = '_';
11241 name_buf[3] = str[0];
11242 name_buf[4] = str[1];
11243 name_buf[5] = '>';
11244 name_buf[6] = NUL;
11245
11246 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11247 match = TRUE;
11248 }
11249 if (match)
11250 {
11251 if (loop == 0)
11252 num_term++;
11253 else
11254 (*file)[count++] = vim_strsave(name_buf);
11255 }
11256 }
11257
11258 /*
11259 * Check special key names.
11260 */
11261 regmatch->rm_ic = TRUE; /* ignore case here */
11262 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11263 {
11264 name_buf[0] = '<';
11265 STRCPY(name_buf + 1, str);
11266 STRCAT(name_buf, ">");
11267
11268 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11269 {
11270 if (loop == 0)
11271 num_term++;
11272 else
11273 (*file)[count++] = vim_strsave(name_buf);
11274 }
11275 }
11276 }
11277 if (loop == 0)
11278 {
11279 if (num_normal > 0)
11280 *num_file = num_normal;
11281 else if (num_term > 0)
11282 *num_file = num_term;
11283 else
11284 return OK;
11285 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11286 if (*file == NULL)
11287 {
11288 *file = (char_u **)"";
11289 return FAIL;
11290 }
11291 }
11292 }
11293 return OK;
11294}
11295
11296 int
11297ExpandOldSetting(num_file, file)
11298 int *num_file;
11299 char_u ***file;
11300{
11301 char_u *var = NULL; /* init for GCC */
11302 char_u *buf;
11303
11304 *num_file = 0;
11305 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11306 if (*file == NULL)
11307 return FAIL;
11308
11309 /*
11310 * For a terminal key code expand_option_idx is < 0.
11311 */
11312 if (expand_option_idx < 0)
11313 {
11314 var = find_termcode(expand_option_name + 2);
11315 if (var == NULL)
11316 expand_option_idx = findoption(expand_option_name);
11317 }
11318
11319 if (expand_option_idx >= 0)
11320 {
11321 /* put string of option value in NameBuff */
11322 option_value2string(&options[expand_option_idx], expand_option_flags);
11323 var = NameBuff;
11324 }
11325 else if (var == NULL)
11326 var = (char_u *)"";
11327
11328 /* A backslash is required before some characters. This is the reverse of
11329 * what happens in do_set(). */
11330 buf = vim_strsave_escaped(var, escape_chars);
11331
11332 if (buf == NULL)
11333 {
11334 vim_free(*file);
11335 *file = NULL;
11336 return FAIL;
11337 }
11338
11339#ifdef BACKSLASH_IN_FILENAME
11340 /* For MS-Windows et al. we don't double backslashes at the start and
11341 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011342 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011343 if (var[0] == '\\' && var[1] == '\\'
11344 && expand_option_idx >= 0
11345 && (options[expand_option_idx].flags & P_EXPAND)
11346 && vim_isfilec(var[2])
11347 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011348 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349#endif
11350
11351 *file[0] = buf;
11352 *num_file = 1;
11353 return OK;
11354}
11355#endif
11356
11357/*
11358 * Get the value for the numeric or string option *opp in a nice format into
11359 * NameBuff[]. Must not be called with a hidden option!
11360 */
11361 static void
11362option_value2string(opp, opt_flags)
11363 struct vimoption *opp;
11364 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11365{
11366 char_u *varp;
11367
11368 varp = get_varp_scope(opp, opt_flags);
11369
11370 if (opp->flags & P_NUM)
11371 {
11372 long wc = 0;
11373
11374 if (wc_use_keyname(varp, &wc))
11375 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11376 else if (wc != 0)
11377 STRCPY(NameBuff, transchar((int)wc));
11378 else
11379 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11380 }
11381 else /* P_STRING */
11382 {
11383 varp = *(char_u **)(varp);
11384 if (varp == NULL) /* just in case */
11385 NameBuff[0] = NUL;
11386#ifdef FEAT_CRYPT
11387 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011388 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389 STRCPY(NameBuff, "*****");
11390#endif
11391 else if (opp->flags & P_EXPAND)
11392 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11393 /* Translate 'pastetoggle' into special key names */
11394 else if ((char_u **)opp->var == &p_pt)
11395 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11396 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011397 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011398 }
11399}
11400
11401/*
11402 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11403 * printed as a keyname.
11404 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11405 */
11406 static int
11407wc_use_keyname(varp, wcp)
11408 char_u *varp;
11409 long *wcp;
11410{
11411 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11412 {
11413 *wcp = *(long *)varp;
11414 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11415 return TRUE;
11416 }
11417 return FALSE;
11418}
11419
Bram Moolenaar01615492015-02-03 13:00:38 +010011420#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011421/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011422 * Any character has an equivalent 'langmap' character. This is used for
11423 * keyboards that have a special language mode that sends characters above
11424 * 128 (although other characters can be translated too). The "to" field is a
11425 * Vim command character. This avoids having to switch the keyboard back to
11426 * ASCII mode when leaving Insert mode.
11427 *
11428 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11429 * commands.
11430 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11431 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11432 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011433 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011434# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011435/*
11436 * With multi-byte support use growarray for 'langmap' chars >= 256
11437 */
11438typedef struct
11439{
11440 int from;
11441 int to;
11442} langmap_entry_T;
11443
11444static garray_T langmap_mapga;
11445static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011446
11447/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011448 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11449 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011450 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011451 static void
11452langmap_set_entry(from, to)
11453 int from;
11454 int to;
11455{
11456 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011457 int a = 0;
11458 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011459
11460 /* Do a binary search for an existing entry. */
11461 while (a != b)
11462 {
11463 int i = (a + b) / 2;
11464 int d = entries[i].from - from;
11465
11466 if (d == 0)
11467 {
11468 entries[i].to = to;
11469 return;
11470 }
11471 if (d < 0)
11472 a = i + 1;
11473 else
11474 b = i;
11475 }
11476
11477 if (ga_grow(&langmap_mapga, 1) != OK)
11478 return; /* out of memory */
11479
11480 /* insert new entry at position "a" */
11481 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11482 mch_memmove(entries + 1, entries,
11483 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11484 ++langmap_mapga.ga_len;
11485 entries[0].from = from;
11486 entries[0].to = to;
11487}
11488
11489/*
11490 * Apply 'langmap' to multi-byte character "c" and return the result.
11491 */
11492 int
11493langmap_adjust_mb(c)
11494 int c;
11495{
11496 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11497 int a = 0;
11498 int b = langmap_mapga.ga_len;
11499
11500 while (a != b)
11501 {
11502 int i = (a + b) / 2;
11503 int d = entries[i].from - c;
11504
11505 if (d == 0)
11506 return entries[i].to; /* found matching entry */
11507 if (d < 0)
11508 a = i + 1;
11509 else
11510 b = i;
11511 }
11512 return c; /* no entry found, return "c" unmodified */
11513}
11514# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011515
11516 static void
11517langmap_init()
11518{
11519 int i;
11520
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011521 for (i = 0; i < 256; i++)
11522 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11523# ifdef FEAT_MBYTE
11524 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11525# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526}
11527
11528/*
11529 * Called when langmap option is set; the language map can be
11530 * changed at any time!
11531 */
11532 static void
11533langmap_set()
11534{
11535 char_u *p;
11536 char_u *p2;
11537 int from, to;
11538
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011539#ifdef FEAT_MBYTE
11540 ga_clear(&langmap_mapga); /* clear the previous map first */
11541#endif
11542 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011543
11544 for (p = p_langmap; p[0] != NUL; )
11545 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011546 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11547 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011548 {
11549 if (p2[0] == '\\' && p2[1] != NUL)
11550 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011551 }
11552 if (p2[0] == ';')
11553 ++p2; /* abcd;ABCD form, p2 points to A */
11554 else
11555 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11556 while (p[0])
11557 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011558 if (p[0] == ',')
11559 {
11560 ++p;
11561 break;
11562 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011563 if (p[0] == '\\' && p[1] != NUL)
11564 ++p;
11565#ifdef FEAT_MBYTE
11566 from = (*mb_ptr2char)(p);
11567#else
11568 from = p[0];
11569#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011570 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011571 if (p2 == NULL)
11572 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011573 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011574 if (p[0] != ',')
11575 {
11576 if (p[0] == '\\')
11577 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011578#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011579 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011581 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011582#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011583 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011584 }
11585 else
11586 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011587 if (p2[0] != ',')
11588 {
11589 if (p2[0] == '\\')
11590 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011591#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011592 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011593#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011594 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011595#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011596 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011597 }
11598 if (to == NUL)
11599 {
11600 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11601 transchar(from));
11602 return;
11603 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011604
11605#ifdef FEAT_MBYTE
11606 if (from >= 256)
11607 langmap_set_entry(from, to);
11608 else
11609#endif
11610 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011611
11612 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011613 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011614 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011615 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011616 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011617 if (*p == ';')
11618 {
11619 p = p2;
11620 if (p[0] != NUL)
11621 {
11622 if (p[0] != ',')
11623 {
11624 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11625 return;
11626 }
11627 ++p;
11628 }
11629 break;
11630 }
11631 }
11632 }
11633 }
11634}
11635#endif
11636
11637/*
11638 * Return TRUE if format option 'x' is in effect.
11639 * Take care of no formatting when 'paste' is set.
11640 */
11641 int
11642has_format_option(x)
11643 int x;
11644{
11645 if (p_paste)
11646 return FALSE;
11647 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11648}
11649
11650/*
11651 * Return TRUE if "x" is present in 'shortmess' option, or
11652 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11653 */
11654 int
11655shortmess(x)
11656 int x;
11657{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011658 return p_shm != NULL &&
11659 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011660 || (vim_strchr(p_shm, 'a') != NULL
11661 && vim_strchr((char_u *)SHM_A, x) != NULL));
11662}
11663
11664/*
11665 * paste_option_changed() - Called after p_paste was set or reset.
11666 */
11667 static void
11668paste_option_changed()
11669{
11670 static int old_p_paste = FALSE;
11671 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011672 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673#ifdef FEAT_CMDL_INFO
11674 static int save_ru = 0;
11675#endif
11676#ifdef FEAT_RIGHTLEFT
11677 static int save_ri = 0;
11678 static int save_hkmap = 0;
11679#endif
11680 buf_T *buf;
11681
11682 if (p_paste)
11683 {
11684 /*
11685 * Paste switched from off to on.
11686 * Save the current values, so they can be restored later.
11687 */
11688 if (!old_p_paste)
11689 {
11690 /* save options for each buffer */
11691 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11692 {
11693 buf->b_p_tw_nopaste = buf->b_p_tw;
11694 buf->b_p_wm_nopaste = buf->b_p_wm;
11695 buf->b_p_sts_nopaste = buf->b_p_sts;
11696 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011697 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011698 }
11699
11700 /* save global options */
11701 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011702 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011703#ifdef FEAT_CMDL_INFO
11704 save_ru = p_ru;
11705#endif
11706#ifdef FEAT_RIGHTLEFT
11707 save_ri = p_ri;
11708 save_hkmap = p_hkmap;
11709#endif
11710 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011711 p_ai_nopaste = p_ai;
11712 p_et_nopaste = p_et;
11713 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714 p_tw_nopaste = p_tw;
11715 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011716 }
11717
11718 /*
11719 * Always set the option values, also when 'paste' is set when it is
11720 * already on.
11721 */
11722 /* set options for each buffer */
11723 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11724 {
11725 buf->b_p_tw = 0; /* textwidth is 0 */
11726 buf->b_p_wm = 0; /* wrapmargin is 0 */
11727 buf->b_p_sts = 0; /* softtabstop is 0 */
11728 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011729 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011730 }
11731
11732 /* set global options */
11733 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011734 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735#ifdef FEAT_CMDL_INFO
11736# ifdef FEAT_WINDOWS
11737 if (p_ru)
11738 status_redraw_all(); /* redraw to remove the ruler */
11739# endif
11740 p_ru = 0; /* no ruler */
11741#endif
11742#ifdef FEAT_RIGHTLEFT
11743 p_ri = 0; /* no reverse insert */
11744 p_hkmap = 0; /* no Hebrew keyboard */
11745#endif
11746 /* set global values for local buffer options */
11747 p_tw = 0;
11748 p_wm = 0;
11749 p_sts = 0;
11750 p_ai = 0;
11751 }
11752
11753 /*
11754 * Paste switched from on to off: Restore saved values.
11755 */
11756 else if (old_p_paste)
11757 {
11758 /* restore options for each buffer */
11759 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11760 {
11761 buf->b_p_tw = buf->b_p_tw_nopaste;
11762 buf->b_p_wm = buf->b_p_wm_nopaste;
11763 buf->b_p_sts = buf->b_p_sts_nopaste;
11764 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011765 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011766 }
11767
11768 /* restore global options */
11769 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011770 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771#ifdef FEAT_CMDL_INFO
11772# ifdef FEAT_WINDOWS
11773 if (p_ru != save_ru)
11774 status_redraw_all(); /* redraw to draw the ruler */
11775# endif
11776 p_ru = save_ru;
11777#endif
11778#ifdef FEAT_RIGHTLEFT
11779 p_ri = save_ri;
11780 p_hkmap = save_hkmap;
11781#endif
11782 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011783 p_ai = p_ai_nopaste;
11784 p_et = p_et_nopaste;
11785 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011786 p_tw = p_tw_nopaste;
11787 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011788 }
11789
11790 old_p_paste = p_paste;
11791}
11792
11793/*
11794 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11795 *
11796 * Reset 'compatible' and set the values for options that didn't get set yet
11797 * to the Vim defaults.
11798 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011799 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011800 */
11801 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011802vimrc_found(fname, envname)
11803 char_u *fname;
11804 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011806 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011807 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011808 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011809
11810 if (!option_was_set((char_u *)"cp"))
11811 {
11812 p_cp = FALSE;
11813 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11814 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11815 set_option_default(opt_idx, OPT_FREE, FALSE);
11816 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011817 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011818 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011819
11820 if (fname != NULL)
11821 {
11822 p = vim_getenv(envname, &dofree);
11823 if (p == NULL)
11824 {
11825 /* Set $MYVIMRC to the first vimrc file found. */
11826 p = FullName_save(fname, FALSE);
11827 if (p != NULL)
11828 {
11829 vim_setenv(envname, p);
11830 vim_free(p);
11831 }
11832 }
11833 else if (dofree)
11834 vim_free(p);
11835 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011836}
11837
11838/*
11839 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11840 */
11841 void
11842change_compatible(on)
11843 int on;
11844{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011845 int opt_idx;
11846
Bram Moolenaar071d4272004-06-13 20:20:40 +000011847 if (p_cp != on)
11848 {
11849 p_cp = on;
11850 compatible_set();
11851 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011852 opt_idx = findoption((char_u *)"cp");
11853 if (opt_idx >= 0)
11854 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855}
11856
11857/*
11858 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011859 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011860 */
11861 int
11862option_was_set(name)
11863 char_u *name;
11864{
11865 int idx;
11866
11867 idx = findoption(name);
11868 if (idx < 0) /* unknown option */
11869 return FALSE;
11870 if (options[idx].flags & P_WAS_SET)
11871 return TRUE;
11872 return FALSE;
11873}
11874
11875/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011876 * Reset the flag indicating option "name" was set.
11877 */
11878 void
11879reset_option_was_set(name)
11880 char_u *name;
11881{
11882 int idx = findoption(name);
11883
11884 if (idx >= 0)
11885 options[idx].flags &= ~P_WAS_SET;
11886}
11887
11888/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889 * compatible_set() - Called when 'compatible' has been set or unset.
11890 *
11891 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11892 * flag) to a Vi compatible value.
11893 * When 'compatible' is unset: Set all options that have a different default
11894 * for Vim (without the P_VI_DEF flag) to that default.
11895 */
11896 static void
11897compatible_set()
11898{
11899 int opt_idx;
11900
11901 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11902 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11903 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11904 set_option_default(opt_idx, OPT_FREE, p_cp);
11905 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011906 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011907}
11908
11909#ifdef FEAT_LINEBREAK
11910
11911# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11912 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011913 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011914# endif
11915
11916/*
11917 * fill_breakat_flags() -- called when 'breakat' changes value.
11918 */
11919 static void
11920fill_breakat_flags()
11921{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011922 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011923 int i;
11924
11925 for (i = 0; i < 256; i++)
11926 breakat_flags[i] = FALSE;
11927
11928 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011929 for (p = p_breakat; *p; p++)
11930 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011931}
11932
11933# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011934 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011935# endif
11936
11937#endif
11938
11939/*
11940 * Check an option that can be a range of string values.
11941 *
11942 * Return OK for correct value, FAIL otherwise.
11943 * Empty is always OK.
11944 */
11945 static int
11946check_opt_strings(val, values, list)
11947 char_u *val;
11948 char **values;
11949 int list; /* when TRUE: accept a list of values */
11950{
11951 return opt_strings_flags(val, values, NULL, list);
11952}
11953
11954/*
11955 * Handle an option that can be a range of string values.
11956 * Set a flag in "*flagp" for each string present.
11957 *
11958 * Return OK for correct value, FAIL otherwise.
11959 * Empty is always OK.
11960 */
11961 static int
11962opt_strings_flags(val, values, flagp, list)
11963 char_u *val; /* new value */
11964 char **values; /* array of valid string values */
11965 unsigned *flagp;
11966 int list; /* when TRUE: accept a list of values */
11967{
11968 int i;
11969 int len;
11970 unsigned new_flags = 0;
11971
11972 while (*val)
11973 {
11974 for (i = 0; ; ++i)
11975 {
11976 if (values[i] == NULL) /* val not found in values[] */
11977 return FAIL;
11978
11979 len = (int)STRLEN(values[i]);
11980 if (STRNCMP(values[i], val, len) == 0
11981 && ((list && val[len] == ',') || val[len] == NUL))
11982 {
11983 val += len + (val[len] == ',');
11984 new_flags |= (1 << i);
11985 break; /* check next item in val list */
11986 }
11987 }
11988 }
11989 if (flagp != NULL)
11990 *flagp = new_flags;
11991
11992 return OK;
11993}
11994
11995/*
11996 * Read the 'wildmode' option, fill wim_flags[].
11997 */
11998 static int
11999check_opt_wim()
12000{
12001 char_u new_wim_flags[4];
12002 char_u *p;
12003 int i;
12004 int idx = 0;
12005
12006 for (i = 0; i < 4; ++i)
12007 new_wim_flags[i] = 0;
12008
12009 for (p = p_wim; *p; ++p)
12010 {
12011 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12012 ;
12013 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12014 return FAIL;
12015 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12016 new_wim_flags[idx] |= WIM_LONGEST;
12017 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12018 new_wim_flags[idx] |= WIM_FULL;
12019 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12020 new_wim_flags[idx] |= WIM_LIST;
12021 else
12022 return FAIL;
12023 p += i;
12024 if (*p == NUL)
12025 break;
12026 if (*p == ',')
12027 {
12028 if (idx == 3)
12029 return FAIL;
12030 ++idx;
12031 }
12032 }
12033
12034 /* fill remaining entries with last flag */
12035 while (idx < 3)
12036 {
12037 new_wim_flags[idx + 1] = new_wim_flags[idx];
12038 ++idx;
12039 }
12040
12041 /* only when there are no errors, wim_flags[] is changed */
12042 for (i = 0; i < 4; ++i)
12043 wim_flags[i] = new_wim_flags[i];
12044 return OK;
12045}
12046
12047/*
12048 * Check if backspacing over something is allowed.
12049 */
12050 int
12051can_bs(what)
12052 int what; /* BS_INDENT, BS_EOL or BS_START */
12053{
12054 switch (*p_bs)
12055 {
12056 case '2': return TRUE;
12057 case '1': return (what != BS_START);
12058 case '0': return FALSE;
12059 }
12060 return vim_strchr(p_bs, what) != NULL;
12061}
12062
12063/*
12064 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12065 * the file must be considered changed when the value is different.
12066 */
12067 void
12068save_file_ff(buf)
12069 buf_T *buf;
12070{
12071 buf->b_start_ffc = *buf->b_p_ff;
12072 buf->b_start_eol = buf->b_p_eol;
12073#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012074 buf->b_start_bomb = buf->b_p_bomb;
12075
Bram Moolenaar071d4272004-06-13 20:20:40 +000012076 /* Only use free/alloc when necessary, they take time. */
12077 if (buf->b_start_fenc == NULL
12078 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12079 {
12080 vim_free(buf->b_start_fenc);
12081 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12082 }
12083#endif
12084}
12085
12086/*
12087 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12088 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012089 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12090 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012091 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012092 * When "ignore_empty" is true don't consider a new, empty buffer to be
12093 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012094 */
12095 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012096file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012097 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012098 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012099{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012100 /* In a buffer that was never loaded the options are not valid. */
12101 if (buf->b_flags & BF_NEVERLOADED)
12102 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012103 if (ignore_empty
12104 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012105 && buf->b_ml.ml_line_count == 1
12106 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12107 return FALSE;
12108 if (buf->b_start_ffc != *buf->b_p_ff)
12109 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012110 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012111 return TRUE;
12112#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012113 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12114 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012115 if (buf->b_start_fenc == NULL)
12116 return (*buf->b_p_fenc != NUL);
12117 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12118#else
12119 return FALSE;
12120#endif
12121}
12122
12123/*
12124 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12125 */
12126 int
12127check_ff_value(p)
12128 char_u *p;
12129{
12130 return check_opt_strings(p, p_ff_values, FALSE);
12131}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012132
12133/*
12134 * Return the effective shiftwidth value for current buffer, using the
12135 * 'tabstop' value when 'shiftwidth' is zero.
12136 */
12137 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012138get_sw_value(buf)
12139 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012140{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012141 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012142}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012143
12144/*
12145 * Return the effective softtabstop value for the current buffer, using the
12146 * 'tabstop' value when 'softtabstop' is negative.
12147 */
12148 long
12149get_sts_value()
12150{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012151 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012152}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012153
12154/*
12155 * Check matchpairs option for "*initc".
12156 * If there is a match set "*initc" to the matching character and "*findc" to
12157 * the opposite character. Set "*backwards" to the direction.
12158 * When "switchit" is TRUE swap the direction.
12159 */
12160 void
12161find_mps_values(initc, findc, backwards, switchit)
12162 int *initc;
12163 int *findc;
12164 int *backwards;
12165 int switchit;
12166{
12167 char_u *ptr;
12168
12169 ptr = curbuf->b_p_mps;
12170 while (*ptr != NUL)
12171 {
12172#ifdef FEAT_MBYTE
12173 if (has_mbyte)
12174 {
12175 char_u *prev;
12176
12177 if (mb_ptr2char(ptr) == *initc)
12178 {
12179 if (switchit)
12180 {
12181 *findc = *initc;
12182 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12183 *backwards = TRUE;
12184 }
12185 else
12186 {
12187 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12188 *backwards = FALSE;
12189 }
12190 return;
12191 }
12192 prev = ptr;
12193 ptr += mb_ptr2len(ptr) + 1;
12194 if (mb_ptr2char(ptr) == *initc)
12195 {
12196 if (switchit)
12197 {
12198 *findc = *initc;
12199 *initc = mb_ptr2char(prev);
12200 *backwards = FALSE;
12201 }
12202 else
12203 {
12204 *findc = mb_ptr2char(prev);
12205 *backwards = TRUE;
12206 }
12207 return;
12208 }
12209 ptr += mb_ptr2len(ptr);
12210 }
12211 else
12212#endif
12213 {
12214 if (*ptr == *initc)
12215 {
12216 if (switchit)
12217 {
12218 *backwards = TRUE;
12219 *findc = *initc;
12220 *initc = ptr[2];
12221 }
12222 else
12223 {
12224 *backwards = FALSE;
12225 *findc = ptr[2];
12226 }
12227 return;
12228 }
12229 ptr += 2;
12230 if (*ptr == *initc)
12231 {
12232 if (switchit)
12233 {
12234 *backwards = FALSE;
12235 *findc = *initc;
12236 *initc = ptr[-2];
12237 }
12238 else
12239 {
12240 *backwards = TRUE;
12241 *findc = ptr[-2];
12242 }
12243 return;
12244 }
12245 ++ptr;
12246 }
12247 if (*ptr == ',')
12248 ++ptr;
12249 }
12250}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012251
12252#if defined(FEAT_LINEBREAK) || defined(PROTO)
12253/*
12254 * This is called when 'breakindentopt' is changed and when a window is
12255 * initialized.
12256 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012257 static int
12258briopt_check(wp)
12259 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012260{
12261 char_u *p;
12262 int bri_shift = 0;
12263 long bri_min = 20;
12264 int bri_sbr = FALSE;
12265
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012266 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012267 while (*p != NUL)
12268 {
12269 if (STRNCMP(p, "shift:", 6) == 0
12270 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12271 {
12272 p += 6;
12273 bri_shift = getdigits(&p);
12274 }
12275 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12276 {
12277 p += 4;
12278 bri_min = getdigits(&p);
12279 }
12280 else if (STRNCMP(p, "sbr", 3) == 0)
12281 {
12282 p += 3;
12283 bri_sbr = TRUE;
12284 }
12285 if (*p != ',' && *p != NUL)
12286 return FAIL;
12287 if (*p == ',')
12288 ++p;
12289 }
12290
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012291 wp->w_p_brishift = bri_shift;
12292 wp->w_p_brimin = bri_min;
12293 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012294
12295 return OK;
12296}
12297#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012298
12299/*
12300 * Get the local or global value of 'backupcopy'.
12301 */
12302 unsigned int
12303get_bkc_value(buf)
12304 buf_T *buf;
12305{
12306 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12307}