blob: 7c9f9c8f523cf48f9af987037953165c2400e9d2 [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)
2984 p_term("t_Co", T_CCO)
2985 p_term("t_CS", T_CCS)
2986 p_term("t_cs", T_CS)
2987#ifdef FEAT_VERTSPLIT
2988 p_term("t_CV", T_CSV)
2989#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 p_term("t_da", T_DA)
2991 p_term("t_db", T_DB)
2992 p_term("t_DL", T_CDL)
2993 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002994 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 p_term("t_fs", T_FS)
2996 p_term("t_IE", T_CIE)
2997 p_term("t_IS", T_CIS)
2998 p_term("t_ke", T_KE)
2999 p_term("t_ks", T_KS)
3000 p_term("t_le", T_LE)
3001 p_term("t_mb", T_MB)
3002 p_term("t_md", T_MD)
3003 p_term("t_me", T_ME)
3004 p_term("t_mr", T_MR)
3005 p_term("t_ms", T_MS)
3006 p_term("t_nd", T_ND)
3007 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003008 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 p_term("t_RI", T_CRI)
3010 p_term("t_RV", T_CRV)
3011 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003013 p_term("t_Sf", T_CSF)
3014 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003016 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 p_term("t_te", T_TE)
3019 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003020 p_term("t_ts", T_TS)
3021 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 p_term("t_ue", T_UE)
3023 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003024 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 p_term("t_vb", T_VB)
3026 p_term("t_ve", T_VE)
3027 p_term("t_vi", T_VI)
3028 p_term("t_vs", T_VS)
3029 p_term("t_WP", T_CWP)
3030 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003031 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 p_term("t_xs", T_XS)
3033 p_term("t_ZH", T_CZH)
3034 p_term("t_ZR", T_CZR)
3035
3036/* terminal key codes are not in here */
3037
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003038 /* end marker */
3039 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040};
3041
3042#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3043
3044#ifdef FEAT_MBYTE
3045static char *(p_ambw_values[]) = {"single", "double", NULL};
3046#endif
3047static char *(p_bg_values[]) = {"light", "dark", NULL};
3048static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3049static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003050#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003051static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003052#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003053#ifdef FEAT_CMDL_COMPL
3054static char *(p_wop_values[]) = {"tagfile", NULL};
3055#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056#ifdef FEAT_WAK
3057static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3058#endif
3059static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3061static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063#ifdef FEAT_BROWSE
3064static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3065#endif
3066#ifdef FEAT_SCROLLBIND
3067static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3068#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003069static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070#ifdef FEAT_VERTSPLIT
3071static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3072#endif
3073#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003074# ifdef FEAT_AUTOCMD
3075static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3076# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003078# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3080#endif
3081static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3082#ifdef FEAT_FOLDING
3083static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003084# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003086# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 NULL};
3088static char *(p_fcl_values[]) = {"all", NULL};
3089#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003090#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003091static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003092#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093
3094static void set_option_default __ARGS((int, int opt_flags, int compatible));
3095static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003096static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003097static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098static char_u *illegal_char __ARGS((char_u *, int));
3099static int string_to_key __ARGS((char_u *arg));
3100#ifdef FEAT_CMDWIN
3101static char_u *check_cedit __ARGS((void));
3102#endif
3103#ifdef FEAT_TITLE
3104static void did_set_title __ARGS((int icon));
3105#endif
3106static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3107static void didset_options __ARGS((void));
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003108static void didset_options2 __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003110#if defined(FEAT_EVAL) || defined(PROTO)
3111static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3112#else
3113# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3114#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003116static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117static 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));
3118static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003119#ifdef FEAT_SYN_HL
3120static int int_cmp __ARGS((const void *a, const void *b));
3121#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122#ifdef FEAT_CLIPBOARD
3123static char_u *check_clipboard_option __ARGS((void));
3124#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003125#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003126static char_u *did_set_spell_option __ARGS((int is_spellfile));
Bram Moolenaar860cae12010-06-05 23:22:07 +02003127static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003128#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003129#ifdef FEAT_EVAL
3130static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003133static 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 +00003134static void check_redraw __ARGS((long_u flags));
3135static int findoption __ARGS((char_u *));
3136static int find_key_option __ARGS((char_u *));
3137static void showoptions __ARGS((int all, int opt_flags));
3138static int optval_default __ARGS((struct vimoption *, char_u *varp));
3139static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3140static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3141static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3142static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3143static int istermoption __ARGS((struct vimoption *));
3144static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3145static char_u *get_varp __ARGS((struct vimoption *));
3146static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003147static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3149#ifdef FEAT_LANGMAP
3150static void langmap_init __ARGS((void));
3151static void langmap_set __ARGS((void));
3152#endif
3153static void paste_option_changed __ARGS((void));
3154static void compatible_set __ARGS((void));
3155#ifdef FEAT_LINEBREAK
3156static void fill_breakat_flags __ARGS((void));
3157#endif
3158static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3159static int check_opt_strings __ARGS((char_u *val, char **values, int));
3160static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003161#ifdef FEAT_LINEBREAK
3162static int briopt_check __ARGS((win_T *wp));
3163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164
3165/*
3166 * Initialize the options, first part.
3167 *
3168 * Called only once from main(), just after creating the first buffer.
3169 */
3170 void
3171set_init_1()
3172{
3173 char_u *p;
3174 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003175 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176
3177#ifdef FEAT_LANGMAP
3178 langmap_init();
3179#endif
3180
3181 /* Be Vi compatible by default */
3182 p_cp = TRUE;
3183
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003184 /* Use POSIX compatibility when $VIM_POSIX is set. */
3185 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003186 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003187 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003188 set_string_default("shm", (char_u *)"A");
3189 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003190
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 /*
3192 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003193 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003195 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3197# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003198 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003200 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003202 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203# endif
3204#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003205 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206 set_string_default("sh", p);
3207
3208#ifdef FEAT_WILDIGN
3209 /*
3210 * Set the default for 'backupskip' to include environment variables for
3211 * temp files.
3212 */
3213 {
3214# ifdef UNIX
3215 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3216# else
3217 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3218# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003219 int len;
3220 garray_T ga;
3221 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222
3223 ga_init2(&ga, 1, 100);
3224 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3225 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003226 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227# ifdef UNIX
3228 if (*names[n] == NUL)
3229 p = (char_u *)"/tmp";
3230 else
3231# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003232 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233 if (p != NULL && *p != NUL)
3234 {
3235 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003236 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237 if (ga_grow(&ga, len) == OK)
3238 {
3239 if (ga.ga_len > 0)
3240 STRCAT(ga.ga_data, ",");
3241 STRCAT(ga.ga_data, p);
3242 add_pathsep(ga.ga_data);
3243 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244 ga.ga_len += len;
3245 }
3246 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003247 if (mustfree)
3248 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249 }
3250 if (ga.ga_data != NULL)
3251 {
3252 set_string_default("bsk", ga.ga_data);
3253 vim_free(ga.ga_data);
3254 }
3255 }
3256#endif
3257
3258 /*
3259 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3260 */
3261 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003262 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003264#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3265 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3266#endif
3267 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003269 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003270 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003271#else
3272# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003273 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003274 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003276 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277# endif
3278#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003280 opt_idx = findoption((char_u *)"maxmem");
3281 if (opt_idx >= 0)
3282 {
3283#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003284 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003285 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3286#endif
3287 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3288 }
3289 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003290 }
3291
3292#ifdef FEAT_GUI_W32
3293 /* force 'shortname' for Win32s */
3294 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003295 {
3296 opt_idx = findoption((char_u *)"shortname");
3297 if (opt_idx >= 0)
3298 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3299 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#endif
3301
3302#ifdef FEAT_SEARCHPATH
3303 {
3304 char_u *cdpath;
3305 char_u *buf;
3306 int i;
3307 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003308 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309
3310 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003311 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003312 if (cdpath != NULL)
3313 {
3314 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3315 if (buf != NULL)
3316 {
3317 buf[0] = ','; /* start with ",", current dir first */
3318 j = 1;
3319 for (i = 0; cdpath[i] != NUL; ++i)
3320 {
3321 if (vim_ispathlistsep(cdpath[i]))
3322 buf[j++] = ',';
3323 else
3324 {
3325 if (cdpath[i] == ' ' || cdpath[i] == ',')
3326 buf[j++] = '\\';
3327 buf[j++] = cdpath[i];
3328 }
3329 }
3330 buf[j] = NUL;
3331 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003332 if (opt_idx >= 0)
3333 {
3334 options[opt_idx].def_val[VI_DEFAULT] = buf;
3335 options[opt_idx].flags |= P_DEF_ALLOCED;
3336 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003337 else
3338 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003340 if (mustfree)
3341 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342 }
3343 }
3344#endif
3345
3346#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3347 /* Set print encoding on platforms that don't default to latin1 */
3348 set_string_default("penc",
3349# if defined(MSWIN) || defined(OS2)
3350 (char_u *)"cp1252"
3351# else
3352# ifdef VMS
3353 (char_u *)"dec-mcs"
3354# else
3355# ifdef EBCDIC
3356 (char_u *)"ebcdic-uk"
3357# else
3358# ifdef MAC
3359 (char_u *)"mac-roman"
3360# else /* HPUX */
3361 (char_u *)"hp-roman8"
3362# endif
3363# endif
3364# endif
3365# endif
3366 );
3367#endif
3368
3369#ifdef FEAT_POSTSCRIPT
3370 /* 'printexpr' must be allocated to be able to evaluate it. */
3371 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003372# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3373 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374# else
3375# ifdef VMS
3376 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3377
3378# else
3379 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3380# endif
3381# endif
3382 );
3383#endif
3384
3385 /*
3386 * Set all the options (except the terminal options) to their default
3387 * value. Also set the global value for local options.
3388 */
3389 set_options_default(0);
3390
3391#ifdef FEAT_GUI
3392 if (found_reverse_arg)
3393 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3394#endif
3395
3396 curbuf->b_p_initialized = TRUE;
3397 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003398 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399 check_buf_options(curbuf);
3400 check_win_options(curwin);
3401 check_options();
3402
3403 /* Must be before option_expand(), because that one needs vim_isIDc() */
3404 didset_options();
3405
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003406#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003407 /* Use the current chartab for the generic chartab. This is not in
3408 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003409 init_spell_chartab();
3410#endif
3411
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412 /*
3413 * Expand environment variables and things like "~" for the defaults.
3414 * If option_expand() returns non-NULL the variable is expanded. This can
3415 * only happen for non-indirect options.
3416 * Also set the default to the expanded value, so ":set" does not list
3417 * them.
3418 * Don't set the P_ALLOCED flag, because we don't want to free the
3419 * default.
3420 */
3421 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3422 {
3423 if ((options[opt_idx].flags & P_GETTEXT)
3424 && options[opt_idx].var != NULL)
3425 p = (char_u *)_(*(char **)options[opt_idx].var);
3426 else
3427 p = option_expand(opt_idx, NULL);
3428 if (p != NULL && (p = vim_strsave(p)) != NULL)
3429 {
3430 *(char_u **)options[opt_idx].var = p;
3431 /* VIMEXP
3432 * Defaults for all expanded options are currently the same for Vi
3433 * and Vim. When this changes, add some code here! Also need to
3434 * split P_DEF_ALLOCED in two.
3435 */
3436 if (options[opt_idx].flags & P_DEF_ALLOCED)
3437 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3438 options[opt_idx].def_val[VI_DEFAULT] = p;
3439 options[opt_idx].flags |= P_DEF_ALLOCED;
3440 }
3441 }
3442
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 save_file_ff(curbuf); /* Buffer is unchanged */
3444
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445#if defined(FEAT_ARABIC)
3446 /* Detect use of mlterm.
3447 * Mlterm is a terminal emulator akin to xterm that has some special
3448 * abilities (bidi namely).
3449 * NOTE: mlterm's author is being asked to 'set' a variable
3450 * instead of an environment variable due to inheritance.
3451 */
3452 if (mch_getenv((char_u *)"MLTERM") != NULL)
3453 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3454#endif
3455
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003456 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457
3458#ifdef FEAT_MBYTE
3459# if defined(WIN3264) && defined(FEAT_GETTEXT)
3460 /*
3461 * If $LANG isn't set, try to get a good value for it. This makes the
3462 * right language be used automatically. Don't do this for English.
3463 */
3464 if (mch_getenv((char_u *)"LANG") == NULL)
3465 {
3466 char buf[20];
3467
3468 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3469 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3470 * only the first two. */
3471 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3472 (LPTSTR)buf, 20);
3473 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3474 {
3475 /* There are a few exceptions (probably more) */
3476 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3477 STRCPY(buf, "zh_TW");
3478 else if (STRNICMP(buf, "chs", 3) == 0
3479 || STRNICMP(buf, "zhc", 3) == 0)
3480 STRCPY(buf, "zh_CN");
3481 else if (STRNICMP(buf, "jp", 2) == 0)
3482 STRCPY(buf, "ja");
3483 else
3484 buf[2] = NUL; /* truncate to two-letter code */
3485 vim_setenv("LANG", buf);
3486 }
3487 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003488# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003489# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003490 /* Moved to os_mac_conv.c to avoid dependency problems. */
3491 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003492# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493# endif
3494
3495 /* enc_locale() will try to find the encoding of the current locale. */
3496 p = enc_locale();
3497 if (p != NULL)
3498 {
3499 char_u *save_enc;
3500
3501 /* Try setting 'encoding' and check if the value is valid.
3502 * If not, go back to the default "latin1". */
3503 save_enc = p_enc;
3504 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003505 if (STRCMP(p_enc, "gb18030") == 0)
3506 {
3507 /* We don't support "gb18030", but "cp936" is a good substitute
3508 * for practical purposes, thus use that. It's not an alias to
3509 * still support conversion between gb18030 and utf-8. */
3510 p_enc = vim_strsave((char_u *)"cp936");
3511 vim_free(p);
3512 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003513 if (mb_init() == NULL)
3514 {
3515 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003516 if (opt_idx >= 0)
3517 {
3518 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3519 options[opt_idx].flags |= P_DEF_ALLOCED;
3520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003522#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3523 || defined(VMS)
3524 if (STRCMP(p_enc, "latin1") == 0
3525# ifdef FEAT_MBYTE
3526 || enc_utf8
3527# endif
3528 )
3529 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003530 /* Adjust the default for 'isprint' and 'iskeyword' to match
3531 * latin1. Also set the defaults for when 'nocompatible' is
3532 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003533 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003534 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003535 set_string_option_direct((char_u *)"isk", -1,
3536 ISK_LATIN1, OPT_FREE, SID_NONE);
3537 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003538 if (opt_idx >= 0)
3539 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003540 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003541 if (opt_idx >= 0)
3542 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003543 (void)init_chartab();
3544 }
3545#endif
3546
Bram Moolenaar071d4272004-06-13 20:20:40 +00003547# if defined(WIN3264) && !defined(FEAT_GUI)
3548 /* Win32 console: When GetACP() returns a different value from
3549 * GetConsoleCP() set 'termencoding'. */
3550 if (GetACP() != GetConsoleCP())
3551 {
3552 char buf[50];
3553
3554 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3555 p_tenc = vim_strsave((char_u *)buf);
3556 if (p_tenc != NULL)
3557 {
3558 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003559 if (opt_idx >= 0)
3560 {
3561 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3562 options[opt_idx].flags |= P_DEF_ALLOCED;
3563 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564 convert_setup(&input_conv, p_tenc, p_enc);
3565 convert_setup(&output_conv, p_enc, p_tenc);
3566 }
3567 else
3568 p_tenc = empty_option;
3569 }
3570# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003571# if defined(WIN3264) && defined(FEAT_MBYTE)
3572 /* $HOME may have characters in active code page. */
3573 init_homedir();
3574# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003575 }
3576 else
3577 {
3578 vim_free(p_enc);
3579 p_enc = save_enc;
3580 }
3581 }
3582#endif
3583
3584#ifdef FEAT_MULTI_LANG
3585 /* Set the default for 'helplang'. */
3586 set_helplang_default(get_mess_lang());
3587#endif
3588}
3589
3590/*
3591 * Set an option to its default value.
3592 * This does not take care of side effects!
3593 */
3594 static void
3595set_option_default(opt_idx, opt_flags, compatible)
3596 int opt_idx;
3597 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3598 int compatible; /* use Vi default value */
3599{
3600 char_u *varp; /* pointer to variable for current option */
3601 int dvi; /* index in def_val[] */
3602 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003603 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3605
3606 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3607 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003608 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609 {
3610 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3611 if (flags & P_STRING)
3612 {
3613 /* Use set_string_option_direct() for local options to handle
3614 * freeing and allocating the value. */
3615 if (options[opt_idx].indir != PV_NONE)
3616 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003617 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 else
3619 {
3620 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3621 free_string_option(*(char_u **)(varp));
3622 *(char_u **)varp = options[opt_idx].def_val[dvi];
3623 options[opt_idx].flags &= ~P_ALLOCED;
3624 }
3625 }
3626 else if (flags & P_NUM)
3627 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003628 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629 win_comp_scroll(curwin);
3630 else
3631 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003632 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003633 /* May also set global value for local option. */
3634 if (both)
3635 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3636 *(long *)varp;
3637 }
3638 }
3639 else /* P_BOOL */
3640 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003641 /* the cast to long is required for Manx C, long_i is needed for
3642 * MSVC */
3643 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003644#ifdef UNIX
3645 /* 'modeline' defaults to off for root */
3646 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3647 *(int *)varp = FALSE;
3648#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649 /* May also set global value for local option. */
3650 if (both)
3651 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3652 *(int *)varp;
3653 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003654
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003655 /* The default value is not insecure. */
3656 flagsp = insecure_flag(opt_idx, opt_flags);
3657 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658 }
3659
3660#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003661 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662#endif
3663}
3664
3665/*
3666 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003667 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003668 */
3669 static void
3670set_options_default(opt_flags)
3671 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3672{
3673 int i;
3674#ifdef FEAT_WINDOWS
3675 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003676 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677#endif
3678
3679 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003680 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003681#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003682 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003683 || (TRUE
3684# if defined(FEAT_MBYTE)
3685 && options[i].var != (char_u *)&p_enc
3686# endif
3687# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003688 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003689 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003690# endif
3691 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003692#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003693 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694 set_option_default(i, opt_flags, p_cp);
3695
3696#ifdef FEAT_WINDOWS
3697 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003698 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003699 win_comp_scroll(wp);
3700#else
3701 win_comp_scroll(curwin);
3702#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003703#ifdef FEAT_CINDENT
3704 parse_cino(curbuf);
3705#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706}
3707
3708/*
3709 * Set the Vi-default value of a string option.
3710 * Used for 'sh', 'backupskip' and 'term'.
3711 */
3712 void
3713set_string_default(name, val)
3714 char *name;
3715 char_u *val;
3716{
3717 char_u *p;
3718 int opt_idx;
3719
3720 p = vim_strsave(val);
3721 if (p != NULL) /* we don't want a NULL */
3722 {
3723 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003724 if (opt_idx >= 0)
3725 {
3726 if (options[opt_idx].flags & P_DEF_ALLOCED)
3727 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3728 options[opt_idx].def_val[VI_DEFAULT] = p;
3729 options[opt_idx].flags |= P_DEF_ALLOCED;
3730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731 }
3732}
3733
3734/*
3735 * Set the Vi-default value of a number option.
3736 * Used for 'lines' and 'columns'.
3737 */
3738 void
3739set_number_default(name, val)
3740 char *name;
3741 long val;
3742{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003743 int opt_idx;
3744
3745 opt_idx = findoption((char_u *)name);
3746 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003747 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748}
3749
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003750#if defined(EXITFREE) || defined(PROTO)
3751/*
3752 * Free all options.
3753 */
3754 void
3755free_all_options()
3756{
3757 int i;
3758
3759 for (i = 0; !istermoption(&options[i]); i++)
3760 {
3761 if (options[i].indir == PV_NONE)
3762 {
3763 /* global option: free value and default value. */
3764 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3765 free_string_option(*(char_u **)options[i].var);
3766 if (options[i].flags & P_DEF_ALLOCED)
3767 free_string_option(options[i].def_val[VI_DEFAULT]);
3768 }
3769 else if (options[i].var != VAR_WIN
3770 && (options[i].flags & P_STRING))
3771 /* buffer-local option: free global value */
3772 free_string_option(*(char_u **)options[i].var);
3773 }
3774}
3775#endif
3776
3777
Bram Moolenaar071d4272004-06-13 20:20:40 +00003778/*
3779 * Initialize the options, part two: After getting Rows and Columns and
3780 * setting 'term'.
3781 */
3782 void
3783set_init_2()
3784{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003785 int idx;
3786
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 /*
3788 * 'scroll' defaults to half the window height. Note that this default is
3789 * wrong when the window height changes.
3790 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003791 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003792 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003793 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003794 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 comp_col();
3796
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003797 /*
3798 * 'window' is only for backwards compatibility with Vi.
3799 * Default is Rows - 1.
3800 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003801 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003802 p_window = Rows - 1;
3803 set_number_default("window", Rows - 1);
3804
Bram Moolenaarf740b292006-02-16 22:11:02 +00003805 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003807 /*
3808 * If 'background' wasn't set by the user, try guessing the value,
3809 * depending on the terminal name. Only need to check for terminals
3810 * with a dark background, that can handle color.
3811 */
3812 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003813 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3814 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003816 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003817 /* don't mark it as set, when starting the GUI it may be
3818 * changed again */
3819 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 }
3821#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003822
3823#ifdef CURSOR_SHAPE
3824 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3825#endif
3826#ifdef FEAT_MOUSESHAPE
3827 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3828#endif
3829#ifdef FEAT_PRINTER
3830 (void)parse_printoptions(); /* parse 'printoptions' default value */
3831#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003832}
3833
3834/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003835 * Return "dark" or "light" depending on the kind of terminal.
3836 * This is just guessing! Recognized are:
3837 * "linux" Linux console
3838 * "screen.linux" Linux console with screen
3839 * "cygwin" Cygwin shell
3840 * "putty" Putty program
3841 * We also check the COLORFGBG environment variable, which is set by
3842 * rxvt and derivatives. This variable contains either two or three
3843 * values separated by semicolons; we want the last value in either
3844 * case. If this value is 0-6 or 8, our background is dark.
3845 */
3846 static char_u *
3847term_bg_default()
3848{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003849#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3850 /* DOS console nearly always black */
3851 return (char_u *)"dark";
3852#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003853 char_u *p;
3854
Bram Moolenaarf740b292006-02-16 22:11:02 +00003855 if (STRCMP(T_NAME, "linux") == 0
3856 || STRCMP(T_NAME, "screen.linux") == 0
3857 || STRCMP(T_NAME, "cygwin") == 0
3858 || STRCMP(T_NAME, "putty") == 0
3859 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3860 && (p = vim_strrchr(p, ';')) != NULL
3861 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3862 && p[2] == NUL))
3863 return (char_u *)"dark";
3864 return (char_u *)"light";
3865#endif
3866}
3867
3868/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 * Initialize the options, part three: After reading the .vimrc
3870 */
3871 void
3872set_init_3()
3873{
3874#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3875/*
3876 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3877 * This is done after other initializations, where 'shell' might have been
3878 * set, but only if they have not been set before.
3879 */
3880 char_u *p;
3881 int idx_srr;
3882 int do_srr;
3883#ifdef FEAT_QUICKFIX
3884 int idx_sp;
3885 int do_sp;
3886#endif
3887
3888 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003889 if (idx_srr < 0)
3890 do_srr = FALSE;
3891 else
3892 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893#ifdef FEAT_QUICKFIX
3894 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003895 if (idx_sp < 0)
3896 do_sp = FALSE;
3897 else
3898 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003899#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003900 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 if (p != NULL)
3902 {
3903 /*
3904 * Default for p_sp is "| tee", for p_srr is ">".
3905 * For known shells it is changed here to include stderr.
3906 */
3907 if ( fnamecmp(p, "csh") == 0
3908 || fnamecmp(p, "tcsh") == 0
3909# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3910 || fnamecmp(p, "csh.exe") == 0
3911 || fnamecmp(p, "tcsh.exe") == 0
3912# endif
3913 )
3914 {
3915#if defined(FEAT_QUICKFIX)
3916 if (do_sp)
3917 {
3918# ifdef WIN3264
3919 p_sp = (char_u *)">&";
3920# else
3921 p_sp = (char_u *)"|& tee";
3922# endif
3923 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3924 }
3925#endif
3926 if (do_srr)
3927 {
3928 p_srr = (char_u *)">&";
3929 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3930 }
3931 }
3932 else
3933# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3934 if ( fnamecmp(p, "sh") == 0
3935 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003936 || fnamecmp(p, "mksh") == 0
3937 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003939 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003941 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942# ifdef WIN3264
3943 || fnamecmp(p, "cmd") == 0
3944 || fnamecmp(p, "sh.exe") == 0
3945 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003946 || fnamecmp(p, "mksh.exe") == 0
3947 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003949 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 || fnamecmp(p, "bash.exe") == 0
3951 || fnamecmp(p, "cmd.exe") == 0
3952# endif
3953 )
3954# endif
3955 {
3956#if defined(FEAT_QUICKFIX)
3957 if (do_sp)
3958 {
3959# ifdef WIN3264
3960 p_sp = (char_u *)">%s 2>&1";
3961# else
3962 p_sp = (char_u *)"2>&1| tee";
3963# endif
3964 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3965 }
3966#endif
3967 if (do_srr)
3968 {
3969 p_srr = (char_u *)">%s 2>&1";
3970 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3971 }
3972 }
3973 vim_free(p);
3974 }
3975#endif
3976
3977#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3978 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003979 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3980 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 * This is done after other initializations, where 'shell' might have been
3982 * set, but only if they have not been set before. Default for p_shcf is
3983 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3984 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3985 * command.com. And for Win32 we need to set p_sxq instead.
3986 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003987 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988 {
3989 int idx3;
3990
3991 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003992 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993 {
3994 p_shcf = (char_u *)"-c";
3995 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3996 }
3997
3998# ifndef DJGPP
3999# ifdef WIN3264
4000 /* Somehow Win32 requires the quotes around the redirection too */
4001 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004002 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 {
4004 p_sxq = (char_u *)"\"";
4005 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4006 }
4007# else
4008 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004009 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004010 {
4011 p_shq = (char_u *)"\"";
4012 options[idx3].def_val[VI_DEFAULT] = p_shq;
4013 }
4014# endif
4015# endif
4016 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004017 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4018 {
4019 int idx3;
4020
4021 /*
4022 * cmd.exe on Windows will strip the first and last double quote given
4023 * on the command line, e.g. most of the time things like:
4024 * cmd /c "my path/to/echo" "my args to echo"
4025 * become:
4026 * my path/to/echo" "my args to echo
4027 * when executed.
4028 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004029 * To avoid this, set shellxquote to surround the command in
4030 * parenthesis. This appears to make most commands work, without
4031 * breaking commands that worked previously, such as
4032 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004033 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004034 idx3 = findoption((char_u *)"sxq");
4035 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4036 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004037 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004038 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4039 }
4040
Bram Moolenaara64ba222012-02-12 23:23:31 +01004041 idx3 = findoption((char_u *)"shcf");
4042 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4043 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004044 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004045 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4046 }
4047 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048#endif
4049
4050#ifdef FEAT_TITLE
4051 set_title_defaults();
4052#endif
4053}
4054
4055#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4056/*
4057 * When 'helplang' is still at its default value, set it to "lang".
4058 * Only the first two characters of "lang" are used.
4059 */
4060 void
4061set_helplang_default(lang)
4062 char_u *lang;
4063{
4064 int idx;
4065
4066 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4067 return;
4068 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004069 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 {
4071 if (options[idx].flags & P_ALLOCED)
4072 free_string_option(p_hlg);
4073 p_hlg = vim_strsave(lang);
4074 if (p_hlg == NULL)
4075 p_hlg = empty_option;
4076 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004077 {
4078 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4079 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4080 {
4081 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4082 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4083 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 options[idx].flags |= P_ALLOCED;
4087 }
4088}
4089#endif
4090
4091#ifdef FEAT_GUI
4092static char_u *gui_bg_default __ARGS((void));
4093
4094 static char_u *
4095gui_bg_default()
4096{
4097 if (gui_get_lightness(gui.back_pixel) < 127)
4098 return (char_u *)"dark";
4099 return (char_u *)"light";
4100}
4101
4102/*
4103 * Option initializations that can only be done after opening the GUI window.
4104 */
4105 void
4106init_gui_options()
4107{
4108 /* Set the 'background' option according to the lightness of the
4109 * background color, unless the user has set it already. */
4110 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4111 {
4112 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4113 highlight_changed();
4114 }
4115}
4116#endif
4117
4118#ifdef FEAT_TITLE
4119/*
4120 * 'title' and 'icon' only default to true if they have not been set or reset
4121 * in .vimrc and we can read the old value.
4122 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4123 * they can be reset. This reduces startup time when using X on a remote
4124 * machine.
4125 */
4126 void
4127set_title_defaults()
4128{
4129 int idx1;
4130 long val;
4131
4132 /*
4133 * If GUI is (going to be) used, we can always set the window title and
4134 * icon name. Saves a bit of time, because the X11 display server does
4135 * not need to be contacted.
4136 */
4137 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004138 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 {
4140#ifdef FEAT_GUI
4141 if (gui.starting || gui.in_use)
4142 val = TRUE;
4143 else
4144#endif
4145 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004146 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 p_title = val;
4148 }
4149 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004150 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 {
4152#ifdef FEAT_GUI
4153 if (gui.starting || gui.in_use)
4154 val = TRUE;
4155 else
4156#endif
4157 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004158 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004159 p_icon = val;
4160 }
4161}
4162#endif
4163
4164/*
4165 * Parse 'arg' for option settings.
4166 *
4167 * 'arg' may be IObuff, but only when no errors can be present and option
4168 * does not need to be expanded with option_expand().
4169 * "opt_flags":
4170 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004171 * OPT_GLOBAL for ":setglobal"
4172 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004173 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004174 * OPT_WINONLY to only set window-local options
4175 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176 *
4177 * returns FAIL if an error is detected, OK otherwise
4178 */
4179 int
4180do_set(arg, opt_flags)
4181 char_u *arg; /* option string (may be written to!) */
4182 int opt_flags;
4183{
4184 int opt_idx;
4185 char_u *errmsg;
4186 char_u errbuf[80];
4187 char_u *startarg;
4188 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4189 int nextchar; /* next non-white char after option name */
4190 int afterchar; /* character just after option name */
4191 int len;
4192 int i;
4193 long value;
4194 int key;
4195 long_u flags; /* flags for current option */
4196 char_u *varp = NULL; /* pointer to variable for current option */
4197 int did_show = FALSE; /* already showed one value */
4198 int adding; /* "opt+=arg" */
4199 int prepending; /* "opt^=arg" */
4200 int removing; /* "opt-=arg" */
4201 int cp_val = 0;
4202 char_u key_name[2];
4203
4204 if (*arg == NUL)
4205 {
4206 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004207 did_show = TRUE;
4208 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004209 }
4210
4211 while (*arg != NUL) /* loop to process all options */
4212 {
4213 errmsg = NULL;
4214 startarg = arg; /* remember for error message */
4215
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004216 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4217 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004218 {
4219 /*
4220 * ":set all" show all options.
4221 * ":set all&" set all options to their default value.
4222 */
4223 arg += 3;
4224 if (*arg == '&')
4225 {
4226 ++arg;
4227 /* Only for :set command set global value of local options. */
4228 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004229 didset_options();
4230 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004231 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232 }
4233 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004234 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004236 did_show = TRUE;
4237 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004239 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240 {
4241 showoptions(2, opt_flags);
4242 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004243 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004244 arg += 7;
4245 }
4246 else
4247 {
4248 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004249 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004250 {
4251 prefix = 0;
4252 arg += 2;
4253 }
4254 else if (STRNCMP(arg, "inv", 3) == 0)
4255 {
4256 prefix = 2;
4257 arg += 3;
4258 }
4259
4260 /* find end of name */
4261 key = 0;
4262 if (*arg == '<')
4263 {
4264 nextchar = 0;
4265 opt_idx = -1;
4266 /* look out for <t_>;> */
4267 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4268 len = 5;
4269 else
4270 {
4271 len = 1;
4272 while (arg[len] != NUL && arg[len] != '>')
4273 ++len;
4274 }
4275 if (arg[len] != '>')
4276 {
4277 errmsg = e_invarg;
4278 goto skip;
4279 }
4280 arg[len] = NUL; /* put NUL after name */
4281 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4282 opt_idx = findoption(arg + 1);
4283 arg[len++] = '>'; /* restore '>' */
4284 if (opt_idx == -1)
4285 key = find_key_option(arg + 1);
4286 }
4287 else
4288 {
4289 len = 0;
4290 /*
4291 * The two characters after "t_" may not be alphanumeric.
4292 */
4293 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4294 len = 4;
4295 else
4296 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4297 ++len;
4298 nextchar = arg[len];
4299 arg[len] = NUL; /* put NUL after name */
4300 opt_idx = findoption(arg);
4301 arg[len] = nextchar; /* restore nextchar */
4302 if (opt_idx == -1)
4303 key = find_key_option(arg);
4304 }
4305
4306 /* remember character after option name */
4307 afterchar = arg[len];
4308
4309 /* skip white space, allow ":set ai ?" */
4310 while (vim_iswhite(arg[len]))
4311 ++len;
4312
4313 adding = FALSE;
4314 prepending = FALSE;
4315 removing = FALSE;
4316 if (arg[len] != NUL && arg[len + 1] == '=')
4317 {
4318 if (arg[len] == '+')
4319 {
4320 adding = TRUE; /* "+=" */
4321 ++len;
4322 }
4323 else if (arg[len] == '^')
4324 {
4325 prepending = TRUE; /* "^=" */
4326 ++len;
4327 }
4328 else if (arg[len] == '-')
4329 {
4330 removing = TRUE; /* "-=" */
4331 ++len;
4332 }
4333 }
4334 nextchar = arg[len];
4335
4336 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4337 {
4338 errmsg = (char_u *)N_("E518: Unknown option");
4339 goto skip;
4340 }
4341
4342 if (opt_idx >= 0)
4343 {
4344 if (options[opt_idx].var == NULL) /* hidden option: skip */
4345 {
4346 /* Only give an error message when requesting the value of
4347 * a hidden option, ignore setting it. */
4348 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4349 && (!(options[opt_idx].flags & P_BOOL)
4350 || nextchar == '?'))
4351 errmsg = (char_u *)N_("E519: Option not supported");
4352 goto skip;
4353 }
4354
4355 flags = options[opt_idx].flags;
4356 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4357 }
4358 else
4359 {
4360 flags = P_STRING;
4361 if (key < 0)
4362 {
4363 key_name[0] = KEY2TERMCAP0(key);
4364 key_name[1] = KEY2TERMCAP1(key);
4365 }
4366 else
4367 {
4368 key_name[0] = KS_KEY;
4369 key_name[1] = (key & 0xff);
4370 }
4371 }
4372
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004373 /* Skip all options that are not window-local (used when showing
4374 * an already loaded buffer in a window). */
4375 if ((opt_flags & OPT_WINONLY)
4376 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4377 goto skip;
4378
Bram Moolenaara3227e22006-03-08 21:32:40 +00004379 /* Skip all options that are window-local (used for :vimgrep). */
4380 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4381 && options[opt_idx].var == VAR_WIN)
4382 goto skip;
4383
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004384 /* Disallow changing some options from modelines. */
4385 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004386 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004387 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004388 {
4389 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4390 goto skip;
4391 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004392#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004393 /* In diff mode some options are overruled. This avoids that
4394 * 'foldmethod' becomes "marker" instead of "diff" and that
4395 * "wrap" gets set. */
4396 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004397 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004398 && (options[opt_idx].indir == PV_FDM
4399 || options[opt_idx].indir == PV_WRAP))
4400 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004401#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004402 }
4403
4404#ifdef HAVE_SANDBOX
4405 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004406 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004407 {
4408 errmsg = (char_u *)_(e_sandbox);
4409 goto skip;
4410 }
4411#endif
4412
4413 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4414 {
4415 arg += len;
4416 cp_val = p_cp;
4417 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4418 {
4419 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4420 {
4421 cp_val = FALSE;
4422 arg += 3;
4423 }
4424 else /* "opt&vi": set to Vi default */
4425 {
4426 cp_val = TRUE;
4427 arg += 2;
4428 }
4429 }
4430 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4431 && arg[1] != NUL && !vim_iswhite(arg[1]))
4432 {
4433 errmsg = e_trailing;
4434 goto skip;
4435 }
4436 }
4437
4438 /*
4439 * allow '=' and ':' as MSDOS command.com allows only one
4440 * '=' character per "set" command line. grrr. (jw)
4441 */
4442 if (nextchar == '?'
4443 || (prefix == 1
4444 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4445 && !(flags & P_BOOL)))
4446 {
4447 /*
4448 * print value
4449 */
4450 if (did_show)
4451 msg_putchar('\n'); /* cursor below last one */
4452 else
4453 {
4454 gotocmdline(TRUE); /* cursor at status line */
4455 did_show = TRUE; /* remember that we did a line */
4456 }
4457 if (opt_idx >= 0)
4458 {
4459 showoneopt(&options[opt_idx], opt_flags);
4460#ifdef FEAT_EVAL
4461 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004462 {
4463 /* Mention where the option was last set. */
4464 if (varp == options[opt_idx].var)
4465 last_set_msg(options[opt_idx].scriptID);
4466 else if ((int)options[opt_idx].indir & PV_WIN)
4467 last_set_msg(curwin->w_p_scriptID[
4468 (int)options[opt_idx].indir & PV_MASK]);
4469 else if ((int)options[opt_idx].indir & PV_BUF)
4470 last_set_msg(curbuf->b_p_scriptID[
4471 (int)options[opt_idx].indir & PV_MASK]);
4472 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004473#endif
4474 }
4475 else
4476 {
4477 char_u *p;
4478
4479 p = find_termcode(key_name);
4480 if (p == NULL)
4481 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004482 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004483 goto skip;
4484 }
4485 else
4486 (void)show_one_termcode(key_name, p, TRUE);
4487 }
4488 if (nextchar != '?'
4489 && nextchar != NUL && !vim_iswhite(afterchar))
4490 errmsg = e_trailing;
4491 }
4492 else
4493 {
4494 if (flags & P_BOOL) /* boolean */
4495 {
4496 if (nextchar == '=' || nextchar == ':')
4497 {
4498 errmsg = e_invarg;
4499 goto skip;
4500 }
4501
4502 /*
4503 * ":set opt!": invert
4504 * ":set opt&": reset to default value
4505 * ":set opt<": reset to global value
4506 */
4507 if (nextchar == '!')
4508 value = *(int *)(varp) ^ 1;
4509 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004510 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004511 ((flags & P_VI_DEF) || cp_val)
4512 ? VI_DEFAULT : VIM_DEFAULT];
4513 else if (nextchar == '<')
4514 {
4515 /* For 'autoread' -1 means to use global value. */
4516 if ((int *)varp == &curbuf->b_p_ar
4517 && opt_flags == OPT_LOCAL)
4518 value = -1;
4519 else
4520 value = *(int *)get_varp_scope(&(options[opt_idx]),
4521 OPT_GLOBAL);
4522 }
4523 else
4524 {
4525 /*
4526 * ":set invopt": invert
4527 * ":set opt" or ":set noopt": set or reset
4528 */
4529 if (nextchar != NUL && !vim_iswhite(afterchar))
4530 {
4531 errmsg = e_trailing;
4532 goto skip;
4533 }
4534 if (prefix == 2) /* inv */
4535 value = *(int *)(varp) ^ 1;
4536 else
4537 value = prefix;
4538 }
4539
4540 errmsg = set_bool_option(opt_idx, varp, (int)value,
4541 opt_flags);
4542 }
4543 else /* numeric or string */
4544 {
4545 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4546 || prefix != 1)
4547 {
4548 errmsg = e_invarg;
4549 goto skip;
4550 }
4551
4552 if (flags & P_NUM) /* numeric */
4553 {
4554 /*
4555 * Different ways to set a number option:
4556 * & set to default value
4557 * < set to global value
4558 * <xx> accept special key codes for 'wildchar'
4559 * c accept any non-digit for 'wildchar'
4560 * [-]0-9 set number
4561 * other error
4562 */
4563 ++arg;
4564 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004565 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004566 ((flags & P_VI_DEF) || cp_val)
4567 ? VI_DEFAULT : VIM_DEFAULT];
4568 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004569 {
4570 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4571 * use the global value. */
4572 if ((long *)varp == &curbuf->b_p_ul
4573 && opt_flags == OPT_LOCAL)
4574 value = NO_LOCAL_UNDOLEVEL;
4575 else
4576 value = *(long *)get_varp_scope(
4577 &(options[opt_idx]), OPT_GLOBAL);
4578 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004579 else if (((long *)varp == &p_wc
4580 || (long *)varp == &p_wcm)
4581 && (*arg == '<'
4582 || *arg == '^'
4583 || ((!arg[1] || vim_iswhite(arg[1]))
4584 && !VIM_ISDIGIT(*arg))))
4585 {
4586 value = string_to_key(arg);
4587 if (value == 0 && (long *)varp != &p_wcm)
4588 {
4589 errmsg = e_invarg;
4590 goto skip;
4591 }
4592 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004593 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4594 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004595 /* Allow negative (for 'undolevels'), octal and
4596 * hex numbers. */
Bram Moolenaar5d1bc782015-07-17 13:03:48 +02004597 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004598 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4599 {
4600 errmsg = e_invarg;
4601 goto skip;
4602 }
4603 }
4604 else
4605 {
4606 errmsg = (char_u *)N_("E521: Number required after =");
4607 goto skip;
4608 }
4609
4610 if (adding)
4611 value = *(long *)varp + value;
4612 if (prepending)
4613 value = *(long *)varp * value;
4614 if (removing)
4615 value = *(long *)varp - value;
4616 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004617 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004618 }
4619 else if (opt_idx >= 0) /* string */
4620 {
4621 char_u *save_arg = NULL;
4622 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004623 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004624 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004625 char_u *origval = NULL;
4626#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4627 char_u *saved_origval = NULL;
4628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629 unsigned newlen;
4630 int comma;
4631 int bs;
4632 int new_value_alloced; /* new string option
4633 was allocated */
4634
4635 /* When using ":set opt=val" for a global option
4636 * with a local value the local value will be
4637 * reset, use the global value here. */
4638 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004639 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004640 varp = options[opt_idx].var;
4641
4642 /* The old value is kept until we are sure that the
4643 * new value is valid. */
4644 oldval = *(char_u **)varp;
4645 if (nextchar == '&') /* set to default val */
4646 {
4647 newval = options[opt_idx].def_val[
4648 ((flags & P_VI_DEF) || cp_val)
4649 ? VI_DEFAULT : VIM_DEFAULT];
4650 if ((char_u **)varp == &p_bg)
4651 {
4652 /* guess the value of 'background' */
4653#ifdef FEAT_GUI
4654 if (gui.in_use)
4655 newval = gui_bg_default();
4656 else
4657#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004658 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004659 }
4660
4661 /* expand environment variables and ~ (since the
4662 * default value was already expanded, only
4663 * required when an environment variable was set
4664 * later */
4665 if (newval == NULL)
4666 newval = empty_option;
4667 else
4668 {
4669 s = option_expand(opt_idx, newval);
4670 if (s == NULL)
4671 s = newval;
4672 newval = vim_strsave(s);
4673 }
4674 new_value_alloced = TRUE;
4675 }
4676 else if (nextchar == '<') /* set to global val */
4677 {
4678 newval = vim_strsave(*(char_u **)get_varp_scope(
4679 &(options[opt_idx]), OPT_GLOBAL));
4680 new_value_alloced = TRUE;
4681 }
4682 else
4683 {
4684 ++arg; /* jump to after the '=' or ':' */
4685
4686 /*
4687 * Set 'keywordprg' to ":help" if an empty
4688 * value was passed to :set by the user.
4689 * Misuse errbuf[] for the resulting string.
4690 */
4691 if (varp == (char_u *)&p_kp
4692 && (*arg == NUL || *arg == ' '))
4693 {
4694 STRCPY(errbuf, ":help");
4695 save_arg = arg;
4696 arg = errbuf;
4697 }
4698 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004699 * Convert 'backspace' number to string, for
4700 * adding, prepending and removing string.
4701 */
4702 else if (varp == (char_u *)&p_bs
4703 && VIM_ISDIGIT(**(char_u **)varp))
4704 {
4705 i = getdigits((char_u **)varp);
4706 switch (i)
4707 {
4708 case 0:
4709 *(char_u **)varp = empty_option;
4710 break;
4711 case 1:
4712 *(char_u **)varp = vim_strsave(
4713 (char_u *)"indent,eol");
4714 break;
4715 case 2:
4716 *(char_u **)varp = vim_strsave(
4717 (char_u *)"indent,eol,start");
4718 break;
4719 }
4720 vim_free(oldval);
4721 oldval = *(char_u **)varp;
4722 }
4723 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004724 * Convert 'whichwrap' number to string, for
4725 * backwards compatibility with Vim 3.0.
4726 * Misuse errbuf[] for the resulting string.
4727 */
4728 else if (varp == (char_u *)&p_ww
4729 && VIM_ISDIGIT(*arg))
4730 {
4731 *errbuf = NUL;
4732 i = getdigits(&arg);
4733 if (i & 1)
4734 STRCAT(errbuf, "b,");
4735 if (i & 2)
4736 STRCAT(errbuf, "s,");
4737 if (i & 4)
4738 STRCAT(errbuf, "h,l,");
4739 if (i & 8)
4740 STRCAT(errbuf, "<,>,");
4741 if (i & 16)
4742 STRCAT(errbuf, "[,],");
4743 if (*errbuf != NUL) /* remove trailing , */
4744 errbuf[STRLEN(errbuf) - 1] = NUL;
4745 save_arg = arg;
4746 arg = errbuf;
4747 }
4748 /*
4749 * Remove '>' before 'dir' and 'bdir', for
4750 * backwards compatibility with version 3.0
4751 */
4752 else if ( *arg == '>'
4753 && (varp == (char_u *)&p_dir
4754 || varp == (char_u *)&p_bdir))
4755 {
4756 ++arg;
4757 }
4758
4759 /* When setting the local value of a global
4760 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004761 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004762 && (opt_flags & OPT_LOCAL))
4763 origval = *(char_u **)get_varp(
4764 &options[opt_idx]);
4765 else
4766 origval = oldval;
4767
4768 /*
4769 * Copy the new string into allocated memory.
4770 * Can't use set_string_option_direct(), because
4771 * we need to remove the backslashes.
4772 */
4773 /* get a bit too much */
4774 newlen = (unsigned)STRLEN(arg) + 1;
4775 if (adding || prepending || removing)
4776 newlen += (unsigned)STRLEN(origval) + 1;
4777 newval = alloc(newlen);
4778 if (newval == NULL) /* out of mem, don't change */
4779 break;
4780 s = newval;
4781
4782 /*
4783 * Copy the string, skip over escaped chars.
4784 * For MS-DOS and WIN32 backslashes before normal
4785 * file name characters are not removed, and keep
4786 * backslash at start, for "\\machine\path", but
4787 * do remove it for "\\\\machine\\path".
4788 * The reverse is found in ExpandOldSetting().
4789 */
4790 while (*arg && !vim_iswhite(*arg))
4791 {
4792 if (*arg == '\\' && arg[1] != NUL
4793#ifdef BACKSLASH_IN_FILENAME
4794 && !((flags & P_EXPAND)
4795 && vim_isfilec(arg[1])
4796 && (arg[1] != '\\'
4797 || (s == newval
4798 && arg[2] != '\\')))
4799#endif
4800 )
4801 ++arg; /* remove backslash */
4802#ifdef FEAT_MBYTE
4803 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004804 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004805 {
4806 /* copy multibyte char */
4807 mch_memmove(s, arg, (size_t)i);
4808 arg += i;
4809 s += i;
4810 }
4811 else
4812#endif
4813 *s++ = *arg++;
4814 }
4815 *s = NUL;
4816
4817 /*
4818 * Expand environment variables and ~.
4819 * Don't do it when adding without inserting a
4820 * comma.
4821 */
4822 if (!(adding || prepending || removing)
4823 || (flags & P_COMMA))
4824 {
4825 s = option_expand(opt_idx, newval);
4826 if (s != NULL)
4827 {
4828 vim_free(newval);
4829 newlen = (unsigned)STRLEN(s) + 1;
4830 if (adding || prepending || removing)
4831 newlen += (unsigned)STRLEN(origval) + 1;
4832 newval = alloc(newlen);
4833 if (newval == NULL)
4834 break;
4835 STRCPY(newval, s);
4836 }
4837 }
4838
4839 /* locate newval[] in origval[] when removing it
4840 * and when adding to avoid duplicates */
4841 i = 0; /* init for GCC */
4842 if (removing || (flags & P_NODUP))
4843 {
4844 i = (int)STRLEN(newval);
4845 bs = 0;
4846 for (s = origval; *s; ++s)
4847 {
4848 if ((!(flags & P_COMMA)
4849 || s == origval
4850 || (s[-1] == ',' && !(bs & 1)))
4851 && STRNCMP(s, newval, i) == 0
4852 && (!(flags & P_COMMA)
4853 || s[i] == ','
4854 || s[i] == NUL))
4855 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004856 /* Count backslashes. Only a comma with an
4857 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004858 * recognized as a separator */
4859 if (s > origval && s[-1] == '\\')
4860 ++bs;
4861 else
4862 bs = 0;
4863 }
4864
4865 /* do not add if already there */
4866 if ((adding || prepending) && *s)
4867 {
4868 prepending = FALSE;
4869 adding = FALSE;
4870 STRCPY(newval, origval);
4871 }
4872 }
4873
4874 /* concatenate the two strings; add a ',' if
4875 * needed */
4876 if (adding || prepending)
4877 {
4878 comma = ((flags & P_COMMA) && *origval != NUL
4879 && *newval != NUL);
4880 if (adding)
4881 {
4882 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004883 /* strip a trailing comma, would get 2 */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02004884 if (comma && (flags & P_ONECOMMA) && i > 1
4885 && origval[i - 1] == ','
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004886 && origval[i - 2] != '\\')
4887 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004888 mch_memmove(newval + i + comma, newval,
4889 STRLEN(newval) + 1);
4890 mch_memmove(newval, origval, (size_t)i);
4891 }
4892 else
4893 {
4894 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004895 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004896 }
4897 if (comma)
4898 newval[i] = ',';
4899 }
4900
4901 /* Remove newval[] from origval[]. (Note: "i" has
4902 * been set above and is used here). */
4903 if (removing)
4904 {
4905 STRCPY(newval, origval);
4906 if (*s)
4907 {
4908 /* may need to remove a comma */
4909 if (flags & P_COMMA)
4910 {
4911 if (s == origval)
4912 {
4913 /* include comma after string */
4914 if (s[i] == ',')
4915 ++i;
4916 }
4917 else
4918 {
4919 /* include comma before string */
4920 --s;
4921 ++i;
4922 }
4923 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004924 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004925 }
4926 }
4927
4928 if (flags & P_FLAGLIST)
4929 {
4930 /* Remove flags that appear twice. */
4931 for (s = newval; *s; ++s)
4932 if ((!(flags & P_COMMA) || *s != ',')
4933 && vim_strchr(s + 1, *s) != NULL)
4934 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004935 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004936 --s;
4937 }
4938 }
4939
4940 if (save_arg != NULL) /* number for 'whichwrap' */
4941 arg = save_arg;
4942 new_value_alloced = TRUE;
4943 }
4944
4945 /* Set the new value. */
4946 *(char_u **)(varp) = newval;
4947
Bram Moolenaar53744302015-07-17 17:38:22 +02004948#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004949 if (!starting
4950# ifdef FEAT_CRYPT
4951 && options[opt_idx].indir != PV_KEY
4952# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004953 && origval != NULL)
4954 /* origval may be freed by
4955 * did_set_string_option(), make a copy. */
4956 saved_origval = vim_strsave(origval);
4957#endif
4958
Bram Moolenaar071d4272004-06-13 20:20:40 +00004959 /* Handle side effects, and set the global value for
4960 * ":set" on local options. */
4961 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4962 new_value_alloced, oldval, errbuf, opt_flags);
4963
4964 /* If error detected, print the error message. */
4965 if (errmsg != NULL)
4966 goto skip;
Bram Moolenaar53744302015-07-17 17:38:22 +02004967#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4968 if (saved_origval != NULL)
4969 {
4970 char_u buf_type[7];
4971
4972 sprintf((char *)buf_type, "%s",
4973 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004974 set_vim_var_string(VV_OPTION_NEW,
4975 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004976 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4977 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4978 apply_autocmds(EVENT_OPTIONSET,
4979 (char_u *)options[opt_idx].fullname,
4980 NULL, FALSE, NULL);
4981 reset_v_option_vars();
4982 vim_free(saved_origval);
4983 }
4984#endif
4985
Bram Moolenaar071d4272004-06-13 20:20:40 +00004986 }
4987 else /* key code option */
4988 {
4989 char_u *p;
4990
4991 if (nextchar == '&')
4992 {
4993 if (add_termcap_entry(key_name, TRUE) == FAIL)
4994 errmsg = (char_u *)N_("E522: Not found in termcap");
4995 }
4996 else
4997 {
4998 ++arg; /* jump to after the '=' or ':' */
4999 for (p = arg; *p && !vim_iswhite(*p); ++p)
5000 if (*p == '\\' && p[1] != NUL)
5001 ++p;
5002 nextchar = *p;
5003 *p = NUL;
5004 add_termcode(key_name, arg, FALSE);
5005 *p = nextchar;
5006 }
5007 if (full_screen)
5008 ttest(FALSE);
5009 redraw_all_later(CLEAR);
5010 }
5011 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005012
Bram Moolenaar071d4272004-06-13 20:20:40 +00005013 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005014 did_set_option(opt_idx, opt_flags,
5015 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016 }
5017
5018skip:
5019 /*
5020 * Advance to next argument.
5021 * - skip until a blank found, taking care of backslashes
5022 * - skip blanks
5023 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5024 */
5025 for (i = 0; i < 2 ; ++i)
5026 {
5027 while (*arg != NUL && !vim_iswhite(*arg))
5028 if (*arg++ == '\\' && *arg != NUL)
5029 ++arg;
5030 arg = skipwhite(arg);
5031 if (*arg != '=')
5032 break;
5033 }
5034 }
5035
5036 if (errmsg != NULL)
5037 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005038 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005039 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005040 if (i + (arg - startarg) < IOSIZE)
5041 {
5042 /* append the argument with the error */
5043 STRCAT(IObuff, ": ");
5044 mch_memmove(IObuff + i, startarg, (arg - startarg));
5045 IObuff[i + (arg - startarg)] = NUL;
5046 }
5047 /* make sure all characters are printable */
5048 trans_characters(IObuff, IOSIZE);
5049
5050 ++no_wait_return; /* wait_return done later */
5051 emsg(IObuff); /* show error highlighted */
5052 --no_wait_return;
5053
5054 return FAIL;
5055 }
5056
5057 arg = skipwhite(arg);
5058 }
5059
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005060theend:
5061 if (silent_mode && did_show)
5062 {
5063 /* After displaying option values in silent mode. */
5064 silent_mode = FALSE;
5065 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5066 msg_putchar('\n');
5067 cursor_on(); /* msg_start() switches it off */
5068 out_flush();
5069 silent_mode = TRUE;
5070 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5071 }
5072
Bram Moolenaar071d4272004-06-13 20:20:40 +00005073 return OK;
5074}
5075
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005076/*
5077 * Call this when an option has been given a new value through a user command.
5078 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5079 */
5080 static void
5081did_set_option(opt_idx, opt_flags, new_value)
5082 int opt_idx;
5083 int opt_flags; /* possibly with OPT_MODELINE */
5084 int new_value; /* value was replaced completely */
5085{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005086 long_u *p;
5087
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005088 options[opt_idx].flags |= P_WAS_SET;
5089
5090 /* When an option is set in the sandbox, from a modeline or in secure mode
5091 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005092 * flag. */
5093 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005094 if (secure
5095#ifdef HAVE_SANDBOX
5096 || sandbox != 0
5097#endif
5098 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005099 *p = *p | P_INSECURE;
5100 else if (new_value)
5101 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005102}
5103
Bram Moolenaar071d4272004-06-13 20:20:40 +00005104 static char_u *
5105illegal_char(errbuf, c)
5106 char_u *errbuf;
5107 int c;
5108{
5109 if (errbuf == NULL)
5110 return (char_u *)"";
5111 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005112 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005113 return errbuf;
5114}
5115
5116/*
5117 * Convert a key name or string into a key value.
5118 * Used for 'wildchar' and 'cedit' options.
5119 */
5120 static int
5121string_to_key(arg)
5122 char_u *arg;
5123{
5124 if (*arg == '<')
5125 return find_key_option(arg + 1);
5126 if (*arg == '^')
5127 return Ctrl_chr(arg[1]);
5128 return *arg;
5129}
5130
5131#ifdef FEAT_CMDWIN
5132/*
5133 * Check value of 'cedit' and set cedit_key.
5134 * Returns NULL if value is OK, error message otherwise.
5135 */
5136 static char_u *
5137check_cedit()
5138{
5139 int n;
5140
5141 if (*p_cedit == NUL)
5142 cedit_key = -1;
5143 else
5144 {
5145 n = string_to_key(p_cedit);
5146 if (vim_isprintc(n))
5147 return e_invarg;
5148 cedit_key = n;
5149 }
5150 return NULL;
5151}
5152#endif
5153
5154#ifdef FEAT_TITLE
5155/*
5156 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5157 * maketitle() to create and display it.
5158 * When switching the title or icon off, call mch_restore_title() to get
5159 * the old value back.
5160 */
5161 static void
5162did_set_title(icon)
5163 int icon; /* Did set icon instead of title */
5164{
5165 if (starting != NO_SCREEN
5166#ifdef FEAT_GUI
5167 && !gui.starting
5168#endif
5169 )
5170 {
5171 maketitle();
5172 if (icon)
5173 {
5174 if (!p_icon)
5175 mch_restore_title(2);
5176 }
5177 else
5178 {
5179 if (!p_title)
5180 mch_restore_title(1);
5181 }
5182 }
5183}
5184#endif
5185
5186/*
5187 * set_options_bin - called when 'bin' changes value.
5188 */
5189 void
5190set_options_bin(oldval, newval, opt_flags)
5191 int oldval;
5192 int newval;
5193 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5194{
5195 /*
5196 * The option values that are changed when 'bin' changes are
5197 * copied when 'bin is set and restored when 'bin' is reset.
5198 */
5199 if (newval)
5200 {
5201 if (!oldval) /* switched on */
5202 {
5203 if (!(opt_flags & OPT_GLOBAL))
5204 {
5205 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5206 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5207 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5208 curbuf->b_p_et_nobin = curbuf->b_p_et;
5209 }
5210 if (!(opt_flags & OPT_LOCAL))
5211 {
5212 p_tw_nobin = p_tw;
5213 p_wm_nobin = p_wm;
5214 p_ml_nobin = p_ml;
5215 p_et_nobin = p_et;
5216 }
5217 }
5218
5219 if (!(opt_flags & OPT_GLOBAL))
5220 {
5221 curbuf->b_p_tw = 0; /* no automatic line wrap */
5222 curbuf->b_p_wm = 0; /* no automatic line wrap */
5223 curbuf->b_p_ml = 0; /* no modelines */
5224 curbuf->b_p_et = 0; /* no expandtab */
5225 }
5226 if (!(opt_flags & OPT_LOCAL))
5227 {
5228 p_tw = 0;
5229 p_wm = 0;
5230 p_ml = FALSE;
5231 p_et = FALSE;
5232 p_bin = TRUE; /* needed when called for the "-b" argument */
5233 }
5234 }
5235 else if (oldval) /* switched off */
5236 {
5237 if (!(opt_flags & OPT_GLOBAL))
5238 {
5239 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5240 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5241 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5242 curbuf->b_p_et = curbuf->b_p_et_nobin;
5243 }
5244 if (!(opt_flags & OPT_LOCAL))
5245 {
5246 p_tw = p_tw_nobin;
5247 p_wm = p_wm_nobin;
5248 p_ml = p_ml_nobin;
5249 p_et = p_et_nobin;
5250 }
5251 }
5252}
5253
5254#ifdef FEAT_VIMINFO
5255/*
5256 * Find the parameter represented by the given character (eg ', :, ", or /),
5257 * and return its associated value in the 'viminfo' string.
5258 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005259 * If the parameter is not specified in the string or there is no following
5260 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005261 */
5262 int
5263get_viminfo_parameter(type)
5264 int type;
5265{
5266 char_u *p;
5267
5268 p = find_viminfo_parameter(type);
5269 if (p != NULL && VIM_ISDIGIT(*p))
5270 return atoi((char *)p);
5271 return -1;
5272}
5273
5274/*
5275 * Find the parameter represented by the given character (eg ''', ':', '"', or
5276 * '/') in the 'viminfo' option and return a pointer to the string after it.
5277 * Return NULL if the parameter is not specified in the string.
5278 */
5279 char_u *
5280find_viminfo_parameter(type)
5281 int type;
5282{
5283 char_u *p;
5284
5285 for (p = p_viminfo; *p; ++p)
5286 {
5287 if (*p == type)
5288 return p + 1;
5289 if (*p == 'n') /* 'n' is always the last one */
5290 break;
5291 p = vim_strchr(p, ','); /* skip until next ',' */
5292 if (p == NULL) /* hit the end without finding parameter */
5293 break;
5294 }
5295 return NULL;
5296}
5297#endif
5298
5299/*
5300 * Expand environment variables for some string options.
5301 * These string options cannot be indirect!
5302 * If "val" is NULL expand the current value of the option.
5303 * Return pointer to NameBuff, or NULL when not expanded.
5304 */
5305 static char_u *
5306option_expand(opt_idx, val)
5307 int opt_idx;
5308 char_u *val;
5309{
5310 /* if option doesn't need expansion nothing to do */
5311 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5312 return NULL;
5313
5314 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5315 * expand_env() would truncate the string. */
5316 if (val != NULL && STRLEN(val) > MAXPATHL)
5317 return NULL;
5318
5319 if (val == NULL)
5320 val = *(char_u **)options[opt_idx].var;
5321
5322 /*
5323 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5324 * Escape spaces when expanding 'tags', they are used to separate file
5325 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005326 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327 */
5328 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005329 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005330#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005331 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5332#endif
5333 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5335 return NULL;
5336
5337 return NameBuff;
5338}
5339
5340/*
5341 * After setting various option values: recompute variables that depend on
5342 * option values.
5343 */
5344 static void
5345didset_options()
5346{
5347 /* initialize the table for 'iskeyword' et.al. */
5348 (void)init_chartab();
5349
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005350#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005354 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355#ifdef FEAT_SESSION
5356 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5357 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5358#endif
5359#ifdef FEAT_FOLDING
5360 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5361#endif
5362 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5363#ifdef FEAT_VIRTUALEDIT
5364 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5365#endif
5366#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5367 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5368#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005369#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005370 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005371 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005372 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005373 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5376 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5377#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005378#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5380#endif
5381#ifdef FEAT_CMDWIN
5382 /* set cedit_key */
5383 (void)check_cedit();
5384#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005385#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005386 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005387#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005388#ifdef FEAT_LINEBREAK
5389 /* initialize the table for 'breakat'. */
5390 fill_breakat_flags();
5391#endif
5392
5393}
5394
5395/*
5396 * More side effects of setting options.
5397 */
5398 static void
5399didset_options2()
5400{
5401 /* Initialize the highlight_attr[] table. */
5402 (void)highlight_changed();
5403
5404 /* Parse default for 'wildmode' */
5405 check_opt_wim();
5406
5407 (void)set_chars_option(&p_lcs);
5408#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5409 /* Parse default for 'fillchars'. */
5410 (void)set_chars_option(&p_fcs);
5411#endif
5412
5413#ifdef FEAT_CLIPBOARD
5414 /* Parse default for 'clipboard' */
5415 (void)check_clipboard_option();
5416#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005417}
5418
5419/*
5420 * Check for string options that are NULL (normally only termcap options).
5421 */
5422 void
5423check_options()
5424{
5425 int opt_idx;
5426
5427 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5428 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5429 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5430}
5431
5432/*
5433 * Check string options in a buffer for NULL value.
5434 */
5435 void
5436check_buf_options(buf)
5437 buf_T *buf;
5438{
5439#if defined(FEAT_QUICKFIX)
5440 check_string_option(&buf->b_p_bh);
5441 check_string_option(&buf->b_p_bt);
5442#endif
5443#ifdef FEAT_MBYTE
5444 check_string_option(&buf->b_p_fenc);
5445#endif
5446 check_string_option(&buf->b_p_ff);
5447#ifdef FEAT_FIND_ID
5448 check_string_option(&buf->b_p_def);
5449 check_string_option(&buf->b_p_inc);
5450# ifdef FEAT_EVAL
5451 check_string_option(&buf->b_p_inex);
5452# endif
5453#endif
5454#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5455 check_string_option(&buf->b_p_inde);
5456 check_string_option(&buf->b_p_indk);
5457#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005458#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5459 check_string_option(&buf->b_p_bexpr);
5460#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005461#if defined(FEAT_CRYPT)
5462 check_string_option(&buf->b_p_cm);
5463#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005464#if defined(FEAT_EVAL)
5465 check_string_option(&buf->b_p_fex);
5466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467#ifdef FEAT_CRYPT
5468 check_string_option(&buf->b_p_key);
5469#endif
5470 check_string_option(&buf->b_p_kp);
5471 check_string_option(&buf->b_p_mps);
5472 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005473 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005474 check_string_option(&buf->b_p_isk);
5475#ifdef FEAT_COMMENTS
5476 check_string_option(&buf->b_p_com);
5477#endif
5478#ifdef FEAT_FOLDING
5479 check_string_option(&buf->b_p_cms);
5480#endif
5481 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005482#ifdef FEAT_TEXTOBJ
5483 check_string_option(&buf->b_p_qe);
5484#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005485#ifdef FEAT_SYN_HL
5486 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005487#endif
5488#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005489 check_string_option(&buf->b_s.b_p_spc);
5490 check_string_option(&buf->b_s.b_p_spf);
5491 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492#endif
5493#ifdef FEAT_SEARCHPATH
5494 check_string_option(&buf->b_p_sua);
5495#endif
5496#ifdef FEAT_CINDENT
5497 check_string_option(&buf->b_p_cink);
5498 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005499 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005500#endif
5501#ifdef FEAT_AUTOCMD
5502 check_string_option(&buf->b_p_ft);
5503#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5505 check_string_option(&buf->b_p_cinw);
5506#endif
5507#ifdef FEAT_INS_EXPAND
5508 check_string_option(&buf->b_p_cpt);
5509#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005510#ifdef FEAT_COMPL_FUNC
5511 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005512 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005513#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514#ifdef FEAT_KEYMAP
5515 check_string_option(&buf->b_p_keymap);
5516#endif
5517#ifdef FEAT_QUICKFIX
5518 check_string_option(&buf->b_p_gp);
5519 check_string_option(&buf->b_p_mp);
5520 check_string_option(&buf->b_p_efm);
5521#endif
5522 check_string_option(&buf->b_p_ep);
5523 check_string_option(&buf->b_p_path);
5524 check_string_option(&buf->b_p_tags);
5525#ifdef FEAT_INS_EXPAND
5526 check_string_option(&buf->b_p_dict);
5527 check_string_option(&buf->b_p_tsr);
5528#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005529#ifdef FEAT_LISP
5530 check_string_option(&buf->b_p_lw);
5531#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005532 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533}
5534
5535/*
5536 * Free the string allocated for an option.
5537 * Checks for the string being empty_option. This may happen if we're out of
5538 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5539 * check_options().
5540 * Does NOT check for P_ALLOCED flag!
5541 */
5542 void
5543free_string_option(p)
5544 char_u *p;
5545{
5546 if (p != empty_option)
5547 vim_free(p);
5548}
5549
5550 void
5551clear_string_option(pp)
5552 char_u **pp;
5553{
5554 if (*pp != empty_option)
5555 vim_free(*pp);
5556 *pp = empty_option;
5557}
5558
5559 static void
5560check_string_option(pp)
5561 char_u **pp;
5562{
5563 if (*pp == NULL)
5564 *pp = empty_option;
5565}
5566
5567/*
5568 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5569 */
5570 void
5571set_term_option_alloced(p)
5572 char_u **p;
5573{
5574 int opt_idx;
5575
5576 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5577 if (options[opt_idx].var == (char_u *)p)
5578 {
5579 options[opt_idx].flags |= P_ALLOCED;
5580 return;
5581 }
5582 return; /* cannot happen: didn't find it! */
5583}
5584
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005585#if defined(FEAT_EVAL) || defined(PROTO)
5586/*
5587 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5588 * Return FALSE when it wasn't.
5589 * Return -1 for an unknown option.
5590 */
5591 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005592was_set_insecurely(opt, opt_flags)
5593 char_u *opt;
5594 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005595{
5596 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005597 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005598
5599 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005600 {
5601 flagp = insecure_flag(idx, opt_flags);
5602 return (*flagp & P_INSECURE) != 0;
5603 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005604 EMSG2(_(e_intern2), "was_set_insecurely()");
5605 return -1;
5606}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005607
5608/*
5609 * Get a pointer to the flags used for the P_INSECURE flag of option
5610 * "opt_idx". For some local options a local flags field is used.
5611 */
5612 static long_u *
5613insecure_flag(opt_idx, opt_flags)
5614 int opt_idx;
5615 int opt_flags;
5616{
5617 if (opt_flags & OPT_LOCAL)
5618 switch ((int)options[opt_idx].indir)
5619 {
5620#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005621 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005622#endif
5623#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005624# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005625 case PV_FDE: return &curwin->w_p_fde_flags;
5626 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005627# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005628# ifdef FEAT_BEVAL
5629 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5630# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005631# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005632 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005633# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005634 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005635# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005636 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005637# endif
5638#endif
5639 }
5640
5641 /* Nothing special, return global flags field. */
5642 return &options[opt_idx].flags;
5643}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005644#endif
5645
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005646#ifdef FEAT_TITLE
5647static void redraw_titles __ARGS((void));
5648
5649/*
5650 * Redraw the window title and/or tab page text later.
5651 */
5652static void redraw_titles()
5653{
5654 need_maketitle = TRUE;
5655# ifdef FEAT_WINDOWS
5656 redraw_tabline = TRUE;
5657# endif
5658}
5659#endif
5660
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661/*
5662 * Set a string option to a new value (without checking the effect).
5663 * The string is copied into allocated memory.
5664 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005665 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005666 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667 */
5668 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005669set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670 char_u *name;
5671 int opt_idx;
5672 char_u *val;
5673 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005674 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675{
5676 char_u *s;
5677 char_u **varp;
5678 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005679 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680
Bram Moolenaar89d40322006-08-29 15:30:07 +00005681 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005683 idx = findoption(name);
5684 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005685 {
5686 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005687 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690 }
5691
Bram Moolenaar89d40322006-08-29 15:30:07 +00005692 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693 return;
5694
5695 s = vim_strsave(val);
5696 if (s != NULL)
5697 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005698 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005700 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 free_string_option(*varp);
5702 *varp = s;
5703
5704 /* For buffer/window local option may also set the global value. */
5705 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005706 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707
Bram Moolenaar89d40322006-08-29 15:30:07 +00005708 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709
5710 /* When setting both values of a global option with a local value,
5711 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005712 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713 {
5714 free_string_option(*varp);
5715 *varp = empty_option;
5716 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005717# ifdef FEAT_EVAL
5718 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005719 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005720 set_sid == 0 ? current_SID : set_sid);
5721# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722 }
5723}
5724
5725/*
5726 * Set global value for string option when it's a local option.
5727 */
5728 static void
5729set_string_option_global(opt_idx, varp)
5730 int opt_idx; /* option index */
5731 char_u **varp; /* pointer to option variable */
5732{
5733 char_u **p, *s;
5734
5735 /* the global value is always allocated */
5736 if (options[opt_idx].var == VAR_WIN)
5737 p = (char_u **)GLOBAL_WO(varp);
5738 else
5739 p = (char_u **)options[opt_idx].var;
5740 if (options[opt_idx].indir != PV_NONE
5741 && p != varp
5742 && (s = vim_strsave(*varp)) != NULL)
5743 {
5744 free_string_option(*p);
5745 *p = s;
5746 }
5747}
5748
5749/*
5750 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005751 *
5752 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005754 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755set_string_option(opt_idx, value, opt_flags)
5756 int opt_idx;
5757 char_u *value;
5758 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5759{
5760 char_u *s;
5761 char_u **varp;
5762 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005763#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5764 char_u *saved_oldval = NULL;
5765#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005766 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005767
5768 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005769 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770
5771 s = vim_strsave(value);
5772 if (s != NULL)
5773 {
5774 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5775 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005776 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005777 ? OPT_GLOBAL : OPT_LOCAL)
5778 : opt_flags);
5779 oldval = *varp;
5780 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005781
5782#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005783 if (!starting
5784# ifdef FEAT_CRYPT
5785 && options[opt_idx].indir != PV_KEY
5786# endif
5787 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005788 saved_oldval = vim_strsave(oldval);
5789#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005790 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5791 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005792 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005793
5794 /* call autocomamnd after handling side effects */
5795#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5796 if (saved_oldval != NULL)
5797 {
5798 char_u buf_type[7];
5799 sprintf((char *)buf_type, "%s",
5800 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005801 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5802 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005803 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5804 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5805 reset_v_option_vars();
5806 vim_free(saved_oldval);
5807 }
5808#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005809 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005810 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005811}
5812
5813/*
5814 * Handle string options that need some action to perform when changed.
5815 * Returns NULL for success, or an error message for an error.
5816 */
5817 static char_u *
5818did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5819 opt_flags)
5820 int opt_idx; /* index in options[] table */
5821 char_u **varp; /* pointer to the option variable */
5822 int new_value_alloced; /* new value was allocated */
5823 char_u *oldval; /* previous value of the option */
5824 char_u *errbuf; /* buffer for errors, or NULL */
5825 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5826{
5827 char_u *errmsg = NULL;
5828 char_u *s, *p;
5829 int did_chartab = FALSE;
5830 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005831 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005832#ifdef FEAT_GUI
5833 /* set when changing an option that only requires a redraw in the GUI */
5834 int redraw_gui_only = FALSE;
5835#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005836
5837 /* Get the global option to compare with, otherwise we would have to check
5838 * two values for all local options. */
5839 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5840
5841 /* Disallow changing some options from secure mode */
5842 if ((secure
5843#ifdef HAVE_SANDBOX
5844 || sandbox != 0
5845#endif
5846 ) && (options[opt_idx].flags & P_SECURE))
5847 {
5848 errmsg = e_secure;
5849 }
5850
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005851 /* Check for a "normal" file name in some options. Disallow a path
5852 * separator (slash and/or backslash), wildcards and characters that are
5853 * often illegal in a file name. */
5854 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005855 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005856 {
5857 errmsg = e_invarg;
5858 }
5859
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 /* 'term' */
5861 else if (varp == &T_NAME)
5862 {
5863 if (T_NAME[0] == NUL)
5864 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5865#ifdef FEAT_GUI
5866 if (gui.in_use)
5867 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5868 else if (term_is_gui(T_NAME))
5869 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5870#endif
5871 else if (set_termname(T_NAME) == FAIL)
5872 errmsg = (char_u *)N_("E522: Not found in termcap");
5873 else
5874 /* Screen colors may have changed. */
5875 redraw_later_clear();
5876 }
5877
5878 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005879 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005881 char_u *bkc = p_bkc;
5882 unsigned int *flags = &bkc_flags;
5883
5884 if (opt_flags & OPT_LOCAL)
5885 {
5886 bkc = curbuf->b_p_bkc;
5887 flags = &curbuf->b_bkc_flags;
5888 }
5889
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005890 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5891 /* make the local value empty: use the global value */
5892 *flags = 0;
5893 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005895 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5896 errmsg = e_invarg;
5897 if ((((int)*flags & BKC_AUTO) != 0)
5898 + (((int)*flags & BKC_YES) != 0)
5899 + (((int)*flags & BKC_NO) != 0) != 1)
5900 {
5901 /* Must have exactly one of "auto", "yes" and "no". */
5902 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5903 errmsg = e_invarg;
5904 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905 }
5906 }
5907
5908 /* 'backupext' and 'patchmode' */
5909 else if (varp == &p_bex || varp == &p_pm)
5910 {
5911 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5912 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5913 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5914 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005915#ifdef FEAT_LINEBREAK
5916 /* 'breakindentopt' */
5917 else if (varp == &curwin->w_p_briopt)
5918 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005919 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005920 errmsg = e_invarg;
5921 }
5922#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005923
5924 /*
5925 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5926 * If the new option is invalid, use old value. 'lisp' option: refill
5927 * chartab[] for '-' char
5928 */
5929 else if ( varp == &p_isi
5930 || varp == &(curbuf->b_p_isk)
5931 || varp == &p_isp
5932 || varp == &p_isf)
5933 {
5934 if (init_chartab() == FAIL)
5935 {
5936 did_chartab = TRUE; /* need to restore it below */
5937 errmsg = e_invarg; /* error in value */
5938 }
5939 }
5940
5941 /* 'helpfile' */
5942 else if (varp == &p_hf)
5943 {
5944 /* May compute new values for $VIM and $VIMRUNTIME */
5945 if (didset_vim)
5946 {
5947 vim_setenv((char_u *)"VIM", (char_u *)"");
5948 didset_vim = FALSE;
5949 }
5950 if (didset_vimruntime)
5951 {
5952 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5953 didset_vimruntime = FALSE;
5954 }
5955 }
5956
Bram Moolenaar1a384422010-07-14 19:53:30 +02005957#ifdef FEAT_SYN_HL
5958 /* 'colorcolumn' */
5959 else if (varp == &curwin->w_p_cc)
5960 errmsg = check_colorcolumn(curwin);
5961#endif
5962
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963#ifdef FEAT_MULTI_LANG
5964 /* 'helplang' */
5965 else if (varp == &p_hlg)
5966 {
5967 /* Check for "", "ab", "ab,cd", etc. */
5968 for (s = p_hlg; *s != NUL; s += 3)
5969 {
5970 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5971 {
5972 errmsg = e_invarg;
5973 break;
5974 }
5975 if (s[2] == NUL)
5976 break;
5977 }
5978 }
5979#endif
5980
5981 /* 'highlight' */
5982 else if (varp == &p_hl)
5983 {
5984 if (highlight_changed() == FAIL)
5985 errmsg = e_invarg; /* invalid flags */
5986 }
5987
5988 /* 'nrformats' */
5989 else if (gvarp == &p_nf)
5990 {
5991 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5992 errmsg = e_invarg;
5993 }
5994
5995#ifdef FEAT_SESSION
5996 /* 'sessionoptions' */
5997 else if (varp == &p_ssop)
5998 {
5999 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6000 errmsg = e_invarg;
6001 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6002 {
6003 /* Don't allow both "sesdir" and "curdir". */
6004 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6005 errmsg = e_invarg;
6006 }
6007 }
6008 /* 'viewoptions' */
6009 else if (varp == &p_vop)
6010 {
6011 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6012 errmsg = e_invarg;
6013 }
6014#endif
6015
6016 /* 'scrollopt' */
6017#ifdef FEAT_SCROLLBIND
6018 else if (varp == &p_sbo)
6019 {
6020 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6021 errmsg = e_invarg;
6022 }
6023#endif
6024
6025 /* 'ambiwidth' */
6026#ifdef FEAT_MBYTE
6027 else if (varp == &p_ambw)
6028 {
6029 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6030 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006031 else if (set_chars_option(&p_lcs) != NULL)
6032 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6033# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6034 else if (set_chars_option(&p_fcs) != NULL)
6035 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6036# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037 }
6038#endif
6039
6040 /* 'background' */
6041 else if (varp == &p_bg)
6042 {
6043 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6044 {
6045#ifdef FEAT_EVAL
6046 int dark = (*p_bg == 'd');
6047#endif
6048
6049 init_highlight(FALSE, FALSE);
6050
6051#ifdef FEAT_EVAL
6052 if (dark != (*p_bg == 'd')
6053 && get_var_value((char_u *)"g:colors_name") != NULL)
6054 {
6055 /* The color scheme must have set 'background' back to another
6056 * value, that's not what we want here. Disable the color
6057 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006058 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006059 free_string_option(p_bg);
6060 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6061 check_string_option(&p_bg);
6062 init_highlight(FALSE, FALSE);
6063 }
6064#endif
6065 }
6066 else
6067 errmsg = e_invarg;
6068 }
6069
6070 /* 'wildmode' */
6071 else if (varp == &p_wim)
6072 {
6073 if (check_opt_wim() == FAIL)
6074 errmsg = e_invarg;
6075 }
6076
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006077#ifdef FEAT_CMDL_COMPL
6078 /* 'wildoptions' */
6079 else if (varp == &p_wop)
6080 {
6081 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6082 errmsg = e_invarg;
6083 }
6084#endif
6085
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086#ifdef FEAT_WAK
6087 /* 'winaltkeys' */
6088 else if (varp == &p_wak)
6089 {
6090 if (*p_wak == NUL
6091 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6092 errmsg = e_invarg;
6093# ifdef FEAT_MENU
6094# ifdef FEAT_GUI_MOTIF
6095 else if (gui.in_use)
6096 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6097# else
6098# ifdef FEAT_GUI_GTK
6099 else if (gui.in_use)
6100 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6101# endif
6102# endif
6103# endif
6104 }
6105#endif
6106
6107#ifdef FEAT_AUTOCMD
6108 /* 'eventignore' */
6109 else if (varp == &p_ei)
6110 {
6111 if (check_ei() == FAIL)
6112 errmsg = e_invarg;
6113 }
6114#endif
6115
6116#ifdef FEAT_MBYTE
6117 /* 'encoding' and 'fileencoding' */
6118 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6119 {
6120 if (gvarp == &p_fenc)
6121 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006122 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123 errmsg = e_modifiable;
6124 else if (vim_strchr(*varp, ',') != NULL)
6125 /* No comma allowed in 'fileencoding'; catches confusing it
6126 * with 'fileencodings'. */
6127 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006129 {
6130# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006131 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006132 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006133# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006134 /* Add 'fileencoding' to the swap file. */
6135 ml_setflags(curbuf);
6136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 }
6138 if (errmsg == NULL)
6139 {
6140 /* canonize the value, so that STRCMP() can be used on it */
6141 p = enc_canonize(*varp);
6142 if (p != NULL)
6143 {
6144 vim_free(*varp);
6145 *varp = p;
6146 }
6147 if (varp == &p_enc)
6148 {
6149 errmsg = mb_init();
6150# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006151 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006152# endif
6153 }
6154 }
6155
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006156# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006157 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6158 {
6159 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6160 if (STRCMP(p_tenc, "utf-8") != 0)
6161 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6162 }
6163# endif
6164
6165 if (errmsg == NULL)
6166 {
6167# ifdef FEAT_KEYMAP
6168 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6169 * (with another encoding). */
6170 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6171 (void)keymap_init();
6172# endif
6173
6174 /* When 'termencoding' is not empty and 'encoding' changes or when
6175 * 'termencoding' changes, need to setup for keyboard input and
6176 * display output conversion. */
6177 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6178 {
6179 convert_setup(&input_conv, p_tenc, p_enc);
6180 convert_setup(&output_conv, p_enc, p_tenc);
6181 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006182
6183# if defined(WIN3264) && defined(FEAT_MBYTE)
6184 /* $HOME may have characters in active code page. */
6185 if (varp == &p_enc)
6186 init_homedir();
6187# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188 }
6189 }
6190#endif
6191
6192#if defined(FEAT_POSTSCRIPT)
6193 else if (varp == &p_penc)
6194 {
6195 /* Canonize printencoding if VIM standard one */
6196 p = enc_canonize(p_penc);
6197 if (p != NULL)
6198 {
6199 vim_free(p_penc);
6200 p_penc = p;
6201 }
6202 else
6203 {
6204 /* Ensure lower case and '-' for '_' */
6205 for (s = p_penc; *s != NUL; s++)
6206 {
6207 if (*s == '_')
6208 *s = '-';
6209 else
6210 *s = TOLOWER_ASC(*s);
6211 }
6212 }
6213 }
6214#endif
6215
Bram Moolenaar9372a112005-12-06 19:59:18 +00006216#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006217 else if (varp == &p_imak)
6218 {
6219 if (gui.in_use && !im_xim_isvalid_imactivate())
6220 errmsg = e_invarg;
6221 }
6222#endif
6223
6224#ifdef FEAT_KEYMAP
6225 else if (varp == &curbuf->b_p_keymap)
6226 {
6227 /* load or unload key mapping tables */
6228 errmsg = keymap_init();
6229
Bram Moolenaarfab06232009-03-04 03:13:35 +00006230 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006231 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006232 if (*curbuf->b_p_keymap != NUL)
6233 {
6234 /* Installed a new keymap, switch on using it. */
6235 curbuf->b_p_iminsert = B_IMODE_LMAP;
6236 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6237 curbuf->b_p_imsearch = B_IMODE_LMAP;
6238 }
6239 else
6240 {
6241 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6242 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6243 curbuf->b_p_iminsert = B_IMODE_NONE;
6244 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6245 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6246 }
6247 if ((opt_flags & OPT_LOCAL) == 0)
6248 {
6249 set_iminsert_global();
6250 set_imsearch_global();
6251 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006252# ifdef FEAT_WINDOWS
6253 status_redraw_curbuf();
6254# endif
6255 }
6256 }
6257#endif
6258
6259 /* 'fileformat' */
6260 else if (gvarp == &p_ff)
6261 {
6262 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6263 errmsg = e_modifiable;
6264 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6265 errmsg = e_invarg;
6266 else
6267 {
6268 /* may also change 'textmode' */
6269 if (get_fileformat(curbuf) == EOL_DOS)
6270 curbuf->b_p_tx = TRUE;
6271 else
6272 curbuf->b_p_tx = FALSE;
6273#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006274 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006275#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006276 /* update flag in swap file */
6277 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006278 /* Redraw needed when switching to/from "mac": a CR in the text
6279 * will be displayed differently. */
6280 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6281 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006282 }
6283 }
6284
6285 /* 'fileformats' */
6286 else if (varp == &p_ffs)
6287 {
6288 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6289 errmsg = e_invarg;
6290 else
6291 {
6292 /* also change 'textauto' */
6293 if (*p_ffs == NUL)
6294 p_ta = FALSE;
6295 else
6296 p_ta = TRUE;
6297 }
6298 }
6299
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006300#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006301 /* 'cryptkey' */
6302 else if (gvarp == &p_key)
6303 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006304# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305 /* Make sure the ":set" command doesn't show the new value in the
6306 * history. */
6307 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006308# endif
6309 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6310 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006311 ml_set_crypt_key(curbuf, oldval,
6312 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006313 }
6314
6315 else if (gvarp == &p_cm)
6316 {
6317 if (opt_flags & OPT_LOCAL)
6318 p = curbuf->b_p_cm;
6319 else
6320 p = p_cm;
6321 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6322 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006323 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006324 errmsg = e_invarg;
6325 else
6326 {
6327 /* When setting the global value to empty, make it "zip". */
6328 if (*p_cm == NUL)
6329 {
6330 if (new_value_alloced)
6331 free_string_option(p_cm);
6332 p_cm = vim_strsave((char_u *)"zip");
6333 new_value_alloced = TRUE;
6334 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006335 /* When using ":set cm=name" the local value is going to be empty.
6336 * Do that here, otherwise the crypt functions will still use the
6337 * local value. */
6338 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6339 {
6340 free_string_option(curbuf->b_p_cm);
6341 curbuf->b_p_cm = empty_option;
6342 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006343
6344 /* Need to update the swapfile when the effective method changed.
6345 * Set "s" to the effective old value, "p" to the effective new
6346 * method and compare. */
6347 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6348 s = p_cm; /* was previously using the global value */
6349 else
6350 s = oldval;
6351 if (*curbuf->b_p_cm == NUL)
6352 p = p_cm; /* is now using the global value */
6353 else
6354 p = curbuf->b_p_cm;
6355 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006356 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006357
6358 /* If the global value changes need to update the swapfile for all
6359 * buffers using that value. */
6360 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6361 {
6362 buf_T *buf;
6363
6364 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6365 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006366 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006367 }
6368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006369 }
6370#endif
6371
6372 /* 'matchpairs' */
6373 else if (gvarp == &p_mps)
6374 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006375#ifdef FEAT_MBYTE
6376 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006378 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006380 int x2 = -1;
6381 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006382
6383 if (*p != NUL)
6384 p += mb_ptr2len(p);
6385 if (*p != NUL)
6386 x2 = *p++;
6387 if (*p != NUL)
6388 {
6389 x3 = mb_ptr2char(p);
6390 p += mb_ptr2len(p);
6391 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006392 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006393 {
6394 errmsg = e_invarg;
6395 break;
6396 }
6397 if (*p == NUL)
6398 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006399 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006400 }
6401 else
6402#endif
6403 {
6404 /* Check for "x:y,x:y" */
6405 for (p = *varp; *p != NUL; p += 4)
6406 {
6407 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6408 {
6409 errmsg = e_invarg;
6410 break;
6411 }
6412 if (p[3] == NUL)
6413 break;
6414 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006415 }
6416 }
6417
6418#ifdef FEAT_COMMENTS
6419 /* 'comments' */
6420 else if (gvarp == &p_com)
6421 {
6422 for (s = *varp; *s; )
6423 {
6424 while (*s && *s != ':')
6425 {
6426 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6427 && !VIM_ISDIGIT(*s) && *s != '-')
6428 {
6429 errmsg = illegal_char(errbuf, *s);
6430 break;
6431 }
6432 ++s;
6433 }
6434 if (*s++ == NUL)
6435 errmsg = (char_u *)N_("E524: Missing colon");
6436 else if (*s == ',' || *s == NUL)
6437 errmsg = (char_u *)N_("E525: Zero length string");
6438 if (errmsg != NULL)
6439 break;
6440 while (*s && *s != ',')
6441 {
6442 if (*s == '\\' && s[1] != NUL)
6443 ++s;
6444 ++s;
6445 }
6446 s = skip_to_option_part(s);
6447 }
6448 }
6449#endif
6450
6451 /* 'listchars' */
6452 else if (varp == &p_lcs)
6453 {
6454 errmsg = set_chars_option(varp);
6455 }
6456
6457#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6458 /* 'fillchars' */
6459 else if (varp == &p_fcs)
6460 {
6461 errmsg = set_chars_option(varp);
6462 }
6463#endif
6464
6465#ifdef FEAT_CMDWIN
6466 /* 'cedit' */
6467 else if (varp == &p_cedit)
6468 {
6469 errmsg = check_cedit();
6470 }
6471#endif
6472
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006473 /* 'verbosefile' */
6474 else if (varp == &p_vfile)
6475 {
6476 verbose_stop();
6477 if (*p_vfile != NUL && verbose_open() == FAIL)
6478 errmsg = e_invarg;
6479 }
6480
Bram Moolenaar071d4272004-06-13 20:20:40 +00006481#ifdef FEAT_VIMINFO
6482 /* 'viminfo' */
6483 else if (varp == &p_viminfo)
6484 {
6485 for (s = p_viminfo; *s;)
6486 {
6487 /* Check it's a valid character */
6488 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6489 {
6490 errmsg = illegal_char(errbuf, *s);
6491 break;
6492 }
6493 if (*s == 'n') /* name is always last one */
6494 {
6495 break;
6496 }
6497 else if (*s == 'r') /* skip until next ',' */
6498 {
6499 while (*++s && *s != ',')
6500 ;
6501 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006502 else if (*s == '%')
6503 {
6504 /* optional number */
6505 while (vim_isdigit(*++s))
6506 ;
6507 }
6508 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006509 ++s; /* no extra chars */
6510 else /* must have a number */
6511 {
6512 while (vim_isdigit(*++s))
6513 ;
6514
6515 if (!VIM_ISDIGIT(*(s - 1)))
6516 {
6517 if (errbuf != NULL)
6518 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006519 sprintf((char *)errbuf,
6520 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521 transchar_byte(*(s - 1)));
6522 errmsg = errbuf;
6523 }
6524 else
6525 errmsg = (char_u *)"";
6526 break;
6527 }
6528 }
6529 if (*s == ',')
6530 ++s;
6531 else if (*s)
6532 {
6533 if (errbuf != NULL)
6534 errmsg = (char_u *)N_("E527: Missing comma");
6535 else
6536 errmsg = (char_u *)"";
6537 break;
6538 }
6539 }
6540 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6541 errmsg = (char_u *)N_("E528: Must specify a ' value");
6542 }
6543#endif /* FEAT_VIMINFO */
6544
6545 /* terminal options */
6546 else if (istermoption(&options[opt_idx]) && full_screen)
6547 {
6548 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6549 if (varp == &T_CCO)
6550 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006551 int colors = atoi((char *)T_CCO);
6552
6553 /* Only reinitialize colors if t_Co value has really changed to
6554 * avoid expensive reload of colorscheme if t_Co is set to the
6555 * same value multiple times. */
6556 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006558 t_colors = colors;
6559 if (t_colors <= 1)
6560 {
6561 if (new_value_alloced)
6562 vim_free(T_CCO);
6563 T_CCO = empty_option;
6564 }
6565 /* We now have a different color setup, initialize it again. */
6566 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 }
6569 ttest(FALSE);
6570 if (varp == &T_ME)
6571 {
6572 out_str(T_ME);
6573 redraw_later(CLEAR);
6574#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6575 /* Since t_me has been set, this probably means that the user
6576 * wants to use this as default colors. Need to reset default
6577 * background/foreground colors. */
6578 mch_set_normal_colors();
6579#endif
6580 }
6581 }
6582
6583#ifdef FEAT_LINEBREAK
6584 /* 'showbreak' */
6585 else if (varp == &p_sbr)
6586 {
6587 for (s = p_sbr; *s; )
6588 {
6589 if (ptr2cells(s) != 1)
6590 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006591 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006592 }
6593 }
6594#endif
6595
6596#ifdef FEAT_GUI
6597 /* 'guifont' */
6598 else if (varp == &p_guifont)
6599 {
6600 if (gui.in_use)
6601 {
6602 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006603# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 /*
6605 * Put up a font dialog and let the user select a new value.
6606 * If this is cancelled go back to the old value but don't
6607 * give an error message.
6608 */
6609 if (STRCMP(p, "*") == 0)
6610 {
6611 p = gui_mch_font_dialog(oldval);
6612
6613 if (new_value_alloced)
6614 free_string_option(p_guifont);
6615
6616 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6617 new_value_alloced = TRUE;
6618 }
6619# endif
6620 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6621 {
6622# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6623 if (STRCMP(p_guifont, "*") == 0)
6624 {
6625 /* Dialog was cancelled: Keep the old value without giving
6626 * an error message. */
6627 if (new_value_alloced)
6628 free_string_option(p_guifont);
6629 p_guifont = vim_strsave(oldval);
6630 new_value_alloced = TRUE;
6631 }
6632 else
6633# endif
6634 errmsg = (char_u *)N_("E596: Invalid font(s)");
6635 }
6636 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006637 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006638 }
6639# ifdef FEAT_XFONTSET
6640 else if (varp == &p_guifontset)
6641 {
6642 if (STRCMP(p_guifontset, "*") == 0)
6643 errmsg = (char_u *)N_("E597: can't select fontset");
6644 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6645 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006646 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006647 }
6648# endif
6649# ifdef FEAT_MBYTE
6650 else if (varp == &p_guifontwide)
6651 {
6652 if (STRCMP(p_guifontwide, "*") == 0)
6653 errmsg = (char_u *)N_("E533: can't select wide font");
6654 else if (gui_get_wide_font() == FAIL)
6655 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006656 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006657 }
6658# endif
6659#endif
6660
6661#ifdef CURSOR_SHAPE
6662 /* 'guicursor' */
6663 else if (varp == &p_guicursor)
6664 errmsg = parse_shape_opt(SHAPE_CURSOR);
6665#endif
6666
6667#ifdef FEAT_MOUSESHAPE
6668 /* 'mouseshape' */
6669 else if (varp == &p_mouseshape)
6670 {
6671 errmsg = parse_shape_opt(SHAPE_MOUSE);
6672 update_mouseshape(-1);
6673 }
6674#endif
6675
6676#ifdef FEAT_PRINTER
6677 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006678 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006679# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006680 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006681 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006682# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006683#endif
6684
6685#ifdef FEAT_LANGMAP
6686 /* 'langmap' */
6687 else if (varp == &p_langmap)
6688 langmap_set();
6689#endif
6690
6691#ifdef FEAT_LINEBREAK
6692 /* 'breakat' */
6693 else if (varp == &p_breakat)
6694 fill_breakat_flags();
6695#endif
6696
6697#ifdef FEAT_TITLE
6698 /* 'titlestring' and 'iconstring' */
6699 else if (varp == &p_titlestring || varp == &p_iconstring)
6700 {
6701# ifdef FEAT_STL_OPT
6702 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6703
6704 /* NULL => statusline syntax */
6705 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6706 stl_syntax |= flagval;
6707 else
6708 stl_syntax &= ~flagval;
6709# endif
6710 did_set_title(varp == &p_iconstring);
6711
6712 }
6713#endif
6714
6715#ifdef FEAT_GUI
6716 /* 'guioptions' */
6717 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006718 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006720 redraw_gui_only = TRUE;
6721 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722#endif
6723
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006724#if defined(FEAT_GUI_TABLINE)
6725 /* 'guitablabel' */
6726 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006727 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006728 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006729 redraw_gui_only = TRUE;
6730 }
6731 /* 'guitabtooltip' */
6732 else if (varp == &p_gtt)
6733 {
6734 redraw_gui_only = TRUE;
6735 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006736#endif
6737
Bram Moolenaar071d4272004-06-13 20:20:40 +00006738#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6739 /* 'ttymouse' */
6740 else if (varp == &p_ttym)
6741 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006742 /* Switch the mouse off before changing the escape sequences used for
6743 * that. */
6744 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6746 errmsg = e_invarg;
6747 else
6748 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006749 if (termcap_active)
6750 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751 }
6752#endif
6753
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 /* 'selection' */
6755 else if (varp == &p_sel)
6756 {
6757 if (*p_sel == NUL
6758 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6759 errmsg = e_invarg;
6760 }
6761
6762 /* 'selectmode' */
6763 else if (varp == &p_slm)
6764 {
6765 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6766 errmsg = e_invarg;
6767 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006768
6769#ifdef FEAT_BROWSE
6770 /* 'browsedir' */
6771 else if (varp == &p_bsdir)
6772 {
6773 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6774 && !mch_isdir(p_bsdir))
6775 errmsg = e_invarg;
6776 }
6777#endif
6778
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779 /* 'keymodel' */
6780 else if (varp == &p_km)
6781 {
6782 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6783 errmsg = e_invarg;
6784 else
6785 {
6786 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6787 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6788 }
6789 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790
6791 /* 'mousemodel' */
6792 else if (varp == &p_mousem)
6793 {
6794 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6795 errmsg = e_invarg;
6796#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6797 else if (*p_mousem != *oldval)
6798 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6799 * to create or delete the popup menus. */
6800 gui_motif_update_mousemodel(root_menu);
6801#endif
6802 }
6803
6804 /* 'switchbuf' */
6805 else if (varp == &p_swb)
6806 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006807 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006808 errmsg = e_invarg;
6809 }
6810
6811 /* 'debug' */
6812 else if (varp == &p_debug)
6813 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006814 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815 errmsg = e_invarg;
6816 }
6817
6818 /* 'display' */
6819 else if (varp == &p_dy)
6820 {
6821 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6822 errmsg = e_invarg;
6823 else
6824 (void)init_chartab();
6825
6826 }
6827
6828#ifdef FEAT_VERTSPLIT
6829 /* 'eadirection' */
6830 else if (varp == &p_ead)
6831 {
6832 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6833 errmsg = e_invarg;
6834 }
6835#endif
6836
6837#ifdef FEAT_CLIPBOARD
6838 /* 'clipboard' */
6839 else if (varp == &p_cb)
6840 errmsg = check_clipboard_option();
6841#endif
6842
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006843#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006844 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6845 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006846 else if (varp == &(curwin->w_s->b_p_spl)
6847 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006848 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006849 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006850 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006851 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006852 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006853 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006854 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006855 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006856 /* 'spellsuggest' */
6857 else if (varp == &p_sps)
6858 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006859 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006860 errmsg = e_invarg;
6861 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006862 /* 'mkspellmem' */
6863 else if (varp == &p_msm)
6864 {
6865 if (spell_check_msm() != OK)
6866 errmsg = e_invarg;
6867 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006868#endif
6869
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870#ifdef FEAT_QUICKFIX
6871 /* When 'bufhidden' is set, check for valid value. */
6872 else if (gvarp == &p_bh)
6873 {
6874 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6875 errmsg = e_invarg;
6876 }
6877
6878 /* When 'buftype' is set, check for valid value. */
6879 else if (gvarp == &p_bt)
6880 {
6881 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6882 errmsg = e_invarg;
6883 else
6884 {
6885# ifdef FEAT_WINDOWS
6886 if (curwin->w_status_height)
6887 {
6888 curwin->w_redr_status = TRUE;
6889 redraw_later(VALID);
6890 }
6891# endif
6892 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006893# ifdef FEAT_TITLE
6894 redraw_titles();
6895# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006896 }
6897 }
6898#endif
6899
6900#ifdef FEAT_STL_OPT
6901 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006902 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903 {
6904 int wid;
6905
6906 if (varp == &p_ruf) /* reset ru_wid first */
6907 ru_wid = 0;
6908 s = *varp;
6909 if (varp == &p_ruf && *s == '%')
6910 {
6911 /* set ru_wid if 'ruf' starts with "%99(" */
6912 if (*++s == '-') /* ignore a '-' */
6913 s++;
6914 wid = getdigits(&s);
6915 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6916 ru_wid = wid;
6917 else
6918 errmsg = check_stl_option(p_ruf);
6919 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006920 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006921 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006922 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006923 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006924 comp_col();
6925 }
6926#endif
6927
6928#ifdef FEAT_INS_EXPAND
6929 /* check if it is a valid value for 'complete' -- Acevedo */
6930 else if (gvarp == &p_cpt)
6931 {
6932 for (s = *varp; *s;)
6933 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006934 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006935 s++;
6936 if (!*s)
6937 break;
6938 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6939 {
6940 errmsg = illegal_char(errbuf, *s);
6941 break;
6942 }
6943 if (*++s != NUL && *s != ',' && *s != ' ')
6944 {
6945 if (s[-1] == 'k' || s[-1] == 's')
6946 {
6947 /* skip optional filename after 'k' and 's' */
6948 while (*s && *s != ',' && *s != ' ')
6949 {
6950 if (*s == '\\')
6951 ++s;
6952 ++s;
6953 }
6954 }
6955 else
6956 {
6957 if (errbuf != NULL)
6958 {
6959 sprintf((char *)errbuf,
6960 _("E535: Illegal character after <%c>"),
6961 *--s);
6962 errmsg = errbuf;
6963 }
6964 else
6965 errmsg = (char_u *)"";
6966 break;
6967 }
6968 }
6969 }
6970 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006971
6972 /* 'completeopt' */
6973 else if (varp == &p_cot)
6974 {
6975 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6976 errmsg = e_invarg;
6977 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006978#endif /* FEAT_INS_EXPAND */
6979
6980
6981#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6982 else if (varp == &p_toolbar)
6983 {
6984 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6985 &toolbar_flags, TRUE) != OK)
6986 errmsg = e_invarg;
6987 else
6988 {
6989 out_flush();
6990 gui_mch_show_toolbar((toolbar_flags &
6991 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6992 }
6993 }
6994#endif
6995
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006996#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006997 /* 'toolbariconsize': GTK+ 2 only */
6998 else if (varp == &p_tbis)
6999 {
7000 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7001 errmsg = e_invarg;
7002 else
7003 {
7004 out_flush();
7005 gui_mch_show_toolbar((toolbar_flags &
7006 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7007 }
7008 }
7009#endif
7010
7011 /* 'pastetoggle': translate key codes like in a mapping */
7012 else if (varp == &p_pt)
7013 {
7014 if (*p_pt)
7015 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007016 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 if (p != NULL)
7018 {
7019 if (new_value_alloced)
7020 free_string_option(p_pt);
7021 p_pt = p;
7022 new_value_alloced = TRUE;
7023 }
7024 }
7025 }
7026
7027 /* 'backspace' */
7028 else if (varp == &p_bs)
7029 {
7030 if (VIM_ISDIGIT(*p_bs))
7031 {
7032 if (*p_bs >'2' || p_bs[1] != NUL)
7033 errmsg = e_invarg;
7034 }
7035 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7036 errmsg = e_invarg;
7037 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007038 else if (varp == &p_bo)
7039 {
7040 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7041 errmsg = e_invarg;
7042 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007044#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007045 /* 'casemap' */
7046 else if (varp == &p_cmp)
7047 {
7048 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7049 errmsg = e_invarg;
7050 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007051#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007052
7053#ifdef FEAT_DIFF
7054 /* 'diffopt' */
7055 else if (varp == &p_dip)
7056 {
7057 if (diffopt_changed() == FAIL)
7058 errmsg = e_invarg;
7059 }
7060#endif
7061
7062#ifdef FEAT_FOLDING
7063 /* 'foldmethod' */
7064 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7065 {
7066 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7067 || *curwin->w_p_fdm == NUL)
7068 errmsg = e_invarg;
7069 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007070 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007072 if (foldmethodIsDiff(curwin))
7073 newFoldLevel();
7074 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007075 }
7076# ifdef FEAT_EVAL
7077 /* 'foldexpr' */
7078 else if (varp == &curwin->w_p_fde)
7079 {
7080 if (foldmethodIsExpr(curwin))
7081 foldUpdateAll(curwin);
7082 }
7083# endif
7084 /* 'foldmarker' */
7085 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7086 {
7087 p = vim_strchr(*varp, ',');
7088 if (p == NULL)
7089 errmsg = (char_u *)N_("E536: comma required");
7090 else if (p == *varp || p[1] == NUL)
7091 errmsg = e_invarg;
7092 else if (foldmethodIsMarker(curwin))
7093 foldUpdateAll(curwin);
7094 }
7095 /* 'commentstring' */
7096 else if (gvarp == &p_cms)
7097 {
7098 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7099 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7100 }
7101 /* 'foldopen' */
7102 else if (varp == &p_fdo)
7103 {
7104 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7105 errmsg = e_invarg;
7106 }
7107 /* 'foldclose' */
7108 else if (varp == &p_fcl)
7109 {
7110 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7111 errmsg = e_invarg;
7112 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007113 /* 'foldignore' */
7114 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7115 {
7116 if (foldmethodIsIndent(curwin))
7117 foldUpdateAll(curwin);
7118 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119#endif
7120
7121#ifdef FEAT_VIRTUALEDIT
7122 /* 'virtualedit' */
7123 else if (varp == &p_ve)
7124 {
7125 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7126 errmsg = e_invarg;
7127 else if (STRCMP(p_ve, oldval) != 0)
7128 {
7129 /* Recompute cursor position in case the new 've' setting
7130 * changes something. */
7131 validate_virtcol();
7132 coladvance(curwin->w_virtcol);
7133 }
7134 }
7135#endif
7136
7137#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7138 else if (varp == &p_csqf)
7139 {
7140 if (p_csqf != NULL)
7141 {
7142 p = p_csqf;
7143 while (*p != NUL)
7144 {
7145 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7146 || p[1] == NUL
7147 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7148 || (p[2] != NUL && p[2] != ','))
7149 {
7150 errmsg = e_invarg;
7151 break;
7152 }
7153 else if (p[2] == NUL)
7154 break;
7155 else
7156 p += 3;
7157 }
7158 }
7159 }
7160#endif
7161
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007162#ifdef FEAT_CINDENT
7163 /* 'cinoptions' */
7164 else if (gvarp == &p_cino)
7165 {
7166 /* TODO: recognize errors */
7167 parse_cino(curbuf);
7168 }
7169#endif
7170
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007171#if defined(FEAT_RENDER_OPTIONS)
7172 else if (varp == &p_rop && gui.in_use)
7173 {
7174 if (!gui_mch_set_rendering_options(p_rop))
7175 errmsg = e_invarg;
7176 }
7177#endif
7178
Bram Moolenaar071d4272004-06-13 20:20:40 +00007179 /* Options that are a list of flags. */
7180 else
7181 {
7182 p = NULL;
7183 if (varp == &p_ww)
7184 p = (char_u *)WW_ALL;
7185 if (varp == &p_shm)
7186 p = (char_u *)SHM_ALL;
7187 else if (varp == &(p_cpo))
7188 p = (char_u *)CPO_ALL;
7189 else if (varp == &(curbuf->b_p_fo))
7190 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007191#ifdef FEAT_CONCEAL
7192 else if (varp == &curwin->w_p_cocu)
7193 p = (char_u *)COCU_ALL;
7194#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007195 else if (varp == &p_mouse)
7196 {
7197#ifdef FEAT_MOUSE
7198 p = (char_u *)MOUSE_ALL;
7199#else
7200 if (*p_mouse != NUL)
7201 errmsg = (char_u *)N_("E538: No mouse support");
7202#endif
7203 }
7204#if defined(FEAT_GUI)
7205 else if (varp == &p_go)
7206 p = (char_u *)GO_ALL;
7207#endif
7208 if (p != NULL)
7209 {
7210 for (s = *varp; *s; ++s)
7211 if (vim_strchr(p, *s) == NULL)
7212 {
7213 errmsg = illegal_char(errbuf, *s);
7214 break;
7215 }
7216 }
7217 }
7218
7219 /*
7220 * If error detected, restore the previous value.
7221 */
7222 if (errmsg != NULL)
7223 {
7224 if (new_value_alloced)
7225 free_string_option(*varp);
7226 *varp = oldval;
7227 /*
7228 * When resetting some values, need to act on it.
7229 */
7230 if (did_chartab)
7231 (void)init_chartab();
7232 if (varp == &p_hl)
7233 (void)highlight_changed();
7234 }
7235 else
7236 {
7237#ifdef FEAT_EVAL
7238 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007239 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007240#endif
7241 /*
7242 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007243 * Use "free_oldval", because recursiveness may change the flags under
7244 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007245 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007246 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247 free_string_option(oldval);
7248 if (new_value_alloced)
7249 options[opt_idx].flags |= P_ALLOCED;
7250 else
7251 options[opt_idx].flags &= ~P_ALLOCED;
7252
7253 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007254 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255 {
7256 /* global option with local value set to use global value; free
7257 * the local value and make it empty */
7258 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7259 free_string_option(*(char_u **)p);
7260 *(char_u **)p = empty_option;
7261 }
7262
7263 /* May set global value for local option. */
7264 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7265 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007266
7267#ifdef FEAT_AUTOCMD
7268 /*
7269 * Trigger the autocommand only after setting the flags.
7270 */
7271# ifdef FEAT_SYN_HL
7272 /* When 'syntax' is set, load the syntax of that name */
7273 if (varp == &(curbuf->b_p_syn))
7274 {
7275 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7276 curbuf->b_fname, TRUE, curbuf);
7277 }
7278# endif
7279 else if (varp == &(curbuf->b_p_ft))
7280 {
7281 /* 'filetype' is set, trigger the FileType autocommand */
7282 did_filetype = TRUE;
7283 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7284 curbuf->b_fname, TRUE, curbuf);
7285 }
7286#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007287#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007288 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007289 {
7290 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007291 char_u *q = curwin->w_s->b_p_spl;
7292
7293 /* Skip the first name if it is "cjk". */
7294 if (STRNCMP(q, "cjk,", 4) == 0)
7295 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007296
7297 /*
7298 * Source the spell/LANG.vim in 'runtimepath'.
7299 * They could set 'spellcapcheck' depending on the language.
7300 * Use the first name in 'spelllang' up to '_region' or
7301 * '.encoding'.
7302 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007303 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007304 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7305 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007306 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007307 source_runtime(fname, TRUE);
7308 }
7309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310 }
7311
7312#ifdef FEAT_MOUSE
7313 if (varp == &p_mouse)
7314 {
7315# ifdef FEAT_MOUSE_TTY
7316 if (*p_mouse == NUL)
7317 mch_setmouse(FALSE); /* switch mouse off */
7318 else
7319# endif
7320 setmouse(); /* in case 'mouse' changed */
7321 }
7322#endif
7323
Bram Moolenaar913077c2012-03-28 19:59:04 +02007324 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007325 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007326 curwin->w_set_curswant = TRUE;
7327
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007328#ifdef FEAT_GUI
7329 /* check redraw when it's not a GUI option or the GUI is active. */
7330 if (!redraw_gui_only || gui.in_use)
7331#endif
7332 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007333
7334 return errmsg;
7335}
7336
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007337#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007338/*
7339 * Simple int comparison function for use with qsort()
7340 */
7341 static int
7342int_cmp(a, b)
7343 const void *a;
7344 const void *b;
7345{
7346 return *(const int *)a - *(const int *)b;
7347}
7348
7349/*
7350 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7351 * Returns error message, NULL if it's OK.
7352 */
7353 char_u *
7354check_colorcolumn(wp)
7355 win_T *wp;
7356{
7357 char_u *s;
7358 int col;
7359 int count = 0;
7360 int color_cols[256];
7361 int i;
7362 int j = 0;
7363
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007364 if (wp->w_buffer == NULL)
7365 return NULL; /* buffer was closed */
7366
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007367 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007368 {
7369 if (*s == '-' || *s == '+')
7370 {
7371 /* -N and +N: add to 'textwidth' */
7372 col = (*s == '-') ? -1 : 1;
7373 ++s;
7374 if (!VIM_ISDIGIT(*s))
7375 return e_invarg;
7376 col = col * getdigits(&s);
7377 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007378 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007379 col += wp->w_buffer->b_p_tw;
7380 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007381 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007382 }
7383 else if (VIM_ISDIGIT(*s))
7384 col = getdigits(&s);
7385 else
7386 return e_invarg;
7387 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007388skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007389 if (*s == NUL)
7390 break;
7391 if (*s != ',')
7392 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007393 if (*++s == NUL)
7394 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007395 }
7396
7397 vim_free(wp->w_p_cc_cols);
7398 if (count == 0)
7399 wp->w_p_cc_cols = NULL;
7400 else
7401 {
7402 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7403 if (wp->w_p_cc_cols != NULL)
7404 {
7405 /* sort the columns for faster usage on screen redraw inside
7406 * win_line() */
7407 qsort(color_cols, count, sizeof(int), int_cmp);
7408
7409 for (i = 0; i < count; ++i)
7410 /* skip duplicates */
7411 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7412 wp->w_p_cc_cols[j++] = color_cols[i];
7413 wp->w_p_cc_cols[j] = -1; /* end marker */
7414 }
7415 }
7416
7417 return NULL; /* no error */
7418}
7419#endif
7420
Bram Moolenaar071d4272004-06-13 20:20:40 +00007421/*
7422 * Handle setting 'listchars' or 'fillchars'.
7423 * Returns error message, NULL if it's OK.
7424 */
7425 static char_u *
7426set_chars_option(varp)
7427 char_u **varp;
7428{
7429 int round, i, len, entries;
7430 char_u *p, *s;
7431 int c1, c2 = 0;
7432 struct charstab
7433 {
7434 int *cp;
7435 char *name;
7436 };
7437#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7438 static struct charstab filltab[] =
7439 {
7440 {&fill_stl, "stl"},
7441 {&fill_stlnc, "stlnc"},
7442 {&fill_vert, "vert"},
7443 {&fill_fold, "fold"},
7444 {&fill_diff, "diff"},
7445 };
7446#endif
7447 static struct charstab lcstab[] =
7448 {
7449 {&lcs_eol, "eol"},
7450 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007451 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007452 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007453 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007454 {&lcs_tab2, "tab"},
7455 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007456#ifdef FEAT_CONCEAL
7457 {&lcs_conceal, "conceal"},
7458#else
7459 {NULL, "conceal"},
7460#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007461 };
7462 struct charstab *tab;
7463
7464#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7465 if (varp == &p_lcs)
7466#endif
7467 {
7468 tab = lcstab;
7469 entries = sizeof(lcstab) / sizeof(struct charstab);
7470 }
7471#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7472 else
7473 {
7474 tab = filltab;
7475 entries = sizeof(filltab) / sizeof(struct charstab);
7476 }
7477#endif
7478
7479 /* first round: check for valid value, second round: assign values */
7480 for (round = 0; round <= 1; ++round)
7481 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007482 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007483 {
7484 /* After checking that the value is valid: set defaults: space for
7485 * 'fillchars', NUL for 'listchars' */
7486 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007487 if (tab[i].cp != NULL)
7488 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 if (varp == &p_lcs)
7490 lcs_tab1 = NUL;
7491#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7492 else
7493 fill_diff = '-';
7494#endif
7495 }
7496 p = *varp;
7497 while (*p)
7498 {
7499 for (i = 0; i < entries; ++i)
7500 {
7501 len = (int)STRLEN(tab[i].name);
7502 if (STRNCMP(p, tab[i].name, len) == 0
7503 && p[len] == ':'
7504 && p[len + 1] != NUL)
7505 {
7506 s = p + len + 1;
7507#ifdef FEAT_MBYTE
7508 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007509 if (mb_char2cells(c1) > 1)
7510 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007511#else
7512 c1 = *s++;
7513#endif
7514 if (tab[i].cp == &lcs_tab2)
7515 {
7516 if (*s == NUL)
7517 continue;
7518#ifdef FEAT_MBYTE
7519 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007520 if (mb_char2cells(c2) > 1)
7521 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007522#else
7523 c2 = *s++;
7524#endif
7525 }
7526 if (*s == ',' || *s == NUL)
7527 {
7528 if (round)
7529 {
7530 if (tab[i].cp == &lcs_tab2)
7531 {
7532 lcs_tab1 = c1;
7533 lcs_tab2 = c2;
7534 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007535 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007536 *(tab[i].cp) = c1;
7537
7538 }
7539 p = s;
7540 break;
7541 }
7542 }
7543 }
7544
7545 if (i == entries)
7546 return e_invarg;
7547 if (*p == ',')
7548 ++p;
7549 }
7550 }
7551
7552 return NULL; /* no error */
7553}
7554
7555#ifdef FEAT_STL_OPT
7556/*
7557 * Check validity of options with the 'statusline' format.
7558 * Return error message or NULL.
7559 */
7560 char_u *
7561check_stl_option(s)
7562 char_u *s;
7563{
7564 int itemcnt = 0;
7565 int groupdepth = 0;
7566 static char_u errbuf[80];
7567
7568 while (*s && itemcnt < STL_MAX_ITEM)
7569 {
7570 /* Check for valid keys after % sequences */
7571 while (*s && *s != '%')
7572 s++;
7573 if (!*s)
7574 break;
7575 s++;
7576 if (*s != '%' && *s != ')')
7577 ++itemcnt;
7578 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7579 {
7580 s++;
7581 continue;
7582 }
7583 if (*s == ')')
7584 {
7585 s++;
7586 if (--groupdepth < 0)
7587 break;
7588 continue;
7589 }
7590 if (*s == '-')
7591 s++;
7592 while (VIM_ISDIGIT(*s))
7593 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007594 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007595 continue;
7596 if (*s == '.')
7597 {
7598 s++;
7599 while (*s && VIM_ISDIGIT(*s))
7600 s++;
7601 }
7602 if (*s == '(')
7603 {
7604 groupdepth++;
7605 continue;
7606 }
7607 if (vim_strchr(STL_ALL, *s) == NULL)
7608 {
7609 return illegal_char(errbuf, *s);
7610 }
7611 if (*s == '{')
7612 {
7613 s++;
7614 while (*s != '}' && *s)
7615 s++;
7616 if (*s != '}')
7617 return (char_u *)N_("E540: Unclosed expression sequence");
7618 }
7619 }
7620 if (itemcnt >= STL_MAX_ITEM)
7621 return (char_u *)N_("E541: too many items");
7622 if (groupdepth != 0)
7623 return (char_u *)N_("E542: unbalanced groups");
7624 return NULL;
7625}
7626#endif
7627
7628#ifdef FEAT_CLIPBOARD
7629/*
7630 * Extract the items in the 'clipboard' option and set global values.
7631 */
7632 static char_u *
7633check_clipboard_option()
7634{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007635 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007636 int new_autoselect_star = FALSE;
7637 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007638 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007639 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007640 regprog_T *new_exclude_prog = NULL;
7641 char_u *errmsg = NULL;
7642 char_u *p;
7643
7644 for (p = p_cb; *p != NUL; )
7645 {
7646 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7647 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007648 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007649 p += 7;
7650 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007651 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007652 && (p[11] == ',' || p[11] == NUL))
7653 {
7654 new_unnamed |= CLIP_UNNAMED_PLUS;
7655 p += 11;
7656 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007657 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007658 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007660 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 p += 10;
7662 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007663 else if (STRNCMP(p, "autoselectplus", 14) == 0
7664 && (p[14] == ',' || p[14] == NUL))
7665 {
7666 new_autoselect_plus = TRUE;
7667 p += 14;
7668 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007669 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007670 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007671 {
7672 new_autoselectml = TRUE;
7673 p += 12;
7674 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007675 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7676 {
7677 new_html = TRUE;
7678 p += 4;
7679 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007680 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7681 {
7682 p += 8;
7683 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7684 if (new_exclude_prog == NULL)
7685 errmsg = e_invarg;
7686 break;
7687 }
7688 else
7689 {
7690 errmsg = e_invarg;
7691 break;
7692 }
7693 if (*p == ',')
7694 ++p;
7695 }
7696 if (errmsg == NULL)
7697 {
7698 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007699 clip_autoselect_star = new_autoselect_star;
7700 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007701 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007702 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007703 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007705#ifdef FEAT_GUI_GTK
7706 if (gui.in_use)
7707 {
7708 gui_gtk_set_selection_targets();
7709 gui_gtk_set_dnd_targets();
7710 }
7711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 }
7713 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007714 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715
7716 return errmsg;
7717}
7718#endif
7719
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007720#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007721 static char_u *
7722did_set_spell_option(is_spellfile)
7723 int is_spellfile;
7724{
7725 char_u *errmsg = NULL;
7726 win_T *wp;
7727 int l;
7728
7729 if (is_spellfile)
7730 {
7731 l = (int)STRLEN(curwin->w_s->b_p_spf);
7732 if (l > 0 && (l < 4
7733 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7734 errmsg = e_invarg;
7735 }
7736
7737 if (errmsg == NULL)
7738 {
7739 FOR_ALL_WINDOWS(wp)
7740 if (wp->w_buffer == curbuf && wp->w_p_spell)
7741 {
7742 errmsg = did_set_spelllang(wp);
7743# ifdef FEAT_WINDOWS
7744 break;
7745# endif
7746 }
7747 }
7748 return errmsg;
7749}
7750
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007751/*
7752 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7753 * Return error message when failed, NULL when OK.
7754 */
7755 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007756compile_cap_prog(synblock)
7757 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007758{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007759 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007760 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007761
Bram Moolenaar860cae12010-06-05 23:22:07 +02007762 if (*synblock->b_p_spc == NUL)
7763 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007764 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007765 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007766 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007767 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007768 if (re != NULL)
7769 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007770 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007771 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007772 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007773 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007774 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007775 return e_invarg;
7776 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007777 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007778 }
7779
Bram Moolenaar473de612013-06-08 18:19:48 +02007780 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007781 return NULL;
7782}
7783#endif
7784
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007785#if defined(FEAT_EVAL) || defined(PROTO)
7786/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007787 * Set the scriptID for an option, taking care of setting the buffer- or
7788 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007789 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007790 static void
7791set_option_scriptID_idx(opt_idx, opt_flags, id)
7792 int opt_idx;
7793 int opt_flags;
7794 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007795{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007796 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7797 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007798
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007799 /* Remember where the option was set. For local options need to do that
7800 * in the buffer or window structure. */
7801 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007802 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007803 if (both || (opt_flags & OPT_LOCAL))
7804 {
7805 if (indir & PV_BUF)
7806 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7807 else if (indir & PV_WIN)
7808 curwin->w_p_scriptID[indir & PV_MASK] = id;
7809 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007810}
7811#endif
7812
Bram Moolenaar071d4272004-06-13 20:20:40 +00007813/*
7814 * Set the value of a boolean option, and take care of side effects.
7815 * Returns NULL for success, or an error message for an error.
7816 */
7817 static char_u *
7818set_bool_option(opt_idx, varp, value, opt_flags)
7819 int opt_idx; /* index in options[] table */
7820 char_u *varp; /* pointer to the option variable */
7821 int value; /* new value */
7822 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7823{
7824 int old_value = *(int *)varp;
7825
Bram Moolenaar071d4272004-06-13 20:20:40 +00007826 /* Disallow changing some options from secure mode */
7827 if ((secure
7828#ifdef HAVE_SANDBOX
7829 || sandbox != 0
7830#endif
7831 ) && (options[opt_idx].flags & P_SECURE))
7832 return e_secure;
7833
7834 *(int *)varp = value; /* set the new value */
7835#ifdef FEAT_EVAL
7836 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007837 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007838#endif
7839
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007840#ifdef FEAT_GUI
7841 need_mouse_correct = TRUE;
7842#endif
7843
Bram Moolenaar071d4272004-06-13 20:20:40 +00007844 /* May set global value for local option. */
7845 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7846 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7847
7848 /*
7849 * Handle side effects of changing a bool option.
7850 */
7851
7852 /* 'compatible' */
7853 if ((int *)varp == &p_cp)
7854 {
7855 compatible_set();
7856 }
7857
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007858#ifdef FEAT_PERSISTENT_UNDO
7859 /* 'undofile' */
7860 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7861 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007862 /* Only take action when the option was set. When reset we do not
7863 * delete the undo file, the option may be set again without making
7864 * any changes in between. */
7865 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007866 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007867 char_u hash[UNDO_HASH_SIZE];
7868 buf_T *save_curbuf = curbuf;
7869
7870 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007871 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007872 /* When 'undofile' is set globally: for every buffer, otherwise
7873 * only for the current buffer: Try to read in the undofile,
7874 * if one exists, the buffer wasn't changed and the buffer was
7875 * loaded */
7876 if ((curbuf == save_curbuf
7877 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7878 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7879 {
7880 u_compute_hash(hash);
7881 u_read_undo(NULL, hash, curbuf->b_fname);
7882 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007883 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007884 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007885 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007886 }
7887#endif
7888
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889 else if ((int *)varp == &curbuf->b_p_ro)
7890 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007891 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7893 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007894
7895 /* when 'readonly' is set may give W10 again */
7896 if (curbuf->b_p_ro)
7897 curbuf->b_did_warn = FALSE;
7898
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007900 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901#endif
7902 }
7903
Bram Moolenaar9c449722010-07-20 18:44:27 +02007904#ifdef FEAT_GUI
7905 else if ((int *)varp == &p_mh)
7906 {
7907 if (!p_mh)
7908 gui_mch_mousehide(FALSE);
7909 }
7910#endif
7911
Bram Moolenaara539df02010-08-01 14:35:05 +02007912#ifdef FEAT_TITLE
7913 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007915 {
7916 redraw_titles();
7917 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 /* when 'endofline' is changed, redraw the window title */
7919 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007920 {
7921 redraw_titles();
7922 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007923 /* when 'fixeol' is changed, redraw the window title */
7924 else if ((int *)varp == &curbuf->b_p_fixeol)
7925 {
7926 redraw_titles();
7927 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007928# ifdef FEAT_MBYTE
7929 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007930 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007931 {
7932 redraw_titles();
7933 }
7934# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935#endif
7936
7937 /* when 'bin' is set also set some other options */
7938 else if ((int *)varp == &curbuf->b_p_bin)
7939 {
7940 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7941#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007942 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943#endif
7944 }
7945
7946#ifdef FEAT_AUTOCMD
7947 /* when 'buflisted' changes, trigger autocommands */
7948 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7949 {
7950 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7951 NULL, NULL, TRUE, curbuf);
7952 }
7953#endif
7954
7955 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7956 else if ((int *)varp == &curbuf->b_p_swf)
7957 {
7958 if (curbuf->b_p_swf && p_uc)
7959 ml_open_file(curbuf); /* create the swap file */
7960 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007961 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7962 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 mf_close_file(curbuf, TRUE); /* remove the swap file */
7964 }
7965
7966 /* when 'terse' is set change 'shortmess' */
7967 else if ((int *)varp == &p_terse)
7968 {
7969 char_u *p;
7970
7971 p = vim_strchr(p_shm, SHM_SEARCH);
7972
7973 /* insert 's' in p_shm */
7974 if (p_terse && p == NULL)
7975 {
7976 STRCPY(IObuff, p_shm);
7977 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007978 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007979 }
7980 /* remove 's' from p_shm */
7981 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007982 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 }
7984
7985 /* when 'paste' is set or reset also change other options */
7986 else if ((int *)varp == &p_paste)
7987 {
7988 paste_option_changed();
7989 }
7990
7991 /* when 'insertmode' is set from an autocommand need to do work here */
7992 else if ((int *)varp == &p_im)
7993 {
7994 if (p_im)
7995 {
7996 if ((State & INSERT) == 0)
7997 need_start_insertmode = TRUE;
7998 stop_insert_mode = FALSE;
7999 }
8000 else
8001 {
8002 need_start_insertmode = FALSE;
8003 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008004 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008005 clear_cmdline = TRUE; /* remove "(insert)" */
8006 restart_edit = 0;
8007 }
8008 }
8009
8010 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8011 else if ((int *)varp == &p_ic && p_hls)
8012 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008013 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014 }
8015
8016#ifdef FEAT_SEARCH_EXTRA
8017 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8018 else if ((int *)varp == &p_hls)
8019 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008020 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 }
8022#endif
8023
8024#ifdef FEAT_SCROLLBIND
8025 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8026 * at the end of normal_cmd() */
8027 else if ((int *)varp == &curwin->w_p_scb)
8028 {
8029 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008030 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008031 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008032 curwin->w_scbind_pos = curwin->w_topline;
8033 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034 }
8035#endif
8036
8037#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8038 /* There can be only one window with 'previewwindow' set. */
8039 else if ((int *)varp == &curwin->w_p_pvw)
8040 {
8041 if (curwin->w_p_pvw)
8042 {
8043 win_T *win;
8044
8045 for (win = firstwin; win != NULL; win = win->w_next)
8046 if (win->w_p_pvw && win != curwin)
8047 {
8048 curwin->w_p_pvw = FALSE;
8049 return (char_u *)N_("E590: A preview window already exists");
8050 }
8051 }
8052 }
8053#endif
8054
8055 /* when 'textmode' is set or reset also change 'fileformat' */
8056 else if ((int *)varp == &curbuf->b_p_tx)
8057 {
8058 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8059 }
8060
8061 /* when 'textauto' is set or reset also change 'fileformats' */
8062 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008063 set_string_option_direct((char_u *)"ffs", -1,
8064 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008065 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066
8067 /*
8068 * When 'lisp' option changes include/exclude '-' in
8069 * keyword characters.
8070 */
8071#ifdef FEAT_LISP
8072 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8073 {
8074 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8075 }
8076#endif
8077
8078#ifdef FEAT_TITLE
8079 /* when 'title' changed, may need to change the title; same for 'icon' */
8080 else if ((int *)varp == &p_title)
8081 {
8082 did_set_title(FALSE);
8083 }
8084
8085 else if ((int *)varp == &p_icon)
8086 {
8087 did_set_title(TRUE);
8088 }
8089#endif
8090
8091 else if ((int *)varp == &curbuf->b_changed)
8092 {
8093 if (!value)
8094 save_file_ff(curbuf); /* Buffer is unchanged */
8095#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008096 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008097#endif
8098#ifdef FEAT_AUTOCMD
8099 modified_was_set = value;
8100#endif
8101 }
8102
8103#ifdef BACKSLASH_IN_FILENAME
8104 else if ((int *)varp == &p_ssl)
8105 {
8106 if (p_ssl)
8107 {
8108 psepc = '/';
8109 psepcN = '\\';
8110 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008111 }
8112 else
8113 {
8114 psepc = '\\';
8115 psepcN = '/';
8116 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 }
8118
8119 /* need to adjust the file name arguments and buffer names. */
8120 buflist_slash_adjust();
8121 alist_slash_adjust();
8122# ifdef FEAT_EVAL
8123 scriptnames_slash_adjust();
8124# endif
8125 }
8126#endif
8127
8128 /* If 'wrap' is set, set w_leftcol to zero. */
8129 else if ((int *)varp == &curwin->w_p_wrap)
8130 {
8131 if (curwin->w_p_wrap)
8132 curwin->w_leftcol = 0;
8133 }
8134
8135#ifdef FEAT_WINDOWS
8136 else if ((int *)varp == &p_ea)
8137 {
8138 if (p_ea && !old_value)
8139 win_equal(curwin, FALSE, 0);
8140 }
8141#endif
8142
8143 else if ((int *)varp == &p_wiv)
8144 {
8145 /*
8146 * When 'weirdinvert' changed, set/reset 't_xs'.
8147 * Then set 'weirdinvert' according to value of 't_xs'.
8148 */
8149 if (p_wiv && !old_value)
8150 T_XS = (char_u *)"y";
8151 else if (!p_wiv && old_value)
8152 T_XS = empty_option;
8153 p_wiv = (*T_XS != NUL);
8154 }
8155
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008156#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 else if ((int *)varp == &p_beval)
8158 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008159 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008161 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008162 gui_mch_disable_beval_area(balloonEval);
8163 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008164#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008166#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 else if ((int *)varp == &p_acd)
8168 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008169 /* Change directories when the 'acd' option is set now. */
8170 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 }
8172#endif
8173
8174#ifdef FEAT_DIFF
8175 /* 'diff' */
8176 else if ((int *)varp == &curwin->w_p_diff)
8177 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008178 /* May add or remove the buffer from the list of diff buffers. */
8179 diff_buf_adjust(curwin);
8180# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181 if (foldmethodIsDiff(curwin))
8182 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008183# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184 }
8185#endif
8186
8187#ifdef USE_IM_CONTROL
8188 /* 'imdisable' */
8189 else if ((int *)varp == &p_imdisable)
8190 {
8191 /* Only de-activate it here, it will be enabled when changing mode. */
8192 if (p_imdisable)
8193 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008194 else if (State & INSERT)
8195 /* When the option is set from an autocommand, it may need to take
8196 * effect right away. */
8197 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198 }
8199#endif
8200
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008201#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008202 /* 'spell' */
8203 else if ((int *)varp == &curwin->w_p_spell)
8204 {
8205 if (curwin->w_p_spell)
8206 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008207 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008208 if (errmsg != NULL)
8209 EMSG(_(errmsg));
8210 }
8211 }
8212#endif
8213
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214#ifdef FEAT_FKMAP
8215 else if ((int *)varp == &p_altkeymap)
8216 {
8217 if (old_value != p_altkeymap)
8218 {
8219 if (!p_altkeymap)
8220 {
8221 p_hkmap = p_fkmap;
8222 p_fkmap = 0;
8223 }
8224 else
8225 {
8226 p_fkmap = p_hkmap;
8227 p_hkmap = 0;
8228 }
8229 (void)init_chartab();
8230 }
8231 }
8232
8233 /*
8234 * In case some second language keymapping options have changed, check
8235 * and correct the setting in a consistent way.
8236 */
8237
8238 /*
8239 * If hkmap or fkmap are set, reset Arabic keymapping.
8240 */
8241 if ((p_hkmap || p_fkmap) && p_altkeymap)
8242 {
8243 p_altkeymap = p_fkmap;
8244# ifdef FEAT_ARABIC
8245 curwin->w_p_arab = FALSE;
8246# endif
8247 (void)init_chartab();
8248 }
8249
8250 /*
8251 * If hkmap set, reset Farsi keymapping.
8252 */
8253 if (p_hkmap && p_altkeymap)
8254 {
8255 p_altkeymap = 0;
8256 p_fkmap = 0;
8257# ifdef FEAT_ARABIC
8258 curwin->w_p_arab = FALSE;
8259# endif
8260 (void)init_chartab();
8261 }
8262
8263 /*
8264 * If fkmap set, reset Hebrew keymapping.
8265 */
8266 if (p_fkmap && !p_altkeymap)
8267 {
8268 p_altkeymap = 1;
8269 p_hkmap = 0;
8270# ifdef FEAT_ARABIC
8271 curwin->w_p_arab = FALSE;
8272# endif
8273 (void)init_chartab();
8274 }
8275#endif
8276
8277#ifdef FEAT_ARABIC
8278 if ((int *)varp == &curwin->w_p_arab)
8279 {
8280 if (curwin->w_p_arab)
8281 {
8282 /*
8283 * 'arabic' is set, handle various sub-settings.
8284 */
8285 if (!p_tbidi)
8286 {
8287 /* set rightleft mode */
8288 if (!curwin->w_p_rl)
8289 {
8290 curwin->w_p_rl = TRUE;
8291 changed_window_setting();
8292 }
8293
8294 /* Enable Arabic shaping (major part of what Arabic requires) */
8295 if (!p_arshape)
8296 {
8297 p_arshape = TRUE;
8298 redraw_later_clear();
8299 }
8300 }
8301
8302 /* Arabic requires a utf-8 encoding, inform the user if its not
8303 * set. */
8304 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008305 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008306 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8307
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008308 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008309 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8310#ifdef FEAT_EVAL
8311 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8312#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008313 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314
8315# ifdef FEAT_MBYTE
8316 /* set 'delcombine' */
8317 p_deco = TRUE;
8318# endif
8319
8320# ifdef FEAT_KEYMAP
8321 /* Force-set the necessary keymap for arabic */
8322 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8323 OPT_LOCAL);
8324# endif
8325# ifdef FEAT_FKMAP
8326 p_altkeymap = 0;
8327 p_hkmap = 0;
8328 p_fkmap = 0;
8329 (void)init_chartab();
8330# endif
8331 }
8332 else
8333 {
8334 /*
8335 * 'arabic' is reset, handle various sub-settings.
8336 */
8337 if (!p_tbidi)
8338 {
8339 /* reset rightleft mode */
8340 if (curwin->w_p_rl)
8341 {
8342 curwin->w_p_rl = FALSE;
8343 changed_window_setting();
8344 }
8345
8346 /* 'arabicshape' isn't reset, it is a global option and
8347 * another window may still need it "on". */
8348 }
8349
8350 /* 'delcombine' isn't reset, it is a global option and another
8351 * window may still want it "on". */
8352
8353# ifdef FEAT_KEYMAP
8354 /* Revert to the default keymap */
8355 curbuf->b_p_iminsert = B_IMODE_NONE;
8356 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8357# endif
8358 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008359 }
8360
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008361#endif
8362
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363 /*
8364 * End of handling side effects for bool options.
8365 */
8366
Bram Moolenaar53744302015-07-17 17:38:22 +02008367 /* after handling side effects, call autocommand */
8368
Bram Moolenaar071d4272004-06-13 20:20:40 +00008369 options[opt_idx].flags |= P_WAS_SET;
8370
Bram Moolenaar53744302015-07-17 17:38:22 +02008371#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8372 if (!starting)
8373 {
8374 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008375 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8376 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8377 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008378 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8379 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8380 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8381 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8382 reset_v_option_vars();
8383 }
8384#endif
8385
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008387 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008388 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008389 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008390 check_redraw(options[opt_idx].flags);
8391
8392 return NULL;
8393}
8394
8395/*
8396 * Set the value of a number option, and take care of side effects.
8397 * Returns NULL for success, or an error message for an error.
8398 */
8399 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008400set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401 int opt_idx; /* index in options[] table */
8402 char_u *varp; /* pointer to the option variable */
8403 long value; /* new value */
8404 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008405 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8407 OPT_MODELINE */
8408{
8409 char_u *errmsg = NULL;
8410 long old_value = *(long *)varp;
8411 long old_Rows = Rows; /* remember old Rows */
8412 long old_Columns = Columns; /* remember old Columns */
8413 long *pp = (long *)varp;
8414
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008415 /* Disallow changing some options from secure mode. */
8416 if ((secure
8417#ifdef HAVE_SANDBOX
8418 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008419#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008420 ) && (options[opt_idx].flags & P_SECURE))
8421 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008422
8423 *pp = value;
8424#ifdef FEAT_EVAL
8425 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008426 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008427#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008428#ifdef FEAT_GUI
8429 need_mouse_correct = TRUE;
8430#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431
Bram Moolenaar14f24742012-08-08 18:01:05 +02008432 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433 {
8434 errmsg = e_positive;
8435 curbuf->b_p_sw = curbuf->b_p_ts;
8436 }
8437
8438 /*
8439 * Number options that need some action when changed
8440 */
8441#ifdef FEAT_WINDOWS
8442 if (pp == &p_wh || pp == &p_hh)
8443 {
8444 if (p_wh < 1)
8445 {
8446 errmsg = e_positive;
8447 p_wh = 1;
8448 }
8449 if (p_wmh > p_wh)
8450 {
8451 errmsg = e_winheight;
8452 p_wh = p_wmh;
8453 }
8454 if (p_hh < 0)
8455 {
8456 errmsg = e_positive;
8457 p_hh = 0;
8458 }
8459
8460 /* Change window height NOW */
8461 if (lastwin != firstwin)
8462 {
8463 if (pp == &p_wh && curwin->w_height < p_wh)
8464 win_setheight((int)p_wh);
8465 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8466 win_setheight((int)p_hh);
8467 }
8468 }
8469
8470 /* 'winminheight' */
8471 else if (pp == &p_wmh)
8472 {
8473 if (p_wmh < 0)
8474 {
8475 errmsg = e_positive;
8476 p_wmh = 0;
8477 }
8478 if (p_wmh > p_wh)
8479 {
8480 errmsg = e_winheight;
8481 p_wmh = p_wh;
8482 }
8483 win_setminheight();
8484 }
8485
8486# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008487 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008488 {
8489 if (p_wiw < 1)
8490 {
8491 errmsg = e_positive;
8492 p_wiw = 1;
8493 }
8494 if (p_wmw > p_wiw)
8495 {
8496 errmsg = e_winwidth;
8497 p_wiw = p_wmw;
8498 }
8499
8500 /* Change window width NOW */
8501 if (lastwin != firstwin && curwin->w_width < p_wiw)
8502 win_setwidth((int)p_wiw);
8503 }
8504
8505 /* 'winminwidth' */
8506 else if (pp == &p_wmw)
8507 {
8508 if (p_wmw < 0)
8509 {
8510 errmsg = e_positive;
8511 p_wmw = 0;
8512 }
8513 if (p_wmw > p_wiw)
8514 {
8515 errmsg = e_winwidth;
8516 p_wmw = p_wiw;
8517 }
8518 win_setminheight();
8519 }
8520# endif
8521
8522#endif
8523
8524#ifdef FEAT_WINDOWS
8525 /* (re)set last window status line */
8526 else if (pp == &p_ls)
8527 {
8528 last_status(FALSE);
8529 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008530
8531 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008532 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008533 {
8534 shell_new_rows(); /* recompute window positions and heights */
8535 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536#endif
8537
8538#ifdef FEAT_GUI
8539 else if (pp == &p_linespace)
8540 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008541 /* Recompute gui.char_height and resize the Vim window to keep the
8542 * same number of lines. */
8543 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008544 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 }
8546#endif
8547
8548#ifdef FEAT_FOLDING
8549 /* 'foldlevel' */
8550 else if (pp == &curwin->w_p_fdl)
8551 {
8552 if (curwin->w_p_fdl < 0)
8553 curwin->w_p_fdl = 0;
8554 newFoldLevel();
8555 }
8556
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008557 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008558 else if (pp == &curwin->w_p_fml)
8559 {
8560 foldUpdateAll(curwin);
8561 }
8562
8563 /* 'foldnestmax' */
8564 else if (pp == &curwin->w_p_fdn)
8565 {
8566 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8567 foldUpdateAll(curwin);
8568 }
8569
8570 /* 'foldcolumn' */
8571 else if (pp == &curwin->w_p_fdc)
8572 {
8573 if (curwin->w_p_fdc < 0)
8574 {
8575 errmsg = e_positive;
8576 curwin->w_p_fdc = 0;
8577 }
8578 else if (curwin->w_p_fdc > 12)
8579 {
8580 errmsg = e_invarg;
8581 curwin->w_p_fdc = 12;
8582 }
8583 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008584#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008585
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008586#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587 /* 'shiftwidth' or 'tabstop' */
8588 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8589 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008590# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 if (foldmethodIsIndent(curwin))
8592 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008593# endif
8594# ifdef FEAT_CINDENT
8595 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8596 * parse 'cinoptions'. */
8597 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8598 parse_cino(curbuf);
8599# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008600 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008601#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008602
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008603#ifdef FEAT_MBYTE
8604 /* 'maxcombine' */
8605 else if (pp == &p_mco)
8606 {
8607 if (p_mco > MAX_MCO)
8608 p_mco = MAX_MCO;
8609 else if (p_mco < 0)
8610 p_mco = 0;
8611 screenclear(); /* will re-allocate the screen */
8612 }
8613#endif
8614
Bram Moolenaar071d4272004-06-13 20:20:40 +00008615 else if (pp == &curbuf->b_p_iminsert)
8616 {
8617 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8618 {
8619 errmsg = e_invarg;
8620 curbuf->b_p_iminsert = B_IMODE_NONE;
8621 }
8622 p_iminsert = curbuf->b_p_iminsert;
8623 if (termcap_active) /* don't do this in the alternate screen */
8624 showmode();
8625#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8626 /* Show/unshow value of 'keymap' in status lines. */
8627 status_redraw_curbuf();
8628#endif
8629 }
8630
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008631 else if (pp == &p_window)
8632 {
8633 if (p_window < 1)
8634 p_window = 1;
8635 else if (p_window >= Rows)
8636 p_window = Rows - 1;
8637 }
8638
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639 else if (pp == &curbuf->b_p_imsearch)
8640 {
8641 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8642 {
8643 errmsg = e_invarg;
8644 curbuf->b_p_imsearch = B_IMODE_NONE;
8645 }
8646 p_imsearch = curbuf->b_p_imsearch;
8647 }
8648
8649#ifdef FEAT_TITLE
8650 /* if 'titlelen' has changed, redraw the title */
8651 else if (pp == &p_titlelen)
8652 {
8653 if (p_titlelen < 0)
8654 {
8655 errmsg = e_positive;
8656 p_titlelen = 85;
8657 }
8658 if (starting != NO_SCREEN && old_value != p_titlelen)
8659 need_maketitle = TRUE;
8660 }
8661#endif
8662
8663 /* if p_ch changed value, change the command line height */
8664 else if (pp == &p_ch)
8665 {
8666 if (p_ch < 1)
8667 {
8668 errmsg = e_positive;
8669 p_ch = 1;
8670 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008671 if (p_ch > Rows - min_rows() + 1)
8672 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673
8674 /* Only compute the new window layout when startup has been
8675 * completed. Otherwise the frame sizes may be wrong. */
8676 if (p_ch != old_value && full_screen
8677#ifdef FEAT_GUI
8678 && !gui.starting
8679#endif
8680 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008681 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 }
8683
8684 /* when 'updatecount' changes from zero to non-zero, open swap files */
8685 else if (pp == &p_uc)
8686 {
8687 if (p_uc < 0)
8688 {
8689 errmsg = e_positive;
8690 p_uc = 100;
8691 }
8692 if (p_uc && !old_value)
8693 ml_open_files();
8694 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008695#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008696 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008697 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008698 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008699 {
8700 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008701 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008702 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008703 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008704 {
8705 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008706 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008707 }
8708 }
8709#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008710#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008711 else if (pp == &p_mzq)
8712 mzvim_reset_timer();
8713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714
8715 /* sync undo before 'undolevels' changes */
8716 else if (pp == &p_ul)
8717 {
8718 /* use the old value, otherwise u_sync() may not work properly */
8719 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008720 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721 p_ul = value;
8722 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008723 else if (pp == &curbuf->b_p_ul)
8724 {
8725 /* use the old value, otherwise u_sync() may not work properly */
8726 curbuf->b_p_ul = old_value;
8727 u_sync(TRUE);
8728 curbuf->b_p_ul = value;
8729 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008730
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008731#ifdef FEAT_LINEBREAK
8732 /* 'numberwidth' must be positive */
8733 else if (pp == &curwin->w_p_nuw)
8734 {
8735 if (curwin->w_p_nuw < 1)
8736 {
8737 errmsg = e_positive;
8738 curwin->w_p_nuw = 1;
8739 }
8740 if (curwin->w_p_nuw > 10)
8741 {
8742 errmsg = e_invarg;
8743 curwin->w_p_nuw = 10;
8744 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008745 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008746 }
8747#endif
8748
Bram Moolenaar1a384422010-07-14 19:53:30 +02008749 else if (pp == &curbuf->b_p_tw)
8750 {
8751 if (curbuf->b_p_tw < 0)
8752 {
8753 errmsg = e_positive;
8754 curbuf->b_p_tw = 0;
8755 }
8756#ifdef FEAT_SYN_HL
8757# ifdef FEAT_WINDOWS
8758 {
8759 win_T *wp;
8760 tabpage_T *tp;
8761
8762 FOR_ALL_TAB_WINDOWS(tp, wp)
8763 check_colorcolumn(wp);
8764 }
8765# else
8766 check_colorcolumn(curwin);
8767# endif
8768#endif
8769 }
8770
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771 /*
8772 * Check the bounds for numeric options here
8773 */
8774 if (Rows < min_rows() && full_screen)
8775 {
8776 if (errbuf != NULL)
8777 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008778 vim_snprintf((char *)errbuf, errbuflen,
8779 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 errmsg = errbuf;
8781 }
8782 Rows = min_rows();
8783 }
8784 if (Columns < MIN_COLUMNS && full_screen)
8785 {
8786 if (errbuf != NULL)
8787 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008788 vim_snprintf((char *)errbuf, errbuflen,
8789 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008790 errmsg = errbuf;
8791 }
8792 Columns = MIN_COLUMNS;
8793 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008794 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795
8796#ifdef DJGPP
8797 /* avoid a crash by checking for a too large value of 'columns' */
8798 if (old_Columns != Columns && full_screen && term_console)
8799 mch_check_columns();
8800#endif
8801
8802 /*
8803 * If the screen (shell) height has been changed, assume it is the
8804 * physical screenheight.
8805 */
8806 if (old_Rows != Rows || old_Columns != Columns)
8807 {
8808 /* Changing the screen size is not allowed while updating the screen. */
8809 if (updating_screen)
8810 *pp = old_value;
8811 else if (full_screen
8812#ifdef FEAT_GUI
8813 && !gui.starting
8814#endif
8815 )
8816 set_shellsize((int)Columns, (int)Rows, TRUE);
8817 else
8818 {
8819 /* Postpone the resizing; check the size and cmdline position for
8820 * messages. */
8821 check_shellsize();
8822 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8823 cmdline_row = Rows - p_ch;
8824 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008825 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008826 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827 }
8828
Bram Moolenaar071d4272004-06-13 20:20:40 +00008829 if (curbuf->b_p_ts <= 0)
8830 {
8831 errmsg = e_positive;
8832 curbuf->b_p_ts = 8;
8833 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834 if (p_tm < 0)
8835 {
8836 errmsg = e_positive;
8837 p_tm = 0;
8838 }
8839 if ((curwin->w_p_scr <= 0
8840 || (curwin->w_p_scr > curwin->w_height
8841 && curwin->w_height > 0))
8842 && full_screen)
8843 {
8844 if (pp == &(curwin->w_p_scr))
8845 {
8846 if (curwin->w_p_scr != 0)
8847 errmsg = e_scroll;
8848 win_comp_scroll(curwin);
8849 }
8850 /* If 'scroll' became invalid because of a side effect silently adjust
8851 * it. */
8852 else if (curwin->w_p_scr <= 0)
8853 curwin->w_p_scr = 1;
8854 else /* curwin->w_p_scr > curwin->w_height */
8855 curwin->w_p_scr = curwin->w_height;
8856 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008857 if (p_hi < 0)
8858 {
8859 errmsg = e_positive;
8860 p_hi = 0;
8861 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008862 else if (p_hi > 10000)
8863 {
8864 errmsg = e_invarg;
8865 p_hi = 10000;
8866 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008867 if (p_re < 0 || p_re > 2)
8868 {
8869 errmsg = e_invarg;
8870 p_re = 0;
8871 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872 if (p_report < 0)
8873 {
8874 errmsg = e_positive;
8875 p_report = 1;
8876 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008877 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008878 {
8879 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8880 p_sj = Rows / 2;
8881 else
8882 {
8883 errmsg = e_scroll;
8884 p_sj = 1;
8885 }
8886 }
8887 if (p_so < 0 && full_screen)
8888 {
8889 errmsg = e_scroll;
8890 p_so = 0;
8891 }
8892 if (p_siso < 0 && full_screen)
8893 {
8894 errmsg = e_positive;
8895 p_siso = 0;
8896 }
8897#ifdef FEAT_CMDWIN
8898 if (p_cwh < 1)
8899 {
8900 errmsg = e_positive;
8901 p_cwh = 1;
8902 }
8903#endif
8904 if (p_ut < 0)
8905 {
8906 errmsg = e_positive;
8907 p_ut = 2000;
8908 }
8909 if (p_ss < 0)
8910 {
8911 errmsg = e_positive;
8912 p_ss = 0;
8913 }
8914
8915 /* May set global value for local option. */
8916 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8917 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8918
8919 options[opt_idx].flags |= P_WAS_SET;
8920
Bram Moolenaar53744302015-07-17 17:38:22 +02008921#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8922 if (!starting && errmsg == NULL)
8923 {
8924 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008925 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8926 vim_snprintf((char *)buf_new, 10, "%ld", value);
8927 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008928 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8929 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8930 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8931 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8932 reset_v_option_vars();
8933 }
8934#endif
8935
Bram Moolenaar071d4272004-06-13 20:20:40 +00008936 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008937 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008938 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008939 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940 check_redraw(options[opt_idx].flags);
8941
8942 return errmsg;
8943}
8944
8945/*
8946 * Called after an option changed: check if something needs to be redrawn.
8947 */
8948 static void
8949check_redraw(flags)
8950 long_u flags;
8951{
8952 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008953 int doclear = (flags & P_RCLR) == P_RCLR;
8954 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008955
8956#ifdef FEAT_WINDOWS
8957 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8958 status_redraw_all();
8959#endif
8960
8961 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8962 changed_window_setting();
8963 if (flags & P_RBUF)
8964 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008965 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008966 redraw_all_later(CLEAR);
8967 else if (all)
8968 redraw_all_later(NOT_VALID);
8969}
8970
8971/*
8972 * Find index for option 'arg'.
8973 * Return -1 if not found.
8974 */
8975 static int
8976findoption(arg)
8977 char_u *arg;
8978{
8979 int opt_idx;
8980 char *s, *p;
8981 static short quick_tab[27] = {0, 0}; /* quick access table */
8982 int is_term_opt;
8983
8984 /*
8985 * For first call: Initialize the quick-access table.
8986 * It contains the index for the first option that starts with a certain
8987 * letter. There are 26 letters, plus the first "t_" option.
8988 */
8989 if (quick_tab[1] == 0)
8990 {
8991 p = options[0].fullname;
8992 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8993 {
8994 if (s[0] != p[0])
8995 {
8996 if (s[0] == 't' && s[1] == '_')
8997 quick_tab[26] = opt_idx;
8998 else
8999 quick_tab[CharOrdLow(s[0])] = opt_idx;
9000 }
9001 p = s;
9002 }
9003 }
9004
9005 /*
9006 * Check for name starting with an illegal character.
9007 */
9008#ifdef EBCDIC
9009 if (!islower(arg[0]))
9010#else
9011 if (arg[0] < 'a' || arg[0] > 'z')
9012#endif
9013 return -1;
9014
9015 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9016 if (is_term_opt)
9017 opt_idx = quick_tab[26];
9018 else
9019 opt_idx = quick_tab[CharOrdLow(arg[0])];
9020 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9021 {
9022 if (STRCMP(arg, s) == 0) /* match full name */
9023 break;
9024 }
9025 if (s == NULL && !is_term_opt)
9026 {
9027 opt_idx = quick_tab[CharOrdLow(arg[0])];
9028 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9029 {
9030 s = options[opt_idx].shortname;
9031 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9032 break;
9033 s = NULL;
9034 }
9035 }
9036 if (s == NULL)
9037 opt_idx = -1;
9038 return opt_idx;
9039}
9040
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009041#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009042/*
9043 * Get the value for an option.
9044 *
9045 * Returns:
9046 * Number or Toggle option: 1, *numval gets value.
9047 * String option: 0, *stringval gets allocated string.
9048 * Hidden Number or Toggle option: -1.
9049 * hidden String option: -2.
9050 * unknown option: -3.
9051 */
9052 int
9053get_option_value(name, numval, stringval, opt_flags)
9054 char_u *name;
9055 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009056 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009057 int opt_flags;
9058{
9059 int opt_idx;
9060 char_u *varp;
9061
9062 opt_idx = findoption(name);
9063 if (opt_idx < 0) /* unknown option */
9064 return -3;
9065
9066 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9067
9068 if (options[opt_idx].flags & P_STRING)
9069 {
9070 if (varp == NULL) /* hidden option */
9071 return -2;
9072 if (stringval != NULL)
9073 {
9074#ifdef FEAT_CRYPT
9075 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009076 if ((char_u **)varp == &curbuf->b_p_key
9077 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009078 *stringval = vim_strsave((char_u *)"*****");
9079 else
9080#endif
9081 *stringval = vim_strsave(*(char_u **)(varp));
9082 }
9083 return 0;
9084 }
9085
9086 if (varp == NULL) /* hidden option */
9087 return -1;
9088 if (options[opt_idx].flags & P_NUM)
9089 *numval = *(long *)varp;
9090 else
9091 {
9092 /* Special case: 'modified' is b_changed, but we also want to consider
9093 * it set when 'ff' or 'fenc' changed. */
9094 if ((int *)varp == &curbuf->b_changed)
9095 *numval = curbufIsChanged();
9096 else
9097 *numval = *(int *)varp;
9098 }
9099 return 1;
9100}
9101#endif
9102
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009103#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009104/*
9105 * Returns the option attributes and its value. Unlike the above function it
9106 * will return either global value or local value of the option depending on
9107 * what was requested, but it will never return global value if it was
9108 * requested to return local one and vice versa. Neither it will return
9109 * buffer-local value if it was requested to return window-local one.
9110 *
9111 * Pretends that option is absent if it is not present in the requested scope
9112 * (i.e. has no global, window-local or buffer-local value depending on
9113 * opt_type). Uses
9114 *
9115 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009116 * 0 hidden or unknown option, also option that does not have requested
9117 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009118 * see SOPT_* in vim.h for other flags
9119 *
9120 * Possible opt_type values: see SREQ_* in vim.h
9121 */
9122 int
9123get_option_value_strict(name, numval, stringval, opt_type, from)
9124 char_u *name;
9125 long *numval;
9126 char_u **stringval; /* NULL when only obtaining attributes */
9127 int opt_type;
9128 void *from;
9129{
9130 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009131 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009132 struct vimoption *p;
9133 int r = 0;
9134
9135 opt_idx = findoption(name);
9136 if (opt_idx < 0)
9137 return 0;
9138
9139 p = &(options[opt_idx]);
9140
9141 /* Hidden option */
9142 if (p->var == NULL)
9143 return 0;
9144
9145 if (p->flags & P_BOOL)
9146 r |= SOPT_BOOL;
9147 else if (p->flags & P_NUM)
9148 r |= SOPT_NUM;
9149 else if (p->flags & P_STRING)
9150 r |= SOPT_STRING;
9151
9152 if (p->indir == PV_NONE)
9153 {
9154 if (opt_type == SREQ_GLOBAL)
9155 r |= SOPT_GLOBAL;
9156 else
9157 return 0; /* Did not request global-only option */
9158 }
9159 else
9160 {
9161 if (p->indir & PV_BOTH)
9162 r |= SOPT_GLOBAL;
9163 else if (opt_type == SREQ_GLOBAL)
9164 return 0; /* Requested global option */
9165
9166 if (p->indir & PV_WIN)
9167 {
9168 if (opt_type == SREQ_BUF)
9169 return 0; /* Did not request window-local option */
9170 else
9171 r |= SOPT_WIN;
9172 }
9173 else if (p->indir & PV_BUF)
9174 {
9175 if (opt_type == SREQ_WIN)
9176 return 0; /* Did not request buffer-local option */
9177 else
9178 r |= SOPT_BUF;
9179 }
9180 }
9181
9182 if (stringval == NULL)
9183 return r;
9184
9185 if (opt_type == SREQ_GLOBAL)
9186 varp = p->var;
9187 else
9188 {
9189 if (opt_type == SREQ_BUF)
9190 {
9191 /* Special case: 'modified' is b_changed, but we also want to
9192 * consider it set when 'ff' or 'fenc' changed. */
9193 if (p->indir == PV_MOD)
9194 {
9195 *numval = bufIsChanged((buf_T *) from);
9196 varp = NULL;
9197 }
9198#ifdef FEAT_CRYPT
9199 else if (p->indir == PV_KEY)
9200 {
9201 /* never return the value of the crypt key */
9202 *stringval = NULL;
9203 varp = NULL;
9204 }
9205#endif
9206 else
9207 {
9208 aco_save_T aco;
9209 aucmd_prepbuf(&aco, (buf_T *) from);
9210 varp = get_varp(p);
9211 aucmd_restbuf(&aco);
9212 }
9213 }
9214 else if (opt_type == SREQ_WIN)
9215 {
9216 win_T *save_curwin;
9217 save_curwin = curwin;
9218 curwin = (win_T *) from;
9219 curbuf = curwin->w_buffer;
9220 varp = get_varp(p);
9221 curwin = save_curwin;
9222 curbuf = curwin->w_buffer;
9223 }
9224 if (varp == p->var)
9225 return (r | SOPT_UNSET);
9226 }
9227
9228 if (varp != NULL)
9229 {
9230 if (p->flags & P_STRING)
9231 *stringval = vim_strsave(*(char_u **)(varp));
9232 else if (p->flags & P_NUM)
9233 *numval = *(long *) varp;
9234 else
9235 *numval = *(int *)varp;
9236 }
9237
9238 return r;
9239}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009240
9241/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009242 * Iterate over options. First argument is a pointer to a pointer to a
9243 * structure inside options[] array, second is option type like in the above
9244 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009245 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009246 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009247 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009248 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009249 * first argument to NULL.
9250 *
9251 * Returns full option name for current option on each call.
9252 */
9253 char_u *
9254option_iter_next(option, opt_type)
9255 void **option;
9256 int opt_type;
9257{
9258 struct vimoption *ret = NULL;
9259 do
9260 {
9261 if (*option == NULL)
9262 *option = (void *) options;
9263 else if (((struct vimoption *) (*option))->fullname == NULL)
9264 {
9265 *option = NULL;
9266 return NULL;
9267 }
9268 else
9269 *option = (void *) (((struct vimoption *) (*option)) + 1);
9270
9271 ret = ((struct vimoption *) (*option));
9272
9273 /* Hidden option */
9274 if (ret->var == NULL)
9275 {
9276 ret = NULL;
9277 continue;
9278 }
9279
9280 switch (opt_type)
9281 {
9282 case SREQ_GLOBAL:
9283 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9284 ret = NULL;
9285 break;
9286 case SREQ_BUF:
9287 if (!(ret->indir & PV_BUF))
9288 ret = NULL;
9289 break;
9290 case SREQ_WIN:
9291 if (!(ret->indir & PV_WIN))
9292 ret = NULL;
9293 break;
9294 default:
9295 EMSG2(_(e_intern2), "option_iter_next()");
9296 return NULL;
9297 }
9298 }
9299 while (ret == NULL);
9300
9301 return (char_u *)ret->fullname;
9302}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009303#endif
9304
Bram Moolenaar071d4272004-06-13 20:20:40 +00009305/*
9306 * Set the value of option "name".
9307 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009308 *
9309 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009310 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009311 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312set_option_value(name, number, string, opt_flags)
9313 char_u *name;
9314 long number;
9315 char_u *string;
9316 int opt_flags; /* OPT_LOCAL or 0 (both) */
9317{
9318 int opt_idx;
9319 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009320 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009321
9322 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009323 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009324 EMSG2(_("E355: Unknown option: %s"), name);
9325 else
9326 {
9327 flags = options[opt_idx].flags;
9328#ifdef HAVE_SANDBOX
9329 /* Disallow changing some options in the sandbox */
9330 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009331 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009332 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009333 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009334 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009336 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009337 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338 else
9339 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009340 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341 if (varp != NULL) /* hidden option is not changed */
9342 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009343 if (number == 0 && string != NULL)
9344 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009345 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009346
9347 /* Either we are given a string or we are setting option
9348 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009349 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009350 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009351 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009352 {
9353 /* There's another character after zeros or the string
9354 * is empty. In both cases, we are trying to set a
9355 * num option using a string. */
9356 EMSG3(_("E521: Number required: &%s = '%s'"),
9357 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009358 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009359
9360 }
9361 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009363 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009364 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009366 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009367 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368 }
9369 }
9370 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009371 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009372}
9373
9374/*
9375 * Get the terminal code for a terminal option.
9376 * Returns NULL when not found.
9377 */
9378 char_u *
9379get_term_code(tname)
9380 char_u *tname;
9381{
9382 int opt_idx;
9383 char_u *varp;
9384
9385 if (tname[0] != 't' || tname[1] != '_' ||
9386 tname[2] == NUL || tname[3] == NUL)
9387 return NULL;
9388 if ((opt_idx = findoption(tname)) >= 0)
9389 {
9390 varp = get_varp(&(options[opt_idx]));
9391 if (varp != NULL)
9392 varp = *(char_u **)(varp);
9393 return varp;
9394 }
9395 return find_termcode(tname + 2);
9396}
9397
9398 char_u *
9399get_highlight_default()
9400{
9401 int i;
9402
9403 i = findoption((char_u *)"hl");
9404 if (i >= 0)
9405 return options[i].def_val[VI_DEFAULT];
9406 return (char_u *)NULL;
9407}
9408
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009409#if defined(FEAT_MBYTE) || defined(PROTO)
9410 char_u *
9411get_encoding_default()
9412{
9413 int i;
9414
9415 i = findoption((char_u *)"enc");
9416 if (i >= 0)
9417 return options[i].def_val[VI_DEFAULT];
9418 return (char_u *)NULL;
9419}
9420#endif
9421
Bram Moolenaar071d4272004-06-13 20:20:40 +00009422/*
9423 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9424 */
9425 static int
9426find_key_option(arg)
9427 char_u *arg;
9428{
9429 int key;
9430 int modifiers;
9431
9432 /*
9433 * Don't use get_special_key_code() for t_xx, we don't want it to call
9434 * add_termcap_entry().
9435 */
9436 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9437 key = TERMCAP2KEY(arg[2], arg[3]);
9438 else
9439 {
9440 --arg; /* put arg at the '<' */
9441 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009442 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443 if (modifiers) /* can't handle modifiers here */
9444 key = 0;
9445 }
9446 return key;
9447}
9448
9449/*
9450 * if 'all' == 0: show changed options
9451 * if 'all' == 1: show all normal options
9452 * if 'all' == 2: show all terminal options
9453 */
9454 static void
9455showoptions(all, opt_flags)
9456 int all;
9457 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9458{
9459 struct vimoption *p;
9460 int col;
9461 int isterm;
9462 char_u *varp;
9463 struct vimoption **items;
9464 int item_count;
9465 int run;
9466 int row, rows;
9467 int cols;
9468 int i;
9469 int len;
9470
9471#define INC 20
9472#define GAP 3
9473
9474 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9475 PARAM_COUNT));
9476 if (items == NULL)
9477 return;
9478
9479 /* Highlight title */
9480 if (all == 2)
9481 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9482 else if (opt_flags & OPT_GLOBAL)
9483 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9484 else if (opt_flags & OPT_LOCAL)
9485 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9486 else
9487 MSG_PUTS_TITLE(_("\n--- Options ---"));
9488
9489 /*
9490 * do the loop two times:
9491 * 1. display the short items
9492 * 2. display the long items (only strings and numbers)
9493 */
9494 for (run = 1; run <= 2 && !got_int; ++run)
9495 {
9496 /*
9497 * collect the items in items[]
9498 */
9499 item_count = 0;
9500 for (p = &options[0]; p->fullname != NULL; p++)
9501 {
9502 varp = NULL;
9503 isterm = istermoption(p);
9504 if (opt_flags != 0)
9505 {
9506 if (p->indir != PV_NONE && !isterm)
9507 varp = get_varp_scope(p, opt_flags);
9508 }
9509 else
9510 varp = get_varp(p);
9511 if (varp != NULL
9512 && ((all == 2 && isterm)
9513 || (all == 1 && !isterm)
9514 || (all == 0 && !optval_default(p, varp))))
9515 {
9516 if (p->flags & P_BOOL)
9517 len = 1; /* a toggle option fits always */
9518 else
9519 {
9520 option_value2string(p, opt_flags);
9521 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9522 }
9523 if ((len <= INC - GAP && run == 1) ||
9524 (len > INC - GAP && run == 2))
9525 items[item_count++] = p;
9526 }
9527 }
9528
9529 /*
9530 * display the items
9531 */
9532 if (run == 1)
9533 {
9534 cols = (Columns + GAP - 3) / INC;
9535 if (cols == 0)
9536 cols = 1;
9537 rows = (item_count + cols - 1) / cols;
9538 }
9539 else /* run == 2 */
9540 rows = item_count;
9541 for (row = 0; row < rows && !got_int; ++row)
9542 {
9543 msg_putchar('\n'); /* go to next line */
9544 if (got_int) /* 'q' typed in more */
9545 break;
9546 col = 0;
9547 for (i = row; i < item_count; i += rows)
9548 {
9549 msg_col = col; /* make columns */
9550 showoneopt(items[i], opt_flags);
9551 col += INC;
9552 }
9553 out_flush();
9554 ui_breakcheck();
9555 }
9556 }
9557 vim_free(items);
9558}
9559
9560/*
9561 * Return TRUE if option "p" has its default value.
9562 */
9563 static int
9564optval_default(p, varp)
9565 struct vimoption *p;
9566 char_u *varp;
9567{
9568 int dvi;
9569
9570 if (varp == NULL)
9571 return TRUE; /* hidden option is always at default */
9572 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9573 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009574 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009575 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009576 /* the cast to long is required for Manx C, long_i is
9577 * needed for MSVC */
9578 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009579 /* P_STRING */
9580 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9581}
9582
9583/*
9584 * showoneopt: show the value of one option
9585 * must not be called with a hidden option!
9586 */
9587 static void
9588showoneopt(p, opt_flags)
9589 struct vimoption *p;
9590 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9591{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009592 char_u *varp;
9593 int save_silent = silent_mode;
9594
9595 silent_mode = FALSE;
9596 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009597
9598 varp = get_varp_scope(p, opt_flags);
9599
9600 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9601 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9602 ? !curbufIsChanged() : !*(int *)varp))
9603 MSG_PUTS("no");
9604 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9605 MSG_PUTS("--");
9606 else
9607 MSG_PUTS(" ");
9608 MSG_PUTS(p->fullname);
9609 if (!(p->flags & P_BOOL))
9610 {
9611 msg_putchar('=');
9612 /* put value string in NameBuff */
9613 option_value2string(p, opt_flags);
9614 msg_outtrans(NameBuff);
9615 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009616
9617 silent_mode = save_silent;
9618 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009619}
9620
9621/*
9622 * Write modified options as ":set" commands to a file.
9623 *
9624 * There are three values for "opt_flags":
9625 * OPT_GLOBAL: Write global option values and fresh values of
9626 * buffer-local options (used for start of a session
9627 * file).
9628 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9629 * curwin (used for a vimrc file).
9630 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9631 * and local values for window-local options of
9632 * curwin. Local values are also written when at the
9633 * default value, because a modeline or autocommand
9634 * may have set them when doing ":edit file" and the
9635 * user has set them back at the default or fresh
9636 * value.
9637 * When "local_only" is TRUE, don't write fresh
9638 * values, only local values (for ":mkview").
9639 * (fresh value = value used for a new buffer or window for a local option).
9640 *
9641 * Return FAIL on error, OK otherwise.
9642 */
9643 int
9644makeset(fd, opt_flags, local_only)
9645 FILE *fd;
9646 int opt_flags;
9647 int local_only;
9648{
9649 struct vimoption *p;
9650 char_u *varp; /* currently used value */
9651 char_u *varp_fresh; /* local value */
9652 char_u *varp_local = NULL; /* fresh value */
9653 char *cmd;
9654 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009655 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009656
9657 /*
9658 * The options that don't have a default (terminal name, columns, lines)
9659 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009660 * Do the loop over "options[]" twice: once for options with the
9661 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009662 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009663 for (pri = 1; pri >= 0; --pri)
9664 {
9665 for (p = &options[0]; !istermoption(p); p++)
9666 if (!(p->flags & P_NO_MKRC)
9667 && !istermoption(p)
9668 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669 {
9670 /* skip global option when only doing locals */
9671 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9672 continue;
9673
9674 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9675 * file, they are always buffer-specific. */
9676 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9677 continue;
9678
9679 /* Global values are only written when not at the default value. */
9680 varp = get_varp_scope(p, opt_flags);
9681 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9682 continue;
9683
9684 round = 2;
9685 if (p->indir != PV_NONE)
9686 {
9687 if (p->var == VAR_WIN)
9688 {
9689 /* skip window-local option when only doing globals */
9690 if (!(opt_flags & OPT_LOCAL))
9691 continue;
9692 /* When fresh value of window-local option is not at the
9693 * default, need to write it too. */
9694 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9695 {
9696 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9697 if (!optval_default(p, varp_fresh))
9698 {
9699 round = 1;
9700 varp_local = varp;
9701 varp = varp_fresh;
9702 }
9703 }
9704 }
9705 }
9706
9707 /* Round 1: fresh value for window-local options.
9708 * Round 2: other values */
9709 for ( ; round <= 2; varp = varp_local, ++round)
9710 {
9711 if (round == 1 || (opt_flags & OPT_GLOBAL))
9712 cmd = "set";
9713 else
9714 cmd = "setlocal";
9715
9716 if (p->flags & P_BOOL)
9717 {
9718 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9719 return FAIL;
9720 }
9721 else if (p->flags & P_NUM)
9722 {
9723 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9724 return FAIL;
9725 }
9726 else /* P_STRING */
9727 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009728#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9729 int do_endif = FALSE;
9730
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731 /* Don't set 'syntax' and 'filetype' again if the value is
9732 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009733 if (
9734# if defined(FEAT_SYN_HL)
9735 p->indir == PV_SYN
9736# if defined(FEAT_AUTOCMD)
9737 ||
9738# endif
9739# endif
9740# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009741 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009742# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009743 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009744 {
9745 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9746 *(char_u **)(varp)) < 0
9747 || put_eol(fd) < 0)
9748 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009749 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009751#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9753 (p->flags & P_EXPAND) != 0) == FAIL)
9754 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009755#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9756 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009757 {
9758 if (put_line(fd, "endif") == FAIL)
9759 return FAIL;
9760 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009761#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762 }
9763 }
9764 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009765 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009766 return OK;
9767}
9768
9769#if defined(FEAT_FOLDING) || defined(PROTO)
9770/*
9771 * Generate set commands for the local fold options only. Used when
9772 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9773 */
9774 int
9775makefoldset(fd)
9776 FILE *fd;
9777{
9778 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9779# ifdef FEAT_EVAL
9780 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9781 == FAIL
9782# endif
9783 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9784 == FAIL
9785 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9786 == FAIL
9787 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9788 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9789 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9790 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9791 )
9792 return FAIL;
9793
9794 return OK;
9795}
9796#endif
9797
9798 static int
9799put_setstring(fd, cmd, name, valuep, expand)
9800 FILE *fd;
9801 char *cmd;
9802 char *name;
9803 char_u **valuep;
9804 int expand;
9805{
9806 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009807 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009808
9809 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9810 return FAIL;
9811 if (*valuep != NULL)
9812 {
9813 /* Output 'pastetoggle' as key names. For other
9814 * options some characters have to be escaped with
9815 * CTRL-V or backslash */
9816 if (valuep == &p_pt)
9817 {
9818 s = *valuep;
9819 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009820 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009821 return FAIL;
9822 }
9823 else if (expand)
9824 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009825 buf = alloc(MAXPATHL);
9826 if (buf == NULL)
9827 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009828 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9829 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009830 {
9831 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009833 }
9834 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009835 }
9836 else if (put_escstr(fd, *valuep, 2) == FAIL)
9837 return FAIL;
9838 }
9839 if (put_eol(fd) < 0)
9840 return FAIL;
9841 return OK;
9842}
9843
9844 static int
9845put_setnum(fd, cmd, name, valuep)
9846 FILE *fd;
9847 char *cmd;
9848 char *name;
9849 long *valuep;
9850{
9851 long wc;
9852
9853 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9854 return FAIL;
9855 if (wc_use_keyname((char_u *)valuep, &wc))
9856 {
9857 /* print 'wildchar' and 'wildcharm' as a key name */
9858 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9859 return FAIL;
9860 }
9861 else if (fprintf(fd, "%ld", *valuep) < 0)
9862 return FAIL;
9863 if (put_eol(fd) < 0)
9864 return FAIL;
9865 return OK;
9866}
9867
9868 static int
9869put_setbool(fd, cmd, name, value)
9870 FILE *fd;
9871 char *cmd;
9872 char *name;
9873 int value;
9874{
Bram Moolenaar893de922007-10-02 18:40:57 +00009875 if (value < 0) /* global/local option using global value */
9876 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9878 || put_eol(fd) < 0)
9879 return FAIL;
9880 return OK;
9881}
9882
9883/*
9884 * Clear all the terminal options.
9885 * If the option has been allocated, free the memory.
9886 * Terminal options are never hidden or indirect.
9887 */
9888 void
9889clear_termoptions()
9890{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009891 /*
9892 * Reset a few things before clearing the old options. This may cause
9893 * outputting a few things that the terminal doesn't understand, but the
9894 * screen will be cleared later, so this is OK.
9895 */
9896#ifdef FEAT_MOUSE_TTY
9897 mch_setmouse(FALSE); /* switch mouse off */
9898#endif
9899#ifdef FEAT_TITLE
9900 mch_restore_title(3); /* restore window titles */
9901#endif
9902#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9903 /* When starting the GUI close the display opened for the clipboard.
9904 * After restoring the title, because that will need the display. */
9905 if (gui.starting)
9906 clear_xterm_clip();
9907#endif
9908#ifdef WIN3264
9909 /*
9910 * Check if this is allowed now.
9911 */
9912 if (can_end_termcap_mode(FALSE) == TRUE)
9913#endif
9914 stoptermcap(); /* stop termcap mode */
9915
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009916 free_termoptions();
9917}
9918
9919 void
9920free_termoptions()
9921{
9922 struct vimoption *p;
9923
Bram Moolenaar071d4272004-06-13 20:20:40 +00009924 for (p = &options[0]; p->fullname != NULL; p++)
9925 if (istermoption(p))
9926 {
9927 if (p->flags & P_ALLOCED)
9928 free_string_option(*(char_u **)(p->var));
9929 if (p->flags & P_DEF_ALLOCED)
9930 free_string_option(p->def_val[VI_DEFAULT]);
9931 *(char_u **)(p->var) = empty_option;
9932 p->def_val[VI_DEFAULT] = empty_option;
9933 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9934 }
9935 clear_termcodes();
9936}
9937
9938/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009939 * Free the string for one term option, if it was allocated.
9940 * Set the string to empty_option and clear allocated flag.
9941 * "var" points to the option value.
9942 */
9943 void
9944free_one_termoption(var)
9945 char_u *var;
9946{
9947 struct vimoption *p;
9948
9949 for (p = &options[0]; p->fullname != NULL; p++)
9950 if (p->var == var)
9951 {
9952 if (p->flags & P_ALLOCED)
9953 free_string_option(*(char_u **)(p->var));
9954 *(char_u **)(p->var) = empty_option;
9955 p->flags &= ~P_ALLOCED;
9956 break;
9957 }
9958}
9959
9960/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961 * Set the terminal option defaults to the current value.
9962 * Used after setting the terminal name.
9963 */
9964 void
9965set_term_defaults()
9966{
9967 struct vimoption *p;
9968
9969 for (p = &options[0]; p->fullname != NULL; p++)
9970 {
9971 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9972 {
9973 if (p->flags & P_DEF_ALLOCED)
9974 {
9975 free_string_option(p->def_val[VI_DEFAULT]);
9976 p->flags &= ~P_DEF_ALLOCED;
9977 }
9978 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9979 if (p->flags & P_ALLOCED)
9980 {
9981 p->flags |= P_DEF_ALLOCED;
9982 p->flags &= ~P_ALLOCED; /* don't free the value now */
9983 }
9984 }
9985 }
9986}
9987
9988/*
9989 * return TRUE if 'p' starts with 't_'
9990 */
9991 static int
9992istermoption(p)
9993 struct vimoption *p;
9994{
9995 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9996}
9997
9998/*
9999 * Compute columns for ruler and shown command. 'sc_col' is also used to
10000 * decide what the maximum length of a message on the status line can be.
10001 * If there is a status line for the last window, 'sc_col' is independent
10002 * of 'ru_col'.
10003 */
10004
10005#define COL_RULER 17 /* columns needed by standard ruler */
10006
10007 void
10008comp_col()
10009{
10010#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10011 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10012
10013 sc_col = 0;
10014 ru_col = 0;
10015 if (p_ru)
10016 {
10017#ifdef FEAT_STL_OPT
10018 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10019#else
10020 ru_col = COL_RULER + 1;
10021#endif
10022 /* no last status line, adjust sc_col */
10023 if (!last_has_status)
10024 sc_col = ru_col;
10025 }
10026 if (p_sc)
10027 {
10028 sc_col += SHOWCMD_COLS;
10029 if (!p_ru || last_has_status) /* no need for separating space */
10030 ++sc_col;
10031 }
10032 sc_col = Columns - sc_col;
10033 ru_col = Columns - ru_col;
10034 if (sc_col <= 0) /* screen too narrow, will become a mess */
10035 sc_col = 1;
10036 if (ru_col <= 0)
10037 ru_col = 1;
10038#else
10039 sc_col = Columns;
10040 ru_col = Columns;
10041#endif
10042}
10043
10044/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010045 * Unset local option value, similar to ":set opt<".
10046 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010047 void
10048unset_global_local_option(name, from)
10049 char_u *name;
10050 void *from;
10051{
10052 struct vimoption *p;
10053 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010054 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010055
10056 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010057 if (opt_idx < 0)
10058 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010059 p = &(options[opt_idx]);
10060
10061 switch ((int)p->indir)
10062 {
10063 /* global option with local value: use local value if it's been set */
10064 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010065 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010066 break;
10067 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010068 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010069 break;
10070 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010071 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010072 break;
10073 case PV_AR:
10074 buf->b_p_ar = -1;
10075 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010076 case PV_BKC:
10077 clear_string_option(&buf->b_p_bkc);
10078 buf->b_bkc_flags = 0;
10079 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010081 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010082 break;
10083#ifdef FEAT_FIND_ID
10084 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010085 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010086 break;
10087 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010088 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010089 break;
10090#endif
10091#ifdef FEAT_INS_EXPAND
10092 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010093 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010094 break;
10095 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010096 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097 break;
10098#endif
10099#ifdef FEAT_QUICKFIX
10100 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010101 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010102 break;
10103 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010104 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010105 break;
10106 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010107 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010108 break;
10109#endif
10110#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10111 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010112 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010113 break;
10114#endif
10115#if defined(FEAT_CRYPT)
10116 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010117 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010118 break;
10119#endif
10120#ifdef FEAT_STL_OPT
10121 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010122 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010123 break;
10124#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010125 case PV_UL:
10126 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10127 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010128#ifdef FEAT_LISP
10129 case PV_LW:
10130 clear_string_option(&buf->b_p_lw);
10131 break;
10132#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010133 }
10134}
10135
10136/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137 * Get pointer to option variable, depending on local or global scope.
10138 */
10139 static char_u *
10140get_varp_scope(p, opt_flags)
10141 struct vimoption *p;
10142 int opt_flags;
10143{
10144 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10145 {
10146 if (p->var == VAR_WIN)
10147 return (char_u *)GLOBAL_WO(get_varp(p));
10148 return p->var;
10149 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010150 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151 {
10152 switch ((int)p->indir)
10153 {
10154#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010155 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10156 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10157 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010158#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010159 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10160 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10161 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010162 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010163 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010164#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010165 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10166 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167#endif
10168#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010169 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10170 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010172#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10173 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10174#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010175#if defined(FEAT_CRYPT)
10176 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10177#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010178#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010179 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010180#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010181 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010182#ifdef FEAT_LISP
10183 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10184#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010185 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 }
10187 return NULL; /* "cannot happen" */
10188 }
10189 return get_varp(p);
10190}
10191
10192/*
10193 * Get pointer to option variable.
10194 */
10195 static char_u *
10196get_varp(p)
10197 struct vimoption *p;
10198{
10199 /* hidden option, always return NULL */
10200 if (p->var == NULL)
10201 return NULL;
10202
10203 switch ((int)p->indir)
10204 {
10205 case PV_NONE: return p->var;
10206
10207 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010208 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010209 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010210 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010212 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010213 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010214 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010216 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010217 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010218 case PV_BKC: return *curbuf->b_p_bkc != NUL
10219 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010221 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010222 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010223 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010224 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10225#endif
10226#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010227 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010229 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010230 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10231#endif
10232#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010233 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010235 case PV_GP: return *curbuf->b_p_gp != NUL
10236 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10237 case PV_MP: return *curbuf->b_p_mp != NUL
10238 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010240#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10241 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10242 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10243#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010244#if defined(FEAT_CRYPT)
10245 case PV_CM: return *curbuf->b_p_cm != NUL
10246 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10247#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010248#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010249 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010250 ? (char_u *)&(curwin->w_p_stl) : p->var;
10251#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010252 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10253 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010254#ifdef FEAT_LISP
10255 case PV_LW: return *curbuf->b_p_lw != NUL
10256 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010258
10259#ifdef FEAT_ARABIC
10260 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10261#endif
10262 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010263#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010264 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10265#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010266#ifdef FEAT_SYN_HL
10267 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10268 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010269 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010270#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271#ifdef FEAT_DIFF
10272 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10273#endif
10274#ifdef FEAT_FOLDING
10275 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10276 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10277 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10278 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10279 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10280 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10281 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10282# ifdef FEAT_EVAL
10283 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10284 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10285# endif
10286 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10287#endif
10288 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010289 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010290#ifdef FEAT_LINEBREAK
10291 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10292#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010293#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10295#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010296#ifdef FEAT_VERTSPLIT
10297 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10298#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010299#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10300 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10301#endif
10302#ifdef FEAT_RIGHTLEFT
10303 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10304 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10305#endif
10306 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10307 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10308#ifdef FEAT_LINEBREAK
10309 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010310 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10311 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312#endif
10313#ifdef FEAT_SCROLLBIND
10314 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10315#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010316#ifdef FEAT_CURSORBIND
10317 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10318#endif
10319#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010320 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10321 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010322#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323
10324 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10325 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10326#ifdef FEAT_MBYTE
10327 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10328#endif
10329#if defined(FEAT_QUICKFIX)
10330 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10331 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10332#endif
10333 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10334 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10335#ifdef FEAT_CINDENT
10336 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10337 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10338 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10339#endif
10340#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10341 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10342#endif
10343#ifdef FEAT_COMMENTS
10344 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10345#endif
10346#ifdef FEAT_FOLDING
10347 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10348#endif
10349#ifdef FEAT_INS_EXPAND
10350 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10351#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010352#ifdef FEAT_COMPL_FUNC
10353 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010354 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010357 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10359#ifdef FEAT_MBYTE
10360 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10361#endif
10362 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10363#ifdef FEAT_AUTOCMD
10364 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10365#endif
10366 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010367 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010368 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10369 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10370 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10371 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10372#ifdef FEAT_FIND_ID
10373# ifdef FEAT_EVAL
10374 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10375# endif
10376#endif
10377#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10378 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10379 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10380#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010381#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010382 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384#ifdef FEAT_CRYPT
10385 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10386#endif
10387#ifdef FEAT_LISP
10388 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10389#endif
10390 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10391 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10392 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10393 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10394 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010396#ifdef FEAT_TEXTOBJ
10397 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10400#ifdef FEAT_SMARTINDENT
10401 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10402#endif
10403#ifndef SHORT_FNAME
10404 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10405#endif
10406 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10407#ifdef FEAT_SEARCHPATH
10408 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10409#endif
10410 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10411#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010412 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010413 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10414#endif
10415#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010416 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10417 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10418 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010419#endif
10420 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10421 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10422 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10423 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010424#ifdef FEAT_PERSISTENT_UNDO
10425 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10426#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010427 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10428#ifdef FEAT_KEYMAP
10429 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10430#endif
10431 default: EMSG(_("E356: get_varp ERROR"));
10432 }
10433 /* always return a valid pointer to avoid a crash! */
10434 return (char_u *)&(curbuf->b_p_wm);
10435}
10436
10437/*
10438 * Get the value of 'equalprg', either the buffer-local one or the global one.
10439 */
10440 char_u *
10441get_equalprg()
10442{
10443 if (*curbuf->b_p_ep == NUL)
10444 return p_ep;
10445 return curbuf->b_p_ep;
10446}
10447
10448#if defined(FEAT_WINDOWS) || defined(PROTO)
10449/*
10450 * Copy options from one window to another.
10451 * Used when splitting a window.
10452 */
10453 void
10454win_copy_options(wp_from, wp_to)
10455 win_T *wp_from;
10456 win_T *wp_to;
10457{
10458 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10459 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10460# ifdef FEAT_RIGHTLEFT
10461# ifdef FEAT_FKMAP
10462 /* Is this right? */
10463 wp_to->w_farsi = wp_from->w_farsi;
10464# endif
10465# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010466#if defined(FEAT_LINEBREAK)
10467 briopt_check(wp_to);
10468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010469}
10470#endif
10471
10472/*
10473 * Copy the options from one winopt_T to another.
10474 * Doesn't free the old option values in "to", use clear_winopt() for that.
10475 * The 'scroll' option is not copied, because it depends on the window height.
10476 * The 'previewwindow' option is reset, there can be only one preview window.
10477 */
10478 void
10479copy_winopt(from, to)
10480 winopt_T *from;
10481 winopt_T *to;
10482{
10483#ifdef FEAT_ARABIC
10484 to->wo_arab = from->wo_arab;
10485#endif
10486 to->wo_list = from->wo_list;
10487 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010488 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010489#ifdef FEAT_LINEBREAK
10490 to->wo_nuw = from->wo_nuw;
10491#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010492#ifdef FEAT_RIGHTLEFT
10493 to->wo_rl = from->wo_rl;
10494 to->wo_rlc = vim_strsave(from->wo_rlc);
10495#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010496#ifdef FEAT_STL_OPT
10497 to->wo_stl = vim_strsave(from->wo_stl);
10498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010500#ifdef FEAT_DIFF
10501 to->wo_wrap_save = from->wo_wrap_save;
10502#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010503#ifdef FEAT_LINEBREAK
10504 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010505 to->wo_bri = from->wo_bri;
10506 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507#endif
10508#ifdef FEAT_SCROLLBIND
10509 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010510 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010512#ifdef FEAT_CURSORBIND
10513 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010514 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010515#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010516#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010517 to->wo_spell = from->wo_spell;
10518#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010519#ifdef FEAT_SYN_HL
10520 to->wo_cuc = from->wo_cuc;
10521 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010522 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524#ifdef FEAT_DIFF
10525 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010526 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010528#ifdef FEAT_CONCEAL
10529 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010530 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010531#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532#ifdef FEAT_FOLDING
10533 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010534 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010536 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537 to->wo_fdi = vim_strsave(from->wo_fdi);
10538 to->wo_fml = from->wo_fml;
10539 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010540 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010542 to->wo_fdm_save = from->wo_diff_saved
10543 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 to->wo_fdn = from->wo_fdn;
10545# ifdef FEAT_EVAL
10546 to->wo_fde = vim_strsave(from->wo_fde);
10547 to->wo_fdt = vim_strsave(from->wo_fdt);
10548# endif
10549 to->wo_fmr = vim_strsave(from->wo_fmr);
10550#endif
10551 check_winopt(to); /* don't want NULL pointers */
10552}
10553
10554/*
10555 * Check string options in a window for a NULL value.
10556 */
10557 void
10558check_win_options(win)
10559 win_T *win;
10560{
10561 check_winopt(&win->w_onebuf_opt);
10562 check_winopt(&win->w_allbuf_opt);
10563}
10564
10565/*
10566 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10567 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010568 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010570 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571{
10572#ifdef FEAT_FOLDING
10573 check_string_option(&wop->wo_fdi);
10574 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010575 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576# ifdef FEAT_EVAL
10577 check_string_option(&wop->wo_fde);
10578 check_string_option(&wop->wo_fdt);
10579# endif
10580 check_string_option(&wop->wo_fmr);
10581#endif
10582#ifdef FEAT_RIGHTLEFT
10583 check_string_option(&wop->wo_rlc);
10584#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010585#ifdef FEAT_STL_OPT
10586 check_string_option(&wop->wo_stl);
10587#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010588#ifdef FEAT_SYN_HL
10589 check_string_option(&wop->wo_cc);
10590#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010591#ifdef FEAT_CONCEAL
10592 check_string_option(&wop->wo_cocu);
10593#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010594#ifdef FEAT_LINEBREAK
10595 check_string_option(&wop->wo_briopt);
10596#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597}
10598
10599/*
10600 * Free the allocated memory inside a winopt_T.
10601 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602 void
10603clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010604 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605{
10606#ifdef FEAT_FOLDING
10607 clear_string_option(&wop->wo_fdi);
10608 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010609 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610# ifdef FEAT_EVAL
10611 clear_string_option(&wop->wo_fde);
10612 clear_string_option(&wop->wo_fdt);
10613# endif
10614 clear_string_option(&wop->wo_fmr);
10615#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010616#ifdef FEAT_LINEBREAK
10617 clear_string_option(&wop->wo_briopt);
10618#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619#ifdef FEAT_RIGHTLEFT
10620 clear_string_option(&wop->wo_rlc);
10621#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010622#ifdef FEAT_STL_OPT
10623 clear_string_option(&wop->wo_stl);
10624#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010625#ifdef FEAT_SYN_HL
10626 clear_string_option(&wop->wo_cc);
10627#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010628#ifdef FEAT_CONCEAL
10629 clear_string_option(&wop->wo_cocu);
10630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631}
10632
10633/*
10634 * Copy global option values to local options for one buffer.
10635 * Used when creating a new buffer and sometimes when entering a buffer.
10636 * flags:
10637 * BCO_ENTER We will enter the buf buffer.
10638 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10639 * appropriate.
10640 * BCO_NOHELP Don't copy the values to a help buffer.
10641 */
10642 void
10643buf_copy_options(buf, flags)
10644 buf_T *buf;
10645 int flags;
10646{
10647 int should_copy = TRUE;
10648 char_u *save_p_isk = NULL; /* init for GCC */
10649 int dont_do_help;
10650 int did_isk = FALSE;
10651
10652 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010653 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010654 */
10655 if (buf == NULL || !buf_valid(buf))
10656 return;
10657
10658 /*
10659 * Skip this when the option defaults have not been set yet. Happens when
10660 * main() allocates the first buffer.
10661 */
10662 if (p_cpo != NULL)
10663 {
10664 /*
10665 * Always copy when entering and 'cpo' contains 'S'.
10666 * Don't copy when already initialized.
10667 * Don't copy when 'cpo' contains 's' and not entering.
10668 * 'S' BCO_ENTER initialized 's' should_copy
10669 * yes yes X X TRUE
10670 * yes no yes X FALSE
10671 * no X yes X FALSE
10672 * X no no yes FALSE
10673 * X no no no TRUE
10674 * no yes no X TRUE
10675 */
10676 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10677 && (buf->b_p_initialized
10678 || (!(flags & BCO_ENTER)
10679 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10680 should_copy = FALSE;
10681
10682 if (should_copy || (flags & BCO_ALWAYS))
10683 {
10684 /* Don't copy the options specific to a help buffer when
10685 * BCO_NOHELP is given or the options were initialized already
10686 * (jumping back to a help file with CTRL-T or CTRL-O) */
10687 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10688 || buf->b_p_initialized;
10689 if (dont_do_help) /* don't free b_p_isk */
10690 {
10691 save_p_isk = buf->b_p_isk;
10692 buf->b_p_isk = NULL;
10693 }
10694 /*
10695 * Always free the allocated strings.
10696 * If not already initialized, set 'readonly' and copy 'fileformat'.
10697 */
10698 if (!buf->b_p_initialized)
10699 {
10700 free_buf_options(buf, TRUE);
10701 buf->b_p_ro = FALSE; /* don't copy readonly */
10702 buf->b_p_tx = p_tx;
10703#ifdef FEAT_MBYTE
10704 buf->b_p_fenc = vim_strsave(p_fenc);
10705#endif
10706 buf->b_p_ff = vim_strsave(p_ff);
10707#if defined(FEAT_QUICKFIX)
10708 buf->b_p_bh = empty_option;
10709 buf->b_p_bt = empty_option;
10710#endif
10711 }
10712 else
10713 free_buf_options(buf, FALSE);
10714
10715 buf->b_p_ai = p_ai;
10716 buf->b_p_ai_nopaste = p_ai_nopaste;
10717 buf->b_p_sw = p_sw;
10718 buf->b_p_tw = p_tw;
10719 buf->b_p_tw_nopaste = p_tw_nopaste;
10720 buf->b_p_tw_nobin = p_tw_nobin;
10721 buf->b_p_wm = p_wm;
10722 buf->b_p_wm_nopaste = p_wm_nopaste;
10723 buf->b_p_wm_nobin = p_wm_nobin;
10724 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010725#ifdef FEAT_MBYTE
10726 buf->b_p_bomb = p_bomb;
10727#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010728 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 buf->b_p_et = p_et;
10730 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010731 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732 buf->b_p_ml = p_ml;
10733 buf->b_p_ml_nobin = p_ml_nobin;
10734 buf->b_p_inf = p_inf;
10735 buf->b_p_swf = p_swf;
10736#ifdef FEAT_INS_EXPAND
10737 buf->b_p_cpt = vim_strsave(p_cpt);
10738#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010739#ifdef FEAT_COMPL_FUNC
10740 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010741 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010742#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 buf->b_p_sts = p_sts;
10744 buf->b_p_sts_nopaste = p_sts_nopaste;
10745#ifndef SHORT_FNAME
10746 buf->b_p_sn = p_sn;
10747#endif
10748#ifdef FEAT_COMMENTS
10749 buf->b_p_com = vim_strsave(p_com);
10750#endif
10751#ifdef FEAT_FOLDING
10752 buf->b_p_cms = vim_strsave(p_cms);
10753#endif
10754 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010755 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010756 buf->b_p_nf = vim_strsave(p_nf);
10757 buf->b_p_mps = vim_strsave(p_mps);
10758#ifdef FEAT_SMARTINDENT
10759 buf->b_p_si = p_si;
10760#endif
10761 buf->b_p_ci = p_ci;
10762#ifdef FEAT_CINDENT
10763 buf->b_p_cin = p_cin;
10764 buf->b_p_cink = vim_strsave(p_cink);
10765 buf->b_p_cino = vim_strsave(p_cino);
10766#endif
10767#ifdef FEAT_AUTOCMD
10768 /* Don't copy 'filetype', it must be detected */
10769 buf->b_p_ft = empty_option;
10770#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771 buf->b_p_pi = p_pi;
10772#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10773 buf->b_p_cinw = vim_strsave(p_cinw);
10774#endif
10775#ifdef FEAT_LISP
10776 buf->b_p_lisp = p_lisp;
10777#endif
10778#ifdef FEAT_SYN_HL
10779 /* Don't copy 'syntax', it must be set */
10780 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010781 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010782#endif
10783#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010784 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010785 (void)compile_cap_prog(&buf->b_s);
10786 buf->b_s.b_p_spf = vim_strsave(p_spf);
10787 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788#endif
10789#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10790 buf->b_p_inde = vim_strsave(p_inde);
10791 buf->b_p_indk = vim_strsave(p_indk);
10792#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010793#if defined(FEAT_EVAL)
10794 buf->b_p_fex = vim_strsave(p_fex);
10795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796#ifdef FEAT_CRYPT
10797 buf->b_p_key = vim_strsave(p_key);
10798#endif
10799#ifdef FEAT_SEARCHPATH
10800 buf->b_p_sua = vim_strsave(p_sua);
10801#endif
10802#ifdef FEAT_KEYMAP
10803 buf->b_p_keymap = vim_strsave(p_keymap);
10804 buf->b_kmap_state |= KEYMAP_INIT;
10805#endif
10806 /* This isn't really an option, but copying the langmap and IME
10807 * state from the current buffer is better than resetting it. */
10808 buf->b_p_iminsert = p_iminsert;
10809 buf->b_p_imsearch = p_imsearch;
10810
10811 /* options that are normally global but also have a local value
10812 * are not copied, start using the global value */
10813 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010814 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010815 buf->b_p_bkc = empty_option;
10816 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817#ifdef FEAT_QUICKFIX
10818 buf->b_p_gp = empty_option;
10819 buf->b_p_mp = empty_option;
10820 buf->b_p_efm = empty_option;
10821#endif
10822 buf->b_p_ep = empty_option;
10823 buf->b_p_kp = empty_option;
10824 buf->b_p_path = empty_option;
10825 buf->b_p_tags = empty_option;
10826#ifdef FEAT_FIND_ID
10827 buf->b_p_def = empty_option;
10828 buf->b_p_inc = empty_option;
10829# ifdef FEAT_EVAL
10830 buf->b_p_inex = vim_strsave(p_inex);
10831# endif
10832#endif
10833#ifdef FEAT_INS_EXPAND
10834 buf->b_p_dict = empty_option;
10835 buf->b_p_tsr = empty_option;
10836#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010837#ifdef FEAT_TEXTOBJ
10838 buf->b_p_qe = vim_strsave(p_qe);
10839#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010840#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10841 buf->b_p_bexpr = empty_option;
10842#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010843#if defined(FEAT_CRYPT)
10844 buf->b_p_cm = empty_option;
10845#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010846#ifdef FEAT_PERSISTENT_UNDO
10847 buf->b_p_udf = p_udf;
10848#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010849#ifdef FEAT_LISP
10850 buf->b_p_lw = empty_option;
10851#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852
10853 /*
10854 * Don't copy the options set by ex_help(), use the saved values,
10855 * when going from a help buffer to a non-help buffer.
10856 * Don't touch these at all when BCO_NOHELP is used and going from
10857 * or to a help buffer.
10858 */
10859 if (dont_do_help)
10860 buf->b_p_isk = save_p_isk;
10861 else
10862 {
10863 buf->b_p_isk = vim_strsave(p_isk);
10864 did_isk = TRUE;
10865 buf->b_p_ts = p_ts;
10866 buf->b_help = FALSE;
10867#ifdef FEAT_QUICKFIX
10868 if (buf->b_p_bt[0] == 'h')
10869 clear_string_option(&buf->b_p_bt);
10870#endif
10871 buf->b_p_ma = p_ma;
10872 }
10873 }
10874
10875 /*
10876 * When the options should be copied (ignoring BCO_ALWAYS), set the
10877 * flag that indicates that the options have been initialized.
10878 */
10879 if (should_copy)
10880 buf->b_p_initialized = TRUE;
10881 }
10882
10883 check_buf_options(buf); /* make sure we don't have NULLs */
10884 if (did_isk)
10885 (void)buf_init_chartab(buf, FALSE);
10886}
10887
10888/*
10889 * Reset the 'modifiable' option and its default value.
10890 */
10891 void
10892reset_modifiable()
10893{
10894 int opt_idx;
10895
10896 curbuf->b_p_ma = FALSE;
10897 p_ma = FALSE;
10898 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010899 if (opt_idx >= 0)
10900 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901}
10902
10903/*
10904 * Set the global value for 'iminsert' to the local value.
10905 */
10906 void
10907set_iminsert_global()
10908{
10909 p_iminsert = curbuf->b_p_iminsert;
10910}
10911
10912/*
10913 * Set the global value for 'imsearch' to the local value.
10914 */
10915 void
10916set_imsearch_global()
10917{
10918 p_imsearch = curbuf->b_p_imsearch;
10919}
10920
10921#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10922static int expand_option_idx = -1;
10923static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10924static int expand_option_flags = 0;
10925
10926 void
10927set_context_in_set_cmd(xp, arg, opt_flags)
10928 expand_T *xp;
10929 char_u *arg;
10930 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10931{
10932 int nextchar;
10933 long_u flags = 0; /* init for GCC */
10934 int opt_idx = 0; /* init for GCC */
10935 char_u *p;
10936 char_u *s;
10937 int is_term_option = FALSE;
10938 int key;
10939
10940 expand_option_flags = opt_flags;
10941
10942 xp->xp_context = EXPAND_SETTINGS;
10943 if (*arg == NUL)
10944 {
10945 xp->xp_pattern = arg;
10946 return;
10947 }
10948 p = arg + STRLEN(arg) - 1;
10949 if (*p == ' ' && *(p - 1) != '\\')
10950 {
10951 xp->xp_pattern = p + 1;
10952 return;
10953 }
10954 while (p > arg)
10955 {
10956 s = p;
10957 /* count number of backslashes before ' ' or ',' */
10958 if (*p == ' ' || *p == ',')
10959 {
10960 while (s > arg && *(s - 1) == '\\')
10961 --s;
10962 }
10963 /* break at a space with an even number of backslashes */
10964 if (*p == ' ' && ((p - s) & 1) == 0)
10965 {
10966 ++p;
10967 break;
10968 }
10969 --p;
10970 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010971 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010972 {
10973 xp->xp_context = EXPAND_BOOL_SETTINGS;
10974 p += 2;
10975 }
10976 if (STRNCMP(p, "inv", 3) == 0)
10977 {
10978 xp->xp_context = EXPAND_BOOL_SETTINGS;
10979 p += 3;
10980 }
10981 xp->xp_pattern = arg = p;
10982 if (*arg == '<')
10983 {
10984 while (*p != '>')
10985 if (*p++ == NUL) /* expand terminal option name */
10986 return;
10987 key = get_special_key_code(arg + 1);
10988 if (key == 0) /* unknown name */
10989 {
10990 xp->xp_context = EXPAND_NOTHING;
10991 return;
10992 }
10993 nextchar = *++p;
10994 is_term_option = TRUE;
10995 expand_option_name[2] = KEY2TERMCAP0(key);
10996 expand_option_name[3] = KEY2TERMCAP1(key);
10997 }
10998 else
10999 {
11000 if (p[0] == 't' && p[1] == '_')
11001 {
11002 p += 2;
11003 if (*p != NUL)
11004 ++p;
11005 if (*p == NUL)
11006 return; /* expand option name */
11007 nextchar = *++p;
11008 is_term_option = TRUE;
11009 expand_option_name[2] = p[-2];
11010 expand_option_name[3] = p[-1];
11011 }
11012 else
11013 {
11014 /* Allow * wildcard */
11015 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11016 p++;
11017 if (*p == NUL)
11018 return;
11019 nextchar = *p;
11020 *p = NUL;
11021 opt_idx = findoption(arg);
11022 *p = nextchar;
11023 if (opt_idx == -1 || options[opt_idx].var == NULL)
11024 {
11025 xp->xp_context = EXPAND_NOTHING;
11026 return;
11027 }
11028 flags = options[opt_idx].flags;
11029 if (flags & P_BOOL)
11030 {
11031 xp->xp_context = EXPAND_NOTHING;
11032 return;
11033 }
11034 }
11035 }
11036 /* handle "-=" and "+=" */
11037 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11038 {
11039 ++p;
11040 nextchar = '=';
11041 }
11042 if ((nextchar != '=' && nextchar != ':')
11043 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11044 {
11045 xp->xp_context = EXPAND_UNSUCCESSFUL;
11046 return;
11047 }
11048 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11049 {
11050 xp->xp_context = EXPAND_OLD_SETTING;
11051 if (is_term_option)
11052 expand_option_idx = -1;
11053 else
11054 expand_option_idx = opt_idx;
11055 xp->xp_pattern = p + 1;
11056 return;
11057 }
11058 xp->xp_context = EXPAND_NOTHING;
11059 if (is_term_option || (flags & P_NUM))
11060 return;
11061
11062 xp->xp_pattern = p + 1;
11063
11064 if (flags & P_EXPAND)
11065 {
11066 p = options[opt_idx].var;
11067 if (p == (char_u *)&p_bdir
11068 || p == (char_u *)&p_dir
11069 || p == (char_u *)&p_path
11070 || p == (char_u *)&p_rtp
11071#ifdef FEAT_SEARCHPATH
11072 || p == (char_u *)&p_cdpath
11073#endif
11074#ifdef FEAT_SESSION
11075 || p == (char_u *)&p_vdir
11076#endif
11077 )
11078 {
11079 xp->xp_context = EXPAND_DIRECTORIES;
11080 if (p == (char_u *)&p_path
11081#ifdef FEAT_SEARCHPATH
11082 || p == (char_u *)&p_cdpath
11083#endif
11084 )
11085 xp->xp_backslash = XP_BS_THREE;
11086 else
11087 xp->xp_backslash = XP_BS_ONE;
11088 }
11089 else
11090 {
11091 xp->xp_context = EXPAND_FILES;
11092 /* for 'tags' need three backslashes for a space */
11093 if (p == (char_u *)&p_tags)
11094 xp->xp_backslash = XP_BS_THREE;
11095 else
11096 xp->xp_backslash = XP_BS_ONE;
11097 }
11098 }
11099
11100 /* For an option that is a list of file names, find the start of the
11101 * last file name. */
11102 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11103 {
11104 /* count number of backslashes before ' ' or ',' */
11105 if (*p == ' ' || *p == ',')
11106 {
11107 s = p;
11108 while (s > xp->xp_pattern && *(s - 1) == '\\')
11109 --s;
11110 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11111 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11112 {
11113 xp->xp_pattern = p + 1;
11114 break;
11115 }
11116 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011117
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011118#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011119 /* for 'spellsuggest' start at "file:" */
11120 if (options[opt_idx].var == (char_u *)&p_sps
11121 && STRNCMP(p, "file:", 5) == 0)
11122 {
11123 xp->xp_pattern = p + 5;
11124 break;
11125 }
11126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011127 }
11128
11129 return;
11130}
11131
11132 int
11133ExpandSettings(xp, regmatch, num_file, file)
11134 expand_T *xp;
11135 regmatch_T *regmatch;
11136 int *num_file;
11137 char_u ***file;
11138{
11139 int num_normal = 0; /* Nr of matching non-term-code settings */
11140 int num_term = 0; /* Nr of matching terminal code settings */
11141 int opt_idx;
11142 int match;
11143 int count = 0;
11144 char_u *str;
11145 int loop;
11146 int is_term_opt;
11147 char_u name_buf[MAX_KEY_NAME_LEN];
11148 static char *(names[]) = {"all", "termcap"};
11149 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11150
11151 /* do this loop twice:
11152 * loop == 0: count the number of matching options
11153 * loop == 1: copy the matching options into allocated memory
11154 */
11155 for (loop = 0; loop <= 1; ++loop)
11156 {
11157 regmatch->rm_ic = ic;
11158 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11159 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011160 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11161 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011162 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11163 {
11164 if (loop == 0)
11165 num_normal++;
11166 else
11167 (*file)[count++] = vim_strsave((char_u *)names[match]);
11168 }
11169 }
11170 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11171 opt_idx++)
11172 {
11173 if (options[opt_idx].var == NULL)
11174 continue;
11175 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11176 && !(options[opt_idx].flags & P_BOOL))
11177 continue;
11178 is_term_opt = istermoption(&options[opt_idx]);
11179 if (is_term_opt && num_normal > 0)
11180 continue;
11181 match = FALSE;
11182 if (vim_regexec(regmatch, str, (colnr_T)0)
11183 || (options[opt_idx].shortname != NULL
11184 && vim_regexec(regmatch,
11185 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11186 match = TRUE;
11187 else if (is_term_opt)
11188 {
11189 name_buf[0] = '<';
11190 name_buf[1] = 't';
11191 name_buf[2] = '_';
11192 name_buf[3] = str[2];
11193 name_buf[4] = str[3];
11194 name_buf[5] = '>';
11195 name_buf[6] = NUL;
11196 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11197 {
11198 match = TRUE;
11199 str = name_buf;
11200 }
11201 }
11202 if (match)
11203 {
11204 if (loop == 0)
11205 {
11206 if (is_term_opt)
11207 num_term++;
11208 else
11209 num_normal++;
11210 }
11211 else
11212 (*file)[count++] = vim_strsave(str);
11213 }
11214 }
11215 /*
11216 * Check terminal key codes, these are not in the option table
11217 */
11218 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11219 {
11220 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11221 {
11222 if (!isprint(str[0]) || !isprint(str[1]))
11223 continue;
11224
11225 name_buf[0] = 't';
11226 name_buf[1] = '_';
11227 name_buf[2] = str[0];
11228 name_buf[3] = str[1];
11229 name_buf[4] = NUL;
11230
11231 match = FALSE;
11232 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11233 match = TRUE;
11234 else
11235 {
11236 name_buf[0] = '<';
11237 name_buf[1] = 't';
11238 name_buf[2] = '_';
11239 name_buf[3] = str[0];
11240 name_buf[4] = str[1];
11241 name_buf[5] = '>';
11242 name_buf[6] = NUL;
11243
11244 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11245 match = TRUE;
11246 }
11247 if (match)
11248 {
11249 if (loop == 0)
11250 num_term++;
11251 else
11252 (*file)[count++] = vim_strsave(name_buf);
11253 }
11254 }
11255
11256 /*
11257 * Check special key names.
11258 */
11259 regmatch->rm_ic = TRUE; /* ignore case here */
11260 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11261 {
11262 name_buf[0] = '<';
11263 STRCPY(name_buf + 1, str);
11264 STRCAT(name_buf, ">");
11265
11266 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11267 {
11268 if (loop == 0)
11269 num_term++;
11270 else
11271 (*file)[count++] = vim_strsave(name_buf);
11272 }
11273 }
11274 }
11275 if (loop == 0)
11276 {
11277 if (num_normal > 0)
11278 *num_file = num_normal;
11279 else if (num_term > 0)
11280 *num_file = num_term;
11281 else
11282 return OK;
11283 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11284 if (*file == NULL)
11285 {
11286 *file = (char_u **)"";
11287 return FAIL;
11288 }
11289 }
11290 }
11291 return OK;
11292}
11293
11294 int
11295ExpandOldSetting(num_file, file)
11296 int *num_file;
11297 char_u ***file;
11298{
11299 char_u *var = NULL; /* init for GCC */
11300 char_u *buf;
11301
11302 *num_file = 0;
11303 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11304 if (*file == NULL)
11305 return FAIL;
11306
11307 /*
11308 * For a terminal key code expand_option_idx is < 0.
11309 */
11310 if (expand_option_idx < 0)
11311 {
11312 var = find_termcode(expand_option_name + 2);
11313 if (var == NULL)
11314 expand_option_idx = findoption(expand_option_name);
11315 }
11316
11317 if (expand_option_idx >= 0)
11318 {
11319 /* put string of option value in NameBuff */
11320 option_value2string(&options[expand_option_idx], expand_option_flags);
11321 var = NameBuff;
11322 }
11323 else if (var == NULL)
11324 var = (char_u *)"";
11325
11326 /* A backslash is required before some characters. This is the reverse of
11327 * what happens in do_set(). */
11328 buf = vim_strsave_escaped(var, escape_chars);
11329
11330 if (buf == NULL)
11331 {
11332 vim_free(*file);
11333 *file = NULL;
11334 return FAIL;
11335 }
11336
11337#ifdef BACKSLASH_IN_FILENAME
11338 /* For MS-Windows et al. we don't double backslashes at the start and
11339 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011340 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011341 if (var[0] == '\\' && var[1] == '\\'
11342 && expand_option_idx >= 0
11343 && (options[expand_option_idx].flags & P_EXPAND)
11344 && vim_isfilec(var[2])
11345 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011346 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011347#endif
11348
11349 *file[0] = buf;
11350 *num_file = 1;
11351 return OK;
11352}
11353#endif
11354
11355/*
11356 * Get the value for the numeric or string option *opp in a nice format into
11357 * NameBuff[]. Must not be called with a hidden option!
11358 */
11359 static void
11360option_value2string(opp, opt_flags)
11361 struct vimoption *opp;
11362 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11363{
11364 char_u *varp;
11365
11366 varp = get_varp_scope(opp, opt_flags);
11367
11368 if (opp->flags & P_NUM)
11369 {
11370 long wc = 0;
11371
11372 if (wc_use_keyname(varp, &wc))
11373 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11374 else if (wc != 0)
11375 STRCPY(NameBuff, transchar((int)wc));
11376 else
11377 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11378 }
11379 else /* P_STRING */
11380 {
11381 varp = *(char_u **)(varp);
11382 if (varp == NULL) /* just in case */
11383 NameBuff[0] = NUL;
11384#ifdef FEAT_CRYPT
11385 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011386 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387 STRCPY(NameBuff, "*****");
11388#endif
11389 else if (opp->flags & P_EXPAND)
11390 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11391 /* Translate 'pastetoggle' into special key names */
11392 else if ((char_u **)opp->var == &p_pt)
11393 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11394 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011395 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011396 }
11397}
11398
11399/*
11400 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11401 * printed as a keyname.
11402 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11403 */
11404 static int
11405wc_use_keyname(varp, wcp)
11406 char_u *varp;
11407 long *wcp;
11408{
11409 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11410 {
11411 *wcp = *(long *)varp;
11412 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11413 return TRUE;
11414 }
11415 return FALSE;
11416}
11417
Bram Moolenaar01615492015-02-03 13:00:38 +010011418#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011420 * Any character has an equivalent 'langmap' character. This is used for
11421 * keyboards that have a special language mode that sends characters above
11422 * 128 (although other characters can be translated too). The "to" field is a
11423 * Vim command character. This avoids having to switch the keyboard back to
11424 * ASCII mode when leaving Insert mode.
11425 *
11426 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11427 * commands.
11428 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11429 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11430 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011432# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011433/*
11434 * With multi-byte support use growarray for 'langmap' chars >= 256
11435 */
11436typedef struct
11437{
11438 int from;
11439 int to;
11440} langmap_entry_T;
11441
11442static garray_T langmap_mapga;
11443static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011444
11445/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011446 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11447 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011448 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011449 static void
11450langmap_set_entry(from, to)
11451 int from;
11452 int to;
11453{
11454 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011455 int a = 0;
11456 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011457
11458 /* Do a binary search for an existing entry. */
11459 while (a != b)
11460 {
11461 int i = (a + b) / 2;
11462 int d = entries[i].from - from;
11463
11464 if (d == 0)
11465 {
11466 entries[i].to = to;
11467 return;
11468 }
11469 if (d < 0)
11470 a = i + 1;
11471 else
11472 b = i;
11473 }
11474
11475 if (ga_grow(&langmap_mapga, 1) != OK)
11476 return; /* out of memory */
11477
11478 /* insert new entry at position "a" */
11479 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11480 mch_memmove(entries + 1, entries,
11481 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11482 ++langmap_mapga.ga_len;
11483 entries[0].from = from;
11484 entries[0].to = to;
11485}
11486
11487/*
11488 * Apply 'langmap' to multi-byte character "c" and return the result.
11489 */
11490 int
11491langmap_adjust_mb(c)
11492 int c;
11493{
11494 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11495 int a = 0;
11496 int b = langmap_mapga.ga_len;
11497
11498 while (a != b)
11499 {
11500 int i = (a + b) / 2;
11501 int d = entries[i].from - c;
11502
11503 if (d == 0)
11504 return entries[i].to; /* found matching entry */
11505 if (d < 0)
11506 a = i + 1;
11507 else
11508 b = i;
11509 }
11510 return c; /* no entry found, return "c" unmodified */
11511}
11512# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011513
11514 static void
11515langmap_init()
11516{
11517 int i;
11518
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011519 for (i = 0; i < 256; i++)
11520 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11521# ifdef FEAT_MBYTE
11522 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11523# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524}
11525
11526/*
11527 * Called when langmap option is set; the language map can be
11528 * changed at any time!
11529 */
11530 static void
11531langmap_set()
11532{
11533 char_u *p;
11534 char_u *p2;
11535 int from, to;
11536
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011537#ifdef FEAT_MBYTE
11538 ga_clear(&langmap_mapga); /* clear the previous map first */
11539#endif
11540 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011541
11542 for (p = p_langmap; p[0] != NUL; )
11543 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011544 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11545 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546 {
11547 if (p2[0] == '\\' && p2[1] != NUL)
11548 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011549 }
11550 if (p2[0] == ';')
11551 ++p2; /* abcd;ABCD form, p2 points to A */
11552 else
11553 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11554 while (p[0])
11555 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011556 if (p[0] == ',')
11557 {
11558 ++p;
11559 break;
11560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561 if (p[0] == '\\' && p[1] != NUL)
11562 ++p;
11563#ifdef FEAT_MBYTE
11564 from = (*mb_ptr2char)(p);
11565#else
11566 from = p[0];
11567#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011568 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011569 if (p2 == NULL)
11570 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011571 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011572 if (p[0] != ',')
11573 {
11574 if (p[0] == '\\')
11575 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011576#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011577 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011578#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011579 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011582 }
11583 else
11584 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011585 if (p2[0] != ',')
11586 {
11587 if (p2[0] == '\\')
11588 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011589#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011590 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011591#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011592 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011593#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011594 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011595 }
11596 if (to == NUL)
11597 {
11598 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11599 transchar(from));
11600 return;
11601 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011602
11603#ifdef FEAT_MBYTE
11604 if (from >= 256)
11605 langmap_set_entry(from, to);
11606 else
11607#endif
11608 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011609
11610 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011611 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011612 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011613 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011614 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011615 if (*p == ';')
11616 {
11617 p = p2;
11618 if (p[0] != NUL)
11619 {
11620 if (p[0] != ',')
11621 {
11622 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11623 return;
11624 }
11625 ++p;
11626 }
11627 break;
11628 }
11629 }
11630 }
11631 }
11632}
11633#endif
11634
11635/*
11636 * Return TRUE if format option 'x' is in effect.
11637 * Take care of no formatting when 'paste' is set.
11638 */
11639 int
11640has_format_option(x)
11641 int x;
11642{
11643 if (p_paste)
11644 return FALSE;
11645 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11646}
11647
11648/*
11649 * Return TRUE if "x" is present in 'shortmess' option, or
11650 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11651 */
11652 int
11653shortmess(x)
11654 int x;
11655{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011656 return p_shm != NULL &&
11657 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011658 || (vim_strchr(p_shm, 'a') != NULL
11659 && vim_strchr((char_u *)SHM_A, x) != NULL));
11660}
11661
11662/*
11663 * paste_option_changed() - Called after p_paste was set or reset.
11664 */
11665 static void
11666paste_option_changed()
11667{
11668 static int old_p_paste = FALSE;
11669 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011670 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011671#ifdef FEAT_CMDL_INFO
11672 static int save_ru = 0;
11673#endif
11674#ifdef FEAT_RIGHTLEFT
11675 static int save_ri = 0;
11676 static int save_hkmap = 0;
11677#endif
11678 buf_T *buf;
11679
11680 if (p_paste)
11681 {
11682 /*
11683 * Paste switched from off to on.
11684 * Save the current values, so they can be restored later.
11685 */
11686 if (!old_p_paste)
11687 {
11688 /* save options for each buffer */
11689 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11690 {
11691 buf->b_p_tw_nopaste = buf->b_p_tw;
11692 buf->b_p_wm_nopaste = buf->b_p_wm;
11693 buf->b_p_sts_nopaste = buf->b_p_sts;
11694 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011695 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011696 }
11697
11698 /* save global options */
11699 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011700 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011701#ifdef FEAT_CMDL_INFO
11702 save_ru = p_ru;
11703#endif
11704#ifdef FEAT_RIGHTLEFT
11705 save_ri = p_ri;
11706 save_hkmap = p_hkmap;
11707#endif
11708 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011709 p_ai_nopaste = p_ai;
11710 p_et_nopaste = p_et;
11711 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011712 p_tw_nopaste = p_tw;
11713 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714 }
11715
11716 /*
11717 * Always set the option values, also when 'paste' is set when it is
11718 * already on.
11719 */
11720 /* set options for each buffer */
11721 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11722 {
11723 buf->b_p_tw = 0; /* textwidth is 0 */
11724 buf->b_p_wm = 0; /* wrapmargin is 0 */
11725 buf->b_p_sts = 0; /* softtabstop is 0 */
11726 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011727 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011728 }
11729
11730 /* set global options */
11731 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011732 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011733#ifdef FEAT_CMDL_INFO
11734# ifdef FEAT_WINDOWS
11735 if (p_ru)
11736 status_redraw_all(); /* redraw to remove the ruler */
11737# endif
11738 p_ru = 0; /* no ruler */
11739#endif
11740#ifdef FEAT_RIGHTLEFT
11741 p_ri = 0; /* no reverse insert */
11742 p_hkmap = 0; /* no Hebrew keyboard */
11743#endif
11744 /* set global values for local buffer options */
11745 p_tw = 0;
11746 p_wm = 0;
11747 p_sts = 0;
11748 p_ai = 0;
11749 }
11750
11751 /*
11752 * Paste switched from on to off: Restore saved values.
11753 */
11754 else if (old_p_paste)
11755 {
11756 /* restore options for each buffer */
11757 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11758 {
11759 buf->b_p_tw = buf->b_p_tw_nopaste;
11760 buf->b_p_wm = buf->b_p_wm_nopaste;
11761 buf->b_p_sts = buf->b_p_sts_nopaste;
11762 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011763 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011764 }
11765
11766 /* restore global options */
11767 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011768 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011769#ifdef FEAT_CMDL_INFO
11770# ifdef FEAT_WINDOWS
11771 if (p_ru != save_ru)
11772 status_redraw_all(); /* redraw to draw the ruler */
11773# endif
11774 p_ru = save_ru;
11775#endif
11776#ifdef FEAT_RIGHTLEFT
11777 p_ri = save_ri;
11778 p_hkmap = save_hkmap;
11779#endif
11780 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011781 p_ai = p_ai_nopaste;
11782 p_et = p_et_nopaste;
11783 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784 p_tw = p_tw_nopaste;
11785 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011786 }
11787
11788 old_p_paste = p_paste;
11789}
11790
11791/*
11792 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11793 *
11794 * Reset 'compatible' and set the values for options that didn't get set yet
11795 * to the Vim defaults.
11796 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011797 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011798 */
11799 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011800vimrc_found(fname, envname)
11801 char_u *fname;
11802 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011803{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011804 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011805 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011806 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807
11808 if (!option_was_set((char_u *)"cp"))
11809 {
11810 p_cp = FALSE;
11811 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11812 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11813 set_option_default(opt_idx, OPT_FREE, FALSE);
11814 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011815 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011817
11818 if (fname != NULL)
11819 {
11820 p = vim_getenv(envname, &dofree);
11821 if (p == NULL)
11822 {
11823 /* Set $MYVIMRC to the first vimrc file found. */
11824 p = FullName_save(fname, FALSE);
11825 if (p != NULL)
11826 {
11827 vim_setenv(envname, p);
11828 vim_free(p);
11829 }
11830 }
11831 else if (dofree)
11832 vim_free(p);
11833 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011834}
11835
11836/*
11837 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11838 */
11839 void
11840change_compatible(on)
11841 int on;
11842{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011843 int opt_idx;
11844
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845 if (p_cp != on)
11846 {
11847 p_cp = on;
11848 compatible_set();
11849 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011850 opt_idx = findoption((char_u *)"cp");
11851 if (opt_idx >= 0)
11852 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011853}
11854
11855/*
11856 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011857 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011858 */
11859 int
11860option_was_set(name)
11861 char_u *name;
11862{
11863 int idx;
11864
11865 idx = findoption(name);
11866 if (idx < 0) /* unknown option */
11867 return FALSE;
11868 if (options[idx].flags & P_WAS_SET)
11869 return TRUE;
11870 return FALSE;
11871}
11872
11873/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011874 * Reset the flag indicating option "name" was set.
11875 */
11876 void
11877reset_option_was_set(name)
11878 char_u *name;
11879{
11880 int idx = findoption(name);
11881
11882 if (idx >= 0)
11883 options[idx].flags &= ~P_WAS_SET;
11884}
11885
11886/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887 * compatible_set() - Called when 'compatible' has been set or unset.
11888 *
11889 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11890 * flag) to a Vi compatible value.
11891 * When 'compatible' is unset: Set all options that have a different default
11892 * for Vim (without the P_VI_DEF flag) to that default.
11893 */
11894 static void
11895compatible_set()
11896{
11897 int opt_idx;
11898
11899 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11900 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11901 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11902 set_option_default(opt_idx, OPT_FREE, p_cp);
11903 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011904 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011905}
11906
11907#ifdef FEAT_LINEBREAK
11908
11909# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11910 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011911 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011912# endif
11913
11914/*
11915 * fill_breakat_flags() -- called when 'breakat' changes value.
11916 */
11917 static void
11918fill_breakat_flags()
11919{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011920 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011921 int i;
11922
11923 for (i = 0; i < 256; i++)
11924 breakat_flags[i] = FALSE;
11925
11926 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011927 for (p = p_breakat; *p; p++)
11928 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011929}
11930
11931# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011932 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933# endif
11934
11935#endif
11936
11937/*
11938 * Check an option that can be a range of string values.
11939 *
11940 * Return OK for correct value, FAIL otherwise.
11941 * Empty is always OK.
11942 */
11943 static int
11944check_opt_strings(val, values, list)
11945 char_u *val;
11946 char **values;
11947 int list; /* when TRUE: accept a list of values */
11948{
11949 return opt_strings_flags(val, values, NULL, list);
11950}
11951
11952/*
11953 * Handle an option that can be a range of string values.
11954 * Set a flag in "*flagp" for each string present.
11955 *
11956 * Return OK for correct value, FAIL otherwise.
11957 * Empty is always OK.
11958 */
11959 static int
11960opt_strings_flags(val, values, flagp, list)
11961 char_u *val; /* new value */
11962 char **values; /* array of valid string values */
11963 unsigned *flagp;
11964 int list; /* when TRUE: accept a list of values */
11965{
11966 int i;
11967 int len;
11968 unsigned new_flags = 0;
11969
11970 while (*val)
11971 {
11972 for (i = 0; ; ++i)
11973 {
11974 if (values[i] == NULL) /* val not found in values[] */
11975 return FAIL;
11976
11977 len = (int)STRLEN(values[i]);
11978 if (STRNCMP(values[i], val, len) == 0
11979 && ((list && val[len] == ',') || val[len] == NUL))
11980 {
11981 val += len + (val[len] == ',');
11982 new_flags |= (1 << i);
11983 break; /* check next item in val list */
11984 }
11985 }
11986 }
11987 if (flagp != NULL)
11988 *flagp = new_flags;
11989
11990 return OK;
11991}
11992
11993/*
11994 * Read the 'wildmode' option, fill wim_flags[].
11995 */
11996 static int
11997check_opt_wim()
11998{
11999 char_u new_wim_flags[4];
12000 char_u *p;
12001 int i;
12002 int idx = 0;
12003
12004 for (i = 0; i < 4; ++i)
12005 new_wim_flags[i] = 0;
12006
12007 for (p = p_wim; *p; ++p)
12008 {
12009 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12010 ;
12011 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12012 return FAIL;
12013 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12014 new_wim_flags[idx] |= WIM_LONGEST;
12015 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12016 new_wim_flags[idx] |= WIM_FULL;
12017 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12018 new_wim_flags[idx] |= WIM_LIST;
12019 else
12020 return FAIL;
12021 p += i;
12022 if (*p == NUL)
12023 break;
12024 if (*p == ',')
12025 {
12026 if (idx == 3)
12027 return FAIL;
12028 ++idx;
12029 }
12030 }
12031
12032 /* fill remaining entries with last flag */
12033 while (idx < 3)
12034 {
12035 new_wim_flags[idx + 1] = new_wim_flags[idx];
12036 ++idx;
12037 }
12038
12039 /* only when there are no errors, wim_flags[] is changed */
12040 for (i = 0; i < 4; ++i)
12041 wim_flags[i] = new_wim_flags[i];
12042 return OK;
12043}
12044
12045/*
12046 * Check if backspacing over something is allowed.
12047 */
12048 int
12049can_bs(what)
12050 int what; /* BS_INDENT, BS_EOL or BS_START */
12051{
12052 switch (*p_bs)
12053 {
12054 case '2': return TRUE;
12055 case '1': return (what != BS_START);
12056 case '0': return FALSE;
12057 }
12058 return vim_strchr(p_bs, what) != NULL;
12059}
12060
12061/*
12062 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12063 * the file must be considered changed when the value is different.
12064 */
12065 void
12066save_file_ff(buf)
12067 buf_T *buf;
12068{
12069 buf->b_start_ffc = *buf->b_p_ff;
12070 buf->b_start_eol = buf->b_p_eol;
12071#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012072 buf->b_start_bomb = buf->b_p_bomb;
12073
Bram Moolenaar071d4272004-06-13 20:20:40 +000012074 /* Only use free/alloc when necessary, they take time. */
12075 if (buf->b_start_fenc == NULL
12076 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12077 {
12078 vim_free(buf->b_start_fenc);
12079 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12080 }
12081#endif
12082}
12083
12084/*
12085 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12086 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012087 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12088 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012089 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012090 * When "ignore_empty" is true don't consider a new, empty buffer to be
12091 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092 */
12093 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012094file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012096 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012097{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012098 /* In a buffer that was never loaded the options are not valid. */
12099 if (buf->b_flags & BF_NEVERLOADED)
12100 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012101 if (ignore_empty
12102 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 && buf->b_ml.ml_line_count == 1
12104 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12105 return FALSE;
12106 if (buf->b_start_ffc != *buf->b_p_ff)
12107 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012108 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109 return TRUE;
12110#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012111 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12112 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012113 if (buf->b_start_fenc == NULL)
12114 return (*buf->b_p_fenc != NUL);
12115 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12116#else
12117 return FALSE;
12118#endif
12119}
12120
12121/*
12122 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12123 */
12124 int
12125check_ff_value(p)
12126 char_u *p;
12127{
12128 return check_opt_strings(p, p_ff_values, FALSE);
12129}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012130
12131/*
12132 * Return the effective shiftwidth value for current buffer, using the
12133 * 'tabstop' value when 'shiftwidth' is zero.
12134 */
12135 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012136get_sw_value(buf)
12137 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012138{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012139 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012140}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012141
12142/*
12143 * Return the effective softtabstop value for the current buffer, using the
12144 * 'tabstop' value when 'softtabstop' is negative.
12145 */
12146 long
12147get_sts_value()
12148{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012149 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012150}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012151
12152/*
12153 * Check matchpairs option for "*initc".
12154 * If there is a match set "*initc" to the matching character and "*findc" to
12155 * the opposite character. Set "*backwards" to the direction.
12156 * When "switchit" is TRUE swap the direction.
12157 */
12158 void
12159find_mps_values(initc, findc, backwards, switchit)
12160 int *initc;
12161 int *findc;
12162 int *backwards;
12163 int switchit;
12164{
12165 char_u *ptr;
12166
12167 ptr = curbuf->b_p_mps;
12168 while (*ptr != NUL)
12169 {
12170#ifdef FEAT_MBYTE
12171 if (has_mbyte)
12172 {
12173 char_u *prev;
12174
12175 if (mb_ptr2char(ptr) == *initc)
12176 {
12177 if (switchit)
12178 {
12179 *findc = *initc;
12180 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12181 *backwards = TRUE;
12182 }
12183 else
12184 {
12185 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12186 *backwards = FALSE;
12187 }
12188 return;
12189 }
12190 prev = ptr;
12191 ptr += mb_ptr2len(ptr) + 1;
12192 if (mb_ptr2char(ptr) == *initc)
12193 {
12194 if (switchit)
12195 {
12196 *findc = *initc;
12197 *initc = mb_ptr2char(prev);
12198 *backwards = FALSE;
12199 }
12200 else
12201 {
12202 *findc = mb_ptr2char(prev);
12203 *backwards = TRUE;
12204 }
12205 return;
12206 }
12207 ptr += mb_ptr2len(ptr);
12208 }
12209 else
12210#endif
12211 {
12212 if (*ptr == *initc)
12213 {
12214 if (switchit)
12215 {
12216 *backwards = TRUE;
12217 *findc = *initc;
12218 *initc = ptr[2];
12219 }
12220 else
12221 {
12222 *backwards = FALSE;
12223 *findc = ptr[2];
12224 }
12225 return;
12226 }
12227 ptr += 2;
12228 if (*ptr == *initc)
12229 {
12230 if (switchit)
12231 {
12232 *backwards = FALSE;
12233 *findc = *initc;
12234 *initc = ptr[-2];
12235 }
12236 else
12237 {
12238 *backwards = TRUE;
12239 *findc = ptr[-2];
12240 }
12241 return;
12242 }
12243 ++ptr;
12244 }
12245 if (*ptr == ',')
12246 ++ptr;
12247 }
12248}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012249
12250#if defined(FEAT_LINEBREAK) || defined(PROTO)
12251/*
12252 * This is called when 'breakindentopt' is changed and when a window is
12253 * initialized.
12254 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012255 static int
12256briopt_check(wp)
12257 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012258{
12259 char_u *p;
12260 int bri_shift = 0;
12261 long bri_min = 20;
12262 int bri_sbr = FALSE;
12263
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012264 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012265 while (*p != NUL)
12266 {
12267 if (STRNCMP(p, "shift:", 6) == 0
12268 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12269 {
12270 p += 6;
12271 bri_shift = getdigits(&p);
12272 }
12273 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12274 {
12275 p += 4;
12276 bri_min = getdigits(&p);
12277 }
12278 else if (STRNCMP(p, "sbr", 3) == 0)
12279 {
12280 p += 3;
12281 bri_sbr = TRUE;
12282 }
12283 if (*p != ',' && *p != NUL)
12284 return FAIL;
12285 if (*p == ',')
12286 ++p;
12287 }
12288
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012289 wp->w_p_brishift = bri_shift;
12290 wp->w_p_brimin = bri_min;
12291 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012292
12293 return OK;
12294}
12295#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012296
12297/*
12298 * Get the local or global value of 'backupcopy'.
12299 */
12300 unsigned int
12301get_bkc_value(buf)
12302 buf_T *buf;
12303{
12304 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12305}