blob: d1bce6ac38e5bac57e84cfe471c5a372d154b700 [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 Moolenaarf9393ef2006-04-24 19:47:27 +00001782#ifdef FEAT_GUI_MAC
1783 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1784 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"magic", NULL, P_BOOL|P_VI_DEF,
1788 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001789 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001790 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791#ifdef FEAT_QUICKFIX
1792 (char_u *)&p_mef, PV_NONE,
1793 {(char_u *)"", (char_u *)0L}
1794#else
1795 (char_u *)NULL, PV_NONE,
1796 {(char_u *)NULL, (char_u *)0L}
1797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001798 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1800#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001801 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001802# ifdef VMS
1803 {(char_u *)"MMS", (char_u *)0L}
1804# else
1805 {(char_u *)"make", (char_u *)0L}
1806# endif
1807#else
1808 (char_u *)NULL, PV_NONE,
1809 {(char_u *)NULL, (char_u *)0L}
1810#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001811 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001812 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1815 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 {"matchtime", "mat", P_NUM|P_VI_DEF,
1817 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001818 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001819 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001820#ifdef FEAT_MBYTE
1821 (char_u *)&p_mco, PV_NONE,
1822#else
1823 (char_u *)NULL, PV_NONE,
1824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001825 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1827#ifdef FEAT_EVAL
1828 (char_u *)&p_mfd, PV_NONE,
1829#else
1830 (char_u *)NULL, PV_NONE,
1831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1834 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001835 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 {"maxmem", "mm", P_NUM|P_VI_DEF,
1837 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1839 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001840 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1841 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001843 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1844 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1846 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001847 {"menuitems", "mis", P_NUM|P_VI_DEF,
1848#ifdef FEAT_MENU
1849 (char_u *)&p_mis, PV_NONE,
1850#else
1851 (char_u *)NULL, PV_NONE,
1852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854 {"mesg", NULL, P_BOOL|P_VI_DEF,
1855 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001856 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001857 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001858#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001859 (char_u *)&p_msm, PV_NONE,
1860 {(char_u *)"460000,2000,500", (char_u *)0L}
1861#else
1862 (char_u *)NULL, PV_NONE,
1863 {(char_u *)0L, (char_u *)0L}
1864#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001865 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 {"modeline", "ml", P_BOOL|P_VIM,
1867 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"modelines", "mls", P_NUM|P_VI_DEF,
1870 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1873 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001874 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001875 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1876 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"more", NULL, P_BOOL|P_VIM,
1879 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1882 (char_u *)&p_mouse, PV_NONE,
1883 {
1884#if defined(MSDOS) || defined(WIN3264)
1885 (char_u *)"a",
1886#else
1887 (char_u *)"",
1888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001889 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1891#ifdef FEAT_GUI
1892 (char_u *)&p_mousef, PV_NONE,
1893#else
1894 (char_u *)NULL, PV_NONE,
1895#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1898#ifdef FEAT_GUI
1899 (char_u *)&p_mh, PV_NONE,
1900#else
1901 (char_u *)NULL, PV_NONE,
1902#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001903 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001904 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1905 (char_u *)&p_mousem, PV_NONE,
1906 {
1907#if defined(MSDOS) || defined(MSWIN)
1908 (char_u *)"popup",
1909#else
1910# if defined(MACOS)
1911 (char_u *)"popup_setpos",
1912# else
1913 (char_u *)"extend",
1914# endif
1915#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001916 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001917 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918#ifdef FEAT_MOUSESHAPE
1919 (char_u *)&p_mouseshape, PV_NONE,
1920 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1921#else
1922 (char_u *)NULL, PV_NONE,
1923 {(char_u *)NULL, (char_u *)0L}
1924#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1927 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001929 {"mzquantum", "mzq", P_NUM,
1930#ifdef FEAT_MZSCHEME
1931 (char_u *)&p_mzq, PV_NONE,
1932#else
1933 (char_u *)NULL, PV_NONE,
1934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"novice", NULL, P_BOOL|P_VI_DEF,
1937 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001939 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001940 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)"octal,hex", (char_u *)0L}
1942 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1944 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001945 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001946 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1947#ifdef FEAT_LINEBREAK
1948 (char_u *)VAR_WIN, PV_NUW,
1949#else
1950 (char_u *)NULL, PV_NONE,
1951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001953 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001954#ifdef FEAT_COMPL_FUNC
1955 (char_u *)&p_ofu, PV_OFU,
1956 {(char_u *)"", (char_u *)0L}
1957#else
1958 (char_u *)NULL, PV_NONE,
1959 {(char_u *)0L, (char_u *)0L}
1960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"open", NULL, P_BOOL|P_VI_DEF,
1963 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001965 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1966#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1967 (char_u *)&p_odev, PV_NONE,
1968#else
1969 (char_u *)NULL, PV_NONE,
1970#endif
1971 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001973 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1974 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 {"optimize", "opt", P_BOOL|P_VI_DEF,
1977 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001981 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"paragraphs", "para", P_STRING|P_VI_DEF,
1983 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001984 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001986 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1990 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1993#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1994 (char_u *)&p_pex, PV_NONE,
1995 {(char_u *)"", (char_u *)0L}
1996#else
1997 (char_u *)NULL, PV_NONE,
1998 {(char_u *)0L, (char_u *)0L}
1999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002001 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002003 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002005 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {
2007#if defined AMIGA || defined MSDOS || defined MSWIN
2008 (char_u *)".,,",
2009#else
2010# if defined(__EMX__)
2011 (char_u *)".,/emx/include,,",
2012# else /* Unix, probably */
2013 (char_u *)".,/usr/include,,",
2014# endif
2015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002016 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2018 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002019 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002020 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2022 (char_u *)&p_pvh, PV_NONE,
2023#else
2024 (char_u *)NULL, PV_NONE,
2025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002026 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2028#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2029 (char_u *)VAR_WIN, PV_PVW,
2030#else
2031 (char_u *)NULL, PV_NONE,
2032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002034 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035#ifdef FEAT_PRINTER
2036 (char_u *)&p_pdev, PV_NONE,
2037 {(char_u *)"", (char_u *)0L}
2038#else
2039 (char_u *)NULL, PV_NONE,
2040 {(char_u *)NULL, (char_u *)0L}
2041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"printencoding", "penc", P_STRING|P_VI_DEF,
2044#ifdef FEAT_POSTSCRIPT
2045 (char_u *)&p_penc, PV_NONE,
2046 {(char_u *)"", (char_u *)0L}
2047#else
2048 (char_u *)NULL, PV_NONE,
2049 {(char_u *)NULL, (char_u *)0L}
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2053#ifdef FEAT_POSTSCRIPT
2054 (char_u *)&p_pexpr, PV_NONE,
2055 {(char_u *)"", (char_u *)0L}
2056#else
2057 (char_u *)NULL, PV_NONE,
2058 {(char_u *)NULL, (char_u *)0L}
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"printfont", "pfn", P_STRING|P_VI_DEF,
2062#ifdef FEAT_PRINTER
2063 (char_u *)&p_pfn, PV_NONE,
2064 {
2065# ifdef MSWIN
2066 (char_u *)"Courier_New:h10",
2067# else
2068 (char_u *)"courier",
2069# endif
2070 (char_u *)0L}
2071#else
2072 (char_u *)NULL, PV_NONE,
2073 {(char_u *)NULL, (char_u *)0L}
2074#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002075 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2077#ifdef FEAT_PRINTER
2078 (char_u *)&p_header, PV_NONE,
2079 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2080#else
2081 (char_u *)NULL, PV_NONE,
2082 {(char_u *)NULL, (char_u *)0L}
2083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002085 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2086#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2087 (char_u *)&p_pmcs, PV_NONE,
2088 {(char_u *)"", (char_u *)0L}
2089#else
2090 (char_u *)NULL, PV_NONE,
2091 {(char_u *)NULL, (char_u *)0L}
2092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002094 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2095#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2096 (char_u *)&p_pmfn, PV_NONE,
2097 {(char_u *)"", (char_u *)0L}
2098#else
2099 (char_u *)NULL, PV_NONE,
2100 {(char_u *)NULL, (char_u *)0L}
2101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002103 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104#ifdef FEAT_PRINTER
2105 (char_u *)&p_popt, PV_NONE,
2106 {(char_u *)"", (char_u *)0L}
2107#else
2108 (char_u *)NULL, PV_NONE,
2109 {(char_u *)NULL, (char_u *)0L}
2110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002112 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002113 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002115 {"pumheight", "ph", P_NUM|P_VI_DEF,
2116#ifdef FEAT_INS_EXPAND
2117 (char_u *)&p_ph, PV_NONE,
2118#else
2119 (char_u *)NULL, PV_NONE,
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002122 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2123#ifdef FEAT_TEXTOBJ
2124 (char_u *)&p_qe, PV_QE,
2125 {(char_u *)"\\", (char_u *)0L}
2126#else
2127 (char_u *)NULL, PV_NONE,
2128 {(char_u *)NULL, (char_u *)0L}
2129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2132 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 {"redraw", NULL, P_BOOL|P_VI_DEF,
2135 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002136 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002137 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2138#ifdef FEAT_RELTIME
2139 (char_u *)&p_rdt, PV_NONE,
2140#else
2141 (char_u *)NULL, PV_NONE,
2142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002144 {"regexpengine", "re", P_NUM|P_VI_DEF,
2145 (char_u *)&p_re, PV_NONE,
2146 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002147 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2148 (char_u *)VAR_WIN, PV_RNU,
2149 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150 {"remap", NULL, P_BOOL|P_VI_DEF,
2151 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002153 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002154#ifdef FEAT_RENDER_OPTIONS
2155 (char_u *)&p_rop, PV_NONE,
2156 {(char_u *)"", (char_u *)0L}
2157#else
2158 (char_u *)NULL, PV_NONE,
2159 {(char_u *)NULL, (char_u *)0L}
2160#endif
2161 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162 {"report", NULL, P_NUM|P_VI_DEF,
2163 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002164 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2166#ifdef WIN3264
2167 (char_u *)&p_rs, PV_NONE,
2168#else
2169 (char_u *)NULL, PV_NONE,
2170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002171 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2173#ifdef FEAT_RIGHTLEFT
2174 (char_u *)&p_ri, PV_NONE,
2175#else
2176 (char_u *)NULL, PV_NONE,
2177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2180#ifdef FEAT_RIGHTLEFT
2181 (char_u *)VAR_WIN, PV_RL,
2182#else
2183 (char_u *)NULL, PV_NONE,
2184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2187#ifdef FEAT_RIGHTLEFT
2188 (char_u *)VAR_WIN, PV_RLC,
2189 {(char_u *)"search", (char_u *)NULL}
2190#else
2191 (char_u *)NULL, PV_NONE,
2192 {(char_u *)NULL, (char_u *)0L}
2193#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002194 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002195 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2196#ifdef FEAT_CMDL_INFO
2197 (char_u *)&p_ru, PV_NONE,
2198#else
2199 (char_u *)NULL, PV_NONE,
2200#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002201 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002202 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2203#ifdef FEAT_STL_OPT
2204 (char_u *)&p_ruf, PV_NONE,
2205#else
2206 (char_u *)NULL, PV_NONE,
2207#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002208 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002209 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2210 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002212 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2213 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002214 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2215 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2218#ifdef FEAT_SCROLLBIND
2219 (char_u *)VAR_WIN, PV_SCBIND,
2220#else
2221 (char_u *)NULL, PV_NONE,
2222#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002223 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2225 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002226 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2228 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002230 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231#ifdef FEAT_SCROLLBIND
2232 (char_u *)&p_sbo, PV_NONE,
2233 {(char_u *)"ver,jump", (char_u *)0L}
2234#else
2235 (char_u *)NULL, PV_NONE,
2236 {(char_u *)0L, (char_u *)0L}
2237#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002238 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"sections", "sect", P_STRING|P_VI_DEF,
2240 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2242 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2244 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002245 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002246 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002248 {(char_u *)"inclusive", (char_u *)0L}
2249 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002250 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002252 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002253 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254#ifdef FEAT_SESSION
2255 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002256 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002257 (char_u *)0L}
2258#else
2259 (char_u *)NULL, PV_NONE,
2260 {(char_u *)0L, (char_u *)0L}
2261#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002262 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2264 (char_u *)&p_sh, PV_NONE,
2265 {
2266#ifdef VMS
2267 (char_u *)"-",
2268#else
2269# if defined(MSDOS)
2270 (char_u *)"command",
2271# else
2272# if defined(WIN16)
2273 (char_u *)"command.com",
2274# else
2275# if defined(WIN3264)
2276 (char_u *)"", /* set in set_init_1() */
2277# else
2278# if defined(OS2)
2279 (char_u *)"cmd.exe",
2280# else
2281# if defined(ARCHIE)
2282 (char_u *)"gos",
2283# else
2284 (char_u *)"sh",
2285# endif
2286# endif
2287# endif
2288# endif
2289# endif
2290#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002291 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2293 (char_u *)&p_shcf, PV_NONE,
2294 {
2295#if defined(MSDOS) || defined(MSWIN)
2296 (char_u *)"/c",
2297#else
2298# if defined(OS2)
2299 (char_u *)"/c",
2300# else
2301 (char_u *)"-c",
2302# endif
2303#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2306#ifdef FEAT_QUICKFIX
2307 (char_u *)&p_sp, PV_NONE,
2308 {
2309#if defined(UNIX) || defined(OS2)
2310# ifdef ARCHIE
2311 (char_u *)"2>",
2312# else
2313 (char_u *)"| tee",
2314# endif
2315#else
2316 (char_u *)">",
2317#endif
2318 (char_u *)0L}
2319#else
2320 (char_u *)NULL, PV_NONE,
2321 {(char_u *)0L, (char_u *)0L}
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2325 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2328 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2331#ifdef BACKSLASH_IN_FILENAME
2332 (char_u *)&p_ssl, PV_NONE,
2333#else
2334 (char_u *)NULL, PV_NONE,
2335#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002337 {"shelltemp", "stmp", P_BOOL,
2338 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"shelltype", "st", P_NUM|P_VI_DEF,
2341#ifdef AMIGA
2342 (char_u *)&p_st, PV_NONE,
2343#else
2344 (char_u *)NULL, PV_NONE,
2345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2348 (char_u *)&p_sxq, PV_NONE,
2349 {
2350#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2351 (char_u *)"\"",
2352#else
2353 (char_u *)"",
2354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002356 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2357 (char_u *)&p_sxe, PV_NONE,
2358 {
2359#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2360 (char_u *)"\"&|<>()@^",
2361#else
2362 (char_u *)"",
2363#endif
2364 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2366 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2369 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2372 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)"", (char_u *)"filnxtToO"}
2374 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"shortname", "sn", P_BOOL|P_VI_DEF,
2376#ifdef SHORT_FNAME
2377 (char_u *)NULL, PV_NONE,
2378#else
2379 (char_u *)&p_sn, PV_SN,
2380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2383#ifdef FEAT_LINEBREAK
2384 (char_u *)&p_sbr, PV_NONE,
2385#else
2386 (char_u *)NULL, PV_NONE,
2387#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"showcmd", "sc", P_BOOL|P_VIM,
2390#ifdef FEAT_CMDL_INFO
2391 (char_u *)&p_sc, PV_NONE,
2392#else
2393 (char_u *)NULL, PV_NONE,
2394#endif
2395 {(char_u *)FALSE,
2396#ifdef UNIX
2397 (char_u *)FALSE
2398#else
2399 (char_u *)TRUE
2400#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002401 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2403 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2406 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"showmode", "smd", P_BOOL|P_VIM,
2409 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002411 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2412#ifdef FEAT_WINDOWS
2413 (char_u *)&p_stal, PV_NONE,
2414#else
2415 (char_u *)NULL, PV_NONE,
2416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002417 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2419 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002420 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2422 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2425 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2428 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2431#ifdef FEAT_SMARTINDENT
2432 (char_u *)&p_si, PV_SI,
2433#else
2434 (char_u *)NULL, PV_NONE,
2435#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2438 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2441 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2444 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002446 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002447#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002448 (char_u *)VAR_WIN, PV_SPELL,
2449#else
2450 (char_u *)NULL, PV_NONE,
2451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002453 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002454#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002455 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002456 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002457#else
2458 (char_u *)NULL, PV_NONE,
2459 {(char_u *)0L, (char_u *)0L}
2460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002462 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2463 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002464#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002465 (char_u *)&p_spf, PV_SPF,
2466 {(char_u *)"", (char_u *)0L}
2467#else
2468 (char_u *)NULL, PV_NONE,
2469 {(char_u *)0L, (char_u *)0L}
2470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002471 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002472 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2473 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002474#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002475 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002476 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002477#else
2478 (char_u *)NULL, PV_NONE,
2479 {(char_u *)0L, (char_u *)0L}
2480#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002482 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002483#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002484 (char_u *)&p_sps, PV_NONE,
2485 {(char_u *)"best", (char_u *)0L}
2486#else
2487 (char_u *)NULL, PV_NONE,
2488 {(char_u *)0L, (char_u *)0L}
2489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002490 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2492#ifdef FEAT_WINDOWS
2493 (char_u *)&p_sb, PV_NONE,
2494#else
2495 (char_u *)NULL, PV_NONE,
2496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"splitright", "spr", P_BOOL|P_VI_DEF,
2499#ifdef FEAT_VERTSPLIT
2500 (char_u *)&p_spr, PV_NONE,
2501#else
2502 (char_u *)NULL, PV_NONE,
2503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2506 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2509#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002510 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511#else
2512 (char_u *)NULL, PV_NONE,
2513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002515 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 (char_u *)&p_su, PV_NONE,
2517 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002519 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002520#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 (char_u *)&p_sua, PV_SUA,
2522 {(char_u *)"", (char_u *)0L}
2523#else
2524 (char_u *)NULL, PV_NONE,
2525 {(char_u *)0L, (char_u *)0L}
2526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2529 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002530 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"swapsync", "sws", P_STRING|P_VI_DEF,
2532 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002534 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002537 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2538#ifdef FEAT_SYN_HL
2539 (char_u *)&p_smc, PV_SMC,
2540 {(char_u *)3000L, (char_u *)0L}
2541#else
2542 (char_u *)NULL, PV_NONE,
2543 {(char_u *)0L, (char_u *)0L}
2544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002546 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547#ifdef FEAT_SYN_HL
2548 (char_u *)&p_syn, PV_SYN,
2549 {(char_u *)"", (char_u *)0L}
2550#else
2551 (char_u *)NULL, PV_NONE,
2552 {(char_u *)0L, (char_u *)0L}
2553#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002554 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002555 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2556#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002557 (char_u *)&p_tal, PV_NONE,
2558#else
2559 (char_u *)NULL, PV_NONE,
2560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002562 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2563#ifdef FEAT_WINDOWS
2564 (char_u *)&p_tpm, PV_NONE,
2565#else
2566 (char_u *)NULL, PV_NONE,
2567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2570 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2573 (char_u *)&p_tbs, PV_NONE,
2574#ifdef VMS /* binary searching doesn't appear to work on VMS */
2575 {(char_u *)0L, (char_u *)0L}
2576#else
2577 {(char_u *)TRUE, (char_u *)0L}
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"taglength", "tl", P_NUM|P_VI_DEF,
2581 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"tagrelative", "tr", P_BOOL|P_VIM,
2584 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002586 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002587 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588 {
2589#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2590 (char_u *)"./tags,./TAGS,tags,TAGS",
2591#else
2592 (char_u *)"./tags,tags",
2593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2596 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2599 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2602#ifdef FEAT_ARABIC
2603 (char_u *)&p_tbidi, PV_NONE,
2604#else
2605 (char_u *)NULL, PV_NONE,
2606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2609#ifdef FEAT_MBYTE
2610 (char_u *)&p_tenc, PV_NONE,
2611 {(char_u *)"", (char_u *)0L}
2612#else
2613 (char_u *)NULL, PV_NONE,
2614 {(char_u *)0L, (char_u *)0L}
2615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"terse", NULL, P_BOOL|P_VI_DEF,
2618 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"textauto", "ta", P_BOOL|P_VIM,
2621 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2623 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2625 (char_u *)&p_tx, PV_TX,
2626 {
2627#ifdef USE_CRNL
2628 (char_u *)TRUE,
2629#else
2630 (char_u *)FALSE,
2631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002633 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002635 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002636 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002638 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639#else
2640 (char_u *)NULL, PV_NONE,
2641#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2644 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"timeout", "to", P_BOOL|P_VI_DEF,
2647 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2650 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"title", NULL, P_BOOL|P_VI_DEF,
2653#ifdef FEAT_TITLE
2654 (char_u *)&p_title, PV_NONE,
2655#else
2656 (char_u *)NULL, PV_NONE,
2657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 {"titlelen", NULL, P_NUM|P_VI_DEF,
2660#ifdef FEAT_TITLE
2661 (char_u *)&p_titlelen, PV_NONE,
2662#else
2663 (char_u *)NULL, PV_NONE,
2664#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002666 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667#ifdef FEAT_TITLE
2668 (char_u *)&p_titleold, PV_NONE,
2669 {(char_u *)N_("Thanks for flying Vim"),
2670 (char_u *)0L}
2671#else
2672 (char_u *)NULL, PV_NONE,
2673 {(char_u *)0L, (char_u *)0L}
2674#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002676 {"titlestring", NULL, P_STRING|P_VI_DEF,
2677#ifdef FEAT_TITLE
2678 (char_u *)&p_titlestring, PV_NONE,
2679#else
2680 (char_u *)NULL, PV_NONE,
2681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002684 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002686 {(char_u *)"icons,tooltips", (char_u *)0L}
2687 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002689#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2691 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002692 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693#endif
2694 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2695 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2698 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2701 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002702 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2704 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002705 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2707#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2708 (char_u *)&p_ttym, PV_NONE,
2709#else
2710 (char_u *)NULL, PV_NONE,
2711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2714 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2717 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002719 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2720 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002721#ifdef FEAT_PERSISTENT_UNDO
2722 (char_u *)&p_udir, PV_NONE,
2723 {(char_u *)".", (char_u *)0L}
2724#else
2725 (char_u *)NULL, PV_NONE,
2726 {(char_u *)0L, (char_u *)0L}
2727#endif
2728 SCRIPTID_INIT},
2729 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2730#ifdef FEAT_PERSISTENT_UNDO
2731 (char_u *)&p_udf, PV_UDF,
2732#else
2733 (char_u *)NULL, PV_NONE,
2734#endif
2735 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002737 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {
2739#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2740 (char_u *)1000L,
2741#else
2742 (char_u *)100L,
2743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002745 {"undoreload", "ur", P_NUM|P_VI_DEF,
2746 (char_u *)&p_ur, PV_NONE,
2747 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"updatecount", "uc", P_NUM|P_VI_DEF,
2749 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002750 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"updatetime", "ut", P_NUM|P_VI_DEF,
2752 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002753 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {"verbose", "vbs", P_NUM|P_VI_DEF,
2755 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002756 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002757 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2758 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002759 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2761#ifdef FEAT_SESSION
2762 (char_u *)&p_vdir, PV_NONE,
2763 {(char_u *)DFLT_VDIR, (char_u *)0L}
2764#else
2765 (char_u *)NULL, PV_NONE,
2766 {(char_u *)0L, (char_u *)0L}
2767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002769 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770#ifdef FEAT_SESSION
2771 (char_u *)&p_vop, PV_NONE,
2772 {(char_u *)"folds,options,cursor", (char_u *)0L}
2773#else
2774 (char_u *)NULL, PV_NONE,
2775 {(char_u *)0L, (char_u *)0L}
2776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002778 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779#ifdef FEAT_VIMINFO
2780 (char_u *)&p_viminfo, PV_NONE,
2781#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002782 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783#else
2784# ifdef AMIGA
2785 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002786 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002788 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789# endif
2790#endif
2791#else
2792 (char_u *)NULL, PV_NONE,
2793 {(char_u *)0L, (char_u *)0L}
2794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002796 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2797 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798#ifdef FEAT_VIRTUALEDIT
2799 (char_u *)&p_ve, PV_NONE,
2800 {(char_u *)"", (char_u *)""}
2801#else
2802 (char_u *)NULL, PV_NONE,
2803 {(char_u *)0L, (char_u *)0L}
2804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2807 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"w300", NULL, P_NUM|P_VI_DEF,
2810 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"w1200", NULL, P_NUM|P_VI_DEF,
2813 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002814 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"w9600", NULL, P_NUM|P_VI_DEF,
2816 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002817 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"warn", NULL, P_BOOL|P_VI_DEF,
2819 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2822 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002823 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002824 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"wildchar", "wc", P_NUM|P_VIM,
2828 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2830 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002831 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002834 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835#ifdef FEAT_WILDIGN
2836 (char_u *)&p_wig, PV_NONE,
2837#else
2838 (char_u *)NULL, PV_NONE,
2839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002841 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2842 (char_u *)&p_wic, PV_NONE,
2843 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2845#ifdef FEAT_WILDMENU
2846 (char_u *)&p_wmnu, PV_NONE,
2847#else
2848 (char_u *)NULL, PV_NONE,
2849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002851 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002854 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2855#ifdef FEAT_CMDL_COMPL
2856 (char_u *)&p_wop, PV_NONE,
2857 {(char_u *)"", (char_u *)0L}
2858#else
2859 (char_u *)NULL, PV_NONE,
2860 {(char_u *)NULL, (char_u *)0L}
2861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2864#ifdef FEAT_WAK
2865 (char_u *)&p_wak, PV_NONE,
2866 {(char_u *)"menu", (char_u *)0L}
2867#else
2868 (char_u *)NULL, PV_NONE,
2869 {(char_u *)NULL, (char_u *)0L}
2870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002873 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002874 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 {"winheight", "wh", P_NUM|P_VI_DEF,
2876#ifdef FEAT_WINDOWS
2877 (char_u *)&p_wh, PV_NONE,
2878#else
2879 (char_u *)NULL, PV_NONE,
2880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002883#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 (char_u *)VAR_WIN, PV_WFH,
2885#else
2886 (char_u *)NULL, PV_NONE,
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002889 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2890#ifdef FEAT_VERTSPLIT
2891 (char_u *)VAR_WIN, PV_WFW,
2892#else
2893 (char_u *)NULL, PV_NONE,
2894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002895 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2897#ifdef FEAT_WINDOWS
2898 (char_u *)&p_wmh, PV_NONE,
2899#else
2900 (char_u *)NULL, PV_NONE,
2901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002902 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2904#ifdef FEAT_VERTSPLIT
2905 (char_u *)&p_wmw, PV_NONE,
2906#else
2907 (char_u *)NULL, PV_NONE,
2908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2911#ifdef FEAT_VERTSPLIT
2912 (char_u *)&p_wiw, PV_NONE,
2913#else
2914 (char_u *)NULL, PV_NONE,
2915#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2918 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2921 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2924 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926 {"write", NULL, P_BOOL|P_VI_DEF,
2927 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002928 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {"writeany", "wa", P_BOOL|P_VI_DEF,
2930 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002931 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2933 (char_u *)&p_wb, PV_NONE,
2934 {
2935#ifdef FEAT_WRITEBACKUP
2936 (char_u *)TRUE,
2937#else
2938 (char_u *)FALSE,
2939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002940 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 {"writedelay", "wd", P_NUM|P_VI_DEF,
2942 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002943 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944
2945/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002946#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949
2950 p_term("t_AB", T_CAB)
2951 p_term("t_AF", T_CAF)
2952 p_term("t_AL", T_CAL)
2953 p_term("t_al", T_AL)
2954 p_term("t_bc", T_BC)
2955 p_term("t_cd", T_CD)
2956 p_term("t_ce", T_CE)
2957 p_term("t_cl", T_CL)
2958 p_term("t_cm", T_CM)
2959 p_term("t_Co", T_CCO)
2960 p_term("t_CS", T_CCS)
2961 p_term("t_cs", T_CS)
2962#ifdef FEAT_VERTSPLIT
2963 p_term("t_CV", T_CSV)
2964#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 p_term("t_da", T_DA)
2966 p_term("t_db", T_DB)
2967 p_term("t_DL", T_CDL)
2968 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002969 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 p_term("t_fs", T_FS)
2971 p_term("t_IE", T_CIE)
2972 p_term("t_IS", T_CIS)
2973 p_term("t_ke", T_KE)
2974 p_term("t_ks", T_KS)
2975 p_term("t_le", T_LE)
2976 p_term("t_mb", T_MB)
2977 p_term("t_md", T_MD)
2978 p_term("t_me", T_ME)
2979 p_term("t_mr", T_MR)
2980 p_term("t_ms", T_MS)
2981 p_term("t_nd", T_ND)
2982 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002983 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984 p_term("t_RI", T_CRI)
2985 p_term("t_RV", T_CRV)
2986 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002988 p_term("t_Sf", T_CSF)
2989 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02002991 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 p_term("t_te", T_TE)
2994 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02002995 p_term("t_ts", T_TS)
2996 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 p_term("t_ue", T_UE)
2998 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02002999 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 p_term("t_vb", T_VB)
3001 p_term("t_ve", T_VE)
3002 p_term("t_vi", T_VI)
3003 p_term("t_vs", T_VS)
3004 p_term("t_WP", T_CWP)
3005 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003006 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 p_term("t_xs", T_XS)
3008 p_term("t_ZH", T_CZH)
3009 p_term("t_ZR", T_CZR)
3010
3011/* terminal key codes are not in here */
3012
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003013 /* end marker */
3014 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015};
3016
3017#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3018
3019#ifdef FEAT_MBYTE
3020static char *(p_ambw_values[]) = {"single", "double", NULL};
3021#endif
3022static char *(p_bg_values[]) = {"light", "dark", NULL};
3023static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3024static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003025#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003026static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003027#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003028#ifdef FEAT_CMDL_COMPL
3029static char *(p_wop_values[]) = {"tagfile", NULL};
3030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031#ifdef FEAT_WAK
3032static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3033#endif
3034static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3036static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038#ifdef FEAT_BROWSE
3039static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3040#endif
3041#ifdef FEAT_SCROLLBIND
3042static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3043#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003044static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045#ifdef FEAT_VERTSPLIT
3046static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3047#endif
3048#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003049# ifdef FEAT_AUTOCMD
3050static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3051# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003053# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3055#endif
3056static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3057#ifdef FEAT_FOLDING
3058static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003059# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003061# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062 NULL};
3063static char *(p_fcl_values[]) = {"all", NULL};
3064#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003065#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003066static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003067#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068
3069static void set_option_default __ARGS((int, int opt_flags, int compatible));
3070static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003071static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003072static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073static char_u *illegal_char __ARGS((char_u *, int));
3074static int string_to_key __ARGS((char_u *arg));
3075#ifdef FEAT_CMDWIN
3076static char_u *check_cedit __ARGS((void));
3077#endif
3078#ifdef FEAT_TITLE
3079static void did_set_title __ARGS((int icon));
3080#endif
3081static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3082static void didset_options __ARGS((void));
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003083static void didset_options2 __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003085#if defined(FEAT_EVAL) || defined(PROTO)
3086static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3087#else
3088# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3089#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003091static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092static 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));
3093static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003094#ifdef FEAT_SYN_HL
3095static int int_cmp __ARGS((const void *a, const void *b));
3096#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097#ifdef FEAT_CLIPBOARD
3098static char_u *check_clipboard_option __ARGS((void));
3099#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003100#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003101static char_u *did_set_spell_option __ARGS((int is_spellfile));
Bram Moolenaar860cae12010-06-05 23:22:07 +02003102static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003103#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003104#ifdef FEAT_EVAL
3105static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3106#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003108static 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 +00003109static void check_redraw __ARGS((long_u flags));
3110static int findoption __ARGS((char_u *));
3111static int find_key_option __ARGS((char_u *));
3112static void showoptions __ARGS((int all, int opt_flags));
3113static int optval_default __ARGS((struct vimoption *, char_u *varp));
3114static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3115static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3116static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3117static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3118static int istermoption __ARGS((struct vimoption *));
3119static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3120static char_u *get_varp __ARGS((struct vimoption *));
3121static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003122static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3124#ifdef FEAT_LANGMAP
3125static void langmap_init __ARGS((void));
3126static void langmap_set __ARGS((void));
3127#endif
3128static void paste_option_changed __ARGS((void));
3129static void compatible_set __ARGS((void));
3130#ifdef FEAT_LINEBREAK
3131static void fill_breakat_flags __ARGS((void));
3132#endif
3133static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3134static int check_opt_strings __ARGS((char_u *val, char **values, int));
3135static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003136#ifdef FEAT_LINEBREAK
3137static int briopt_check __ARGS((win_T *wp));
3138#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139
3140/*
3141 * Initialize the options, first part.
3142 *
3143 * Called only once from main(), just after creating the first buffer.
3144 */
3145 void
3146set_init_1()
3147{
3148 char_u *p;
3149 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003150 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151
3152#ifdef FEAT_LANGMAP
3153 langmap_init();
3154#endif
3155
3156 /* Be Vi compatible by default */
3157 p_cp = TRUE;
3158
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003159 /* Use POSIX compatibility when $VIM_POSIX is set. */
3160 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003161 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003162 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003163 set_string_default("shm", (char_u *)"A");
3164 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003165
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 /*
3167 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003168 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003170 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3172# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003173 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003175 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003177 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178# endif
3179#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003180 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 set_string_default("sh", p);
3182
3183#ifdef FEAT_WILDIGN
3184 /*
3185 * Set the default for 'backupskip' to include environment variables for
3186 * temp files.
3187 */
3188 {
3189# ifdef UNIX
3190 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3191# else
3192 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3193# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003194 int len;
3195 garray_T ga;
3196 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197
3198 ga_init2(&ga, 1, 100);
3199 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3200 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003201 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202# ifdef UNIX
3203 if (*names[n] == NUL)
3204 p = (char_u *)"/tmp";
3205 else
3206# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003207 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208 if (p != NULL && *p != NUL)
3209 {
3210 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003211 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 if (ga_grow(&ga, len) == OK)
3213 {
3214 if (ga.ga_len > 0)
3215 STRCAT(ga.ga_data, ",");
3216 STRCAT(ga.ga_data, p);
3217 add_pathsep(ga.ga_data);
3218 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 ga.ga_len += len;
3220 }
3221 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003222 if (mustfree)
3223 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224 }
3225 if (ga.ga_data != NULL)
3226 {
3227 set_string_default("bsk", ga.ga_data);
3228 vim_free(ga.ga_data);
3229 }
3230 }
3231#endif
3232
3233 /*
3234 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3235 */
3236 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003237 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003239#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3240 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3241#endif
3242 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003244 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003245 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246#else
3247# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003248 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003249 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003251 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252# endif
3253#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003255 opt_idx = findoption((char_u *)"maxmem");
3256 if (opt_idx >= 0)
3257 {
3258#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003259 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003260 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3261#endif
3262 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3263 }
3264 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265 }
3266
3267#ifdef FEAT_GUI_W32
3268 /* force 'shortname' for Win32s */
3269 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003270 {
3271 opt_idx = findoption((char_u *)"shortname");
3272 if (opt_idx >= 0)
3273 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3274 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275#endif
3276
3277#ifdef FEAT_SEARCHPATH
3278 {
3279 char_u *cdpath;
3280 char_u *buf;
3281 int i;
3282 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003283 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284
3285 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003286 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287 if (cdpath != NULL)
3288 {
3289 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3290 if (buf != NULL)
3291 {
3292 buf[0] = ','; /* start with ",", current dir first */
3293 j = 1;
3294 for (i = 0; cdpath[i] != NUL; ++i)
3295 {
3296 if (vim_ispathlistsep(cdpath[i]))
3297 buf[j++] = ',';
3298 else
3299 {
3300 if (cdpath[i] == ' ' || cdpath[i] == ',')
3301 buf[j++] = '\\';
3302 buf[j++] = cdpath[i];
3303 }
3304 }
3305 buf[j] = NUL;
3306 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003307 if (opt_idx >= 0)
3308 {
3309 options[opt_idx].def_val[VI_DEFAULT] = buf;
3310 options[opt_idx].flags |= P_DEF_ALLOCED;
3311 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003312 else
3313 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003315 if (mustfree)
3316 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317 }
3318 }
3319#endif
3320
3321#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3322 /* Set print encoding on platforms that don't default to latin1 */
3323 set_string_default("penc",
3324# if defined(MSWIN) || defined(OS2)
3325 (char_u *)"cp1252"
3326# else
3327# ifdef VMS
3328 (char_u *)"dec-mcs"
3329# else
3330# ifdef EBCDIC
3331 (char_u *)"ebcdic-uk"
3332# else
3333# ifdef MAC
3334 (char_u *)"mac-roman"
3335# else /* HPUX */
3336 (char_u *)"hp-roman8"
3337# endif
3338# endif
3339# endif
3340# endif
3341 );
3342#endif
3343
3344#ifdef FEAT_POSTSCRIPT
3345 /* 'printexpr' must be allocated to be able to evaluate it. */
3346 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003347# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3348 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349# else
3350# ifdef VMS
3351 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3352
3353# else
3354 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3355# endif
3356# endif
3357 );
3358#endif
3359
3360 /*
3361 * Set all the options (except the terminal options) to their default
3362 * value. Also set the global value for local options.
3363 */
3364 set_options_default(0);
3365
3366#ifdef FEAT_GUI
3367 if (found_reverse_arg)
3368 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3369#endif
3370
3371 curbuf->b_p_initialized = TRUE;
3372 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003373 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374 check_buf_options(curbuf);
3375 check_win_options(curwin);
3376 check_options();
3377
3378 /* Must be before option_expand(), because that one needs vim_isIDc() */
3379 didset_options();
3380
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003381#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003382 /* Use the current chartab for the generic chartab. This is not in
3383 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003384 init_spell_chartab();
3385#endif
3386
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 /*
3388 * Expand environment variables and things like "~" for the defaults.
3389 * If option_expand() returns non-NULL the variable is expanded. This can
3390 * only happen for non-indirect options.
3391 * Also set the default to the expanded value, so ":set" does not list
3392 * them.
3393 * Don't set the P_ALLOCED flag, because we don't want to free the
3394 * default.
3395 */
3396 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3397 {
3398 if ((options[opt_idx].flags & P_GETTEXT)
3399 && options[opt_idx].var != NULL)
3400 p = (char_u *)_(*(char **)options[opt_idx].var);
3401 else
3402 p = option_expand(opt_idx, NULL);
3403 if (p != NULL && (p = vim_strsave(p)) != NULL)
3404 {
3405 *(char_u **)options[opt_idx].var = p;
3406 /* VIMEXP
3407 * Defaults for all expanded options are currently the same for Vi
3408 * and Vim. When this changes, add some code here! Also need to
3409 * split P_DEF_ALLOCED in two.
3410 */
3411 if (options[opt_idx].flags & P_DEF_ALLOCED)
3412 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3413 options[opt_idx].def_val[VI_DEFAULT] = p;
3414 options[opt_idx].flags |= P_DEF_ALLOCED;
3415 }
3416 }
3417
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 save_file_ff(curbuf); /* Buffer is unchanged */
3419
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420#if defined(FEAT_ARABIC)
3421 /* Detect use of mlterm.
3422 * Mlterm is a terminal emulator akin to xterm that has some special
3423 * abilities (bidi namely).
3424 * NOTE: mlterm's author is being asked to 'set' a variable
3425 * instead of an environment variable due to inheritance.
3426 */
3427 if (mch_getenv((char_u *)"MLTERM") != NULL)
3428 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3429#endif
3430
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003431 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432
3433#ifdef FEAT_MBYTE
3434# if defined(WIN3264) && defined(FEAT_GETTEXT)
3435 /*
3436 * If $LANG isn't set, try to get a good value for it. This makes the
3437 * right language be used automatically. Don't do this for English.
3438 */
3439 if (mch_getenv((char_u *)"LANG") == NULL)
3440 {
3441 char buf[20];
3442
3443 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3444 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3445 * only the first two. */
3446 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3447 (LPTSTR)buf, 20);
3448 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3449 {
3450 /* There are a few exceptions (probably more) */
3451 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3452 STRCPY(buf, "zh_TW");
3453 else if (STRNICMP(buf, "chs", 3) == 0
3454 || STRNICMP(buf, "zhc", 3) == 0)
3455 STRCPY(buf, "zh_CN");
3456 else if (STRNICMP(buf, "jp", 2) == 0)
3457 STRCPY(buf, "ja");
3458 else
3459 buf[2] = NUL; /* truncate to two-letter code */
3460 vim_setenv("LANG", buf);
3461 }
3462 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003463# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003464# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003465 /* Moved to os_mac_conv.c to avoid dependency problems. */
3466 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003467# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468# endif
3469
3470 /* enc_locale() will try to find the encoding of the current locale. */
3471 p = enc_locale();
3472 if (p != NULL)
3473 {
3474 char_u *save_enc;
3475
3476 /* Try setting 'encoding' and check if the value is valid.
3477 * If not, go back to the default "latin1". */
3478 save_enc = p_enc;
3479 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003480 if (STRCMP(p_enc, "gb18030") == 0)
3481 {
3482 /* We don't support "gb18030", but "cp936" is a good substitute
3483 * for practical purposes, thus use that. It's not an alias to
3484 * still support conversion between gb18030 and utf-8. */
3485 p_enc = vim_strsave((char_u *)"cp936");
3486 vim_free(p);
3487 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 if (mb_init() == NULL)
3489 {
3490 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003491 if (opt_idx >= 0)
3492 {
3493 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3494 options[opt_idx].flags |= P_DEF_ALLOCED;
3495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003497#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3498 || defined(VMS)
3499 if (STRCMP(p_enc, "latin1") == 0
3500# ifdef FEAT_MBYTE
3501 || enc_utf8
3502# endif
3503 )
3504 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003505 /* Adjust the default for 'isprint' and 'iskeyword' to match
3506 * latin1. Also set the defaults for when 'nocompatible' is
3507 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003508 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003509 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003510 set_string_option_direct((char_u *)"isk", -1,
3511 ISK_LATIN1, OPT_FREE, SID_NONE);
3512 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003513 if (opt_idx >= 0)
3514 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003515 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003516 if (opt_idx >= 0)
3517 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003518 (void)init_chartab();
3519 }
3520#endif
3521
Bram Moolenaar071d4272004-06-13 20:20:40 +00003522# if defined(WIN3264) && !defined(FEAT_GUI)
3523 /* Win32 console: When GetACP() returns a different value from
3524 * GetConsoleCP() set 'termencoding'. */
3525 if (GetACP() != GetConsoleCP())
3526 {
3527 char buf[50];
3528
3529 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3530 p_tenc = vim_strsave((char_u *)buf);
3531 if (p_tenc != NULL)
3532 {
3533 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003534 if (opt_idx >= 0)
3535 {
3536 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3537 options[opt_idx].flags |= P_DEF_ALLOCED;
3538 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003539 convert_setup(&input_conv, p_tenc, p_enc);
3540 convert_setup(&output_conv, p_enc, p_tenc);
3541 }
3542 else
3543 p_tenc = empty_option;
3544 }
3545# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003546# if defined(WIN3264) && defined(FEAT_MBYTE)
3547 /* $HOME may have characters in active code page. */
3548 init_homedir();
3549# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550 }
3551 else
3552 {
3553 vim_free(p_enc);
3554 p_enc = save_enc;
3555 }
3556 }
3557#endif
3558
3559#ifdef FEAT_MULTI_LANG
3560 /* Set the default for 'helplang'. */
3561 set_helplang_default(get_mess_lang());
3562#endif
3563}
3564
3565/*
3566 * Set an option to its default value.
3567 * This does not take care of side effects!
3568 */
3569 static void
3570set_option_default(opt_idx, opt_flags, compatible)
3571 int opt_idx;
3572 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3573 int compatible; /* use Vi default value */
3574{
3575 char_u *varp; /* pointer to variable for current option */
3576 int dvi; /* index in def_val[] */
3577 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003578 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003579 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3580
3581 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3582 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003583 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003584 {
3585 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3586 if (flags & P_STRING)
3587 {
3588 /* Use set_string_option_direct() for local options to handle
3589 * freeing and allocating the value. */
3590 if (options[opt_idx].indir != PV_NONE)
3591 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003592 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 else
3594 {
3595 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3596 free_string_option(*(char_u **)(varp));
3597 *(char_u **)varp = options[opt_idx].def_val[dvi];
3598 options[opt_idx].flags &= ~P_ALLOCED;
3599 }
3600 }
3601 else if (flags & P_NUM)
3602 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003603 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 win_comp_scroll(curwin);
3605 else
3606 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003607 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608 /* May also set global value for local option. */
3609 if (both)
3610 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3611 *(long *)varp;
3612 }
3613 }
3614 else /* P_BOOL */
3615 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003616 /* the cast to long is required for Manx C, long_i is needed for
3617 * MSVC */
3618 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003619#ifdef UNIX
3620 /* 'modeline' defaults to off for root */
3621 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3622 *(int *)varp = FALSE;
3623#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003624 /* May also set global value for local option. */
3625 if (both)
3626 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3627 *(int *)varp;
3628 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003629
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003630 /* The default value is not insecure. */
3631 flagsp = insecure_flag(opt_idx, opt_flags);
3632 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003633 }
3634
3635#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003636 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003637#endif
3638}
3639
3640/*
3641 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003642 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643 */
3644 static void
3645set_options_default(opt_flags)
3646 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3647{
3648 int i;
3649#ifdef FEAT_WINDOWS
3650 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003651 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652#endif
3653
3654 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003655 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003656#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003657 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003658 || (TRUE
3659# if defined(FEAT_MBYTE)
3660 && options[i].var != (char_u *)&p_enc
3661# endif
3662# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003663 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003664 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003665# endif
3666 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003667#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003668 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003669 set_option_default(i, opt_flags, p_cp);
3670
3671#ifdef FEAT_WINDOWS
3672 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003673 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674 win_comp_scroll(wp);
3675#else
3676 win_comp_scroll(curwin);
3677#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003678#ifdef FEAT_CINDENT
3679 parse_cino(curbuf);
3680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681}
3682
3683/*
3684 * Set the Vi-default value of a string option.
3685 * Used for 'sh', 'backupskip' and 'term'.
3686 */
3687 void
3688set_string_default(name, val)
3689 char *name;
3690 char_u *val;
3691{
3692 char_u *p;
3693 int opt_idx;
3694
3695 p = vim_strsave(val);
3696 if (p != NULL) /* we don't want a NULL */
3697 {
3698 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 {
3701 if (options[opt_idx].flags & P_DEF_ALLOCED)
3702 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3703 options[opt_idx].def_val[VI_DEFAULT] = p;
3704 options[opt_idx].flags |= P_DEF_ALLOCED;
3705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 }
3707}
3708
3709/*
3710 * Set the Vi-default value of a number option.
3711 * Used for 'lines' and 'columns'.
3712 */
3713 void
3714set_number_default(name, val)
3715 char *name;
3716 long val;
3717{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003718 int opt_idx;
3719
3720 opt_idx = findoption((char_u *)name);
3721 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003722 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723}
3724
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003725#if defined(EXITFREE) || defined(PROTO)
3726/*
3727 * Free all options.
3728 */
3729 void
3730free_all_options()
3731{
3732 int i;
3733
3734 for (i = 0; !istermoption(&options[i]); i++)
3735 {
3736 if (options[i].indir == PV_NONE)
3737 {
3738 /* global option: free value and default value. */
3739 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3740 free_string_option(*(char_u **)options[i].var);
3741 if (options[i].flags & P_DEF_ALLOCED)
3742 free_string_option(options[i].def_val[VI_DEFAULT]);
3743 }
3744 else if (options[i].var != VAR_WIN
3745 && (options[i].flags & P_STRING))
3746 /* buffer-local option: free global value */
3747 free_string_option(*(char_u **)options[i].var);
3748 }
3749}
3750#endif
3751
3752
Bram Moolenaar071d4272004-06-13 20:20:40 +00003753/*
3754 * Initialize the options, part two: After getting Rows and Columns and
3755 * setting 'term'.
3756 */
3757 void
3758set_init_2()
3759{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003760 int idx;
3761
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 /*
3763 * 'scroll' defaults to half the window height. Note that this default is
3764 * wrong when the window height changes.
3765 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003766 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003767 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003768 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003769 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 comp_col();
3771
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003772 /*
3773 * 'window' is only for backwards compatibility with Vi.
3774 * Default is Rows - 1.
3775 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003776 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003777 p_window = Rows - 1;
3778 set_number_default("window", Rows - 1);
3779
Bram Moolenaarf740b292006-02-16 22:11:02 +00003780 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003782 /*
3783 * If 'background' wasn't set by the user, try guessing the value,
3784 * depending on the terminal name. Only need to check for terminals
3785 * with a dark background, that can handle color.
3786 */
3787 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003788 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3789 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003791 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003792 /* don't mark it as set, when starting the GUI it may be
3793 * changed again */
3794 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 }
3796#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003797
3798#ifdef CURSOR_SHAPE
3799 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3800#endif
3801#ifdef FEAT_MOUSESHAPE
3802 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3803#endif
3804#ifdef FEAT_PRINTER
3805 (void)parse_printoptions(); /* parse 'printoptions' default value */
3806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807}
3808
3809/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003810 * Return "dark" or "light" depending on the kind of terminal.
3811 * This is just guessing! Recognized are:
3812 * "linux" Linux console
3813 * "screen.linux" Linux console with screen
3814 * "cygwin" Cygwin shell
3815 * "putty" Putty program
3816 * We also check the COLORFGBG environment variable, which is set by
3817 * rxvt and derivatives. This variable contains either two or three
3818 * values separated by semicolons; we want the last value in either
3819 * case. If this value is 0-6 or 8, our background is dark.
3820 */
3821 static char_u *
3822term_bg_default()
3823{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003824#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3825 /* DOS console nearly always black */
3826 return (char_u *)"dark";
3827#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003828 char_u *p;
3829
Bram Moolenaarf740b292006-02-16 22:11:02 +00003830 if (STRCMP(T_NAME, "linux") == 0
3831 || STRCMP(T_NAME, "screen.linux") == 0
3832 || STRCMP(T_NAME, "cygwin") == 0
3833 || STRCMP(T_NAME, "putty") == 0
3834 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3835 && (p = vim_strrchr(p, ';')) != NULL
3836 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3837 && p[2] == NUL))
3838 return (char_u *)"dark";
3839 return (char_u *)"light";
3840#endif
3841}
3842
3843/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844 * Initialize the options, part three: After reading the .vimrc
3845 */
3846 void
3847set_init_3()
3848{
3849#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3850/*
3851 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3852 * This is done after other initializations, where 'shell' might have been
3853 * set, but only if they have not been set before.
3854 */
3855 char_u *p;
3856 int idx_srr;
3857 int do_srr;
3858#ifdef FEAT_QUICKFIX
3859 int idx_sp;
3860 int do_sp;
3861#endif
3862
3863 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003864 if (idx_srr < 0)
3865 do_srr = FALSE;
3866 else
3867 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868#ifdef FEAT_QUICKFIX
3869 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003870 if (idx_sp < 0)
3871 do_sp = FALSE;
3872 else
3873 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003874#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003875 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876 if (p != NULL)
3877 {
3878 /*
3879 * Default for p_sp is "| tee", for p_srr is ">".
3880 * For known shells it is changed here to include stderr.
3881 */
3882 if ( fnamecmp(p, "csh") == 0
3883 || fnamecmp(p, "tcsh") == 0
3884# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3885 || fnamecmp(p, "csh.exe") == 0
3886 || fnamecmp(p, "tcsh.exe") == 0
3887# endif
3888 )
3889 {
3890#if defined(FEAT_QUICKFIX)
3891 if (do_sp)
3892 {
3893# ifdef WIN3264
3894 p_sp = (char_u *)">&";
3895# else
3896 p_sp = (char_u *)"|& tee";
3897# endif
3898 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3899 }
3900#endif
3901 if (do_srr)
3902 {
3903 p_srr = (char_u *)">&";
3904 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3905 }
3906 }
3907 else
3908# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3909 if ( fnamecmp(p, "sh") == 0
3910 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003911 || fnamecmp(p, "mksh") == 0
3912 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003914 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003916 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917# ifdef WIN3264
3918 || fnamecmp(p, "cmd") == 0
3919 || fnamecmp(p, "sh.exe") == 0
3920 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003921 || fnamecmp(p, "mksh.exe") == 0
3922 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003924 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925 || fnamecmp(p, "bash.exe") == 0
3926 || fnamecmp(p, "cmd.exe") == 0
3927# endif
3928 )
3929# endif
3930 {
3931#if defined(FEAT_QUICKFIX)
3932 if (do_sp)
3933 {
3934# ifdef WIN3264
3935 p_sp = (char_u *)">%s 2>&1";
3936# else
3937 p_sp = (char_u *)"2>&1| tee";
3938# endif
3939 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3940 }
3941#endif
3942 if (do_srr)
3943 {
3944 p_srr = (char_u *)">%s 2>&1";
3945 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3946 }
3947 }
3948 vim_free(p);
3949 }
3950#endif
3951
3952#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3953 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003954 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3955 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 * This is done after other initializations, where 'shell' might have been
3957 * set, but only if they have not been set before. Default for p_shcf is
3958 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3959 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3960 * command.com. And for Win32 we need to set p_sxq instead.
3961 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003962 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 {
3964 int idx3;
3965
3966 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003967 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968 {
3969 p_shcf = (char_u *)"-c";
3970 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3971 }
3972
3973# ifndef DJGPP
3974# ifdef WIN3264
3975 /* Somehow Win32 requires the quotes around the redirection too */
3976 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003977 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 {
3979 p_sxq = (char_u *)"\"";
3980 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3981 }
3982# else
3983 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003984 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985 {
3986 p_shq = (char_u *)"\"";
3987 options[idx3].def_val[VI_DEFAULT] = p_shq;
3988 }
3989# endif
3990# endif
3991 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003992 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3993 {
3994 int idx3;
3995
3996 /*
3997 * cmd.exe on Windows will strip the first and last double quote given
3998 * on the command line, e.g. most of the time things like:
3999 * cmd /c "my path/to/echo" "my args to echo"
4000 * become:
4001 * my path/to/echo" "my args to echo
4002 * when executed.
4003 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004004 * To avoid this, set shellxquote to surround the command in
4005 * parenthesis. This appears to make most commands work, without
4006 * breaking commands that worked previously, such as
4007 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004008 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004009 idx3 = findoption((char_u *)"sxq");
4010 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4011 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004012 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004013 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4014 }
4015
Bram Moolenaara64ba222012-02-12 23:23:31 +01004016 idx3 = findoption((char_u *)"shcf");
4017 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4018 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004019 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004020 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4021 }
4022 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023#endif
4024
4025#ifdef FEAT_TITLE
4026 set_title_defaults();
4027#endif
4028}
4029
4030#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4031/*
4032 * When 'helplang' is still at its default value, set it to "lang".
4033 * Only the first two characters of "lang" are used.
4034 */
4035 void
4036set_helplang_default(lang)
4037 char_u *lang;
4038{
4039 int idx;
4040
4041 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4042 return;
4043 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004044 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045 {
4046 if (options[idx].flags & P_ALLOCED)
4047 free_string_option(p_hlg);
4048 p_hlg = vim_strsave(lang);
4049 if (p_hlg == NULL)
4050 p_hlg = empty_option;
4051 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004052 {
4053 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4054 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4055 {
4056 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4057 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4058 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 options[idx].flags |= P_ALLOCED;
4062 }
4063}
4064#endif
4065
4066#ifdef FEAT_GUI
4067static char_u *gui_bg_default __ARGS((void));
4068
4069 static char_u *
4070gui_bg_default()
4071{
4072 if (gui_get_lightness(gui.back_pixel) < 127)
4073 return (char_u *)"dark";
4074 return (char_u *)"light";
4075}
4076
4077/*
4078 * Option initializations that can only be done after opening the GUI window.
4079 */
4080 void
4081init_gui_options()
4082{
4083 /* Set the 'background' option according to the lightness of the
4084 * background color, unless the user has set it already. */
4085 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4086 {
4087 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4088 highlight_changed();
4089 }
4090}
4091#endif
4092
4093#ifdef FEAT_TITLE
4094/*
4095 * 'title' and 'icon' only default to true if they have not been set or reset
4096 * in .vimrc and we can read the old value.
4097 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4098 * they can be reset. This reduces startup time when using X on a remote
4099 * machine.
4100 */
4101 void
4102set_title_defaults()
4103{
4104 int idx1;
4105 long val;
4106
4107 /*
4108 * If GUI is (going to be) used, we can always set the window title and
4109 * icon name. Saves a bit of time, because the X11 display server does
4110 * not need to be contacted.
4111 */
4112 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004113 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 {
4115#ifdef FEAT_GUI
4116 if (gui.starting || gui.in_use)
4117 val = TRUE;
4118 else
4119#endif
4120 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004121 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 p_title = val;
4123 }
4124 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004125 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 {
4127#ifdef FEAT_GUI
4128 if (gui.starting || gui.in_use)
4129 val = TRUE;
4130 else
4131#endif
4132 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004133 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 p_icon = val;
4135 }
4136}
4137#endif
4138
4139/*
4140 * Parse 'arg' for option settings.
4141 *
4142 * 'arg' may be IObuff, but only when no errors can be present and option
4143 * does not need to be expanded with option_expand().
4144 * "opt_flags":
4145 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004146 * OPT_GLOBAL for ":setglobal"
4147 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004149 * OPT_WINONLY to only set window-local options
4150 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 *
4152 * returns FAIL if an error is detected, OK otherwise
4153 */
4154 int
4155do_set(arg, opt_flags)
4156 char_u *arg; /* option string (may be written to!) */
4157 int opt_flags;
4158{
4159 int opt_idx;
4160 char_u *errmsg;
4161 char_u errbuf[80];
4162 char_u *startarg;
4163 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4164 int nextchar; /* next non-white char after option name */
4165 int afterchar; /* character just after option name */
4166 int len;
4167 int i;
4168 long value;
4169 int key;
4170 long_u flags; /* flags for current option */
4171 char_u *varp = NULL; /* pointer to variable for current option */
4172 int did_show = FALSE; /* already showed one value */
4173 int adding; /* "opt+=arg" */
4174 int prepending; /* "opt^=arg" */
4175 int removing; /* "opt-=arg" */
4176 int cp_val = 0;
4177 char_u key_name[2];
4178
4179 if (*arg == NUL)
4180 {
4181 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004182 did_show = TRUE;
4183 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184 }
4185
4186 while (*arg != NUL) /* loop to process all options */
4187 {
4188 errmsg = NULL;
4189 startarg = arg; /* remember for error message */
4190
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004191 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4192 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 {
4194 /*
4195 * ":set all" show all options.
4196 * ":set all&" set all options to their default value.
4197 */
4198 arg += 3;
4199 if (*arg == '&')
4200 {
4201 ++arg;
4202 /* Only for :set command set global value of local options. */
4203 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004204 didset_options();
4205 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004206 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 }
4208 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004209 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004211 did_show = TRUE;
4212 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004213 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004214 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215 {
4216 showoptions(2, opt_flags);
4217 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004218 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219 arg += 7;
4220 }
4221 else
4222 {
4223 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004224 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225 {
4226 prefix = 0;
4227 arg += 2;
4228 }
4229 else if (STRNCMP(arg, "inv", 3) == 0)
4230 {
4231 prefix = 2;
4232 arg += 3;
4233 }
4234
4235 /* find end of name */
4236 key = 0;
4237 if (*arg == '<')
4238 {
4239 nextchar = 0;
4240 opt_idx = -1;
4241 /* look out for <t_>;> */
4242 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4243 len = 5;
4244 else
4245 {
4246 len = 1;
4247 while (arg[len] != NUL && arg[len] != '>')
4248 ++len;
4249 }
4250 if (arg[len] != '>')
4251 {
4252 errmsg = e_invarg;
4253 goto skip;
4254 }
4255 arg[len] = NUL; /* put NUL after name */
4256 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4257 opt_idx = findoption(arg + 1);
4258 arg[len++] = '>'; /* restore '>' */
4259 if (opt_idx == -1)
4260 key = find_key_option(arg + 1);
4261 }
4262 else
4263 {
4264 len = 0;
4265 /*
4266 * The two characters after "t_" may not be alphanumeric.
4267 */
4268 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4269 len = 4;
4270 else
4271 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4272 ++len;
4273 nextchar = arg[len];
4274 arg[len] = NUL; /* put NUL after name */
4275 opt_idx = findoption(arg);
4276 arg[len] = nextchar; /* restore nextchar */
4277 if (opt_idx == -1)
4278 key = find_key_option(arg);
4279 }
4280
4281 /* remember character after option name */
4282 afterchar = arg[len];
4283
4284 /* skip white space, allow ":set ai ?" */
4285 while (vim_iswhite(arg[len]))
4286 ++len;
4287
4288 adding = FALSE;
4289 prepending = FALSE;
4290 removing = FALSE;
4291 if (arg[len] != NUL && arg[len + 1] == '=')
4292 {
4293 if (arg[len] == '+')
4294 {
4295 adding = TRUE; /* "+=" */
4296 ++len;
4297 }
4298 else if (arg[len] == '^')
4299 {
4300 prepending = TRUE; /* "^=" */
4301 ++len;
4302 }
4303 else if (arg[len] == '-')
4304 {
4305 removing = TRUE; /* "-=" */
4306 ++len;
4307 }
4308 }
4309 nextchar = arg[len];
4310
4311 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4312 {
4313 errmsg = (char_u *)N_("E518: Unknown option");
4314 goto skip;
4315 }
4316
4317 if (opt_idx >= 0)
4318 {
4319 if (options[opt_idx].var == NULL) /* hidden option: skip */
4320 {
4321 /* Only give an error message when requesting the value of
4322 * a hidden option, ignore setting it. */
4323 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4324 && (!(options[opt_idx].flags & P_BOOL)
4325 || nextchar == '?'))
4326 errmsg = (char_u *)N_("E519: Option not supported");
4327 goto skip;
4328 }
4329
4330 flags = options[opt_idx].flags;
4331 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4332 }
4333 else
4334 {
4335 flags = P_STRING;
4336 if (key < 0)
4337 {
4338 key_name[0] = KEY2TERMCAP0(key);
4339 key_name[1] = KEY2TERMCAP1(key);
4340 }
4341 else
4342 {
4343 key_name[0] = KS_KEY;
4344 key_name[1] = (key & 0xff);
4345 }
4346 }
4347
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004348 /* Skip all options that are not window-local (used when showing
4349 * an already loaded buffer in a window). */
4350 if ((opt_flags & OPT_WINONLY)
4351 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4352 goto skip;
4353
Bram Moolenaara3227e22006-03-08 21:32:40 +00004354 /* Skip all options that are window-local (used for :vimgrep). */
4355 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4356 && options[opt_idx].var == VAR_WIN)
4357 goto skip;
4358
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004359 /* Disallow changing some options from modelines. */
4360 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004361 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004362 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004363 {
4364 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4365 goto skip;
4366 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004367#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004368 /* In diff mode some options are overruled. This avoids that
4369 * 'foldmethod' becomes "marker" instead of "diff" and that
4370 * "wrap" gets set. */
4371 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004372 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004373 && (options[opt_idx].indir == PV_FDM
4374 || options[opt_idx].indir == PV_WRAP))
4375 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377 }
4378
4379#ifdef HAVE_SANDBOX
4380 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004381 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004382 {
4383 errmsg = (char_u *)_(e_sandbox);
4384 goto skip;
4385 }
4386#endif
4387
4388 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4389 {
4390 arg += len;
4391 cp_val = p_cp;
4392 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4393 {
4394 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4395 {
4396 cp_val = FALSE;
4397 arg += 3;
4398 }
4399 else /* "opt&vi": set to Vi default */
4400 {
4401 cp_val = TRUE;
4402 arg += 2;
4403 }
4404 }
4405 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4406 && arg[1] != NUL && !vim_iswhite(arg[1]))
4407 {
4408 errmsg = e_trailing;
4409 goto skip;
4410 }
4411 }
4412
4413 /*
4414 * allow '=' and ':' as MSDOS command.com allows only one
4415 * '=' character per "set" command line. grrr. (jw)
4416 */
4417 if (nextchar == '?'
4418 || (prefix == 1
4419 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4420 && !(flags & P_BOOL)))
4421 {
4422 /*
4423 * print value
4424 */
4425 if (did_show)
4426 msg_putchar('\n'); /* cursor below last one */
4427 else
4428 {
4429 gotocmdline(TRUE); /* cursor at status line */
4430 did_show = TRUE; /* remember that we did a line */
4431 }
4432 if (opt_idx >= 0)
4433 {
4434 showoneopt(&options[opt_idx], opt_flags);
4435#ifdef FEAT_EVAL
4436 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004437 {
4438 /* Mention where the option was last set. */
4439 if (varp == options[opt_idx].var)
4440 last_set_msg(options[opt_idx].scriptID);
4441 else if ((int)options[opt_idx].indir & PV_WIN)
4442 last_set_msg(curwin->w_p_scriptID[
4443 (int)options[opt_idx].indir & PV_MASK]);
4444 else if ((int)options[opt_idx].indir & PV_BUF)
4445 last_set_msg(curbuf->b_p_scriptID[
4446 (int)options[opt_idx].indir & PV_MASK]);
4447 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004448#endif
4449 }
4450 else
4451 {
4452 char_u *p;
4453
4454 p = find_termcode(key_name);
4455 if (p == NULL)
4456 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004457 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004458 goto skip;
4459 }
4460 else
4461 (void)show_one_termcode(key_name, p, TRUE);
4462 }
4463 if (nextchar != '?'
4464 && nextchar != NUL && !vim_iswhite(afterchar))
4465 errmsg = e_trailing;
4466 }
4467 else
4468 {
4469 if (flags & P_BOOL) /* boolean */
4470 {
4471 if (nextchar == '=' || nextchar == ':')
4472 {
4473 errmsg = e_invarg;
4474 goto skip;
4475 }
4476
4477 /*
4478 * ":set opt!": invert
4479 * ":set opt&": reset to default value
4480 * ":set opt<": reset to global value
4481 */
4482 if (nextchar == '!')
4483 value = *(int *)(varp) ^ 1;
4484 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004485 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004486 ((flags & P_VI_DEF) || cp_val)
4487 ? VI_DEFAULT : VIM_DEFAULT];
4488 else if (nextchar == '<')
4489 {
4490 /* For 'autoread' -1 means to use global value. */
4491 if ((int *)varp == &curbuf->b_p_ar
4492 && opt_flags == OPT_LOCAL)
4493 value = -1;
4494 else
4495 value = *(int *)get_varp_scope(&(options[opt_idx]),
4496 OPT_GLOBAL);
4497 }
4498 else
4499 {
4500 /*
4501 * ":set invopt": invert
4502 * ":set opt" or ":set noopt": set or reset
4503 */
4504 if (nextchar != NUL && !vim_iswhite(afterchar))
4505 {
4506 errmsg = e_trailing;
4507 goto skip;
4508 }
4509 if (prefix == 2) /* inv */
4510 value = *(int *)(varp) ^ 1;
4511 else
4512 value = prefix;
4513 }
4514
4515 errmsg = set_bool_option(opt_idx, varp, (int)value,
4516 opt_flags);
4517 }
4518 else /* numeric or string */
4519 {
4520 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4521 || prefix != 1)
4522 {
4523 errmsg = e_invarg;
4524 goto skip;
4525 }
4526
4527 if (flags & P_NUM) /* numeric */
4528 {
4529 /*
4530 * Different ways to set a number option:
4531 * & set to default value
4532 * < set to global value
4533 * <xx> accept special key codes for 'wildchar'
4534 * c accept any non-digit for 'wildchar'
4535 * [-]0-9 set number
4536 * other error
4537 */
4538 ++arg;
4539 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004540 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004541 ((flags & P_VI_DEF) || cp_val)
4542 ? VI_DEFAULT : VIM_DEFAULT];
4543 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004544 {
4545 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4546 * use the global value. */
4547 if ((long *)varp == &curbuf->b_p_ul
4548 && opt_flags == OPT_LOCAL)
4549 value = NO_LOCAL_UNDOLEVEL;
4550 else
4551 value = *(long *)get_varp_scope(
4552 &(options[opt_idx]), OPT_GLOBAL);
4553 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004554 else if (((long *)varp == &p_wc
4555 || (long *)varp == &p_wcm)
4556 && (*arg == '<'
4557 || *arg == '^'
4558 || ((!arg[1] || vim_iswhite(arg[1]))
4559 && !VIM_ISDIGIT(*arg))))
4560 {
4561 value = string_to_key(arg);
4562 if (value == 0 && (long *)varp != &p_wcm)
4563 {
4564 errmsg = e_invarg;
4565 goto skip;
4566 }
4567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004568 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4569 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004570 /* Allow negative (for 'undolevels'), octal and
4571 * hex numbers. */
Bram Moolenaar5d1bc782015-07-17 13:03:48 +02004572 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004573 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4574 {
4575 errmsg = e_invarg;
4576 goto skip;
4577 }
4578 }
4579 else
4580 {
4581 errmsg = (char_u *)N_("E521: Number required after =");
4582 goto skip;
4583 }
4584
4585 if (adding)
4586 value = *(long *)varp + value;
4587 if (prepending)
4588 value = *(long *)varp * value;
4589 if (removing)
4590 value = *(long *)varp - value;
4591 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004592 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004593 }
4594 else if (opt_idx >= 0) /* string */
4595 {
4596 char_u *save_arg = NULL;
4597 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004598 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004599 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004600 char_u *origval = NULL;
4601#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4602 char_u *saved_origval = NULL;
4603#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004604 unsigned newlen;
4605 int comma;
4606 int bs;
4607 int new_value_alloced; /* new string option
4608 was allocated */
4609
4610 /* When using ":set opt=val" for a global option
4611 * with a local value the local value will be
4612 * reset, use the global value here. */
4613 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004614 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 varp = options[opt_idx].var;
4616
4617 /* The old value is kept until we are sure that the
4618 * new value is valid. */
4619 oldval = *(char_u **)varp;
4620 if (nextchar == '&') /* set to default val */
4621 {
4622 newval = options[opt_idx].def_val[
4623 ((flags & P_VI_DEF) || cp_val)
4624 ? VI_DEFAULT : VIM_DEFAULT];
4625 if ((char_u **)varp == &p_bg)
4626 {
4627 /* guess the value of 'background' */
4628#ifdef FEAT_GUI
4629 if (gui.in_use)
4630 newval = gui_bg_default();
4631 else
4632#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004633 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004634 }
4635
4636 /* expand environment variables and ~ (since the
4637 * default value was already expanded, only
4638 * required when an environment variable was set
4639 * later */
4640 if (newval == NULL)
4641 newval = empty_option;
4642 else
4643 {
4644 s = option_expand(opt_idx, newval);
4645 if (s == NULL)
4646 s = newval;
4647 newval = vim_strsave(s);
4648 }
4649 new_value_alloced = TRUE;
4650 }
4651 else if (nextchar == '<') /* set to global val */
4652 {
4653 newval = vim_strsave(*(char_u **)get_varp_scope(
4654 &(options[opt_idx]), OPT_GLOBAL));
4655 new_value_alloced = TRUE;
4656 }
4657 else
4658 {
4659 ++arg; /* jump to after the '=' or ':' */
4660
4661 /*
4662 * Set 'keywordprg' to ":help" if an empty
4663 * value was passed to :set by the user.
4664 * Misuse errbuf[] for the resulting string.
4665 */
4666 if (varp == (char_u *)&p_kp
4667 && (*arg == NUL || *arg == ' '))
4668 {
4669 STRCPY(errbuf, ":help");
4670 save_arg = arg;
4671 arg = errbuf;
4672 }
4673 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004674 * Convert 'backspace' number to string, for
4675 * adding, prepending and removing string.
4676 */
4677 else if (varp == (char_u *)&p_bs
4678 && VIM_ISDIGIT(**(char_u **)varp))
4679 {
4680 i = getdigits((char_u **)varp);
4681 switch (i)
4682 {
4683 case 0:
4684 *(char_u **)varp = empty_option;
4685 break;
4686 case 1:
4687 *(char_u **)varp = vim_strsave(
4688 (char_u *)"indent,eol");
4689 break;
4690 case 2:
4691 *(char_u **)varp = vim_strsave(
4692 (char_u *)"indent,eol,start");
4693 break;
4694 }
4695 vim_free(oldval);
4696 oldval = *(char_u **)varp;
4697 }
4698 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004699 * Convert 'whichwrap' number to string, for
4700 * backwards compatibility with Vim 3.0.
4701 * Misuse errbuf[] for the resulting string.
4702 */
4703 else if (varp == (char_u *)&p_ww
4704 && VIM_ISDIGIT(*arg))
4705 {
4706 *errbuf = NUL;
4707 i = getdigits(&arg);
4708 if (i & 1)
4709 STRCAT(errbuf, "b,");
4710 if (i & 2)
4711 STRCAT(errbuf, "s,");
4712 if (i & 4)
4713 STRCAT(errbuf, "h,l,");
4714 if (i & 8)
4715 STRCAT(errbuf, "<,>,");
4716 if (i & 16)
4717 STRCAT(errbuf, "[,],");
4718 if (*errbuf != NUL) /* remove trailing , */
4719 errbuf[STRLEN(errbuf) - 1] = NUL;
4720 save_arg = arg;
4721 arg = errbuf;
4722 }
4723 /*
4724 * Remove '>' before 'dir' and 'bdir', for
4725 * backwards compatibility with version 3.0
4726 */
4727 else if ( *arg == '>'
4728 && (varp == (char_u *)&p_dir
4729 || varp == (char_u *)&p_bdir))
4730 {
4731 ++arg;
4732 }
4733
4734 /* When setting the local value of a global
4735 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004736 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004737 && (opt_flags & OPT_LOCAL))
4738 origval = *(char_u **)get_varp(
4739 &options[opt_idx]);
4740 else
4741 origval = oldval;
4742
4743 /*
4744 * Copy the new string into allocated memory.
4745 * Can't use set_string_option_direct(), because
4746 * we need to remove the backslashes.
4747 */
4748 /* get a bit too much */
4749 newlen = (unsigned)STRLEN(arg) + 1;
4750 if (adding || prepending || removing)
4751 newlen += (unsigned)STRLEN(origval) + 1;
4752 newval = alloc(newlen);
4753 if (newval == NULL) /* out of mem, don't change */
4754 break;
4755 s = newval;
4756
4757 /*
4758 * Copy the string, skip over escaped chars.
4759 * For MS-DOS and WIN32 backslashes before normal
4760 * file name characters are not removed, and keep
4761 * backslash at start, for "\\machine\path", but
4762 * do remove it for "\\\\machine\\path".
4763 * The reverse is found in ExpandOldSetting().
4764 */
4765 while (*arg && !vim_iswhite(*arg))
4766 {
4767 if (*arg == '\\' && arg[1] != NUL
4768#ifdef BACKSLASH_IN_FILENAME
4769 && !((flags & P_EXPAND)
4770 && vim_isfilec(arg[1])
4771 && (arg[1] != '\\'
4772 || (s == newval
4773 && arg[2] != '\\')))
4774#endif
4775 )
4776 ++arg; /* remove backslash */
4777#ifdef FEAT_MBYTE
4778 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004779 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004780 {
4781 /* copy multibyte char */
4782 mch_memmove(s, arg, (size_t)i);
4783 arg += i;
4784 s += i;
4785 }
4786 else
4787#endif
4788 *s++ = *arg++;
4789 }
4790 *s = NUL;
4791
4792 /*
4793 * Expand environment variables and ~.
4794 * Don't do it when adding without inserting a
4795 * comma.
4796 */
4797 if (!(adding || prepending || removing)
4798 || (flags & P_COMMA))
4799 {
4800 s = option_expand(opt_idx, newval);
4801 if (s != NULL)
4802 {
4803 vim_free(newval);
4804 newlen = (unsigned)STRLEN(s) + 1;
4805 if (adding || prepending || removing)
4806 newlen += (unsigned)STRLEN(origval) + 1;
4807 newval = alloc(newlen);
4808 if (newval == NULL)
4809 break;
4810 STRCPY(newval, s);
4811 }
4812 }
4813
4814 /* locate newval[] in origval[] when removing it
4815 * and when adding to avoid duplicates */
4816 i = 0; /* init for GCC */
4817 if (removing || (flags & P_NODUP))
4818 {
4819 i = (int)STRLEN(newval);
4820 bs = 0;
4821 for (s = origval; *s; ++s)
4822 {
4823 if ((!(flags & P_COMMA)
4824 || s == origval
4825 || (s[-1] == ',' && !(bs & 1)))
4826 && STRNCMP(s, newval, i) == 0
4827 && (!(flags & P_COMMA)
4828 || s[i] == ','
4829 || s[i] == NUL))
4830 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004831 /* Count backslashes. Only a comma with an
4832 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004833 * recognized as a separator */
4834 if (s > origval && s[-1] == '\\')
4835 ++bs;
4836 else
4837 bs = 0;
4838 }
4839
4840 /* do not add if already there */
4841 if ((adding || prepending) && *s)
4842 {
4843 prepending = FALSE;
4844 adding = FALSE;
4845 STRCPY(newval, origval);
4846 }
4847 }
4848
4849 /* concatenate the two strings; add a ',' if
4850 * needed */
4851 if (adding || prepending)
4852 {
4853 comma = ((flags & P_COMMA) && *origval != NUL
4854 && *newval != NUL);
4855 if (adding)
4856 {
4857 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004858 /* strip a trailing comma, would get 2 */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02004859 if (comma && (flags & P_ONECOMMA) && i > 1
4860 && origval[i - 1] == ','
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004861 && origval[i - 2] != '\\')
4862 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004863 mch_memmove(newval + i + comma, newval,
4864 STRLEN(newval) + 1);
4865 mch_memmove(newval, origval, (size_t)i);
4866 }
4867 else
4868 {
4869 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004870 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004871 }
4872 if (comma)
4873 newval[i] = ',';
4874 }
4875
4876 /* Remove newval[] from origval[]. (Note: "i" has
4877 * been set above and is used here). */
4878 if (removing)
4879 {
4880 STRCPY(newval, origval);
4881 if (*s)
4882 {
4883 /* may need to remove a comma */
4884 if (flags & P_COMMA)
4885 {
4886 if (s == origval)
4887 {
4888 /* include comma after string */
4889 if (s[i] == ',')
4890 ++i;
4891 }
4892 else
4893 {
4894 /* include comma before string */
4895 --s;
4896 ++i;
4897 }
4898 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004899 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004900 }
4901 }
4902
4903 if (flags & P_FLAGLIST)
4904 {
4905 /* Remove flags that appear twice. */
4906 for (s = newval; *s; ++s)
4907 if ((!(flags & P_COMMA) || *s != ',')
4908 && vim_strchr(s + 1, *s) != NULL)
4909 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004910 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004911 --s;
4912 }
4913 }
4914
4915 if (save_arg != NULL) /* number for 'whichwrap' */
4916 arg = save_arg;
4917 new_value_alloced = TRUE;
4918 }
4919
4920 /* Set the new value. */
4921 *(char_u **)(varp) = newval;
4922
Bram Moolenaar53744302015-07-17 17:38:22 +02004923#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004924 if (!starting
4925# ifdef FEAT_CRYPT
4926 && options[opt_idx].indir != PV_KEY
4927# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004928 && origval != NULL)
4929 /* origval may be freed by
4930 * did_set_string_option(), make a copy. */
4931 saved_origval = vim_strsave(origval);
4932#endif
4933
Bram Moolenaar071d4272004-06-13 20:20:40 +00004934 /* Handle side effects, and set the global value for
4935 * ":set" on local options. */
4936 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4937 new_value_alloced, oldval, errbuf, opt_flags);
4938
4939 /* If error detected, print the error message. */
4940 if (errmsg != NULL)
4941 goto skip;
Bram Moolenaar53744302015-07-17 17:38:22 +02004942#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4943 if (saved_origval != NULL)
4944 {
4945 char_u buf_type[7];
4946
4947 sprintf((char *)buf_type, "%s",
4948 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004949 set_vim_var_string(VV_OPTION_NEW,
4950 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004951 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4952 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4953 apply_autocmds(EVENT_OPTIONSET,
4954 (char_u *)options[opt_idx].fullname,
4955 NULL, FALSE, NULL);
4956 reset_v_option_vars();
4957 vim_free(saved_origval);
4958 }
4959#endif
4960
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 }
4962 else /* key code option */
4963 {
4964 char_u *p;
4965
4966 if (nextchar == '&')
4967 {
4968 if (add_termcap_entry(key_name, TRUE) == FAIL)
4969 errmsg = (char_u *)N_("E522: Not found in termcap");
4970 }
4971 else
4972 {
4973 ++arg; /* jump to after the '=' or ':' */
4974 for (p = arg; *p && !vim_iswhite(*p); ++p)
4975 if (*p == '\\' && p[1] != NUL)
4976 ++p;
4977 nextchar = *p;
4978 *p = NUL;
4979 add_termcode(key_name, arg, FALSE);
4980 *p = nextchar;
4981 }
4982 if (full_screen)
4983 ttest(FALSE);
4984 redraw_all_later(CLEAR);
4985 }
4986 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004987
Bram Moolenaar071d4272004-06-13 20:20:40 +00004988 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004989 did_set_option(opt_idx, opt_flags,
4990 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004991 }
4992
4993skip:
4994 /*
4995 * Advance to next argument.
4996 * - skip until a blank found, taking care of backslashes
4997 * - skip blanks
4998 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4999 */
5000 for (i = 0; i < 2 ; ++i)
5001 {
5002 while (*arg != NUL && !vim_iswhite(*arg))
5003 if (*arg++ == '\\' && *arg != NUL)
5004 ++arg;
5005 arg = skipwhite(arg);
5006 if (*arg != '=')
5007 break;
5008 }
5009 }
5010
5011 if (errmsg != NULL)
5012 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005013 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005014 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005015 if (i + (arg - startarg) < IOSIZE)
5016 {
5017 /* append the argument with the error */
5018 STRCAT(IObuff, ": ");
5019 mch_memmove(IObuff + i, startarg, (arg - startarg));
5020 IObuff[i + (arg - startarg)] = NUL;
5021 }
5022 /* make sure all characters are printable */
5023 trans_characters(IObuff, IOSIZE);
5024
5025 ++no_wait_return; /* wait_return done later */
5026 emsg(IObuff); /* show error highlighted */
5027 --no_wait_return;
5028
5029 return FAIL;
5030 }
5031
5032 arg = skipwhite(arg);
5033 }
5034
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005035theend:
5036 if (silent_mode && did_show)
5037 {
5038 /* After displaying option values in silent mode. */
5039 silent_mode = FALSE;
5040 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5041 msg_putchar('\n');
5042 cursor_on(); /* msg_start() switches it off */
5043 out_flush();
5044 silent_mode = TRUE;
5045 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5046 }
5047
Bram Moolenaar071d4272004-06-13 20:20:40 +00005048 return OK;
5049}
5050
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005051/*
5052 * Call this when an option has been given a new value through a user command.
5053 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5054 */
5055 static void
5056did_set_option(opt_idx, opt_flags, new_value)
5057 int opt_idx;
5058 int opt_flags; /* possibly with OPT_MODELINE */
5059 int new_value; /* value was replaced completely */
5060{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005061 long_u *p;
5062
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005063 options[opt_idx].flags |= P_WAS_SET;
5064
5065 /* When an option is set in the sandbox, from a modeline or in secure mode
5066 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005067 * flag. */
5068 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005069 if (secure
5070#ifdef HAVE_SANDBOX
5071 || sandbox != 0
5072#endif
5073 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005074 *p = *p | P_INSECURE;
5075 else if (new_value)
5076 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005077}
5078
Bram Moolenaar071d4272004-06-13 20:20:40 +00005079 static char_u *
5080illegal_char(errbuf, c)
5081 char_u *errbuf;
5082 int c;
5083{
5084 if (errbuf == NULL)
5085 return (char_u *)"";
5086 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005087 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005088 return errbuf;
5089}
5090
5091/*
5092 * Convert a key name or string into a key value.
5093 * Used for 'wildchar' and 'cedit' options.
5094 */
5095 static int
5096string_to_key(arg)
5097 char_u *arg;
5098{
5099 if (*arg == '<')
5100 return find_key_option(arg + 1);
5101 if (*arg == '^')
5102 return Ctrl_chr(arg[1]);
5103 return *arg;
5104}
5105
5106#ifdef FEAT_CMDWIN
5107/*
5108 * Check value of 'cedit' and set cedit_key.
5109 * Returns NULL if value is OK, error message otherwise.
5110 */
5111 static char_u *
5112check_cedit()
5113{
5114 int n;
5115
5116 if (*p_cedit == NUL)
5117 cedit_key = -1;
5118 else
5119 {
5120 n = string_to_key(p_cedit);
5121 if (vim_isprintc(n))
5122 return e_invarg;
5123 cedit_key = n;
5124 }
5125 return NULL;
5126}
5127#endif
5128
5129#ifdef FEAT_TITLE
5130/*
5131 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5132 * maketitle() to create and display it.
5133 * When switching the title or icon off, call mch_restore_title() to get
5134 * the old value back.
5135 */
5136 static void
5137did_set_title(icon)
5138 int icon; /* Did set icon instead of title */
5139{
5140 if (starting != NO_SCREEN
5141#ifdef FEAT_GUI
5142 && !gui.starting
5143#endif
5144 )
5145 {
5146 maketitle();
5147 if (icon)
5148 {
5149 if (!p_icon)
5150 mch_restore_title(2);
5151 }
5152 else
5153 {
5154 if (!p_title)
5155 mch_restore_title(1);
5156 }
5157 }
5158}
5159#endif
5160
5161/*
5162 * set_options_bin - called when 'bin' changes value.
5163 */
5164 void
5165set_options_bin(oldval, newval, opt_flags)
5166 int oldval;
5167 int newval;
5168 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5169{
5170 /*
5171 * The option values that are changed when 'bin' changes are
5172 * copied when 'bin is set and restored when 'bin' is reset.
5173 */
5174 if (newval)
5175 {
5176 if (!oldval) /* switched on */
5177 {
5178 if (!(opt_flags & OPT_GLOBAL))
5179 {
5180 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5181 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5182 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5183 curbuf->b_p_et_nobin = curbuf->b_p_et;
5184 }
5185 if (!(opt_flags & OPT_LOCAL))
5186 {
5187 p_tw_nobin = p_tw;
5188 p_wm_nobin = p_wm;
5189 p_ml_nobin = p_ml;
5190 p_et_nobin = p_et;
5191 }
5192 }
5193
5194 if (!(opt_flags & OPT_GLOBAL))
5195 {
5196 curbuf->b_p_tw = 0; /* no automatic line wrap */
5197 curbuf->b_p_wm = 0; /* no automatic line wrap */
5198 curbuf->b_p_ml = 0; /* no modelines */
5199 curbuf->b_p_et = 0; /* no expandtab */
5200 }
5201 if (!(opt_flags & OPT_LOCAL))
5202 {
5203 p_tw = 0;
5204 p_wm = 0;
5205 p_ml = FALSE;
5206 p_et = FALSE;
5207 p_bin = TRUE; /* needed when called for the "-b" argument */
5208 }
5209 }
5210 else if (oldval) /* switched off */
5211 {
5212 if (!(opt_flags & OPT_GLOBAL))
5213 {
5214 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5215 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5216 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5217 curbuf->b_p_et = curbuf->b_p_et_nobin;
5218 }
5219 if (!(opt_flags & OPT_LOCAL))
5220 {
5221 p_tw = p_tw_nobin;
5222 p_wm = p_wm_nobin;
5223 p_ml = p_ml_nobin;
5224 p_et = p_et_nobin;
5225 }
5226 }
5227}
5228
5229#ifdef FEAT_VIMINFO
5230/*
5231 * Find the parameter represented by the given character (eg ', :, ", or /),
5232 * and return its associated value in the 'viminfo' string.
5233 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005234 * If the parameter is not specified in the string or there is no following
5235 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005236 */
5237 int
5238get_viminfo_parameter(type)
5239 int type;
5240{
5241 char_u *p;
5242
5243 p = find_viminfo_parameter(type);
5244 if (p != NULL && VIM_ISDIGIT(*p))
5245 return atoi((char *)p);
5246 return -1;
5247}
5248
5249/*
5250 * Find the parameter represented by the given character (eg ''', ':', '"', or
5251 * '/') in the 'viminfo' option and return a pointer to the string after it.
5252 * Return NULL if the parameter is not specified in the string.
5253 */
5254 char_u *
5255find_viminfo_parameter(type)
5256 int type;
5257{
5258 char_u *p;
5259
5260 for (p = p_viminfo; *p; ++p)
5261 {
5262 if (*p == type)
5263 return p + 1;
5264 if (*p == 'n') /* 'n' is always the last one */
5265 break;
5266 p = vim_strchr(p, ','); /* skip until next ',' */
5267 if (p == NULL) /* hit the end without finding parameter */
5268 break;
5269 }
5270 return NULL;
5271}
5272#endif
5273
5274/*
5275 * Expand environment variables for some string options.
5276 * These string options cannot be indirect!
5277 * If "val" is NULL expand the current value of the option.
5278 * Return pointer to NameBuff, or NULL when not expanded.
5279 */
5280 static char_u *
5281option_expand(opt_idx, val)
5282 int opt_idx;
5283 char_u *val;
5284{
5285 /* if option doesn't need expansion nothing to do */
5286 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5287 return NULL;
5288
5289 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5290 * expand_env() would truncate the string. */
5291 if (val != NULL && STRLEN(val) > MAXPATHL)
5292 return NULL;
5293
5294 if (val == NULL)
5295 val = *(char_u **)options[opt_idx].var;
5296
5297 /*
5298 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5299 * Escape spaces when expanding 'tags', they are used to separate file
5300 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005301 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005302 */
5303 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005304 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005305#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005306 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5307#endif
5308 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5310 return NULL;
5311
5312 return NameBuff;
5313}
5314
5315/*
5316 * After setting various option values: recompute variables that depend on
5317 * option values.
5318 */
5319 static void
5320didset_options()
5321{
5322 /* initialize the table for 'iskeyword' et.al. */
5323 (void)init_chartab();
5324
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005325#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005327#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005328 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005329 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330#ifdef FEAT_SESSION
5331 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5332 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5333#endif
5334#ifdef FEAT_FOLDING
5335 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5336#endif
5337 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5338#ifdef FEAT_VIRTUALEDIT
5339 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5340#endif
5341#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5342 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5343#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005344#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005345 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005346 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005347 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005348 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5351 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5352#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005353#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5355#endif
5356#ifdef FEAT_CMDWIN
5357 /* set cedit_key */
5358 (void)check_cedit();
5359#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005360#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005361 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005362#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005363#ifdef FEAT_LINEBREAK
5364 /* initialize the table for 'breakat'. */
5365 fill_breakat_flags();
5366#endif
5367
5368}
5369
5370/*
5371 * More side effects of setting options.
5372 */
5373 static void
5374didset_options2()
5375{
5376 /* Initialize the highlight_attr[] table. */
5377 (void)highlight_changed();
5378
5379 /* Parse default for 'wildmode' */
5380 check_opt_wim();
5381
5382 (void)set_chars_option(&p_lcs);
5383#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5384 /* Parse default for 'fillchars'. */
5385 (void)set_chars_option(&p_fcs);
5386#endif
5387
5388#ifdef FEAT_CLIPBOARD
5389 /* Parse default for 'clipboard' */
5390 (void)check_clipboard_option();
5391#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005392}
5393
5394/*
5395 * Check for string options that are NULL (normally only termcap options).
5396 */
5397 void
5398check_options()
5399{
5400 int opt_idx;
5401
5402 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5403 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5404 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5405}
5406
5407/*
5408 * Check string options in a buffer for NULL value.
5409 */
5410 void
5411check_buf_options(buf)
5412 buf_T *buf;
5413{
5414#if defined(FEAT_QUICKFIX)
5415 check_string_option(&buf->b_p_bh);
5416 check_string_option(&buf->b_p_bt);
5417#endif
5418#ifdef FEAT_MBYTE
5419 check_string_option(&buf->b_p_fenc);
5420#endif
5421 check_string_option(&buf->b_p_ff);
5422#ifdef FEAT_FIND_ID
5423 check_string_option(&buf->b_p_def);
5424 check_string_option(&buf->b_p_inc);
5425# ifdef FEAT_EVAL
5426 check_string_option(&buf->b_p_inex);
5427# endif
5428#endif
5429#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5430 check_string_option(&buf->b_p_inde);
5431 check_string_option(&buf->b_p_indk);
5432#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005433#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5434 check_string_option(&buf->b_p_bexpr);
5435#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005436#if defined(FEAT_CRYPT)
5437 check_string_option(&buf->b_p_cm);
5438#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005439#if defined(FEAT_EVAL)
5440 check_string_option(&buf->b_p_fex);
5441#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005442#ifdef FEAT_CRYPT
5443 check_string_option(&buf->b_p_key);
5444#endif
5445 check_string_option(&buf->b_p_kp);
5446 check_string_option(&buf->b_p_mps);
5447 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005448 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005449 check_string_option(&buf->b_p_isk);
5450#ifdef FEAT_COMMENTS
5451 check_string_option(&buf->b_p_com);
5452#endif
5453#ifdef FEAT_FOLDING
5454 check_string_option(&buf->b_p_cms);
5455#endif
5456 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005457#ifdef FEAT_TEXTOBJ
5458 check_string_option(&buf->b_p_qe);
5459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460#ifdef FEAT_SYN_HL
5461 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005462#endif
5463#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005464 check_string_option(&buf->b_s.b_p_spc);
5465 check_string_option(&buf->b_s.b_p_spf);
5466 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467#endif
5468#ifdef FEAT_SEARCHPATH
5469 check_string_option(&buf->b_p_sua);
5470#endif
5471#ifdef FEAT_CINDENT
5472 check_string_option(&buf->b_p_cink);
5473 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005474 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005475#endif
5476#ifdef FEAT_AUTOCMD
5477 check_string_option(&buf->b_p_ft);
5478#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005479#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5480 check_string_option(&buf->b_p_cinw);
5481#endif
5482#ifdef FEAT_INS_EXPAND
5483 check_string_option(&buf->b_p_cpt);
5484#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005485#ifdef FEAT_COMPL_FUNC
5486 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005487 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005488#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005489#ifdef FEAT_KEYMAP
5490 check_string_option(&buf->b_p_keymap);
5491#endif
5492#ifdef FEAT_QUICKFIX
5493 check_string_option(&buf->b_p_gp);
5494 check_string_option(&buf->b_p_mp);
5495 check_string_option(&buf->b_p_efm);
5496#endif
5497 check_string_option(&buf->b_p_ep);
5498 check_string_option(&buf->b_p_path);
5499 check_string_option(&buf->b_p_tags);
5500#ifdef FEAT_INS_EXPAND
5501 check_string_option(&buf->b_p_dict);
5502 check_string_option(&buf->b_p_tsr);
5503#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005504#ifdef FEAT_LISP
5505 check_string_option(&buf->b_p_lw);
5506#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005507 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508}
5509
5510/*
5511 * Free the string allocated for an option.
5512 * Checks for the string being empty_option. This may happen if we're out of
5513 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5514 * check_options().
5515 * Does NOT check for P_ALLOCED flag!
5516 */
5517 void
5518free_string_option(p)
5519 char_u *p;
5520{
5521 if (p != empty_option)
5522 vim_free(p);
5523}
5524
5525 void
5526clear_string_option(pp)
5527 char_u **pp;
5528{
5529 if (*pp != empty_option)
5530 vim_free(*pp);
5531 *pp = empty_option;
5532}
5533
5534 static void
5535check_string_option(pp)
5536 char_u **pp;
5537{
5538 if (*pp == NULL)
5539 *pp = empty_option;
5540}
5541
5542/*
5543 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5544 */
5545 void
5546set_term_option_alloced(p)
5547 char_u **p;
5548{
5549 int opt_idx;
5550
5551 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5552 if (options[opt_idx].var == (char_u *)p)
5553 {
5554 options[opt_idx].flags |= P_ALLOCED;
5555 return;
5556 }
5557 return; /* cannot happen: didn't find it! */
5558}
5559
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005560#if defined(FEAT_EVAL) || defined(PROTO)
5561/*
5562 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5563 * Return FALSE when it wasn't.
5564 * Return -1 for an unknown option.
5565 */
5566 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005567was_set_insecurely(opt, opt_flags)
5568 char_u *opt;
5569 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005570{
5571 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005572 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005573
5574 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005575 {
5576 flagp = insecure_flag(idx, opt_flags);
5577 return (*flagp & P_INSECURE) != 0;
5578 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005579 EMSG2(_(e_intern2), "was_set_insecurely()");
5580 return -1;
5581}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005582
5583/*
5584 * Get a pointer to the flags used for the P_INSECURE flag of option
5585 * "opt_idx". For some local options a local flags field is used.
5586 */
5587 static long_u *
5588insecure_flag(opt_idx, opt_flags)
5589 int opt_idx;
5590 int opt_flags;
5591{
5592 if (opt_flags & OPT_LOCAL)
5593 switch ((int)options[opt_idx].indir)
5594 {
5595#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005596 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005597#endif
5598#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005599# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005600 case PV_FDE: return &curwin->w_p_fde_flags;
5601 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005602# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005603# ifdef FEAT_BEVAL
5604 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5605# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005606# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005607 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005608# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005609 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005610# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005611 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005612# endif
5613#endif
5614 }
5615
5616 /* Nothing special, return global flags field. */
5617 return &options[opt_idx].flags;
5618}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005619#endif
5620
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005621#ifdef FEAT_TITLE
5622static void redraw_titles __ARGS((void));
5623
5624/*
5625 * Redraw the window title and/or tab page text later.
5626 */
5627static void redraw_titles()
5628{
5629 need_maketitle = TRUE;
5630# ifdef FEAT_WINDOWS
5631 redraw_tabline = TRUE;
5632# endif
5633}
5634#endif
5635
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636/*
5637 * Set a string option to a new value (without checking the effect).
5638 * The string is copied into allocated memory.
5639 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005640 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005641 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005642 */
5643 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005644set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645 char_u *name;
5646 int opt_idx;
5647 char_u *val;
5648 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005649 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650{
5651 char_u *s;
5652 char_u **varp;
5653 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005654 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655
Bram Moolenaar89d40322006-08-29 15:30:07 +00005656 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005658 idx = findoption(name);
5659 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005660 {
5661 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005662 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005664 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665 }
5666
Bram Moolenaar89d40322006-08-29 15:30:07 +00005667 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668 return;
5669
5670 s = vim_strsave(val);
5671 if (s != NULL)
5672 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005673 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005674 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005675 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676 free_string_option(*varp);
5677 *varp = s;
5678
5679 /* For buffer/window local option may also set the global value. */
5680 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005681 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682
Bram Moolenaar89d40322006-08-29 15:30:07 +00005683 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684
5685 /* When setting both values of a global option with a local value,
5686 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005687 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688 {
5689 free_string_option(*varp);
5690 *varp = empty_option;
5691 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005692# ifdef FEAT_EVAL
5693 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005694 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005695 set_sid == 0 ? current_SID : set_sid);
5696# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697 }
5698}
5699
5700/*
5701 * Set global value for string option when it's a local option.
5702 */
5703 static void
5704set_string_option_global(opt_idx, varp)
5705 int opt_idx; /* option index */
5706 char_u **varp; /* pointer to option variable */
5707{
5708 char_u **p, *s;
5709
5710 /* the global value is always allocated */
5711 if (options[opt_idx].var == VAR_WIN)
5712 p = (char_u **)GLOBAL_WO(varp);
5713 else
5714 p = (char_u **)options[opt_idx].var;
5715 if (options[opt_idx].indir != PV_NONE
5716 && p != varp
5717 && (s = vim_strsave(*varp)) != NULL)
5718 {
5719 free_string_option(*p);
5720 *p = s;
5721 }
5722}
5723
5724/*
5725 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005726 *
5727 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005729 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005730set_string_option(opt_idx, value, opt_flags)
5731 int opt_idx;
5732 char_u *value;
5733 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5734{
5735 char_u *s;
5736 char_u **varp;
5737 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005738#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5739 char_u *saved_oldval = NULL;
5740#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005741 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742
5743 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005744 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745
5746 s = vim_strsave(value);
5747 if (s != NULL)
5748 {
5749 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5750 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005751 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005752 ? OPT_GLOBAL : OPT_LOCAL)
5753 : opt_flags);
5754 oldval = *varp;
5755 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005756
5757#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005758 if (!starting
5759# ifdef FEAT_CRYPT
5760 && options[opt_idx].indir != PV_KEY
5761# endif
5762 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005763 saved_oldval = vim_strsave(oldval);
5764#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005765 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5766 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005767 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005768
5769 /* call autocomamnd after handling side effects */
5770#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5771 if (saved_oldval != NULL)
5772 {
5773 char_u buf_type[7];
5774 sprintf((char *)buf_type, "%s",
5775 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005776 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5777 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005778 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5779 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5780 reset_v_option_vars();
5781 vim_free(saved_oldval);
5782 }
5783#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005784 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005785 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005786}
5787
5788/*
5789 * Handle string options that need some action to perform when changed.
5790 * Returns NULL for success, or an error message for an error.
5791 */
5792 static char_u *
5793did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5794 opt_flags)
5795 int opt_idx; /* index in options[] table */
5796 char_u **varp; /* pointer to the option variable */
5797 int new_value_alloced; /* new value was allocated */
5798 char_u *oldval; /* previous value of the option */
5799 char_u *errbuf; /* buffer for errors, or NULL */
5800 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5801{
5802 char_u *errmsg = NULL;
5803 char_u *s, *p;
5804 int did_chartab = FALSE;
5805 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005806 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005807#ifdef FEAT_GUI
5808 /* set when changing an option that only requires a redraw in the GUI */
5809 int redraw_gui_only = FALSE;
5810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005811
5812 /* Get the global option to compare with, otherwise we would have to check
5813 * two values for all local options. */
5814 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5815
5816 /* Disallow changing some options from secure mode */
5817 if ((secure
5818#ifdef HAVE_SANDBOX
5819 || sandbox != 0
5820#endif
5821 ) && (options[opt_idx].flags & P_SECURE))
5822 {
5823 errmsg = e_secure;
5824 }
5825
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005826 /* Check for a "normal" file name in some options. Disallow a path
5827 * separator (slash and/or backslash), wildcards and characters that are
5828 * often illegal in a file name. */
5829 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005830 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005831 {
5832 errmsg = e_invarg;
5833 }
5834
Bram Moolenaar071d4272004-06-13 20:20:40 +00005835 /* 'term' */
5836 else if (varp == &T_NAME)
5837 {
5838 if (T_NAME[0] == NUL)
5839 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5840#ifdef FEAT_GUI
5841 if (gui.in_use)
5842 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5843 else if (term_is_gui(T_NAME))
5844 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5845#endif
5846 else if (set_termname(T_NAME) == FAIL)
5847 errmsg = (char_u *)N_("E522: Not found in termcap");
5848 else
5849 /* Screen colors may have changed. */
5850 redraw_later_clear();
5851 }
5852
5853 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005854 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005855 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005856 char_u *bkc = p_bkc;
5857 unsigned int *flags = &bkc_flags;
5858
5859 if (opt_flags & OPT_LOCAL)
5860 {
5861 bkc = curbuf->b_p_bkc;
5862 flags = &curbuf->b_bkc_flags;
5863 }
5864
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005865 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5866 /* make the local value empty: use the global value */
5867 *flags = 0;
5868 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005870 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5871 errmsg = e_invarg;
5872 if ((((int)*flags & BKC_AUTO) != 0)
5873 + (((int)*flags & BKC_YES) != 0)
5874 + (((int)*flags & BKC_NO) != 0) != 1)
5875 {
5876 /* Must have exactly one of "auto", "yes" and "no". */
5877 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5878 errmsg = e_invarg;
5879 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880 }
5881 }
5882
5883 /* 'backupext' and 'patchmode' */
5884 else if (varp == &p_bex || varp == &p_pm)
5885 {
5886 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5887 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5888 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5889 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005890#ifdef FEAT_LINEBREAK
5891 /* 'breakindentopt' */
5892 else if (varp == &curwin->w_p_briopt)
5893 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005894 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005895 errmsg = e_invarg;
5896 }
5897#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898
5899 /*
5900 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5901 * If the new option is invalid, use old value. 'lisp' option: refill
5902 * chartab[] for '-' char
5903 */
5904 else if ( varp == &p_isi
5905 || varp == &(curbuf->b_p_isk)
5906 || varp == &p_isp
5907 || varp == &p_isf)
5908 {
5909 if (init_chartab() == FAIL)
5910 {
5911 did_chartab = TRUE; /* need to restore it below */
5912 errmsg = e_invarg; /* error in value */
5913 }
5914 }
5915
5916 /* 'helpfile' */
5917 else if (varp == &p_hf)
5918 {
5919 /* May compute new values for $VIM and $VIMRUNTIME */
5920 if (didset_vim)
5921 {
5922 vim_setenv((char_u *)"VIM", (char_u *)"");
5923 didset_vim = FALSE;
5924 }
5925 if (didset_vimruntime)
5926 {
5927 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5928 didset_vimruntime = FALSE;
5929 }
5930 }
5931
Bram Moolenaar1a384422010-07-14 19:53:30 +02005932#ifdef FEAT_SYN_HL
5933 /* 'colorcolumn' */
5934 else if (varp == &curwin->w_p_cc)
5935 errmsg = check_colorcolumn(curwin);
5936#endif
5937
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938#ifdef FEAT_MULTI_LANG
5939 /* 'helplang' */
5940 else if (varp == &p_hlg)
5941 {
5942 /* Check for "", "ab", "ab,cd", etc. */
5943 for (s = p_hlg; *s != NUL; s += 3)
5944 {
5945 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5946 {
5947 errmsg = e_invarg;
5948 break;
5949 }
5950 if (s[2] == NUL)
5951 break;
5952 }
5953 }
5954#endif
5955
5956 /* 'highlight' */
5957 else if (varp == &p_hl)
5958 {
5959 if (highlight_changed() == FAIL)
5960 errmsg = e_invarg; /* invalid flags */
5961 }
5962
5963 /* 'nrformats' */
5964 else if (gvarp == &p_nf)
5965 {
5966 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5967 errmsg = e_invarg;
5968 }
5969
5970#ifdef FEAT_SESSION
5971 /* 'sessionoptions' */
5972 else if (varp == &p_ssop)
5973 {
5974 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5975 errmsg = e_invarg;
5976 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5977 {
5978 /* Don't allow both "sesdir" and "curdir". */
5979 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5980 errmsg = e_invarg;
5981 }
5982 }
5983 /* 'viewoptions' */
5984 else if (varp == &p_vop)
5985 {
5986 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5987 errmsg = e_invarg;
5988 }
5989#endif
5990
5991 /* 'scrollopt' */
5992#ifdef FEAT_SCROLLBIND
5993 else if (varp == &p_sbo)
5994 {
5995 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5996 errmsg = e_invarg;
5997 }
5998#endif
5999
6000 /* 'ambiwidth' */
6001#ifdef FEAT_MBYTE
6002 else if (varp == &p_ambw)
6003 {
6004 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6005 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006006 else if (set_chars_option(&p_lcs) != NULL)
6007 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6008# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6009 else if (set_chars_option(&p_fcs) != NULL)
6010 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6011# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006012 }
6013#endif
6014
6015 /* 'background' */
6016 else if (varp == &p_bg)
6017 {
6018 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6019 {
6020#ifdef FEAT_EVAL
6021 int dark = (*p_bg == 'd');
6022#endif
6023
6024 init_highlight(FALSE, FALSE);
6025
6026#ifdef FEAT_EVAL
6027 if (dark != (*p_bg == 'd')
6028 && get_var_value((char_u *)"g:colors_name") != NULL)
6029 {
6030 /* The color scheme must have set 'background' back to another
6031 * value, that's not what we want here. Disable the color
6032 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006033 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006034 free_string_option(p_bg);
6035 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6036 check_string_option(&p_bg);
6037 init_highlight(FALSE, FALSE);
6038 }
6039#endif
6040 }
6041 else
6042 errmsg = e_invarg;
6043 }
6044
6045 /* 'wildmode' */
6046 else if (varp == &p_wim)
6047 {
6048 if (check_opt_wim() == FAIL)
6049 errmsg = e_invarg;
6050 }
6051
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006052#ifdef FEAT_CMDL_COMPL
6053 /* 'wildoptions' */
6054 else if (varp == &p_wop)
6055 {
6056 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6057 errmsg = e_invarg;
6058 }
6059#endif
6060
Bram Moolenaar071d4272004-06-13 20:20:40 +00006061#ifdef FEAT_WAK
6062 /* 'winaltkeys' */
6063 else if (varp == &p_wak)
6064 {
6065 if (*p_wak == NUL
6066 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6067 errmsg = e_invarg;
6068# ifdef FEAT_MENU
6069# ifdef FEAT_GUI_MOTIF
6070 else if (gui.in_use)
6071 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6072# else
6073# ifdef FEAT_GUI_GTK
6074 else if (gui.in_use)
6075 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6076# endif
6077# endif
6078# endif
6079 }
6080#endif
6081
6082#ifdef FEAT_AUTOCMD
6083 /* 'eventignore' */
6084 else if (varp == &p_ei)
6085 {
6086 if (check_ei() == FAIL)
6087 errmsg = e_invarg;
6088 }
6089#endif
6090
6091#ifdef FEAT_MBYTE
6092 /* 'encoding' and 'fileencoding' */
6093 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6094 {
6095 if (gvarp == &p_fenc)
6096 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006097 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006098 errmsg = e_modifiable;
6099 else if (vim_strchr(*varp, ',') != NULL)
6100 /* No comma allowed in 'fileencoding'; catches confusing it
6101 * with 'fileencodings'. */
6102 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006103 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006104 {
6105# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006106 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006107 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006108# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006109 /* Add 'fileencoding' to the swap file. */
6110 ml_setflags(curbuf);
6111 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 }
6113 if (errmsg == NULL)
6114 {
6115 /* canonize the value, so that STRCMP() can be used on it */
6116 p = enc_canonize(*varp);
6117 if (p != NULL)
6118 {
6119 vim_free(*varp);
6120 *varp = p;
6121 }
6122 if (varp == &p_enc)
6123 {
6124 errmsg = mb_init();
6125# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006126 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127# endif
6128 }
6129 }
6130
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006131# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6133 {
6134 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6135 if (STRCMP(p_tenc, "utf-8") != 0)
6136 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6137 }
6138# endif
6139
6140 if (errmsg == NULL)
6141 {
6142# ifdef FEAT_KEYMAP
6143 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6144 * (with another encoding). */
6145 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6146 (void)keymap_init();
6147# endif
6148
6149 /* When 'termencoding' is not empty and 'encoding' changes or when
6150 * 'termencoding' changes, need to setup for keyboard input and
6151 * display output conversion. */
6152 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6153 {
6154 convert_setup(&input_conv, p_tenc, p_enc);
6155 convert_setup(&output_conv, p_enc, p_tenc);
6156 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006157
6158# if defined(WIN3264) && defined(FEAT_MBYTE)
6159 /* $HOME may have characters in active code page. */
6160 if (varp == &p_enc)
6161 init_homedir();
6162# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006163 }
6164 }
6165#endif
6166
6167#if defined(FEAT_POSTSCRIPT)
6168 else if (varp == &p_penc)
6169 {
6170 /* Canonize printencoding if VIM standard one */
6171 p = enc_canonize(p_penc);
6172 if (p != NULL)
6173 {
6174 vim_free(p_penc);
6175 p_penc = p;
6176 }
6177 else
6178 {
6179 /* Ensure lower case and '-' for '_' */
6180 for (s = p_penc; *s != NUL; s++)
6181 {
6182 if (*s == '_')
6183 *s = '-';
6184 else
6185 *s = TOLOWER_ASC(*s);
6186 }
6187 }
6188 }
6189#endif
6190
Bram Moolenaar9372a112005-12-06 19:59:18 +00006191#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006192 else if (varp == &p_imak)
6193 {
6194 if (gui.in_use && !im_xim_isvalid_imactivate())
6195 errmsg = e_invarg;
6196 }
6197#endif
6198
6199#ifdef FEAT_KEYMAP
6200 else if (varp == &curbuf->b_p_keymap)
6201 {
6202 /* load or unload key mapping tables */
6203 errmsg = keymap_init();
6204
Bram Moolenaarfab06232009-03-04 03:13:35 +00006205 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006206 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006207 if (*curbuf->b_p_keymap != NUL)
6208 {
6209 /* Installed a new keymap, switch on using it. */
6210 curbuf->b_p_iminsert = B_IMODE_LMAP;
6211 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6212 curbuf->b_p_imsearch = B_IMODE_LMAP;
6213 }
6214 else
6215 {
6216 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6217 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6218 curbuf->b_p_iminsert = B_IMODE_NONE;
6219 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6220 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6221 }
6222 if ((opt_flags & OPT_LOCAL) == 0)
6223 {
6224 set_iminsert_global();
6225 set_imsearch_global();
6226 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006227# ifdef FEAT_WINDOWS
6228 status_redraw_curbuf();
6229# endif
6230 }
6231 }
6232#endif
6233
6234 /* 'fileformat' */
6235 else if (gvarp == &p_ff)
6236 {
6237 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6238 errmsg = e_modifiable;
6239 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6240 errmsg = e_invarg;
6241 else
6242 {
6243 /* may also change 'textmode' */
6244 if (get_fileformat(curbuf) == EOL_DOS)
6245 curbuf->b_p_tx = TRUE;
6246 else
6247 curbuf->b_p_tx = FALSE;
6248#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006249 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006250#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006251 /* update flag in swap file */
6252 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006253 /* Redraw needed when switching to/from "mac": a CR in the text
6254 * will be displayed differently. */
6255 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6256 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006257 }
6258 }
6259
6260 /* 'fileformats' */
6261 else if (varp == &p_ffs)
6262 {
6263 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6264 errmsg = e_invarg;
6265 else
6266 {
6267 /* also change 'textauto' */
6268 if (*p_ffs == NUL)
6269 p_ta = FALSE;
6270 else
6271 p_ta = TRUE;
6272 }
6273 }
6274
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006275#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276 /* 'cryptkey' */
6277 else if (gvarp == &p_key)
6278 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006279# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006280 /* Make sure the ":set" command doesn't show the new value in the
6281 * history. */
6282 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006283# endif
6284 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6285 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006286 ml_set_crypt_key(curbuf, oldval,
6287 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006288 }
6289
6290 else if (gvarp == &p_cm)
6291 {
6292 if (opt_flags & OPT_LOCAL)
6293 p = curbuf->b_p_cm;
6294 else
6295 p = p_cm;
6296 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6297 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006298 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006299 errmsg = e_invarg;
6300 else
6301 {
6302 /* When setting the global value to empty, make it "zip". */
6303 if (*p_cm == NUL)
6304 {
6305 if (new_value_alloced)
6306 free_string_option(p_cm);
6307 p_cm = vim_strsave((char_u *)"zip");
6308 new_value_alloced = TRUE;
6309 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006310 /* When using ":set cm=name" the local value is going to be empty.
6311 * Do that here, otherwise the crypt functions will still use the
6312 * local value. */
6313 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6314 {
6315 free_string_option(curbuf->b_p_cm);
6316 curbuf->b_p_cm = empty_option;
6317 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006318
6319 /* Need to update the swapfile when the effective method changed.
6320 * Set "s" to the effective old value, "p" to the effective new
6321 * method and compare. */
6322 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6323 s = p_cm; /* was previously using the global value */
6324 else
6325 s = oldval;
6326 if (*curbuf->b_p_cm == NUL)
6327 p = p_cm; /* is now using the global value */
6328 else
6329 p = curbuf->b_p_cm;
6330 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006331 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006332
6333 /* If the global value changes need to update the swapfile for all
6334 * buffers using that value. */
6335 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6336 {
6337 buf_T *buf;
6338
6339 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6340 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006341 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006342 }
6343 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344 }
6345#endif
6346
6347 /* 'matchpairs' */
6348 else if (gvarp == &p_mps)
6349 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006350#ifdef FEAT_MBYTE
6351 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006352 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006353 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006355 int x2 = -1;
6356 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006357
6358 if (*p != NUL)
6359 p += mb_ptr2len(p);
6360 if (*p != NUL)
6361 x2 = *p++;
6362 if (*p != NUL)
6363 {
6364 x3 = mb_ptr2char(p);
6365 p += mb_ptr2len(p);
6366 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006367 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006368 {
6369 errmsg = e_invarg;
6370 break;
6371 }
6372 if (*p == NUL)
6373 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006375 }
6376 else
6377#endif
6378 {
6379 /* Check for "x:y,x:y" */
6380 for (p = *varp; *p != NUL; p += 4)
6381 {
6382 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6383 {
6384 errmsg = e_invarg;
6385 break;
6386 }
6387 if (p[3] == NUL)
6388 break;
6389 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006390 }
6391 }
6392
6393#ifdef FEAT_COMMENTS
6394 /* 'comments' */
6395 else if (gvarp == &p_com)
6396 {
6397 for (s = *varp; *s; )
6398 {
6399 while (*s && *s != ':')
6400 {
6401 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6402 && !VIM_ISDIGIT(*s) && *s != '-')
6403 {
6404 errmsg = illegal_char(errbuf, *s);
6405 break;
6406 }
6407 ++s;
6408 }
6409 if (*s++ == NUL)
6410 errmsg = (char_u *)N_("E524: Missing colon");
6411 else if (*s == ',' || *s == NUL)
6412 errmsg = (char_u *)N_("E525: Zero length string");
6413 if (errmsg != NULL)
6414 break;
6415 while (*s && *s != ',')
6416 {
6417 if (*s == '\\' && s[1] != NUL)
6418 ++s;
6419 ++s;
6420 }
6421 s = skip_to_option_part(s);
6422 }
6423 }
6424#endif
6425
6426 /* 'listchars' */
6427 else if (varp == &p_lcs)
6428 {
6429 errmsg = set_chars_option(varp);
6430 }
6431
6432#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6433 /* 'fillchars' */
6434 else if (varp == &p_fcs)
6435 {
6436 errmsg = set_chars_option(varp);
6437 }
6438#endif
6439
6440#ifdef FEAT_CMDWIN
6441 /* 'cedit' */
6442 else if (varp == &p_cedit)
6443 {
6444 errmsg = check_cedit();
6445 }
6446#endif
6447
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006448 /* 'verbosefile' */
6449 else if (varp == &p_vfile)
6450 {
6451 verbose_stop();
6452 if (*p_vfile != NUL && verbose_open() == FAIL)
6453 errmsg = e_invarg;
6454 }
6455
Bram Moolenaar071d4272004-06-13 20:20:40 +00006456#ifdef FEAT_VIMINFO
6457 /* 'viminfo' */
6458 else if (varp == &p_viminfo)
6459 {
6460 for (s = p_viminfo; *s;)
6461 {
6462 /* Check it's a valid character */
6463 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6464 {
6465 errmsg = illegal_char(errbuf, *s);
6466 break;
6467 }
6468 if (*s == 'n') /* name is always last one */
6469 {
6470 break;
6471 }
6472 else if (*s == 'r') /* skip until next ',' */
6473 {
6474 while (*++s && *s != ',')
6475 ;
6476 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006477 else if (*s == '%')
6478 {
6479 /* optional number */
6480 while (vim_isdigit(*++s))
6481 ;
6482 }
6483 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006484 ++s; /* no extra chars */
6485 else /* must have a number */
6486 {
6487 while (vim_isdigit(*++s))
6488 ;
6489
6490 if (!VIM_ISDIGIT(*(s - 1)))
6491 {
6492 if (errbuf != NULL)
6493 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006494 sprintf((char *)errbuf,
6495 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006496 transchar_byte(*(s - 1)));
6497 errmsg = errbuf;
6498 }
6499 else
6500 errmsg = (char_u *)"";
6501 break;
6502 }
6503 }
6504 if (*s == ',')
6505 ++s;
6506 else if (*s)
6507 {
6508 if (errbuf != NULL)
6509 errmsg = (char_u *)N_("E527: Missing comma");
6510 else
6511 errmsg = (char_u *)"";
6512 break;
6513 }
6514 }
6515 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6516 errmsg = (char_u *)N_("E528: Must specify a ' value");
6517 }
6518#endif /* FEAT_VIMINFO */
6519
6520 /* terminal options */
6521 else if (istermoption(&options[opt_idx]) && full_screen)
6522 {
6523 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6524 if (varp == &T_CCO)
6525 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006526 int colors = atoi((char *)T_CCO);
6527
6528 /* Only reinitialize colors if t_Co value has really changed to
6529 * avoid expensive reload of colorscheme if t_Co is set to the
6530 * same value multiple times. */
6531 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006532 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006533 t_colors = colors;
6534 if (t_colors <= 1)
6535 {
6536 if (new_value_alloced)
6537 vim_free(T_CCO);
6538 T_CCO = empty_option;
6539 }
6540 /* We now have a different color setup, initialize it again. */
6541 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006542 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006543 }
6544 ttest(FALSE);
6545 if (varp == &T_ME)
6546 {
6547 out_str(T_ME);
6548 redraw_later(CLEAR);
6549#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6550 /* Since t_me has been set, this probably means that the user
6551 * wants to use this as default colors. Need to reset default
6552 * background/foreground colors. */
6553 mch_set_normal_colors();
6554#endif
6555 }
6556 }
6557
6558#ifdef FEAT_LINEBREAK
6559 /* 'showbreak' */
6560 else if (varp == &p_sbr)
6561 {
6562 for (s = p_sbr; *s; )
6563 {
6564 if (ptr2cells(s) != 1)
6565 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006566 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 }
6568 }
6569#endif
6570
6571#ifdef FEAT_GUI
6572 /* 'guifont' */
6573 else if (varp == &p_guifont)
6574 {
6575 if (gui.in_use)
6576 {
6577 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006578# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006579 /*
6580 * Put up a font dialog and let the user select a new value.
6581 * If this is cancelled go back to the old value but don't
6582 * give an error message.
6583 */
6584 if (STRCMP(p, "*") == 0)
6585 {
6586 p = gui_mch_font_dialog(oldval);
6587
6588 if (new_value_alloced)
6589 free_string_option(p_guifont);
6590
6591 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6592 new_value_alloced = TRUE;
6593 }
6594# endif
6595 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6596 {
6597# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6598 if (STRCMP(p_guifont, "*") == 0)
6599 {
6600 /* Dialog was cancelled: Keep the old value without giving
6601 * an error message. */
6602 if (new_value_alloced)
6603 free_string_option(p_guifont);
6604 p_guifont = vim_strsave(oldval);
6605 new_value_alloced = TRUE;
6606 }
6607 else
6608# endif
6609 errmsg = (char_u *)N_("E596: Invalid font(s)");
6610 }
6611 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006612 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006613 }
6614# ifdef FEAT_XFONTSET
6615 else if (varp == &p_guifontset)
6616 {
6617 if (STRCMP(p_guifontset, "*") == 0)
6618 errmsg = (char_u *)N_("E597: can't select fontset");
6619 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6620 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006621 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006622 }
6623# endif
6624# ifdef FEAT_MBYTE
6625 else if (varp == &p_guifontwide)
6626 {
6627 if (STRCMP(p_guifontwide, "*") == 0)
6628 errmsg = (char_u *)N_("E533: can't select wide font");
6629 else if (gui_get_wide_font() == FAIL)
6630 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006631 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006632 }
6633# endif
6634#endif
6635
6636#ifdef CURSOR_SHAPE
6637 /* 'guicursor' */
6638 else if (varp == &p_guicursor)
6639 errmsg = parse_shape_opt(SHAPE_CURSOR);
6640#endif
6641
6642#ifdef FEAT_MOUSESHAPE
6643 /* 'mouseshape' */
6644 else if (varp == &p_mouseshape)
6645 {
6646 errmsg = parse_shape_opt(SHAPE_MOUSE);
6647 update_mouseshape(-1);
6648 }
6649#endif
6650
6651#ifdef FEAT_PRINTER
6652 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006653 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006654# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006655 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006656 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006657# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006658#endif
6659
6660#ifdef FEAT_LANGMAP
6661 /* 'langmap' */
6662 else if (varp == &p_langmap)
6663 langmap_set();
6664#endif
6665
6666#ifdef FEAT_LINEBREAK
6667 /* 'breakat' */
6668 else if (varp == &p_breakat)
6669 fill_breakat_flags();
6670#endif
6671
6672#ifdef FEAT_TITLE
6673 /* 'titlestring' and 'iconstring' */
6674 else if (varp == &p_titlestring || varp == &p_iconstring)
6675 {
6676# ifdef FEAT_STL_OPT
6677 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6678
6679 /* NULL => statusline syntax */
6680 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6681 stl_syntax |= flagval;
6682 else
6683 stl_syntax &= ~flagval;
6684# endif
6685 did_set_title(varp == &p_iconstring);
6686
6687 }
6688#endif
6689
6690#ifdef FEAT_GUI
6691 /* 'guioptions' */
6692 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006693 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006694 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006695 redraw_gui_only = TRUE;
6696 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006697#endif
6698
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006699#if defined(FEAT_GUI_TABLINE)
6700 /* 'guitablabel' */
6701 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006702 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006703 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006704 redraw_gui_only = TRUE;
6705 }
6706 /* 'guitabtooltip' */
6707 else if (varp == &p_gtt)
6708 {
6709 redraw_gui_only = TRUE;
6710 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006711#endif
6712
Bram Moolenaar071d4272004-06-13 20:20:40 +00006713#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6714 /* 'ttymouse' */
6715 else if (varp == &p_ttym)
6716 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006717 /* Switch the mouse off before changing the escape sequences used for
6718 * that. */
6719 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006720 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6721 errmsg = e_invarg;
6722 else
6723 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006724 if (termcap_active)
6725 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006726 }
6727#endif
6728
Bram Moolenaar071d4272004-06-13 20:20:40 +00006729 /* 'selection' */
6730 else if (varp == &p_sel)
6731 {
6732 if (*p_sel == NUL
6733 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6734 errmsg = e_invarg;
6735 }
6736
6737 /* 'selectmode' */
6738 else if (varp == &p_slm)
6739 {
6740 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6741 errmsg = e_invarg;
6742 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006743
6744#ifdef FEAT_BROWSE
6745 /* 'browsedir' */
6746 else if (varp == &p_bsdir)
6747 {
6748 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6749 && !mch_isdir(p_bsdir))
6750 errmsg = e_invarg;
6751 }
6752#endif
6753
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 /* 'keymodel' */
6755 else if (varp == &p_km)
6756 {
6757 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6758 errmsg = e_invarg;
6759 else
6760 {
6761 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6762 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6763 }
6764 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765
6766 /* 'mousemodel' */
6767 else if (varp == &p_mousem)
6768 {
6769 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6770 errmsg = e_invarg;
6771#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6772 else if (*p_mousem != *oldval)
6773 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6774 * to create or delete the popup menus. */
6775 gui_motif_update_mousemodel(root_menu);
6776#endif
6777 }
6778
6779 /* 'switchbuf' */
6780 else if (varp == &p_swb)
6781 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006782 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 errmsg = e_invarg;
6784 }
6785
6786 /* 'debug' */
6787 else if (varp == &p_debug)
6788 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006789 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 errmsg = e_invarg;
6791 }
6792
6793 /* 'display' */
6794 else if (varp == &p_dy)
6795 {
6796 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6797 errmsg = e_invarg;
6798 else
6799 (void)init_chartab();
6800
6801 }
6802
6803#ifdef FEAT_VERTSPLIT
6804 /* 'eadirection' */
6805 else if (varp == &p_ead)
6806 {
6807 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6808 errmsg = e_invarg;
6809 }
6810#endif
6811
6812#ifdef FEAT_CLIPBOARD
6813 /* 'clipboard' */
6814 else if (varp == &p_cb)
6815 errmsg = check_clipboard_option();
6816#endif
6817
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006818#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006819 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6820 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006821 else if (varp == &(curwin->w_s->b_p_spl)
6822 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006823 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006824 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006825 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006826 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006827 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006828 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006829 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006830 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006831 /* 'spellsuggest' */
6832 else if (varp == &p_sps)
6833 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006834 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006835 errmsg = e_invarg;
6836 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006837 /* 'mkspellmem' */
6838 else if (varp == &p_msm)
6839 {
6840 if (spell_check_msm() != OK)
6841 errmsg = e_invarg;
6842 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006843#endif
6844
Bram Moolenaar071d4272004-06-13 20:20:40 +00006845#ifdef FEAT_QUICKFIX
6846 /* When 'bufhidden' is set, check for valid value. */
6847 else if (gvarp == &p_bh)
6848 {
6849 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6850 errmsg = e_invarg;
6851 }
6852
6853 /* When 'buftype' is set, check for valid value. */
6854 else if (gvarp == &p_bt)
6855 {
6856 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6857 errmsg = e_invarg;
6858 else
6859 {
6860# ifdef FEAT_WINDOWS
6861 if (curwin->w_status_height)
6862 {
6863 curwin->w_redr_status = TRUE;
6864 redraw_later(VALID);
6865 }
6866# endif
6867 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006868# ifdef FEAT_TITLE
6869 redraw_titles();
6870# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871 }
6872 }
6873#endif
6874
6875#ifdef FEAT_STL_OPT
6876 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006877 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006878 {
6879 int wid;
6880
6881 if (varp == &p_ruf) /* reset ru_wid first */
6882 ru_wid = 0;
6883 s = *varp;
6884 if (varp == &p_ruf && *s == '%')
6885 {
6886 /* set ru_wid if 'ruf' starts with "%99(" */
6887 if (*++s == '-') /* ignore a '-' */
6888 s++;
6889 wid = getdigits(&s);
6890 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6891 ru_wid = wid;
6892 else
6893 errmsg = check_stl_option(p_ruf);
6894 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006895 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006896 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006897 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006898 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 comp_col();
6900 }
6901#endif
6902
6903#ifdef FEAT_INS_EXPAND
6904 /* check if it is a valid value for 'complete' -- Acevedo */
6905 else if (gvarp == &p_cpt)
6906 {
6907 for (s = *varp; *s;)
6908 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006909 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 s++;
6911 if (!*s)
6912 break;
6913 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6914 {
6915 errmsg = illegal_char(errbuf, *s);
6916 break;
6917 }
6918 if (*++s != NUL && *s != ',' && *s != ' ')
6919 {
6920 if (s[-1] == 'k' || s[-1] == 's')
6921 {
6922 /* skip optional filename after 'k' and 's' */
6923 while (*s && *s != ',' && *s != ' ')
6924 {
6925 if (*s == '\\')
6926 ++s;
6927 ++s;
6928 }
6929 }
6930 else
6931 {
6932 if (errbuf != NULL)
6933 {
6934 sprintf((char *)errbuf,
6935 _("E535: Illegal character after <%c>"),
6936 *--s);
6937 errmsg = errbuf;
6938 }
6939 else
6940 errmsg = (char_u *)"";
6941 break;
6942 }
6943 }
6944 }
6945 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006946
6947 /* 'completeopt' */
6948 else if (varp == &p_cot)
6949 {
6950 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6951 errmsg = e_invarg;
6952 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006953#endif /* FEAT_INS_EXPAND */
6954
6955
6956#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6957 else if (varp == &p_toolbar)
6958 {
6959 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6960 &toolbar_flags, TRUE) != OK)
6961 errmsg = e_invarg;
6962 else
6963 {
6964 out_flush();
6965 gui_mch_show_toolbar((toolbar_flags &
6966 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6967 }
6968 }
6969#endif
6970
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006971#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972 /* 'toolbariconsize': GTK+ 2 only */
6973 else if (varp == &p_tbis)
6974 {
6975 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6976 errmsg = e_invarg;
6977 else
6978 {
6979 out_flush();
6980 gui_mch_show_toolbar((toolbar_flags &
6981 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6982 }
6983 }
6984#endif
6985
6986 /* 'pastetoggle': translate key codes like in a mapping */
6987 else if (varp == &p_pt)
6988 {
6989 if (*p_pt)
6990 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006991 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992 if (p != NULL)
6993 {
6994 if (new_value_alloced)
6995 free_string_option(p_pt);
6996 p_pt = p;
6997 new_value_alloced = TRUE;
6998 }
6999 }
7000 }
7001
7002 /* 'backspace' */
7003 else if (varp == &p_bs)
7004 {
7005 if (VIM_ISDIGIT(*p_bs))
7006 {
7007 if (*p_bs >'2' || p_bs[1] != NUL)
7008 errmsg = e_invarg;
7009 }
7010 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7011 errmsg = e_invarg;
7012 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007013 else if (varp == &p_bo)
7014 {
7015 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7016 errmsg = e_invarg;
7017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007019#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007020 /* 'casemap' */
7021 else if (varp == &p_cmp)
7022 {
7023 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7024 errmsg = e_invarg;
7025 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007026#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027
7028#ifdef FEAT_DIFF
7029 /* 'diffopt' */
7030 else if (varp == &p_dip)
7031 {
7032 if (diffopt_changed() == FAIL)
7033 errmsg = e_invarg;
7034 }
7035#endif
7036
7037#ifdef FEAT_FOLDING
7038 /* 'foldmethod' */
7039 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7040 {
7041 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7042 || *curwin->w_p_fdm == NUL)
7043 errmsg = e_invarg;
7044 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007045 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007046 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007047 if (foldmethodIsDiff(curwin))
7048 newFoldLevel();
7049 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 }
7051# ifdef FEAT_EVAL
7052 /* 'foldexpr' */
7053 else if (varp == &curwin->w_p_fde)
7054 {
7055 if (foldmethodIsExpr(curwin))
7056 foldUpdateAll(curwin);
7057 }
7058# endif
7059 /* 'foldmarker' */
7060 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7061 {
7062 p = vim_strchr(*varp, ',');
7063 if (p == NULL)
7064 errmsg = (char_u *)N_("E536: comma required");
7065 else if (p == *varp || p[1] == NUL)
7066 errmsg = e_invarg;
7067 else if (foldmethodIsMarker(curwin))
7068 foldUpdateAll(curwin);
7069 }
7070 /* 'commentstring' */
7071 else if (gvarp == &p_cms)
7072 {
7073 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7074 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7075 }
7076 /* 'foldopen' */
7077 else if (varp == &p_fdo)
7078 {
7079 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7080 errmsg = e_invarg;
7081 }
7082 /* 'foldclose' */
7083 else if (varp == &p_fcl)
7084 {
7085 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7086 errmsg = e_invarg;
7087 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007088 /* 'foldignore' */
7089 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7090 {
7091 if (foldmethodIsIndent(curwin))
7092 foldUpdateAll(curwin);
7093 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007094#endif
7095
7096#ifdef FEAT_VIRTUALEDIT
7097 /* 'virtualedit' */
7098 else if (varp == &p_ve)
7099 {
7100 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7101 errmsg = e_invarg;
7102 else if (STRCMP(p_ve, oldval) != 0)
7103 {
7104 /* Recompute cursor position in case the new 've' setting
7105 * changes something. */
7106 validate_virtcol();
7107 coladvance(curwin->w_virtcol);
7108 }
7109 }
7110#endif
7111
7112#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7113 else if (varp == &p_csqf)
7114 {
7115 if (p_csqf != NULL)
7116 {
7117 p = p_csqf;
7118 while (*p != NUL)
7119 {
7120 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7121 || p[1] == NUL
7122 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7123 || (p[2] != NUL && p[2] != ','))
7124 {
7125 errmsg = e_invarg;
7126 break;
7127 }
7128 else if (p[2] == NUL)
7129 break;
7130 else
7131 p += 3;
7132 }
7133 }
7134 }
7135#endif
7136
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007137#ifdef FEAT_CINDENT
7138 /* 'cinoptions' */
7139 else if (gvarp == &p_cino)
7140 {
7141 /* TODO: recognize errors */
7142 parse_cino(curbuf);
7143 }
7144#endif
7145
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007146#if defined(FEAT_RENDER_OPTIONS)
7147 else if (varp == &p_rop && gui.in_use)
7148 {
7149 if (!gui_mch_set_rendering_options(p_rop))
7150 errmsg = e_invarg;
7151 }
7152#endif
7153
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 /* Options that are a list of flags. */
7155 else
7156 {
7157 p = NULL;
7158 if (varp == &p_ww)
7159 p = (char_u *)WW_ALL;
7160 if (varp == &p_shm)
7161 p = (char_u *)SHM_ALL;
7162 else if (varp == &(p_cpo))
7163 p = (char_u *)CPO_ALL;
7164 else if (varp == &(curbuf->b_p_fo))
7165 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007166#ifdef FEAT_CONCEAL
7167 else if (varp == &curwin->w_p_cocu)
7168 p = (char_u *)COCU_ALL;
7169#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007170 else if (varp == &p_mouse)
7171 {
7172#ifdef FEAT_MOUSE
7173 p = (char_u *)MOUSE_ALL;
7174#else
7175 if (*p_mouse != NUL)
7176 errmsg = (char_u *)N_("E538: No mouse support");
7177#endif
7178 }
7179#if defined(FEAT_GUI)
7180 else if (varp == &p_go)
7181 p = (char_u *)GO_ALL;
7182#endif
7183 if (p != NULL)
7184 {
7185 for (s = *varp; *s; ++s)
7186 if (vim_strchr(p, *s) == NULL)
7187 {
7188 errmsg = illegal_char(errbuf, *s);
7189 break;
7190 }
7191 }
7192 }
7193
7194 /*
7195 * If error detected, restore the previous value.
7196 */
7197 if (errmsg != NULL)
7198 {
7199 if (new_value_alloced)
7200 free_string_option(*varp);
7201 *varp = oldval;
7202 /*
7203 * When resetting some values, need to act on it.
7204 */
7205 if (did_chartab)
7206 (void)init_chartab();
7207 if (varp == &p_hl)
7208 (void)highlight_changed();
7209 }
7210 else
7211 {
7212#ifdef FEAT_EVAL
7213 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007214 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007215#endif
7216 /*
7217 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007218 * Use "free_oldval", because recursiveness may change the flags under
7219 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007221 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007222 free_string_option(oldval);
7223 if (new_value_alloced)
7224 options[opt_idx].flags |= P_ALLOCED;
7225 else
7226 options[opt_idx].flags &= ~P_ALLOCED;
7227
7228 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007229 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007230 {
7231 /* global option with local value set to use global value; free
7232 * the local value and make it empty */
7233 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7234 free_string_option(*(char_u **)p);
7235 *(char_u **)p = empty_option;
7236 }
7237
7238 /* May set global value for local option. */
7239 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7240 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007241
7242#ifdef FEAT_AUTOCMD
7243 /*
7244 * Trigger the autocommand only after setting the flags.
7245 */
7246# ifdef FEAT_SYN_HL
7247 /* When 'syntax' is set, load the syntax of that name */
7248 if (varp == &(curbuf->b_p_syn))
7249 {
7250 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7251 curbuf->b_fname, TRUE, curbuf);
7252 }
7253# endif
7254 else if (varp == &(curbuf->b_p_ft))
7255 {
7256 /* 'filetype' is set, trigger the FileType autocommand */
7257 did_filetype = TRUE;
7258 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7259 curbuf->b_fname, TRUE, curbuf);
7260 }
7261#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007262#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007263 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007264 {
7265 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007266 char_u *q = curwin->w_s->b_p_spl;
7267
7268 /* Skip the first name if it is "cjk". */
7269 if (STRNCMP(q, "cjk,", 4) == 0)
7270 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007271
7272 /*
7273 * Source the spell/LANG.vim in 'runtimepath'.
7274 * They could set 'spellcapcheck' depending on the language.
7275 * Use the first name in 'spelllang' up to '_region' or
7276 * '.encoding'.
7277 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007278 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007279 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7280 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007281 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007282 source_runtime(fname, TRUE);
7283 }
7284#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285 }
7286
7287#ifdef FEAT_MOUSE
7288 if (varp == &p_mouse)
7289 {
7290# ifdef FEAT_MOUSE_TTY
7291 if (*p_mouse == NUL)
7292 mch_setmouse(FALSE); /* switch mouse off */
7293 else
7294# endif
7295 setmouse(); /* in case 'mouse' changed */
7296 }
7297#endif
7298
Bram Moolenaar913077c2012-03-28 19:59:04 +02007299 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007300 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007301 curwin->w_set_curswant = TRUE;
7302
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007303#ifdef FEAT_GUI
7304 /* check redraw when it's not a GUI option or the GUI is active. */
7305 if (!redraw_gui_only || gui.in_use)
7306#endif
7307 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007308
7309 return errmsg;
7310}
7311
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007312#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007313/*
7314 * Simple int comparison function for use with qsort()
7315 */
7316 static int
7317int_cmp(a, b)
7318 const void *a;
7319 const void *b;
7320{
7321 return *(const int *)a - *(const int *)b;
7322}
7323
7324/*
7325 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7326 * Returns error message, NULL if it's OK.
7327 */
7328 char_u *
7329check_colorcolumn(wp)
7330 win_T *wp;
7331{
7332 char_u *s;
7333 int col;
7334 int count = 0;
7335 int color_cols[256];
7336 int i;
7337 int j = 0;
7338
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007339 if (wp->w_buffer == NULL)
7340 return NULL; /* buffer was closed */
7341
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007342 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007343 {
7344 if (*s == '-' || *s == '+')
7345 {
7346 /* -N and +N: add to 'textwidth' */
7347 col = (*s == '-') ? -1 : 1;
7348 ++s;
7349 if (!VIM_ISDIGIT(*s))
7350 return e_invarg;
7351 col = col * getdigits(&s);
7352 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007353 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007354 col += wp->w_buffer->b_p_tw;
7355 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007356 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007357 }
7358 else if (VIM_ISDIGIT(*s))
7359 col = getdigits(&s);
7360 else
7361 return e_invarg;
7362 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007363skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007364 if (*s == NUL)
7365 break;
7366 if (*s != ',')
7367 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007368 if (*++s == NUL)
7369 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007370 }
7371
7372 vim_free(wp->w_p_cc_cols);
7373 if (count == 0)
7374 wp->w_p_cc_cols = NULL;
7375 else
7376 {
7377 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7378 if (wp->w_p_cc_cols != NULL)
7379 {
7380 /* sort the columns for faster usage on screen redraw inside
7381 * win_line() */
7382 qsort(color_cols, count, sizeof(int), int_cmp);
7383
7384 for (i = 0; i < count; ++i)
7385 /* skip duplicates */
7386 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7387 wp->w_p_cc_cols[j++] = color_cols[i];
7388 wp->w_p_cc_cols[j] = -1; /* end marker */
7389 }
7390 }
7391
7392 return NULL; /* no error */
7393}
7394#endif
7395
Bram Moolenaar071d4272004-06-13 20:20:40 +00007396/*
7397 * Handle setting 'listchars' or 'fillchars'.
7398 * Returns error message, NULL if it's OK.
7399 */
7400 static char_u *
7401set_chars_option(varp)
7402 char_u **varp;
7403{
7404 int round, i, len, entries;
7405 char_u *p, *s;
7406 int c1, c2 = 0;
7407 struct charstab
7408 {
7409 int *cp;
7410 char *name;
7411 };
7412#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7413 static struct charstab filltab[] =
7414 {
7415 {&fill_stl, "stl"},
7416 {&fill_stlnc, "stlnc"},
7417 {&fill_vert, "vert"},
7418 {&fill_fold, "fold"},
7419 {&fill_diff, "diff"},
7420 };
7421#endif
7422 static struct charstab lcstab[] =
7423 {
7424 {&lcs_eol, "eol"},
7425 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007426 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007427 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007428 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007429 {&lcs_tab2, "tab"},
7430 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007431#ifdef FEAT_CONCEAL
7432 {&lcs_conceal, "conceal"},
7433#else
7434 {NULL, "conceal"},
7435#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007436 };
7437 struct charstab *tab;
7438
7439#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7440 if (varp == &p_lcs)
7441#endif
7442 {
7443 tab = lcstab;
7444 entries = sizeof(lcstab) / sizeof(struct charstab);
7445 }
7446#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7447 else
7448 {
7449 tab = filltab;
7450 entries = sizeof(filltab) / sizeof(struct charstab);
7451 }
7452#endif
7453
7454 /* first round: check for valid value, second round: assign values */
7455 for (round = 0; round <= 1; ++round)
7456 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007457 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007458 {
7459 /* After checking that the value is valid: set defaults: space for
7460 * 'fillchars', NUL for 'listchars' */
7461 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007462 if (tab[i].cp != NULL)
7463 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007464 if (varp == &p_lcs)
7465 lcs_tab1 = NUL;
7466#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7467 else
7468 fill_diff = '-';
7469#endif
7470 }
7471 p = *varp;
7472 while (*p)
7473 {
7474 for (i = 0; i < entries; ++i)
7475 {
7476 len = (int)STRLEN(tab[i].name);
7477 if (STRNCMP(p, tab[i].name, len) == 0
7478 && p[len] == ':'
7479 && p[len + 1] != NUL)
7480 {
7481 s = p + len + 1;
7482#ifdef FEAT_MBYTE
7483 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007484 if (mb_char2cells(c1) > 1)
7485 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486#else
7487 c1 = *s++;
7488#endif
7489 if (tab[i].cp == &lcs_tab2)
7490 {
7491 if (*s == NUL)
7492 continue;
7493#ifdef FEAT_MBYTE
7494 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007495 if (mb_char2cells(c2) > 1)
7496 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007497#else
7498 c2 = *s++;
7499#endif
7500 }
7501 if (*s == ',' || *s == NUL)
7502 {
7503 if (round)
7504 {
7505 if (tab[i].cp == &lcs_tab2)
7506 {
7507 lcs_tab1 = c1;
7508 lcs_tab2 = c2;
7509 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007510 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007511 *(tab[i].cp) = c1;
7512
7513 }
7514 p = s;
7515 break;
7516 }
7517 }
7518 }
7519
7520 if (i == entries)
7521 return e_invarg;
7522 if (*p == ',')
7523 ++p;
7524 }
7525 }
7526
7527 return NULL; /* no error */
7528}
7529
7530#ifdef FEAT_STL_OPT
7531/*
7532 * Check validity of options with the 'statusline' format.
7533 * Return error message or NULL.
7534 */
7535 char_u *
7536check_stl_option(s)
7537 char_u *s;
7538{
7539 int itemcnt = 0;
7540 int groupdepth = 0;
7541 static char_u errbuf[80];
7542
7543 while (*s && itemcnt < STL_MAX_ITEM)
7544 {
7545 /* Check for valid keys after % sequences */
7546 while (*s && *s != '%')
7547 s++;
7548 if (!*s)
7549 break;
7550 s++;
7551 if (*s != '%' && *s != ')')
7552 ++itemcnt;
7553 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7554 {
7555 s++;
7556 continue;
7557 }
7558 if (*s == ')')
7559 {
7560 s++;
7561 if (--groupdepth < 0)
7562 break;
7563 continue;
7564 }
7565 if (*s == '-')
7566 s++;
7567 while (VIM_ISDIGIT(*s))
7568 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007569 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570 continue;
7571 if (*s == '.')
7572 {
7573 s++;
7574 while (*s && VIM_ISDIGIT(*s))
7575 s++;
7576 }
7577 if (*s == '(')
7578 {
7579 groupdepth++;
7580 continue;
7581 }
7582 if (vim_strchr(STL_ALL, *s) == NULL)
7583 {
7584 return illegal_char(errbuf, *s);
7585 }
7586 if (*s == '{')
7587 {
7588 s++;
7589 while (*s != '}' && *s)
7590 s++;
7591 if (*s != '}')
7592 return (char_u *)N_("E540: Unclosed expression sequence");
7593 }
7594 }
7595 if (itemcnt >= STL_MAX_ITEM)
7596 return (char_u *)N_("E541: too many items");
7597 if (groupdepth != 0)
7598 return (char_u *)N_("E542: unbalanced groups");
7599 return NULL;
7600}
7601#endif
7602
7603#ifdef FEAT_CLIPBOARD
7604/*
7605 * Extract the items in the 'clipboard' option and set global values.
7606 */
7607 static char_u *
7608check_clipboard_option()
7609{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007610 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007611 int new_autoselect_star = FALSE;
7612 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007613 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007614 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007615 regprog_T *new_exclude_prog = NULL;
7616 char_u *errmsg = NULL;
7617 char_u *p;
7618
7619 for (p = p_cb; *p != NUL; )
7620 {
7621 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7622 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007623 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007624 p += 7;
7625 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007626 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007627 && (p[11] == ',' || p[11] == NUL))
7628 {
7629 new_unnamed |= CLIP_UNNAMED_PLUS;
7630 p += 11;
7631 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007632 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007633 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007634 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007635 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636 p += 10;
7637 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007638 else if (STRNCMP(p, "autoselectplus", 14) == 0
7639 && (p[14] == ',' || p[14] == NUL))
7640 {
7641 new_autoselect_plus = TRUE;
7642 p += 14;
7643 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007644 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007645 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007646 {
7647 new_autoselectml = TRUE;
7648 p += 12;
7649 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007650 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7651 {
7652 new_html = TRUE;
7653 p += 4;
7654 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007655 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7656 {
7657 p += 8;
7658 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7659 if (new_exclude_prog == NULL)
7660 errmsg = e_invarg;
7661 break;
7662 }
7663 else
7664 {
7665 errmsg = e_invarg;
7666 break;
7667 }
7668 if (*p == ',')
7669 ++p;
7670 }
7671 if (errmsg == NULL)
7672 {
7673 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007674 clip_autoselect_star = new_autoselect_star;
7675 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007676 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007677 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007678 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007679 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007680#ifdef FEAT_GUI_GTK
7681 if (gui.in_use)
7682 {
7683 gui_gtk_set_selection_targets();
7684 gui_gtk_set_dnd_targets();
7685 }
7686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007687 }
7688 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007689 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007690
7691 return errmsg;
7692}
7693#endif
7694
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007695#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007696 static char_u *
7697did_set_spell_option(is_spellfile)
7698 int is_spellfile;
7699{
7700 char_u *errmsg = NULL;
7701 win_T *wp;
7702 int l;
7703
7704 if (is_spellfile)
7705 {
7706 l = (int)STRLEN(curwin->w_s->b_p_spf);
7707 if (l > 0 && (l < 4
7708 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7709 errmsg = e_invarg;
7710 }
7711
7712 if (errmsg == NULL)
7713 {
7714 FOR_ALL_WINDOWS(wp)
7715 if (wp->w_buffer == curbuf && wp->w_p_spell)
7716 {
7717 errmsg = did_set_spelllang(wp);
7718# ifdef FEAT_WINDOWS
7719 break;
7720# endif
7721 }
7722 }
7723 return errmsg;
7724}
7725
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007726/*
7727 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7728 * Return error message when failed, NULL when OK.
7729 */
7730 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007731compile_cap_prog(synblock)
7732 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007733{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007734 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007735 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007736
Bram Moolenaar860cae12010-06-05 23:22:07 +02007737 if (*synblock->b_p_spc == NUL)
7738 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007739 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007740 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007741 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007742 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007743 if (re != NULL)
7744 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007745 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007746 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007747 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007748 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007749 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007750 return e_invarg;
7751 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007752 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007753 }
7754
Bram Moolenaar473de612013-06-08 18:19:48 +02007755 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007756 return NULL;
7757}
7758#endif
7759
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007760#if defined(FEAT_EVAL) || defined(PROTO)
7761/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007762 * Set the scriptID for an option, taking care of setting the buffer- or
7763 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007764 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007765 static void
7766set_option_scriptID_idx(opt_idx, opt_flags, id)
7767 int opt_idx;
7768 int opt_flags;
7769 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007770{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007771 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7772 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007773
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007774 /* Remember where the option was set. For local options need to do that
7775 * in the buffer or window structure. */
7776 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007777 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007778 if (both || (opt_flags & OPT_LOCAL))
7779 {
7780 if (indir & PV_BUF)
7781 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7782 else if (indir & PV_WIN)
7783 curwin->w_p_scriptID[indir & PV_MASK] = id;
7784 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007785}
7786#endif
7787
Bram Moolenaar071d4272004-06-13 20:20:40 +00007788/*
7789 * Set the value of a boolean option, and take care of side effects.
7790 * Returns NULL for success, or an error message for an error.
7791 */
7792 static char_u *
7793set_bool_option(opt_idx, varp, value, opt_flags)
7794 int opt_idx; /* index in options[] table */
7795 char_u *varp; /* pointer to the option variable */
7796 int value; /* new value */
7797 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7798{
7799 int old_value = *(int *)varp;
7800
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801 /* Disallow changing some options from secure mode */
7802 if ((secure
7803#ifdef HAVE_SANDBOX
7804 || sandbox != 0
7805#endif
7806 ) && (options[opt_idx].flags & P_SECURE))
7807 return e_secure;
7808
7809 *(int *)varp = value; /* set the new value */
7810#ifdef FEAT_EVAL
7811 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007812 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007813#endif
7814
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007815#ifdef FEAT_GUI
7816 need_mouse_correct = TRUE;
7817#endif
7818
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819 /* May set global value for local option. */
7820 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7821 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7822
7823 /*
7824 * Handle side effects of changing a bool option.
7825 */
7826
7827 /* 'compatible' */
7828 if ((int *)varp == &p_cp)
7829 {
7830 compatible_set();
7831 }
7832
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007833#ifdef FEAT_PERSISTENT_UNDO
7834 /* 'undofile' */
7835 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7836 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007837 /* Only take action when the option was set. When reset we do not
7838 * delete the undo file, the option may be set again without making
7839 * any changes in between. */
7840 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007841 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007842 char_u hash[UNDO_HASH_SIZE];
7843 buf_T *save_curbuf = curbuf;
7844
7845 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007846 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007847 /* When 'undofile' is set globally: for every buffer, otherwise
7848 * only for the current buffer: Try to read in the undofile,
7849 * if one exists, the buffer wasn't changed and the buffer was
7850 * loaded */
7851 if ((curbuf == save_curbuf
7852 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7853 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7854 {
7855 u_compute_hash(hash);
7856 u_read_undo(NULL, hash, curbuf->b_fname);
7857 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007858 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007859 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007860 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007861 }
7862#endif
7863
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864 else if ((int *)varp == &curbuf->b_p_ro)
7865 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007866 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007867 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7868 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007869
7870 /* when 'readonly' is set may give W10 again */
7871 if (curbuf->b_p_ro)
7872 curbuf->b_did_warn = FALSE;
7873
Bram Moolenaar071d4272004-06-13 20:20:40 +00007874#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007875 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007876#endif
7877 }
7878
Bram Moolenaar9c449722010-07-20 18:44:27 +02007879#ifdef FEAT_GUI
7880 else if ((int *)varp == &p_mh)
7881 {
7882 if (!p_mh)
7883 gui_mch_mousehide(FALSE);
7884 }
7885#endif
7886
Bram Moolenaara539df02010-08-01 14:35:05 +02007887#ifdef FEAT_TITLE
7888 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007890 {
7891 redraw_titles();
7892 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007893 /* when 'endofline' is changed, redraw the window title */
7894 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007895 {
7896 redraw_titles();
7897 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007898 /* when 'fixeol' is changed, redraw the window title */
7899 else if ((int *)varp == &curbuf->b_p_fixeol)
7900 {
7901 redraw_titles();
7902 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007903# ifdef FEAT_MBYTE
7904 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007905 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007906 {
7907 redraw_titles();
7908 }
7909# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007910#endif
7911
7912 /* when 'bin' is set also set some other options */
7913 else if ((int *)varp == &curbuf->b_p_bin)
7914 {
7915 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7916#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007917 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918#endif
7919 }
7920
7921#ifdef FEAT_AUTOCMD
7922 /* when 'buflisted' changes, trigger autocommands */
7923 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7924 {
7925 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7926 NULL, NULL, TRUE, curbuf);
7927 }
7928#endif
7929
7930 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7931 else if ((int *)varp == &curbuf->b_p_swf)
7932 {
7933 if (curbuf->b_p_swf && p_uc)
7934 ml_open_file(curbuf); /* create the swap file */
7935 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007936 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7937 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 mf_close_file(curbuf, TRUE); /* remove the swap file */
7939 }
7940
7941 /* when 'terse' is set change 'shortmess' */
7942 else if ((int *)varp == &p_terse)
7943 {
7944 char_u *p;
7945
7946 p = vim_strchr(p_shm, SHM_SEARCH);
7947
7948 /* insert 's' in p_shm */
7949 if (p_terse && p == NULL)
7950 {
7951 STRCPY(IObuff, p_shm);
7952 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007953 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 }
7955 /* remove 's' from p_shm */
7956 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007957 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 }
7959
7960 /* when 'paste' is set or reset also change other options */
7961 else if ((int *)varp == &p_paste)
7962 {
7963 paste_option_changed();
7964 }
7965
7966 /* when 'insertmode' is set from an autocommand need to do work here */
7967 else if ((int *)varp == &p_im)
7968 {
7969 if (p_im)
7970 {
7971 if ((State & INSERT) == 0)
7972 need_start_insertmode = TRUE;
7973 stop_insert_mode = FALSE;
7974 }
7975 else
7976 {
7977 need_start_insertmode = FALSE;
7978 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007979 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 clear_cmdline = TRUE; /* remove "(insert)" */
7981 restart_edit = 0;
7982 }
7983 }
7984
7985 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7986 else if ((int *)varp == &p_ic && p_hls)
7987 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007988 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007989 }
7990
7991#ifdef FEAT_SEARCH_EXTRA
7992 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7993 else if ((int *)varp == &p_hls)
7994 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007995 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996 }
7997#endif
7998
7999#ifdef FEAT_SCROLLBIND
8000 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8001 * at the end of normal_cmd() */
8002 else if ((int *)varp == &curwin->w_p_scb)
8003 {
8004 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008005 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008006 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008007 curwin->w_scbind_pos = curwin->w_topline;
8008 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009 }
8010#endif
8011
8012#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8013 /* There can be only one window with 'previewwindow' set. */
8014 else if ((int *)varp == &curwin->w_p_pvw)
8015 {
8016 if (curwin->w_p_pvw)
8017 {
8018 win_T *win;
8019
8020 for (win = firstwin; win != NULL; win = win->w_next)
8021 if (win->w_p_pvw && win != curwin)
8022 {
8023 curwin->w_p_pvw = FALSE;
8024 return (char_u *)N_("E590: A preview window already exists");
8025 }
8026 }
8027 }
8028#endif
8029
8030 /* when 'textmode' is set or reset also change 'fileformat' */
8031 else if ((int *)varp == &curbuf->b_p_tx)
8032 {
8033 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8034 }
8035
8036 /* when 'textauto' is set or reset also change 'fileformats' */
8037 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008038 set_string_option_direct((char_u *)"ffs", -1,
8039 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008040 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008041
8042 /*
8043 * When 'lisp' option changes include/exclude '-' in
8044 * keyword characters.
8045 */
8046#ifdef FEAT_LISP
8047 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8048 {
8049 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8050 }
8051#endif
8052
8053#ifdef FEAT_TITLE
8054 /* when 'title' changed, may need to change the title; same for 'icon' */
8055 else if ((int *)varp == &p_title)
8056 {
8057 did_set_title(FALSE);
8058 }
8059
8060 else if ((int *)varp == &p_icon)
8061 {
8062 did_set_title(TRUE);
8063 }
8064#endif
8065
8066 else if ((int *)varp == &curbuf->b_changed)
8067 {
8068 if (!value)
8069 save_file_ff(curbuf); /* Buffer is unchanged */
8070#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008071 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072#endif
8073#ifdef FEAT_AUTOCMD
8074 modified_was_set = value;
8075#endif
8076 }
8077
8078#ifdef BACKSLASH_IN_FILENAME
8079 else if ((int *)varp == &p_ssl)
8080 {
8081 if (p_ssl)
8082 {
8083 psepc = '/';
8084 psepcN = '\\';
8085 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086 }
8087 else
8088 {
8089 psepc = '\\';
8090 psepcN = '/';
8091 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008092 }
8093
8094 /* need to adjust the file name arguments and buffer names. */
8095 buflist_slash_adjust();
8096 alist_slash_adjust();
8097# ifdef FEAT_EVAL
8098 scriptnames_slash_adjust();
8099# endif
8100 }
8101#endif
8102
8103 /* If 'wrap' is set, set w_leftcol to zero. */
8104 else if ((int *)varp == &curwin->w_p_wrap)
8105 {
8106 if (curwin->w_p_wrap)
8107 curwin->w_leftcol = 0;
8108 }
8109
8110#ifdef FEAT_WINDOWS
8111 else if ((int *)varp == &p_ea)
8112 {
8113 if (p_ea && !old_value)
8114 win_equal(curwin, FALSE, 0);
8115 }
8116#endif
8117
8118 else if ((int *)varp == &p_wiv)
8119 {
8120 /*
8121 * When 'weirdinvert' changed, set/reset 't_xs'.
8122 * Then set 'weirdinvert' according to value of 't_xs'.
8123 */
8124 if (p_wiv && !old_value)
8125 T_XS = (char_u *)"y";
8126 else if (!p_wiv && old_value)
8127 T_XS = empty_option;
8128 p_wiv = (*T_XS != NUL);
8129 }
8130
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008131#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132 else if ((int *)varp == &p_beval)
8133 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008134 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008136 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137 gui_mch_disable_beval_area(balloonEval);
8138 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008139#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008140
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008141#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142 else if ((int *)varp == &p_acd)
8143 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008144 /* Change directories when the 'acd' option is set now. */
8145 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146 }
8147#endif
8148
8149#ifdef FEAT_DIFF
8150 /* 'diff' */
8151 else if ((int *)varp == &curwin->w_p_diff)
8152 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008153 /* May add or remove the buffer from the list of diff buffers. */
8154 diff_buf_adjust(curwin);
8155# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156 if (foldmethodIsDiff(curwin))
8157 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008158# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159 }
8160#endif
8161
8162#ifdef USE_IM_CONTROL
8163 /* 'imdisable' */
8164 else if ((int *)varp == &p_imdisable)
8165 {
8166 /* Only de-activate it here, it will be enabled when changing mode. */
8167 if (p_imdisable)
8168 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008169 else if (State & INSERT)
8170 /* When the option is set from an autocommand, it may need to take
8171 * effect right away. */
8172 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 }
8174#endif
8175
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008176#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008177 /* 'spell' */
8178 else if ((int *)varp == &curwin->w_p_spell)
8179 {
8180 if (curwin->w_p_spell)
8181 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008182 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008183 if (errmsg != NULL)
8184 EMSG(_(errmsg));
8185 }
8186 }
8187#endif
8188
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189#ifdef FEAT_FKMAP
8190 else if ((int *)varp == &p_altkeymap)
8191 {
8192 if (old_value != p_altkeymap)
8193 {
8194 if (!p_altkeymap)
8195 {
8196 p_hkmap = p_fkmap;
8197 p_fkmap = 0;
8198 }
8199 else
8200 {
8201 p_fkmap = p_hkmap;
8202 p_hkmap = 0;
8203 }
8204 (void)init_chartab();
8205 }
8206 }
8207
8208 /*
8209 * In case some second language keymapping options have changed, check
8210 * and correct the setting in a consistent way.
8211 */
8212
8213 /*
8214 * If hkmap or fkmap are set, reset Arabic keymapping.
8215 */
8216 if ((p_hkmap || p_fkmap) && p_altkeymap)
8217 {
8218 p_altkeymap = p_fkmap;
8219# ifdef FEAT_ARABIC
8220 curwin->w_p_arab = FALSE;
8221# endif
8222 (void)init_chartab();
8223 }
8224
8225 /*
8226 * If hkmap set, reset Farsi keymapping.
8227 */
8228 if (p_hkmap && p_altkeymap)
8229 {
8230 p_altkeymap = 0;
8231 p_fkmap = 0;
8232# ifdef FEAT_ARABIC
8233 curwin->w_p_arab = FALSE;
8234# endif
8235 (void)init_chartab();
8236 }
8237
8238 /*
8239 * If fkmap set, reset Hebrew keymapping.
8240 */
8241 if (p_fkmap && !p_altkeymap)
8242 {
8243 p_altkeymap = 1;
8244 p_hkmap = 0;
8245# ifdef FEAT_ARABIC
8246 curwin->w_p_arab = FALSE;
8247# endif
8248 (void)init_chartab();
8249 }
8250#endif
8251
8252#ifdef FEAT_ARABIC
8253 if ((int *)varp == &curwin->w_p_arab)
8254 {
8255 if (curwin->w_p_arab)
8256 {
8257 /*
8258 * 'arabic' is set, handle various sub-settings.
8259 */
8260 if (!p_tbidi)
8261 {
8262 /* set rightleft mode */
8263 if (!curwin->w_p_rl)
8264 {
8265 curwin->w_p_rl = TRUE;
8266 changed_window_setting();
8267 }
8268
8269 /* Enable Arabic shaping (major part of what Arabic requires) */
8270 if (!p_arshape)
8271 {
8272 p_arshape = TRUE;
8273 redraw_later_clear();
8274 }
8275 }
8276
8277 /* Arabic requires a utf-8 encoding, inform the user if its not
8278 * set. */
8279 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008280 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008281 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8282
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008283 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008284 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8285#ifdef FEAT_EVAL
8286 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8287#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008288 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289
8290# ifdef FEAT_MBYTE
8291 /* set 'delcombine' */
8292 p_deco = TRUE;
8293# endif
8294
8295# ifdef FEAT_KEYMAP
8296 /* Force-set the necessary keymap for arabic */
8297 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8298 OPT_LOCAL);
8299# endif
8300# ifdef FEAT_FKMAP
8301 p_altkeymap = 0;
8302 p_hkmap = 0;
8303 p_fkmap = 0;
8304 (void)init_chartab();
8305# endif
8306 }
8307 else
8308 {
8309 /*
8310 * 'arabic' is reset, handle various sub-settings.
8311 */
8312 if (!p_tbidi)
8313 {
8314 /* reset rightleft mode */
8315 if (curwin->w_p_rl)
8316 {
8317 curwin->w_p_rl = FALSE;
8318 changed_window_setting();
8319 }
8320
8321 /* 'arabicshape' isn't reset, it is a global option and
8322 * another window may still need it "on". */
8323 }
8324
8325 /* 'delcombine' isn't reset, it is a global option and another
8326 * window may still want it "on". */
8327
8328# ifdef FEAT_KEYMAP
8329 /* Revert to the default keymap */
8330 curbuf->b_p_iminsert = B_IMODE_NONE;
8331 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8332# endif
8333 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008334 }
8335
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008336#endif
8337
Bram Moolenaar071d4272004-06-13 20:20:40 +00008338 /*
8339 * End of handling side effects for bool options.
8340 */
8341
Bram Moolenaar53744302015-07-17 17:38:22 +02008342 /* after handling side effects, call autocommand */
8343
Bram Moolenaar071d4272004-06-13 20:20:40 +00008344 options[opt_idx].flags |= P_WAS_SET;
8345
Bram Moolenaar53744302015-07-17 17:38:22 +02008346#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8347 if (!starting)
8348 {
8349 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008350 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8351 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8352 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008353 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8354 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8355 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8356 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8357 reset_v_option_vars();
8358 }
8359#endif
8360
Bram Moolenaar071d4272004-06-13 20:20:40 +00008361 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008362 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008363 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008364 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365 check_redraw(options[opt_idx].flags);
8366
8367 return NULL;
8368}
8369
8370/*
8371 * Set the value of a number option, and take care of side effects.
8372 * Returns NULL for success, or an error message for an error.
8373 */
8374 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008375set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376 int opt_idx; /* index in options[] table */
8377 char_u *varp; /* pointer to the option variable */
8378 long value; /* new value */
8379 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008380 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008381 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8382 OPT_MODELINE */
8383{
8384 char_u *errmsg = NULL;
8385 long old_value = *(long *)varp;
8386 long old_Rows = Rows; /* remember old Rows */
8387 long old_Columns = Columns; /* remember old Columns */
8388 long *pp = (long *)varp;
8389
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008390 /* Disallow changing some options from secure mode. */
8391 if ((secure
8392#ifdef HAVE_SANDBOX
8393 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008395 ) && (options[opt_idx].flags & P_SECURE))
8396 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397
8398 *pp = value;
8399#ifdef FEAT_EVAL
8400 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008401 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008402#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008403#ifdef FEAT_GUI
8404 need_mouse_correct = TRUE;
8405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406
Bram Moolenaar14f24742012-08-08 18:01:05 +02008407 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 {
8409 errmsg = e_positive;
8410 curbuf->b_p_sw = curbuf->b_p_ts;
8411 }
8412
8413 /*
8414 * Number options that need some action when changed
8415 */
8416#ifdef FEAT_WINDOWS
8417 if (pp == &p_wh || pp == &p_hh)
8418 {
8419 if (p_wh < 1)
8420 {
8421 errmsg = e_positive;
8422 p_wh = 1;
8423 }
8424 if (p_wmh > p_wh)
8425 {
8426 errmsg = e_winheight;
8427 p_wh = p_wmh;
8428 }
8429 if (p_hh < 0)
8430 {
8431 errmsg = e_positive;
8432 p_hh = 0;
8433 }
8434
8435 /* Change window height NOW */
8436 if (lastwin != firstwin)
8437 {
8438 if (pp == &p_wh && curwin->w_height < p_wh)
8439 win_setheight((int)p_wh);
8440 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8441 win_setheight((int)p_hh);
8442 }
8443 }
8444
8445 /* 'winminheight' */
8446 else if (pp == &p_wmh)
8447 {
8448 if (p_wmh < 0)
8449 {
8450 errmsg = e_positive;
8451 p_wmh = 0;
8452 }
8453 if (p_wmh > p_wh)
8454 {
8455 errmsg = e_winheight;
8456 p_wmh = p_wh;
8457 }
8458 win_setminheight();
8459 }
8460
8461# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008462 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008463 {
8464 if (p_wiw < 1)
8465 {
8466 errmsg = e_positive;
8467 p_wiw = 1;
8468 }
8469 if (p_wmw > p_wiw)
8470 {
8471 errmsg = e_winwidth;
8472 p_wiw = p_wmw;
8473 }
8474
8475 /* Change window width NOW */
8476 if (lastwin != firstwin && curwin->w_width < p_wiw)
8477 win_setwidth((int)p_wiw);
8478 }
8479
8480 /* 'winminwidth' */
8481 else if (pp == &p_wmw)
8482 {
8483 if (p_wmw < 0)
8484 {
8485 errmsg = e_positive;
8486 p_wmw = 0;
8487 }
8488 if (p_wmw > p_wiw)
8489 {
8490 errmsg = e_winwidth;
8491 p_wmw = p_wiw;
8492 }
8493 win_setminheight();
8494 }
8495# endif
8496
8497#endif
8498
8499#ifdef FEAT_WINDOWS
8500 /* (re)set last window status line */
8501 else if (pp == &p_ls)
8502 {
8503 last_status(FALSE);
8504 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008505
8506 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008507 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008508 {
8509 shell_new_rows(); /* recompute window positions and heights */
8510 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008511#endif
8512
8513#ifdef FEAT_GUI
8514 else if (pp == &p_linespace)
8515 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008516 /* Recompute gui.char_height and resize the Vim window to keep the
8517 * same number of lines. */
8518 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008519 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 }
8521#endif
8522
8523#ifdef FEAT_FOLDING
8524 /* 'foldlevel' */
8525 else if (pp == &curwin->w_p_fdl)
8526 {
8527 if (curwin->w_p_fdl < 0)
8528 curwin->w_p_fdl = 0;
8529 newFoldLevel();
8530 }
8531
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008532 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533 else if (pp == &curwin->w_p_fml)
8534 {
8535 foldUpdateAll(curwin);
8536 }
8537
8538 /* 'foldnestmax' */
8539 else if (pp == &curwin->w_p_fdn)
8540 {
8541 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8542 foldUpdateAll(curwin);
8543 }
8544
8545 /* 'foldcolumn' */
8546 else if (pp == &curwin->w_p_fdc)
8547 {
8548 if (curwin->w_p_fdc < 0)
8549 {
8550 errmsg = e_positive;
8551 curwin->w_p_fdc = 0;
8552 }
8553 else if (curwin->w_p_fdc > 12)
8554 {
8555 errmsg = e_invarg;
8556 curwin->w_p_fdc = 12;
8557 }
8558 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008559#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008561#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008562 /* 'shiftwidth' or 'tabstop' */
8563 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8564 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008565# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008566 if (foldmethodIsIndent(curwin))
8567 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008568# endif
8569# ifdef FEAT_CINDENT
8570 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8571 * parse 'cinoptions'. */
8572 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8573 parse_cino(curbuf);
8574# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008576#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008578#ifdef FEAT_MBYTE
8579 /* 'maxcombine' */
8580 else if (pp == &p_mco)
8581 {
8582 if (p_mco > MAX_MCO)
8583 p_mco = MAX_MCO;
8584 else if (p_mco < 0)
8585 p_mco = 0;
8586 screenclear(); /* will re-allocate the screen */
8587 }
8588#endif
8589
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590 else if (pp == &curbuf->b_p_iminsert)
8591 {
8592 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8593 {
8594 errmsg = e_invarg;
8595 curbuf->b_p_iminsert = B_IMODE_NONE;
8596 }
8597 p_iminsert = curbuf->b_p_iminsert;
8598 if (termcap_active) /* don't do this in the alternate screen */
8599 showmode();
8600#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8601 /* Show/unshow value of 'keymap' in status lines. */
8602 status_redraw_curbuf();
8603#endif
8604 }
8605
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008606 else if (pp == &p_window)
8607 {
8608 if (p_window < 1)
8609 p_window = 1;
8610 else if (p_window >= Rows)
8611 p_window = Rows - 1;
8612 }
8613
Bram Moolenaar071d4272004-06-13 20:20:40 +00008614 else if (pp == &curbuf->b_p_imsearch)
8615 {
8616 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8617 {
8618 errmsg = e_invarg;
8619 curbuf->b_p_imsearch = B_IMODE_NONE;
8620 }
8621 p_imsearch = curbuf->b_p_imsearch;
8622 }
8623
8624#ifdef FEAT_TITLE
8625 /* if 'titlelen' has changed, redraw the title */
8626 else if (pp == &p_titlelen)
8627 {
8628 if (p_titlelen < 0)
8629 {
8630 errmsg = e_positive;
8631 p_titlelen = 85;
8632 }
8633 if (starting != NO_SCREEN && old_value != p_titlelen)
8634 need_maketitle = TRUE;
8635 }
8636#endif
8637
8638 /* if p_ch changed value, change the command line height */
8639 else if (pp == &p_ch)
8640 {
8641 if (p_ch < 1)
8642 {
8643 errmsg = e_positive;
8644 p_ch = 1;
8645 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008646 if (p_ch > Rows - min_rows() + 1)
8647 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648
8649 /* Only compute the new window layout when startup has been
8650 * completed. Otherwise the frame sizes may be wrong. */
8651 if (p_ch != old_value && full_screen
8652#ifdef FEAT_GUI
8653 && !gui.starting
8654#endif
8655 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008656 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008657 }
8658
8659 /* when 'updatecount' changes from zero to non-zero, open swap files */
8660 else if (pp == &p_uc)
8661 {
8662 if (p_uc < 0)
8663 {
8664 errmsg = e_positive;
8665 p_uc = 100;
8666 }
8667 if (p_uc && !old_value)
8668 ml_open_files();
8669 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008670#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008671 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008672 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008673 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008674 {
8675 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008676 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008677 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008678 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008679 {
8680 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008681 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008682 }
8683 }
8684#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008685#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008686 else if (pp == &p_mzq)
8687 mzvim_reset_timer();
8688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689
8690 /* sync undo before 'undolevels' changes */
8691 else if (pp == &p_ul)
8692 {
8693 /* use the old value, otherwise u_sync() may not work properly */
8694 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008695 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008696 p_ul = value;
8697 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008698 else if (pp == &curbuf->b_p_ul)
8699 {
8700 /* use the old value, otherwise u_sync() may not work properly */
8701 curbuf->b_p_ul = old_value;
8702 u_sync(TRUE);
8703 curbuf->b_p_ul = value;
8704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008706#ifdef FEAT_LINEBREAK
8707 /* 'numberwidth' must be positive */
8708 else if (pp == &curwin->w_p_nuw)
8709 {
8710 if (curwin->w_p_nuw < 1)
8711 {
8712 errmsg = e_positive;
8713 curwin->w_p_nuw = 1;
8714 }
8715 if (curwin->w_p_nuw > 10)
8716 {
8717 errmsg = e_invarg;
8718 curwin->w_p_nuw = 10;
8719 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008720 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008721 }
8722#endif
8723
Bram Moolenaar1a384422010-07-14 19:53:30 +02008724 else if (pp == &curbuf->b_p_tw)
8725 {
8726 if (curbuf->b_p_tw < 0)
8727 {
8728 errmsg = e_positive;
8729 curbuf->b_p_tw = 0;
8730 }
8731#ifdef FEAT_SYN_HL
8732# ifdef FEAT_WINDOWS
8733 {
8734 win_T *wp;
8735 tabpage_T *tp;
8736
8737 FOR_ALL_TAB_WINDOWS(tp, wp)
8738 check_colorcolumn(wp);
8739 }
8740# else
8741 check_colorcolumn(curwin);
8742# endif
8743#endif
8744 }
8745
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746 /*
8747 * Check the bounds for numeric options here
8748 */
8749 if (Rows < min_rows() && full_screen)
8750 {
8751 if (errbuf != NULL)
8752 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008753 vim_snprintf((char *)errbuf, errbuflen,
8754 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755 errmsg = errbuf;
8756 }
8757 Rows = min_rows();
8758 }
8759 if (Columns < MIN_COLUMNS && full_screen)
8760 {
8761 if (errbuf != NULL)
8762 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008763 vim_snprintf((char *)errbuf, errbuflen,
8764 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765 errmsg = errbuf;
8766 }
8767 Columns = MIN_COLUMNS;
8768 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008769 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008770
8771#ifdef DJGPP
8772 /* avoid a crash by checking for a too large value of 'columns' */
8773 if (old_Columns != Columns && full_screen && term_console)
8774 mch_check_columns();
8775#endif
8776
8777 /*
8778 * If the screen (shell) height has been changed, assume it is the
8779 * physical screenheight.
8780 */
8781 if (old_Rows != Rows || old_Columns != Columns)
8782 {
8783 /* Changing the screen size is not allowed while updating the screen. */
8784 if (updating_screen)
8785 *pp = old_value;
8786 else if (full_screen
8787#ifdef FEAT_GUI
8788 && !gui.starting
8789#endif
8790 )
8791 set_shellsize((int)Columns, (int)Rows, TRUE);
8792 else
8793 {
8794 /* Postpone the resizing; check the size and cmdline position for
8795 * messages. */
8796 check_shellsize();
8797 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8798 cmdline_row = Rows - p_ch;
8799 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008800 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008801 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802 }
8803
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 if (curbuf->b_p_ts <= 0)
8805 {
8806 errmsg = e_positive;
8807 curbuf->b_p_ts = 8;
8808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 if (p_tm < 0)
8810 {
8811 errmsg = e_positive;
8812 p_tm = 0;
8813 }
8814 if ((curwin->w_p_scr <= 0
8815 || (curwin->w_p_scr > curwin->w_height
8816 && curwin->w_height > 0))
8817 && full_screen)
8818 {
8819 if (pp == &(curwin->w_p_scr))
8820 {
8821 if (curwin->w_p_scr != 0)
8822 errmsg = e_scroll;
8823 win_comp_scroll(curwin);
8824 }
8825 /* If 'scroll' became invalid because of a side effect silently adjust
8826 * it. */
8827 else if (curwin->w_p_scr <= 0)
8828 curwin->w_p_scr = 1;
8829 else /* curwin->w_p_scr > curwin->w_height */
8830 curwin->w_p_scr = curwin->w_height;
8831 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008832 if (p_hi < 0)
8833 {
8834 errmsg = e_positive;
8835 p_hi = 0;
8836 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008837 else if (p_hi > 10000)
8838 {
8839 errmsg = e_invarg;
8840 p_hi = 10000;
8841 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008842 if (p_re < 0 || p_re > 2)
8843 {
8844 errmsg = e_invarg;
8845 p_re = 0;
8846 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008847 if (p_report < 0)
8848 {
8849 errmsg = e_positive;
8850 p_report = 1;
8851 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008852 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853 {
8854 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8855 p_sj = Rows / 2;
8856 else
8857 {
8858 errmsg = e_scroll;
8859 p_sj = 1;
8860 }
8861 }
8862 if (p_so < 0 && full_screen)
8863 {
8864 errmsg = e_scroll;
8865 p_so = 0;
8866 }
8867 if (p_siso < 0 && full_screen)
8868 {
8869 errmsg = e_positive;
8870 p_siso = 0;
8871 }
8872#ifdef FEAT_CMDWIN
8873 if (p_cwh < 1)
8874 {
8875 errmsg = e_positive;
8876 p_cwh = 1;
8877 }
8878#endif
8879 if (p_ut < 0)
8880 {
8881 errmsg = e_positive;
8882 p_ut = 2000;
8883 }
8884 if (p_ss < 0)
8885 {
8886 errmsg = e_positive;
8887 p_ss = 0;
8888 }
8889
8890 /* May set global value for local option. */
8891 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8892 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8893
8894 options[opt_idx].flags |= P_WAS_SET;
8895
Bram Moolenaar53744302015-07-17 17:38:22 +02008896#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8897 if (!starting && errmsg == NULL)
8898 {
8899 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008900 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8901 vim_snprintf((char *)buf_new, 10, "%ld", value);
8902 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008903 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8904 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8905 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8906 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8907 reset_v_option_vars();
8908 }
8909#endif
8910
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008912 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008913 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008914 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008915 check_redraw(options[opt_idx].flags);
8916
8917 return errmsg;
8918}
8919
8920/*
8921 * Called after an option changed: check if something needs to be redrawn.
8922 */
8923 static void
8924check_redraw(flags)
8925 long_u flags;
8926{
8927 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008928 int doclear = (flags & P_RCLR) == P_RCLR;
8929 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008930
8931#ifdef FEAT_WINDOWS
8932 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8933 status_redraw_all();
8934#endif
8935
8936 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8937 changed_window_setting();
8938 if (flags & P_RBUF)
8939 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008940 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941 redraw_all_later(CLEAR);
8942 else if (all)
8943 redraw_all_later(NOT_VALID);
8944}
8945
8946/*
8947 * Find index for option 'arg'.
8948 * Return -1 if not found.
8949 */
8950 static int
8951findoption(arg)
8952 char_u *arg;
8953{
8954 int opt_idx;
8955 char *s, *p;
8956 static short quick_tab[27] = {0, 0}; /* quick access table */
8957 int is_term_opt;
8958
8959 /*
8960 * For first call: Initialize the quick-access table.
8961 * It contains the index for the first option that starts with a certain
8962 * letter. There are 26 letters, plus the first "t_" option.
8963 */
8964 if (quick_tab[1] == 0)
8965 {
8966 p = options[0].fullname;
8967 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8968 {
8969 if (s[0] != p[0])
8970 {
8971 if (s[0] == 't' && s[1] == '_')
8972 quick_tab[26] = opt_idx;
8973 else
8974 quick_tab[CharOrdLow(s[0])] = opt_idx;
8975 }
8976 p = s;
8977 }
8978 }
8979
8980 /*
8981 * Check for name starting with an illegal character.
8982 */
8983#ifdef EBCDIC
8984 if (!islower(arg[0]))
8985#else
8986 if (arg[0] < 'a' || arg[0] > 'z')
8987#endif
8988 return -1;
8989
8990 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8991 if (is_term_opt)
8992 opt_idx = quick_tab[26];
8993 else
8994 opt_idx = quick_tab[CharOrdLow(arg[0])];
8995 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8996 {
8997 if (STRCMP(arg, s) == 0) /* match full name */
8998 break;
8999 }
9000 if (s == NULL && !is_term_opt)
9001 {
9002 opt_idx = quick_tab[CharOrdLow(arg[0])];
9003 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9004 {
9005 s = options[opt_idx].shortname;
9006 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9007 break;
9008 s = NULL;
9009 }
9010 }
9011 if (s == NULL)
9012 opt_idx = -1;
9013 return opt_idx;
9014}
9015
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009016#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009017/*
9018 * Get the value for an option.
9019 *
9020 * Returns:
9021 * Number or Toggle option: 1, *numval gets value.
9022 * String option: 0, *stringval gets allocated string.
9023 * Hidden Number or Toggle option: -1.
9024 * hidden String option: -2.
9025 * unknown option: -3.
9026 */
9027 int
9028get_option_value(name, numval, stringval, opt_flags)
9029 char_u *name;
9030 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009031 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009032 int opt_flags;
9033{
9034 int opt_idx;
9035 char_u *varp;
9036
9037 opt_idx = findoption(name);
9038 if (opt_idx < 0) /* unknown option */
9039 return -3;
9040
9041 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9042
9043 if (options[opt_idx].flags & P_STRING)
9044 {
9045 if (varp == NULL) /* hidden option */
9046 return -2;
9047 if (stringval != NULL)
9048 {
9049#ifdef FEAT_CRYPT
9050 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009051 if ((char_u **)varp == &curbuf->b_p_key
9052 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009053 *stringval = vim_strsave((char_u *)"*****");
9054 else
9055#endif
9056 *stringval = vim_strsave(*(char_u **)(varp));
9057 }
9058 return 0;
9059 }
9060
9061 if (varp == NULL) /* hidden option */
9062 return -1;
9063 if (options[opt_idx].flags & P_NUM)
9064 *numval = *(long *)varp;
9065 else
9066 {
9067 /* Special case: 'modified' is b_changed, but we also want to consider
9068 * it set when 'ff' or 'fenc' changed. */
9069 if ((int *)varp == &curbuf->b_changed)
9070 *numval = curbufIsChanged();
9071 else
9072 *numval = *(int *)varp;
9073 }
9074 return 1;
9075}
9076#endif
9077
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009078#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009079/*
9080 * Returns the option attributes and its value. Unlike the above function it
9081 * will return either global value or local value of the option depending on
9082 * what was requested, but it will never return global value if it was
9083 * requested to return local one and vice versa. Neither it will return
9084 * buffer-local value if it was requested to return window-local one.
9085 *
9086 * Pretends that option is absent if it is not present in the requested scope
9087 * (i.e. has no global, window-local or buffer-local value depending on
9088 * opt_type). Uses
9089 *
9090 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009091 * 0 hidden or unknown option, also option that does not have requested
9092 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009093 * see SOPT_* in vim.h for other flags
9094 *
9095 * Possible opt_type values: see SREQ_* in vim.h
9096 */
9097 int
9098get_option_value_strict(name, numval, stringval, opt_type, from)
9099 char_u *name;
9100 long *numval;
9101 char_u **stringval; /* NULL when only obtaining attributes */
9102 int opt_type;
9103 void *from;
9104{
9105 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009106 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009107 struct vimoption *p;
9108 int r = 0;
9109
9110 opt_idx = findoption(name);
9111 if (opt_idx < 0)
9112 return 0;
9113
9114 p = &(options[opt_idx]);
9115
9116 /* Hidden option */
9117 if (p->var == NULL)
9118 return 0;
9119
9120 if (p->flags & P_BOOL)
9121 r |= SOPT_BOOL;
9122 else if (p->flags & P_NUM)
9123 r |= SOPT_NUM;
9124 else if (p->flags & P_STRING)
9125 r |= SOPT_STRING;
9126
9127 if (p->indir == PV_NONE)
9128 {
9129 if (opt_type == SREQ_GLOBAL)
9130 r |= SOPT_GLOBAL;
9131 else
9132 return 0; /* Did not request global-only option */
9133 }
9134 else
9135 {
9136 if (p->indir & PV_BOTH)
9137 r |= SOPT_GLOBAL;
9138 else if (opt_type == SREQ_GLOBAL)
9139 return 0; /* Requested global option */
9140
9141 if (p->indir & PV_WIN)
9142 {
9143 if (opt_type == SREQ_BUF)
9144 return 0; /* Did not request window-local option */
9145 else
9146 r |= SOPT_WIN;
9147 }
9148 else if (p->indir & PV_BUF)
9149 {
9150 if (opt_type == SREQ_WIN)
9151 return 0; /* Did not request buffer-local option */
9152 else
9153 r |= SOPT_BUF;
9154 }
9155 }
9156
9157 if (stringval == NULL)
9158 return r;
9159
9160 if (opt_type == SREQ_GLOBAL)
9161 varp = p->var;
9162 else
9163 {
9164 if (opt_type == SREQ_BUF)
9165 {
9166 /* Special case: 'modified' is b_changed, but we also want to
9167 * consider it set when 'ff' or 'fenc' changed. */
9168 if (p->indir == PV_MOD)
9169 {
9170 *numval = bufIsChanged((buf_T *) from);
9171 varp = NULL;
9172 }
9173#ifdef FEAT_CRYPT
9174 else if (p->indir == PV_KEY)
9175 {
9176 /* never return the value of the crypt key */
9177 *stringval = NULL;
9178 varp = NULL;
9179 }
9180#endif
9181 else
9182 {
9183 aco_save_T aco;
9184 aucmd_prepbuf(&aco, (buf_T *) from);
9185 varp = get_varp(p);
9186 aucmd_restbuf(&aco);
9187 }
9188 }
9189 else if (opt_type == SREQ_WIN)
9190 {
9191 win_T *save_curwin;
9192 save_curwin = curwin;
9193 curwin = (win_T *) from;
9194 curbuf = curwin->w_buffer;
9195 varp = get_varp(p);
9196 curwin = save_curwin;
9197 curbuf = curwin->w_buffer;
9198 }
9199 if (varp == p->var)
9200 return (r | SOPT_UNSET);
9201 }
9202
9203 if (varp != NULL)
9204 {
9205 if (p->flags & P_STRING)
9206 *stringval = vim_strsave(*(char_u **)(varp));
9207 else if (p->flags & P_NUM)
9208 *numval = *(long *) varp;
9209 else
9210 *numval = *(int *)varp;
9211 }
9212
9213 return r;
9214}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009215
9216/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009217 * Iterate over options. First argument is a pointer to a pointer to a
9218 * structure inside options[] array, second is option type like in the above
9219 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009220 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009221 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009222 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009223 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009224 * first argument to NULL.
9225 *
9226 * Returns full option name for current option on each call.
9227 */
9228 char_u *
9229option_iter_next(option, opt_type)
9230 void **option;
9231 int opt_type;
9232{
9233 struct vimoption *ret = NULL;
9234 do
9235 {
9236 if (*option == NULL)
9237 *option = (void *) options;
9238 else if (((struct vimoption *) (*option))->fullname == NULL)
9239 {
9240 *option = NULL;
9241 return NULL;
9242 }
9243 else
9244 *option = (void *) (((struct vimoption *) (*option)) + 1);
9245
9246 ret = ((struct vimoption *) (*option));
9247
9248 /* Hidden option */
9249 if (ret->var == NULL)
9250 {
9251 ret = NULL;
9252 continue;
9253 }
9254
9255 switch (opt_type)
9256 {
9257 case SREQ_GLOBAL:
9258 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9259 ret = NULL;
9260 break;
9261 case SREQ_BUF:
9262 if (!(ret->indir & PV_BUF))
9263 ret = NULL;
9264 break;
9265 case SREQ_WIN:
9266 if (!(ret->indir & PV_WIN))
9267 ret = NULL;
9268 break;
9269 default:
9270 EMSG2(_(e_intern2), "option_iter_next()");
9271 return NULL;
9272 }
9273 }
9274 while (ret == NULL);
9275
9276 return (char_u *)ret->fullname;
9277}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009278#endif
9279
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280/*
9281 * Set the value of option "name".
9282 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009283 *
9284 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009285 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009286 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009287set_option_value(name, number, string, opt_flags)
9288 char_u *name;
9289 long number;
9290 char_u *string;
9291 int opt_flags; /* OPT_LOCAL or 0 (both) */
9292{
9293 int opt_idx;
9294 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009295 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009296
9297 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009298 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009299 EMSG2(_("E355: Unknown option: %s"), name);
9300 else
9301 {
9302 flags = options[opt_idx].flags;
9303#ifdef HAVE_SANDBOX
9304 /* Disallow changing some options in the sandbox */
9305 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009306 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009308 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009309 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009310#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009311 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009312 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009313 else
9314 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009315 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009316 if (varp != NULL) /* hidden option is not changed */
9317 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009318 if (number == 0 && string != NULL)
9319 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009320 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009321
9322 /* Either we are given a string or we are setting option
9323 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009324 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009325 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009326 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009327 {
9328 /* There's another character after zeros or the string
9329 * is empty. In both cases, we are trying to set a
9330 * num option using a string. */
9331 EMSG3(_("E521: Number required: &%s = '%s'"),
9332 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009333 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009334
9335 }
9336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009338 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009339 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009340 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009341 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009342 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343 }
9344 }
9345 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009346 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347}
9348
9349/*
9350 * Get the terminal code for a terminal option.
9351 * Returns NULL when not found.
9352 */
9353 char_u *
9354get_term_code(tname)
9355 char_u *tname;
9356{
9357 int opt_idx;
9358 char_u *varp;
9359
9360 if (tname[0] != 't' || tname[1] != '_' ||
9361 tname[2] == NUL || tname[3] == NUL)
9362 return NULL;
9363 if ((opt_idx = findoption(tname)) >= 0)
9364 {
9365 varp = get_varp(&(options[opt_idx]));
9366 if (varp != NULL)
9367 varp = *(char_u **)(varp);
9368 return varp;
9369 }
9370 return find_termcode(tname + 2);
9371}
9372
9373 char_u *
9374get_highlight_default()
9375{
9376 int i;
9377
9378 i = findoption((char_u *)"hl");
9379 if (i >= 0)
9380 return options[i].def_val[VI_DEFAULT];
9381 return (char_u *)NULL;
9382}
9383
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009384#if defined(FEAT_MBYTE) || defined(PROTO)
9385 char_u *
9386get_encoding_default()
9387{
9388 int i;
9389
9390 i = findoption((char_u *)"enc");
9391 if (i >= 0)
9392 return options[i].def_val[VI_DEFAULT];
9393 return (char_u *)NULL;
9394}
9395#endif
9396
Bram Moolenaar071d4272004-06-13 20:20:40 +00009397/*
9398 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9399 */
9400 static int
9401find_key_option(arg)
9402 char_u *arg;
9403{
9404 int key;
9405 int modifiers;
9406
9407 /*
9408 * Don't use get_special_key_code() for t_xx, we don't want it to call
9409 * add_termcap_entry().
9410 */
9411 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9412 key = TERMCAP2KEY(arg[2], arg[3]);
9413 else
9414 {
9415 --arg; /* put arg at the '<' */
9416 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009417 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418 if (modifiers) /* can't handle modifiers here */
9419 key = 0;
9420 }
9421 return key;
9422}
9423
9424/*
9425 * if 'all' == 0: show changed options
9426 * if 'all' == 1: show all normal options
9427 * if 'all' == 2: show all terminal options
9428 */
9429 static void
9430showoptions(all, opt_flags)
9431 int all;
9432 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9433{
9434 struct vimoption *p;
9435 int col;
9436 int isterm;
9437 char_u *varp;
9438 struct vimoption **items;
9439 int item_count;
9440 int run;
9441 int row, rows;
9442 int cols;
9443 int i;
9444 int len;
9445
9446#define INC 20
9447#define GAP 3
9448
9449 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9450 PARAM_COUNT));
9451 if (items == NULL)
9452 return;
9453
9454 /* Highlight title */
9455 if (all == 2)
9456 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9457 else if (opt_flags & OPT_GLOBAL)
9458 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9459 else if (opt_flags & OPT_LOCAL)
9460 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9461 else
9462 MSG_PUTS_TITLE(_("\n--- Options ---"));
9463
9464 /*
9465 * do the loop two times:
9466 * 1. display the short items
9467 * 2. display the long items (only strings and numbers)
9468 */
9469 for (run = 1; run <= 2 && !got_int; ++run)
9470 {
9471 /*
9472 * collect the items in items[]
9473 */
9474 item_count = 0;
9475 for (p = &options[0]; p->fullname != NULL; p++)
9476 {
9477 varp = NULL;
9478 isterm = istermoption(p);
9479 if (opt_flags != 0)
9480 {
9481 if (p->indir != PV_NONE && !isterm)
9482 varp = get_varp_scope(p, opt_flags);
9483 }
9484 else
9485 varp = get_varp(p);
9486 if (varp != NULL
9487 && ((all == 2 && isterm)
9488 || (all == 1 && !isterm)
9489 || (all == 0 && !optval_default(p, varp))))
9490 {
9491 if (p->flags & P_BOOL)
9492 len = 1; /* a toggle option fits always */
9493 else
9494 {
9495 option_value2string(p, opt_flags);
9496 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9497 }
9498 if ((len <= INC - GAP && run == 1) ||
9499 (len > INC - GAP && run == 2))
9500 items[item_count++] = p;
9501 }
9502 }
9503
9504 /*
9505 * display the items
9506 */
9507 if (run == 1)
9508 {
9509 cols = (Columns + GAP - 3) / INC;
9510 if (cols == 0)
9511 cols = 1;
9512 rows = (item_count + cols - 1) / cols;
9513 }
9514 else /* run == 2 */
9515 rows = item_count;
9516 for (row = 0; row < rows && !got_int; ++row)
9517 {
9518 msg_putchar('\n'); /* go to next line */
9519 if (got_int) /* 'q' typed in more */
9520 break;
9521 col = 0;
9522 for (i = row; i < item_count; i += rows)
9523 {
9524 msg_col = col; /* make columns */
9525 showoneopt(items[i], opt_flags);
9526 col += INC;
9527 }
9528 out_flush();
9529 ui_breakcheck();
9530 }
9531 }
9532 vim_free(items);
9533}
9534
9535/*
9536 * Return TRUE if option "p" has its default value.
9537 */
9538 static int
9539optval_default(p, varp)
9540 struct vimoption *p;
9541 char_u *varp;
9542{
9543 int dvi;
9544
9545 if (varp == NULL)
9546 return TRUE; /* hidden option is always at default */
9547 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9548 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009549 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009550 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009551 /* the cast to long is required for Manx C, long_i is
9552 * needed for MSVC */
9553 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009554 /* P_STRING */
9555 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9556}
9557
9558/*
9559 * showoneopt: show the value of one option
9560 * must not be called with a hidden option!
9561 */
9562 static void
9563showoneopt(p, opt_flags)
9564 struct vimoption *p;
9565 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9566{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009567 char_u *varp;
9568 int save_silent = silent_mode;
9569
9570 silent_mode = FALSE;
9571 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009572
9573 varp = get_varp_scope(p, opt_flags);
9574
9575 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9576 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9577 ? !curbufIsChanged() : !*(int *)varp))
9578 MSG_PUTS("no");
9579 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9580 MSG_PUTS("--");
9581 else
9582 MSG_PUTS(" ");
9583 MSG_PUTS(p->fullname);
9584 if (!(p->flags & P_BOOL))
9585 {
9586 msg_putchar('=');
9587 /* put value string in NameBuff */
9588 option_value2string(p, opt_flags);
9589 msg_outtrans(NameBuff);
9590 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009591
9592 silent_mode = save_silent;
9593 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009594}
9595
9596/*
9597 * Write modified options as ":set" commands to a file.
9598 *
9599 * There are three values for "opt_flags":
9600 * OPT_GLOBAL: Write global option values and fresh values of
9601 * buffer-local options (used for start of a session
9602 * file).
9603 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9604 * curwin (used for a vimrc file).
9605 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9606 * and local values for window-local options of
9607 * curwin. Local values are also written when at the
9608 * default value, because a modeline or autocommand
9609 * may have set them when doing ":edit file" and the
9610 * user has set them back at the default or fresh
9611 * value.
9612 * When "local_only" is TRUE, don't write fresh
9613 * values, only local values (for ":mkview").
9614 * (fresh value = value used for a new buffer or window for a local option).
9615 *
9616 * Return FAIL on error, OK otherwise.
9617 */
9618 int
9619makeset(fd, opt_flags, local_only)
9620 FILE *fd;
9621 int opt_flags;
9622 int local_only;
9623{
9624 struct vimoption *p;
9625 char_u *varp; /* currently used value */
9626 char_u *varp_fresh; /* local value */
9627 char_u *varp_local = NULL; /* fresh value */
9628 char *cmd;
9629 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009630 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009631
9632 /*
9633 * The options that don't have a default (terminal name, columns, lines)
9634 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009635 * Do the loop over "options[]" twice: once for options with the
9636 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009637 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009638 for (pri = 1; pri >= 0; --pri)
9639 {
9640 for (p = &options[0]; !istermoption(p); p++)
9641 if (!(p->flags & P_NO_MKRC)
9642 && !istermoption(p)
9643 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644 {
9645 /* skip global option when only doing locals */
9646 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9647 continue;
9648
9649 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9650 * file, they are always buffer-specific. */
9651 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9652 continue;
9653
9654 /* Global values are only written when not at the default value. */
9655 varp = get_varp_scope(p, opt_flags);
9656 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9657 continue;
9658
9659 round = 2;
9660 if (p->indir != PV_NONE)
9661 {
9662 if (p->var == VAR_WIN)
9663 {
9664 /* skip window-local option when only doing globals */
9665 if (!(opt_flags & OPT_LOCAL))
9666 continue;
9667 /* When fresh value of window-local option is not at the
9668 * default, need to write it too. */
9669 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9670 {
9671 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9672 if (!optval_default(p, varp_fresh))
9673 {
9674 round = 1;
9675 varp_local = varp;
9676 varp = varp_fresh;
9677 }
9678 }
9679 }
9680 }
9681
9682 /* Round 1: fresh value for window-local options.
9683 * Round 2: other values */
9684 for ( ; round <= 2; varp = varp_local, ++round)
9685 {
9686 if (round == 1 || (opt_flags & OPT_GLOBAL))
9687 cmd = "set";
9688 else
9689 cmd = "setlocal";
9690
9691 if (p->flags & P_BOOL)
9692 {
9693 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9694 return FAIL;
9695 }
9696 else if (p->flags & P_NUM)
9697 {
9698 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9699 return FAIL;
9700 }
9701 else /* P_STRING */
9702 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009703#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9704 int do_endif = FALSE;
9705
Bram Moolenaar071d4272004-06-13 20:20:40 +00009706 /* Don't set 'syntax' and 'filetype' again if the value is
9707 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009708 if (
9709# if defined(FEAT_SYN_HL)
9710 p->indir == PV_SYN
9711# if defined(FEAT_AUTOCMD)
9712 ||
9713# endif
9714# endif
9715# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009716 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009717# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009718 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009719 {
9720 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9721 *(char_u **)(varp)) < 0
9722 || put_eol(fd) < 0)
9723 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009724 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009727 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9728 (p->flags & P_EXPAND) != 0) == FAIL)
9729 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009730#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9731 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009732 {
9733 if (put_line(fd, "endif") == FAIL)
9734 return FAIL;
9735 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737 }
9738 }
9739 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009740 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741 return OK;
9742}
9743
9744#if defined(FEAT_FOLDING) || defined(PROTO)
9745/*
9746 * Generate set commands for the local fold options only. Used when
9747 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9748 */
9749 int
9750makefoldset(fd)
9751 FILE *fd;
9752{
9753 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9754# ifdef FEAT_EVAL
9755 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9756 == FAIL
9757# endif
9758 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9759 == FAIL
9760 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9761 == FAIL
9762 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9763 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9764 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9765 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9766 )
9767 return FAIL;
9768
9769 return OK;
9770}
9771#endif
9772
9773 static int
9774put_setstring(fd, cmd, name, valuep, expand)
9775 FILE *fd;
9776 char *cmd;
9777 char *name;
9778 char_u **valuep;
9779 int expand;
9780{
9781 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009782 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783
9784 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9785 return FAIL;
9786 if (*valuep != NULL)
9787 {
9788 /* Output 'pastetoggle' as key names. For other
9789 * options some characters have to be escaped with
9790 * CTRL-V or backslash */
9791 if (valuep == &p_pt)
9792 {
9793 s = *valuep;
9794 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009795 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009796 return FAIL;
9797 }
9798 else if (expand)
9799 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009800 buf = alloc(MAXPATHL);
9801 if (buf == NULL)
9802 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009803 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9804 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009805 {
9806 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009807 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009808 }
9809 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810 }
9811 else if (put_escstr(fd, *valuep, 2) == FAIL)
9812 return FAIL;
9813 }
9814 if (put_eol(fd) < 0)
9815 return FAIL;
9816 return OK;
9817}
9818
9819 static int
9820put_setnum(fd, cmd, name, valuep)
9821 FILE *fd;
9822 char *cmd;
9823 char *name;
9824 long *valuep;
9825{
9826 long wc;
9827
9828 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9829 return FAIL;
9830 if (wc_use_keyname((char_u *)valuep, &wc))
9831 {
9832 /* print 'wildchar' and 'wildcharm' as a key name */
9833 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9834 return FAIL;
9835 }
9836 else if (fprintf(fd, "%ld", *valuep) < 0)
9837 return FAIL;
9838 if (put_eol(fd) < 0)
9839 return FAIL;
9840 return OK;
9841}
9842
9843 static int
9844put_setbool(fd, cmd, name, value)
9845 FILE *fd;
9846 char *cmd;
9847 char *name;
9848 int value;
9849{
Bram Moolenaar893de922007-10-02 18:40:57 +00009850 if (value < 0) /* global/local option using global value */
9851 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009852 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9853 || put_eol(fd) < 0)
9854 return FAIL;
9855 return OK;
9856}
9857
9858/*
9859 * Clear all the terminal options.
9860 * If the option has been allocated, free the memory.
9861 * Terminal options are never hidden or indirect.
9862 */
9863 void
9864clear_termoptions()
9865{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009866 /*
9867 * Reset a few things before clearing the old options. This may cause
9868 * outputting a few things that the terminal doesn't understand, but the
9869 * screen will be cleared later, so this is OK.
9870 */
9871#ifdef FEAT_MOUSE_TTY
9872 mch_setmouse(FALSE); /* switch mouse off */
9873#endif
9874#ifdef FEAT_TITLE
9875 mch_restore_title(3); /* restore window titles */
9876#endif
9877#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9878 /* When starting the GUI close the display opened for the clipboard.
9879 * After restoring the title, because that will need the display. */
9880 if (gui.starting)
9881 clear_xterm_clip();
9882#endif
9883#ifdef WIN3264
9884 /*
9885 * Check if this is allowed now.
9886 */
9887 if (can_end_termcap_mode(FALSE) == TRUE)
9888#endif
9889 stoptermcap(); /* stop termcap mode */
9890
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009891 free_termoptions();
9892}
9893
9894 void
9895free_termoptions()
9896{
9897 struct vimoption *p;
9898
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899 for (p = &options[0]; p->fullname != NULL; p++)
9900 if (istermoption(p))
9901 {
9902 if (p->flags & P_ALLOCED)
9903 free_string_option(*(char_u **)(p->var));
9904 if (p->flags & P_DEF_ALLOCED)
9905 free_string_option(p->def_val[VI_DEFAULT]);
9906 *(char_u **)(p->var) = empty_option;
9907 p->def_val[VI_DEFAULT] = empty_option;
9908 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9909 }
9910 clear_termcodes();
9911}
9912
9913/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009914 * Free the string for one term option, if it was allocated.
9915 * Set the string to empty_option and clear allocated flag.
9916 * "var" points to the option value.
9917 */
9918 void
9919free_one_termoption(var)
9920 char_u *var;
9921{
9922 struct vimoption *p;
9923
9924 for (p = &options[0]; p->fullname != NULL; p++)
9925 if (p->var == var)
9926 {
9927 if (p->flags & P_ALLOCED)
9928 free_string_option(*(char_u **)(p->var));
9929 *(char_u **)(p->var) = empty_option;
9930 p->flags &= ~P_ALLOCED;
9931 break;
9932 }
9933}
9934
9935/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009936 * Set the terminal option defaults to the current value.
9937 * Used after setting the terminal name.
9938 */
9939 void
9940set_term_defaults()
9941{
9942 struct vimoption *p;
9943
9944 for (p = &options[0]; p->fullname != NULL; p++)
9945 {
9946 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9947 {
9948 if (p->flags & P_DEF_ALLOCED)
9949 {
9950 free_string_option(p->def_val[VI_DEFAULT]);
9951 p->flags &= ~P_DEF_ALLOCED;
9952 }
9953 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9954 if (p->flags & P_ALLOCED)
9955 {
9956 p->flags |= P_DEF_ALLOCED;
9957 p->flags &= ~P_ALLOCED; /* don't free the value now */
9958 }
9959 }
9960 }
9961}
9962
9963/*
9964 * return TRUE if 'p' starts with 't_'
9965 */
9966 static int
9967istermoption(p)
9968 struct vimoption *p;
9969{
9970 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9971}
9972
9973/*
9974 * Compute columns for ruler and shown command. 'sc_col' is also used to
9975 * decide what the maximum length of a message on the status line can be.
9976 * If there is a status line for the last window, 'sc_col' is independent
9977 * of 'ru_col'.
9978 */
9979
9980#define COL_RULER 17 /* columns needed by standard ruler */
9981
9982 void
9983comp_col()
9984{
9985#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9986 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9987
9988 sc_col = 0;
9989 ru_col = 0;
9990 if (p_ru)
9991 {
9992#ifdef FEAT_STL_OPT
9993 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9994#else
9995 ru_col = COL_RULER + 1;
9996#endif
9997 /* no last status line, adjust sc_col */
9998 if (!last_has_status)
9999 sc_col = ru_col;
10000 }
10001 if (p_sc)
10002 {
10003 sc_col += SHOWCMD_COLS;
10004 if (!p_ru || last_has_status) /* no need for separating space */
10005 ++sc_col;
10006 }
10007 sc_col = Columns - sc_col;
10008 ru_col = Columns - ru_col;
10009 if (sc_col <= 0) /* screen too narrow, will become a mess */
10010 sc_col = 1;
10011 if (ru_col <= 0)
10012 ru_col = 1;
10013#else
10014 sc_col = Columns;
10015 ru_col = Columns;
10016#endif
10017}
10018
10019/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010020 * Unset local option value, similar to ":set opt<".
10021 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010022 void
10023unset_global_local_option(name, from)
10024 char_u *name;
10025 void *from;
10026{
10027 struct vimoption *p;
10028 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010029 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010030
10031 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010032 if (opt_idx < 0)
10033 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010034 p = &(options[opt_idx]);
10035
10036 switch ((int)p->indir)
10037 {
10038 /* global option with local value: use local value if it's been set */
10039 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010040 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010041 break;
10042 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010043 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010044 break;
10045 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010046 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010047 break;
10048 case PV_AR:
10049 buf->b_p_ar = -1;
10050 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010051 case PV_BKC:
10052 clear_string_option(&buf->b_p_bkc);
10053 buf->b_bkc_flags = 0;
10054 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010055 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010056 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010057 break;
10058#ifdef FEAT_FIND_ID
10059 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010060 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010061 break;
10062 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010063 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010064 break;
10065#endif
10066#ifdef FEAT_INS_EXPAND
10067 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010068 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010069 break;
10070 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010071 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010072 break;
10073#endif
10074#ifdef FEAT_QUICKFIX
10075 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010076 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010077 break;
10078 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010079 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080 break;
10081 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010082 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010083 break;
10084#endif
10085#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10086 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010087 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010088 break;
10089#endif
10090#if defined(FEAT_CRYPT)
10091 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010092 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010093 break;
10094#endif
10095#ifdef FEAT_STL_OPT
10096 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010097 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010098 break;
10099#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010100 case PV_UL:
10101 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10102 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010103#ifdef FEAT_LISP
10104 case PV_LW:
10105 clear_string_option(&buf->b_p_lw);
10106 break;
10107#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010108 }
10109}
10110
10111/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010112 * Get pointer to option variable, depending on local or global scope.
10113 */
10114 static char_u *
10115get_varp_scope(p, opt_flags)
10116 struct vimoption *p;
10117 int opt_flags;
10118{
10119 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10120 {
10121 if (p->var == VAR_WIN)
10122 return (char_u *)GLOBAL_WO(get_varp(p));
10123 return p->var;
10124 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010125 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010126 {
10127 switch ((int)p->indir)
10128 {
10129#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010130 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10131 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10132 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010134 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10135 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10136 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010137 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010138 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010140 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10141 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010142#endif
10143#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010144 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10145 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010147#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10148 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10149#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010150#if defined(FEAT_CRYPT)
10151 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10152#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010153#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010154 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010155#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010156 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010157#ifdef FEAT_LISP
10158 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10159#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010160 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161 }
10162 return NULL; /* "cannot happen" */
10163 }
10164 return get_varp(p);
10165}
10166
10167/*
10168 * Get pointer to option variable.
10169 */
10170 static char_u *
10171get_varp(p)
10172 struct vimoption *p;
10173{
10174 /* hidden option, always return NULL */
10175 if (p->var == NULL)
10176 return NULL;
10177
10178 switch ((int)p->indir)
10179 {
10180 case PV_NONE: return p->var;
10181
10182 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010183 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010185 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010187 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010189 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010191 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010193 case PV_BKC: return *curbuf->b_p_bkc != NUL
10194 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010196 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010198 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10200#endif
10201#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010202 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010204 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10206#endif
10207#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010208 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010209 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010210 case PV_GP: return *curbuf->b_p_gp != NUL
10211 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10212 case PV_MP: return *curbuf->b_p_mp != NUL
10213 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010214#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010215#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10216 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10217 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10218#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010219#if defined(FEAT_CRYPT)
10220 case PV_CM: return *curbuf->b_p_cm != NUL
10221 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10222#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010223#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010224 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010225 ? (char_u *)&(curwin->w_p_stl) : p->var;
10226#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010227 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10228 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010229#ifdef FEAT_LISP
10230 case PV_LW: return *curbuf->b_p_lw != NUL
10231 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10232#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233
10234#ifdef FEAT_ARABIC
10235 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10236#endif
10237 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010238#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010239 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10240#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010241#ifdef FEAT_SYN_HL
10242 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10243 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010244 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246#ifdef FEAT_DIFF
10247 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10248#endif
10249#ifdef FEAT_FOLDING
10250 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10251 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10252 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10253 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10254 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10255 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10256 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10257# ifdef FEAT_EVAL
10258 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10259 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10260# endif
10261 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10262#endif
10263 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010264 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010265#ifdef FEAT_LINEBREAK
10266 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10267#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010268#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10270#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010271#ifdef FEAT_VERTSPLIT
10272 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10273#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10275 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10276#endif
10277#ifdef FEAT_RIGHTLEFT
10278 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10279 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10280#endif
10281 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10282 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10283#ifdef FEAT_LINEBREAK
10284 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010285 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10286 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010287#endif
10288#ifdef FEAT_SCROLLBIND
10289 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10290#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010291#ifdef FEAT_CURSORBIND
10292 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10293#endif
10294#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010295 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10296 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010297#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010298
10299 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10300 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10301#ifdef FEAT_MBYTE
10302 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10303#endif
10304#if defined(FEAT_QUICKFIX)
10305 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10306 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10307#endif
10308 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10309 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10310#ifdef FEAT_CINDENT
10311 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10312 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10313 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10314#endif
10315#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10316 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10317#endif
10318#ifdef FEAT_COMMENTS
10319 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10320#endif
10321#ifdef FEAT_FOLDING
10322 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10323#endif
10324#ifdef FEAT_INS_EXPAND
10325 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10326#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010327#ifdef FEAT_COMPL_FUNC
10328 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010329 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010332 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010333 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10334#ifdef FEAT_MBYTE
10335 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10336#endif
10337 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10338#ifdef FEAT_AUTOCMD
10339 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10340#endif
10341 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010342 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10344 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10345 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10346 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10347#ifdef FEAT_FIND_ID
10348# ifdef FEAT_EVAL
10349 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10350# endif
10351#endif
10352#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10353 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10354 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10355#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010356#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010357 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010359#ifdef FEAT_CRYPT
10360 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10361#endif
10362#ifdef FEAT_LISP
10363 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10364#endif
10365 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10366 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10367 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10368 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10369 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010371#ifdef FEAT_TEXTOBJ
10372 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010374 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10375#ifdef FEAT_SMARTINDENT
10376 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10377#endif
10378#ifndef SHORT_FNAME
10379 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10380#endif
10381 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10382#ifdef FEAT_SEARCHPATH
10383 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10384#endif
10385 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10386#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010387 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010388 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10389#endif
10390#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010391 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10392 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10393 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010394#endif
10395 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10396 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10397 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10398 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010399#ifdef FEAT_PERSISTENT_UNDO
10400 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10401#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10403#ifdef FEAT_KEYMAP
10404 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10405#endif
10406 default: EMSG(_("E356: get_varp ERROR"));
10407 }
10408 /* always return a valid pointer to avoid a crash! */
10409 return (char_u *)&(curbuf->b_p_wm);
10410}
10411
10412/*
10413 * Get the value of 'equalprg', either the buffer-local one or the global one.
10414 */
10415 char_u *
10416get_equalprg()
10417{
10418 if (*curbuf->b_p_ep == NUL)
10419 return p_ep;
10420 return curbuf->b_p_ep;
10421}
10422
10423#if defined(FEAT_WINDOWS) || defined(PROTO)
10424/*
10425 * Copy options from one window to another.
10426 * Used when splitting a window.
10427 */
10428 void
10429win_copy_options(wp_from, wp_to)
10430 win_T *wp_from;
10431 win_T *wp_to;
10432{
10433 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10434 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10435# ifdef FEAT_RIGHTLEFT
10436# ifdef FEAT_FKMAP
10437 /* Is this right? */
10438 wp_to->w_farsi = wp_from->w_farsi;
10439# endif
10440# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010441#if defined(FEAT_LINEBREAK)
10442 briopt_check(wp_to);
10443#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010444}
10445#endif
10446
10447/*
10448 * Copy the options from one winopt_T to another.
10449 * Doesn't free the old option values in "to", use clear_winopt() for that.
10450 * The 'scroll' option is not copied, because it depends on the window height.
10451 * The 'previewwindow' option is reset, there can be only one preview window.
10452 */
10453 void
10454copy_winopt(from, to)
10455 winopt_T *from;
10456 winopt_T *to;
10457{
10458#ifdef FEAT_ARABIC
10459 to->wo_arab = from->wo_arab;
10460#endif
10461 to->wo_list = from->wo_list;
10462 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010463 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010464#ifdef FEAT_LINEBREAK
10465 to->wo_nuw = from->wo_nuw;
10466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010467#ifdef FEAT_RIGHTLEFT
10468 to->wo_rl = from->wo_rl;
10469 to->wo_rlc = vim_strsave(from->wo_rlc);
10470#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010471#ifdef FEAT_STL_OPT
10472 to->wo_stl = vim_strsave(from->wo_stl);
10473#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010474 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010475#ifdef FEAT_DIFF
10476 to->wo_wrap_save = from->wo_wrap_save;
10477#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010478#ifdef FEAT_LINEBREAK
10479 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010480 to->wo_bri = from->wo_bri;
10481 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482#endif
10483#ifdef FEAT_SCROLLBIND
10484 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010485 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010487#ifdef FEAT_CURSORBIND
10488 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010489 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010490#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010491#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010492 to->wo_spell = from->wo_spell;
10493#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010494#ifdef FEAT_SYN_HL
10495 to->wo_cuc = from->wo_cuc;
10496 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010497 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499#ifdef FEAT_DIFF
10500 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010501 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010503#ifdef FEAT_CONCEAL
10504 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010505 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010506#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507#ifdef FEAT_FOLDING
10508 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010509 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010511 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512 to->wo_fdi = vim_strsave(from->wo_fdi);
10513 to->wo_fml = from->wo_fml;
10514 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010515 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010517 to->wo_fdm_save = from->wo_diff_saved
10518 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519 to->wo_fdn = from->wo_fdn;
10520# ifdef FEAT_EVAL
10521 to->wo_fde = vim_strsave(from->wo_fde);
10522 to->wo_fdt = vim_strsave(from->wo_fdt);
10523# endif
10524 to->wo_fmr = vim_strsave(from->wo_fmr);
10525#endif
10526 check_winopt(to); /* don't want NULL pointers */
10527}
10528
10529/*
10530 * Check string options in a window for a NULL value.
10531 */
10532 void
10533check_win_options(win)
10534 win_T *win;
10535{
10536 check_winopt(&win->w_onebuf_opt);
10537 check_winopt(&win->w_allbuf_opt);
10538}
10539
10540/*
10541 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10542 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010543 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010545 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010546{
10547#ifdef FEAT_FOLDING
10548 check_string_option(&wop->wo_fdi);
10549 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010550 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551# ifdef FEAT_EVAL
10552 check_string_option(&wop->wo_fde);
10553 check_string_option(&wop->wo_fdt);
10554# endif
10555 check_string_option(&wop->wo_fmr);
10556#endif
10557#ifdef FEAT_RIGHTLEFT
10558 check_string_option(&wop->wo_rlc);
10559#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010560#ifdef FEAT_STL_OPT
10561 check_string_option(&wop->wo_stl);
10562#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010563#ifdef FEAT_SYN_HL
10564 check_string_option(&wop->wo_cc);
10565#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010566#ifdef FEAT_CONCEAL
10567 check_string_option(&wop->wo_cocu);
10568#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010569#ifdef FEAT_LINEBREAK
10570 check_string_option(&wop->wo_briopt);
10571#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572}
10573
10574/*
10575 * Free the allocated memory inside a winopt_T.
10576 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577 void
10578clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010579 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580{
10581#ifdef FEAT_FOLDING
10582 clear_string_option(&wop->wo_fdi);
10583 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010584 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585# ifdef FEAT_EVAL
10586 clear_string_option(&wop->wo_fde);
10587 clear_string_option(&wop->wo_fdt);
10588# endif
10589 clear_string_option(&wop->wo_fmr);
10590#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010591#ifdef FEAT_LINEBREAK
10592 clear_string_option(&wop->wo_briopt);
10593#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594#ifdef FEAT_RIGHTLEFT
10595 clear_string_option(&wop->wo_rlc);
10596#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010597#ifdef FEAT_STL_OPT
10598 clear_string_option(&wop->wo_stl);
10599#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010600#ifdef FEAT_SYN_HL
10601 clear_string_option(&wop->wo_cc);
10602#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010603#ifdef FEAT_CONCEAL
10604 clear_string_option(&wop->wo_cocu);
10605#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606}
10607
10608/*
10609 * Copy global option values to local options for one buffer.
10610 * Used when creating a new buffer and sometimes when entering a buffer.
10611 * flags:
10612 * BCO_ENTER We will enter the buf buffer.
10613 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10614 * appropriate.
10615 * BCO_NOHELP Don't copy the values to a help buffer.
10616 */
10617 void
10618buf_copy_options(buf, flags)
10619 buf_T *buf;
10620 int flags;
10621{
10622 int should_copy = TRUE;
10623 char_u *save_p_isk = NULL; /* init for GCC */
10624 int dont_do_help;
10625 int did_isk = FALSE;
10626
10627 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010628 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629 */
10630 if (buf == NULL || !buf_valid(buf))
10631 return;
10632
10633 /*
10634 * Skip this when the option defaults have not been set yet. Happens when
10635 * main() allocates the first buffer.
10636 */
10637 if (p_cpo != NULL)
10638 {
10639 /*
10640 * Always copy when entering and 'cpo' contains 'S'.
10641 * Don't copy when already initialized.
10642 * Don't copy when 'cpo' contains 's' and not entering.
10643 * 'S' BCO_ENTER initialized 's' should_copy
10644 * yes yes X X TRUE
10645 * yes no yes X FALSE
10646 * no X yes X FALSE
10647 * X no no yes FALSE
10648 * X no no no TRUE
10649 * no yes no X TRUE
10650 */
10651 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10652 && (buf->b_p_initialized
10653 || (!(flags & BCO_ENTER)
10654 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10655 should_copy = FALSE;
10656
10657 if (should_copy || (flags & BCO_ALWAYS))
10658 {
10659 /* Don't copy the options specific to a help buffer when
10660 * BCO_NOHELP is given or the options were initialized already
10661 * (jumping back to a help file with CTRL-T or CTRL-O) */
10662 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10663 || buf->b_p_initialized;
10664 if (dont_do_help) /* don't free b_p_isk */
10665 {
10666 save_p_isk = buf->b_p_isk;
10667 buf->b_p_isk = NULL;
10668 }
10669 /*
10670 * Always free the allocated strings.
10671 * If not already initialized, set 'readonly' and copy 'fileformat'.
10672 */
10673 if (!buf->b_p_initialized)
10674 {
10675 free_buf_options(buf, TRUE);
10676 buf->b_p_ro = FALSE; /* don't copy readonly */
10677 buf->b_p_tx = p_tx;
10678#ifdef FEAT_MBYTE
10679 buf->b_p_fenc = vim_strsave(p_fenc);
10680#endif
10681 buf->b_p_ff = vim_strsave(p_ff);
10682#if defined(FEAT_QUICKFIX)
10683 buf->b_p_bh = empty_option;
10684 buf->b_p_bt = empty_option;
10685#endif
10686 }
10687 else
10688 free_buf_options(buf, FALSE);
10689
10690 buf->b_p_ai = p_ai;
10691 buf->b_p_ai_nopaste = p_ai_nopaste;
10692 buf->b_p_sw = p_sw;
10693 buf->b_p_tw = p_tw;
10694 buf->b_p_tw_nopaste = p_tw_nopaste;
10695 buf->b_p_tw_nobin = p_tw_nobin;
10696 buf->b_p_wm = p_wm;
10697 buf->b_p_wm_nopaste = p_wm_nopaste;
10698 buf->b_p_wm_nobin = p_wm_nobin;
10699 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010700#ifdef FEAT_MBYTE
10701 buf->b_p_bomb = p_bomb;
10702#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010703 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704 buf->b_p_et = p_et;
10705 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010706 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707 buf->b_p_ml = p_ml;
10708 buf->b_p_ml_nobin = p_ml_nobin;
10709 buf->b_p_inf = p_inf;
10710 buf->b_p_swf = p_swf;
10711#ifdef FEAT_INS_EXPAND
10712 buf->b_p_cpt = vim_strsave(p_cpt);
10713#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010714#ifdef FEAT_COMPL_FUNC
10715 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010716 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718 buf->b_p_sts = p_sts;
10719 buf->b_p_sts_nopaste = p_sts_nopaste;
10720#ifndef SHORT_FNAME
10721 buf->b_p_sn = p_sn;
10722#endif
10723#ifdef FEAT_COMMENTS
10724 buf->b_p_com = vim_strsave(p_com);
10725#endif
10726#ifdef FEAT_FOLDING
10727 buf->b_p_cms = vim_strsave(p_cms);
10728#endif
10729 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010730 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010731 buf->b_p_nf = vim_strsave(p_nf);
10732 buf->b_p_mps = vim_strsave(p_mps);
10733#ifdef FEAT_SMARTINDENT
10734 buf->b_p_si = p_si;
10735#endif
10736 buf->b_p_ci = p_ci;
10737#ifdef FEAT_CINDENT
10738 buf->b_p_cin = p_cin;
10739 buf->b_p_cink = vim_strsave(p_cink);
10740 buf->b_p_cino = vim_strsave(p_cino);
10741#endif
10742#ifdef FEAT_AUTOCMD
10743 /* Don't copy 'filetype', it must be detected */
10744 buf->b_p_ft = empty_option;
10745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746 buf->b_p_pi = p_pi;
10747#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10748 buf->b_p_cinw = vim_strsave(p_cinw);
10749#endif
10750#ifdef FEAT_LISP
10751 buf->b_p_lisp = p_lisp;
10752#endif
10753#ifdef FEAT_SYN_HL
10754 /* Don't copy 'syntax', it must be set */
10755 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010756 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010757#endif
10758#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010759 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010760 (void)compile_cap_prog(&buf->b_s);
10761 buf->b_s.b_p_spf = vim_strsave(p_spf);
10762 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763#endif
10764#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10765 buf->b_p_inde = vim_strsave(p_inde);
10766 buf->b_p_indk = vim_strsave(p_indk);
10767#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010768#if defined(FEAT_EVAL)
10769 buf->b_p_fex = vim_strsave(p_fex);
10770#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771#ifdef FEAT_CRYPT
10772 buf->b_p_key = vim_strsave(p_key);
10773#endif
10774#ifdef FEAT_SEARCHPATH
10775 buf->b_p_sua = vim_strsave(p_sua);
10776#endif
10777#ifdef FEAT_KEYMAP
10778 buf->b_p_keymap = vim_strsave(p_keymap);
10779 buf->b_kmap_state |= KEYMAP_INIT;
10780#endif
10781 /* This isn't really an option, but copying the langmap and IME
10782 * state from the current buffer is better than resetting it. */
10783 buf->b_p_iminsert = p_iminsert;
10784 buf->b_p_imsearch = p_imsearch;
10785
10786 /* options that are normally global but also have a local value
10787 * are not copied, start using the global value */
10788 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010789 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010790 buf->b_p_bkc = empty_option;
10791 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010792#ifdef FEAT_QUICKFIX
10793 buf->b_p_gp = empty_option;
10794 buf->b_p_mp = empty_option;
10795 buf->b_p_efm = empty_option;
10796#endif
10797 buf->b_p_ep = empty_option;
10798 buf->b_p_kp = empty_option;
10799 buf->b_p_path = empty_option;
10800 buf->b_p_tags = empty_option;
10801#ifdef FEAT_FIND_ID
10802 buf->b_p_def = empty_option;
10803 buf->b_p_inc = empty_option;
10804# ifdef FEAT_EVAL
10805 buf->b_p_inex = vim_strsave(p_inex);
10806# endif
10807#endif
10808#ifdef FEAT_INS_EXPAND
10809 buf->b_p_dict = empty_option;
10810 buf->b_p_tsr = empty_option;
10811#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010812#ifdef FEAT_TEXTOBJ
10813 buf->b_p_qe = vim_strsave(p_qe);
10814#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010815#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10816 buf->b_p_bexpr = empty_option;
10817#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010818#if defined(FEAT_CRYPT)
10819 buf->b_p_cm = empty_option;
10820#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010821#ifdef FEAT_PERSISTENT_UNDO
10822 buf->b_p_udf = p_udf;
10823#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010824#ifdef FEAT_LISP
10825 buf->b_p_lw = empty_option;
10826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827
10828 /*
10829 * Don't copy the options set by ex_help(), use the saved values,
10830 * when going from a help buffer to a non-help buffer.
10831 * Don't touch these at all when BCO_NOHELP is used and going from
10832 * or to a help buffer.
10833 */
10834 if (dont_do_help)
10835 buf->b_p_isk = save_p_isk;
10836 else
10837 {
10838 buf->b_p_isk = vim_strsave(p_isk);
10839 did_isk = TRUE;
10840 buf->b_p_ts = p_ts;
10841 buf->b_help = FALSE;
10842#ifdef FEAT_QUICKFIX
10843 if (buf->b_p_bt[0] == 'h')
10844 clear_string_option(&buf->b_p_bt);
10845#endif
10846 buf->b_p_ma = p_ma;
10847 }
10848 }
10849
10850 /*
10851 * When the options should be copied (ignoring BCO_ALWAYS), set the
10852 * flag that indicates that the options have been initialized.
10853 */
10854 if (should_copy)
10855 buf->b_p_initialized = TRUE;
10856 }
10857
10858 check_buf_options(buf); /* make sure we don't have NULLs */
10859 if (did_isk)
10860 (void)buf_init_chartab(buf, FALSE);
10861}
10862
10863/*
10864 * Reset the 'modifiable' option and its default value.
10865 */
10866 void
10867reset_modifiable()
10868{
10869 int opt_idx;
10870
10871 curbuf->b_p_ma = FALSE;
10872 p_ma = FALSE;
10873 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010874 if (opt_idx >= 0)
10875 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876}
10877
10878/*
10879 * Set the global value for 'iminsert' to the local value.
10880 */
10881 void
10882set_iminsert_global()
10883{
10884 p_iminsert = curbuf->b_p_iminsert;
10885}
10886
10887/*
10888 * Set the global value for 'imsearch' to the local value.
10889 */
10890 void
10891set_imsearch_global()
10892{
10893 p_imsearch = curbuf->b_p_imsearch;
10894}
10895
10896#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10897static int expand_option_idx = -1;
10898static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10899static int expand_option_flags = 0;
10900
10901 void
10902set_context_in_set_cmd(xp, arg, opt_flags)
10903 expand_T *xp;
10904 char_u *arg;
10905 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10906{
10907 int nextchar;
10908 long_u flags = 0; /* init for GCC */
10909 int opt_idx = 0; /* init for GCC */
10910 char_u *p;
10911 char_u *s;
10912 int is_term_option = FALSE;
10913 int key;
10914
10915 expand_option_flags = opt_flags;
10916
10917 xp->xp_context = EXPAND_SETTINGS;
10918 if (*arg == NUL)
10919 {
10920 xp->xp_pattern = arg;
10921 return;
10922 }
10923 p = arg + STRLEN(arg) - 1;
10924 if (*p == ' ' && *(p - 1) != '\\')
10925 {
10926 xp->xp_pattern = p + 1;
10927 return;
10928 }
10929 while (p > arg)
10930 {
10931 s = p;
10932 /* count number of backslashes before ' ' or ',' */
10933 if (*p == ' ' || *p == ',')
10934 {
10935 while (s > arg && *(s - 1) == '\\')
10936 --s;
10937 }
10938 /* break at a space with an even number of backslashes */
10939 if (*p == ' ' && ((p - s) & 1) == 0)
10940 {
10941 ++p;
10942 break;
10943 }
10944 --p;
10945 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010946 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947 {
10948 xp->xp_context = EXPAND_BOOL_SETTINGS;
10949 p += 2;
10950 }
10951 if (STRNCMP(p, "inv", 3) == 0)
10952 {
10953 xp->xp_context = EXPAND_BOOL_SETTINGS;
10954 p += 3;
10955 }
10956 xp->xp_pattern = arg = p;
10957 if (*arg == '<')
10958 {
10959 while (*p != '>')
10960 if (*p++ == NUL) /* expand terminal option name */
10961 return;
10962 key = get_special_key_code(arg + 1);
10963 if (key == 0) /* unknown name */
10964 {
10965 xp->xp_context = EXPAND_NOTHING;
10966 return;
10967 }
10968 nextchar = *++p;
10969 is_term_option = TRUE;
10970 expand_option_name[2] = KEY2TERMCAP0(key);
10971 expand_option_name[3] = KEY2TERMCAP1(key);
10972 }
10973 else
10974 {
10975 if (p[0] == 't' && p[1] == '_')
10976 {
10977 p += 2;
10978 if (*p != NUL)
10979 ++p;
10980 if (*p == NUL)
10981 return; /* expand option name */
10982 nextchar = *++p;
10983 is_term_option = TRUE;
10984 expand_option_name[2] = p[-2];
10985 expand_option_name[3] = p[-1];
10986 }
10987 else
10988 {
10989 /* Allow * wildcard */
10990 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10991 p++;
10992 if (*p == NUL)
10993 return;
10994 nextchar = *p;
10995 *p = NUL;
10996 opt_idx = findoption(arg);
10997 *p = nextchar;
10998 if (opt_idx == -1 || options[opt_idx].var == NULL)
10999 {
11000 xp->xp_context = EXPAND_NOTHING;
11001 return;
11002 }
11003 flags = options[opt_idx].flags;
11004 if (flags & P_BOOL)
11005 {
11006 xp->xp_context = EXPAND_NOTHING;
11007 return;
11008 }
11009 }
11010 }
11011 /* handle "-=" and "+=" */
11012 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11013 {
11014 ++p;
11015 nextchar = '=';
11016 }
11017 if ((nextchar != '=' && nextchar != ':')
11018 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11019 {
11020 xp->xp_context = EXPAND_UNSUCCESSFUL;
11021 return;
11022 }
11023 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11024 {
11025 xp->xp_context = EXPAND_OLD_SETTING;
11026 if (is_term_option)
11027 expand_option_idx = -1;
11028 else
11029 expand_option_idx = opt_idx;
11030 xp->xp_pattern = p + 1;
11031 return;
11032 }
11033 xp->xp_context = EXPAND_NOTHING;
11034 if (is_term_option || (flags & P_NUM))
11035 return;
11036
11037 xp->xp_pattern = p + 1;
11038
11039 if (flags & P_EXPAND)
11040 {
11041 p = options[opt_idx].var;
11042 if (p == (char_u *)&p_bdir
11043 || p == (char_u *)&p_dir
11044 || p == (char_u *)&p_path
11045 || p == (char_u *)&p_rtp
11046#ifdef FEAT_SEARCHPATH
11047 || p == (char_u *)&p_cdpath
11048#endif
11049#ifdef FEAT_SESSION
11050 || p == (char_u *)&p_vdir
11051#endif
11052 )
11053 {
11054 xp->xp_context = EXPAND_DIRECTORIES;
11055 if (p == (char_u *)&p_path
11056#ifdef FEAT_SEARCHPATH
11057 || p == (char_u *)&p_cdpath
11058#endif
11059 )
11060 xp->xp_backslash = XP_BS_THREE;
11061 else
11062 xp->xp_backslash = XP_BS_ONE;
11063 }
11064 else
11065 {
11066 xp->xp_context = EXPAND_FILES;
11067 /* for 'tags' need three backslashes for a space */
11068 if (p == (char_u *)&p_tags)
11069 xp->xp_backslash = XP_BS_THREE;
11070 else
11071 xp->xp_backslash = XP_BS_ONE;
11072 }
11073 }
11074
11075 /* For an option that is a list of file names, find the start of the
11076 * last file name. */
11077 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11078 {
11079 /* count number of backslashes before ' ' or ',' */
11080 if (*p == ' ' || *p == ',')
11081 {
11082 s = p;
11083 while (s > xp->xp_pattern && *(s - 1) == '\\')
11084 --s;
11085 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11086 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11087 {
11088 xp->xp_pattern = p + 1;
11089 break;
11090 }
11091 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011092
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011093#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011094 /* for 'spellsuggest' start at "file:" */
11095 if (options[opt_idx].var == (char_u *)&p_sps
11096 && STRNCMP(p, "file:", 5) == 0)
11097 {
11098 xp->xp_pattern = p + 5;
11099 break;
11100 }
11101#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102 }
11103
11104 return;
11105}
11106
11107 int
11108ExpandSettings(xp, regmatch, num_file, file)
11109 expand_T *xp;
11110 regmatch_T *regmatch;
11111 int *num_file;
11112 char_u ***file;
11113{
11114 int num_normal = 0; /* Nr of matching non-term-code settings */
11115 int num_term = 0; /* Nr of matching terminal code settings */
11116 int opt_idx;
11117 int match;
11118 int count = 0;
11119 char_u *str;
11120 int loop;
11121 int is_term_opt;
11122 char_u name_buf[MAX_KEY_NAME_LEN];
11123 static char *(names[]) = {"all", "termcap"};
11124 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11125
11126 /* do this loop twice:
11127 * loop == 0: count the number of matching options
11128 * loop == 1: copy the matching options into allocated memory
11129 */
11130 for (loop = 0; loop <= 1; ++loop)
11131 {
11132 regmatch->rm_ic = ic;
11133 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11134 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011135 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11136 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011137 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11138 {
11139 if (loop == 0)
11140 num_normal++;
11141 else
11142 (*file)[count++] = vim_strsave((char_u *)names[match]);
11143 }
11144 }
11145 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11146 opt_idx++)
11147 {
11148 if (options[opt_idx].var == NULL)
11149 continue;
11150 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11151 && !(options[opt_idx].flags & P_BOOL))
11152 continue;
11153 is_term_opt = istermoption(&options[opt_idx]);
11154 if (is_term_opt && num_normal > 0)
11155 continue;
11156 match = FALSE;
11157 if (vim_regexec(regmatch, str, (colnr_T)0)
11158 || (options[opt_idx].shortname != NULL
11159 && vim_regexec(regmatch,
11160 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11161 match = TRUE;
11162 else if (is_term_opt)
11163 {
11164 name_buf[0] = '<';
11165 name_buf[1] = 't';
11166 name_buf[2] = '_';
11167 name_buf[3] = str[2];
11168 name_buf[4] = str[3];
11169 name_buf[5] = '>';
11170 name_buf[6] = NUL;
11171 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11172 {
11173 match = TRUE;
11174 str = name_buf;
11175 }
11176 }
11177 if (match)
11178 {
11179 if (loop == 0)
11180 {
11181 if (is_term_opt)
11182 num_term++;
11183 else
11184 num_normal++;
11185 }
11186 else
11187 (*file)[count++] = vim_strsave(str);
11188 }
11189 }
11190 /*
11191 * Check terminal key codes, these are not in the option table
11192 */
11193 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11194 {
11195 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11196 {
11197 if (!isprint(str[0]) || !isprint(str[1]))
11198 continue;
11199
11200 name_buf[0] = 't';
11201 name_buf[1] = '_';
11202 name_buf[2] = str[0];
11203 name_buf[3] = str[1];
11204 name_buf[4] = NUL;
11205
11206 match = FALSE;
11207 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11208 match = TRUE;
11209 else
11210 {
11211 name_buf[0] = '<';
11212 name_buf[1] = 't';
11213 name_buf[2] = '_';
11214 name_buf[3] = str[0];
11215 name_buf[4] = str[1];
11216 name_buf[5] = '>';
11217 name_buf[6] = NUL;
11218
11219 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11220 match = TRUE;
11221 }
11222 if (match)
11223 {
11224 if (loop == 0)
11225 num_term++;
11226 else
11227 (*file)[count++] = vim_strsave(name_buf);
11228 }
11229 }
11230
11231 /*
11232 * Check special key names.
11233 */
11234 regmatch->rm_ic = TRUE; /* ignore case here */
11235 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11236 {
11237 name_buf[0] = '<';
11238 STRCPY(name_buf + 1, str);
11239 STRCAT(name_buf, ">");
11240
11241 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11242 {
11243 if (loop == 0)
11244 num_term++;
11245 else
11246 (*file)[count++] = vim_strsave(name_buf);
11247 }
11248 }
11249 }
11250 if (loop == 0)
11251 {
11252 if (num_normal > 0)
11253 *num_file = num_normal;
11254 else if (num_term > 0)
11255 *num_file = num_term;
11256 else
11257 return OK;
11258 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11259 if (*file == NULL)
11260 {
11261 *file = (char_u **)"";
11262 return FAIL;
11263 }
11264 }
11265 }
11266 return OK;
11267}
11268
11269 int
11270ExpandOldSetting(num_file, file)
11271 int *num_file;
11272 char_u ***file;
11273{
11274 char_u *var = NULL; /* init for GCC */
11275 char_u *buf;
11276
11277 *num_file = 0;
11278 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11279 if (*file == NULL)
11280 return FAIL;
11281
11282 /*
11283 * For a terminal key code expand_option_idx is < 0.
11284 */
11285 if (expand_option_idx < 0)
11286 {
11287 var = find_termcode(expand_option_name + 2);
11288 if (var == NULL)
11289 expand_option_idx = findoption(expand_option_name);
11290 }
11291
11292 if (expand_option_idx >= 0)
11293 {
11294 /* put string of option value in NameBuff */
11295 option_value2string(&options[expand_option_idx], expand_option_flags);
11296 var = NameBuff;
11297 }
11298 else if (var == NULL)
11299 var = (char_u *)"";
11300
11301 /* A backslash is required before some characters. This is the reverse of
11302 * what happens in do_set(). */
11303 buf = vim_strsave_escaped(var, escape_chars);
11304
11305 if (buf == NULL)
11306 {
11307 vim_free(*file);
11308 *file = NULL;
11309 return FAIL;
11310 }
11311
11312#ifdef BACKSLASH_IN_FILENAME
11313 /* For MS-Windows et al. we don't double backslashes at the start and
11314 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011315 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316 if (var[0] == '\\' && var[1] == '\\'
11317 && expand_option_idx >= 0
11318 && (options[expand_option_idx].flags & P_EXPAND)
11319 && vim_isfilec(var[2])
11320 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011321 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322#endif
11323
11324 *file[0] = buf;
11325 *num_file = 1;
11326 return OK;
11327}
11328#endif
11329
11330/*
11331 * Get the value for the numeric or string option *opp in a nice format into
11332 * NameBuff[]. Must not be called with a hidden option!
11333 */
11334 static void
11335option_value2string(opp, opt_flags)
11336 struct vimoption *opp;
11337 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11338{
11339 char_u *varp;
11340
11341 varp = get_varp_scope(opp, opt_flags);
11342
11343 if (opp->flags & P_NUM)
11344 {
11345 long wc = 0;
11346
11347 if (wc_use_keyname(varp, &wc))
11348 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11349 else if (wc != 0)
11350 STRCPY(NameBuff, transchar((int)wc));
11351 else
11352 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11353 }
11354 else /* P_STRING */
11355 {
11356 varp = *(char_u **)(varp);
11357 if (varp == NULL) /* just in case */
11358 NameBuff[0] = NUL;
11359#ifdef FEAT_CRYPT
11360 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011361 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011362 STRCPY(NameBuff, "*****");
11363#endif
11364 else if (opp->flags & P_EXPAND)
11365 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11366 /* Translate 'pastetoggle' into special key names */
11367 else if ((char_u **)opp->var == &p_pt)
11368 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11369 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011370 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011371 }
11372}
11373
11374/*
11375 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11376 * printed as a keyname.
11377 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11378 */
11379 static int
11380wc_use_keyname(varp, wcp)
11381 char_u *varp;
11382 long *wcp;
11383{
11384 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11385 {
11386 *wcp = *(long *)varp;
11387 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11388 return TRUE;
11389 }
11390 return FALSE;
11391}
11392
Bram Moolenaar01615492015-02-03 13:00:38 +010011393#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011394/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011395 * Any character has an equivalent 'langmap' character. This is used for
11396 * keyboards that have a special language mode that sends characters above
11397 * 128 (although other characters can be translated too). The "to" field is a
11398 * Vim command character. This avoids having to switch the keyboard back to
11399 * ASCII mode when leaving Insert mode.
11400 *
11401 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11402 * commands.
11403 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11404 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11405 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011406 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011407# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011408/*
11409 * With multi-byte support use growarray for 'langmap' chars >= 256
11410 */
11411typedef struct
11412{
11413 int from;
11414 int to;
11415} langmap_entry_T;
11416
11417static garray_T langmap_mapga;
11418static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419
11420/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011421 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11422 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011423 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011424 static void
11425langmap_set_entry(from, to)
11426 int from;
11427 int to;
11428{
11429 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011430 int a = 0;
11431 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011432
11433 /* Do a binary search for an existing entry. */
11434 while (a != b)
11435 {
11436 int i = (a + b) / 2;
11437 int d = entries[i].from - from;
11438
11439 if (d == 0)
11440 {
11441 entries[i].to = to;
11442 return;
11443 }
11444 if (d < 0)
11445 a = i + 1;
11446 else
11447 b = i;
11448 }
11449
11450 if (ga_grow(&langmap_mapga, 1) != OK)
11451 return; /* out of memory */
11452
11453 /* insert new entry at position "a" */
11454 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11455 mch_memmove(entries + 1, entries,
11456 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11457 ++langmap_mapga.ga_len;
11458 entries[0].from = from;
11459 entries[0].to = to;
11460}
11461
11462/*
11463 * Apply 'langmap' to multi-byte character "c" and return the result.
11464 */
11465 int
11466langmap_adjust_mb(c)
11467 int c;
11468{
11469 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11470 int a = 0;
11471 int b = langmap_mapga.ga_len;
11472
11473 while (a != b)
11474 {
11475 int i = (a + b) / 2;
11476 int d = entries[i].from - c;
11477
11478 if (d == 0)
11479 return entries[i].to; /* found matching entry */
11480 if (d < 0)
11481 a = i + 1;
11482 else
11483 b = i;
11484 }
11485 return c; /* no entry found, return "c" unmodified */
11486}
11487# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488
11489 static void
11490langmap_init()
11491{
11492 int i;
11493
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011494 for (i = 0; i < 256; i++)
11495 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11496# ifdef FEAT_MBYTE
11497 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11498# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499}
11500
11501/*
11502 * Called when langmap option is set; the language map can be
11503 * changed at any time!
11504 */
11505 static void
11506langmap_set()
11507{
11508 char_u *p;
11509 char_u *p2;
11510 int from, to;
11511
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011512#ifdef FEAT_MBYTE
11513 ga_clear(&langmap_mapga); /* clear the previous map first */
11514#endif
11515 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011516
11517 for (p = p_langmap; p[0] != NUL; )
11518 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011519 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11520 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011521 {
11522 if (p2[0] == '\\' && p2[1] != NUL)
11523 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524 }
11525 if (p2[0] == ';')
11526 ++p2; /* abcd;ABCD form, p2 points to A */
11527 else
11528 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11529 while (p[0])
11530 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011531 if (p[0] == ',')
11532 {
11533 ++p;
11534 break;
11535 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011536 if (p[0] == '\\' && p[1] != NUL)
11537 ++p;
11538#ifdef FEAT_MBYTE
11539 from = (*mb_ptr2char)(p);
11540#else
11541 from = p[0];
11542#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011543 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011544 if (p2 == NULL)
11545 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011546 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011547 if (p[0] != ',')
11548 {
11549 if (p[0] == '\\')
11550 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011551#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011552 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011554 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011556 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557 }
11558 else
11559 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011560 if (p2[0] != ',')
11561 {
11562 if (p2[0] == '\\')
11563 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011564#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011565 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011567 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011568#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011570 }
11571 if (to == NUL)
11572 {
11573 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11574 transchar(from));
11575 return;
11576 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011577
11578#ifdef FEAT_MBYTE
11579 if (from >= 256)
11580 langmap_set_entry(from, to);
11581 else
11582#endif
11583 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011584
11585 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011586 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011587 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011588 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011589 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590 if (*p == ';')
11591 {
11592 p = p2;
11593 if (p[0] != NUL)
11594 {
11595 if (p[0] != ',')
11596 {
11597 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11598 return;
11599 }
11600 ++p;
11601 }
11602 break;
11603 }
11604 }
11605 }
11606 }
11607}
11608#endif
11609
11610/*
11611 * Return TRUE if format option 'x' is in effect.
11612 * Take care of no formatting when 'paste' is set.
11613 */
11614 int
11615has_format_option(x)
11616 int x;
11617{
11618 if (p_paste)
11619 return FALSE;
11620 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11621}
11622
11623/*
11624 * Return TRUE if "x" is present in 'shortmess' option, or
11625 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11626 */
11627 int
11628shortmess(x)
11629 int x;
11630{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011631 return p_shm != NULL &&
11632 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633 || (vim_strchr(p_shm, 'a') != NULL
11634 && vim_strchr((char_u *)SHM_A, x) != NULL));
11635}
11636
11637/*
11638 * paste_option_changed() - Called after p_paste was set or reset.
11639 */
11640 static void
11641paste_option_changed()
11642{
11643 static int old_p_paste = FALSE;
11644 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011645 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011646#ifdef FEAT_CMDL_INFO
11647 static int save_ru = 0;
11648#endif
11649#ifdef FEAT_RIGHTLEFT
11650 static int save_ri = 0;
11651 static int save_hkmap = 0;
11652#endif
11653 buf_T *buf;
11654
11655 if (p_paste)
11656 {
11657 /*
11658 * Paste switched from off to on.
11659 * Save the current values, so they can be restored later.
11660 */
11661 if (!old_p_paste)
11662 {
11663 /* save options for each buffer */
11664 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11665 {
11666 buf->b_p_tw_nopaste = buf->b_p_tw;
11667 buf->b_p_wm_nopaste = buf->b_p_wm;
11668 buf->b_p_sts_nopaste = buf->b_p_sts;
11669 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011670 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011671 }
11672
11673 /* save global options */
11674 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011675 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011676#ifdef FEAT_CMDL_INFO
11677 save_ru = p_ru;
11678#endif
11679#ifdef FEAT_RIGHTLEFT
11680 save_ri = p_ri;
11681 save_hkmap = p_hkmap;
11682#endif
11683 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011684 p_ai_nopaste = p_ai;
11685 p_et_nopaste = p_et;
11686 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011687 p_tw_nopaste = p_tw;
11688 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689 }
11690
11691 /*
11692 * Always set the option values, also when 'paste' is set when it is
11693 * already on.
11694 */
11695 /* set options for each buffer */
11696 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11697 {
11698 buf->b_p_tw = 0; /* textwidth is 0 */
11699 buf->b_p_wm = 0; /* wrapmargin is 0 */
11700 buf->b_p_sts = 0; /* softtabstop is 0 */
11701 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011702 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011703 }
11704
11705 /* set global options */
11706 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011707 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011708#ifdef FEAT_CMDL_INFO
11709# ifdef FEAT_WINDOWS
11710 if (p_ru)
11711 status_redraw_all(); /* redraw to remove the ruler */
11712# endif
11713 p_ru = 0; /* no ruler */
11714#endif
11715#ifdef FEAT_RIGHTLEFT
11716 p_ri = 0; /* no reverse insert */
11717 p_hkmap = 0; /* no Hebrew keyboard */
11718#endif
11719 /* set global values for local buffer options */
11720 p_tw = 0;
11721 p_wm = 0;
11722 p_sts = 0;
11723 p_ai = 0;
11724 }
11725
11726 /*
11727 * Paste switched from on to off: Restore saved values.
11728 */
11729 else if (old_p_paste)
11730 {
11731 /* restore options for each buffer */
11732 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11733 {
11734 buf->b_p_tw = buf->b_p_tw_nopaste;
11735 buf->b_p_wm = buf->b_p_wm_nopaste;
11736 buf->b_p_sts = buf->b_p_sts_nopaste;
11737 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011738 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011739 }
11740
11741 /* restore global options */
11742 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011743 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011744#ifdef FEAT_CMDL_INFO
11745# ifdef FEAT_WINDOWS
11746 if (p_ru != save_ru)
11747 status_redraw_all(); /* redraw to draw the ruler */
11748# endif
11749 p_ru = save_ru;
11750#endif
11751#ifdef FEAT_RIGHTLEFT
11752 p_ri = save_ri;
11753 p_hkmap = save_hkmap;
11754#endif
11755 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011756 p_ai = p_ai_nopaste;
11757 p_et = p_et_nopaste;
11758 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011759 p_tw = p_tw_nopaste;
11760 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 }
11762
11763 old_p_paste = p_paste;
11764}
11765
11766/*
11767 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11768 *
11769 * Reset 'compatible' and set the values for options that didn't get set yet
11770 * to the Vim defaults.
11771 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011772 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011773 */
11774 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011775vimrc_found(fname, envname)
11776 char_u *fname;
11777 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011778{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011779 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011780 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011781 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782
11783 if (!option_was_set((char_u *)"cp"))
11784 {
11785 p_cp = FALSE;
11786 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11787 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11788 set_option_default(opt_idx, OPT_FREE, FALSE);
11789 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011790 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011791 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011792
11793 if (fname != NULL)
11794 {
11795 p = vim_getenv(envname, &dofree);
11796 if (p == NULL)
11797 {
11798 /* Set $MYVIMRC to the first vimrc file found. */
11799 p = FullName_save(fname, FALSE);
11800 if (p != NULL)
11801 {
11802 vim_setenv(envname, p);
11803 vim_free(p);
11804 }
11805 }
11806 else if (dofree)
11807 vim_free(p);
11808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011809}
11810
11811/*
11812 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11813 */
11814 void
11815change_compatible(on)
11816 int on;
11817{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011818 int opt_idx;
11819
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820 if (p_cp != on)
11821 {
11822 p_cp = on;
11823 compatible_set();
11824 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011825 opt_idx = findoption((char_u *)"cp");
11826 if (opt_idx >= 0)
11827 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011828}
11829
11830/*
11831 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011832 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011833 */
11834 int
11835option_was_set(name)
11836 char_u *name;
11837{
11838 int idx;
11839
11840 idx = findoption(name);
11841 if (idx < 0) /* unknown option */
11842 return FALSE;
11843 if (options[idx].flags & P_WAS_SET)
11844 return TRUE;
11845 return FALSE;
11846}
11847
11848/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011849 * Reset the flag indicating option "name" was set.
11850 */
11851 void
11852reset_option_was_set(name)
11853 char_u *name;
11854{
11855 int idx = findoption(name);
11856
11857 if (idx >= 0)
11858 options[idx].flags &= ~P_WAS_SET;
11859}
11860
11861/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011862 * compatible_set() - Called when 'compatible' has been set or unset.
11863 *
11864 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11865 * flag) to a Vi compatible value.
11866 * When 'compatible' is unset: Set all options that have a different default
11867 * for Vim (without the P_VI_DEF flag) to that default.
11868 */
11869 static void
11870compatible_set()
11871{
11872 int opt_idx;
11873
11874 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11875 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11876 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11877 set_option_default(opt_idx, OPT_FREE, p_cp);
11878 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011879 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011880}
11881
11882#ifdef FEAT_LINEBREAK
11883
11884# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11885 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011886 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887# endif
11888
11889/*
11890 * fill_breakat_flags() -- called when 'breakat' changes value.
11891 */
11892 static void
11893fill_breakat_flags()
11894{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011895 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011896 int i;
11897
11898 for (i = 0; i < 256; i++)
11899 breakat_flags[i] = FALSE;
11900
11901 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011902 for (p = p_breakat; *p; p++)
11903 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011904}
11905
11906# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011907 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011908# endif
11909
11910#endif
11911
11912/*
11913 * Check an option that can be a range of string values.
11914 *
11915 * Return OK for correct value, FAIL otherwise.
11916 * Empty is always OK.
11917 */
11918 static int
11919check_opt_strings(val, values, list)
11920 char_u *val;
11921 char **values;
11922 int list; /* when TRUE: accept a list of values */
11923{
11924 return opt_strings_flags(val, values, NULL, list);
11925}
11926
11927/*
11928 * Handle an option that can be a range of string values.
11929 * Set a flag in "*flagp" for each string present.
11930 *
11931 * Return OK for correct value, FAIL otherwise.
11932 * Empty is always OK.
11933 */
11934 static int
11935opt_strings_flags(val, values, flagp, list)
11936 char_u *val; /* new value */
11937 char **values; /* array of valid string values */
11938 unsigned *flagp;
11939 int list; /* when TRUE: accept a list of values */
11940{
11941 int i;
11942 int len;
11943 unsigned new_flags = 0;
11944
11945 while (*val)
11946 {
11947 for (i = 0; ; ++i)
11948 {
11949 if (values[i] == NULL) /* val not found in values[] */
11950 return FAIL;
11951
11952 len = (int)STRLEN(values[i]);
11953 if (STRNCMP(values[i], val, len) == 0
11954 && ((list && val[len] == ',') || val[len] == NUL))
11955 {
11956 val += len + (val[len] == ',');
11957 new_flags |= (1 << i);
11958 break; /* check next item in val list */
11959 }
11960 }
11961 }
11962 if (flagp != NULL)
11963 *flagp = new_flags;
11964
11965 return OK;
11966}
11967
11968/*
11969 * Read the 'wildmode' option, fill wim_flags[].
11970 */
11971 static int
11972check_opt_wim()
11973{
11974 char_u new_wim_flags[4];
11975 char_u *p;
11976 int i;
11977 int idx = 0;
11978
11979 for (i = 0; i < 4; ++i)
11980 new_wim_flags[i] = 0;
11981
11982 for (p = p_wim; *p; ++p)
11983 {
11984 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11985 ;
11986 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11987 return FAIL;
11988 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11989 new_wim_flags[idx] |= WIM_LONGEST;
11990 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11991 new_wim_flags[idx] |= WIM_FULL;
11992 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11993 new_wim_flags[idx] |= WIM_LIST;
11994 else
11995 return FAIL;
11996 p += i;
11997 if (*p == NUL)
11998 break;
11999 if (*p == ',')
12000 {
12001 if (idx == 3)
12002 return FAIL;
12003 ++idx;
12004 }
12005 }
12006
12007 /* fill remaining entries with last flag */
12008 while (idx < 3)
12009 {
12010 new_wim_flags[idx + 1] = new_wim_flags[idx];
12011 ++idx;
12012 }
12013
12014 /* only when there are no errors, wim_flags[] is changed */
12015 for (i = 0; i < 4; ++i)
12016 wim_flags[i] = new_wim_flags[i];
12017 return OK;
12018}
12019
12020/*
12021 * Check if backspacing over something is allowed.
12022 */
12023 int
12024can_bs(what)
12025 int what; /* BS_INDENT, BS_EOL or BS_START */
12026{
12027 switch (*p_bs)
12028 {
12029 case '2': return TRUE;
12030 case '1': return (what != BS_START);
12031 case '0': return FALSE;
12032 }
12033 return vim_strchr(p_bs, what) != NULL;
12034}
12035
12036/*
12037 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12038 * the file must be considered changed when the value is different.
12039 */
12040 void
12041save_file_ff(buf)
12042 buf_T *buf;
12043{
12044 buf->b_start_ffc = *buf->b_p_ff;
12045 buf->b_start_eol = buf->b_p_eol;
12046#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012047 buf->b_start_bomb = buf->b_p_bomb;
12048
Bram Moolenaar071d4272004-06-13 20:20:40 +000012049 /* Only use free/alloc when necessary, they take time. */
12050 if (buf->b_start_fenc == NULL
12051 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12052 {
12053 vim_free(buf->b_start_fenc);
12054 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12055 }
12056#endif
12057}
12058
12059/*
12060 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12061 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012062 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12063 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012064 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012065 * When "ignore_empty" is true don't consider a new, empty buffer to be
12066 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012067 */
12068 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012069file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012071 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012072{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012073 /* In a buffer that was never loaded the options are not valid. */
12074 if (buf->b_flags & BF_NEVERLOADED)
12075 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012076 if (ignore_empty
12077 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078 && buf->b_ml.ml_line_count == 1
12079 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12080 return FALSE;
12081 if (buf->b_start_ffc != *buf->b_p_ff)
12082 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012083 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012084 return TRUE;
12085#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012086 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12087 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012088 if (buf->b_start_fenc == NULL)
12089 return (*buf->b_p_fenc != NUL);
12090 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12091#else
12092 return FALSE;
12093#endif
12094}
12095
12096/*
12097 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12098 */
12099 int
12100check_ff_value(p)
12101 char_u *p;
12102{
12103 return check_opt_strings(p, p_ff_values, FALSE);
12104}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012105
12106/*
12107 * Return the effective shiftwidth value for current buffer, using the
12108 * 'tabstop' value when 'shiftwidth' is zero.
12109 */
12110 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012111get_sw_value(buf)
12112 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012113{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012114 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012115}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012116
12117/*
12118 * Return the effective softtabstop value for the current buffer, using the
12119 * 'tabstop' value when 'softtabstop' is negative.
12120 */
12121 long
12122get_sts_value()
12123{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012124 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012125}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012126
12127/*
12128 * Check matchpairs option for "*initc".
12129 * If there is a match set "*initc" to the matching character and "*findc" to
12130 * the opposite character. Set "*backwards" to the direction.
12131 * When "switchit" is TRUE swap the direction.
12132 */
12133 void
12134find_mps_values(initc, findc, backwards, switchit)
12135 int *initc;
12136 int *findc;
12137 int *backwards;
12138 int switchit;
12139{
12140 char_u *ptr;
12141
12142 ptr = curbuf->b_p_mps;
12143 while (*ptr != NUL)
12144 {
12145#ifdef FEAT_MBYTE
12146 if (has_mbyte)
12147 {
12148 char_u *prev;
12149
12150 if (mb_ptr2char(ptr) == *initc)
12151 {
12152 if (switchit)
12153 {
12154 *findc = *initc;
12155 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12156 *backwards = TRUE;
12157 }
12158 else
12159 {
12160 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12161 *backwards = FALSE;
12162 }
12163 return;
12164 }
12165 prev = ptr;
12166 ptr += mb_ptr2len(ptr) + 1;
12167 if (mb_ptr2char(ptr) == *initc)
12168 {
12169 if (switchit)
12170 {
12171 *findc = *initc;
12172 *initc = mb_ptr2char(prev);
12173 *backwards = FALSE;
12174 }
12175 else
12176 {
12177 *findc = mb_ptr2char(prev);
12178 *backwards = TRUE;
12179 }
12180 return;
12181 }
12182 ptr += mb_ptr2len(ptr);
12183 }
12184 else
12185#endif
12186 {
12187 if (*ptr == *initc)
12188 {
12189 if (switchit)
12190 {
12191 *backwards = TRUE;
12192 *findc = *initc;
12193 *initc = ptr[2];
12194 }
12195 else
12196 {
12197 *backwards = FALSE;
12198 *findc = ptr[2];
12199 }
12200 return;
12201 }
12202 ptr += 2;
12203 if (*ptr == *initc)
12204 {
12205 if (switchit)
12206 {
12207 *backwards = FALSE;
12208 *findc = *initc;
12209 *initc = ptr[-2];
12210 }
12211 else
12212 {
12213 *backwards = TRUE;
12214 *findc = ptr[-2];
12215 }
12216 return;
12217 }
12218 ++ptr;
12219 }
12220 if (*ptr == ',')
12221 ++ptr;
12222 }
12223}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012224
12225#if defined(FEAT_LINEBREAK) || defined(PROTO)
12226/*
12227 * This is called when 'breakindentopt' is changed and when a window is
12228 * initialized.
12229 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012230 static int
12231briopt_check(wp)
12232 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012233{
12234 char_u *p;
12235 int bri_shift = 0;
12236 long bri_min = 20;
12237 int bri_sbr = FALSE;
12238
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012239 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012240 while (*p != NUL)
12241 {
12242 if (STRNCMP(p, "shift:", 6) == 0
12243 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12244 {
12245 p += 6;
12246 bri_shift = getdigits(&p);
12247 }
12248 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12249 {
12250 p += 4;
12251 bri_min = getdigits(&p);
12252 }
12253 else if (STRNCMP(p, "sbr", 3) == 0)
12254 {
12255 p += 3;
12256 bri_sbr = TRUE;
12257 }
12258 if (*p != ',' && *p != NUL)
12259 return FAIL;
12260 if (*p == ',')
12261 ++p;
12262 }
12263
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012264 wp->w_p_brishift = bri_shift;
12265 wp->w_p_brimin = bri_min;
12266 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012267
12268 return OK;
12269}
12270#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012271
12272/*
12273 * Get the local or global value of 'backupcopy'.
12274 */
12275 unsigned int
12276get_bkc_value(buf)
12277 buf_T *buf;
12278{
12279 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12280}